Skip to content
Draft
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
10 changes: 10 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ configure_file(${CMAKE_SOURCE_DIR}/theme.qrc.in ${CMAKE_SOURCE_DIR}/theme.qrc)
set(theme_dir ${CMAKE_SOURCE_DIR}/theme)

set(client_UI_SRCS
advancedsettings.ui
accountsettings.ui
conflictdialog.ui
invalidfilenamedialog.ui
Expand All @@ -32,6 +33,7 @@ set(client_UI_SRCS
folderwizardsourcepage.ui
folderwizardtargetpage.ui
generalsettings.ui
infosettings.ui
legalnotice.ui
ignorelisteditor.ui
ignorelisttablewidget.ui
Expand All @@ -58,6 +60,8 @@ qt_add_resources(client_UI_SRCS ../../resources.qrc ${CMAKE_SOURCE_DIR}/theme.qr
set(client_SRCS
accountmanager.h
accountmanager.cpp
advancedsettings.h
advancedsettings.cpp
accountsettings.h
accountsettings.cpp
accountsetupfromcommandlinejob.h
Expand Down Expand Up @@ -104,6 +108,8 @@ set(client_SRCS
folderwizard.cpp
generalsettings.h
generalsettings.cpp
infosettings.h
infosettings.cpp
legalnotice.h
legalnotice.cpp
ignorelisteditor.h
Expand Down Expand Up @@ -136,6 +142,10 @@ set(client_SRCS
selectivesyncdialog.cpp
settingsdialog.h
settingsdialog.cpp
settingspanelstyle.h
settingspanelstyle.cpp
settingsswitch.h
settingsswitch.cpp
sharemanager.h
sharemanager.cpp
profilepagewidget.h
Expand Down
83 changes: 64 additions & 19 deletions src/gui/accountsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <cmath>

#include <QDesktopServices>
#include <QDialog>
#include <QDialogButtonBox>
#include <QDir>
#include <QListWidgetItem>
Expand All @@ -57,6 +58,7 @@
#include <QPushButton>
#include <QStyle>
#include <QFileDialog>
#include <QFrame>

using namespace Qt::StringLiterals;

Expand All @@ -65,7 +67,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 70 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=AZ4mqr7A-Svkp3hBDNHO&open=AZ4mqr7A-Svkp3hBDNHO&pullRequest=10031
#endif

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

#include "account.h"

Check warning on line 83 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=AZ4mqr7A-Svkp3hBDNHP&open=AZ4mqr7A-Svkp3hBDNHP&pullRequest=10031

namespace {
constexpr auto propertyFolder = "folder";
Expand All @@ -87,7 +89,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 92 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=AZ4mqr7A-Svkp3hBDNHR&open=AZ4mqr7A-Svkp3hBDNHR&pullRequest=10031
}

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

Check warning on line 184 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=AZ4mqr7A-Svkp3hBDNHQ&open=AZ4mqr7A-Svkp3hBDNHQ&pullRequest=10031

Check failure on line 184 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=AZ4mqr7A-Svkp3hBDNHS&open=AZ4mqr7A-Svkp3hBDNHS&pullRequest=10031
, _accountState(accountState)
, _userInfo(accountState, false, true)
{
_ui->setupUi(this);

_encryptionPanel = new QFrame(this);
_encryptionPanel->setObjectName(QLatin1String("encryptionPanel"));
_encryptionPanel->setFrameShape(QFrame::NoFrame);
_encryptionPanel->setAttribute(Qt::WA_StyledBackground, true);
auto *encryptionPanelLayout = new QVBoxLayout(_encryptionPanel);

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

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:194:11 [cppcoreguidelines-init-variables]

variable 'encryptionPanelLayout' is not initialized
encryptionPanelLayout->setContentsMargins(0, 0, 0, 0);
encryptionPanelLayout->setSpacing(0);
_ui->accountStatusLayout->removeWidget(_ui->encryptionMessage);
encryptionPanelLayout->addWidget(_ui->encryptionMessage);

auto *connectionSettingsButton = new QPushButton(tr("Connection settings"), _ui->accountStatus);

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

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:200:11 [cppcoreguidelines-init-variables]

variable 'connectionSettingsButton' is not initialized

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

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

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4mqr7A-Svkp3hBDNHU&open=AZ4mqr7A-Svkp3hBDNHU&pullRequest=10031
connectionSettingsButton->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
_ui->gridLayout_2->addWidget(connectionSettingsButton, 0, 2, Qt::AlignRight | Qt::AlignVCenter);
connect(connectionSettingsButton, &QPushButton::clicked, this, &AccountSettings::showConnectionSettingsDialog);

_ui->verticalLayout_2->removeWidget(_ui->accountStatusPanel);
_ui->verticalLayout_2->removeWidget(_ui->fileProviderPanel);
_ui->verticalLayout_2->removeWidget(_ui->syncFoldersPanel);
_ui->verticalLayout_2->removeWidget(_ui->connectionSettingsPanel);
_ui->connectionSettingsPanel->hide();
_ui->verticalLayout_2->insertWidget(0, _ui->fileProviderPanel);
_ui->verticalLayout_2->insertWidget(1, _ui->syncFoldersPanel);
_ui->verticalLayout_2->insertWidget(2, _encryptionPanel);
_ui->verticalLayout_2->insertWidget(3, _ui->accountStatusPanel);

_model->setAccountState(_accountState);
_model->setParent(this);
const auto delegate = new FolderStatusDelegate;
delegate->setParent(this);

setStyleSheet("QWidget#syncFoldersPanelContents, QWidget#connectionSettingsPanelContents, QWidget#fileProviderPanelContents { background: palette(" BACKGROUND_PALETTE "); }"_L1);
setStyleSheet("QWidget#syncFoldersPanelContents, QWidget#fileProviderPanelContents { background: palette(" BACKGROUND_PALETTE "); }"_L1);
_ui->syncFoldersPanelContents->setAutoFillBackground(true);
_ui->syncFoldersPanelContents->setAttribute(Qt::WA_StyledBackground, true);
_ui->syncFoldersPanelContents->setContentsMargins(0, 0, 0, 0);
_ui->fileProviderPanelContents->setAutoFillBackground(true);
_ui->fileProviderPanelContents->setAttribute(Qt::WA_StyledBackground, true);
_ui->fileProviderPanelContents->setContentsMargins(0, 0, 0, 0);
_ui->connectionSettingsPanelContents->setAutoFillBackground(true);
_ui->connectionSettingsPanelContents->setAttribute(Qt::WA_StyledBackground, true);
_ui->connectionSettingsPanelContents->setContentsMargins(0, 0, 0, 0);

// Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching)
connect(this, &AccountSettings::styleChanged, delegate, &FolderStatusDelegate::slotStyleChanged);

Expand Down Expand Up @@ -241,17 +264,6 @@
_ui->fileProviderPanel->setVisible(false);
#endif

const auto connectionSettingsPanelContents = _ui->connectionSettingsPanelContents;
const auto connectionSettingsLayout = new QVBoxLayout(connectionSettingsPanelContents);
const auto networkSettings = new NetworkSettings(_accountState->account(), connectionSettingsPanelContents);
if (const auto networkSettingsLayout = networkSettings->layout()) {
networkSettingsLayout->setContentsMargins(0, 0, 0, 0);
}
connectionSettingsLayout->setContentsMargins(0, 0, 0, 0);
connectionSettingsLayout->setSpacing(0);
connectionSettingsLayout->addWidget(networkSettings, 1);
connectionSettingsPanelContents->setLayout(connectionSettingsLayout);

const auto mouseCursorChanger = new MouseCursorChanger(this);
mouseCursorChanger->folderList = _ui->_folderList;
mouseCursorChanger->model = _model;
Expand Down Expand Up @@ -318,6 +330,7 @@
_ui->encryptionMessageLabel->setOpenExternalLinks(true);
_ui->encryptionMessageButtonsLayout->addStretch();
setEncryptionMessageIcon({});
setEncryptionPanelVisible(_ui->encryptionMessage->isVisible());

_ui->connectLabel->setText(tr("No account configured."));

Expand Down Expand Up @@ -355,7 +368,7 @@

_ui->encryptionMessageLabel->setText(tr("Encryption is set-up. Remember to <b>Encrypt</b> a folder to end-to-end encrypt any new files added to it."));
setEncryptionMessageIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/lock.svg")));
_ui->encryptionMessage->show();
setEncryptionPanelVisible(true);
}

void AccountSettings::slotE2eEncryptionGenerateKeys()
Expand Down Expand Up @@ -489,7 +502,7 @@
Q_ASSERT(folder);

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

Check warning on line 505 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=AZ4mqr7A-Svkp3hBDNHW&open=AZ4mqr7A-Svkp3hBDNHW&pullRequest=10031
const auto fileId = folderInfo->_fileId;
const auto encryptFolder = [this, fileId, path, folderAlias] {
const auto folder = FolderMan::instance()->folder(folderAlias);
Expand All @@ -503,7 +516,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 519 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=AZ4mqr7A-Svkp3hBDNHY&open=AZ4mqr7A-Svkp3hBDNHY&pullRequest=10031
job->setParent(this);
job->setProperty(propertyFolder, QVariant::fromValue(folder));
job->setProperty(propertyPath, QVariant::fromValue(path));
Expand Down Expand Up @@ -1286,6 +1299,30 @@
_ui->accountStatus->setVisible(!message.isEmpty());
}

void AccountSettings::showConnectionSettingsDialog()

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

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:1302:23 [readability-convert-member-functions-to-static]

method 'showConnectionSettingsDialog' can be made static
{
auto *dialog = new QDialog(this);

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

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:1304:11 [cppcoreguidelines-init-variables]

variable 'dialog' is not initialized

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "dialog" of type "class QDialog *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4mqr7A-Svkp3hBDNHb&open=AZ4mqr7A-Svkp3hBDNHb&pullRequest=10031
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowTitle(tr("Connection settings"));

auto *layout = new QVBoxLayout(dialog);

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

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:1308:11 [cppcoreguidelines-init-variables]

variable 'layout' is not initialized
layout->setContentsMargins(12, 12, 12, 12);
layout->setSpacing(12);

auto *networkSettings = new NetworkSettings(_accountState->account(), dialog);

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

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:1312:11 [cppcoreguidelines-init-variables]

variable 'networkSettings' is not initialized
if (auto *networkSettingsLayout = networkSettings->layout()) {

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "networkSettingsLayout" of type "class QLayout *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4mqr7A-Svkp3hBDNHe&open=AZ4mqr7A-Svkp3hBDNHe&pullRequest=10031
networkSettingsLayout->setContentsMargins(0, 0, 0, 0);
}
layout->addWidget(networkSettings);

auto *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, dialog);

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

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:1318:11 [cppcoreguidelines-init-variables]

variable 'buttonBox' is not initialized

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unmodified variable "buttonBox" of type "class QDialogButtonBox *" should be const-qualified.

See more on https://sonarcloud.io/project/issues?id=nextcloud_desktop&issues=AZ4mqr7A-Svkp3hBDNHf&open=AZ4mqr7A-Svkp3hBDNHf&pullRequest=10031
connect(buttonBox, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
layout->addWidget(buttonBox);

dialog->resize(networkSettings->sizeHint());
dialog->open();
}

void AccountSettings::slotEnableCurrentFolder(bool terminate)
{
const auto alias = selectedFolderAlias();
Expand Down Expand Up @@ -1504,7 +1541,7 @@
<< "Client Side Encryption" << accountsState()->account()->capabilities().clientSideEncryptionAvailable();

if (_accountState->account()->capabilities().clientSideEncryptionAvailable()) {
_ui->encryptionMessage->show();
setEncryptionPanelVisible(true);
}
}

Expand Down Expand Up @@ -1867,12 +1904,20 @@
#endif
_ui->encryptionMessageLabel->setText(encryptionMessage);
setEncryptionMessageIcon(Theme::createColorAwareIcon(QStringLiteral(":/client/theme/info.svg")));
_ui->encryptionMessage->hide();
setEncryptionPanelVisible(false);

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

Check warning on line 1909 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=AZ4mqr7A-Svkp3hBDNHk&open=AZ4mqr7A-Svkp3hBDNHk&pullRequest=10031
connect(actionSetupE2e, &QAction::triggered, this, &AccountSettings::slotE2eEncryptionGenerateKeys);
}

void AccountSettings::setEncryptionPanelVisible(bool visible)
{
_ui->encryptionMessage->setVisible(visible);
if (_encryptionPanel) {

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

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.cpp:1916:9 [readability-implicit-bool-conversion]

implicit conversion 'QFrame *' -> bool
_encryptionPanel->setVisible(visible);
}
}

void AccountSettings::setEncryptionMessageIcon(const QIcon &icon)
{
if (icon.isNull()) {
Expand Down
4 changes: 4 additions & 0 deletions src/gui/accountsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef ACCOUNTSETTINGS_H
#define ACCOUNTSETTINGS_H

#include <QWidget>

Check failure on line 10 in src/gui/accountsettings.h

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.h:10:10 [clang-diagnostic-error]

'QWidget' file not found
#include <QUrl>
#include <QPointer>
#include <QHash>
Expand All @@ -29,6 +29,7 @@
class QLabel;
class QPushButton;
class QIcon;
class QFrame;

Check warning on line 32 in src/gui/accountsettings.h

View workflow job for this annotation

GitHub Actions / build

src/gui/accountsettings.h:32:7 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'QFrame' is non-const and globally accessible, consider making it const

namespace OCC {

Expand Down Expand Up @@ -119,7 +120,7 @@
const QVector<int> &roles);
void slotPossiblyUnblacklistE2EeFoldersAndRestartSync();

void slotE2eEncryptionCertificateNeedMigration();

Check warning on line 123 in src/gui/accountsettings.h

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=AZ4mqr0c-Svkp3hBDNHM&open=AZ4mqr0c-Svkp3hBDNHM&pullRequest=10031

private slots:
void updateBlackListAndScheduleFolderSync(const QStringList &blackList, OCC::Folder *folder, const QStringList &foldersToRemoveFromBlacklist) const;
Expand All @@ -127,16 +128,18 @@

private slots:
void displayMnemonic(const QString &mnemonic);
void forgetEncryptionOnDeviceForAccount(const OCC::AccountPtr &account) const;

Check warning on line 131 in src/gui/accountsettings.h

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=AZ4mqr0c-Svkp3hBDNHN&open=AZ4mqr0c-Svkp3hBDNHN&pullRequest=10031
void migrateCertificateForAccount(const OCC::AccountPtr &account);
void showConnectionLabel(const QString &message, QStringList errors = QStringList());
void showConnectionSettingsDialog();
void openIgnoredFilesDialog(const QString & absFolderPath);
void customizeStyle();

void setupE2eEncryption();
void forgetE2eEncryption();
void checkClientSideEncryptionState();
void removeActionFromEncryptionMessage(const QString &actionId);
void setEncryptionPanelVisible(bool visible);

private:
bool event(QEvent *) override;
Expand All @@ -160,6 +163,7 @@
QAction *_addAccountAction = nullptr;

bool _menuShown = false;
QFrame *_encryptionPanel = nullptr;

QHash<QString, QMetaObject::Connection> _folderConnections;
QHash<QAction *, QPushButton *> _encryptionMessageButtons;
Expand Down
Loading
Loading