int FolderMan::setupFolders() { unloadAndDeleteAllFolders(); auto settings = Account::settingsWithGroup(QLatin1String("Accounts")); const auto accountsWithSettings = settings->childGroups(); if (accountsWithSettings.isEmpty()) { int r = setupFoldersMigration(); if (r > 0) { AccountManager::instance()->save(false); // don't save credentials, they had not been loaded from keychain } return r; } qDebug() << "* Setup folders from settings file"; foreach (const auto& account, AccountManager::instance()->accounts()) { const auto id = account->account()->id(); if (!accountsWithSettings.contains(id)) { continue; } settings->beginGroup(id); settings->beginGroup(QLatin1String("Folders")); foreach (const auto& folderAlias, settings->childGroups()) { FolderDefinition folderDefinition; if (FolderDefinition::load(*settings, folderAlias, &folderDefinition)) { Folder* f = addFolderInternal(folderDefinition); if (f) { f->setAccountState( account.data() ); slotScheduleSync(f); emit folderSyncStateChange(f); } } } settings->endGroup(); // Folders settings->endGroup(); // <account> } emit folderListChanged(_folderMap); return _folderMap.size(); }
void FolderMan::setupFoldersHelper(QSettings &settings, AccountStatePtr account, bool backwardsCompatible) { foreach (const auto &folderAlias, settings.childGroups()) { FolderDefinition folderDefinition; if (FolderDefinition::load(settings, folderAlias, &folderDefinition)) { auto defaultJournalPath = folderDefinition.defaultJournalPath(account->account()); // Migration: Old settings don't have journalPath if (folderDefinition.journalPath.isEmpty()) { folderDefinition.journalPath = defaultJournalPath; } // Migration: ._ files sometimes don't work // So if the configured journalPath is the default one ("._sync_*.db") // but the current default doesn't have the underscore, switch to the // new default. See SyncJournalDb::makeDbName(). if (folderDefinition.journalPath.startsWith("._sync_") && defaultJournalPath.startsWith(".sync_")) { folderDefinition.journalPath = defaultJournalPath; } // Migration: If an old db is found, move it to the new name. if (backwardsCompatible) { SyncJournalDb::maybeMigrateDb(folderDefinition.localPath, folderDefinition.absoluteJournalPath()); } Folder *f = addFolderInternal(std::move(folderDefinition), account.data()); if (f) { // Migration: Mark folders that shall be saved in a backwards-compatible way if (backwardsCompatible) { f->setSaveBackwardsCompatible(true); } scheduleFolder(f); emit folderSyncStateChange(f); } } } }