From: Markus Goetz Date: Fri, 27 Apr 2018 07:10:38 +0000 (+0200) Subject: Auto Updater: Show UI element also on macOS X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~22^2~46^2~24 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=311e3a3bd87d6fe30cdd919911abda6be78df7dd;p=nextcloud-desktop.git Auto Updater: Show UI element also on macOS (cherry picked from commit dfdc2e1e87f99d387a042f4983c999fbb7fcf3d9) --- diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index cf8af8fd2..93929fa73 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -163,7 +163,7 @@ IF( APPLE ) if(SPARKLE_FOUND AND BUILD_UPDATER) # Define this, we need to check in updater.cpp add_definitions( -DHAVE_SPARKLE ) - list(APPEND updater_SRCS updater/sparkleupdater_mac.mm) + list(APPEND updater_SRCS updater/sparkleupdater_mac.mm updater/sparkleupdater.h) endif() ENDIF() diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 965af6130..b9081da43 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -26,6 +26,10 @@ #if defined(BUILD_UPDATER) #include "updater/updater.h" #include "updater/ocupdater.h" +#ifdef Q_OS_MAC +// FIXME We should unify those, but Sparkle does everything behind the scene transparently +#include "updater/sparkleupdater.h" +#endif #endif #include "ignorelisteditor.h" @@ -248,28 +252,30 @@ void GeneralSettings::loadMiscSettings() #if defined(BUILD_UPDATER) void GeneralSettings::slotUpdateInfo() { - // Note: the sparkle-updater is not an OCUpdater - auto *updater = qobject_cast(Updater::instance()); if (ConfigFile().skipUpdateCheck()) { - updater = nullptr; // don't show update info if updates are disabled + // updater disabled on compile + _ui->updatesGroupBox->setVisible(false); + return; } - if (updater) { - connect(updater, &OCUpdater::downloadStateChanged, this, &GeneralSettings::slotUpdateInfo, Qt::UniqueConnection); - connect(_ui->restartButton, &QAbstractButton::clicked, updater, &OCUpdater::slotStartInstaller, Qt::UniqueConnection); + // Note: the sparkle-updater is not an OCUpdater + auto *ocupdater = qobject_cast(Updater::instance()); + if (ocupdater) { + connect(ocupdater, &OCUpdater::downloadStateChanged, this, &GeneralSettings::slotUpdateInfo, Qt::UniqueConnection); + connect(_ui->restartButton, &QAbstractButton::clicked, ocupdater, &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(); + QString status = ocupdater->statusString(); Theme::replaceLinkColorStringBackgroundAware(status); _ui->updateStateLabel->setText(status); - _ui->restartButton->setVisible(updater->downloadState() == OCUpdater::DownloadComplete); + _ui->restartButton->setVisible(ocupdater->downloadState() == OCUpdater::DownloadComplete); - _ui->updateButton->setEnabled(updater->downloadState() != OCUpdater::CheckingServer && - updater->downloadState() != OCUpdater::Downloading && - updater->downloadState() != OCUpdater::DownloadComplete); + _ui->updateButton->setEnabled(ocupdater->downloadState() != OCUpdater::CheckingServer && + ocupdater->downloadState() != OCUpdater::Downloading && + ocupdater->downloadState() != OCUpdater::DownloadComplete); _ui->autoCheckForUpdatesCheckBox->setChecked(ConfigFile().autoUpdateCheck()); @@ -277,11 +283,19 @@ void GeneralSettings::slotUpdateInfo() _ui->updateChannel->setCurrentIndex(ConfigFile().updateChannel() == "beta" ? 1 : 0); connect(_ui->updateChannel, &QComboBox::currentTextChanged, this, &GeneralSettings::slotUpdateChannelChanged, Qt::UniqueConnection); + } +#ifdef Q_OS_MAC + else if (auto sparkleUpdater = qobject_cast(Updater::instance())) { + _ui->updateStateLabel->setText(sparkleUpdater->statusString()); + _ui->restartButton->setVisible(false); - } else { - // can't have those infos from sparkle currently - _ui->updatesGroupBox->setVisible(false); + // Channel selection + _ui->updateChannel->setCurrentIndex(ConfigFile().updateChannel() == "beta" ? 1 : 0); + connect(_ui->updateChannel, &QComboBox::currentTextChanged, + this, &GeneralSettings::slotUpdateChannelChanged, Qt::UniqueConnection); } +#endif + } void GeneralSettings::slotUpdateChannelChanged(const QString &channel) diff --git a/src/gui/updater/sparkleupdater.h b/src/gui/updater/sparkleupdater.h index 5a3c70eb7..d565c6f6e 100644 --- a/src/gui/updater/sparkleupdater.h +++ b/src/gui/updater/sparkleupdater.h @@ -23,6 +23,7 @@ namespace OCC { class SparkleUpdater : public Updater { + Q_OBJECT public: SparkleUpdater(const QString &appCastUrl); ~SparkleUpdater(); @@ -32,6 +33,8 @@ public: void backgroundCheckForUpdate() override; bool handleStartup() override { return false; } + QString statusString(); + private: class Private; Private *d; diff --git a/src/gui/updater/sparkleupdater_mac.mm b/src/gui/updater/sparkleupdater_mac.mm index cfb1189ad..5bf43efdb 100644 --- a/src/gui/updater/sparkleupdater_mac.mm +++ b/src/gui/updater/sparkleupdater_mac.mm @@ -114,7 +114,7 @@ SparkleUpdater::~SparkleUpdater() delete d; } - +// FIXME: Should be changed to not instanicate the SparkleUpdater at all in this case bool autoUpdaterAllowed() { // See https://github.com/owncloud/client/issues/2931 @@ -143,4 +143,10 @@ void SparkleUpdater::backgroundCheckForUpdate() } } +QString SparkleUpdater::statusString() +{ + // FIXME Show the real state depending on the callbacks + return QString(); +} + } // namespace OCC