diff options
author | Christian Kamm <mail@ckamm.de> | 2018-05-02 16:40:54 +0300 |
---|---|---|
committer | ckamm <mail@ckamm.de> | 2018-05-24 13:18:44 +0300 |
commit | 57a28819068b2ca77e264ab754c1a15b064b881b (patch) | |
tree | bafcc94e1a529f5e2ae8d841a893354e00de0253 /src/gui/accountmanager.cpp | |
parent | c625d8e3b74ef1a7b9cf03533521c78553bdd1ee (diff) |
Config: Add version flags to accounts and folders
Also, if there is too-new configuration, backup the file, show a
warning message asking the user whether it's ok to discard the
configuration from the future.
See #6504
Diffstat (limited to 'src/gui/accountmanager.cpp')
-rw-r--r-- | src/gui/accountmanager.cpp | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 38a0ff185..eaa0184c1 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -33,6 +33,10 @@ static const char caCertsKeyC[] = "CaCertificates"; static const char accountsC[] = "Accounts"; static const char versionC[] = "version"; static const char serverVersionC[] = "serverVersion"; + +// The maximum versions that this client can read +static const int maxAccountsVersion = 2; +static const int maxAccountVersion = 1; } @@ -76,6 +80,27 @@ bool AccountManager::restore() return true; } +QStringList AccountManager::backwardMigrationKeys() +{ + auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC)); + QStringList badKeys; + + const int accountsVersion = settings->value(QLatin1String(versionC)).toInt(); + if (accountsVersion <= maxAccountsVersion) { + foreach (const auto &accountId, settings->childGroups()) { + settings->beginGroup(accountId); + const int accountVersion = settings->value(QLatin1String(versionC), 1).toInt(); + if (accountVersion > maxAccountVersion) { + badKeys.append(settings->group()); + } + settings->endGroup(); + } + } else { + badKeys.append(settings->group()); + } + return badKeys; +} + bool AccountManager::restoreFromLegacySettings() { qCInfo(lcAccountManager) << "Migrate: restoreFromLegacySettings, checking settings group" @@ -136,7 +161,7 @@ bool AccountManager::restoreFromLegacySettings() void AccountManager::save(bool saveCredentials) { auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC)); - settings->setValue(QLatin1String(versionC), 2); + settings->setValue(QLatin1String(versionC), maxAccountsVersion); foreach (const auto &acc, _accounts) { settings->beginGroup(acc->account()->id()); saveAccountHelper(acc->account().data(), *settings, saveCredentials); @@ -174,6 +199,7 @@ void AccountManager::saveAccountState(AccountState *a) void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool saveCredentials) { + settings.setValue(QLatin1String(versionC), maxAccountVersion); settings.setValue(QLatin1String(urlC), acc->_url.toString()); settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion); if (acc->_credentials) { @@ -324,7 +350,6 @@ AccountPtr AccountManager::createAccount() return acc; } - void AccountManager::shutdown() { auto accountsCopy = _accounts; |