1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

update delete avatar action

This commit is contained in:
PKEv 2015-10-14 23:31:05 +03:00
parent 0a11ccbeab
commit afb3bf35ee
3 changed files with 13 additions and 7 deletions

View File

@ -529,6 +529,15 @@ QList<HistoryKeeper::HistMessage> HistoryKeeper::exportMessagesDeleteFile()
return msgs; return msgs;
} }
void HistoryKeeper::removeAvatar(const QString& ownerId)
{
QSqlQuery query;
query.prepare("UPDATE aliases SET avatar=NULL, av_hash=NULL WHERE user_id = (:id)");
query.bindValue(":id", ownerId.left(64));
query.exec();
}
void HistoryKeeper::saveAvatar(QPixmap& pic, const QString& ownerId) void HistoryKeeper::saveAvatar(QPixmap& pic, const QString& ownerId)
{ {
QByteArray bArray; QByteArray bArray;

View File

@ -78,6 +78,8 @@ public:
void saveAvatarHash(const QByteArray& hash, const QString& ownerId); void saveAvatarHash(const QByteArray& hash, const QString& ownerId);
QByteArray getAvatarHash(const QString& ownerId); QByteArray getAvatarHash(const QString& ownerId);
void removeAvatar(const QString& ownerId);
private: private:
HistoryKeeper(GenericDdInterface *db_); HistoryKeeper(GenericDdInterface *db_);
HistoryKeeper(HistoryKeeper &hk) = delete; HistoryKeeper(HistoryKeeper &hk) = delete;

View File

@ -184,18 +184,13 @@ void ProfileForm::showProfilePictureContextMenu(const QPoint &point)
QPoint pos = profilePicture->mapToGlobal(point); QPoint pos = profilePicture->mapToGlobal(point);
QMenu contextMenu; QMenu contextMenu;
QAction *removeAction = contextMenu.addAction(tr("Remove")); QAction *removeAction = contextMenu.addAction(style()->standardIcon(QStyle::SP_DialogCancelButton), tr("Remove"));
QAction *selectedItem = contextMenu.exec(pos); QAction *selectedItem = contextMenu.exec(pos);
if (selectedItem == removeAction) if (selectedItem == removeAction)
{ {
QString selfPubKey = Core::getInstance()->getSelfId().publicKey; QString selfPubKey = Core::getInstance()->getSelfId().publicKey;
if (!QFile::remove(Settings::getInstance().getSettingsDirPath()+"avatars/"+selfPubKey.left(64)+".png")) HistoryKeeper::getInstance()->removeAvatar(selfPubKey);
{
GUI::showError(tr("Error"), tr("Could not remove avatar."));
return;
}
Core::getInstance()->setAvatar({}); Core::getInstance()->setAvatar({});
} }
} }