return &instance;
}
-bool AccountManager::restore(bool alsoRestoreLegacySettings)
+AccountManager::AccountsRestoreResult AccountManager::restore(const bool alsoRestoreLegacySettings)
{
QStringList skipSettingsKeys;
backwardMigrationSettingsKeys(&skipSettingsKeys, &skipSettingsKeys);
if (settings->status() != QSettings::NoError || !settings->isWritable()) {
qCWarning(lcAccountManager) << "Could not read settings from" << settings->fileName()
<< settings->status();
- return false;
+ return AccountsRestoreFailure;
}
if (skipSettingsKeys.contains(settings->group())) {
// Should not happen: bad container keys should have been deleted
qCWarning(lcAccountManager) << "Accounts structure is too new, ignoring";
- return true;
+ return AccountsRestoreSuccessWithSkipped;
}
// If there are no accounts, check the old format.
if (settings->childGroups().isEmpty() && !settings->contains(QLatin1String(versionC)) && alsoRestoreLegacySettings) {
restoreFromLegacySettings();
- return true;
+ return AccountsRestoreSuccessFromLegacyVersion;
}
+ auto result = AccountsRestoreSuccess;
const auto settingsChildGroups = settings->childGroups();
for (const auto &accountId : settingsChildGroups) {
settings->beginGroup(accountId);
} else {
qCInfo(lcAccountManager) << "Account" << accountId << "is too new, ignoring";
_additionalBlockedAccountIds.insert(accountId);
+ result = AccountsRestoreSuccessWithSkipped;
}
settings->endGroup();
}
- return true;
+ return result;
}
void AccountManager::backwardMigrationSettingsKeys(QStringList *deleteKeys, QStringList *ignoreKeys)
{
Q_OBJECT
public:
+ enum AccountsRestoreResult {
+ AccountsRestoreFailure = 0,
+ AccountsRestoreSuccess,
+ AccountsRestoreSuccessFromLegacyVersion,
+ AccountsRestoreSuccessWithSkipped
+ };
+ Q_ENUM (AccountsRestoreResult);
+
static AccountManager *instance();
~AccountManager() override = default;
* Returns false if there was an error reading the settings,
* but note that settings not existing is not an error.
*/
- bool restore(bool alsoRestoreLegacySettings = true);
+ AccountsRestoreResult restore(const bool alsoRestoreLegacySettings = true);
/**
* Add this account in the list of saved accounts.
connect(this, &SharedTools::QtSingleApplication::messageReceived, this, &Application::slotParseMessage);
- if (!AccountManager::instance()->restore(cfg.overrideServerUrl().isEmpty())) {
+ const auto tryMigrate = cfg.overrideServerUrl().isEmpty();
+ auto accountsRestoreResult = AccountManager::AccountsRestoreFailure;
+ if (accountsRestoreResult = AccountManager::instance()->restore(tryMigrate);
+ accountsRestoreResult == AccountManager::AccountsRestoreFailure) {
// If there is an error reading the account settings, try again
// after a couple of seconds, if that fails, give up.
// (non-existence is not an error)
Utility::sleep(5);
- if (!AccountManager::instance()->restore(cfg.overrideServerUrl().isEmpty())) {
+ if (accountsRestoreResult = AccountManager::instance()->restore(tryMigrate);
+ accountsRestoreResult == AccountManager::AccountsRestoreFailure) {
qCCritical(lcApplication) << "Could not read the account settings, quitting";
QMessageBox::critical(
nullptr,