diff options
author | Marius Kintel <marius@kintel.net> | 2013-02-05 05:36:25 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-02-05 05:36:25 (GMT) |
commit | fa00547507566a646db2baffea114104b1ffd567 (patch) | |
tree | 85d8d3e09c9b4c1f651829042e20b061166ea415 /src/SparkleAutoUpdater.mm | |
parent | 03be37d16b585e64de87118053206aaae06e7cf8 (diff) |
First version of automatic updates for Mac
Diffstat (limited to 'src/SparkleAutoUpdater.mm')
-rw-r--r-- | src/SparkleAutoUpdater.mm | 72 |
1 files changed, 72 insertions, 0 deletions
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]]; +} |