Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 63 additions & 50 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2015 ownCloud GmbH
Expand Down Expand Up @@ -46,6 +46,7 @@
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";
Expand Down Expand Up @@ -139,8 +140,8 @@
jar->restore(acc->cookieJarPath());
}
addAccountState(accState);
migrateNetworkSettings(acc, *settings);
settings->endGroup();
moveNetworkSettingsFromGlobalToAccount(acc);
} else {
qCInfo(lcAccountManager) << "Account" << accountId << "is too new, ignoring";
_additionalBlockedAccountIds.insert(accountId);
Expand Down Expand Up @@ -294,6 +295,9 @@
configFile.setVfsEnabled(settings->value(ConfigFile::isVfsEnabledC, configFile.isVfsEnabled()).toBool());
configFile.setLaunchOnSystemStartup(settings->value(ConfigFile::launchOnSystemStartupC,
configFile.launchOnSystemStartup()).toBool());
const auto useMonoIcons = settings->value(ConfigFile::monoIconsC, configFile.monoIcons()).toBool();
Theme::instance()->setSystrayUseMonoIcons(useMonoIcons);
configFile.setMonoIcons(useMonoIcons);
configFile.setOptionalServerNotifications(settings->value(ConfigFile::optionalServerNotificationsC,
configFile.optionalServerNotifications()).toBool());
configFile.setPromptDeleteFiles(settings->value(ConfigFile::promptDeleteC,
Expand All @@ -320,7 +324,8 @@
: ConfigFile::unbrandedAppName;
const auto updaterGroupName = QString("%1/%2").arg(previousAppName, ConfigFile::autoUpdateCheckC);
configFile.setAutoUpdateCheck(settings->value(updaterGroupName, configFile.autoUpdateCheck()).toBool(), {});
// Network

// Global Proxy and Network
ClientProxy().saveProxyConfigurationFromSettings(*settings);
configFile.setUseUploadLimit(settings->value(ConfigFile::useUploadLimitC, configFile.useUploadLimit()).toInt());
configFile.setUploadLimit(settings->value(ConfigFile::uploadLimitC, configFile.uploadLimit()).toInt());
Expand All @@ -339,8 +344,8 @@
continue;
}
addAccount(acc);
migrateNetworkSettings(acc, *settings);
settings->endGroup();
moveNetworkSettingsFromGlobalToAccount(acc);
}
configFile.cleanupGlobalNetworkConfiguration();
ClientProxy().cleanupGlobalNetworkConfiguration();
Expand Down Expand Up @@ -507,30 +512,60 @@
}
}

