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

add import avatars

This commit is contained in:
PKEv 2015-10-11 22:17:27 +03:00
parent dd975c38eb
commit 0a11ccbeab
2 changed files with 41 additions and 0 deletions

View File

@ -136,11 +136,13 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) :
} }
ans.clear(); ans.clear();
bool needImportAvatar = false;
ans = db->exec("PRAGMA table_info('aliases')"); ans = db->exec("PRAGMA table_info('aliases')");
ans.seek(2); ans.seek(2);
if (!ans.value(1).toString().contains("av_hash")) if (!ans.value(1).toString().contains("av_hash"))
{ {
//add collum in table //add collum in table
needImportAvatar = true;
db->exec("ALTER TABLE aliases ADD COLUMN av_hash BLOB"); db->exec("ALTER TABLE aliases ADD COLUMN av_hash BLOB");
qDebug() << "Struct DB updated: Added column av_hash in table aliases."; 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")) if (!ans.value(1).toString().contains("avatar"))
{ {
//add collum in table //add collum in table
needImportAvatar = true;
db->exec("ALTER TABLE aliases ADD COLUMN avatar BLOB"); db->exec("ALTER TABLE aliases ADD COLUMN avatar BLOB");
qDebug() << "Struct DB updated: Added column avatar in table aliases."; qDebug() << "Struct DB updated: Added column avatar in table aliases.";
} }
if (needImportAvatar)
{
importAvatar();
}
updateChatsID(); updateChatsID();
updateAliases(); updateAliases();
@ -165,6 +173,37 @@ HistoryKeeper::HistoryKeeper(GenericDdInterface *db_) :
messageID = sqlAnswer.value(0).toLongLong(); 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() HistoryKeeper::~HistoryKeeper()
{ {
delete db; delete db;

View File

@ -93,6 +93,8 @@ private:
ChatType convertToChatType(int); ChatType convertToChatType(int);
void importAvatar(); // may be deleted after all move to new db structure
GenericDdInterface *db; GenericDdInterface *db;
QMap<QString, int> aliases; QMap<QString, int> aliases;
QMap<QString, QPair<int, ChatType>> chats; QMap<QString, QPair<int, ChatType>> chats;