-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppController.m
More file actions
67 lines (53 loc) · 1.43 KB
/
Copy pathAppController.m
File metadata and controls
67 lines (53 loc) · 1.43 KB
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
#import "AppController.h"
#import "PasswordStorage.h"
#import "BirthdaySyncer.h"
#import "BirthdaySyncConstants.h"
@interface AppController (Private)
- (void) startSync;
- (void) endSync:(BirthdaySyncer*)bs;
@end
@implementation AppController
@synthesize syncInProgress;
- (void)awakeFromNib {
NSString *pw = getBirthdaySyncPassword();
if (pw) {
[gui_password setStringValue:pw];
}
[gui_password setDelegate:self];
[[NSUserDefaults standardUserDefaults]
addObserver:self
forKeyPath:kEnableSyncPref
options:NSKeyValueObservingOptionNew
context:NULL];
}
-(void) controlTextDidEndEditing:(NSNotification *)aNotification {
saveBirthdaySyncPassword([gui_password stringValue]);
}
- (void) observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
BOOL enabled = [[NSUserDefaults standardUserDefaults] boolForKey:kEnableSyncPref];
if (enabled) {
[BirthdaySyncer registerWithSyncServices];
}
else {
[BirthdaySyncer unregisterFromSyncServices];
}
}
- (IBAction) syncNow:(id)sender {
[self startSync];
}
@end
@implementation AppController (Private)
- (void) startSync {
[self setSyncInProgress:YES];
BirthdaySyncer *bs = [[BirthdaySyncer alloc] init];
[bs runAsynchronousSyncAndCall:self
selector:@selector(endSync:)];
}
- (void) endSync:(BirthdaySyncer*)bs {
[bs release];
[self setSyncInProgress:NO];
}
@end