Skip to content

Commit

Permalink
Clean up code, fix comments, remove not needed function...
Browse files Browse the repository at this point in the history
Signed-off-by: Camila <[email protected]>
  • Loading branch information
Camila committed Sep 20, 2023
1 parent b74d0ef commit 1f0b2fc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
74 changes: 36 additions & 38 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<AccountStatePtr> &accounts)
{
const auto prettyNamesList = [](const QList<AccountStatePtr> &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) {
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/gui/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 1f0b2fc

Please sign in to comment.