Files
textmate/Frameworks/Preferences/src/SoftwareUpdatePreferences.mm
2012-10-24 18:19:18 +07:00

79 lines
2.8 KiB
Plaintext

#import "SoftwareUpdatePreferences.h"
#import "Keys.h"
#import <CrashReporter/CrashReporter.h>
#import <OakAppKit/NSImage Additions.h>
#import <OakFoundation/NSDate Additions.h>
#import <OakFoundation/OakStringListTransformer.h>
#import <SoftwareUpdate/SoftwareUpdate.h>
// kUserDefaultsLastSoftwareUpdateCheckKey
// kUserDefaultsLastBundleUpdateCheckKey
@interface SoftwareUpdatePreferences ()
@property (nonatomic, assign) BOOL isChecking;
@property (nonatomic, retain) NSDate* lastPoll;
@property (nonatomic, retain) NSString* errorString;
@property (nonatomic, retain) NSString* lastPollString;
@property (nonatomic, retain) NSTimer* updateLastPollStringTimer;
@end
@implementation SoftwareUpdatePreferences
+ (NSSet*)keyPathsForValuesAffectingLastCheck { return [NSSet setWithObjects:@"isChecking", @"lastPollString", @"errorString", nil]; }
- (id)init
{
if(self = [super initWithNibName:@"SoftwareUpdatePreferences" label:@"Software Update" image:[NSImage imageNamed:@"Software Update" inSameBundleAsClass:[self class]]])
{
[OakStringListTransformer createTransformerWithName:@"OakSoftwareUpdateChannelTransformer" andObjectsArray:@[ kSoftwareUpdateChannelRelease, kSoftwareUpdateChannelBeta ]];
[self bind:@"isChecking" toObject:[SoftwareUpdate sharedInstance] withKeyPath:@"isChecking" options:nil];
[self bind:@"lastPoll" toObject:[SoftwareUpdate sharedInstance] withKeyPath:@"lastPoll" options:nil];
[self bind:@"errorString" toObject:[SoftwareUpdate sharedInstance] withKeyPath:@"errorString" options:nil];
self.defaultsProperties = [NSDictionary dictionaryWithObjectsAndKeys:
kUserDefaultsDisableSoftwareUpdatesKey, @"disableSoftwareUpdates",
kUserDefaultsDisableBundleUpdatesKey, @"disableBundleUpdates",
kUserDefaultsDisableCrashReportingKey, @"disableCrashReports",
kUserDefaultsSoftwareUpdateChannelKey, @"softwareUpdateChannel",
kUserDefaultsAskBeforeUpdatingKey, @"askBeforeDownloading",
kUserDefaultsSubmitUsageInfoKey, @"submitUsageInfo",
kUserDefaultsCrashReportsContactInfoKey, @"contactInfo",
nil];
}
return self;
}
- (IBAction)performSoftwareUpdateCheck:(id)sender
{
[[SoftwareUpdate sharedInstance] checkForUpdates:self];
}
- (NSString*)lastCheck
{
return _isChecking ? @"Checking…" : (_errorString ?: (_lastPollString ?: @"Never"));
}
- (void)updateLastPollString:(id)sender
{
self.lastPollString = [self.lastPoll humanReadableTimeElapsed];
}
- (void)setLastPoll:(NSDate*)aDate
{
_lastPoll = aDate;
[self updateLastPollString:self];
}
- (void)viewWillAppear
{
[self updateLastPollString:nil];
self.updateLastPollStringTimer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(updateLastPollString:) userInfo:nil repeats:YES];
}
- (void)viewDidDisappear
{
[self.updateLastPollStringTimer invalidate];
self.updateLastPollStringTimer = nil;
}
@end