void AccountManager::moveNetworkSettingsFromGlobalToAccount(const AccountPtr &account)
void AccountManager::migrateNetworkSettings(const AccountPtr &account, const QSettings &settings)
{
// QSettings from old ConfigFile to new ConfigFile to Account
auto accountProxyType = settings.value(networkProxyTypeC).value<QNetworkProxy::ProxyType>();
auto accountProxyHost = settings.value(networkProxyHostNameC).toString();
auto accountProxyPort = settings.value(networkProxyPortC).toInt();
auto accountProxyNeedsAuth = settings.value(networkProxyNeedsAuthC).toBool();
auto accountProxyUser = settings.value(networkProxyUserC).toString();

// Override user settings with global settings if user is set to use global settings
ConfigFile configFile;
const auto hostname = configFile.proxyHostName();

if (!hostname.isEmpty()) {
account->setProxySettings(static_cast<QNetworkProxy::ProxyType>(configFile.proxyType()),
hostname,
configFile.proxyPort(),
configFile.proxyNeedsAuth(),
configFile.proxyUser(),
configFile.proxyPassword());
}

const auto useUploadLimit = configFile.useUploadLimit();
const auto useDownloadLimit = configFile.useDownloadLimit();
if (useUploadLimit == 0 && useDownloadLimit == 0) {
return;
auto accountProxySetting = settings.value(networkProxySettingC).toInt();
if (accountProxySetting == 0 && configFile.isMigrationInProgress()) {
accountProxyType = static_cast<QNetworkProxy::ProxyType>(configFile.proxyType());
accountProxyHost = configFile.proxyHostName();
accountProxyPort = configFile.proxyPort();
accountProxyNeedsAuth = configFile.proxyNeedsAuth();
accountProxyUser = configFile.proxyUser();
qCInfo(lcAccountManager) << "Account is using global settings:" << accountProxyType;
}
account->setProxyType(accountProxyType);
account->setProxyHostName(accountProxyHost);
account->setProxyPort(accountProxyPort);
account->setProxyNeedsAuth(accountProxyNeedsAuth);
account->setProxyUser(accountProxyUser);
const auto globalUseUploadLimit = static_cast<Account::AccountNetworkTransferLimitSetting>(configFile.useUploadLimit());
const auto globalUseDownloadLimit = static_cast<Account::AccountNetworkTransferLimitSetting>(configFile.useDownloadLimit());
// User network settings
auto userUseUploadLimit = static_cast<Account::AccountNetworkTransferLimitSetting>(settings.value(networkUploadLimitSettingC,
QVariant::fromValue(account->uploadLimitSetting())).toInt());
auto userUploadLimit = settings.value(networkUploadLimitC, account->uploadLimit()).toInt();
auto userUseDownloadLimit = static_cast<Account::AccountNetworkTransferLimitSetting>(settings.value(networkDownloadLimitSettingC,
QVariant::fromValue(account->downloadLimitSetting())).toInt());
auto userDownloadLimit = settings.value(networkDownloadLimitC, account->downloadLimit()).toInt();
if (userUseUploadLimit == Account::AccountNetworkTransferLimitSetting::LegacyGlobalLimit) {
userUseUploadLimit = globalUseUploadLimit;
userUploadLimit = configFile.uploadLimit();
qCDebug(lcAccountManager) << "Overriding upload limit with global setting:" << userUseUploadLimit
<< "- upload limit:" << userUploadLimit;
}
if (userUseDownloadLimit == Account::AccountNetworkTransferLimitSetting::LegacyGlobalLimit) {
userUseDownloadLimit = globalUseDownloadLimit;
userDownloadLimit = configFile.downloadLimit();
qCDebug(lcAccountManager) << "Overriding download limit with global setting" << userUseDownloadLimit
<< "- download limit:" << userDownloadLimit;
}
if (userUseUploadLimit != Account::AccountNetworkTransferLimitSetting::NoLimit) {
account->setUploadLimitSetting(userUseUploadLimit);
account->setUploadLimit(userUploadLimit);
}
if (userUseDownloadLimit != Account::AccountNetworkTransferLimitSetting::NoLimit) {
account->setDownloadLimitSetting(userUseDownloadLimit);
account->setDownloadLimit(userDownloadLimit);
}

account->setUploadLimitSetting(static_cast<Account::AccountNetworkTransferLimitSetting>(useUploadLimit));
account->setUploadLimit(configFile.uploadLimit());
account->setDownloadLimitSetting(static_cast<Account::AccountNetworkTransferLimitSetting>(useDownloadLimit));
account->setDownloadLimit(configFile.downloadLimit());
}

AccountPtr AccountManager::loadAccountHelper(QSettings &settings)
Expand Down Expand Up @@ -606,31 +641,6 @@
}
acc->setCredentials(CredentialsFactory::create(authType));

{
auto accountProxyType = settings.value(networkProxyTypeC).value<QNetworkProxy::ProxyType>();
auto accountProxyHost = settings.value(networkProxyHostNameC).toString();
auto accountProxyPort = settings.value(networkProxyPortC).toInt();
auto accountProxyNeedsAuth = settings.value(networkProxyNeedsAuthC).toBool();
auto accountProxyUser = settings.value(networkProxyUserC).toString();
const auto globalProxyType = settings.value(ClientProxy::proxyTypeC).value<QNetworkProxy::ProxyType>();
qCDebug(lcAccountManager) << "Account proxy type:" << accountProxyType;
qCDebug(lcAccountManager) << "Global proxy type:" << globalProxyType;
if (accountProxyType == QNetworkProxy::NoProxy && globalProxyType != QNetworkProxy::NoProxy) {
accountProxyType = globalProxyType;
accountProxyHost = settings.value(ClientProxy::proxyHostC).toString();
accountProxyPort = settings.value(ClientProxy::proxyPortC).toInt();
accountProxyNeedsAuth = settings.value(ClientProxy::proxyNeedsAuthC).toBool();
accountProxyUser = settings.value(ClientProxy::proxyUserC).toString();
qCInfo(lcAccountManager) << "Account has no proxy set, using global proxy instead.";
}

acc->setProxyType(accountProxyType);
acc->setProxyHostName(accountProxyHost);
acc->setProxyPort(accountProxyPort);
acc->setProxyNeedsAuth(accountProxyNeedsAuth);
acc->setProxyUser(accountProxyUser);
}

