- // kinda ugly, but I currently see no other way to do that
-#ifdef Q_OS_WIN32
- QString quasselDir = QDir::homePath() + qgetenv("APPDATA") + "\\quassel\\";
-#else
- QString quasselDir = QDir::homePath() + "/.quassel/";
-#endif
-
- QDir qDir(quasselDir);
- if(!qDir.exists(quasselDir))
- qDir.mkpath(quasselDir);
-
- return quasselDir + "quassel-storage.sqlite";
-}
-
-
-// ONLY NEEDED FOR MIGRATION
-bool SqliteStorage::init(const QVariantMap &settings) {
- if(!AbstractSqlStorage::init(settings))
- return false;
-
- QSqlQuery checkMigratedQuery(logDb());
- checkMigratedQuery.prepare("SELECT DISTINCT typeOf(password) FROM quasseluser");
- checkMigratedQuery.exec();
- if(!watchQuery(&checkMigratedQuery))
- return false;
-
- if(!checkMigratedQuery.first())
- return false;
-
- QString passType = checkMigratedQuery.value(0).toString().toLower();
- if(passType == "text")
- return true; // allready migrated
-
- Q_ASSERT(passType == "blob");
-
- QSqlQuery getPasswordsQuery(logDb());
- getPasswordsQuery.prepare("SELECT userid, password FROM quasseluser");
- getPasswordsQuery.exec();
-
- if(!watchQuery(&getPasswordsQuery)) {
- qWarning() << "unable to migrate to new password format!";
- return false;
- }
-
- QHash<int, QByteArray> passHash;
- while(getPasswordsQuery.next()) {
- passHash[getPasswordsQuery.value(0).toInt()] = getPasswordsQuery.value(1).toByteArray();
- }
-
- QSqlQuery setPasswordsQuery(logDb());
- setPasswordsQuery.prepare("UPDATE quasseluser SET password = :password WHERE userid = :userid");
- foreach(int userId, passHash.keys()) {
- setPasswordsQuery.bindValue(":password", QString(passHash[userId]));
- setPasswordsQuery.bindValue(":userid", userId);
- setPasswordsQuery.exec();
- watchQuery(&setPasswordsQuery);
- }
-
- qDebug() << "successfully migrated passwords!";
- return true;