Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 20 additions & 14 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2014 ownCloud GmbH
Expand Down Expand Up @@ -65,7 +65,7 @@
#define BACKGROUND_PALETTE "alternate-base"
#else
// ...and "alternate-base" looks too bright on macOS only. On Linux/Plasma either one looked fine ...
#define BACKGROUND_PALETTE "light"

Check failure on line 68 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this macro by "const", "constexpr" or an "enum".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpYCu9rCdcB_xDMc&open=AZ4cnpYCu9rCdcB_xDMc&pullRequest=10021
#endif

#ifdef BUILD_FILE_PROVIDER_MODULE
Expand All @@ -78,7 +78,7 @@
#include "common/macsandboxpersistentaccess.h"
#endif

#include "account.h"

Check warning on line 81 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this #include directive to the top of the file.

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

namespace {
constexpr auto propertyFolder = "folder";
Expand All @@ -87,7 +87,7 @@
constexpr auto e2EeUiActionSetupEncryptionId = "setup_encryption";
constexpr auto e2EeUiActionForgetEncryptionId = "forget_encryption";
constexpr auto e2EeUiActionDisplayMnemonicId = "display_mnemonic";
constexpr auto e2EeUiActionMigrateCertificateId = "migrate_certificate";

Check warning on line 90 in src/gui/accountsettings.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=AZ4cnpYCu9rCdcB_xDMf&open=AZ4cnpYCu9rCdcB_xDMf&pullRequest=10021
}

namespace OCC {
Expand Down Expand Up @@ -179,7 +179,7 @@
AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent)
: QWidget(parent)
, _ui(new Ui::AccountSettings)
, _model(new FolderStatusModel)

Check warning on line 182 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not use the constructor's initializer list for data member "_model". Use the in-class initializer instead.

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

