summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/AutoUpdater.cc3
-rw-r--r--src/AutoUpdater.h25
-rw-r--r--src/MainWindow.h1
-rw-r--r--src/MainWindow.ui12
-rw-r--r--src/Preferences.cc33
-rw-r--r--src/Preferences.h3
-rw-r--r--src/Preferences.ui170
-rw-r--r--src/SparkleAutoUpdater.h32
-rw-r--r--src/SparkleAutoUpdater.mm72
-rw-r--r--src/mainwin.cc18
-rw-r--r--src/openscad.cc9
11 files changed, 373 insertions, 5 deletions
diff --git a/src/AutoUpdater.cc b/src/AutoUpdater.cc
new file mode 100644
index 0000000..b64cc82
--- /dev/null
+++ b/src/AutoUpdater.cc
@@ -0,0 +1,3 @@
+#include "AutoUpdater.h"
+
+AutoUpdater *AutoUpdater::updater_instance = NULL;
diff --git a/src/AutoUpdater.h b/src/AutoUpdater.h
new file mode 100644
index 0000000..18527c8
--- /dev/null
+++ b/src/AutoUpdater.h
@@ -0,0 +1,25 @@
+#ifndef AUTOUPDATER_H_
+#define AUTOUPDATER_H_
+
+#include <QString>
+
+class AutoUpdater
+{
+public:
+ 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;
+
+ static AutoUpdater *updater() { return updater_instance; }
+ static void setUpdater(AutoUpdater *updater) { updater_instance = updater; }
+
+protected:
+ static AutoUpdater *updater_instance;
+};
+
+#endif
diff --git a/src/MainWindow.h b/src/MainWindow.h
index a4835c2..033ef49 100644
--- a/src/MainWindow.h
+++ b/src/MainWindow.h
@@ -91,6 +91,7 @@ private:
class QMessageBox *openglbox;
private slots:
+ void actionUpdateCheck();
void actionNew();
void actionOpen();
void actionOpenRecent();
diff --git a/src/MainWindow.ui b/src/MainWindow.ui
index f71ac96..4b1639b 100644
--- a/src/MainWindow.ui
+++ b/src/MainWindow.ui
@@ -223,6 +223,7 @@
<addaction name="helpActionHomepage"/>
<addaction name="helpActionManual"/>
<addaction name="helpActionLibraryInfo"/>
+ <addaction name="appActionUpdateCheck"/>
</widget>
<addaction name="menu_File"/>
<addaction name="menu_Edit"/>
@@ -611,6 +612,9 @@
</property>
</action>
<action name="helpActionAbout">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
<property name="text">
<string>About</string>
</property>
@@ -676,6 +680,14 @@
<string>Library info</string>
</property>
</action>
+ <action name="appActionUpdateCheck">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Check for Update..</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
diff --git a/src/Preferences.cc b/src/Preferences.cc
index ec66094..fe7462a 100644
--- a/src/Preferences.cc
+++ b/src/Preferences.cc
@@ -29,7 +29,9 @@
#include <QFontDatabase>
#include <QKeyEvent>
#include <QSettings>
+#include <QStatusBar>
#include "PolySetCache.h"
+#include "AutoUpdater.h"
#ifdef ENABLE_CGAL
#include "CGALCache.h"
#endif
@@ -88,6 +90,7 @@ Preferences::Preferences(QWidget *parent) : QMainWindow(parent)
QActionGroup *group = new QActionGroup(this);
group->addAction(prefsAction3DView);
group->addAction(prefsActionEditor);
+ group->addAction(prefsActionUpdate);
group->addAction(prefsActionAdvanced);
connect(group, SIGNAL(triggered(QAction*)), this, SLOT(actionTriggered(QAction*)));
@@ -155,6 +158,9 @@ Preferences::actionTriggered(QAction *action)
else if (action == this->prefsActionEditor) {
this->stackedWidget->setCurrentWidget(this->pageEditor);
}
+ else if (action == this->prefsActionUpdate) {
+ this->stackedWidget->setCurrentWidget(this->pageUpdate);
+ }
else if (action == this->prefsActionAdvanced) {
this->stackedWidget->setCurrentWidget(this->pageAdvanced);
}
@@ -186,6 +192,27 @@ void Preferences::on_fontSize_editTextChanged(const QString &size)
emit fontChanged(getValue("editor/fontfamily").toString(), intsize);
}
+void Preferences::on_updateCheckBox_toggled(bool on)
+{
+ if (AutoUpdater *updater =AutoUpdater::updater()) {
+ updater->setAutomaticallyChecksForUpdates(on);
+ }
+}
+
+void Preferences::on_snapshotCheckBox_toggled(bool on)
+{
+ if (AutoUpdater *updater =AutoUpdater::updater()) {
+ updater->setEnableSnapshots(on);
+ }
+}
+
+void Preferences::on_checkNowButton_clicked()
+{
+ if (AutoUpdater *updater =AutoUpdater::updater()) {
+ updater->checkForUpdates();
+ }
+}
+
void
Preferences::on_openCSGWarningBox_toggled(bool state)
{
@@ -289,6 +316,12 @@ void Preferences::updateGUI()
this->fontSize->setEditText(fontsize);
}
+ if (AutoUpdater *updater = AutoUpdater::updater()) {
+ this->updateCheckBox->setChecked(updater->automaticallyChecksForUpdates());
+ this->snapshotCheckBox->setChecked(updater->enableSnapshots());
+ this->lastCheckedLabel->setText(updater->lastUpdateCheckDate());
+ }
+
this->openCSGWarningBox->setChecked(getValue("advanced/opencsg_show_warning").toBool());
this->enableOpenCSGBox->setChecked(getValue("advanced/enable_opencsg_opengl1x").toBool());
this->cgalCacheSizeEdit->setText(getValue("advanced/cgalCacheSize").toString());
diff --git a/src/Preferences.h b/src/Preferences.h
index 48e07b4..4656793 100644
--- a/src/Preferences.h
+++ b/src/Preferences.h
@@ -30,6 +30,9 @@ public slots:
void on_polysetCacheSizeEdit_textChanged(const QString &);
void on_opencsgLimitEdit_textChanged(const QString &);
void on_forceGoldfeatherBox_toggled(bool);
+ void on_updateCheckBox_toggled(bool);
+ void on_snapshotCheckBox_toggled(bool);
+ void on_checkNowButton_clicked();
signals:
void requestRedraw() const;
diff --git a/src/Preferences.ui b/src/Preferences.ui
index 9b4671a..d67db6a 100644
--- a/src/Preferences.ui
+++ b/src/Preferences.ui
@@ -6,10 +6,16 @@
<rect>
<x>0</x>
<y>0</y>
- <width>531</width>
- <height>418</height>
+ <width>473</width>
+ <height>320</height>
</rect>
</property>
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="windowTitle">
<string>Preferences</string>
</property>
@@ -173,6 +179,150 @@
</item>
</layout>
</widget>
+ <widget class="QWidget" name="pageUpdate">
+ <layout class="QVBoxLayout" name="verticalLayout_16">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_9">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_8">
+ <item>
+ <widget class="QCheckBox" name="updateCheckBox">
+ <property name="text">
+ <string>Automatically check for updates</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="snapshotCheckBox">
+ <property name="text">
+ <string>Include development snapshots</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_7">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_11">
+ <item>
+ <spacer name="horizontalSpacer_10">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="checkNowButton">
+ <property name="text">
+ <string>Check Now</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_9">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_10">
+ <item>
+ <spacer name="horizontalSpacer_11">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="lastCheckedLabel">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>11</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Last checked: </string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_12">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <spacer name="verticalSpacer_7">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>89</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
<widget class="QWidget" name="pageAdvanced">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
@@ -227,9 +377,6 @@
</widget>
</item>
</layout>
- <zorder>openCSGWarningBox</zorder>
- <zorder>enableOpenCSGBox</zorder>
- <zorder>forceGoldfeatherBox</zorder>
</widget>
</item>
<item>
@@ -317,6 +464,7 @@
</attribute>
<addaction name="prefsAction3DView"/>
<addaction name="prefsActionEditor"/>
+ <addaction name="prefsActionUpdate"/>
<addaction name="prefsActionAdvanced"/>
</widget>
<action name="prefsAction3DView">
@@ -355,6 +503,18 @@
<string>Editor</string>
</property>
</action>
+ <action name="prefsActionUpdate">
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <property name="icon">
+ <iconset resource="../openscad.qrc">
+ <normaloff>:/icons/prefsUpdate.png</normaloff>:/icons/prefsUpdate.png</iconset>
+ </property>
+ <property name="text">
+ <string>Update</string>
+ </property>
+ </action>
</widget>
<resources>
<include location="../openscad.qrc"/>
diff --git a/src/SparkleAutoUpdater.h b/src/SparkleAutoUpdater.h
new file mode 100644
index 0000000..786a190
--- /dev/null
+++ b/src/SparkleAutoUpdater.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2008 Remko Troncon. BSD license
+ * Copyright (C) 2013 Marius Kintel. BSD license
+ */
+#ifndef SPARKLEAUTOUPDATER_H
+#define SPARKLEAUTOUPDATER_H
+
+#include <QString>
+
+#include "AutoUpdater.h"
+
+class SparkleAutoUpdater : public AutoUpdater
+{
+public:
+ SparkleAutoUpdater();
+ ~SparkleAutoUpdater();
+
+ void checkForUpdates();
+ void setAutomaticallyChecksForUpdates(bool on);
+ bool automaticallyChecksForUpdates();
+ void setEnableSnapshots(bool on);
+ bool enableSnapshots();
+ QString lastUpdateCheckDate();
+
+private:
+ void updateFeed();
+
+ class Private;
+ Private *d;
+};
+
+#endif
diff --git a/src/SparkleAutoUpdater.mm b/src/SparkleAutoUpdater.mm
new file mode 100644
index 0000000..5176e80
--- /dev/null
+++ b/src/SparkleAutoUpdater.mm
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2008 Remko Troncon. BSD license
+ * Copyright (C) 2013 Marius Kintel. BSD license
+ */
+
+#include "SparkleAutoUpdater.h"
+
+#include <Cocoa/Cocoa.h>
+#include <Sparkle/Sparkle.h>
+
+NSString *const SUEnableSnapshotsKey = @"SUEnableSnapshots";
+
+class SparkleAutoUpdater::Private
+{
+public:
+ SUUpdater* updater;
+};
+
+SparkleAutoUpdater::SparkleAutoUpdater()
+{
+ d = new Private;
+
+ d->updater = [SUUpdater sharedUpdater];
+ [d->updater retain];
+
+ updateFeed();
+}
+
+SparkleAutoUpdater::~SparkleAutoUpdater()
+{
+ [d->updater release];
+ delete d;
+}
+
+void SparkleAutoUpdater::checkForUpdates()
+{
+ [d->updater checkForUpdatesInBackground];
+}
+
+void SparkleAutoUpdater::setAutomaticallyChecksForUpdates(bool on)
+{
+ [d->updater setAutomaticallyChecksForUpdates:on];
+}
+
+bool SparkleAutoUpdater::automaticallyChecksForUpdates()
+{
+ return [d->updater automaticallyChecksForUpdates];
+}
+
+void SparkleAutoUpdater::setEnableSnapshots(bool on)
+{
+ [[NSUserDefaults standardUserDefaults] setBool:on forKey:SUEnableSnapshotsKey];
+ updateFeed();
+}
+
+bool SparkleAutoUpdater::enableSnapshots()
+{
+ return [[NSUserDefaults standardUserDefaults] boolForKey:SUEnableSnapshotsKey];
+}
+
+QString SparkleAutoUpdater::lastUpdateCheckDate()
+{
+ NSString *datestring = [NSString stringWithFormat:@"Last checked: %@",
+ [d->updater lastUpdateCheckDate]];
+ return QString::fromUtf8([datestring UTF8String]);
+}
+
+void SparkleAutoUpdater::updateFeed()
+{
+ NSString *urlstring = [NSString stringWithFormat:@"http://openscad.org/appcast%@.xml", enableSnapshots() ? @"-snapshots" : @""];
+ [d->updater setFeedURL:[NSURL URLWithString:urlstring]];
+}
diff --git a/src/mainwin.cc b/src/mainwin.cc
index 17b9ef7..a05a4d4 100644
--- a/src/mainwin.cc
+++ b/src/mainwin.cc
@@ -48,6 +48,7 @@
#include "ProgressWidget.h"
#include "ThrownTogetherRenderer.h"
#include "csgtermnormalizer.h"
+#include "AutoUpdater.h"
#include <QMenu>
#include <QTime>
@@ -205,6 +206,16 @@ MainWindow::MainWindow(const QString &filename)
animate_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()));
@@ -781,6 +792,13 @@ void MainWindow::compileCSG(bool procevents)
}
}
+void MainWindow::actionUpdateCheck()
+{
+ if (AutoUpdater *updater =AutoUpdater::updater()) {
+ updater->checkForUpdates();
+ }
+}
+
void MainWindow::actionNew()
{
#ifdef ENABLE_MDI
diff --git a/src/openscad.cc b/src/openscad.cc
index 880aa0d..e0b4a68 100644
--- a/src/openscad.cc
+++ b/src/openscad.cc
@@ -54,6 +54,7 @@
#ifdef Q_WS_MAC
#include "EventFilter.h"
#include "AppleEvents.h"
+#include "SparkleAutoUpdater.h"
#endif
#include <boost/program_options.hpp>
@@ -386,6 +387,14 @@ int main(int argc, char **argv)
installAppleEventHandlers();
#endif
+#ifndef DEBUG
+#ifdef Q_WS_MAC
+ AutoUpdater *updater = new SparkleAutoUpdater;
+ AutoUpdater::setUpdater(updater);
+ if (updater->automaticallyChecksForUpdates()) updater->checkForUpdates();
+#endif
+#endif
+
QString qfilename;
if (filename) qfilename = QString::fromStdString(boosty::stringy(boosty::absolute(filename)));
contact: Jan Huwald // Impressum