AccountSettings: Restore from legacy only once #3565

And also introduce a Accounts/version int at the same time. That
may make future account settings migrations easier to manage.
This commit is contained in:
Christian Kamm 2015-09-03 06:23:19 +02:00
parent 69f8dd896f
commit 419deff861

View file

@ -29,6 +29,7 @@ static const char userC[] = "user";
static const char httpUserC[] = "http_user";
static const char caCertsKeyC[] = "CaCertificates";
static const char accountsC[] = "Accounts";
static const char versionC[] = "version";
}
@ -45,7 +46,8 @@ bool AccountManager::restore()
auto settings = Account::settingsWithGroup(QLatin1String(accountsC));
// If there are no accounts, check the old format.
if (settings->childGroups().isEmpty()) {
if (settings->childGroups().isEmpty()
&& !settings->contains(QLatin1String(versionC))) {
return restoreFromLegacySettings();
}
@ -122,6 +124,7 @@ bool AccountManager::restoreFromLegacySettings()
void AccountManager::save(bool saveCredentials)
{
auto settings = Account::settingsWithGroup(QLatin1String(accountsC));
settings->setValue(QLatin1String(versionC), 2);
foreach (const auto &acc, _accounts) {
settings->beginGroup(acc->account()->id());
save(acc->account(), *settings, saveCredentials);