From 18a071a62283dfc1c529bc0e9110b77a72a68101 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 17 Oct 2024 09:35:02 +0200 Subject: [PATCH 1/8] Remove checks for the update channel from the getter function. It should only return the value. Signed-off-by: Camila Ayres --- src/libsync/configfile.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index f5efd8eb1fc9e..0bfec5be4ad84 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -707,32 +707,25 @@ QString ConfigFile::defaultUpdateChannel() const if (serverHasValidSubscription() && !isBranded) { if (const auto serverChannel = desktopEnterpriseChannel(); validUpdateChannels().contains(serverChannel)) { - qCWarning(lcConfigFile()) << "Enforcing update channel" << serverChannel << "because that is the desktop enterprise channel returned by the server."; + qCWarning(lcConfigFile()) << "Default update channel is" << serverChannel << "because that is the desktop enterprise channel returned by the server."; return serverChannel; } } if (const auto currentVersionSuffix = Theme::instance()->versionSuffix(); validUpdateChannels().contains(currentVersionSuffix) && !isBranded) { - qCWarning(lcConfigFile()) << "Enforcing update channel" << currentVersionSuffix << "because of the version suffix of the current client."; + qCWarning(lcConfigFile()) << "Default update channel is" << currentVersionSuffix << "because of the version suffix of the current client."; return currentVersionSuffix; } - qCWarning(lcConfigFile()) << "Enforcing default update channel" << defaultUpdateChannelName; + qCWarning(lcConfigFile()) << "Default update channel is" << defaultUpdateChannelName; return defaultUpdateChannelName; } QString ConfigFile::currentUpdateChannel() const { - auto updateChannel = defaultUpdateChannel(); QSettings settings(configFile(), QSettings::IniFormat); - if (const auto configUpdateChannel = settings.value(QLatin1String(updateChannelC), updateChannel).toString(); - validUpdateChannels().contains(configUpdateChannel)) { - qCWarning(lcConfigFile()) << "Config file has a valid update channel:" << configUpdateChannel; - updateChannel = configUpdateChannel; - } - - return updateChannel; + return settings.value(QLatin1String(updateChannelC), defaultUpdateChannel()).toString(); } void ConfigFile::setUpdateChannel(const QString &channel) From d463711a79fba9569cd3aaa282b9c05dc4996ff2 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Wed, 16 Oct 2024 11:43:39 +0200 Subject: [PATCH 2/8] Change the list of update channels when server capabilities change. Signed-off-by: Camila Ayres --- src/gui/accountmanager.cpp | 1 + src/gui/accountmanager.h | 1 + src/gui/generalsettings.cpp | 23 +++++++++++++++-------- src/gui/generalsettings.h | 5 +++++ src/gui/settingsdialog.cpp | 6 ++++-- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 57dfd097bb9cf..e091b4de930fa 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -665,6 +665,7 @@ void AccountManager::addAccountState(AccountState *const accountState) Q_ASSERT(accountState->account()); QObject::connect(accountState->account().data(), &Account::wantsAccountSaved, this, &AccountManager::saveAccount); + QObject::connect(accountState->account().data(), &Account::capabilitiesChanged, this, &AccountManager::capabilitiesChanged); AccountStatePtr ptr(accountState); _accounts << ptr; diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h index 32b7ca8e40aed..768f902ef3c99 100644 --- a/src/gui/accountmanager.h +++ b/src/gui/accountmanager.h @@ -114,6 +114,7 @@ public slots: void accountSyncConnectionRemoved(OCC::AccountState *account); void removeAccountFolders(OCC::AccountState *account); void forceLegacyImportChanged(); + void capabilitiesChanged(); private: // saving and loading Account to settings diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index ab28ca196903f..264bca62b17b6 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -244,6 +244,10 @@ GeneralSettings::GeneralSettings(QWidget *parent) // accountAdded means the wizard was finished and the wizard might change some options. connect(AccountManager::instance(), &AccountManager::accountAdded, this, &GeneralSettings::loadMiscSettings); +#if defined(BUILD_UPDATER) + loadUpdateChannelsList(); +#endif + customizeStyle(); } @@ -284,18 +288,21 @@ void GeneralSettings::loadMiscSettings() _ui->stopExistingFolderNowBigSyncCheckBox->setChecked(_ui->existingFolderLimitCheckBox->isChecked() && cfgFile.stopSyncingExistingFoldersOverLimit()); _ui->newExternalStorage->setChecked(cfgFile.confirmExternalStorage()); _ui->monoIconsCheckBox->setChecked(cfgFile.monoIcons()); +} #if defined(BUILD_UPDATER) - const auto validUpdateChannels = cfgFile.validUpdateChannels(); - _ui->updateChannel->clear(); - _ui->updateChannel->addItems(validUpdateChannels); - const auto currentUpdateChannelIndex = validUpdateChannels.indexOf(cfgFile.currentUpdateChannel()); - _ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1? currentUpdateChannelIndex : 0); - connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged); -#endif +void GeneralSettings::loadUpdateChannelsList() { + ConfigFile cfgFile; + if (_currentUpdateChannelList != cfgFile.validUpdateChannels()) { + _currentUpdateChannelList = cfgFile.validUpdateChannels(); + _ui->updateChannel->clear(); + _ui->updateChannel->addItems(_currentUpdateChannelList); + const auto currentUpdateChannelIndex = _currentUpdateChannelList.indexOf(cfgFile.currentUpdateChannel()); + _ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1? currentUpdateChannelIndex : 0); + connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged); + } } -#if defined(BUILD_UPDATER) void GeneralSettings::slotUpdateInfo() { ConfigFile config; diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index 70a726142db8b..02a8cef3dedf2 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -23,6 +23,7 @@ namespace OCC { class IgnoreListEditor; class SyncLogDialog; +class AccountState; namespace Ui { class GeneralSettings; @@ -43,6 +44,9 @@ class GeneralSettings : public QWidget public slots: void slotStyleChanged(); +#if defined(BUILD_UPDATER) + void loadUpdateChannelsList(); +#endif private slots: void saveMiscSettings(); @@ -67,6 +71,7 @@ private slots: Ui::GeneralSettings *_ui; QPointer _ignoreEditor; bool _currentlyLoading = false; + QStringList _currentUpdateChannelList; }; diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index a59314a15ce73..bd14bb71b043d 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -127,6 +127,8 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) // Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching) connect(this, &SettingsDialog::styleChanged, generalSettings, &GeneralSettings::slotStyleChanged); + connect(AccountManager::instance(), &AccountManager::accountAdded, generalSettings, &GeneralSettings::loadUpdateChannelsList); + connect(AccountManager::instance(), &AccountManager::capabilitiesChanged, generalSettings, &GeneralSettings::loadUpdateChannelsList); QAction *networkAction = createColorAwareAction(QLatin1String(":/client/theme/network.svg"), tr("Network")); _actionGroup->addAction(networkAction); @@ -137,8 +139,8 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) _actionGroupWidgets.insert(generalAction, generalSettings); _actionGroupWidgets.insert(networkAction, networkSettings); - foreach(auto ai, AccountManager::instance()->accounts()) { - accountAdded(ai.data()); + foreach(auto account, AccountManager::instance()->accounts()) { + accountAdded(account.data()); } QTimer::singleShot(1, this, &SettingsDialog::showFirstPage); From 3e4c1c51c2f9c41fb2e38bbf4fbcdf3f0135f374 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 17 Oct 2024 16:47:59 +0200 Subject: [PATCH 3/8] Do not override the subscription value if one of the account has enterprise. Signed-off-by: Camila Ayres --- src/libsync/account.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 401e22ae9a038..676459f8839fe 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1079,7 +1079,7 @@ void Account::updateServerSubcription() { ConfigFile currentConfig; if (const auto serverHasValidSubscription = _capabilities.serverHasValidSubscription(); - serverHasValidSubscription != currentConfig.serverHasValidSubscription()) { + serverHasValidSubscription != currentConfig.serverHasValidSubscription() && !serverHasValidSubscription) { currentConfig.setServerHasValidSubscription(serverHasValidSubscription); } } From 6d01abf8fffd441f0fd0018e0441ed481f61410f Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 17 Oct 2024 16:51:27 +0200 Subject: [PATCH 4/8] Do not override the channels list if one of the account has enterprise. Maintain stable and enterprise. Signed-off-by: Camila Ayres --- src/gui/generalsettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 264bca62b17b6..1152342edeba6 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -293,7 +293,7 @@ void GeneralSettings::loadMiscSettings() #if defined(BUILD_UPDATER) void GeneralSettings::loadUpdateChannelsList() { ConfigFile cfgFile; - if (_currentUpdateChannelList != cfgFile.validUpdateChannels()) { + if (_currentUpdateChannelList != cfgFile.validUpdateChannels() && !cfgFile.serverHasValidSubscription()) { _currentUpdateChannelList = cfgFile.validUpdateChannels(); _ui->updateChannel->clear(); _ui->updateChannel->addItems(_currentUpdateChannelList); From 0421f228cf9545e0a8630f35a43621c26034e77a Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 17 Oct 2024 18:40:06 +0200 Subject: [PATCH 5/8] Save serverHasValidsubcription in the account. Signed-off-by: Camila Ayres --- src/gui/accountmanager.cpp | 2 +- src/libsync/account.cpp | 21 ++++++++++++++++++--- src/libsync/account.h | 5 +++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index e091b4de930fa..b23f31e7133d8 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -338,7 +338,7 @@ void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool s settings.setValue(QLatin1String(serverVersionC), acc->_serverVersion); settings.setValue(QLatin1String(serverColorC), acc->_serverColor); settings.setValue(QLatin1String(serverTextColorC), acc->_serverTextColor); - settings.setValue(QLatin1String(serverHasValidSubscriptionC), acc->capabilities().serverHasValidSubscription()); + settings.setValue(QLatin1String(serverHasValidSubscriptionC), acc->serverHasValidSubscription()); if (!acc->_skipE2eeMetadataChecksumValidation) { settings.remove(QLatin1String(skipE2eeMetadataChecksumValidationC)); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 676459f8839fe..362164148f8e1 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1075,13 +1075,28 @@ void Account::setAskUserForMnemonic(const bool ask) emit askUserForMnemonicChanged(); } +bool Account::serverHasValidSubscription() const +{ + return _serverHasValidSubscription; +} + +void Account::setServerHasValidSubscription(bool valid) +{ + if (_serverHasValidSubscription != valid) { + _serverHasValidSubscription = valid; + } +} + void Account::updateServerSubcription() { ConfigFile currentConfig; - if (const auto serverHasValidSubscription = _capabilities.serverHasValidSubscription(); - serverHasValidSubscription != currentConfig.serverHasValidSubscription() && !serverHasValidSubscription) { - currentConfig.setServerHasValidSubscription(serverHasValidSubscription); + const auto capabilityValidSubscription = _capabilities.serverHasValidSubscription(); + const auto configValidSubscription = currentConfig.serverHasValidSubscription(); + if (capabilityValidSubscription != configValidSubscription && !configValidSubscription) { + currentConfig.setServerHasValidSubscription(capabilityValidSubscription); } + + setServerHasValidSubscription(capabilityValidSubscription); } void Account::updateDesktopEnterpriseChannel() diff --git a/src/libsync/account.h b/src/libsync/account.h index 4afd9f654dc37..abceb28541f7e 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -409,6 +409,9 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject [[nodiscard]] unsigned int downloadLimit() const; void setDownloadLimit(unsigned int kbytes); + [[nodiscard]] bool serverHasValidSubscription() const; + void setServerHasValidSubscription(bool valid); + public slots: /// Used when forgetting credentials void clearQNAMCache(); @@ -552,6 +555,8 @@ private slots: unsigned int _uploadLimit = 0; unsigned int _downloadLimit = 0; + bool _serverHasValidSubscription = false; + /* IMPORTANT - remove later - FIXME MS@2019-12-07 --> * TODO: For "Log out" & "Remove account": Remove client CA certs and KEY! * From cd93ec3489f82d852639033bf232ae23a8d6fd8e Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 17 Oct 2024 19:53:59 +0200 Subject: [PATCH 6/8] Fix logic for initial load of update channels and priority for user with subscription. Signed-off-by: Camila Ayres --- src/gui/generalsettings.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 1152342edeba6..57936b7182c88 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -293,8 +293,9 @@ void GeneralSettings::loadMiscSettings() #if defined(BUILD_UPDATER) void GeneralSettings::loadUpdateChannelsList() { ConfigFile cfgFile; - if (_currentUpdateChannelList != cfgFile.validUpdateChannels() && !cfgFile.serverHasValidSubscription()) { - _currentUpdateChannelList = cfgFile.validUpdateChannels(); + const auto validUpdateChannels = cfgFile.validUpdateChannels(); + if (_currentUpdateChannelList.isEmpty() || (_currentUpdateChannelList != validUpdateChannels && !cfgFile.serverHasValidSubscription())) { + _currentUpdateChannelList = validUpdateChannels; _ui->updateChannel->clear(); _ui->updateChannel->addItems(_currentUpdateChannelList); const auto currentUpdateChannelIndex = _currentUpdateChannelList.indexOf(cfgFile.currentUpdateChannel()); From 74a70c6bed9fd6905c6aa4f1a2753cfa84a859bf Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 17 Oct 2024 20:55:19 +0200 Subject: [PATCH 7/8] Update config value when serverHasValidSubscription when accounts are added or removed. To give priority to server susbscriptions and keep listing the right update channels. Signed-off-by: Camila Ayres --- src/gui/accountmanager.cpp | 26 ++++++++++++++++++++++++++ src/gui/accountmanager.h | 3 +++ src/gui/settingsdialog.cpp | 1 + 3 files changed, 30 insertions(+) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index b23f31e7133d8..4245d683b407d 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -606,10 +606,30 @@ void AccountManager::deleteAccount(OCC::AccountState *account) account->account()->deleteAppToken(); + // clean up config from subscriptions if the account removed was the only with valid subscription + if (account->account()->serverHasValidSubscription()) { + updateServerHasValidSubscriptionConfig(); + } + emit accountSyncConnectionRemoved(account); emit accountRemoved(account); } +void AccountManager::updateServerHasValidSubscriptionConfig() +{ + auto serverHasValidSubscription = false; + for (const auto &account : _accounts) { + if (!account->account()->serverHasValidSubscription()) { + continue; + } + + serverHasValidSubscription = true; + break; + } + + ConfigFile().setServerHasValidSubscription(serverHasValidSubscription); +} + AccountPtr AccountManager::createAccount() { const auto acc = Account::create(); @@ -670,6 +690,12 @@ void AccountManager::addAccountState(AccountState *const accountState) AccountStatePtr ptr(accountState); _accounts << ptr; ptr->trySignIn(); + + // update config subscriptions if the account added is the only with valid subscription + if (accountState->account()->serverHasValidSubscription() && !ConfigFile().serverHasValidSubscription()) { + updateServerHasValidSubscriptionConfig(); + } + emit accountAdded(accountState); } diff --git a/src/gui/accountmanager.h b/src/gui/accountmanager.h index 768f902ef3c99..85a244ced4fb5 100644 --- a/src/gui/accountmanager.h +++ b/src/gui/accountmanager.h @@ -129,6 +129,9 @@ public slots: // Adds an account to the tracked list, emitting accountAdded() void addAccountState(AccountState *const accountState); + // update config serverHasValidSubscription when accounts list changes + void updateServerHasValidSubscriptionConfig(); + AccountManager() = default; QList _accounts; /// Account ids from settings that weren't read diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index bd14bb71b043d..429808d66ee1a 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -128,6 +128,7 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) // Connect styleChanged events to our widgets, so they can adapt (Dark-/Light-Mode switching) connect(this, &SettingsDialog::styleChanged, generalSettings, &GeneralSettings::slotStyleChanged); connect(AccountManager::instance(), &AccountManager::accountAdded, generalSettings, &GeneralSettings::loadUpdateChannelsList); + connect(AccountManager::instance(), &AccountManager::accountRemoved, generalSettings, &GeneralSettings::loadUpdateChannelsList); connect(AccountManager::instance(), &AccountManager::capabilitiesChanged, generalSettings, &GeneralSettings::loadUpdateChannelsList); QAction *networkAction = createColorAwareAction(QLatin1String(":/client/theme/network.svg"), tr("Network")); From 7d5db8e9f72276ebfb34d8233bca8103b312b382 Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 17 Oct 2024 21:04:56 +0200 Subject: [PATCH 8/8] Address PR feedback. Signed-off-by: Camila Ayres --- src/gui/generalsettings.cpp | 2 +- src/gui/settingsdialog.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 57936b7182c88..d9fcbefe284cd 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -299,7 +299,7 @@ void GeneralSettings::loadUpdateChannelsList() { _ui->updateChannel->clear(); _ui->updateChannel->addItems(_currentUpdateChannelList); const auto currentUpdateChannelIndex = _currentUpdateChannelList.indexOf(cfgFile.currentUpdateChannel()); - _ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1? currentUpdateChannelIndex : 0); + _ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1 ? currentUpdateChannelIndex : 0); connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged); } } diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index 429808d66ee1a..261526e11ac27 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -140,7 +140,8 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) _actionGroupWidgets.insert(generalAction, generalSettings); _actionGroupWidgets.insert(networkAction, networkSettings); - foreach(auto account, AccountManager::instance()->accounts()) { + const auto accountsList = AccountManager::instance()->accounts(); + for (const auto &account : accountsList) { accountAdded(account.data()); }