From 40aae17c0e16928eba736c2699f29238a2411666 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 10 Nov 2014 15:01:34 -0500 Subject: [PATCH] Move software update menu handling to AutoUpdater. This should fix #714 --- sparkle.pri | 1 + src/AutoUpdater.cc | 20 ++++++++++++ src/AutoUpdater.h | 16 ++++++++-- src/MainWindow.h | 1 - src/MainWindow.ui | 66 +++++++++++++++++++++++++++++++--------- src/Preferences.cc | 4 +-- src/SparkleAutoUpdater.h | 1 + src/mainwin.cc | 26 +++++----------- src/openscad.cc | 15 ++++----- 9 files changed, 104 insertions(+), 46 deletions(-) diff --git a/sparkle.pri b/sparkle.pri index 2f71b030..95eecd7d 100644 --- a/sparkle.pri +++ b/sparkle.pri @@ -8,4 +8,5 @@ sparkle { LIBS += -framework Sparkle HEADERS += src/SparkleAutoUpdater.h OBJECTIVE_SOURCES += src/SparkleAutoUpdater.mm + DEFINES += OPENSCAD_UPDATER } diff --git a/src/AutoUpdater.cc b/src/AutoUpdater.cc index b64cc827..632fbe5a 100644 --- a/src/AutoUpdater.cc +++ b/src/AutoUpdater.cc @@ -1,3 +1,23 @@ #include "AutoUpdater.h" +#include +#include AutoUpdater *AutoUpdater::updater_instance = NULL; + +void AutoUpdater::init() +{ +#ifdef OPENSCAD_UPDATER + if (!this->updateAction) { + QMenuBar *mb = new QMenuBar(); + this->updateMenu = mb->addMenu("special"); + this->updateAction = new QAction("Check for Update..", this); + // Add to application menu + this->updateAction->setMenuRole(QAction::ApplicationSpecificRole); + this->updateAction->setEnabled(true); + this->connect(this->updateAction, SIGNAL(triggered()), this, SLOT(checkForUpdates())); + + this->updateMenu->addAction(this->updateAction); + + } +#endif +} diff --git a/src/AutoUpdater.h b/src/AutoUpdater.h index 0580a694..6820bf59 100644 --- a/src/AutoUpdater.h +++ b/src/AutoUpdater.h @@ -1,22 +1,34 @@ #pragma once #include +#include -class AutoUpdater +class AutoUpdater : public QObject { + Q_OBJECT; + public: + AutoUpdater() : updateAction(NULL) {} virtual ~AutoUpdater() {} - virtual void checkForUpdates() = 0; virtual void setAutomaticallyChecksForUpdates(bool on) = 0; virtual bool automaticallyChecksForUpdates() = 0; virtual void setEnableSnapshots(bool on) = 0; virtual bool enableSnapshots() = 0; virtual QString lastUpdateCheckDate() = 0; + virtual void init(); static AutoUpdater *updater() { return updater_instance; } static void setUpdater(AutoUpdater *updater) { updater_instance = updater; } +public slots: + virtual void checkForUpdates() = 0; + + +public: + class QAction *updateAction; + class QMenu *updateMenu; + protected: static AutoUpdater *updater_instance; }; diff --git a/src/MainWindow.h b/src/MainWindow.h index d6cb7bb7..9b5833bf 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -119,7 +119,6 @@ private: class FontListDialog *font_list_dialog; private slots: - void actionUpdateCheck(); void actionNew(); void actionOpen(); void actionOpenRecent(); diff --git a/src/MainWindow.ui b/src/MainWindow.ui index 66cdd4e9..c883a92a 100644 --- a/src/MainWindow.ui +++ b/src/MainWindow.ui @@ -15,7 +15,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -30,7 +39,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -64,7 +82,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -143,7 +170,7 @@ 0 0 1397 - 33 + 22 @@ -280,7 +307,6 @@ - @@ -298,7 +324,16 @@ 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -418,7 +453,16 @@ - + + 0 + + + 0 + + + 0 + + 0 @@ -1013,14 +1057,6 @@ Library info - - - false - - - Check for Update.. - - Show Library Folder... diff --git a/src/Preferences.cc b/src/Preferences.cc index 97b5e4d2..771a6f8c 100644 --- a/src/Preferences.cc +++ b/src/Preferences.cc @@ -113,7 +113,7 @@ void Preferences::init() { QActionGroup *group = new QActionGroup(this); addPrefPage(group, prefsAction3DView, page3DView); addPrefPage(group, prefsActionEditor, pageEditor); -#if defined(OPENSCAD_DEPLOY) && defined(Q_OS_MAC) +#ifdef OPENSCAD_UPDATER addPrefPage(group, prefsActionUpdate, pageUpdate); #else this->toolBar->removeAction(prefsActionUpdate); @@ -307,7 +307,7 @@ void Preferences::on_snapshotCheckBox_toggled(bool on) void Preferences::on_checkNowButton_clicked() { - if (AutoUpdater *updater =AutoUpdater::updater()) { + if (AutoUpdater *updater = AutoUpdater::updater()) { updater->checkForUpdates(); } else { unimplemented_msg(); diff --git a/src/SparkleAutoUpdater.h b/src/SparkleAutoUpdater.h index 928f8bb4..5cf28bae 100644 --- a/src/SparkleAutoUpdater.h +++ b/src/SparkleAutoUpdater.h @@ -10,6 +10,7 @@ class SparkleAutoUpdater : public AutoUpdater { + Q_OBJECT; public: SparkleAutoUpdater(); ~SparkleAutoUpdater(); diff --git a/src/mainwin.cc b/src/mainwin.cc index 38daa18e..be3c4337 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -56,11 +56,13 @@ #include "ThrownTogetherRenderer.h" #include "csgtermnormalizer.h" #include "QGLView.h" -#include "AutoUpdater.h" #ifdef Q_OS_MAC #include "CocoaUtils.h" #endif #include "PlatformUtils.h" +#ifdef OPENSCAD_UPDATER +#include "AutoUpdater.h" +#endif #include #include @@ -276,17 +278,6 @@ MainWindow::MainWindow(const QString &filename) animate_panel->hide(); find_panel->hide(); - // Application menu -#ifdef DEBUG - this->appActionUpdateCheck->setEnabled(false); -#else -#ifdef Q_OS_MAC - this->appActionUpdateCheck->setMenuRole(QAction::ApplicationSpecificRole); - this->appActionUpdateCheck->setEnabled(true); - connect(this->appActionUpdateCheck, SIGNAL(triggered()), this, SLOT(actionUpdateCheck())); -#endif -#endif - // File menu connect(this->fileActionNew, SIGNAL(triggered()), this, SLOT(actionNew())); connect(this->fileActionOpen, SIGNAL(triggered()), this, SLOT(actionOpen())); @@ -410,6 +401,10 @@ MainWindow::MainWindow(const QString &filename) connect(this->helpActionLibraryInfo, SIGNAL(triggered()), this, SLOT(helpLibrary())); connect(this->helpActionFontInfo, SIGNAL(triggered()), this, SLOT(helpFontInfo())); +#ifdef OPENSCAD_UPDATER + this->menuBar()->addMenu(AutoUpdater::updater()->updateMenu); +#endif + setCurrentOutput(); PRINT(helptitle); @@ -1136,13 +1131,6 @@ void MainWindow::compileCSG(bool procevents) if (procevents) QApplication::processEvents(); } -void MainWindow::actionUpdateCheck() -{ - if (AutoUpdater *updater =AutoUpdater::updater()) { - updater->checkForUpdates(); - } -} - void MainWindow::actionNew() { if (MainWindow::mdiMode) { diff --git a/src/openscad.cc b/src/openscad.cc index 5f660284..f25d0677 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -65,9 +65,9 @@ #ifdef __APPLE__ #include "AppleEvents.h" -#ifdef OPENSCAD_DEPLOY - #include "SparkleAutoUpdater.h" -#endif + #ifdef OPENSCAD_UPDATER + #include "SparkleAutoUpdater.h" + #endif #endif #ifdef _MSC_VER @@ -556,10 +556,11 @@ int gui(vector &inputFiles, const fs::path &original_path, int argc, cha installAppleEventHandlers(); #endif -#if defined(OPENSCAD_DEPLOY) && defined(Q_OS_MAC) -// AutoUpdater *updater = new SparkleAutoUpdater; -// AutoUpdater::setUpdater(updater); -// if (updater->automaticallyChecksForUpdates()) updater->checkForUpdates(); +#ifdef OPENSCAD_UPDATER + AutoUpdater *updater = new SparkleAutoUpdater; + AutoUpdater::setUpdater(updater); + if (updater->automaticallyChecksForUpdates()) updater->checkForUpdates(); + updater->init(); #endif #if 0 /*** disabled by clifford wolf: adds rendering artefacts with OpenCSG ***/