From 1f0b2fc60096f3674a4fe5d0abd09e0402a10707 Mon Sep 17 00:00:00 2001 From: Camila Date: Wed, 20 Sep 2023 16:34:53 +0200 Subject: [PATCH] Clean up code, fix comments, remove not needed function... Signed-off-by: Camila --- src/gui/application.cpp | 74 ++++++++++++++++++++--------------------- src/gui/application.h | 4 +-- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 2a4a0bc0d226e..e29f1af60ab0b 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -245,8 +245,9 @@ Application::Application(int &argc, char **argv) setApplicationName(_theme->appName()); setWindowIcon(_theme->applicationIcon()); - // create config file if needed - createConfigFile(); + if (ConfigFile().exists()) { + createConfigFile(); + } if (_theme->doNotUseProxy()) { ConfigFile().setProxyType(QNetworkProxy::NoProxy); @@ -282,13 +283,34 @@ Application::Application(int &argc, char **argv) setupLogging(); setupTranslations(); - // try to migrate the settings if there was an older version before + // try to migrate legacy accounts and folders from a previous client version + // only copy the settings and check what should be skipped if (!configVersionMigration()) { qCWarning(lcApplication) << "Config version migration was not possible."; } - if (shouldExit()) { - std::exit(0); + ConfigFile cfg; + { + auto shouldExit = false; + + // these config values will always be empty after the first client run + if (!_overrideServerUrl.isEmpty()) { + cfg.setOverrideServerUrl(_overrideServerUrl); + shouldExit = true; + } + + if (!_overrideLocalDir.isEmpty()) { + cfg.setOverrideLocalDir(_overrideLocalDir); + shouldExit = true; + } + + if (AccountSetupCommandLineManager::instance()) { + cfg.setVfsEnabled(AccountSetupCommandLineManager::instance()->isVfsEnabled()); + } + + if (shouldExit) { + std::exit(0); + } } // The timeout is initialized with an environment variable, if not, override with the value from the config @@ -322,6 +344,7 @@ Application::Application(int &argc, char **argv) _fileProvider.reset(new Mac::FileProvider); #endif + // create accounts and folders from a legacy desktop client or from the current config file setupOrRestoreSettings(); setQuitOnLastWindowClosed(false); @@ -404,47 +427,22 @@ Application::~Application() AccountManager::instance()->shutdown(); } -bool Application::shouldExit() -{ - ConfigFile cfg; - auto shouldExit = false; - - // these config values will always be empty after the first client run - if (!_overrideServerUrl.isEmpty()) { - cfg.setOverrideServerUrl(_overrideServerUrl); - shouldExit = true; - } - - if (!_overrideLocalDir.isEmpty()) { - cfg.setOverrideLocalDir(_overrideLocalDir); - shouldExit = true; - } - - if (AccountSetupCommandLineManager::instance()) { - cfg.setVfsEnabled(AccountSetupCommandLineManager::instance()->isVfsEnabled()); - } - - return shouldExit; -} - void Application::setupOrRestoreSettings() { - // try to restore legacy accounts const auto accountsRestoreResult = restoreLegacyAccount(); + _folderManager.reset(new FolderMan); FolderMan::instance()->setSyncEnabled(true); + const auto foldersListSize = FolderMan::instance()->setupFolders(); - const auto prettyNamesList = [](const QList &accounts) - { + const auto prettyNamesList = [](const QList &accountStates) { QStringList list; - for (const auto &account : accounts) { + for (const auto &account : accountStates) { list << account->account()->prettyName().prepend("- "); } return list.join("\n"); }; - // try to restore legacy folders or set up folders - const auto foldersListSize = FolderMan::instance()->setupFolders(); if (const auto accounts = AccountManager::instance()->accounts(); accountsRestoreResult == AccountManager::AccountsRestoreSuccessFromLegacyVersion && accounts.size() > 0) { @@ -465,15 +463,15 @@ void Application::setupOrRestoreSettings() ); messageBox->setWindowModality(Qt::NonModal); messageBox->open(); + } else { + qCWarning(lcApplication) << "Migration result AccountManager::AccountsRestoreResult: " << accountsRestoreResult; + qCWarning(lcApplication) << "Folders migrated: " << foldersListSize; + qCWarning(lcApplication) << "No accounts were migrated, prompting user to set up accounts and folders from scratch."; } } void Application::createConfigFile() { - if (ConfigFile().exists()) { - return; - } - // Migrate from version <= 2.4 setApplicationName(_theme->appNameGUI()); #ifndef QT_WARNING_DISABLE_DEPRECATED // Was added in Qt 5.9 diff --git a/src/gui/application.h b/src/gui/application.h index 5f153c8381e4f..8ffd43fb87267 100644 --- a/src/gui/application.h +++ b/src/gui/application.h @@ -120,10 +120,8 @@ protected slots: AccountManager::AccountsRestoreResult restoreLegacyAccount(); void createConfigFile(); - // Attempt to setup new settings or restore legacy settings - // The settings include the accounts and folders saved in the config file void setupOrRestoreSettings(); - bool shouldExit(); + /** * Maybe a newer version of the client was used with this config file: * if so, backup, confirm with user and remove the config that can't be read.