Skip to content

Commit

Permalink
Update config value when serverHasValidSubscription when accounts are…
Browse files Browse the repository at this point in the history
… added or removed.

To give priority to server susbscriptions and keep listing the right update channels.

Signed-off-by: Camila Ayres <[email protected]>
  • Loading branch information
camilasan committed Oct 31, 2024
1 parent 1921df5 commit 8d0c321
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -675,6 +695,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);
}

Expand Down
3 changes: 3 additions & 0 deletions src/gui/accountmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountStatePtr> _accounts;
/// Account ids from settings that weren't read
Expand Down
1 change: 1 addition & 0 deletions src/gui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 8d0c321

Please sign in to comment.