From 0a11ccbeab84e589f785e515256dff32226826a0 Mon Sep 17 00:00:00 2001 From: PKEv Date: Sun, 11 Oct 2015 22:17:27 +0300 Subject: [PATCH] add import avatars --- src/persistence/historykeeper.cpp | 39 +++++++++++++++++++++++++++++++ src/persistence/historykeeper.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/src/persistence/historykeeper.cpp b/src/persistence/historykeeper.cpp index c450e26cf..188a41bbf 100644 --- a/src/persistence/historykeeper.cpp +++ b/src/persistence/historykeeper.cpp @@ -136,11 +136,13 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) : } ans.clear(); + bool needImportAvatar = false; ans = db->exec("PRAGMA table_info('aliases')"); ans.seek(2); if (!ans.value(1).toString().contains("av_hash")) { //add collum in table + needImportAvatar = true; db->exec("ALTER TABLE aliases ADD COLUMN av_hash BLOB"); qDebug() << "Struct DB updated: Added column av_hash in table aliases."; } @@ -149,10 +151,16 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) : if (!ans.value(1).toString().contains("avatar")) { //add collum in table + needImportAvatar = true; db->exec("ALTER TABLE aliases ADD COLUMN avatar BLOB"); qDebug() << "Struct DB updated: Added column avatar in table aliases."; } + if (needImportAvatar) + { + importAvatar(); + } + updateChatsID(); updateAliases(); @@ -165,6 +173,37 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) : messageID = sqlAnswer.value(0).toLongLong(); } +void HistoryKeeper::importAvatar() +{ + QSqlQuery sqlAnswer = db->exec("SELECT * FROM aliases;"); + while (sqlAnswer.next()) + { + QString userID = sqlAnswer.value(1).toString(); + QString puth (Settings::getInstance().getSettingsDirPath() + + QString("avatars") + QDir::separator() + + userID +".png"); + qDebug() << QString("Try import avatar for: %1.").arg(userID); + if (QFile::exists(puth)) + { + QPixmap pic(puth); + saveAvatar(pic,userID); + qDebug() << QString("Import avatar for: %1.").arg(userID); + } + else + { + puth = Settings::getInstance().getSettingsDirPath() + + "avatar_" + userID + ".png"; + if (QFile::exists(puth)) + { + QPixmap pic(puth); + saveAvatar(pic,userID); + qDebug() << QString("Import from profile_dir avatar for: %1.").arg(userID); + } + } + + } +} + HistoryKeeper::~HistoryKeeper() { delete db; diff --git a/src/persistence/historykeeper.h b/src/persistence/historykeeper.h index 5708d98f5..2ee7c54ac 100644 --- a/src/persistence/historykeeper.h +++ b/src/persistence/historykeeper.h @@ -93,6 +93,8 @@ private: ChatType convertToChatType(int); + void importAvatar(); // may be deleted after all move to new db structure + GenericDdInterface *db; QMap aliases; QMap> chats;