acc->setUploadLimitSetting(
settings.value(
networkUploadLimitSettingC,
Expand All @@ -644,8 +654,11 @@
acc->setUploadLimit(settings.value(networkUploadLimitC).toInt());
acc->setDownloadLimit(settings.value(networkDownloadLimitC).toInt());

ConfigFile configFile;
const auto proxyPasswordKey = QString(acc->userIdAtHostWithPort() + networkProxyPasswordKeychainKeySuffixC);
const auto job = new QKeychain::ReadPasswordJob(Theme::instance()->appName(), this);
const auto appName = configFile.isUnbrandedToBrandedMigrationInProgress() ? ConfigFile::unbrandedAppName
: Theme::instance()->appName();
const auto job = new QKeychain::ReadPasswordJob(appName, this);
job->setKey(proxyPasswordKey);
connect(job, &QKeychain::Job::finished, this, [acc](const QKeychain::Job *const incomingJob) {
const auto incomingReadJob = qobject_cast<const QKeychain::ReadPasswordJob *>(incomingJob);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/accountmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include "account.h"

Check failure on line 9 in src/gui/accountmanager.h

View workflow job for this annotation

GitHub Actions / build

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

'account.h' file not found
#include "accountstate.h"

namespace OCC {
Expand Down Expand Up @@ -113,7 +113,7 @@
// saving and loading Account to settings
void saveAccountHelper(const AccountPtr &account, QSettings &settings, bool saveCredentials = true);
AccountPtr loadAccountHelper(QSettings &settings);
void moveNetworkSettingsFromGlobalToAccount(const AccountPtr &account);
void migrateNetworkSettings(const AccountPtr &account, const QSettings &settings);

bool restoreFromLegacySettings();

Expand Down
2 changes: 0 additions & 2 deletions src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@
namespace {
static constexpr char showMainDialogAsNormalWindowC[] = "showMainDialogAsNormalWindow";
static constexpr char showConfigBackupWarningC[] = "showConfigBackupWarning";

static constexpr char remotePollIntervalC[] = "remotePollInterval";
static constexpr char forceSyncIntervalC[] = "forceSyncInterval";
static constexpr char fullLocalDiscoveryIntervalC[] = "fullLocalDiscoveryInterval";
static constexpr char notificationRefreshIntervalC[] = "notificationRefreshInterval";
static constexpr char monoIconsC[] = "monoIcons";
static constexpr char deleteFilesThresholdC[] = "deleteFilesThreshold";
static constexpr char skipUpdateCheckC[] = "skipUpdateCheck";
static constexpr char updateCheckIntervalC[] = "updateCheckInterval";
Expand Down
1 change: 1 addition & 0 deletions src/libsync/configfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef CONFIGFILE_H
#define CONFIGFILE_H

#include "owncloudlib.h"

Check failure on line 10 in src/libsync/configfile.h

View workflow job for this annotation

GitHub Actions / build

src/libsync/configfile.h:10:10 [clang-diagnostic-error]

'owncloudlib.h' file not found
#include <memory>
#include <QSharedPointer>
#include <QSettings>
Expand Down Expand Up @@ -274,6 +274,7 @@

static constexpr char isVfsEnabledC[] = "isVfsEnabled";
static constexpr char launchOnSystemStartupC[] = "launchOnSystemStartup";
static constexpr char monoIconsC[] = "monoIcons";
static constexpr char optionalServerNotificationsC[] = "optionalServerNotifications";
static constexpr char promptDeleteC[] = "promptDeleteAllFiles";
static constexpr char showCallNotificationsC[] = "showCallNotifications";
Expand Down
Loading