From 63f15de5bb42cd45550703660cb1e2896e602cc1 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 27 Jun 2024 16:57:16 +0800 Subject: [PATCH 01/49] Add connection settings tab to account settings Signed-off-by: Claudio Cambra --- src/gui/accountsettings.ui | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/gui/accountsettings.ui b/src/gui/accountsettings.ui index bc1594e8f3189..3e6323d26eb5c 100644 --- a/src/gui/accountsettings.ui +++ b/src/gui/accountsettings.ui @@ -259,8 +259,11 @@ + + QTabWidget::Rounded + - 1 + 0 @@ -308,6 +311,11 @@ Virtual file sync + + + Connection settings + + From 88d20649d8d7b9d28f505071086aa0ab138dd799 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 27 Jun 2024 16:57:51 +0800 Subject: [PATCH 02/49] Present network settings component within connection settings tab in account settings Signed-off-by: Claudio Cambra --- src/gui/accountsettings.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 2b581e3606cf5..d51601392344d 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -42,6 +42,7 @@ #include "syncresult.h" #include "ignorelisttablewidget.h" #include "wizard/owncloudwizard.h" +#include "networksettings.h" #include "ui_mnemonicdialog.h" #include @@ -206,14 +207,17 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) const auto fpSettingsWidget = fpSettingsController->settingsViewWidget(fpAccountUserIdAtHost, fileProviderTab); fpSettingsLayout->addWidget(fpSettingsWidget); fileProviderTab->setLayout(fpSettingsLayout); - } else { - disguiseTabWidget(); } #else - disguiseTabWidget(); _ui->tabWidget->setCurrentIndex(0); #endif + const auto connectionSettingsTab = _ui->connectionSettingsTab; + const auto connectionSettingsLayout = new QVBoxLayout(connectionSettingsTab); + const auto networkSettings = new NetworkSettings(connectionSettingsTab); + connectionSettingsLayout->addWidget(networkSettings); + connectionSettingsTab->setLayout(connectionSettingsLayout); + const auto mouseCursorChanger = new MouseCursorChanger(this); mouseCursorChanger->folderList = _ui->_folderList; mouseCursorChanger->model = _model; From ae1b9bda5de2141bdd0851c4842bd6e4cb8a4408 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:46:11 +0800 Subject: [PATCH 03/49] Add AccountNetworkProxySetting enum to account Signed-off-by: Claudio Cambra --- src/libsync/account.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libsync/account.h b/src/libsync/account.h index ea371c8ede21e..79096cd80edd7 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -92,6 +92,14 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(bool askUserForMnemonic READ askUserForMnemonic WRITE setAskUserForMnemonic NOTIFY askUserForMnemonicChanged) public: + enum class AccountNetworkProxySetting { + GlobalProxy = 0, + NoProxy, + ManualProxy, + AutoProxy + }; + Q_ENUM(AccountNetworkProxySetting) + static AccountPtr create(); ~Account() override; From 15bc9a48921942bdb05eec91ecfc73406434a56f Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:46:36 +0800 Subject: [PATCH 04/49] Add AccountNetworkTransferLimitSetting enum to account Signed-off-by: Claudio Cambra --- src/libsync/account.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libsync/account.h b/src/libsync/account.h index 79096cd80edd7..55ff4fc7baf54 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -100,6 +100,14 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject }; Q_ENUM(AccountNetworkProxySetting) + enum class AccountNetworkTransferLimitSetting { + GlobalLimit = 0, + NoLimit, + ManualLimit, + AutoLimit + }; + Q_ENUM(AccountNetworkTransferLimitSetting) + static AccountPtr create(); ~Account() override; From 2501cdf44d79df5af2cdb78f0a79cc69ce602d9b Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:51:11 +0800 Subject: [PATCH 05/49] Add network proxy setting property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 14 ++++++++++++++ src/libsync/account.h | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 1a05650edad37..9eb87f8fe15a9 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1088,5 +1088,19 @@ void Account::updateDesktopEnterpriseChannel() } } +Account::AccountNetworkProxySetting Account::networkProxySetting() const +{ + return _networkProxySetting; +} + +void Account::setNetworkProxySetting(const AccountNetworkProxySetting setting) +{ + if (setting == _networkProxySetting) { + return; + } + + _networkProxySetting = setting; + emit networkProxySettingChanged(); +} } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index 55ff4fc7baf54..4864f8075ce1b 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -90,6 +90,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(QUrl url MEMBER _url) Q_PROPERTY(bool e2eEncryptionKeysGenerationAllowed MEMBER _e2eEncryptionKeysGenerationAllowed) Q_PROPERTY(bool askUserForMnemonic READ askUserForMnemonic WRITE setAskUserForMnemonic NOTIFY askUserForMnemonicChanged) + Q_PROPERTY(AccountNetworkProxySetting networkProxySetting READ networkProxySetting WRITE setNetworkProxySetting NOTIFY networkProxySettingChanged) public: enum class AccountNetworkProxySetting { @@ -354,6 +355,10 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject void updateServerSubcription(); void updateDesktopEnterpriseChannel(); + // Network-related settings + [[nodiscard]] AccountNetworkProxySetting networkProxySetting() const; + void setNetworkProxySetting(AccountNetworkProxySetting networkProxySetting); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -398,6 +403,8 @@ public slots: void lockFileSuccess(); void lockFileError(const QString&); + void networkProxySettingChanged(); + protected Q_SLOTS: void slotCredentialsFetched(); void slotCredentialsAsked(); @@ -473,6 +480,7 @@ private slots: QHash> _lockStatusChangeInprogress; + AccountNetworkProxySetting _networkProxySetting = AccountNetworkProxySetting::GlobalProxy; /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From 73dd00042917abedc1d360b69919ea6872549abf Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:52:31 +0800 Subject: [PATCH 06/49] Add proxy type property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 9eb87f8fe15a9..ad90dd03c399d 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1103,4 +1103,19 @@ void Account::setNetworkProxySetting(const AccountNetworkProxySetting setting) emit networkProxySettingChanged(); } +QNetworkProxy::ProxyType Account::proxyType() const +{ + return _proxyType; +} + +void Account::setProxyType(QNetworkProxy::ProxyType proxyType) +{ + if (_proxyType == proxyType) { + return; + } + + _proxyType = proxyType; + emit proxyTypeChanged(); +} + } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index 4864f8075ce1b..2b8d0ecc0d8e5 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -91,6 +92,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(bool e2eEncryptionKeysGenerationAllowed MEMBER _e2eEncryptionKeysGenerationAllowed) Q_PROPERTY(bool askUserForMnemonic READ askUserForMnemonic WRITE setAskUserForMnemonic NOTIFY askUserForMnemonicChanged) Q_PROPERTY(AccountNetworkProxySetting networkProxySetting READ networkProxySetting WRITE setNetworkProxySetting NOTIFY networkProxySettingChanged) + Q_PROPERTY(QNetworkProxy::ProxyType proxyType READ proxyType WRITE setProxyType NOTIFY proxyTypeChanged) public: enum class AccountNetworkProxySetting { @@ -359,6 +361,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] AccountNetworkProxySetting networkProxySetting() const; void setNetworkProxySetting(AccountNetworkProxySetting networkProxySetting); + [[nodiscard]] QNetworkProxy::ProxyType proxyType() const; + void setProxyType(QNetworkProxy::ProxyType proxyType); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -404,6 +409,7 @@ public slots: void lockFileError(const QString&); void networkProxySettingChanged(); + void proxyTypeChanged(); protected Q_SLOTS: void slotCredentialsFetched(); @@ -481,6 +487,7 @@ private slots: QHash> _lockStatusChangeInprogress; AccountNetworkProxySetting _networkProxySetting = AccountNetworkProxySetting::GlobalProxy; + QNetworkProxy::ProxyType _proxyType = QNetworkProxy::NoProxy; /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From a4553f5929bf9abe6ebf4ac5fd25045f62facf08 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:53:01 +0800 Subject: [PATCH 07/49] Add proxy host name property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index ad90dd03c399d..d559b158a5cd2 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1118,4 +1118,19 @@ void Account::setProxyType(QNetworkProxy::ProxyType proxyType) emit proxyTypeChanged(); } +QString Account::proxyHostName() const +{ + return _proxyHostName; +} + +void Account::setProxyHostName(const QString &hostName) +{ + if (_proxyHostName == hostName) { + return; + } + + _proxyHostName = hostName; + emit proxyHostNameChanged(); +} + } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index 2b8d0ecc0d8e5..f50f045373a41 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -93,6 +93,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(bool askUserForMnemonic READ askUserForMnemonic WRITE setAskUserForMnemonic NOTIFY askUserForMnemonicChanged) Q_PROPERTY(AccountNetworkProxySetting networkProxySetting READ networkProxySetting WRITE setNetworkProxySetting NOTIFY networkProxySettingChanged) Q_PROPERTY(QNetworkProxy::ProxyType proxyType READ proxyType WRITE setProxyType NOTIFY proxyTypeChanged) + Q_PROPERTY(QString proxyHostName READ proxyHostName WRITE setProxyHostName NOTIFY proxyHostNameChanged) public: enum class AccountNetworkProxySetting { @@ -364,6 +365,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] QNetworkProxy::ProxyType proxyType() const; void setProxyType(QNetworkProxy::ProxyType proxyType); + [[nodiscard]] QString proxyHostName() const; + void setProxyHostName(const QString &host); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -410,6 +414,7 @@ public slots: void networkProxySettingChanged(); void proxyTypeChanged(); + void proxyHostNameChanged(); protected Q_SLOTS: void slotCredentialsFetched(); @@ -488,6 +493,7 @@ private slots: AccountNetworkProxySetting _networkProxySetting = AccountNetworkProxySetting::GlobalProxy; QNetworkProxy::ProxyType _proxyType = QNetworkProxy::NoProxy; + QString _proxyHostName; /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From 8c6a181ee38215303ec29831e0d5336e8577eb21 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:54:06 +0800 Subject: [PATCH 08/49] Add proxy port property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index d559b158a5cd2..1d3030971dce8 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1133,4 +1133,19 @@ void Account::setProxyHostName(const QString &hostName) emit proxyHostNameChanged(); } +int Account::proxyPort() const +{ + return _proxyPort; +} + +void Account::setProxyPort(const int port) +{ + if (_proxyPort == port) { + return; + } + + _proxyPort = port; + emit proxyPortChanged(); +} + } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index f50f045373a41..8677718400f4c 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -94,6 +94,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(AccountNetworkProxySetting networkProxySetting READ networkProxySetting WRITE setNetworkProxySetting NOTIFY networkProxySettingChanged) Q_PROPERTY(QNetworkProxy::ProxyType proxyType READ proxyType WRITE setProxyType NOTIFY proxyTypeChanged) Q_PROPERTY(QString proxyHostName READ proxyHostName WRITE setProxyHostName NOTIFY proxyHostNameChanged) + Q_PROPERTY(int proxyPort READ proxyPort WRITE setProxyPort NOTIFY proxyPortChanged) public: enum class AccountNetworkProxySetting { @@ -368,6 +369,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] QString proxyHostName() const; void setProxyHostName(const QString &host); + [[nodiscard]] int proxyPort() const; + void setProxyPort(int port); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -415,6 +419,7 @@ public slots: void networkProxySettingChanged(); void proxyTypeChanged(); void proxyHostNameChanged(); + void proxyPortChanged(); protected Q_SLOTS: void slotCredentialsFetched(); @@ -494,6 +499,7 @@ private slots: AccountNetworkProxySetting _networkProxySetting = AccountNetworkProxySetting::GlobalProxy; QNetworkProxy::ProxyType _proxyType = QNetworkProxy::NoProxy; QString _proxyHostName; + int _proxyPort = 0; /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From daed4c7b7f40ecd4cf215413488bb8b447985a69 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:54:27 +0800 Subject: [PATCH 09/49] Add proxy needs auth property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 1d3030971dce8..d522eb813dafa 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1148,4 +1148,19 @@ void Account::setProxyPort(const int port) emit proxyPortChanged(); } +bool Account::proxyNeedsAuth() const +{ + return _proxyNeedsAuth; +} + +void Account::setProxyNeedsAuth(const bool needsAuth) +{ + if (_proxyNeedsAuth == needsAuth) { + return; + } + + _proxyNeedsAuth = needsAuth; + emit proxyNeedsAuthChanged(); +} + } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index 8677718400f4c..b84e81467f5ed 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -95,6 +95,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(QNetworkProxy::ProxyType proxyType READ proxyType WRITE setProxyType NOTIFY proxyTypeChanged) Q_PROPERTY(QString proxyHostName READ proxyHostName WRITE setProxyHostName NOTIFY proxyHostNameChanged) Q_PROPERTY(int proxyPort READ proxyPort WRITE setProxyPort NOTIFY proxyPortChanged) + Q_PROPERTY(bool proxyNeedsAuth READ proxyNeedsAuth WRITE setProxyNeedsAuth NOTIFY proxyNeedsAuthChanged) public: enum class AccountNetworkProxySetting { @@ -372,6 +373,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] int proxyPort() const; void setProxyPort(int port); + [[nodiscard]] bool proxyNeedsAuth() const; + void setProxyNeedsAuth(bool needsAuth); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -420,6 +424,7 @@ public slots: void proxyTypeChanged(); void proxyHostNameChanged(); void proxyPortChanged(); + void proxyNeedsAuthChanged(); protected Q_SLOTS: void slotCredentialsFetched(); @@ -500,6 +505,7 @@ private slots: QNetworkProxy::ProxyType _proxyType = QNetworkProxy::NoProxy; QString _proxyHostName; int _proxyPort = 0; + bool _proxyNeedsAuth = false; /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From c0cd839a29a1a87d32e40d07ed906104abb88145 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:54:59 +0800 Subject: [PATCH 10/49] Add proxy user property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index d522eb813dafa..bd1aff68c2597 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1163,4 +1163,19 @@ void Account::setProxyNeedsAuth(const bool needsAuth) emit proxyNeedsAuthChanged(); } +QString Account::proxyUser() const +{ + return _proxyUser; +} + +void Account::setProxyUser(const QString &user) +{ + if (_proxyUser == user) { + return; + } + + _proxyUser = user; + emit proxyUserChanged(); +} + } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index b84e81467f5ed..82d54c4e25961 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -96,6 +96,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(QString proxyHostName READ proxyHostName WRITE setProxyHostName NOTIFY proxyHostNameChanged) Q_PROPERTY(int proxyPort READ proxyPort WRITE setProxyPort NOTIFY proxyPortChanged) Q_PROPERTY(bool proxyNeedsAuth READ proxyNeedsAuth WRITE setProxyNeedsAuth NOTIFY proxyNeedsAuthChanged) + Q_PROPERTY(QString proxyUser READ proxyUser WRITE setProxyUser NOTIFY proxyUserChanged) public: enum class AccountNetworkProxySetting { @@ -376,6 +377,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] bool proxyNeedsAuth() const; void setProxyNeedsAuth(bool needsAuth); + [[nodiscard]] QString proxyUser() const; + void setProxyUser(const QString &user); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -425,6 +429,7 @@ public slots: void proxyHostNameChanged(); void proxyPortChanged(); void proxyNeedsAuthChanged(); + void proxyUserChanged(); protected Q_SLOTS: void slotCredentialsFetched(); @@ -506,6 +511,7 @@ private slots: QString _proxyHostName; int _proxyPort = 0; bool _proxyNeedsAuth = false; + QString _proxyUser; /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From 56b8fcf0617523ac628c36c68b02b7791cd05a9b Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:55:41 +0800 Subject: [PATCH 11/49] Add proxy password property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index bd1aff68c2597..e13d0f0d38019 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1178,4 +1178,19 @@ void Account::setProxyUser(const QString &user) emit proxyUserChanged(); } +QString Account::proxyPassword() const +{ + return _proxyPassword; +} + +void Account::setProxyPassword(const QString &password) +{ + if (_proxyPassword == password) { + return; + } + + _proxyPassword = password; + emit proxyPasswordChanged(); +} + } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index 82d54c4e25961..fa5c70fd4b52b 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -97,6 +97,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(int proxyPort READ proxyPort WRITE setProxyPort NOTIFY proxyPortChanged) Q_PROPERTY(bool proxyNeedsAuth READ proxyNeedsAuth WRITE setProxyNeedsAuth NOTIFY proxyNeedsAuthChanged) Q_PROPERTY(QString proxyUser READ proxyUser WRITE setProxyUser NOTIFY proxyUserChanged) + Q_PROPERTY(QString proxyPassword READ proxyPassword WRITE setProxyPassword NOTIFY proxyPasswordChanged) public: enum class AccountNetworkProxySetting { @@ -380,6 +381,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] QString proxyUser() const; void setProxyUser(const QString &user); + [[nodiscard]] QString proxyPassword() const; + void setProxyPassword(const QString &password); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -430,6 +434,7 @@ public slots: void proxyPortChanged(); void proxyNeedsAuthChanged(); void proxyUserChanged(); + void proxyPasswordChanged(); protected Q_SLOTS: void slotCredentialsFetched(); @@ -512,6 +517,7 @@ private slots: int _proxyPort = 0; bool _proxyNeedsAuth = false; QString _proxyUser; + QString _proxyPassword; /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From 7a9fd727c47c040d52a47ae93bca8735630cc6ff Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:56:21 +0800 Subject: [PATCH 12/49] Add upload limit setting property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index e13d0f0d38019..64743269a7457 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1193,4 +1193,19 @@ void Account::setProxyPassword(const QString &password) emit proxyPasswordChanged(); } +Account::AccountNetworkTransferLimitSetting Account::uploadLimitSetting() const +{ + return _uploadLimitSetting; +} + +void Account::setUploadLimitSetting(const AccountNetworkTransferLimitSetting setting) +{ + if (setting == _uploadLimitSetting) { + return; + } + + _uploadLimitSetting = setting; + emit uploadLimitSettingChanged(); +} + } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index fa5c70fd4b52b..3dae27316507a 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -98,6 +98,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(bool proxyNeedsAuth READ proxyNeedsAuth WRITE setProxyNeedsAuth NOTIFY proxyNeedsAuthChanged) Q_PROPERTY(QString proxyUser READ proxyUser WRITE setProxyUser NOTIFY proxyUserChanged) Q_PROPERTY(QString proxyPassword READ proxyPassword WRITE setProxyPassword NOTIFY proxyPasswordChanged) + Q_PROPERTY(AccountNetworkTransferLimitSetting uploadLimitSetting READ uploadLimitSetting WRITE setUploadLimitSetting NOTIFY uploadLimitSettingChanged) public: enum class AccountNetworkProxySetting { @@ -384,6 +385,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] QString proxyPassword() const; void setProxyPassword(const QString &password); + [[nodiscard]] AccountNetworkTransferLimitSetting uploadLimitSetting() const; + void setUploadLimitSetting(AccountNetworkTransferLimitSetting setting); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -435,6 +439,7 @@ public slots: void proxyNeedsAuthChanged(); void proxyUserChanged(); void proxyPasswordChanged(); + void uploadLimitSettingChanged(); protected Q_SLOTS: void slotCredentialsFetched(); @@ -518,6 +523,7 @@ private slots: bool _proxyNeedsAuth = false; QString _proxyUser; QString _proxyPassword; + AccountNetworkTransferLimitSetting _uploadLimitSetting = AccountNetworkTransferLimitSetting::GlobalLimit; /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From f96fe64bdeb597d854aa35db09a9e11202e7fa45 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:56:45 +0800 Subject: [PATCH 13/49] Add download limit setting property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 64743269a7457..87dfc966795a4 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1208,4 +1208,19 @@ void Account::setUploadLimitSetting(const AccountNetworkTransferLimitSetting set emit uploadLimitSettingChanged(); } +Account::AccountNetworkTransferLimitSetting Account::downloadLimitSetting() const +{ + return _downloadLimitSetting; +} + +void Account::setDownloadLimitSetting(const AccountNetworkTransferLimitSetting setting) +{ + if (setting == _downloadLimitSetting) { + return; + } + + _downloadLimitSetting = setting; + emit downloadLimitSettingChanged(); +} + } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index 3dae27316507a..fdf4d124971cb 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -99,6 +99,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(QString proxyUser READ proxyUser WRITE setProxyUser NOTIFY proxyUserChanged) Q_PROPERTY(QString proxyPassword READ proxyPassword WRITE setProxyPassword NOTIFY proxyPasswordChanged) Q_PROPERTY(AccountNetworkTransferLimitSetting uploadLimitSetting READ uploadLimitSetting WRITE setUploadLimitSetting NOTIFY uploadLimitSettingChanged) + Q_PROPERTY(AccountNetworkTransferLimitSetting downloadLimitSetting READ downloadLimitSetting WRITE setDownloadLimitSetting NOTIFY downloadLimitSettingChanged) public: enum class AccountNetworkProxySetting { @@ -388,6 +389,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] AccountNetworkTransferLimitSetting uploadLimitSetting() const; void setUploadLimitSetting(AccountNetworkTransferLimitSetting setting); + [[nodiscard]] AccountNetworkTransferLimitSetting downloadLimitSetting() const; + void setDownloadLimitSetting(AccountNetworkTransferLimitSetting setting); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -440,6 +444,7 @@ public slots: void proxyUserChanged(); void proxyPasswordChanged(); void uploadLimitSettingChanged(); + void downloadLimitSettingChanged(); protected Q_SLOTS: void slotCredentialsFetched(); @@ -524,6 +529,7 @@ private slots: QString _proxyUser; QString _proxyPassword; AccountNetworkTransferLimitSetting _uploadLimitSetting = AccountNetworkTransferLimitSetting::GlobalLimit; + AccountNetworkTransferLimitSetting _downloadLimitSetting = AccountNetworkTransferLimitSetting::GlobalLimit; /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From d06e8b1d4ed799e328ec7bcfdd7fc50e5aa324e1 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:57:07 +0800 Subject: [PATCH 14/49] Add upload limit property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 87dfc966795a4..42f46c250fcd6 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1223,4 +1223,19 @@ void Account::setDownloadLimitSetting(const AccountNetworkTransferLimitSetting s emit downloadLimitSettingChanged(); } +unsigned int Account::uploadLimit() const +{ + return _uploadLimit; +} + +void Account::setUploadLimit(const unsigned int limit) +{ + if (_uploadLimit == limit) { + return; + } + + _uploadLimit = limit; + emit uploadLimitChanged(); +} + } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index fdf4d124971cb..e50df0f486612 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -100,6 +100,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(QString proxyPassword READ proxyPassword WRITE setProxyPassword NOTIFY proxyPasswordChanged) Q_PROPERTY(AccountNetworkTransferLimitSetting uploadLimitSetting READ uploadLimitSetting WRITE setUploadLimitSetting NOTIFY uploadLimitSettingChanged) Q_PROPERTY(AccountNetworkTransferLimitSetting downloadLimitSetting READ downloadLimitSetting WRITE setDownloadLimitSetting NOTIFY downloadLimitSettingChanged) + Q_PROPERTY(unsigned int uploadLimit READ uploadLimit WRITE setUploadLimit NOTIFY uploadLimitChanged) public: enum class AccountNetworkProxySetting { @@ -392,6 +393,10 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] AccountNetworkTransferLimitSetting downloadLimitSetting() const; void setDownloadLimitSetting(AccountNetworkTransferLimitSetting setting); + /** in kbyte/s */ + [[nodiscard]] unsigned int uploadLimit() const; + void setUploadLimit(unsigned int kbytes); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -445,6 +450,7 @@ public slots: void proxyPasswordChanged(); void uploadLimitSettingChanged(); void downloadLimitSettingChanged(); + void uploadLimitChanged(); protected Q_SLOTS: void slotCredentialsFetched(); @@ -530,6 +536,7 @@ private slots: QString _proxyPassword; AccountNetworkTransferLimitSetting _uploadLimitSetting = AccountNetworkTransferLimitSetting::GlobalLimit; AccountNetworkTransferLimitSetting _downloadLimitSetting = AccountNetworkTransferLimitSetting::GlobalLimit; + unsigned int _uploadLimit = 0; /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From 35bc728a39980dc88a42c7d224fe258c2c35cf22 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:57:16 +0800 Subject: [PATCH 15/49] Add download limit setting property to account Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 15 +++++++++++++++ src/libsync/account.h | 7 +++++++ 2 files changed, 22 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 42f46c250fcd6..046d984fd7d14 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1238,4 +1238,19 @@ void Account::setUploadLimit(const unsigned int limit) emit uploadLimitChanged(); } +unsigned int Account::downloadLimit() const +{ + return _downloadLimit; +} + +void Account::setDownloadLimit(const unsigned int limit) +{ + if (_downloadLimit == limit) { + return; + } + + _downloadLimit = limit; + emit downloadLimitChanged(); +} + } // namespace OCC diff --git a/src/libsync/account.h b/src/libsync/account.h index e50df0f486612..8fbc2acac29ce 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -101,6 +101,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(AccountNetworkTransferLimitSetting uploadLimitSetting READ uploadLimitSetting WRITE setUploadLimitSetting NOTIFY uploadLimitSettingChanged) Q_PROPERTY(AccountNetworkTransferLimitSetting downloadLimitSetting READ downloadLimitSetting WRITE setDownloadLimitSetting NOTIFY downloadLimitSettingChanged) Q_PROPERTY(unsigned int uploadLimit READ uploadLimit WRITE setUploadLimit NOTIFY uploadLimitChanged) + Q_PROPERTY(unsigned int downloadLimit READ downloadLimit WRITE setDownloadLimit NOTIFY downloadLimitChanged) public: enum class AccountNetworkProxySetting { @@ -397,6 +398,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] unsigned int uploadLimit() const; void setUploadLimit(unsigned int kbytes); + [[nodiscard]] unsigned int downloadLimit() const; + void setDownloadLimit(unsigned int kbytes); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -451,6 +455,7 @@ public slots: void uploadLimitSettingChanged(); void downloadLimitSettingChanged(); void uploadLimitChanged(); + void downloadLimitChanged(); protected Q_SLOTS: void slotCredentialsFetched(); @@ -537,6 +542,8 @@ private slots: AccountNetworkTransferLimitSetting _uploadLimitSetting = AccountNetworkTransferLimitSetting::GlobalLimit; AccountNetworkTransferLimitSetting _downloadLimitSetting = AccountNetworkTransferLimitSetting::GlobalLimit; unsigned int _uploadLimit = 0; + unsigned int _downloadLimit = 0; + /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From 3956612ac632187177ba27264702ee48fd91cc97 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:57:57 +0800 Subject: [PATCH 16/49] Save and restore account-specific network settings in account maanger Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 9a11314ce21c0..881acaed7c483 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace { constexpr auto urlC = "url"; @@ -46,6 +47,17 @@ constexpr auto serverVersionC = "serverVersion"; constexpr auto serverColorC = "serverColor"; constexpr auto serverTextColorC = "serverTextColor"; constexpr auto skipE2eeMetadataChecksumValidationC = "skipE2eeMetadataChecksumValidation"; +constexpr auto networkProxySettingC = "networkProxySetting"; +constexpr auto networkProxyTypeC = "networkProxyType"; +constexpr auto networkProxyHostNameC = "networkProxyHostName"; +constexpr auto networkProxyPortC = "networkProxyPort"; +constexpr auto networkProxyNeedsAuthC = "networkProxyNeedsAuth"; +constexpr auto networkProxyUserC = "networkProxyUser"; +constexpr auto networkProxyPasswordC = "networkProxyPassword"; +constexpr auto networkUploadLimitSettingC = "networkUploadLimitSetting"; +constexpr auto networkDownloadLimitSettingC = "networkDownloadLimitSetting"; +constexpr auto networkUploadLimitC = "networkUploadLimit"; +constexpr auto networkDownloadLimitC = "networkDownloadLimit"; constexpr auto generalC = "General"; constexpr auto dummyAuthTypeC = "dummy"; @@ -330,6 +342,17 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s } else { settings.setValue(QLatin1String(skipE2eeMetadataChecksumValidationC), acc->_skipE2eeMetadataChecksumValidation); } + settings.setValue(networkProxySettingC, static_cast>(acc->networkProxySetting())); + settings.setValue(networkProxyTypeC, acc->proxyType()); + settings.setValue(networkProxyHostNameC, acc->proxyHostName()); + settings.setValue(networkProxyPortC, acc->proxyPort()); + settings.setValue(networkProxyNeedsAuthC, acc->proxyNeedsAuth()); + settings.setValue(networkProxyUserC, acc->proxyUser()); + settings.setValue(networkProxyPasswordC, acc->proxyPassword()); + settings.setValue(networkUploadLimitSettingC, static_cast>(acc->uploadLimitSetting())); + settings.setValue(networkDownloadLimitSettingC, static_cast>(acc->downloadLimitSetting())); + settings.setValue(networkUploadLimitC, acc->uploadLimit()); + settings.setValue(networkDownloadLimitC, acc->downloadLimit()); if (acc->_credentials) { if (saveCredentials) { @@ -451,6 +474,18 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) acc->setCredentials(CredentialsFactory::create(authType)); + acc->setNetworkProxySetting(settings.value(networkProxySettingC).value()); + acc->setProxyType(settings.value(networkProxyTypeC).value()); + acc->setProxyHostName(settings.value(networkProxyHostNameC).toString()); + acc->setProxyPort(settings.value(networkProxyPortC).toInt()); + acc->setProxyNeedsAuth(settings.value(networkProxyNeedsAuthC).toBool()); + acc->setProxyUser(settings.value(networkProxyUserC).toString()); + acc->setProxyPassword(settings.value(networkProxyPasswordC).toString()); + acc->setUploadLimitSetting(settings.value(networkUploadLimitSettingC).value()); + acc->setDownloadLimitSetting(settings.value(networkDownloadLimitSettingC).value()); + acc->setUploadLimit(settings.value(networkUploadLimitC).toInt()); + acc->setDownloadLimit(settings.value(networkDownloadLimitC).toInt()); + // now the server cert, it is in the general group settings.beginGroup(QLatin1String(generalC)); const auto certs = QSslCertificate::fromData(settings.value(caCertsKeyC).toByteArray()); From 03946a867804396c760108a69ec1574b21254c12 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:58:24 +0800 Subject: [PATCH 17/49] Take account-specific network configuration into account in proxyauthhandler Signed-off-by: Claudio Cambra --- src/gui/proxyauthhandler.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gui/proxyauthhandler.cpp b/src/gui/proxyauthhandler.cpp index 2f48f4489c133..64c922037f920 100644 --- a/src/gui/proxyauthhandler.cpp +++ b/src/gui/proxyauthhandler.cpp @@ -61,7 +61,8 @@ void ProxyAuthHandler::handleProxyAuthenticationRequired( return; } - QString key = proxy.hostName() + QLatin1Char(':') + QString::number(proxy.port()); + const auto account = qobject_cast(sender()); + const auto key = proxy.hostName() + QLatin1Char(':') + QString::number(proxy.port()); // If the proxy server has changed, forget what we know. if (key != _proxy) { @@ -73,7 +74,10 @@ void ProxyAuthHandler::handleProxyAuthenticationRequired( // If the user explicitly configured the proxy in the // network settings, don't ask about it. - if (_configFile->proxyType() == QNetworkProxy::HttpProxy + if ((account && (account->networkProxySetting() == Account::AccountNetworkProxySetting::GlobalProxy + || account->proxyType() == QNetworkProxy::HttpProxy + || account->proxyType() == QNetworkProxy::Socks5Proxy)) + || _configFile->proxyType() == QNetworkProxy::HttpProxy || _configFile->proxyType() == QNetworkProxy::Socks5Proxy) { _blocked = true; } @@ -85,7 +89,7 @@ void ProxyAuthHandler::handleProxyAuthenticationRequired( // Find the responsible QNAM if possible. QPointer sending_qnam = nullptr; - if (auto account = qobject_cast(sender())) { + if (account) { // Since we go into an event loop, it's possible for the account's qnam // to be destroyed before we get back. We can use this to check for its // liveness. From dd7143611a8ae7753d3621ac0b41891db6ae00fc Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 17:59:24 +0800 Subject: [PATCH 18/49] Add account member to network settings Signed-off-by: Claudio Cambra --- src/gui/accountsettings.cpp | 2 +- src/gui/networksettings.cpp | 23 ++-- src/gui/networksettings.h | 4 +- src/gui/networksettings.ui | 213 ++++++++++++++++++++---------------- 4 files changed, 138 insertions(+), 104 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index d51601392344d..bebc5fa7c40e6 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -214,7 +214,7 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) const auto connectionSettingsTab = _ui->connectionSettingsTab; const auto connectionSettingsLayout = new QVBoxLayout(connectionSettingsTab); - const auto networkSettings = new NetworkSettings(connectionSettingsTab); + const auto networkSettings = new NetworkSettings(_accountState->account().get(), connectionSettingsTab); connectionSettingsLayout->addWidget(networkSettings); connectionSettingsTab->setLayout(connectionSettingsLayout); diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index 66ddbbaa5f983..dd1be9af4e06f 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -15,12 +15,12 @@ #include "networksettings.h" #include "ui_networksettings.h" -#include "theme.h" -#include "configfile.h" +#include "account.h" +#include "accountmanager.h" #include "application.h" #include "configfile.h" #include "folderman.h" -#include "accountmanager.h" +#include "theme.h" #include #include @@ -28,9 +28,10 @@ namespace OCC { -NetworkSettings::NetworkSettings(QWidget *parent) +NetworkSettings::NetworkSettings(Account *const account, QWidget *parent) : QWidget(parent) , _ui(new Ui::NetworkSettings) + , _account(account) { _ui->setupUi(this); @@ -38,6 +39,12 @@ NetworkSettings::NetworkSettings(QWidget *parent) _ui->proxyGroupBox->setVisible(!Theme::instance()->doNotUseProxy()); + if (account == nullptr) { + _ui->globalProxySettingsRadioButton->setVisible(false); + _ui->globalDownloadSettingsRadioButton->setVisible(false); + _ui->globalUploadSettingsRadioButton->setVisible(false); + } + if (!Theme::instance()->doNotUseProxy()) { _ui->hostLineEdit->setPlaceholderText(tr("Hostname of proxy server")); _ui->userLineEdit->setPlaceholderText(tr("Username for proxy server")); @@ -60,10 +67,8 @@ NetworkSettings::NetworkSettings(QWidget *parent) loadProxySettings(); - connect(_ui->typeComboBox, static_cast(&QComboBox::currentIndexChanged), this, - &NetworkSettings::saveProxySettings); - connect(_ui->proxyButtonGroup, &QButtonGroup::buttonClicked, this, - &NetworkSettings::saveProxySettings); + connect(_ui->typeComboBox, static_cast(&QComboBox::currentIndexChanged), this, &NetworkSettings::saveProxySettings); + connect(_ui->proxyButtonGroup, &QButtonGroup::buttonClicked, this, &NetworkSettings::saveProxySettings); connect(_ui->hostLineEdit, &QLineEdit::editingFinished, this, &NetworkSettings::saveProxySettings); connect(_ui->userLineEdit, &QLineEdit::editingFinished, this, &NetworkSettings::saveProxySettings); connect(_ui->passwordLineEdit, &QLineEdit::editingFinished, this, &NetworkSettings::saveProxySettings); @@ -85,9 +90,11 @@ NetworkSettings::NetworkSettings(QWidget *parent) _ui->uploadSpinBox->setVisible(_ui->uploadLimitRadioButton->isChecked()); _ui->uploadSpinBoxLabel->setVisible(_ui->uploadLimitRadioButton->isChecked()); + connect(_ui->globalUploadSettingsRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings); connect(_ui->uploadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings); connect(_ui->noUploadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings); connect(_ui->autoUploadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings); + connect(_ui->globalDownloadSettingsRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings); connect(_ui->downloadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings); connect(_ui->noDownloadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings); connect(_ui->autoDownloadLimitRadioButton, &QAbstractButton::clicked, this, &NetworkSettings::saveBWLimitSettings); diff --git a/src/gui/networksettings.h b/src/gui/networksettings.h index 8e3a97c446b6d..9ebfa3f515026 100644 --- a/src/gui/networksettings.h +++ b/src/gui/networksettings.h @@ -19,6 +19,7 @@ namespace OCC { +class Account; namespace Ui { class NetworkSettings; @@ -33,7 +34,7 @@ class NetworkSettings : public QWidget Q_OBJECT public: - explicit NetworkSettings(QWidget *parent = nullptr); + explicit NetworkSettings(Account *const account = nullptr, QWidget *parent = nullptr); ~NetworkSettings() override; [[nodiscard]] QSize sizeHint() const override; @@ -54,6 +55,7 @@ private slots: void loadBWLimitSettings(); Ui::NetworkSettings *_ui; + Account *_account; }; diff --git a/src/gui/networksettings.ui b/src/gui/networksettings.ui index 3974a1f82caa0..db6db42be4802 100644 --- a/src/gui/networksettings.ui +++ b/src/gui/networksettings.ui @@ -42,20 +42,7 @@ Proxy Settings - - - - No proxy - - - true - - - proxyButtonGroup - - - - + Use system proxy @@ -65,30 +52,7 @@ - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Manually specify proxy - - - proxyButtonGroup - - - - + @@ -276,6 +240,52 @@ + + + + Manually specify proxy + + + proxyButtonGroup + + + + + + + No proxy + + + true + + + proxyButtonGroup + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Use global settings + + + proxyButtonGroup + + + @@ -311,7 +321,7 @@ 6 - + No limit @@ -321,24 +331,7 @@ - - - - Limit to 3/4 of estimated bandwidth - - - Limit automatically - - - - - - - Limit to - - - - + @@ -368,7 +361,7 @@ - + Qt::Vertical @@ -381,6 +374,30 @@ + + + + Limit to + + + + + + + Limit to 3/4 of estimated bandwidth + + + Limit automatically + + + + + + + Use global settings + + + @@ -411,7 +428,47 @@ 6 + + + + Limit to 3/4 of estimated bandwidth + + + Limit automatically + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + Limit to + + + + + + + No limit + + + true + + + + @@ -444,51 +501,19 @@ - - - - Limit to 3/4 of estimated bandwidth - - - Limit automatically - - - - - - - Limit to - - - - - + + - No limit - - - true + Use global settings - - - - Qt::Vertical - - - - 20 - 40 - - - - autoUploadLimitRadioButton uploadLimitRadioButton noUploadLimitRadioButton verticalSpacer_3 + globalUploadSettingsRadioButton From fe031a131c1475bd61ffed45b96177e1f8f1a384 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 18:00:11 +0800 Subject: [PATCH 19/49] Load in account specific network settings in network settings widget Signed-off-by: Claudio Cambra --- src/gui/networksettings.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index dd1be9af4e06f..3a0cd863737ca 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -122,10 +122,18 @@ void NetworkSettings::loadProxySettings() _ui->proxyGroupBox->setEnabled(false); return; } + + const auto useGlobalProxy = _account == nullptr || _account->networkProxySetting() == Account::AccountNetworkProxySetting::GlobalProxy; + const auto cfgFile = ConfigFile(); + const auto proxyType = useGlobalProxy ? cfgFile.proxyType() : _account->proxyType(); + const auto proxyPort = useGlobalProxy ? cfgFile.proxyPort() : _account->proxyPort(); + const auto proxyHostName = useGlobalProxy ? cfgFile.proxyHostName() : _account->proxyHostName(); + const auto proxyNeedsAuth = useGlobalProxy ? cfgFile.proxyNeedsAuth() : _account->proxyNeedsAuth(); + const auto proxyUser = useGlobalProxy ? cfgFile.proxyUser() : _account->proxyUser(); + const auto proxyPassword = useGlobalProxy ? cfgFile.proxyPassword() : _account->proxyPassword(); + // load current proxy settings - OCC::ConfigFile cfgFile; - int type = cfgFile.proxyType(); - switch (type) { + switch (proxyType) { case QNetworkProxy::NoProxy: _ui->noProxyRadioButton->setChecked(true); break; @@ -134,21 +142,18 @@ void NetworkSettings::loadProxySettings() break; case QNetworkProxy::Socks5Proxy: case QNetworkProxy::HttpProxy: - _ui->typeComboBox->setCurrentIndex(_ui->typeComboBox->findData(type)); + _ui->typeComboBox->setCurrentIndex(_ui->typeComboBox->findData(proxyType)); _ui->manualProxyRadioButton->setChecked(true); break; default: break; } - _ui->hostLineEdit->setText(cfgFile.proxyHostName()); - int port = cfgFile.proxyPort(); - if (port == 0) - port = 8080; - _ui->portSpinBox->setValue(port); - _ui->authRequiredcheckBox->setChecked(cfgFile.proxyNeedsAuth()); - _ui->userLineEdit->setText(cfgFile.proxyUser()); - _ui->passwordLineEdit->setText(cfgFile.proxyPassword()); + _ui->hostLineEdit->setText(proxyHostName); + _ui->portSpinBox->setValue(proxyPort == 0 ? 8080 : proxyPort); + _ui->authRequiredcheckBox->setChecked(proxyNeedsAuth); + _ui->userLineEdit->setText(proxyUser); + _ui->passwordLineEdit->setText(proxyPassword); } void NetworkSettings::loadBWLimitSettings() From f9d0f435d1b9ae592294bed53b96c9f7599aa419 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 18:43:47 +0800 Subject: [PATCH 20/49] Adapt network settings loadBwLimitSettings for account-specific settings Signed-off-by: Claudio Cambra --- src/gui/networksettings.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index 3a0cd863737ca..3548800ffee24 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace OCC { @@ -158,27 +159,34 @@ void NetworkSettings::loadProxySettings() void NetworkSettings::loadBWLimitSettings() { - ConfigFile cfgFile; - - int useDownloadLimit = cfgFile.useDownloadLimit(); - if (useDownloadLimit >= 1) { + const auto useGlobalLimit = _account == nullptr || _account->downloadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit; + const auto cfgFile = ConfigFile(); + const auto useDownloadLimit = useGlobalLimit ? cfgFile.useDownloadLimit() : static_cast>(_account->downloadLimitSetting()); + const auto downloadLimit = useGlobalLimit ? cfgFile.downloadLimit() : _account->downloadLimit(); + const auto useUploadLimit = useGlobalLimit ? cfgFile.useUploadLimit() : static_cast>(_account->uploadLimitSetting()); + const auto uploadLimit = useGlobalLimit ? cfgFile.uploadLimit() : _account->uploadLimit(); + + if (_account != nullptr && _account->downloadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit) { + _ui->globalDownloadSettingsRadioButton->setChecked(true); + } else if (useDownloadLimit >= 1) { _ui->downloadLimitRadioButton->setChecked(true); } else if (useDownloadLimit == 0) { _ui->noDownloadLimitRadioButton->setChecked(true); } else { _ui->autoDownloadLimitRadioButton->setChecked(true); } - _ui->downloadSpinBox->setValue(cfgFile.downloadLimit()); + _ui->downloadSpinBox->setValue(downloadLimit); - int useUploadLimit = cfgFile.useUploadLimit(); - if (useUploadLimit >= 1) { + if (_account != nullptr && _account->uploadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit) { + _ui->globalUploadSettingsRadioButton->setChecked(true); + } else if (useUploadLimit >= 1) { _ui->uploadLimitRadioButton->setChecked(true); } else if (useUploadLimit == 0) { _ui->noUploadLimitRadioButton->setChecked(true); } else { _ui->autoUploadLimitRadioButton->setChecked(true); } - _ui->uploadSpinBox->setValue(cfgFile.uploadLimit()); + _ui->uploadSpinBox->setValue(uploadLimit); } void NetworkSettings::saveProxySettings() From f9b4c76b333e2b46d6805e4ff50cfe38bd04e273 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 19:22:00 +0800 Subject: [PATCH 21/49] Implement saving proxy settings to account in network settings Signed-off-by: Claudio Cambra --- src/gui/networksettings.cpp | 68 ++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 20 deletions(-) diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index 3548800ffee24..9de0323bbcf4b 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -194,33 +194,61 @@ void NetworkSettings::saveProxySettings() ConfigFile cfgFile; checkEmptyProxyHost(); + + const auto useGlobalProxy = _ui->globalProxySettingsRadioButton->isChecked(); + const auto user = _ui->userLineEdit->text(); + const auto password = _ui->passwordLineEdit->text(); + const auto host = _ui->hostLineEdit->text(); + const auto port = _ui->portSpinBox->value(); + const auto needsAuth = _ui->authRequiredcheckBox->isChecked(); + + auto proxyType = QNetworkProxy::NoProxy; + if (_ui->noProxyRadioButton->isChecked()) { - cfgFile.setProxyType(QNetworkProxy::NoProxy); + proxyType = QNetworkProxy::NoProxy; } else if (_ui->systemProxyRadioButton->isChecked()) { - cfgFile.setProxyType(QNetworkProxy::DefaultProxy); + proxyType = QNetworkProxy::DefaultProxy; } else if (_ui->manualProxyRadioButton->isChecked()) { - int type = _ui->typeComboBox->itemData(_ui->typeComboBox->currentIndex()).toInt(); - QString host = _ui->hostLineEdit->text(); - if (host.isEmpty()) - type = QNetworkProxy::NoProxy; - bool needsAuth = _ui->authRequiredcheckBox->isChecked(); - QString user = _ui->userLineEdit->text(); - QString pass = _ui->passwordLineEdit->text(); - cfgFile.setProxyType(type, _ui->hostLineEdit->text(), - _ui->portSpinBox->value(), needsAuth, user, pass); + proxyType = _ui->typeComboBox->itemData(_ui->typeComboBox->currentIndex()).value(); + if (host.isEmpty()) { + proxyType = QNetworkProxy::NoProxy; + } } - ClientProxy proxy; - proxy.setupQtProxyFromConfig(); // Refresh the Qt proxy settings as the - // quota check can happen all the time. + if (_account) { // We must be setting up network proxy for a specific account + _account->setNetworkProxySetting(useGlobalProxy ? Account::AccountNetworkProxySetting::GlobalProxy : Account::AccountNetworkProxySetting::AccountSpecificProxy); + _account->setProxyType(proxyType); + _account->setProxyHostName(host); + _account->setProxyPort(_ui->portSpinBox->value()); + _account->setProxyNeedsAuth(needsAuth); + _account->setProxyUser(user); + _account->setProxyPassword(password); + + if (useGlobalProxy) { + _account->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); + } else { + const auto proxy = QNetworkProxy(proxyType, host, port, user, password); + _account->networkAccessManager()->setProxy(proxy); + } - // ...and set the folders dirty, they refresh their proxy next time they - // start the sync. - FolderMan::instance()->setDirtyProxy(); + const auto accountState = AccountManager::instance()->accountFromUserId(_account->userIdAtHostWithPort()); + accountState->freshConnectionAttempt(); + } else { + cfgFile.setProxyType(proxyType, host, port, needsAuth, user, password); + ClientProxy proxy; + proxy.setupQtProxyFromConfig(); // Refresh the Qt proxy settings as the + // quota check can happen all the time. + + // ...and set the folders dirty, they refresh their proxy next time they + // start the sync. + FolderMan::instance()->setDirtyProxy(); - const auto accounts = AccountManager::instance()->accounts(); - for (auto account : accounts) { - account->freshConnectionAttempt(); + const auto accounts = AccountManager::instance()->accounts(); + for (const auto &accountState : accounts) { + if (accountState->account()->networkProxySetting() == Account::AccountNetworkProxySetting::GlobalProxy) { + accountState->freshConnectionAttempt(); + } + } } } From 8dabae6c293277c6575fffd7272e6c3e80c08340 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 19:42:58 +0800 Subject: [PATCH 22/49] Respect account proxy settings in owncloudsetupwizard server check Signed-off-by: Claudio Cambra --- src/gui/owncloudsetupwizard.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/owncloudsetupwizard.cpp b/src/gui/owncloudsetupwizard.cpp index c96f0351d0f7c..5eae50e44aae7 100644 --- a/src/gui/owncloudsetupwizard.cpp +++ b/src/gui/owncloudsetupwizard.cpp @@ -178,10 +178,10 @@ void OwncloudSetupWizard::slotCheckServer(const QString &urlString) account->networkAccessManager()->clearAccessCache(); // Lookup system proxy in a thread https://github.com/owncloud/client/issues/2993 - if (ClientProxy::isUsingSystemDefault()) { + if ((ClientProxy::isUsingSystemDefault() && account->networkProxySetting() == Account::AccountNetworkProxySetting::GlobalProxy) + || account->proxyType() == QNetworkProxy::DefaultProxy) { qCDebug(lcWizard) << "Trying to look up system proxy"; - ClientProxy::lookupSystemProxyAsync(account->url(), - this, SLOT(slotSystemProxyLookupDone(QNetworkProxy))); + ClientProxy::lookupSystemProxyAsync(account->url(), this, SLOT(slotSystemProxyLookupDone(QNetworkProxy))); } else { // We want to reset the QNAM proxy so that the global proxy settings are used (via ClientProxy settings) account->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); From ac9819797c0ee58e7c9abdd70252f5c8136fe47a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 19:43:07 +0800 Subject: [PATCH 23/49] Respect account proxy settings in connectionvalidator Signed-off-by: Claudio Cambra --- src/gui/connectionvalidator.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/connectionvalidator.cpp b/src/gui/connectionvalidator.cpp index 9cc24de4a7521..6bdeca0f7c3a1 100644 --- a/src/gui/connectionvalidator.cpp +++ b/src/gui/connectionvalidator.cpp @@ -57,10 +57,10 @@ void ConnectionValidator::checkServerAndAuth() _isCheckingServerAndAuth = true; // Lookup system proxy in a thread https://github.com/owncloud/client/issues/2993 - if (ClientProxy::isUsingSystemDefault()) { + if ((ClientProxy::isUsingSystemDefault() && _account->networkProxySetting() == Account::AccountNetworkProxySetting::GlobalProxy) + || _account->proxyType() == QNetworkProxy::DefaultProxy) { qCDebug(lcConnectionValidator) << "Trying to look up system proxy"; - ClientProxy::lookupSystemProxyAsync(_account->url(), - this, SLOT(systemProxyLookupDone(QNetworkProxy))); + ClientProxy::lookupSystemProxyAsync(_account->url(), this, SLOT(systemProxyLookupDone(QNetworkProxy))); } else { // We want to reset the QNAM proxy so that the global proxy settings are used (via ClientProxy settings) _account->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); From 8e9e125deeb9e07c78308be3a6b46c3cb5f83dee Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 19:43:48 +0800 Subject: [PATCH 24/49] When generally setting dirty proxy in folderman only mark dirty those that follow general client proxy settings Signed-off-by: Claudio Cambra --- src/gui/folderman.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 46073c24874a0..eab67ee5b9fd7 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1511,13 +1511,14 @@ void FolderMan::setDirtyProxy() { const auto folderMapValues = _folderMap.values(); for (const auto folder : folderMapValues) { - if (folder) { - if (folder->accountState() && folder->accountState()->account() - && folder->accountState()->account()->networkAccessManager()) { - // Need to do this so we do not use the old determined system proxy - folder->accountState()->account()->networkAccessManager()->setProxy( - QNetworkProxy(QNetworkProxy::DefaultProxy)); - } + if (folder + && folder->accountState() + && folder->accountState()->account() + && folder->accountState()->account()->networkAccessManager() + && folder->accountState()->account()->networkProxySetting() == Account::AccountNetworkProxySetting::GlobalProxy) { + // Need to do this so we do not use the old determined system proxy + const auto proxy = QNetworkProxy(QNetworkProxy::DefaultProxy); + folder->accountState()->account()->networkAccessManager()->setProxy(proxy); } } } From 9dfcd876acd1b6c8aed5a9d7f34d42864711afba Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 19:46:21 +0800 Subject: [PATCH 25/49] Ensure we are resetting account proxy settings when not using proxy is enforced Signed-off-by: Claudio Cambra --- src/gui/application.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 0b49a2e93e543..c2d0b55c3729a 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -298,6 +298,11 @@ Application::Application(int &argc, char **argv) if (_theme->doNotUseProxy()) { ConfigFile().setProxyType(QNetworkProxy::NoProxy); + for (const auto &accountState : AccountManager::instance()->accounts()) { + if (accountState && accountState->account()) { + accountState->account()->setNetworkProxySetting(Account::AccountNetworkProxySetting::GlobalProxy); + } + } } parseOptions(arguments()); From ab1d02dab6f458eace1465a3d1168f8c56a97d40 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 19:46:47 +0800 Subject: [PATCH 26/49] Fix account-specific network setting enum values Signed-off-by: Claudio Cambra --- src/libsync/account.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libsync/account.h b/src/libsync/account.h index 8fbc2acac29ce..e58fc3ee44e6f 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -104,19 +104,19 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject Q_PROPERTY(unsigned int downloadLimit READ downloadLimit WRITE setDownloadLimit NOTIFY downloadLimitChanged) public: + // We need to decide whether to use the client's global proxy settings or whether to use + // a specific setting for each account. Hence this enum enum class AccountNetworkProxySetting { GlobalProxy = 0, - NoProxy, - ManualProxy, - AutoProxy + AccountSpecificProxy, }; Q_ENUM(AccountNetworkProxySetting) enum class AccountNetworkTransferLimitSetting { - GlobalLimit = 0, + GlobalLimit = -2, + AutoLimit, // Value under 0 is interpreted as auto in general NoLimit, ManualLimit, - AutoLimit }; Q_ENUM(AccountNetworkTransferLimitSetting) From 04f335e9722fac78411a1340b4e26c7f50963612 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 19:48:31 +0800 Subject: [PATCH 27/49] Modify network access manager proxy within account when setting proxy values Signed-off-by: Claudio Cambra --- src/libsync/account.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 046d984fd7d14..af0efc8f8e9ce 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1115,6 +1115,13 @@ void Account::setProxyType(QNetworkProxy::ProxyType proxyType) } _proxyType = proxyType; + + if (networkProxySetting() == AccountNetworkProxySetting::AccountSpecificProxy) { + auto proxy = _am->proxy(); + proxy.setType(proxyType); + _am->setProxy(proxy); + } + emit proxyTypeChanged(); } @@ -1130,6 +1137,13 @@ void Account::setProxyHostName(const QString &hostName) } _proxyHostName = hostName; + + if (networkProxySetting() == AccountNetworkProxySetting::AccountSpecificProxy) { + auto proxy = _am->proxy(); + proxy.setHostName(hostName); + _am->setProxy(proxy); + } + emit proxyHostNameChanged(); } @@ -1145,6 +1159,13 @@ void Account::setProxyPort(const int port) } _proxyPort = port; + + if (networkProxySetting() == AccountNetworkProxySetting::AccountSpecificProxy) { + auto proxy = _am->proxy(); + proxy.setPort(port); + _am->setProxy(proxy); + } + emit proxyPortChanged(); } @@ -1175,6 +1196,13 @@ void Account::setProxyUser(const QString &user) } _proxyUser = user; + + if (networkProxySetting() == AccountNetworkProxySetting::AccountSpecificProxy) { + auto proxy = _am->proxy(); + proxy.setUser(user); + _am->setProxy(proxy); + } + emit proxyUserChanged(); } @@ -1190,6 +1218,13 @@ void Account::setProxyPassword(const QString &password) } _proxyPassword = password; + + if (networkProxySetting() == AccountNetworkProxySetting::AccountSpecificProxy) { + auto proxy = _am->proxy(); + proxy.setPassword(password); + _am->setProxy(proxy); + } + emit proxyPasswordChanged(); } From b14b86e370f8990c37b8152136d530e5ee2a98de Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 20:04:49 +0800 Subject: [PATCH 28/49] Clean up networksettings saveProxySettings Signed-off-by: Claudio Cambra --- src/gui/networksettings.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index 9de0323bbcf4b..47010c2b7c8e6 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -191,8 +191,6 @@ void NetworkSettings::loadBWLimitSettings() void NetworkSettings::saveProxySettings() { - ConfigFile cfgFile; - checkEmptyProxyHost(); const auto useGlobalProxy = _ui->globalProxySettingsRadioButton->isChecked(); @@ -219,7 +217,7 @@ void NetworkSettings::saveProxySettings() _account->setNetworkProxySetting(useGlobalProxy ? Account::AccountNetworkProxySetting::GlobalProxy : Account::AccountNetworkProxySetting::AccountSpecificProxy); _account->setProxyType(proxyType); _account->setProxyHostName(host); - _account->setProxyPort(_ui->portSpinBox->value()); + _account->setProxyPort(port); _account->setProxyNeedsAuth(needsAuth); _account->setProxyUser(user); _account->setProxyPassword(password); @@ -234,7 +232,7 @@ void NetworkSettings::saveProxySettings() const auto accountState = AccountManager::instance()->accountFromUserId(_account->userIdAtHostWithPort()); accountState->freshConnectionAttempt(); } else { - cfgFile.setProxyType(proxyType, host, port, needsAuth, user, password); + ConfigFile().setProxyType(proxyType, host, port, needsAuth, user, password); ClientProxy proxy; proxy.setupQtProxyFromConfig(); // Refresh the Qt proxy settings as the // quota check can happen all the time. From 97f31a296582e9de27fd4342cefd2e7de9c5e29a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 20:05:55 +0800 Subject: [PATCH 29/49] Save bwlimits for account-specific network configuration Signed-off-by: Claudio Cambra --- src/gui/networksettings.cpp | 38 ++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index 47010c2b7c8e6..9a3929a64a0b0 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -252,24 +252,44 @@ void NetworkSettings::saveProxySettings() void NetworkSettings::saveBWLimitSettings() { - ConfigFile cfgFile; + const auto downloadLimit = _ui->downloadSpinBox->value(); + const auto uploadLimit = _ui->uploadSpinBox->value(); + + auto useDownloadLimit = 0; + auto useUploadLimit = 0; + if (_ui->downloadLimitRadioButton->isChecked()) { - cfgFile.setUseDownloadLimit(1); + useDownloadLimit = 1; } else if (_ui->noDownloadLimitRadioButton->isChecked()) { - cfgFile.setUseDownloadLimit(0); + useDownloadLimit = 0; } else if (_ui->autoDownloadLimitRadioButton->isChecked()) { - cfgFile.setUseDownloadLimit(-1); + useDownloadLimit = -1; + } else if (_account && _ui->globalDownloadSettingsRadioButton->isChecked()) { + useDownloadLimit = -2; } - cfgFile.setDownloadLimit(_ui->downloadSpinBox->value()); if (_ui->uploadLimitRadioButton->isChecked()) { - cfgFile.setUseUploadLimit(1); + useUploadLimit = 1; } else if (_ui->noUploadLimitRadioButton->isChecked()) { - cfgFile.setUseUploadLimit(0); + useUploadLimit = 0; } else if (_ui->autoUploadLimitRadioButton->isChecked()) { - cfgFile.setUseUploadLimit(-1); + useUploadLimit = -1; + } else if (_account && _ui->globalUploadSettingsRadioButton->isChecked()) { + useUploadLimit = -2; + } + + if (_account) { + _account->setDownloadLimitSetting(static_cast(useDownloadLimit)); + _account->setDownloadLimit(downloadLimit); + _account->setUploadLimitSetting(static_cast(useUploadLimit)); + _account->setUploadLimit(uploadLimit); + } else { + ConfigFile cfg; + cfg.setUseDownloadLimit(useDownloadLimit); + cfg.setUseUploadLimit(useUploadLimit); + cfg.setDownloadLimit(downloadLimit); + cfg.setUploadLimit(uploadLimit); } - cfgFile.setUploadLimit(_ui->uploadSpinBox->value()); FolderMan::instance()->setDirtyNetworkLimits(); } From 480828bbbb4d0e9bb1bd575041068f4753abf57a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 28 Jun 2024 20:06:17 +0800 Subject: [PATCH 30/49] Respect account-specific transfer limits in folder Signed-off-by: Claudio Cambra --- src/gui/folder.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index 37d83430ae117..3aad88a0f8078 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -47,6 +47,7 @@ #include #include #include +#include namespace { #ifndef VERSION_C @@ -1134,19 +1135,28 @@ SyncOptions Folder::initializeSyncOptions() const void Folder::setDirtyNetworkLimits() { + const auto account = _accountState->account(); + const auto useGlobalDown = account->downloadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit; + const auto useGlobalUp = account->uploadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit; + ConfigFile cfg; + int downloadLimit = -75; // 75% - int useDownLimit = cfg.useDownloadLimit(); + const auto useDownLimit = useGlobalDown + ? cfg.useDownloadLimit() + : static_cast>(account->downloadLimitSetting()); if (useDownLimit >= 1) { - downloadLimit = cfg.downloadLimit() * 1000; + downloadLimit = useGlobalDown ? cfg.downloadLimit() * 1000 : account->downloadLimit() * 1000; } else if (useDownLimit == 0) { downloadLimit = 0; } int uploadLimit = -75; // 75% - int useUpLimit = cfg.useUploadLimit(); + const auto useUpLimit = useGlobalUp + ? cfg.useUploadLimit() + : static_cast>(account->uploadLimitSetting()); if (useUpLimit >= 1) { - uploadLimit = cfg.uploadLimit() * 1000; + uploadLimit = useGlobalUp ? cfg.uploadLimit() * 1000 : account->uploadLimit() * 1000; } else if (useUpLimit == 0) { uploadLimit = 0; } From 9c856d29d407aa9f7c5458834ff8593323fd2877 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Sun, 7 Jul 2024 20:42:43 +0800 Subject: [PATCH 31/49] Correctly load global proxy setting state on account-specific network settings Signed-off-by: Claudio Cambra --- src/gui/networksettings.cpp | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index 9a3929a64a0b0..cb78708166c61 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -134,20 +134,24 @@ void NetworkSettings::loadProxySettings() const auto proxyPassword = useGlobalProxy ? cfgFile.proxyPassword() : _account->proxyPassword(); // load current proxy settings - switch (proxyType) { - case QNetworkProxy::NoProxy: - _ui->noProxyRadioButton->setChecked(true); - break; - case QNetworkProxy::DefaultProxy: - _ui->systemProxyRadioButton->setChecked(true); - break; - case QNetworkProxy::Socks5Proxy: - case QNetworkProxy::HttpProxy: - _ui->typeComboBox->setCurrentIndex(_ui->typeComboBox->findData(proxyType)); - _ui->manualProxyRadioButton->setChecked(true); - break; - default: - break; + if (_account && _account->networkProxySetting() == Account::AccountNetworkProxySetting::GlobalProxy) { + _ui->globalProxySettingsRadioButton->setChecked(true); + } else { + switch (proxyType) { + case QNetworkProxy::NoProxy: + _ui->noProxyRadioButton->setChecked(true); + break; + case QNetworkProxy::DefaultProxy: + _ui->systemProxyRadioButton->setChecked(true); + break; + case QNetworkProxy::Socks5Proxy: + case QNetworkProxy::HttpProxy: + _ui->typeComboBox->setCurrentIndex(_ui->typeComboBox->findData(proxyType)); + _ui->manualProxyRadioButton->setChecked(true); + break; + default: + break; + } } _ui->hostLineEdit->setText(proxyHostName); From 770beba6920f6ed873609ab11cbfb65d79542a8d Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Sun, 7 Jul 2024 23:23:37 +0800 Subject: [PATCH 32/49] Store accounts' proxy passwords in keychain Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 881acaed7c483..8cdfc29588e96 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -16,9 +16,9 @@ #include "sslerrordialog.h" #include "proxyauthhandler.h" -#include "common/asserts.h" #include "creds/credentialsfactory.h" #include "creds/abstractcredentials.h" +#include "creds/keychainchunk.h" #include "libsync/clientsideencryption.h" #include "libsync/configfile.h" #include "libsync/cookiejar.h" @@ -53,7 +53,6 @@ constexpr auto networkProxyHostNameC = "networkProxyHostName"; constexpr auto networkProxyPortC = "networkProxyPort"; constexpr auto networkProxyNeedsAuthC = "networkProxyNeedsAuth"; constexpr auto networkProxyUserC = "networkProxyUser"; -constexpr auto networkProxyPasswordC = "networkProxyPassword"; constexpr auto networkUploadLimitSettingC = "networkUploadLimitSetting"; constexpr auto networkDownloadLimitSettingC = "networkDownloadLimitSetting"; constexpr auto networkUploadLimitC = "networkUploadLimit"; @@ -348,12 +347,21 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s settings.setValue(networkProxyPortC, acc->proxyPort()); settings.setValue(networkProxyNeedsAuthC, acc->proxyNeedsAuth()); settings.setValue(networkProxyUserC, acc->proxyUser()); - settings.setValue(networkProxyPasswordC, acc->proxyPassword()); settings.setValue(networkUploadLimitSettingC, static_cast>(acc->uploadLimitSetting())); settings.setValue(networkDownloadLimitSettingC, static_cast>(acc->downloadLimitSetting())); settings.setValue(networkUploadLimitC, acc->uploadLimit()); settings.setValue(networkDownloadLimitC, acc->downloadLimit()); + const auto proxyPasswordKey = acc->userIdAtHostWithPort() + QStringLiteral("_proxy_password"); + const auto proxyPassword = acc->proxyPassword(); + if (proxyPassword.isEmpty()) { + const auto job = new KeychainChunk::DeleteJob(proxyPasswordKey); + job->exec(); + } else { + const auto job = new KeychainChunk::WriteJob(proxyPasswordKey, proxyPassword.toUtf8()); + job->exec(); + } + if (acc->_credentials) { if (saveCredentials) { // Only persist the credentials if the parameter is set, on migration from 1.8.x @@ -480,12 +488,21 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) acc->setProxyPort(settings.value(networkProxyPortC).toInt()); acc->setProxyNeedsAuth(settings.value(networkProxyNeedsAuthC).toBool()); acc->setProxyUser(settings.value(networkProxyUserC).toString()); - acc->setProxyPassword(settings.value(networkProxyPasswordC).toString()); acc->setUploadLimitSetting(settings.value(networkUploadLimitSettingC).value()); acc->setDownloadLimitSetting(settings.value(networkDownloadLimitSettingC).value()); acc->setUploadLimit(settings.value(networkUploadLimitC).toInt()); acc->setDownloadLimit(settings.value(networkDownloadLimitC).toInt()); + const auto proxyPasswordKey = acc->userIdAtHostWithPort() + QStringLiteral("_proxy_password"); + const auto job = new KeychainChunk::ReadJob(proxyPasswordKey); + connect(job, &KeychainChunk::ReadJob::finished, this, [acc](const KeychainChunk::ReadJob *const finishedJob) { + if (finishedJob->error() == QKeychain::NoError) { + const auto password = finishedJob->textData(); + acc->setProxyPassword(password); + } + }); + job->exec(); + // now the server cert, it is in the general group settings.beginGroup(QLatin1String(generalC)); const auto certs = QSslCertificate::fromData(settings.value(caCertsKeyC).toByteArray()); From e3b002a52dca54e5b6efafdfad23d4581d016f55 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Sun, 7 Jul 2024 23:36:26 +0800 Subject: [PATCH 33/49] Use single-defined constexpr string for proxy password keychain key Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 8cdfc29588e96..a5c1755dc7bdc 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -66,6 +66,8 @@ constexpr auto shibbolethAuthTypeC = "shibboleth"; constexpr auto httpAuthPrefix = "http_"; constexpr auto webflowAuthPrefix = "webflow_"; +constexpr auto networkProxyPasswordKeychainKeySuffixC = "_proxy_password"; + constexpr auto legacyRelativeConfigLocationC = "/ownCloud/owncloud.cfg"; constexpr auto legacyCfgFileNameC = "owncloud.cfg"; @@ -352,7 +354,7 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s settings.setValue(networkUploadLimitC, acc->uploadLimit()); settings.setValue(networkDownloadLimitC, acc->downloadLimit()); - const auto proxyPasswordKey = acc->userIdAtHostWithPort() + QStringLiteral("_proxy_password"); + const auto proxyPasswordKey = acc->userIdAtHostWithPort() + QString::fromUtf8(networkProxyPasswordKeychainKeySuffixC); const auto proxyPassword = acc->proxyPassword(); if (proxyPassword.isEmpty()) { const auto job = new KeychainChunk::DeleteJob(proxyPasswordKey); @@ -493,7 +495,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) acc->setUploadLimit(settings.value(networkUploadLimitC).toInt()); acc->setDownloadLimit(settings.value(networkDownloadLimitC).toInt()); - const auto proxyPasswordKey = acc->userIdAtHostWithPort() + QStringLiteral("_proxy_password"); + const auto proxyPasswordKey = acc->userIdAtHostWithPort() + QString::fromUtf8(networkProxyPasswordKeychainKeySuffixC); const auto job = new KeychainChunk::ReadJob(proxyPasswordKey); connect(job, &KeychainChunk::ReadJob::finished, this, [acc](const KeychainChunk::ReadJob *const finishedJob) { if (finishedJob->error() == QKeychain::NoError) { From 5db01d4849bfa7b00746af72265765770e6ea09f Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 00:05:45 +0800 Subject: [PATCH 34/49] Ensure keychain chunk jobs in account manager run as intended Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index a5c1755dc7bdc..a1afecd65943f 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -358,10 +358,10 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s const auto proxyPassword = acc->proxyPassword(); if (proxyPassword.isEmpty()) { const auto job = new KeychainChunk::DeleteJob(proxyPasswordKey); - job->exec(); + Q_ASSERT(job->exec()); } else { const auto job = new KeychainChunk::WriteJob(proxyPasswordKey, proxyPassword.toUtf8()); - job->exec(); + Q_ASSERT(job->exec()); } if (acc->_credentials) { @@ -503,7 +503,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) acc->setProxyPassword(password); } }); - job->exec(); + Q_ASSERT(job->exec()); // now the server cert, it is in the general group settings.beginGroup(QLatin1String(generalC)); From 2803690285c0b80f5a2759fee69632d78b29f7bc Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 00:07:18 +0800 Subject: [PATCH 35/49] KeychainChunk job exec is synchronous, do not bother with signals in account manager use Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index a1afecd65943f..a92f62f16fc07 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -496,14 +496,12 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) acc->setDownloadLimit(settings.value(networkDownloadLimitC).toInt()); const auto proxyPasswordKey = acc->userIdAtHostWithPort() + QString::fromUtf8(networkProxyPasswordKeychainKeySuffixC); - const auto job = new KeychainChunk::ReadJob(proxyPasswordKey); - connect(job, &KeychainChunk::ReadJob::finished, this, [acc](const KeychainChunk::ReadJob *const finishedJob) { - if (finishedJob->error() == QKeychain::NoError) { - const auto password = finishedJob->textData(); - acc->setProxyPassword(password); - } - }); + const auto job = new KeychainChunk::ReadJob(proxyPasswordKey, this); Q_ASSERT(job->exec()); + if (job->error() == QKeychain::NoError) { + const auto password = job->textData(); + acc->setProxyPassword(password); + } // now the server cert, it is in the general group settings.beginGroup(QLatin1String(generalC)); From 2d0c0690396a0e5ba12e0935758299384474a128 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 00:09:17 +0800 Subject: [PATCH 36/49] Get intended default values for bw limit settings for account when nothing is set Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index a92f62f16fc07..6ef2bafadff4d 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -490,8 +490,16 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) acc->setProxyPort(settings.value(networkProxyPortC).toInt()); acc->setProxyNeedsAuth(settings.value(networkProxyNeedsAuthC).toBool()); acc->setProxyUser(settings.value(networkProxyUserC).toString()); - acc->setUploadLimitSetting(settings.value(networkUploadLimitSettingC).value()); - acc->setDownloadLimitSetting(settings.value(networkDownloadLimitSettingC).value()); + acc->setUploadLimitSetting( + settings.value( + networkUploadLimitSettingC, + QVariant::fromValue(Account::AccountNetworkTransferLimitSetting::GlobalLimit) + ).value()); + acc->setDownloadLimitSetting( + settings.value( + networkDownloadLimitSettingC, + QVariant::fromValue(Account::AccountNetworkTransferLimitSetting::GlobalLimit) + ).value()); acc->setUploadLimit(settings.value(networkUploadLimitC).toInt()); acc->setDownloadLimit(settings.value(networkDownloadLimitC).toInt()); From 01f819915751e79b13edb0fd84c574e1cb717298 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 00:33:07 +0800 Subject: [PATCH 37/49] Use better keychain chunk job constructors Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 6ef2bafadff4d..e40d3efc71fd7 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -357,10 +357,10 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s const auto proxyPasswordKey = acc->userIdAtHostWithPort() + QString::fromUtf8(networkProxyPasswordKeychainKeySuffixC); const auto proxyPassword = acc->proxyPassword(); if (proxyPassword.isEmpty()) { - const auto job = new KeychainChunk::DeleteJob(proxyPasswordKey); + const auto job = new KeychainChunk::DeleteJob(proxyPasswordKey, this); Q_ASSERT(job->exec()); } else { - const auto job = new KeychainChunk::WriteJob(proxyPasswordKey, proxyPassword.toUtf8()); + const auto job = new KeychainChunk::WriteJob(acc, proxyPasswordKey, proxyPassword.toUtf8(), this); Q_ASSERT(job->exec()); } From 70e7bcf9a0f7e5d9126fa0050149031d6c4da39a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 00:35:03 +0800 Subject: [PATCH 38/49] Simplify proxy password keychain keys Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index e40d3efc71fd7..a0f1e837fab9d 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -354,8 +354,8 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s settings.setValue(networkUploadLimitC, acc->uploadLimit()); settings.setValue(networkDownloadLimitC, acc->downloadLimit()); - const auto proxyPasswordKey = acc->userIdAtHostWithPort() + QString::fromUtf8(networkProxyPasswordKeychainKeySuffixC); const auto proxyPassword = acc->proxyPassword(); + const auto proxyPasswordKey = QString(acc->davUser() + networkProxyPasswordKeychainKeySuffixC); if (proxyPassword.isEmpty()) { const auto job = new KeychainChunk::DeleteJob(proxyPasswordKey, this); Q_ASSERT(job->exec()); @@ -503,7 +503,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) acc->setUploadLimit(settings.value(networkUploadLimitC).toInt()); acc->setDownloadLimit(settings.value(networkDownloadLimitC).toInt()); - const auto proxyPasswordKey = acc->userIdAtHostWithPort() + QString::fromUtf8(networkProxyPasswordKeychainKeySuffixC); + const auto proxyPasswordKey = QString(acc->davUser() + networkProxyPasswordKeychainKeySuffixC); const auto job = new KeychainChunk::ReadJob(proxyPasswordKey, this); Q_ASSERT(job->exec()); if (job->error() == QKeychain::NoError) { From a8c5cbced48254262aa407f484ce9bcbc7a5c856 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 00:36:28 +0800 Subject: [PATCH 39/49] Add logging on error for proxy password saving Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index a0f1e837fab9d..148fb47d00344 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -354,14 +354,19 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s settings.setValue(networkUploadLimitC, acc->uploadLimit()); settings.setValue(networkDownloadLimitC, acc->downloadLimit()); - const auto proxyPassword = acc->proxyPassword(); const auto proxyPasswordKey = QString(acc->davUser() + networkProxyPasswordKeychainKeySuffixC); - if (proxyPassword.isEmpty()) { + if (const auto proxyPassword = acc->proxyPassword(); proxyPassword.isEmpty()) { const auto job = new KeychainChunk::DeleteJob(proxyPasswordKey, this); Q_ASSERT(job->exec()); + if (job->error() != QKeychain::NoError) { + qCWarning(lcAccountManager) << "Failed to delete proxy password from keychain" << job->errorString(); + } } else { const auto job = new KeychainChunk::WriteJob(acc, proxyPasswordKey, proxyPassword.toUtf8(), this); Q_ASSERT(job->exec()); + if (job->error() != QKeychain::NoError) { + qCWarning(lcAccountManager) << "Failed to save proxy password to keychain" << job->errorString(); + } } if (acc->_credentials) { @@ -509,6 +514,8 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) if (job->error() == QKeychain::NoError) { const auto password = job->textData(); acc->setProxyPassword(password); + } else { + qCWarning(lcAccountManager) << "Failed to read proxy password from keychain" << job->errorString(); } // now the server cert, it is in the general group From 68cff89c8b733710f1da165035261ebe52c49afe Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 00:36:49 +0800 Subject: [PATCH 40/49] Ensure per-account network settings are saved on change Signed-off-by: Claudio Cambra --- src/gui/networksettings.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index cb78708166c61..d325ae82c9365 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -235,6 +235,7 @@ void NetworkSettings::saveProxySettings() const auto accountState = AccountManager::instance()->accountFromUserId(_account->userIdAtHostWithPort()); accountState->freshConnectionAttempt(); + AccountManager::instance()->saveAccount(_account); } else { ConfigFile().setProxyType(proxyType, host, port, needsAuth, user, password); ClientProxy proxy; @@ -287,6 +288,7 @@ void NetworkSettings::saveBWLimitSettings() _account->setDownloadLimit(downloadLimit); _account->setUploadLimitSetting(static_cast(useUploadLimit)); _account->setUploadLimit(uploadLimit); + AccountManager::instance()->saveAccount(_account); } else { ConfigFile cfg; cfg.setUseDownloadLimit(useDownloadLimit); From 5c0c2afd577eb685c8ce5013f8932a6ea010edd5 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 16:45:41 +0800 Subject: [PATCH 41/49] Move folder status model initialisation to member init list in AccountSettings Signed-off-by: Claudio Cambra --- src/gui/accountsettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index bebc5fa7c40e6..c22bf3094ae49 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -174,12 +174,12 @@ class MouseCursorChanger : public QObject AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) : QWidget(parent) , _ui(new Ui::AccountSettings) + , _model(new FolderStatusModel) , _accountState(accountState) , _userInfo(accountState, false, true) { _ui->setupUi(this); - _model = new FolderStatusModel; _model->setAccountState(_accountState); _model->setParent(this); const auto delegate = new FolderStatusDelegate; From 5b8f9e46cea860e7dd3f0cd51e730d20a5372542 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 16:46:55 +0800 Subject: [PATCH 42/49] Ensure file provider tab is not shown when file provider module not enabled Signed-off-by: Claudio Cambra --- src/gui/accountsettings.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index c22bf3094ae49..27aab10cee8c5 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -209,7 +209,12 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) fileProviderTab->setLayout(fpSettingsLayout); } #else - _ui->tabWidget->setCurrentIndex(0); + const auto tabWidget = _ui->tabWidget; + const auto fileProviderTab = _ui->fileProviderTab; + if (const auto fileProviderWidgetTabIndex = tabWidget->indexOf(fileProviderTab); fileProviderWidgetTabIndex >= 0) { + tabWidget->removeTab(fileProviderWidgetTabIndex); + } + tabWidget->setCurrentIndex(0); #endif const auto connectionSettingsTab = _ui->connectionSettingsTab; From 926c3b6c00609e09197d935364e4dced0cdf8f82 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 16:56:07 +0800 Subject: [PATCH 43/49] Use an AccountPtr instead of raw pointer in networksettings Signed-off-by: Claudio Cambra --- src/gui/accountsettings.cpp | 2 +- src/gui/networksettings.cpp | 16 ++++++++-------- src/gui/networksettings.h | 5 +++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 27aab10cee8c5..0ed49dc2799fb 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -219,7 +219,7 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) const auto connectionSettingsTab = _ui->connectionSettingsTab; const auto connectionSettingsLayout = new QVBoxLayout(connectionSettingsTab); - const auto networkSettings = new NetworkSettings(_accountState->account().get(), connectionSettingsTab); + const auto networkSettings = new NetworkSettings(_accountState->account(), connectionSettingsTab); connectionSettingsLayout->addWidget(networkSettings); connectionSettingsTab->setLayout(connectionSettingsLayout); diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index d325ae82c9365..891882fdec638 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -29,7 +29,7 @@ namespace OCC { -NetworkSettings::NetworkSettings(Account *const account, QWidget *parent) +NetworkSettings::NetworkSettings(const AccountPtr &account, QWidget *parent) : QWidget(parent) , _ui(new Ui::NetworkSettings) , _account(account) @@ -40,7 +40,7 @@ NetworkSettings::NetworkSettings(Account *const account, QWidget *parent) _ui->proxyGroupBox->setVisible(!Theme::instance()->doNotUseProxy()); - if (account == nullptr) { + if (!account) { _ui->globalProxySettingsRadioButton->setVisible(false); _ui->globalDownloadSettingsRadioButton->setVisible(false); _ui->globalUploadSettingsRadioButton->setVisible(false); @@ -124,7 +124,7 @@ void NetworkSettings::loadProxySettings() return; } - const auto useGlobalProxy = _account == nullptr || _account->networkProxySetting() == Account::AccountNetworkProxySetting::GlobalProxy; + const auto useGlobalProxy = !_account || _account->networkProxySetting() == Account::AccountNetworkProxySetting::GlobalProxy; const auto cfgFile = ConfigFile(); const auto proxyType = useGlobalProxy ? cfgFile.proxyType() : _account->proxyType(); const auto proxyPort = useGlobalProxy ? cfgFile.proxyPort() : _account->proxyPort(); @@ -163,14 +163,14 @@ void NetworkSettings::loadProxySettings() void NetworkSettings::loadBWLimitSettings() { - const auto useGlobalLimit = _account == nullptr || _account->downloadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit; + const auto useGlobalLimit = !_account || _account->downloadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit; const auto cfgFile = ConfigFile(); const auto useDownloadLimit = useGlobalLimit ? cfgFile.useDownloadLimit() : static_cast>(_account->downloadLimitSetting()); const auto downloadLimit = useGlobalLimit ? cfgFile.downloadLimit() : _account->downloadLimit(); const auto useUploadLimit = useGlobalLimit ? cfgFile.useUploadLimit() : static_cast>(_account->uploadLimitSetting()); const auto uploadLimit = useGlobalLimit ? cfgFile.uploadLimit() : _account->uploadLimit(); - if (_account != nullptr && _account->downloadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit) { + if (_account && _account->downloadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit) { _ui->globalDownloadSettingsRadioButton->setChecked(true); } else if (useDownloadLimit >= 1) { _ui->downloadLimitRadioButton->setChecked(true); @@ -181,7 +181,7 @@ void NetworkSettings::loadBWLimitSettings() } _ui->downloadSpinBox->setValue(downloadLimit); - if (_account != nullptr && _account->uploadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit) { + if (_account && _account->uploadLimitSetting() == Account::AccountNetworkTransferLimitSetting::GlobalLimit) { _ui->globalUploadSettingsRadioButton->setChecked(true); } else if (useUploadLimit >= 1) { _ui->uploadLimitRadioButton->setChecked(true); @@ -235,7 +235,7 @@ void NetworkSettings::saveProxySettings() const auto accountState = AccountManager::instance()->accountFromUserId(_account->userIdAtHostWithPort()); accountState->freshConnectionAttempt(); - AccountManager::instance()->saveAccount(_account); + AccountManager::instance()->saveAccount(_account.data()); } else { ConfigFile().setProxyType(proxyType, host, port, needsAuth, user, password); ClientProxy proxy; @@ -288,7 +288,7 @@ void NetworkSettings::saveBWLimitSettings() _account->setDownloadLimit(downloadLimit); _account->setUploadLimitSetting(static_cast(useUploadLimit)); _account->setUploadLimit(uploadLimit); - AccountManager::instance()->saveAccount(_account); + AccountManager::instance()->saveAccount(_account.data()); } else { ConfigFile cfg; cfg.setUseDownloadLimit(useDownloadLimit); diff --git a/src/gui/networksettings.h b/src/gui/networksettings.h index 9ebfa3f515026..6fa95bd903381 100644 --- a/src/gui/networksettings.h +++ b/src/gui/networksettings.h @@ -17,6 +17,7 @@ #include +#include "libsync/accountfwd.h" namespace OCC { class Account; @@ -34,7 +35,7 @@ class NetworkSettings : public QWidget Q_OBJECT public: - explicit NetworkSettings(Account *const account = nullptr, QWidget *parent = nullptr); + explicit NetworkSettings(const AccountPtr &account = {}, QWidget *parent = nullptr); ~NetworkSettings() override; [[nodiscard]] QSize sizeHint() const override; @@ -55,7 +56,7 @@ private slots: void loadBWLimitSettings(); Ui::NetworkSettings *_ui; - Account *_account; + AccountPtr _account; }; From 5bc6388760e8b3827b35d78747b20567cf7949ce Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 16:57:16 +0800 Subject: [PATCH 44/49] Add a method to set a specific account's folders' network limits as dirty Signed-off-by: Claudio Cambra --- src/gui/folderman.cpp | 11 +++++++++++ src/gui/folderman.h | 1 + src/gui/networksettings.cpp | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index eab67ee5b9fd7..0dc60e626b8b3 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -1534,6 +1534,17 @@ void FolderMan::setDirtyNetworkLimits() } } +void FolderMan::setDirtyNetworkLimits(const AccountPtr &account) const +{ + const auto folderMapValues = _folderMap.values(); + for (const auto folder : folderMapValues) { + // set only in busy folders. Otherwise they read the config anyway. + if (folder && folder->isBusy() && folder->accountState()->account() == account) { + folder->setDirtyNetworkLimits(); + } + } +} + void FolderMan::leaveShare(const QString &localFile) { const auto localFileNoTrailingSlash = localFile.endsWith('/') ? localFile.chopped(1) : localFile; diff --git a/src/gui/folderman.h b/src/gui/folderman.h index af2d5e092e696..0fcffc9fdd16c 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -227,6 +227,7 @@ class FolderMan : public QObject void setDirtyProxy(); void setDirtyNetworkLimits(); + void setDirtyNetworkLimits(const AccountPtr &account) const; /** removes current user from the share **/ void leaveShare(const QString &localFile); diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index 891882fdec638..74ee54f0294da 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -297,7 +297,7 @@ void NetworkSettings::saveBWLimitSettings() cfg.setUploadLimit(uploadLimit); } - FolderMan::instance()->setDirtyNetworkLimits(); + FolderMan::instance()->setDirtyNetworkLimits(_account); } void NetworkSettings::checkEmptyProxyHost() From ef593998048324eb25fc42c71bb50c14cba16084 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 17:37:34 +0800 Subject: [PATCH 45/49] Use qtkeychain directly in account manager Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 59 ++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 148fb47d00344..3bb5c69949f02 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -31,6 +31,12 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#else +#include +#endif + namespace { constexpr auto urlC = "url"; constexpr auto authTypeC = "authType"; @@ -356,17 +362,28 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s const auto proxyPasswordKey = QString(acc->davUser() + networkProxyPasswordKeychainKeySuffixC); if (const auto proxyPassword = acc->proxyPassword(); proxyPassword.isEmpty()) { - const auto job = new KeychainChunk::DeleteJob(proxyPasswordKey, this); - Q_ASSERT(job->exec()); - if (job->error() != QKeychain::NoError) { - qCWarning(lcAccountManager) << "Failed to delete proxy password from keychain" << job->errorString(); - } + const auto job = new QKeychain::DeletePasswordJob(Theme::instance()->appName(), this); + job->setKey(proxyPasswordKey); + connect(job, &QKeychain::Job::finished, this, [](const QKeychain::Job *const incomingJob) { + if (incomingJob->error() == QKeychain::NoError) { + qCInfo(lcAccountManager) << "Deleted proxy password from keychain"; + } else { + qCWarning(lcAccountManager) << "Failed to delete proxy password to keychain" << incomingJob->errorString(); + } + }); + job->start(); } else { - const auto job = new KeychainChunk::WriteJob(acc, proxyPasswordKey, proxyPassword.toUtf8(), this); - Q_ASSERT(job->exec()); - if (job->error() != QKeychain::NoError) { - qCWarning(lcAccountManager) << "Failed to save proxy password to keychain" << job->errorString(); - } + const auto job = new QKeychain::WritePasswordJob(Theme::instance()->appName(), this); + job->setKey(proxyPasswordKey); + job->setBinaryData(proxyPassword.toUtf8()); + connect(job, &QKeychain::Job::finished, this, [](const QKeychain::Job *const incomingJob) { + if (incomingJob->error() == QKeychain::NoError) { + qCInfo(lcAccountManager) << "Saved proxy password to keychain"; + } else { + qCWarning(lcAccountManager) << "Failed to save proxy password to keychain" << incomingJob->errorString(); + } + }); + job->start(); } if (acc->_credentials) { @@ -509,14 +526,20 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) acc->setDownloadLimit(settings.value(networkDownloadLimitC).toInt()); const auto proxyPasswordKey = QString(acc->davUser() + networkProxyPasswordKeychainKeySuffixC); - const auto job = new KeychainChunk::ReadJob(proxyPasswordKey, this); - Q_ASSERT(job->exec()); - if (job->error() == QKeychain::NoError) { - const auto password = job->textData(); - acc->setProxyPassword(password); - } else { - qCWarning(lcAccountManager) << "Failed to read proxy password from keychain" << job->errorString(); - } + const auto job = new QKeychain::ReadPasswordJob(Theme::instance()->appName(), this); + job->setKey(proxyPasswordKey); + connect(job, &QKeychain::Job::finished, this, [acc](const QKeychain::Job *const incomingJob) { + const auto incomingReadJob = qobject_cast(incomingJob); + if (incomingReadJob->error() == QKeychain::NoError) { + qCInfo(lcAccountManager) << "Read proxy password to keychain for" << acc->userIdAtHostWithPort(); + const auto passwordData = incomingReadJob->binaryData(); + const auto password = QString::fromUtf8(passwordData); + acc->setProxyPassword(password); + } else { + qCWarning(lcAccountManager) << "Failed to read proxy password to keychain" << incomingJob->errorString(); + } + }); + job->start(); // now the server cert, it is in the general group settings.beginGroup(QLatin1String(generalC)); From 37c77d81ecd51adfba6a12d9d873445191203ffb Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 8 Jul 2024 17:41:13 +0800 Subject: [PATCH 46/49] Use full user id at host with port for proxy password keychain Signed-off-by: Claudio Cambra --- src/gui/accountmanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 3bb5c69949f02..e89fdc7e72c6e 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -360,7 +360,7 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s settings.setValue(networkUploadLimitC, acc->uploadLimit()); settings.setValue(networkDownloadLimitC, acc->downloadLimit()); - const auto proxyPasswordKey = QString(acc->davUser() + networkProxyPasswordKeychainKeySuffixC); + const auto proxyPasswordKey = QString(acc->userIdAtHostWithPort() + networkProxyPasswordKeychainKeySuffixC); if (const auto proxyPassword = acc->proxyPassword(); proxyPassword.isEmpty()) { const auto job = new QKeychain::DeletePasswordJob(Theme::instance()->appName(), this); job->setKey(proxyPasswordKey); @@ -525,7 +525,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) acc->setUploadLimit(settings.value(networkUploadLimitC).toInt()); acc->setDownloadLimit(settings.value(networkDownloadLimitC).toInt()); - const auto proxyPasswordKey = QString(acc->davUser() + networkProxyPasswordKeychainKeySuffixC); + const auto proxyPasswordKey = QString(acc->userIdAtHostWithPort() + networkProxyPasswordKeychainKeySuffixC); const auto job = new QKeychain::ReadPasswordJob(Theme::instance()->appName(), this); job->setKey(proxyPasswordKey); connect(job, &QKeychain::Job::finished, this, [acc](const QKeychain::Job *const incomingJob) { From 564be17ce4690263c5f0f263ce9c1e399809b6e2 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 9 Jul 2024 14:37:17 +0800 Subject: [PATCH 47/49] Remove now unused disguiseTabWidget Signed-off-by: Claudio Cambra --- src/gui/accountsettings.cpp | 8 -------- src/gui/accountsettings.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 0ed49dc2799fb..15498d5629f5b 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -1718,14 +1718,6 @@ void AccountSettings::initializeE2eEncryptionSettingsMessage() connect(actionEnableE2e, &QAction::triggered, this, &AccountSettings::slotE2eEncryptionGenerateKeys); } -void AccountSettings::disguiseTabWidget() const -{ - // Ensure all elements of the tab widget are hidden. - // Document mode lets the child view take up the whole view. - _ui->tabWidget->setDocumentMode(true); - _ui->tabWidget->tabBar()->hide(); -} - } // namespace OCC #include "accountsettings.moc" diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h index 117a3aa536a0a..8981f1dffe6f8 100644 --- a/src/gui/accountsettings.h +++ b/src/gui/accountsettings.h @@ -141,8 +141,6 @@ private slots: /// Returns the alias of the selected folder, empty string if none [[nodiscard]] QString selectedFolderAlias() const; - void disguiseTabWidget() const; - Ui::AccountSettings *_ui; FolderStatusModel *_model; From eeb9cc284a0b7efd8c7f8e8fe632f235acd7329c Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 22 Jul 2024 15:58:26 +0800 Subject: [PATCH 48/49] Use application proxy when setting global proxy setting via network settings Signed-off-by: Claudio Cambra --- src/gui/networksettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index 74ee54f0294da..16bb1ad50b72a 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -227,7 +227,7 @@ void NetworkSettings::saveProxySettings() _account->setProxyPassword(password); if (useGlobalProxy) { - _account->networkAccessManager()->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); + _account->networkAccessManager()->setProxy(QNetworkProxy::applicationProxy()); } else { const auto proxy = QNetworkProxy(proxyType, host, port, user, password); _account->networkAccessManager()->setProxy(proxy); From 7dec7b26a018836d66e67bb9e743d0e861cb401f Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 22 Jul 2024 16:17:38 +0800 Subject: [PATCH 49/49] Move all proxy configuration procedures into account and out of network settings Signed-off-by: Claudio Cambra --- src/gui/networksettings.cpp | 17 ++-------------- src/libsync/account.cpp | 39 +++++++++++++++++++++++++++++++++++++ src/libsync/account.h | 8 ++++++++ 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/gui/networksettings.cpp b/src/gui/networksettings.cpp index 16bb1ad50b72a..c0f60b7bb1f37 100644 --- a/src/gui/networksettings.cpp +++ b/src/gui/networksettings.cpp @@ -218,21 +218,8 @@ void NetworkSettings::saveProxySettings() } if (_account) { // We must be setting up network proxy for a specific account - _account->setNetworkProxySetting(useGlobalProxy ? Account::AccountNetworkProxySetting::GlobalProxy : Account::AccountNetworkProxySetting::AccountSpecificProxy); - _account->setProxyType(proxyType); - _account->setProxyHostName(host); - _account->setProxyPort(port); - _account->setProxyNeedsAuth(needsAuth); - _account->setProxyUser(user); - _account->setProxyPassword(password); - - if (useGlobalProxy) { - _account->networkAccessManager()->setProxy(QNetworkProxy::applicationProxy()); - } else { - const auto proxy = QNetworkProxy(proxyType, host, port, user, password); - _account->networkAccessManager()->setProxy(proxy); - } - + const auto proxySetting = useGlobalProxy ? Account::AccountNetworkProxySetting::GlobalProxy : Account::AccountNetworkProxySetting::AccountSpecificProxy; + _account->setProxySettings(proxySetting, proxyType, host, port, needsAuth, user, password); const auto accountState = AccountManager::instance()->accountFromUserId(_account->userIdAtHostWithPort()); accountState->freshConnectionAttempt(); AccountManager::instance()->saveAccount(_account.data()); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index af0efc8f8e9ce..632b3bd3f6e87 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1100,6 +1100,23 @@ void Account::setNetworkProxySetting(const AccountNetworkProxySetting setting) } _networkProxySetting = setting; + if (setting == AccountNetworkProxySetting::AccountSpecificProxy) { + auto proxy = _am->proxy(); + proxy.setType(proxyType()); + proxy.setHostName(proxyHostName()); + proxy.setPort(proxyPort()); + proxy.setUser(proxyUser()); + proxy.setPassword(proxyPassword()); + _am->setProxy(proxy); + } else { + const auto proxy = QNetworkProxy::applicationProxy(); + _am->setProxy(proxy); + setProxyType(proxy.type()); + setProxyHostName(proxy.hostName()); + setProxyPort(proxy.port()); + setProxyUser(proxy.user()); + setProxyPassword(proxy.password()); + } emit networkProxySettingChanged(); } @@ -1228,6 +1245,28 @@ void Account::setProxyPassword(const QString &password) emit proxyPasswordChanged(); } +void Account::setProxySettings(const AccountNetworkProxySetting networkProxySetting, + const QNetworkProxy::ProxyType proxyType, + const QString &hostName, + const int port, + const bool needsAuth, + const QString &user, + const QString &password) +{ + if (networkProxySetting == AccountNetworkProxySetting::GlobalProxy) { + setNetworkProxySetting(networkProxySetting); + return; + } + + setProxyType(proxyType); + setProxyHostName(hostName); + setProxyPort(port); + setProxyNeedsAuth(needsAuth); + setProxyUser(user); + setProxyPassword(password); + setNetworkProxySetting(networkProxySetting); +} + Account::AccountNetworkTransferLimitSetting Account::uploadLimitSetting() const { return _uploadLimitSetting; diff --git a/src/libsync/account.h b/src/libsync/account.h index e58fc3ee44e6f..4afd9f654dc37 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -388,6 +388,14 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] QString proxyPassword() const; void setProxyPassword(const QString &password); + void setProxySettings(const AccountNetworkProxySetting networkProxySetting, + const QNetworkProxy::ProxyType proxyType, + const QString &proxyHostName, + const int proxyPort, + const bool proxyNeedsAuth, + const QString &proxyUser, + const QString &proxyPassword); + [[nodiscard]] AccountNetworkTransferLimitSetting uploadLimitSetting() const; void setUploadLimitSetting(AccountNetworkTransferLimitSetting setting);