-
Notifications
You must be signed in to change notification settings - Fork 1
/
PrefsController.m
60 lines (48 loc) · 1.57 KB
/
PrefsController.m
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
//
// PrefsController.m
// SABnzbdDropTarget
//
// Created by Thomas Schoendorfer on 10-10-18.
// Copyright 2010 Thomas Schoendorfer. All rights reserved.
//
#import "PrefsController.h"
@implementation PrefsController
@synthesize host;
@synthesize apiKey;
@synthesize hostField;
@synthesize apiKeyField;
-(id) init {
if(![super initWithWindowNibName:@"Prefs"])
return nil;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"default host: %@", [defaults URLForKey:HostPrefKey]);
[self setHost:[defaults URLForKey:HostPrefKey]];
NSLog(@"default apikey: %@", [defaults objectForKey:APIKeyPrefKey]);
[self setApiKey:[defaults objectForKey:APIKeyPrefKey]];
return self;
}
-(void) windowDidLoad {
[[self window] setDelegate:self];
[self displayDefaults];
}
-(void) savePreferences {
[self setHost:[NSURL URLWithString:[hostField stringValue]]];
NSLog(@"New host value: %@", [self host]);
[self setApiKey:[apiKeyField stringValue]];
NSLog(@"New apikey value: %@", [self apiKey]);
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setURL:host forKey:HostPrefKey];
NSLog(@"new default host: %@", [defaults URLForKey:HostPrefKey]);
[defaults setObject:apiKey forKey:APIKeyPrefKey];
NSLog(@"new default apikey: %@", [defaults objectForKey:APIKeyPrefKey]);
[defaults synchronize];
}
-(void) displayDefaults {
[hostField setStringValue:[[self host] description]];
[apiKeyField setStringValue:[self apiKey]];
}
-(void)windowWillClose:(NSNotification *)notification {
NSLog(@"Prefs window will close");
[self savePreferences];
}
@end