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"));