From 74a70c6bed9fd6905c6aa4f1a2753cfa84a859bf Mon Sep 17 00:00:00 2001 From: Camila Ayres Date: Thu, 17 Oct 2024 20:55:19 +0200 Subject: [PATCH] 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"));