ensure we only store update channel not localized in settings
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Tue, 22 Mar 2022 20:15:57 +0000 (21:15 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Wed, 23 Mar 2022 16:35:39 +0000 (17:35 +0100)
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/gui/generalsettings.cpp
src/gui/generalsettings.h

index 589ab7afed90a357042333cf28114b98fac2f136..d132e3ca467ba29507cdf8d8d678534d95616e6d 100644 (file)
@@ -304,10 +304,43 @@ void GeneralSettings::slotUpdateInfo()
         this, &GeneralSettings::slotUpdateChannelChanged, Qt::UniqueConnection);
 }
 
-void GeneralSettings::slotUpdateChannelChanged(const QString &channel)
+void GeneralSettings::slotUpdateChannelChanged(const QString &translatedChannel)
 {
-    if (channel == ConfigFile().updateChannel())
+    const auto updateChannelToLocalized = [](const QString &channel) {
+        auto decodedTranslatedChannel = QString{};
+
+        if (channel == QStringLiteral("stable")) {
+            decodedTranslatedChannel = tr("stable");
+        } else if (channel == QStringLiteral("beta")) {
+            decodedTranslatedChannel = tr("beta");
+        }
+
+        return decodedTranslatedChannel;
+    };
+
+    const auto updateChannelFromLocalized = [](const int index) {
+        auto channel = QString{};
+
+        switch (index)
+        {
+        case 0:
+            channel = QStringLiteral("stable");
+            break;
+        case 1:
+            channel = QStringLiteral("beta");
+            break;
+        default:
+            channel = QString{};
+        }
+
+        return channel;
+    };
+
+    const auto channel = updateChannelFromLocalized(_ui->updateChannel->currentIndex());
+
+    if (translatedChannel == ConfigFile().updateChannel()) {
         return;
+    }
 
     auto msgBox = new QMessageBox(
         QMessageBox::Warning,
@@ -327,7 +360,7 @@ void GeneralSettings::slotUpdateChannelChanged(const QString &channel)
         this);
     auto acceptButton = msgBox->addButton(tr("Change update channel"), QMessageBox::AcceptRole);
     msgBox->addButton(tr("Cancel"), QMessageBox::RejectRole);
-    connect(msgBox, &QMessageBox::finished, msgBox, [this, channel, msgBox, acceptButton] {
+    connect(msgBox, &QMessageBox::finished, msgBox, [this, channel, msgBox, acceptButton, updateChannelToLocalized] {
         msgBox->deleteLater();
         if (msgBox->clickedButton() == acceptButton) {
             ConfigFile().setUpdateChannel(channel);
@@ -342,7 +375,7 @@ void GeneralSettings::slotUpdateChannelChanged(const QString &channel)
             }
 #endif
         } else {
-            _ui->updateChannel->setCurrentText(ConfigFile().updateChannel());
+            _ui->updateChannel->setCurrentText(updateChannelToLocalized(ConfigFile().updateChannel()));
         }
     });
     msgBox->open();
index 8243fb241a00470bddf31cf8d2460c7816585543..6c71348170adcf564da16c19f8665f4057517964 100644 (file)
@@ -55,7 +55,7 @@ private slots:
     void slotShowLegalNotice();
 #if defined(BUILD_UPDATER)
     void slotUpdateInfo();
-    void slotUpdateChannelChanged(const QString &channel);
+    void slotUpdateChannelChanged(const QString &translatedChannel);
     void slotUpdateCheckNow();
     void slotToggleAutoUpdateCheck();
 #endif