Settings: Add update channel combobox #6259
authorChristian Kamm <mail@ckamm.de>
Thu, 26 Apr 2018 09:24:30 +0000 (11:24 +0200)
committerCamila (Rebase PR Action) <hello@camila.codes>
Tue, 24 Nov 2020 18:22:33 +0000 (18:22 +0000)
src/gui/generalsettings.cpp
src/gui/generalsettings.h
src/gui/generalsettings.ui
src/gui/updater/ocupdater.cpp
src/gui/updater/ocupdater.h
src/gui/updater/updater.cpp
src/gui/updater/updater.h
src/libsync/configfile.cpp
src/libsync/configfile.h

index 8e57eb8d1db09e72ff5ba2af57b78d675c3c1a6c..965af6130570b2106aefc99c5470faabb8569d3a 100644 (file)
@@ -272,12 +272,28 @@ void GeneralSettings::slotUpdateInfo()
                                       updater->downloadState() != OCUpdater::DownloadComplete);
 
         _ui->autoCheckForUpdatesCheckBox->setChecked(ConfigFile().autoUpdateCheck());
+
+        // Channel selection
+        _ui->updateChannel->setCurrentIndex(ConfigFile().updateChannel() == "beta" ? 1 : 0);
+        connect(_ui->updateChannel, &QComboBox::currentTextChanged,
+            this, &GeneralSettings::slotUpdateChannelChanged, Qt::UniqueConnection);
+
     } else {
         // can't have those infos from sparkle currently
         _ui->updatesGroupBox->setVisible(false);
     }
 }
 
+void GeneralSettings::slotUpdateChannelChanged(const QString &channel)
+{
+    ConfigFile().setUpdateChannel(channel);
+    auto *updater = qobject_cast<OCUpdater *>(Updater::instance());
+    if (updater) {
+        updater->setUpdateUrl(Updater::updateUrl());
+        updater->checkForUpdate();
+    }
+}
+
 void GeneralSettings::slotUpdateCheckNow()
 {
     auto *updater = qobject_cast<OCUpdater *>(Updater::instance());
index fa6fe11b9cefed562bb789c8bc23f08a25c235d1..3bc29f7ef5c4d0d6e8b1f2143adcb3f8b383a0f9 100644 (file)
@@ -53,6 +53,7 @@ private slots:
     void slotShowLegalNotice();
 #if defined(BUILD_UPDATER)
     void slotUpdateInfo();
+    void slotUpdateChannelChanged(const QString &channel);
     void slotUpdateCheckNow();
     void slotToggleAutoUpdateCheck();
 #endif
index a32e373f1e27b53efef1f0c744b3c7c6e0e8e7e3..f7347884a5675ae965c97b1f272519ab2fe44155 100644 (file)
           </property>
          </widget>
         </item>
+       </layout>
+      </item>
+      <item row="1" column="0">
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
         <item>
-         <spacer name="horizontalSpacer_5">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
+         <widget class="QLabel" name="updateChannelLabel">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Maximum" vsizetype="Preferred">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
           </property>
-          <property name="sizeType">
-           <enum>QSizePolicy::Preferred</enum>
+          <property name="text">
+           <string>&amp;Channel</string>
           </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>40</width>
-            <height>20</height>
-           </size>
+          <property name="buddy">
+           <cstring>updateChannel</cstring>
           </property>
-         </spacer>
+         </widget>
+        </item>
+        <item>
+         <widget class="QComboBox" name="updateChannel">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Maximum" vsizetype="Fixed">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <item>
+           <property name="text">
+            <string>stable</string>
+           </property>
+          </item>
+          <item>
+           <property name="text">
+            <string>beta</string>
+           </property>
+          </item>
+         </widget>
         </item>
-       </layout>
-      </item>
-      <item row="1" column="0">
-       <layout class="QHBoxLayout" name="horizontalLayout_2">
         <item>
          <widget class="QLabel" name="updateStateLabel">
           <property name="text">
           </property>
          </widget>
         </item>
-        <item>
-         <spacer name="horizontalSpacer">
-          <property name="orientation">
-           <enum>Qt::Horizontal</enum>
-          </property>
-          <property name="sizeType">
-           <enum>QSizePolicy::Preferred</enum>
-          </property>
-          <property name="sizeHint" stdset="0">
-           <size>
-            <width>40</width>
-            <height>20</height>
-           </size>
-          </property>
-         </spacer>
-        </item>
        </layout>
       </item>
      </layout>
index 3f772ef01fab193c8fac5bd477b06cc69ef266d3..4a84b3fa5ec453c3573b975c8a73bc90b64df562 100644 (file)
@@ -92,6 +92,11 @@ OCUpdater::OCUpdater(const QUrl &url)
 {
 }
 
+void OCUpdater::setUpdateUrl(const QUrl &url)
+{
+    _updateUrl = url;
+}
+
 bool OCUpdater::performUpdate()
 {
     ConfigFile cfg;
index f88875c50550080188e992490d8ae98abc0d3b2c..34c940732e5731f65a7a0266a1bebac8e7cd2082 100644 (file)
@@ -99,6 +99,8 @@ public:
         UpdateOnlyAvailableThroughSystem };
     explicit OCUpdater(const QUrl &url);
 
+    void setUpdateUrl(const QUrl &url);
+
     bool performUpdate();
 
     void checkForUpdate() override;
index 227d67afdcf6a698a14f14475ce4b5136613ff5e..36fd3f06fdb64f34a2cfa19f403709631421e99c 100644 (file)
@@ -23,6 +23,7 @@
 #include "theme.h"
 #include "common/utility.h"
 #include "version.h"
+#include "configfile.h"
 
 #include "config.h"
 #include "configfile.h"
@@ -41,6 +42,27 @@ Updater *Updater::instance()
     return _instance;
 }
 
