summaryrefslogtreecommitdiff
path: root/src/SparkleAutoUpdater.mm
blob: c52e2bbf4c84825e6471ac15e7e5c668240f241d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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()
{
  NSDate *date = [d->updater lastUpdateCheckDate];
  NSString *datestring = date ? [NSString stringWithFormat:@"Last checked: %@", date] : @"";
  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]];
}
contact: Jan Huwald // Impressum