Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
{
ConfigFile configFile;
const auto shouldTryToMigrate = configFile.shouldTryToMigrate();
if (!shouldTryToMigrate) {

Check warning on line 127 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the init-statement to declare "shouldTryToMigrate" inside the if statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlZ&open=AZ9Ce3ngG5cpcpcN_mlZ&pullRequest=10325
qCInfo(lcApplication) << "This is not an upgrade/downgrade/migration. Proceed to read current application config file.";
configFile.setMigrationPhase(ConfigFile::MigrationPhase::Done);
return false;
Expand Down Expand Up @@ -309,7 +309,7 @@
qCDebug(lcApplication) << "Failed to move the old config directory to its new location (" << legacyDir << "to" << confDir << ")";

// Try to move the files one by one
if (QFileInfo(confDir).isDir() || QDir().mkdir(confDir)) {

Check failure on line 312 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this TOCTOU race condition window when accessing files

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlb&open=AZ9Ce3ngG5cpcpcN_mlb&pullRequest=10325
const QStringList filesList = QDir(legacyDir).entryList(QDir::Files);
qCDebug(lcApplication) << "Will move the individual files" << filesList;
for (const auto &name : filesList) {
Expand All @@ -321,7 +321,7 @@
} else {
#ifndef Q_OS_WIN
// Create a symbolic link so a downgrade of the client would still find the config.
QFile::link(confDir, legacyDir);

Check failure on line 324 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this TOCTOU race condition window when accessing files

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mla&open=AZ9Ce3ngG5cpcpcN_mla&pullRequest=10325
#endif
}
}
Expand All @@ -329,7 +329,7 @@
setupConfigFile();
}

if (_theme->doNotUseProxy()) {

Check warning on line 332 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "->" with "::" for access to "Theme::doNotUseProxy".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlc&open=AZ9Ce3ngG5cpcpcN_mlc&pullRequest=10325
ConfigFile().setProxyType(QNetworkProxy::NoProxy);
const auto &allAccounts = AccountManager::instance()->accounts();
for (const auto &accountState : allAccounts) {
Expand Down Expand Up @@ -412,8 +412,10 @@
connect(&_singleApp, &KDSingleApplication::messageReceived, this, &Application::slotParseMessage);
#endif

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

if (AccountSetupCommandLineManager::instance()->isCommandLineParsed()) {
_folderManager.reset(new FolderMan);
AccountSetupCommandLineManager::instance()->setupAccountFromCommandLine();
_quitInstance = true;
}
Expand All @@ -422,9 +424,6 @@
return;
}

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

setQuitOnLastWindowClosed(false);

// Setting up the gui class will allow tray notifications for the
Expand All @@ -439,7 +438,7 @@
_gui->setupCloudProviders();
#endif

if (_theme->doNotUseProxy()) {

Check warning on line 441 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace "->" with "::" for access to "Theme::doNotUseProxy".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mld&open=AZ9Ce3ngG5cpcpcN_mld&pullRequest=10325
ConfigFile().setProxyType(QNetworkProxy::NoProxy);
const auto &allAccounts = AccountManager::instance()->accounts();
for (const auto &accountState : allAccounts) {
Expand Down Expand Up @@ -624,7 +623,7 @@
const auto foldersRestoreMessage = foldersListSize > 1
? tr("%1 folders", "number of folders imported").arg(QString::number(foldersListSize))
: tr("1 folder");
const auto messageBox = new QMessageBox(QMessageBox::Information,

Check failure on line 626 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mle&open=AZ9Ce3ngG5cpcpcN_mle&pullRequest=10325
tr("Legacy import"),
tr("Imported %1 and %2 from a legacy desktop client.\n%3",
"number of accounts and folders imported. list of users.")
Expand Down Expand Up @@ -678,7 +677,7 @@
AccountSetupCommandLineManager::destroy();
}

void Application::setupConfigFile()

Check warning on line 680 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This function should be declared "const".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlf&open=AZ9Ce3ngG5cpcpcN_mlf&pullRequest=10325
{
// Migrate from version <= 2.4
setApplicationName(_theme->appNameGUI());
Expand Down Expand Up @@ -713,11 +712,11 @@
qCDebug(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)) {

Check failure on line 715 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this TOCTOU race condition window when accessing files

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlh&open=AZ9Ce3ngG5cpcpcN_mlh&pullRequest=10325
const QStringList filesList = QDir(oldDir).entryList(QDir::Files);
qCDebug(lcApplication) << "Will move the individual files" << filesList;
for (const auto &name : filesList) {
if (!QFile::rename(oldDir + "/" + name, confDir + "/" + name)) {

Check failure on line 719 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlg&open=AZ9Ce3ngG5cpcpcN_mlg&pullRequest=10325
qCDebug(lcApplication) << "Fallback move of " << name << "also failed";
}
}
Expand All @@ -730,9 +729,9 @@
}
}

AccountManager::AccountsRestoreResult Application::restoreLegacyAccount()

Check warning on line 732 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This function should be declared "const".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mli&open=AZ9Ce3ngG5cpcpcN_mli&pullRequest=10325
{
ConfigFile cfg;

Check warning on line 734 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "cfg" of type "class OCC::ConfigFile" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlj&open=AZ9Ce3ngG5cpcpcN_mlj&pullRequest=10325
const auto tryMigrate = cfg.overrideServerUrl().isEmpty();
auto accountsRestoreResult = AccountManager::AccountsRestoreFailure;
if (accountsRestoreResult = AccountManager::instance()->restore(tryMigrate);
Expand Down Expand Up @@ -809,7 +808,7 @@
// FIXME: This is not ideal yet since a ConnectionValidator might already be running and is in
// progress of timing out in some seconds.
// Maybe we need 2 validators, one triggered by timer, one by network configuration changes?
void Application::slotSystemOnlineConfigurationChanged()

Check warning on line 811 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this identifier to be shorter or equal to 31 characters.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlk&open=AZ9Ce3ngG5cpcpcN_mlk&pullRequest=10325

Check warning on line 811 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

This function should be declared "const".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mll&open=AZ9Ce3ngG5cpcpcN_mll&pullRequest=10325
{
if (QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Site ||
QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online) {
Expand Down Expand Up @@ -996,7 +995,7 @@
}
} else if (option == QStringLiteral("--overrideserverurl")) {
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
const auto overrideUrl = it.next();

Check warning on line 998 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid this unnecessary copy by using a "const" reference.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlm&open=AZ9Ce3ngG5cpcpcN_mlm&pullRequest=10325
const auto isUrlValid = (overrideUrl.startsWith(QStringLiteral("http://")) || overrideUrl.startsWith(QStringLiteral("https://")))
&& QUrl::fromUserInput(overrideUrl).isValid();
if (!isUrlValid) {
Expand Down Expand Up @@ -1172,7 +1171,7 @@
{
const ConfigFile cfg;
const auto configLanguage = cfg.language();
if (!configLanguage.isEmpty()) {

Check warning on line 1174 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the init-statement to declare "configLanguage" inside the if statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mln&open=AZ9Ce3ngG5cpcpcN_mln&pullRequest=10325
// always prefer value from configuration
return configLanguage;
}
Expand Down Expand Up @@ -1224,8 +1223,8 @@
const QString qtBaseTrFile = QLatin1String("qtbase_") + choosenLanguage;
if (!qtTranslator->load(qtTrFile, qtTrPath)) {
if (!qtTranslator->load(qtTrFile, trPath)) {
if (!qtTranslator->load(qtBaseTrFile, qtTrPath)) {

Check failure on line 1226 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlo&open=AZ9Ce3ngG5cpcpcN_mlo&pullRequest=10325
if (!qtTranslator->load(qtBaseTrFile, trPath)) {

Check warning on line 1227 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlq&open=AZ9Ce3ngG5cpcpcN_mlq&pullRequest=10325
qCDebug(lcApplication()) << "impossible to load Qt translation catalog" << qtBaseTrFile;
}
}
Expand All @@ -1233,7 +1232,7 @@
}
const QString qtkeychainTrFile = QLatin1String("qtkeychain_") + choosenLanguage;
if (!qtkeychainTranslator->load(qtkeychainTrFile, qtTrPath)) {
if (!qtkeychainTranslator->load(qtkeychainTrFile, trPath)) {

Check warning on line 1235 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this "if" statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlp&open=AZ9Ce3ngG5cpcpcN_mlp&pullRequest=10325
qCDebug(lcApplication()) << "impossible to load QtKeychain translation catalog" << qtkeychainTrFile;
}
}
Expand Down Expand Up @@ -1283,7 +1282,7 @@

void Application::openVirtualFile(const QString &filename)
{
QString virtualFileExt = QStringLiteral(APPLICATION_DOTVIRTUALFILE_SUFFIX);

Check warning on line 1285 in src/gui/application.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ9Ce3ngG5cpcpcN_mlr&open=AZ9Ce3ngG5cpcpcN_mlr&pullRequest=10325
if (!filename.endsWith(virtualFileExt)) {
qWarning(lcApplication) << "Can only handle file ending in .owncloud. Unable to open" << filename;
return;
Expand Down
Loading