+QUrl Updater::updateUrl()
+{
+    QUrl updateBaseUrl(QString::fromLocal8Bit(qgetenv("OCC_UPDATE_URL")));
+    if (updateBaseUrl.isEmpty()) {
+        updateBaseUrl = QUrl(QLatin1String(APPLICATION_UPDATE_URL));
+    }
+    if (!updateBaseUrl.isValid() || updateBaseUrl.host() == ".") {
+        return QUrl();
+    }
+
+    auto urlQuery = getQueryParams();
+
+#if defined(Q_OS_MAC) && defined(HAVE_SPARKLE)
+    urlQuery.addQueryItem(QLatin1String("sparkle"), QLatin1String("true"));
+#endif
+
+    updateBaseUrl.setQuery(urlQuery);
+
+    return updateBaseUrl;
+}
+
 QUrlQuery Updater::getQueryParams()
 {
     QUrlQuery query;
@@ -66,14 +88,10 @@ QUrlQuery Updater::getQueryParams()
 
     QString suffix = QString::fromLatin1(MIRALL_STRINGIFY(MIRALL_VERSION_SUFFIX));
     query.addQueryItem(QLatin1String("versionsuffix"), suffix);
-    if (suffix.startsWith("daily")
-            || suffix.startsWith("nightly")
-            || suffix.startsWith("alpha")
-            || suffix.startsWith("rc")
-            || suffix.startsWith("beta")) {
-        query.addQueryItem(QLatin1String("channel"), "beta");
-        // FIXME: Provide a checkbox in UI to enable regular versions to switch
-        // to beta channel
+
+    auto channel = ConfigFile().updateChannel();
+    if (channel != "stable") {
+        query.addQueryItem(QLatin1String("channel"), channel);
     }
 
     // updateSegment (see configfile.h)
@@ -105,30 +123,19 @@ QString Updater::getSystemInfo()
 // To test, cmake with -DAPPLICATION_UPDATE_URL="http://127.0.0.1:8080/test.rss"
 Updater *Updater::create()
 {
-    QUrl updateBaseUrl(QString::fromLocal8Bit(qgetenv("OCC_UPDATE_URL")));
-    if (updateBaseUrl.isEmpty()) {
-        updateBaseUrl = QUrl(QLatin1String(APPLICATION_UPDATE_URL));
-    }
-    if (!updateBaseUrl.isValid() || updateBaseUrl.host() == ".") {
+    auto url = updateUrl();
+    if (url.isEmpty()) {
         qCWarning(lcUpdater) << "Not a valid updater URL, will not do update check";
         return nullptr;
     }
 
-    auto urlQuery = getQueryParams();
-
-#if defined(Q_OS_MAC) && defined(HAVE_SPARKLE)
-    urlQuery.addQueryItem(QLatin1String("sparkle"), QLatin1String("true"));
-#endif
-
-    updateBaseUrl.setQuery(urlQuery);
-
 #if defined(Q_OS_MAC) && defined(HAVE_SPARKLE)
-    return new SparkleUpdater(updateBaseUrl.toString());
+    return new SparkleUpdater(url.toString());
 #elif defined(Q_OS_WIN32)
     // the best we can do is notify about updates
-    return new NSISUpdater(updateBaseUrl);
+    return new NSISUpdater(url);
 #else
-    return new PassiveUpdateNotifier(QUrl(updateBaseUrl));
+    return new PassiveUpdateNotifier(url);
 #endif
 }
 
index d744340019f3b6dd4fec9226c90e288172a59b72..33ba223411395060efb49942c14b5599c0622b56 100644 (file)
@@ -37,6 +37,7 @@ public:
     };
 
     static Updater *instance();
+    static QUrl updateUrl();
 
     virtual void checkForUpdate() = 0;
     virtual void backgroundCheckForUpdate() = 0;
index da4aca58e1bd1ba26fe7c35d004306edd779496c..057332edaad2f4ffae1255eac6a70841d3b47109 100644 (file)
@@ -18,6 +18,7 @@
 #include "theme.h"
 #include "common/utility.h"
 #include "common/asserts.h"
+#include "version.h"
 
 #include "creds/abstractcredentials.h"
 #include "creds/keychainchunk.h"
@@ -67,6 +68,7 @@ static const char skipUpdateCheckC[] = "skipUpdateCheck";
 static const char autoUpdateCheckC[] = "autoUpdateCheck";
 static const char updateCheckIntervalC[] = "updateCheckInterval";
 static const char updateSegmentC[] = "updateSegment";
+static const char updateChannelC[] = "updateChannel";
 static const char geometryC[] = "geometry";
 static const char timeoutC[] = "timeout";
 static const char chunkSizeC[] = "chunkSize";
@@ -624,6 +626,28 @@ int ConfigFile::updateSegment() const
     return segment;
 }
 
+QString ConfigFile::updateChannel() const
+{
+    QString defaultUpdateChannel = QStringLiteral("stable");
+    QString suffix = QString::fromLatin1(MIRALL_STRINGIFY(MIRALL_VERSION_SUFFIX));
+    if (suffix.startsWith("daily")
+        || suffix.startsWith("nightly")
+        || suffix.startsWith("alpha")
+        || suffix.startsWith("rc")
+        || suffix.startsWith("beta")) {
+        defaultUpdateChannel = QStringLiteral("beta");
+    }
+
+    QSettings settings(configFile(), QSettings::IniFormat);
+    return settings.value(QLatin1String(updateChannelC), defaultUpdateChannel).toString();
+}
+
+void ConfigFile::setUpdateChannel(const QString &channel)
+{
+    QSettings settings(configFile(), QSettings::IniFormat);
+    settings.setValue(QLatin1String(updateChannelC), channel);
+}
+
 int ConfigFile::maxLogLines() const
 {
     QSettings settings(configFile(), QSettings::IniFormat);
index e0629c1df5910adea00e790663c4881812339bae..9cd3e2dfb6decacc0ade425f51a8cb98c4e13785 100644 (file)
@@ -171,6 +171,9 @@ public:
         See: https://github.com/nextcloud/client_updater_server/pull/36 */
     int updateSegment() const;
 
+    QString updateChannel() const;
+    void setUpdateChannel(const QString &channel);
+
     void saveGeometryHeader(QHeaderView *header);
     void restoreGeometryHeader(QHeaderView *header);