Skip to content

Commit

Permalink
Application function and var renames and clean up setupConfigFile fun…
Browse files Browse the repository at this point in the history
…ction.

Signed-off-by: Camila <[email protected]>
  • Loading branch information
Camila authored and mgallien committed Sep 26, 2023
1 parent 0a5c147 commit 6a170bf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 43 deletions.
75 changes: 38 additions & 37 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Application::Application(int &argc, char **argv)
setWindowIcon(_theme->applicationIcon());

if (ConfigFile().exists()) {
createConfigFile();
setupConfigFile();
}

if (_theme->doNotUseProxy()) {
Expand Down Expand Up @@ -345,7 +345,7 @@ Application::Application(int &argc, char **argv)
#endif

// create accounts and folders from a legacy desktop client or from the current config file
setupOrRestoreSettings();
setupAccountsAndFolders();

setQuitOnLastWindowClosed(false);

Expand Down Expand Up @@ -427,36 +427,36 @@ Application::~Application()
AccountManager::instance()->shutdown();
}

void Application::setupOrRestoreSettings()
void Application::setupAccountsAndFolders()
{
const auto accountsRestoreResult = restoreLegacyAccount();

_folderManager.reset(new FolderMan);
FolderMan::instance()->setSyncEnabled(true);
const auto foldersListSize = FolderMan::instance()->setupFolders();

const auto prettyNamesList = [](const QList<AccountStatePtr> &accountStates) {
const auto prettyNamesList = [](const QList<AccountStatePtr> &accounts) {
QStringList list;
for (const auto &account : accountStates) {
for (const auto &account : accounts) {
list << account->account()->prettyName().prepend("- ");
}
return list.join("\n");
};

if (const auto accounts = AccountManager::instance()->accounts();
accountsRestoreResult == AccountManager::AccountsRestoreSuccessFromLegacyVersion
&& accounts.size() > 0) {
&& !accounts.isEmpty()) {
const auto accountsListSize = accounts.size();
const auto accountsRestoreMessage = accountsListSize > 1
? tr("%1 accounts", "number of legacy accounts imported").arg(QString::number(accountsListSize))

This comment has been minimized.

Copy link
@Valdnet

Valdnet Oct 2, 2023

Contributor

@camilasan @mgallien You need to add a condition for 2 accounts.
In Polish, there is a different variation for 5 accounts and a different one for 2 accounts.

: tr("one account");
? tr("%1 accounts", "number of accounts imported").arg(QString::number(accountsListSize))
: tr("1 account");
const auto foldersRestoreMessage = foldersListSize > 1
? tr("%1 folders", "number of legacy folders imported").arg(QString::number(foldersListSize))

This comment has been minimized.

Copy link
@Valdnet

Valdnet Oct 2, 2023

Contributor

@camilasan @mgallien You need to add a condition for 2 folders.
In Polish, there is a different variation for 5 folders and a different one for 2 folders.

: tr("one folder");
? tr("%1 folders", "number of folders imported").arg(QString::number(foldersListSize))
: tr("1 folder");
const auto messageBox = new QMessageBox(QMessageBox::Information,
tr("Legacy import"),
tr("Imported %1 and %2 from a legacy desktop client.\n%3",
"number of legacy accounts and folders imported. list of users.")
"number of accounts and folders imported. list of users.")
.arg(accountsRestoreMessage,
foldersRestoreMessage,
prettyNamesList(accounts))
Expand All @@ -470,54 +470,55 @@ void Application::setupOrRestoreSettings()
}
}

void Application::createConfigFile()
void Application::setupConfigFile()
{
// Migrate from version <= 2.4
setApplicationName(_theme->appNameGUI());
#ifndef QT_WARNING_DISABLE_DEPRECATED // Was added in Qt 5.9
#ifndef QT_WARNING_DISABLE_DEPRECATED // Was added in Qt 5.9
#define QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
#endif
#endif
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
QT_WARNING_POP
setApplicationName(_theme->appName());

QString oldDir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
auto oldDir = QStandardPaths::writableLocation(QStandardPaths::DataLocation);

// macOS 10.11.x does not like trailing slash for rename/move.
if (oldDir.endsWith('/')) {
oldDir.chop(1);
}

if (QFileInfo(oldDir).isDir()) {
auto confDir = ConfigFile().configPath();

// macOS 10.11.x does not like trailing slash for rename/move.
if (confDir.endsWith('/')) {
confDir.chop(1);
}
if (!QFileInfo(oldDir).isDir()) {
return;
}

qCInfo(lcApplication) << "Migrating old config from" << oldDir << "to" << confDir;
auto confDir = ConfigFile().configPath();

if (!QFile::rename(oldDir, confDir)) {
qCWarning(lcApplication) << "Failed to move the old config directory to its new location (" << oldDir << "to" << confDir << ")";
// macOS 10.11.x does not like trailing slash for rename/move.
if (confDir.endsWith('/')) {
confDir.chop(1);
}

// Try to move the files one by one
if (QFileInfo(confDir).isDir() || QDir().mkdir(confDir)) {
const QStringList filesList = QDir(oldDir).entryList(QDir::Files);
qCInfo(lcApplication) << "Will move the individual files" << filesList;
for (const auto &name : filesList) {
if (!QFile::rename(oldDir + "/" + name, confDir + "/" + name)) {
qCWarning(lcApplication) << "Fallback move of " << name << "also failed";
}
qCInfo(lcApplication) << "Migrating old config from" << oldDir << "to" << confDir;
if (!QFile::rename(oldDir, confDir)) {
qCWarning(lcApplication) << "Failed to move the old config directory to its new location (" << oldDir << "to" << confDir << ")";

// Try to move the files one by one
if (QFileInfo(confDir).isDir() || QDir().mkdir(confDir)) {
const QStringList filesList = QDir(oldDir).entryList(QDir::Files);
qCInfo(lcApplication) << "Will move the individual files" << filesList;
for (const auto &name : filesList) {
if (!QFile::rename(oldDir + "/" + name, confDir + "/" + name)) {
qCWarning(lcApplication) << "Fallback move of " << name << "also failed";
}
}
} else {
}
} else {
#ifndef Q_OS_WIN
// Create a symbolic link so a downgrade of the client would still find the config.
QFile::link(confDir, oldDir);
// Create a symbolic link so a downgrade of the client would still find the config.
QFile::link(confDir, oldDir);
#endif
}
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/gui/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ public slots:
void setupTranslations();
void setupLogging();

// Attempt to setup new settings or restore legacy settings
// The settings include the accounts and folders saved in the config file
void setupOrRestoreSettings();

signals:
void folderRemoved();
void folderStateChanged(OCC::Folder *);
Expand All @@ -122,8 +118,9 @@ protected slots:

void handleEditLocallyFromOptions();

AccountManager::AccountsRestoreResult restoreLegacyAccount();
void createConfigFile();
AccountManager::AccountsRestoreResult restoreLegacyAccount();
void setupConfigFile();
void setupAccountsAndFolders();

/**
* Maybe a newer version of the client was used with this config file:
Expand Down

0 comments on commit 6a170bf

Please sign in to comment.