Check failure on line 182 in src/gui/accountsettings.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=AZ4cnpYCu9rCdcB_xDMg&open=AZ4cnpYCu9rCdcB_xDMg&pullRequest=10021
, _accountState(accountState)
, _userInfo(accountState, false, true)
{
Expand Down Expand Up @@ -216,21 +216,27 @@
new ToolTipUpdater(_ui->_folderList);

#if defined(BUILD_FILE_PROVIDER_MODULE)
const auto fileProviderPanelContents = _ui->fileProviderPanelContents;
const auto fpSettingsLayout = new QVBoxLayout(fileProviderPanelContents);
const auto fpAccountUserIdAtHost = _accountState->account()->userIdAtHostWithPort();
const auto fpSettingsController = Mac::FileProviderSettingsController::instance();
const auto fpSettingsWidget = fpSettingsController->settingsViewWidget(fpAccountUserIdAtHost, fileProviderPanelContents,
QQuickWidget::SizeRootObjectToView);
fpSettingsLayout->setContentsMargins(0, 0, 0, 0);
fpSettingsLayout->setSpacing(0);

fpSettingsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
if (const auto fpSettingsWidgetLayout = fpSettingsWidget->layout()) {
fpSettingsWidgetLayout->setContentsMargins(0, 0, 0, 0);
if (Mac::FileProvider::available()) {
const auto fileProviderPanelContents = _ui->fileProviderPanelContents;
const auto fpSettingsLayout = new QVBoxLayout(fileProviderPanelContents);
const auto fpAccountUserIdAtHost = _accountState->account()->userIdAtHostWithPort();
const auto fpSettingsController = Mac::FileProviderSettingsController::instance();
const auto fpSettingsWidget = fpSettingsController->settingsViewWidget(fpAccountUserIdAtHost, fileProviderPanelContents,
QQuickWidget::SizeRootObjectToView);
fpSettingsLayout->setContentsMargins(0, 0, 0, 0);
fpSettingsLayout->setSpacing(0);

fpSettingsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
if (const auto fpSettingsWidgetLayout = fpSettingsWidget->layout()) {
fpSettingsWidgetLayout->setContentsMargins(0, 0, 0, 0);
}
fpSettingsLayout->addWidget(fpSettingsWidget, 1);
fileProviderPanelContents->setLayout(fpSettingsLayout);
} else {
// macOS 13 Ventura: the file provider feature is unsupported there.
// This branch can be removed once Ventura is no longer supported.
_ui->fileProviderPanel->setVisible(false);
}
fpSettingsLayout->addWidget(fpSettingsWidget, 1);
fileProviderPanelContents->setLayout(fpSettingsLayout);
#else
_ui->fileProviderPanel->setVisible(false);
#endif
Expand Down Expand Up @@ -473,7 +479,7 @@
return true;
}

void AccountSettings::slotMarkSubfolderEncrypted(FolderStatusModel::SubFolderInfo* folderInfo)

Check warning on line 482 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "folderInfo" is "struct OCC::FolderStatusModel::SubFolderInfo *".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpYCu9rCdcB_xDMh&open=AZ4cnpYCu9rCdcB_xDMh&pullRequest=10021
{
if (!canEncryptOrDecrypt(folderInfo)) {
return;
Expand All @@ -483,8 +489,8 @@
Q_ASSERT(folder);

const auto folderAlias = folder->alias();
const auto path = folderInfo->_path;

Check warning on line 492 in src/gui/accountsettings.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=AZ4cnpYCu9rCdcB_xDMi&open=AZ4cnpYCu9rCdcB_xDMi&pullRequest=10021
const auto fileId = folderInfo->_fileId;

Check warning on line 493 in src/gui/accountsettings.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=AZ4cnpYCu9rCdcB_xDMj&open=AZ4cnpYCu9rCdcB_xDMj&pullRequest=10021
const auto encryptFolder = [this, fileId, path, folderAlias] {
const auto folder = FolderMan::instance()->folder(folderAlias);
if (!folder) {
Expand All @@ -497,7 +503,7 @@
Q_ASSERT(!path.startsWith('/') && path.endsWith('/'));
// But EncryptFolderJob expects directory path Foo/Bar convention
const auto choppedPath = path.chopped(1);
auto job = new OCC::EncryptFolderJob(accountsState()->account(), folder->journalDb(), choppedPath, choppedPath, folder->remotePath(), fileId);

Check warning on line 506 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "job" of type "class OCC::EncryptFolderJob *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpYCu9rCdcB_xDMk&open=AZ4cnpYCu9rCdcB_xDMk&pullRequest=10021
job->setParent(this);
job->setProperty(propertyFolder, QVariant::fromValue(folder));
job->setProperty(propertyPath, QVariant::fromValue(path));
Expand Down Expand Up @@ -754,7 +760,7 @@
if (const auto mode = bestAvailableVfsMode();
!Theme::instance()->disableVirtualFilesSyncFolder() &&
Theme::instance()->showVirtualFilesOption() && !folder->virtualFilesEnabled() && Vfs::checkAvailability(folder->path(), mode)) {
if (mode == Vfs::WindowsCfApi || ConfigFile().showExperimentalOptions()) {

Check warning on line 763 in src/gui/accountsettings.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=AZ4cnpYCu9rCdcB_xDMl&open=AZ4cnpYCu9rCdcB_xDMl&pullRequest=10021
ac = menu->addAction(tr("Enable virtual file support %1 …").arg(mode == Vfs::WindowsCfApi ? QString() : tr("(experimental)")));
// TODO: remove when UX decision is made
ac->setEnabled(!Utility::isPathWindowsDrivePartitionRoot(folder->path()));
Expand Down Expand Up @@ -1220,7 +1226,7 @@
widget.exec();
}

void AccountSettings::forgetEncryptionOnDeviceForAccount(const AccountPtr &account) const

Check warning on line 1229 in src/gui/accountsettings.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=AZ4cnpYCu9rCdcB_xDMm&open=AZ4cnpYCu9rCdcB_xDMm&pullRequest=10021
{
QMessageBox dialog;
dialog.setWindowTitle(tr("Forget the end-to-end encryption on this device"));
Expand Down Expand Up @@ -1386,7 +1392,7 @@
slotAccountStateChanged();
}

void AccountSettings::slotAccountStateChanged()

Check failure on line 1395 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 26 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpYCu9rCdcB_xDMn&open=AZ4cnpYCu9rCdcB_xDMn&pullRequest=10021
{
const auto state = _accountState ? _accountState->state() : AccountState::Disconnected;
if (state != AccountState::Disconnected) {
Expand Down Expand Up @@ -1509,7 +1515,7 @@
const auto li = link.split(QLatin1String("?folder="));
if (li.count() > 1) {
auto myFolder = li[0];
const auto alias = li[1];

Check warning on line 1518 in src/gui/accountsettings.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=AZ4cnpYCu9rCdcB_xDMo&open=AZ4cnpYCu9rCdcB_xDMo&pullRequest=10021
if (myFolder.endsWith(QLatin1Char('/'))) {
myFolder.chop(1);
}
Expand Down Expand Up @@ -1637,7 +1643,7 @@
}
}

void AccountSettings::slotE2eEncryptionCertificateNeedMigration()

Check warning on line 1646 in src/gui/accountsettings.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=AZ4cnpYCu9rCdcB_xDMp&open=AZ4cnpYCu9rCdcB_xDMp&pullRequest=10021
{
const auto actionMigrateCertificate = addActionToEncryptionMessage(tr("Migrate certificate to a new one"), e2EeUiActionMigrateCertificateId);
connect(actionMigrateCertificate, &QAction::triggered, this, [this] {
Expand Down Expand Up @@ -1824,9 +1830,9 @@

void AccountSettings::removeActionFromEncryptionMessage(const QString &actionId)
{
const auto foundEnableEncryptionActionIt = std::find_if(std::cbegin(_ui->encryptionMessage->actions()), std::cend(_ui->encryptionMessage->actions()), [&actionId](const QAction *action) {
return action->property(e2eUiActionIdKey).toString() == actionId;
});

Check warning on line 1835 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace with the version of "std::ranges::find_if" that takes a range.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpYCu9rCdcB_xDMq&open=AZ4cnpYCu9rCdcB_xDMq&pullRequest=10021
if (foundEnableEncryptionActionIt != std::cend(_ui->encryptionMessage->actions())) {
_ui->encryptionMessage->removeAction(*foundEnableEncryptionActionIt);
(*foundEnableEncryptionActionIt)->deleteLater();
Expand Down Expand Up @@ -1863,7 +1869,7 @@
setEncryptionMessageIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/info.svg")));
_ui->encryptionMessage->hide();

auto *const actionSetupE2e = addActionToEncryptionMessage(tr("Set up encryption"), e2EeUiActionSetupEncryptionId);

Check warning on line 1872 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this variable a pointer-to-const. The current type of "actionSetupE2e" is "class QAction *const".

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpYCu9rCdcB_xDMr&open=AZ4cnpYCu9rCdcB_xDMr&pullRequest=10021
connect(actionSetupE2e, &QAction::triggered, this, &AccountSettings::slotE2eEncryptionGenerateKeys);
}

Expand All @@ -1889,7 +1895,7 @@
_encryptionMessageButtons.clear();

const auto actions = _ui->encryptionMessage->actions();
auto *layout = _ui->encryptionMessageButtonsLayout;

Check warning on line 1898 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "layout" of type "class QHBoxLayout *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpYCu9rCdcB_xDMs&open=AZ4cnpYCu9rCdcB_xDMs&pullRequest=10021
int stretchIndex = -1;
for (int i = 0; i < layout->count(); ++i) {
if (layout->itemAt(i)->spacerItem()) {
Expand All @@ -1902,8 +1908,8 @@
stretchIndex = layout->count() - 1;
}

for (QAction *action : actions) {

Check warning on line 1911 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "action" of type "class QAction *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpYCu9rCdcB_xDMt&open=AZ4cnpYCu9rCdcB_xDMt&pullRequest=10021
auto *button = new QPushButton(_ui->encryptionMessage);

Check warning on line 1912 in src/gui/accountsettings.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "button" of type "class QPushButton *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpYCu9rCdcB_xDMu&open=AZ4cnpYCu9rCdcB_xDMu&pullRequest=10021
button->setText(action->text());
button->setIcon(action->icon());
button->setEnabled(action->isEnabled());
Expand Down
11 changes: 10 additions & 1 deletion src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "shellextensionsserver.h"
#elif defined(Q_OS_MACOS)
#include "macOS/fileprovider.h"
#include "macOS/fileprovidersettingscontroller.h"
#include "macOS/findersyncxpc.h"
#include "macOS/findersyncservice.h"
#endif
Expand Down Expand Up @@ -124,7 +125,7 @@
{
ConfigFile configFile;
const auto shouldTryToMigrate = configFile.shouldTryToMigrate();
if (!shouldTryToMigrate) {

Check warning on line 128 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=AZ4cnphou9rCdcB_xDMv&open=AZ4cnphou9rCdcB_xDMv&pullRequest=10021
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 @@ -300,7 +301,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 304 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=AZ4cnphou9rCdcB_xDMx&open=AZ4cnphou9rCdcB_xDMx&pullRequest=10021
const QStringList filesList = QDir(legacyDir).entryList(QDir::Files);
qCDebug(lcApplication) << "Will move the individual files" << filesList;
for (const auto &name : filesList) {
Expand All @@ -312,7 +313,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 316 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=AZ4cnphou9rCdcB_xDMw&open=AZ4cnphou9rCdcB_xDMw&pullRequest=10021
#endif
}
}
Expand All @@ -320,7 +321,7 @@
setupConfigFile();
}

if (_theme->doNotUseProxy()) {

Check warning on line 324 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=AZ4cnphou9rCdcB_xDMy&open=AZ4cnphou9rCdcB_xDMy&pullRequest=10021
ConfigFile().setProxyType(QNetworkProxy::NoProxy);
const auto &allAccounts = AccountManager::instance()->accounts();
for (const auto &accountState : allAccounts) {
Expand Down Expand Up @@ -418,7 +419,7 @@
_gui->setupCloudProviders();
#endif

if (_theme->doNotUseProxy()) {

Check warning on line 422 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=AZ4cnphou9rCdcB_xDMz&open=AZ4cnphou9rCdcB_xDMz&pullRequest=10021
ConfigFile().setProxyType(QNetworkProxy::NoProxy);
const auto &allAccounts = AccountManager::instance()->accounts();
for (const auto &accountState : allAccounts) {
Expand Down Expand Up @@ -497,7 +498,15 @@

#if defined(BUILD_FILE_PROVIDER_MODULE)
Mac::FileProvider::instance();
Mac::FileProvider::instance()->configureXPC();
if (Mac::FileProvider::available()) {
Mac::FileProvider::instance()->configureXPC();
} else {
// macOS 13 Ventura: instantiating the settings controller triggers the
// one-time cleanup that gracefully tears down any pre-existing VFS
// domains. The check (and this branch) can be removed once Ventura is
// no longer supported.
Mac::FileProviderSettingsController::instance();
}
#endif

#if defined(Q_OS_MACOS)
Expand Down Expand Up @@ -600,7 +609,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 612 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=AZ4cnphou9rCdcB_xDM0&open=AZ4cnphou9rCdcB_xDM0&pullRequest=10021
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 All @@ -617,7 +626,7 @@
qCWarning(lcApplication) << accountsListSize << "account(s) migrated:" << prettyNamesList(accounts);
}

void Application::setupConfigFile()

Check warning on line 629 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=AZ4cnphou9rCdcB_xDM1&open=AZ4cnphou9rCdcB_xDM1&pullRequest=10021
{
// Migrate from version <= 2.4
setApplicationName(_theme->appNameGUI());
Expand Down Expand Up @@ -652,11 +661,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 664 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=AZ4cnphou9rCdcB_xDM3&open=AZ4cnphou9rCdcB_xDM3&pullRequest=10021
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 668 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=AZ4cnphou9rCdcB_xDM2&open=AZ4cnphou9rCdcB_xDM2&pullRequest=10021
qCDebug(lcApplication) << "Fallback move of " << name << "also failed";
}
}
Expand All @@ -669,9 +678,9 @@
}
}

AccountManager::AccountsRestoreResult Application::restoreLegacyAccount()

Check warning on line 681 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=AZ4cnphou9rCdcB_xDM4&open=AZ4cnphou9rCdcB_xDM4&pullRequest=10021
{
ConfigFile cfg;

Check warning on line 683 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=AZ4cnphou9rCdcB_xDM5&open=AZ4cnphou9rCdcB_xDM5&pullRequest=10021
const auto tryMigrate = cfg.overrideServerUrl().isEmpty();
auto accountsRestoreResult = AccountManager::AccountsRestoreFailure;
if (accountsRestoreResult = AccountManager::instance()->restore(tryMigrate);
Expand Down Expand Up @@ -748,7 +757,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 760 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=AZ4cnphou9rCdcB_xDM7&open=AZ4cnphou9rCdcB_xDM7&pullRequest=10021

Check warning on line 760 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=AZ4cnphou9rCdcB_xDM6&open=AZ4cnphou9rCdcB_xDM6&pullRequest=10021
{
if (QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Site ||
QNetworkInformation::instance()->reachability() == QNetworkInformation::Reachability::Online) {
Expand Down Expand Up @@ -942,7 +951,7 @@
}
} else if (option == QStringLiteral("--overrideserverurl")) {
if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) {
const auto overrideUrl = it.next();

Check warning on line 954 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=AZ4cnphou9rCdcB_xDM8&open=AZ4cnphou9rCdcB_xDM8&pullRequest=10021
const auto isUrlValid = (overrideUrl.startsWith(QStringLiteral("http://")) || overrideUrl.startsWith(QStringLiteral("https://")))
&& QUrl::fromUserInput(overrideUrl).isValid();
if (!isUrlValid) {
Expand Down Expand Up @@ -1085,7 +1094,7 @@
{
const ConfigFile cfg;
const auto configLanguage = cfg.language();
if (!configLanguage.isEmpty()) {

Check warning on line 1097 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=AZ4cnphou9rCdcB_xDM9&open=AZ4cnphou9rCdcB_xDM9&pullRequest=10021
// always prefer value from configuration
return configLanguage;
}
Expand Down Expand Up @@ -1137,8 +1146,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 1149 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=AZ4cnphou9rCdcB_xDM-&open=AZ4cnphou9rCdcB_xDM-&pullRequest=10021
if (!qtTranslator->load(qtBaseTrFile, trPath)) {

Check warning on line 1150 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=AZ4cnphou9rCdcB_xDNA&open=AZ4cnphou9rCdcB_xDNA&pullRequest=10021
qCDebug(lcApplication()) << "impossible to load Qt translation catalog" << qtBaseTrFile;
}
}
Expand All @@ -1146,7 +1155,7 @@
}
const QString qtkeychainTrFile = QLatin1String("qtkeychain_") + choosenLanguage;
if (!qtkeychainTranslator->load(qtkeychainTrFile, qtTrPath)) {
if (!qtkeychainTranslator->load(qtkeychainTrFile, trPath)) {

Check warning on line 1158 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=AZ4cnphou9rCdcB_xDM_&open=AZ4cnphou9rCdcB_xDM_&pullRequest=10021
qCDebug(lcApplication()) << "impossible to load QtKeychain translation catalog" << qtkeychainTrFile;
}
}
Expand Down Expand Up @@ -1196,7 +1205,7 @@

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

Check warning on line 1208 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=AZ4cnphou9rCdcB_xDNB&open=AZ4cnphou9rCdcB_xDNB&pullRequest=10021
if (!filename.endsWith(virtualFileExt)) {
qWarning(lcApplication) << "Can only handle file ending in .owncloud. Unable to open" << filename;
return;
Expand Down
9 changes: 9 additions & 0 deletions src/gui/macOS/fileprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#pragma once

#include <QObject>

Check failure on line 8 in src/gui/macOS/fileprovider.h

View workflow job for this annotation

GitHub Actions / build

src/gui/macOS/fileprovider.h:8:10 [clang-diagnostic-error]

'QObject' file not found

#include "fileproviderdomainmanager.h"
#include "fileproviderservice.h"
Expand All @@ -28,6 +28,15 @@
static FileProvider *instance();
~FileProvider() override;

/**
* @brief Whether the macOS file provider feature is usable on the current OS.
*
* Returns false on macOS 13 Ventura, where the extension is incompatible
* (see nextcloud/desktop#9927). This runtime check can be removed once
* macOS 13 Ventura is no longer supported.
*/
[[nodiscard]] static bool available();

void configureXPC();
[[nodiscard]] FileProviderXPC *xpc() const;
[[nodiscard]] FileProviderDomainManager *domainManager() const;
Expand Down
11 changes: 11 additions & 0 deletions src/gui/macOS/fileprovider_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "fileprovider.h"

#include <QLoggingCategory>
#include <QOperatingSystemVersion>

#include "libsync/configfile.h"
#include "gui/macOS/fileproviderxpc.h"
Expand Down Expand Up @@ -48,13 +49,23 @@
return _instance;
}

bool FileProvider::available()
{
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSSonoma;
}

FileProvider::~FileProvider()
{
_instance = nullptr;
}

void FileProvider::configureXPC()
{
if (!available()) {
qCInfo(lcMacFileProvider) << "Skipping file provider XPC configuration on unsupported macOS version.";
return;
}

_xpc = std::make_unique<FileProviderXPC>(new FileProviderXPC(this));

if (_xpc) {
Expand Down
37 changes: 34 additions & 3 deletions src/gui/macOS/fileprovidersettingscontroller_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ explicit MacImplementation(FileProviderSettingsController *const parent)

migrateToAppSandbox();
removeOrphanedDomains();
restoreMissingDomains();
Mac::FileProvider::instance()->domainManager()->reconnectAll();
Mac::FileProvider::instance()->configureXPC();

if (Mac::FileProvider::available()) {
restoreMissingDomains();
Mac::FileProvider::instance()->domainManager()->reconnectAll();
Mac::FileProvider::instance()->configureXPC();
} else {
disableFileProviderForAllEnabledAccountsOnUnsupportedOS();
}
};

~MacImplementation() override = default;
Expand Down Expand Up @@ -286,6 +291,32 @@ void removeOrphanedDomains()
qCInfo(lcFileProviderSettingsController) << "Finished removing orphaned domains.";
}

// macOS 13 Ventura cleanup: removes any pre-existing file provider domain
// gracefully (preserving dirty user data) for each account that still has
// VFS enabled. Can be deleted once Ventura is no longer supported.
void disableFileProviderForAllEnabledAccountsOnUnsupportedOS()
{
qCInfo(lcFileProviderSettingsController) << "macOS 13 Ventura: disabling file provider for all enabled accounts.";

const auto accountStates = AccountManager::instance()->accounts();

for (const auto &accountState : accountStates) {
const auto account = accountState->account();

if (!account) {
continue;
}

if (account->fileProviderDomainIdentifier().isEmpty()) {
continue;
}

const auto userIdAtHost = account->userIdAtHostWithPort();
qCInfo(lcFileProviderSettingsController) << "Disabling file provider for account" << userIdAtHost;
(void)setVfsEnabledForAccount(userIdAtHost, false);
}
}

private:
[[maybe_unused]] FileProviderSettingsController *q = nullptr;
};
Expand Down
12 changes: 6 additions & 6 deletions src/gui/wizard/owncloudadvancedsetuppage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include <QDir>

Check failure on line 7 in src/gui/wizard/owncloudadvancedsetuppage.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/wizard/owncloudadvancedsetuppage.cpp:7:10 [clang-diagnostic-error]

'QDir' file not found
#include <QFileDialog>
#include <QUrl>
#include <QTimer>
Expand Down Expand Up @@ -106,7 +106,7 @@
#ifdef Q_OS_WIN
bestAvailableVfsMode() == Vfs::WindowsCfApi
#elif defined(BUILD_FILE_PROVIDER_MODULE)
true
Mac::FileProvider::available()
#else
false
#endif
Expand Down Expand Up @@ -149,14 +149,14 @@
{
WizardCommon::initErrorLabel(_ui.errorLabel);

if (Theme::instance()->disableVirtualFilesSyncFolder()
|| !(Theme::instance()->showVirtualFilesOption()
const auto hideVfsOption = Theme::instance()->disableVirtualFilesSyncFolder()
#ifdef BUILD_FILE_PROVIDER_MODULE
|| true
|| !Mac::FileProvider::available();
#else
&& bestAvailableVfsMode() != Vfs::Off
|| !(Theme::instance()->showVirtualFilesOption() && bestAvailableVfsMode() != Vfs::Off);
#endif
)) {

if (hideVfsOption) {

Check warning on line 159 in src/gui/wizard/owncloudadvancedsetuppage.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpPJu9rCdcB_xDMW&open=AZ4cnpPJu9rCdcB_xDMW&pullRequest=10021
// If the layout were wrapped in a widget, the auto-grouping of the
// radio buttons no longer works and there are surprising margins.
// Just manually hide the button and remove the layout.
Expand Down Expand Up @@ -200,7 +200,7 @@
}

ConfigFile cfgFile;
auto newFolderLimit = cfgFile.newBigFolderSizeLimit();

Check warning on line 203 in src/gui/wizard/owncloudadvancedsetuppage.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this declaration by a structured binding declaration.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpPJu9rCdcB_xDMX&open=AZ4cnpPJu9rCdcB_xDMX&pullRequest=10021
_ui.confCheckBoxSize->setChecked(newFolderLimit.first);
_ui.confSpinBox->setValue(newFolderLimit.second);
_ui.confCheckBoxExternal->setChecked(cfgFile.confirmExternalStorage());
Expand Down Expand Up @@ -305,7 +305,7 @@
const QString locFolder = localFolder();

// check if the local folder exists. If so, and if its not empty, show a warning.
const auto pathValidityCheckResult = FolderMan::instance()->checkPathValidityForNewFolder(locFolder, serverUrl());

Check warning on line 308 in src/gui/wizard/owncloudadvancedsetuppage.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this declaration by a structured binding declaration.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpPJu9rCdcB_xDMY&open=AZ4cnpPJu9rCdcB_xDMY&pullRequest=10021
auto errorStr = pathValidityCheckResult.second;
_localFolderValid = errorStr.isEmpty() || pathValidityCheckResult.first == FolderMan::PathValidityResult::ErrorNonEmptyFolder;

Expand Down Expand Up @@ -423,10 +423,10 @@
if (useVirtualFileSync()) {
const auto availability = Vfs::checkAvailability(localFolder(), bestAvailableVfsMode());
if (!availability) {
auto msg = new QMessageBox(QMessageBox::Warning,
tr("Virtual files are not supported at the selected location"),
availability.error(),
QMessageBox::Ok, this);

Check warning on line 429 in src/gui/wizard/owncloudadvancedsetuppage.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "msg" of type "class QMessageBox *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpPJu9rCdcB_xDMZ&open=AZ4cnpPJu9rCdcB_xDMZ&pullRequest=10021
msg->setAttribute(Qt::WA_DeleteOnClose);
msg->open();
return false;
Expand Down Expand Up @@ -576,7 +576,7 @@
updateStatus();
}

void OwncloudAdvancedSetupPage::slotQuotaRetrievedWithError(QNetworkReply *reply)

Check warning on line 579 in src/gui/wizard/owncloudadvancedsetuppage.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this parameter a pointer-to-const. The current type of "reply" is "class QNetworkReply *".

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

Check warning on line 579 in src/gui/wizard/owncloudadvancedsetuppage.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "reply" of type "class QNetworkReply *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpPJu9rCdcB_xDMb&open=AZ4cnpPJu9rCdcB_xDMb&pullRequest=10021
{
Q_UNUSED(reply)
_rSize = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/wizard/owncloudwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "account.h"

Check failure on line 7 in src/gui/wizard/owncloudwizard.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/wizard/owncloudwizard.cpp:7:10 [clang-diagnostic-error]

'account.h' file not found
#include "config.h"
#include "configfile.h"
#include "theme.h"
Expand Down Expand Up @@ -162,11 +162,11 @@
QList<QSize> pageSizes;
const auto pIds = pageIds();

std::transform(pIds.cbegin(), pIds.cend(), std::back_inserter(pageSizes), [this](int pageId) {
auto p = page(pageId);
p->adjustSize();
return p->sizeHint();
});

Check warning on line 169 in src/gui/wizard/owncloudwizard.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace with the version of "std::ranges::transform" that takes a range.

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

return pageSizes;
}
Expand Down Expand Up @@ -233,7 +233,7 @@
bool OwncloudWizard::useVirtualFileSyncByDefault() const
{
#ifdef BUILD_FILE_PROVIDER_MODULE
return true;
return Mac::FileProvider::available();
#else
return false;
#endif
Expand Down Expand Up @@ -392,7 +392,7 @@

void OwncloudWizard::displayError(const QString &msg, bool retryHTTPonly)
{
switch (static_cast<WizardCommon::Pages>(currentId())) {

Check failure on line 395 in src/gui/wizard/owncloudwizard.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Add a "default" case to this switch statement.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpLgu9rCdcB_xDMS&open=AZ4cnpLgu9rCdcB_xDMS&pullRequest=10021
case WizardCommon::Page_Welcome:
case WizardCommon::Page_Flow2AuthCreds:
#ifdef WITH_WEBENGINE
Expand Down Expand Up @@ -457,7 +457,7 @@
QWizard::changeEvent(e);
}

void OwncloudWizard::hideEvent(QHideEvent *event)

Check warning on line 460 in src/gui/wizard/owncloudwizard.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this method "hideEvent" to simply inherit it.

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

Check warning on line 460 in src/gui/wizard/owncloudwizard.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "event" of type "class QHideEvent *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpLgu9rCdcB_xDMU&open=AZ4cnpLgu9rCdcB_xDMU&pullRequest=10021
{
QWizard::hideEvent(event);
#ifdef Q_OS_MACOS
Expand All @@ -466,7 +466,7 @@
#endif
}

void OwncloudWizard::closeEvent(QCloseEvent *event)

Check warning on line 469 in src/gui/wizard/owncloudwizard.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "event" of type "class QCloseEvent *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4cnpLgu9rCdcB_xDMV&open=AZ4cnpLgu9rCdcB_xDMV&pullRequest=10021
{
emit wizardClosed();
QWizard::closeEvent(event);
Expand Down
Loading