diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index a2cfd8d1b4ca1..37117ed975adb 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -97,7 +97,7 @@ bool AccountManager::restore(bool alsoRestoreLegacySettings) for (const auto &accountId : settingsChildGroups) { settings->beginGroup(accountId); if (!skipSettingsKeys.contains(settings->group())) { - if (const auto acc = loadAccountHelper(*settings)) { + if (const auto acc = loadAccountHelper(*settings, *ConfigFile::localSettings())) { acc->_id = accountId; if (auto accState = AccountState::loadFromSettings(acc, *settings)) { auto jar = qobject_cast(acc->_am->cookieJar()); @@ -232,7 +232,7 @@ bool AccountManager::restoreFromLegacySettings() const auto childGroups = settings->childGroups(); for (const auto &accountId : childGroups) { settings->beginGroup(accountId); - if (const auto acc = loadAccountHelper(*settings)) { + if (const auto acc = loadAccountHelper(*settings, *ConfigFile::localSettings())) { addAccount(acc); return true; @@ -248,7 +248,7 @@ void AccountManager::save(bool saveCredentials) settings->setValue(QLatin1String(versionC), maxAccountsVersion); for (const auto &acc : qAsConst(_accounts)) { settings->beginGroup(acc->account()->id()); - saveAccountHelper(acc->account().data(), *settings, saveCredentials); + saveAccountHelper(acc->account().data(), *settings, *ConfigFile::localSettings(), saveCredentials); acc->writeToSettings(*settings); settings->endGroup(); } @@ -261,8 +261,9 @@ void AccountManager::saveAccount(Account *a) { qCDebug(lcAccountManager) << "Saving account" << a->url().toString(); const auto settings = ConfigFile::settingsWithGroup(QLatin1String(accountsC)); + const auto localData = ConfigFile::localSettings(); settings->beginGroup(a->id()); - saveAccountHelper(a, *settings, false); // don't save credentials they might not have been loaded yet + saveAccountHelper(a, *settings, *localData, false); // don't save credentials they might not have been loaded yet settings->endGroup(); settings->sync(); @@ -281,14 +282,13 @@ void AccountManager::saveAccountState(AccountState *a) qCDebug(lcAccountManager) << "Saved account state settings, status:" << settings->status(); } -void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool saveCredentials) +void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, QSettings &localData, bool saveCredentials) { settings.setValue(QLatin1String(versionC), maxAccountVersion); settings.setValue(QLatin1String(urlC), acc->_url.toString()); settings.setValue(QLatin1String(davUserC), acc->_davUser); settings.setValue(QLatin1String(displayNameC), acc->_displayName); - settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion); - + localData.setValue(QLatin1String(serverVersionC), acc->_serverVersion); if (acc->_credentials) { if (saveCredentials) { // Only persist the credentials if the parameter is set, on migration from 1.8.x @@ -335,7 +335,7 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s } } -AccountPtr AccountManager::loadAccountHelper(QSettings &settings) +AccountPtr AccountManager::loadAccountHelper(QSettings &settings, QSettings &localData) { const auto urlConfig = settings.value(QLatin1String(urlC)); if (!urlConfig.isValid()) { @@ -386,7 +386,8 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) qCInfo(lcAccountManager) << "Account for" << acc->url() << "using auth type" << authType; - acc->_serverVersion = settings.value(QLatin1String(serverVersionC)).toString(); + acc->_serverVersion = localData.value(QLatin1String(serverVersionC)).toString(); + acc->_davUser = settings.value(QLatin1String(davUserC), "").toString(); // We want to only restore settings for that auth type and the user value diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h index c1c56c7cc1e5d..30a18a9a03512 100644 --- a/src/gui/accountmanager.h +++ b/src/gui/accountmanager.h @@ -90,8 +90,8 @@ class AccountManager : public QObject private: // saving and loading Account to settings - void saveAccountHelper(Account *account, QSettings &settings, bool saveCredentials = true); - AccountPtr loadAccountHelper(QSettings &settings); + void saveAccountHelper(Account *account, QSettings &settings, QSettings &localData, bool saveCredentials = true); + AccountPtr loadAccountHelper(QSettings &settings, QSettings &localData); bool restoreFromLegacySettings(); diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 08064026f4058..b6185af011983 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -270,7 +270,7 @@ void ConfigFile::saveGeometry(QWidget *w) { #ifndef TOKEN_AUTH_ONLY ASSERT(!w->objectName().isNull()); - QSettings settings(configFile(), QSettings::IniFormat); + QSettings settings(localConfigFile(), QSettings::IniFormat); settings.beginGroup(w->objectName()); settings.setValue(QLatin1String(geometryC), w->saveGeometry()); settings.sync(); @@ -291,7 +291,7 @@ void ConfigFile::saveGeometryHeader(QHeaderView *header) return; ASSERT(!header->objectName().isEmpty()); - QSettings settings(configFile(), QSettings::IniFormat); + QSettings settings(localConfigFile(), QSettings::IniFormat); settings.beginGroup(header->objectName()); settings.setValue(QLatin1String(geometryC), header->saveState()); settings.sync(); @@ -305,7 +305,7 @@ void ConfigFile::restoreGeometryHeader(QHeaderView *header) return; ASSERT(!header->objectName().isNull()); - QSettings settings(configFile(), QSettings::IniFormat); + QSettings settings(localConfigFile(), QSettings::IniFormat); settings.beginGroup(header->objectName()); header->restoreState(settings.value(geometryC).toByteArray()); #endif @@ -363,6 +363,17 @@ QString ConfigFile::configPath() const return dir; } +QString ConfigFile::localConfigFile() const +{ + const QString settingspath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + if(!QDir(settingspath).exists()) { + QDir().mkdir(settingspath); + } + QString filename = settingspath + QLatin1String("/") + QLatin1String("settings.cfg"); + +return filename; +} + static const QLatin1String exclFile("sync-exclude.lst"); QString ConfigFile::excludeFile(Scope scope) const @@ -775,7 +786,7 @@ QVariant ConfigFile::getValue(const QString ¶m, const QString &group, systemSetting = systemSettings.value(param, defaultValue); } - QSettings settings(configFile(), QSettings::IniFormat); + QSettings settings((param != QLatin1String(geometryC)) ? configFile() : localConfigFile(), QSettings::IniFormat); if (!group.isEmpty()) settings.beginGroup(group); @@ -1070,13 +1081,13 @@ void ConfigFile::setCertificatePasswd(const QString &cPasswd) QString ConfigFile::clientVersionString() const { - QSettings settings(configFile(), QSettings::IniFormat); + QSettings settings(localConfigFile(), QSettings::IniFormat); return settings.value(QLatin1String(clientVersionC), QString()).toString(); } void ConfigFile::setClientVersionString(const QString &version) { - QSettings settings(configFile(), QSettings::IniFormat); + QSettings settings(localConfigFile(), QSettings::IniFormat); settings.setValue(QLatin1String(clientVersionC), version); } @@ -1094,6 +1105,13 @@ std::unique_ptr ConfigFile::settingsWithGroup(const QString &group, Q return settings; } +std::unique_ptr ConfigFile::localSettings(QObject *parent) +{ + ConfigFile cfg; + std::unique_ptr settings(std::make_unique(cfg.localConfigFile(), QSettings::IniFormat, parent)); + return settings; +} + void ConfigFile::setupDefaultExcludeFilePaths(ExcludedFiles &excludedFiles) { ConfigFile cfg; diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index 719cce0835ada..046cd1227d4a0 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -45,7 +45,9 @@ class OWNCLOUDSYNC_EXPORT ConfigFile [[nodiscard]] QString configPath() const; [[nodiscard]] QString configFile() const; + [[nodiscard]] QString localConfigFile() const; [[nodiscard]] QString excludeFile(Scope scope) const; + static QString excludeFileFromSystem(); // doesn't access config dir /** @@ -209,6 +211,8 @@ class OWNCLOUDSYNC_EXPORT ConfigFile with the given parent. If no parent is specified, the caller must destroy the settings */ static std::unique_ptr settingsWithGroup(const QString &group, QObject *parent = nullptr); + static std::unique_ptr localSettings(QObject *parent = nullptr); + /// Add the system and user exclude file path to the ExcludedFiles instance. static void setupDefaultExcludeFilePaths(ExcludedFiles &excludedFiles);