From: Christian Kamm Date: Thu, 26 Apr 2018 09:24:30 +0000 (+0200) Subject: Settings: Add update channel combobox #6259 X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~22^2~46^2~25 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=a8ad94675875adea6faa6103df3544bed85d165d;p=nextcloud-desktop.git Settings: Add update channel combobox #6259 --- diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 8e57eb8d1..965af6130 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -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(Updater::instance()); + if (updater) { + updater->setUpdateUrl(Updater::updateUrl()); + updater->checkForUpdate(); + } +} + void GeneralSettings::slotUpdateCheckNow() { auto *updater = qobject_cast(Updater::instance()); diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index fa6fe11b9..3bc29f7ef 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -53,6 +53,7 @@ private slots: void slotShowLegalNotice(); #if defined(BUILD_UPDATER) void slotUpdateInfo(); + void slotUpdateChannelChanged(const QString &channel); void slotUpdateCheckNow(); void slotToggleAutoUpdateCheck(); #endif diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index a32e373f1..f7347884a 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -124,26 +124,46 @@ + + + + - - - Qt::Horizontal + + + + 0 + 0 + - - QSizePolicy::Preferred + + &Channel - - - 40 - 20 - + + updateChannel - + + + + + + + 0 + 0 + + + + + stable + + + + + beta + + + - - - - @@ -170,22 +190,6 @@ - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 40 - 20 - - - - diff --git a/src/gui/updater/ocupdater.cpp b/src/gui/updater/ocupdater.cpp index 3f772ef01..4a84b3fa5 100644 --- a/src/gui/updater/ocupdater.cpp +++ b/src/gui/updater/ocupdater.cpp @@ -92,6 +92,11 @@ OCUpdater::OCUpdater(const QUrl &url) { } +void OCUpdater::setUpdateUrl(const QUrl &url) +{ + _updateUrl = url; +} + bool OCUpdater::performUpdate() { ConfigFile cfg; diff --git a/src/gui/updater/ocupdater.h b/src/gui/updater/ocupdater.h index f88875c50..34c940732 100644 --- a/src/gui/updater/ocupdater.h +++ b/src/gui/updater/ocupdater.h @@ -99,6 +99,8 @@ public: UpdateOnlyAvailableThroughSystem }; explicit OCUpdater(const QUrl &url); + void setUpdateUrl(const QUrl &url); + bool performUpdate(); void checkForUpdate() override; diff --git a/src/gui/updater/updater.cpp b/src/gui/updater/updater.cpp index 227d67afd..36fd3f06f 100644 --- a/src/gui/updater/updater.cpp +++ b/src/gui/updater/updater.cpp @@ -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 } diff --git a/src/gui/updater/updater.h b/src/gui/updater/updater.h index d74434001..33ba22341 100644 --- a/src/gui/updater/updater.h +++ b/src/gui/updater/updater.h @@ -37,6 +37,7 @@ public: }; static Updater *instance(); + static QUrl updateUrl(); virtual void checkForUpdate() = 0; virtual void backgroundCheckForUpdate() = 0; diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index da4aca58e..057332eda 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -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); diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index e0629c1df..9cd3e2dfb 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -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);