-
Notifications
You must be signed in to change notification settings - Fork 0
/
PreferenceController.m
193 lines (127 loc) · 5.08 KB
/
PreferenceController.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#import "PreferenceController.h"
NSString *JKBMessageCheckInterval = @"MessageCheckInterval";
NSString *JKBCountInboxOrAll = @"CountInboxOrAll";
NSString *JKBOpenOnLogin = @"OpenOnLogin";
NSString *JKBLaunchMailOnCount = @"LaunchMailOnCount";
@implementation PreferenceController
- (id)init
{
self = [super initWithWindowNibName:@"Preferences"];
return self;
}
- (void)windowDidLoad
{
// Set the preference window elements to reflect the user's preferences
NSNumber *intervalSecondsUserDefaults;
intervalSecondsUserDefaults = [[NSUserDefaults standardUserDefaults] objectForKey: JKBMessageCheckInterval];
[intervalSecondsTextField setIntValue: [intervalSecondsUserDefaults intValue]];
NSNumber *countInboxOrAllUserDefaults;
countInboxOrAllUserDefaults = [[NSUserDefaults standardUserDefaults] objectForKey: JKBCountInboxOrAll];
if ([countInboxOrAllUserDefaults intValue] == 1)
[countInboxOrAll selectCellAtRow: 0 column: 0];
else if ([countInboxOrAllUserDefaults intValue] == 2)
[countInboxOrAll selectCellAtRow: 1 column: 0];
BOOL launchMailOnCountUserDefaults;
launchMailOnCountUserDefaults = [[[NSUserDefaults standardUserDefaults] objectForKey: JKBLaunchMailOnCount] boolValue];
if (launchMailOnCountUserDefaults == YES)
[launchMailOnCountCheckbox setState: NSOnState];
else
[launchMailOnCountCheckbox setState: NSOffState];
BOOL openAtLoginUserDefaults;
openAtLoginUserDefaults = [[[NSUserDefaults standardUserDefaults] objectForKey: JKBOpenOnLogin] boolValue];
if (openAtLoginUserDefaults == YES)
[openOnLoginCheckbox setState: NSOnState];
else
[openOnLoginCheckbox setState: NSOffState];
}
// Because our application is only a status bar item, it is never activated.
// Therefore, we must activate the preference window manually when it is
// asked to display itself
- (IBAction)showWindow:(id)sender
{
[super showWindow: sender];
[[self window] orderFrontRegardless];
}
- (int) checkInterval
{
NSNumber *checkIntervalUserDefaults;
NSUserDefaults *userDefaults;
userDefaults = [NSUserDefaults standardUserDefaults];
checkIntervalUserDefaults = [userDefaults objectForKey: JKBMessageCheckInterval];
NSLog(@"Interval checked. Returned %i", [checkIntervalUserDefaults intValue]);
return [checkIntervalUserDefaults intValue];
}
- (int)countInboxOrAll
{
NSNumber *countInboxOrAllUserDefaults;
NSUserDefaults *userDefaults;
userDefaults = [NSUserDefaults standardUserDefaults];
countInboxOrAllUserDefaults = [userDefaults objectForKey: JKBCountInboxOrAll];
return [countInboxOrAllUserDefaults intValue];
}
- (BOOL)launchMailOnCount
{
BOOL launchMailOnCountUserDefaults;
NSUserDefaults *userDefaults;
userDefaults = [NSUserDefaults standardUserDefaults];
launchMailOnCountUserDefaults = [[userDefaults objectForKey: JKBLaunchMailOnCount] boolValue];
return launchMailOnCountUserDefaults;
}
- (BOOL)openOnLogin
{
BOOL openAtLoginUserDefaults;
NSUserDefaults *userDefaults;
userDefaults = [NSUserDefaults standardUserDefaults];
openAtLoginUserDefaults = [[userDefaults objectForKey: JKBOpenOnLogin] boolValue];
return openAtLoginUserDefaults;
}
- (IBAction)changeCheckInterval:(id)sender
{
NSNumber *newCheckInterval;
newCheckInterval = [NSNumber numberWithInt: [sender intValue]];
NSUserDefaults *userDefaults;
userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject: newCheckInterval forKey: JKBMessageCheckInterval];
NSLog(@"Changed value to the number: %i", [sender intValue]);
NSNotificationCenter *nc;
nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName: @"JKBTimerIntervalChanged" object: self];
}
- (IBAction)changeCountInboxOrAll:(id)sender
{
NSNumber *newCountInboxOrAllValue;
NSUserDefaults *userDefaults;
if ([sender selectedRow] == 0)
newCountInboxOrAllValue = [NSNumber numberWithInt: 1];
else if ([sender selectedRow] == 1)
newCountInboxOrAllValue = [NSNumber numberWithInt: 2];
userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject: newCountInboxOrAllValue forKey: JKBCountInboxOrAll];
NSLog(@"Changed Count Inbox or All value to: %i", [newCountInboxOrAllValue intValue]);
}
- (IBAction)changeLaunchMailOnCount:(id)sender
{
BOOL newLaunchMailOnCountValue;
NSUserDefaults *userDefaults;
if ([sender state] == NSOnState)
newLaunchMailOnCountValue = YES;
else if ([sender state] == NSOffState)
newLaunchMailOnCountValue = NO;
userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject: [NSNumber numberWithBool: newLaunchMailOnCountValue] forKey: JKBLaunchMailOnCount];
}
- (IBAction)changeOpenOnLogin:(id)sender
{
BOOL newOpenOnLoginValue;
NSUserDefaults *userDefaults;
if ([sender state] == NSOnState)
newOpenOnLoginValue = YES;
else if ([sender state] == NSOffState)
newOpenOnLoginValue = NO;
userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject: [NSNumber numberWithBool: newOpenOnLoginValue] forKey: JKBOpenOnLogin];
NSNotificationCenter *nc;
nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName: @"JKBCheckInboxOrAllChanged" object: self];
}
@end