From: Michael Schuster Date: Mon, 9 Mar 2020 00:17:02 +0000 (+0100) Subject: Updater UI: Implement auto-update option and update button X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~322^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c043a4e55c7b6dc97b8c8f1e7daa96db2200f4de;p=nextcloud-desktop.git Updater UI: Implement auto-update option and update button - Add checkbox and button to UI - Add new parameter autoUpdateCheck to ConfigFile Signed-off-by: Michael Schuster --- diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 050e57450..6d0a56d39 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -162,18 +162,47 @@ void GeneralSettings::slotUpdateInfo() connect(updater, &OCUpdater::downloadStateChanged, this, &GeneralSettings::slotUpdateInfo, Qt::UniqueConnection); connect(_ui->restartButton, &QAbstractButton::clicked, updater, &OCUpdater::slotStartInstaller, Qt::UniqueConnection); connect(_ui->restartButton, &QAbstractButton::clicked, qApp, &QApplication::quit, Qt::UniqueConnection); + connect(_ui->updateButton, &QAbstractButton::clicked, this, &GeneralSettings::slotUpdateCheckNow, Qt::UniqueConnection); + connect(_ui->autoCheckForUpdatesCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleAutoUpdateCheck); QString status = updater->statusString(); Theme::replaceLinkColorStringBackgroundAware(status); _ui->updateStateLabel->setText(status); _ui->restartButton->setVisible(updater->downloadState() == OCUpdater::DownloadComplete); + + _ui->updateButton->setEnabled(updater->downloadState() != OCUpdater::CheckingServer && + updater->downloadState() != OCUpdater::Downloading && + updater->downloadState() != OCUpdater::DownloadComplete); + + _ui->autoCheckForUpdatesCheckBox->setChecked(ConfigFile().autoUpdateCheck()); } else { // can't have those infos from sparkle currently _ui->updatesGroupBox->setVisible(false); } } +void GeneralSettings::slotUpdateCheckNow() +{ + OCUpdater *updater = qobject_cast(Updater::instance()); + if (ConfigFile().skipUpdateCheck()) { + updater = nullptr; // don't show update info if updates are disabled + } + + if (updater) { + _ui->updateButton->setEnabled(false); + + updater->checkForUpdate(); + } +} + +void GeneralSettings::slotToggleAutoUpdateCheck() +{ + ConfigFile cfgFile; + bool isChecked = _ui->autoCheckForUpdatesCheckBox->isChecked(); + cfgFile.setAutoUpdateCheck(isChecked, QString()); +} + void GeneralSettings::saveMiscSettings() { if (_currentlyLoading) diff --git a/src/gui/generalsettings.h b/src/gui/generalsettings.h index f7a759161..eb8b2e49b 100644 --- a/src/gui/generalsettings.h +++ b/src/gui/generalsettings.h @@ -47,10 +47,12 @@ private slots: void slotToggleLaunchOnStartup(bool); void slotToggleOptionalServerNotifications(bool); void slotShowInExplorerNavigationPane(bool); - void slotUpdateInfo(); void slotIgnoreFilesEditor(); void loadMiscSettings(); void slotShowLegalNotice(); + void slotUpdateInfo(); + void slotUpdateCheckNow(); + void slotToggleAutoUpdateCheck(); private: void customizeStyle(); diff --git a/src/gui/generalsettings.ui b/src/gui/generalsettings.ui index 1c7c25015..ebc69ebd6 100644 --- a/src/gui/generalsettings.ui +++ b/src/gui/generalsettings.ui @@ -98,48 +98,95 @@ Updates - - - - - - - - true - - - true - - - - - - - - 0 - 0 - - - - &Restart && Update - - + + + + + + + &Automatically check for Updates + + + true + + + + + + + + 0 + 0 + + + + &Check for Update now + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 40 + 20 + + + + + - - - - Qt::Horizontal - - - QSizePolicy::Preferred - - - - 40 - 20 - - - + + + + + + + + + true + + + true + + + + + + + + 0 + 0 + + + + &Restart && Update + + + + + + + Qt::Horizontal + + + QSizePolicy::Preferred + + + + 40 + 20 + + + + + @@ -283,6 +330,8 @@ newFolderLimitCheckBox newFolderLimitSpinBox crashreporterCheckBox + autoCheckForUpdatesCheckBox + updateButton restartButton diff --git a/src/gui/updater/ocupdater.cpp b/src/gui/updater/ocupdater.cpp index 90294712c..21e57ef80 100644 --- a/src/gui/updater/ocupdater.cpp +++ b/src/gui/updater/ocupdater.cpp @@ -68,8 +68,8 @@ void UpdaterScheduler::slotTimerFired() qCInfo(lcUpdater) << "Setting new update check interval " << checkInterval; } - // consider the skipUpdateCheck flag in the config. - if (cfg.skipUpdateCheck()) { + // consider the skipUpdateCheck and !autoUpdateCheck flags in the config. + if (cfg.skipUpdateCheck() || !cfg.autoUpdateCheck()) { qCInfo(lcUpdater) << "Skipping update check because of config file"; return; } diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 69de66cf4..874585d41 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -63,6 +63,7 @@ static const char crashReporterC[] = "crashReporter"; static const char optionalServerNotificationsC[] = "optionalServerNotifications"; static const char showInExplorerNavigationPaneC[] = "showInExplorerNavigationPane"; static const char skipUpdateCheckC[] = "skipUpdateCheck"; +static const char autoUpdateCheckC[] = "autoUpdateCheck"; static const char updateCheckIntervalC[] = "updateCheckInterval"; static const char updateSegmentC[] = "updateSegment"; static const char geometryC[] = "geometry"; @@ -577,6 +578,32 @@ void ConfigFile::setSkipUpdateCheck(bool skip, const QString &connection) settings.sync(); } +bool ConfigFile::autoUpdateCheck(const QString &connection) const +{ + QString con(connection); + if (connection.isEmpty()) + con = defaultConnection(); + + QVariant fallback = getValue(QLatin1String(autoUpdateCheckC), con, true); + fallback = getValue(QLatin1String(autoUpdateCheckC), QString(), fallback); + + QVariant value = getPolicySetting(QLatin1String(autoUpdateCheckC), fallback); + return value.toBool(); +} + +void ConfigFile::setAutoUpdateCheck(bool autoCheck, const QString &connection) +{ + QString con(connection); + if (connection.isEmpty()) + con = defaultConnection(); + + QSettings settings(configFile(), QSettings::IniFormat); + settings.beginGroup(con); + + settings.setValue(QLatin1String(autoUpdateCheckC), QVariant(autoCheck)); + settings.sync(); +} + int ConfigFile::updateSegment() const { QSettings settings(configFile(), QSettings::IniFormat); diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index 2fb911c9b..7b84ef89c 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -146,9 +146,14 @@ public: // how often the check about new versions runs std::chrono::milliseconds updateCheckInterval(const QString &connection = QString()) const; + // skipUpdateCheck completely disables the updater and hides its UI bool skipUpdateCheck(const QString &connection = QString()) const; void setSkipUpdateCheck(bool, const QString &); + // autoUpdateCheck allows the user to make the choice in the UI + bool autoUpdateCheck(const QString &connection = QString()) const; + void setAutoUpdateCheck(bool, const QString &); + /** Query-parameter 'updatesegment' for the update check, value between 0 and 99. Used to throttle down desktop release rollout in order to keep the update servers alive at peak times. See: https://github.com/nextcloud/client_updater_server/pull/36 */