Change the list of update channels when server capabilities change.
authorCamila Ayres <hello@camilasan.com>
Wed, 16 Oct 2024 09:43:39 +0000 (11:43 +0200)
committerCamila Ayres <hello@camilasan.com>
Thu, 31 Oct 2024 12:06:03 +0000 (13:06 +0100)
Signed-off-by: Camila Ayres <hello@camilasan.com>
src/gui/accountmanager.cpp
src/gui/accountmanager.h
src/gui/generalsettings.cpp
src/gui/generalsettings.h
src/gui/settingsdialog.cpp

index c6102a7d7cad227620409c52351e3a0f3b8932f1..f934e1cdbbd07faf28cad90bcc3b815891db15f4 100644 (file)
@@ -670,6 +670,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;
index 32b7ca8e40aed3e443190353ca651d3701a5cad9..768f902ef3c999be097963f6728764aac889732c 100644 (file)
@@ -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
index ab28ca196903f1fd07b9919866fde24cfbc634a2..264bca62b17b6838a82f988cf2a57d35224188cc 100644 (file)
@@ -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;
index 70a726142db8bac922c2c61dcc1d3ac5bff91fa0..02a8cef3dedf28dfa19a39f70d414dc76e3b876d 100644 (file)
@@ -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<IgnoreListEditor> _ignoreEditor;
     bool _currentlyLoading = false;
+    QStringList _currentUpdateChannelList;
 };
 
 
index a59314a15ce735913abd229eb1fbaabe19004de4..bd14bb71b043da61f0b39b366cfd2a4ad14c72f7 100644 (file)
@@ -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);