diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index c6102a7d7..a6b96d45b 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)); @@ -611,10 +611,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,10 +690,17 @@ 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; 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 32b7ca8e4..85a244ced 100644 --- a/src/gui/accountmanager.h +++ b/src/gui/accountmanager.h @@ -114,6 +114,7 @@ signals: void accountSyncConnectionRemoved(OCC::AccountState *account); void removeAccountFolders(OCC::AccountState *account); void forceLegacyImportChanged(); + void capabilitiesChanged(); private: // saving and loading Account to settings @@ -128,6 +129,9 @@ private: // 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/generalsettings.cpp b/src/gui/generalsettings.cpp index ab28ca196..d9fcbefe2 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,22 @@ 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 } #if defined(BUILD_UPDATER) +void GeneralSettings::loadUpdateChannelsList() { + ConfigFile cfgFile; + 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()); + _ui->updateChannel->setCurrentIndex(currentUpdateChannelIndex != -1 ? currentUpdateChannelIndex : 0); + connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged); + } +} + void GeneralSettings::slotUpdateInfo() { ConfigFile config; diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index 70a726142..02a8cef3d 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 @@ public: public slots: void slotStyleChanged(); +#if defined(BUILD_UPDATER) + void loadUpdateChannelsList(); +#endif private slots: void saveMiscSettings(); @@ -67,6 +71,7 @@ private: Ui::GeneralSettings *_ui; QPointer _ignoreEditor; bool _currentlyLoading = false; + QStringList _currentUpdateChannelList; }; diff --git a/src/gui/settingsdialog.cpp b/src/gui/settingsdialog.cpp index a59314a15..fc09c0cdc 100644 --- a/src/gui/settingsdialog.cpp +++ b/src/gui/settingsdialog.cpp @@ -128,6 +128,12 @@ 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); +#if defined(BUILD_UPDATER) + connect(AccountManager::instance(), &AccountManager::accountAdded, generalSettings, &GeneralSettings::loadUpdateChannelsList); + connect(AccountManager::instance(), &AccountManager::accountRemoved, generalSettings, &GeneralSettings::loadUpdateChannelsList); + connect(AccountManager::instance(), &AccountManager::capabilitiesChanged, generalSettings, &GeneralSettings::loadUpdateChannelsList); +#endif + QAction *networkAction = createColorAwareAction(QLatin1String(":/client/theme/network.svg"), tr("Network")); _actionGroup->addAction(networkAction); _toolBar->addAction(networkAction); @@ -137,8 +143,9 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) _actionGroupWidgets.insert(generalAction, generalSettings); _actionGroupWidgets.insert(networkAction, networkSettings); - foreach(auto ai, AccountManager::instance()->accounts()) { - accountAdded(ai.data()); + const auto accountsList = AccountManager::instance()->accounts(); + for (const auto &account : accountsList) { + accountAdded(account.data()); } QTimer::singleShot(1, this, &SettingsDialog::showFirstPage); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 7f9d93c93..df4030de8 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1076,13 +1076,26 @@ void Account::setAskUserForMnemonic(const bool ask) emit askUserForMnemonicChanged(); } +bool Account::serverHasValidSubscription() const +{ + return _serverHasValidSubscription; +} + +void Account::setServerHasValidSubscription(bool valid) +{ + _serverHasValidSubscription = valid; +} + void Account::updateServerSubcription() { ConfigFile currentConfig; - if (const auto serverHasValidSubscription = _capabilities.serverHasValidSubscription(); - serverHasValidSubscription != currentConfig.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 92a132ef6..6333164ad 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -409,6 +409,9 @@ public: [[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(); @@ -553,6 +556,8 @@ private: 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! * diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 7e62925c7..1f571de3c 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)