Skip to content

Commit

Permalink
Move all proxy configuration procedures into account and out of netwo…
Browse files Browse the repository at this point in the history
…rk settings

Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Jul 22, 2024
1 parent eeb9cc2 commit 7dec7b2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/gui/networksettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
39 changes: 39 additions & 0 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 7dec7b2

Please sign in to comment.