forked from robbiehanson/AlarmClock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prefs.m
244 lines (194 loc) · 7.32 KB
/
Prefs.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#import "Prefs.h"
// General Preferences
#define COLORED_ICONS_KEY @"ColoredIcons"
#define ALARM_VOLUME_KEY @"AlarmVolume"
#define SNOOZE_DURATION_KEY @"SnoozeDuration"
#define KILL_DURATION_KEY @"KillDuration"
// Easy Wake Preferences
#define EASY_WAKE_DEFAULT_KEY @"EasyWakeDefault"
#define INITIAL_VOLUME_KEY @"InitialVolume"
#define FINAL_VOLUME_KEY @"FinalVolume"
#define EASY_WAKE_DURATION_KEY @"EasyWakeDuration"
// Advanced Preferences
#define WAKE_FROM_SLEEP_KEY @"WakeFromSleep"
#define ANY_KEY_STOPS_KEY @"AnyKeyStops"
#define LAUNCH_AT_LOGIN_KEY @"LaunchAtLogin"
#define APPLE_REMOTE_KEY @"AppleRemote"
// Hidden Preferences
#define FIRST_RUN_KEY @"FirstRun"
#define XML_PATH_KEY @"XMLPath"
#define DIGITAL_AUDIO_KEY @"DigitalAudio"
@implementation Prefs
// INITIALIZATION, DEINITIALIZATION
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
This method is automatically called (courtesy of Cocoa) before the first instantiation of this class.
We use it to register default values for the app's preferences.
**/
+ (void)initialize
{
static BOOL initialized = NO;
if(!initialized)
{
NSLog(@"Initializing Prefs...");
/* Register Default Values */
// Create a dictionary to hold the default preferences
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
// General Preferences
[defaultValues setObject:[NSNumber numberWithBool:YES] forKey:COLORED_ICONS_KEY];
[defaultValues setObject:[NSNumber numberWithFloat:0.6] forKey:ALARM_VOLUME_KEY];
[defaultValues setObject:[NSNumber numberWithInt:8] forKey:SNOOZE_DURATION_KEY];
[defaultValues setObject:[NSNumber numberWithInt:15] forKey:KILL_DURATION_KEY];
// Alarm Preferences
[defaultValues setObject:[NSNumber numberWithFloat:0.25] forKey:INITIAL_VOLUME_KEY];
[defaultValues setObject:[NSNumber numberWithFloat:1.0] forKey:FINAL_VOLUME_KEY];
[defaultValues setObject:[NSNumber numberWithInt:2] forKey:EASY_WAKE_DURATION_KEY];
// Advanced Preferences
[defaultValues setObject:[NSNumber numberWithBool:NO] forKey:WAKE_FROM_SLEEP_KEY];
[defaultValues setObject:[NSNumber numberWithBool:NO] forKey:ANY_KEY_STOPS_KEY];
[defaultValues setObject:[NSNumber numberWithBool:NO] forKey:LAUNCH_AT_LOGIN_KEY];
[defaultValues setObject:[NSNumber numberWithBool:YES] forKey:APPLE_REMOTE_KEY];
// Hidden Preferences
[defaultValues setObject:[NSNumber numberWithBool:YES] forKey:FIRST_RUN_KEY];
[defaultValues setObject:@"" forKey:XML_PATH_KEY];
[defaultValues setObject:[NSNumber numberWithBool:NO] forKey:DIGITAL_AUDIO_KEY];
// Register default values
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
// Update initialization status
initialized = YES;
}
}
/**
Called (via our application delegate) when the application is terminating.
All cleanup tasks should go here.
**/
+ (void)deinitialize
{
// Nothing to do here.
// NSUserDefaults automatically takes flushes changes to the disk, and forces a flush prior to termination.
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark General Preferences
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ (BOOL)useColoredIcons
{
return [[NSUserDefaults standardUserDefaults] boolForKey:COLORED_ICONS_KEY];
}
+ (void)setUseColoredIcons:(BOOL)flag
{
[[NSUserDefaults standardUserDefaults] setBool:flag forKey:COLORED_ICONS_KEY];
}
+ (float)prefVolume
{
return [[NSUserDefaults standardUserDefaults] floatForKey:ALARM_VOLUME_KEY];
}
+ (void)setPrefVolume:(float)volume
{
[[NSUserDefaults standardUserDefaults] setFloat:volume forKey:ALARM_VOLUME_KEY];
}
+ (int)snoozeDuration
{
return [[NSUserDefaults standardUserDefaults] integerForKey:SNOOZE_DURATION_KEY];
}
+ (void)setSnoozeDuration:(int)time
{
[[NSUserDefaults standardUserDefaults] setInteger:time forKey:SNOOZE_DURATION_KEY];
}
+ (int)killDuration
{
return [[NSUserDefaults standardUserDefaults] integerForKey:KILL_DURATION_KEY];
}
+ (void)setKillDuration:(int)duration
{
[[NSUserDefaults standardUserDefaults] setInteger:duration forKey:KILL_DURATION_KEY];
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Easy Wake Preferences
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ (BOOL)useEasyWakeByDefault
{
return [[NSUserDefaults standardUserDefaults] boolForKey:EASY_WAKE_DEFAULT_KEY];
}
+ (void)setUseEasyWakeByDefault:(BOOL)flag
{
[[NSUserDefaults standardUserDefaults] setBool:flag forKey:EASY_WAKE_DEFAULT_KEY];
}
+ (float)minVolume
{
return [[NSUserDefaults standardUserDefaults] floatForKey:INITIAL_VOLUME_KEY];
}
+ (void)setMinVolume:(float)volume
{
[[NSUserDefaults standardUserDefaults] setFloat:volume forKey:INITIAL_VOLUME_KEY];
}
+ (float)maxVolume
{
return [[NSUserDefaults standardUserDefaults] floatForKey:FINAL_VOLUME_KEY];
}
+ (void)setMaxVolume:(float)volume
{
[[NSUserDefaults standardUserDefaults] setFloat:volume forKey:FINAL_VOLUME_KEY];
}
+ (int)easyWakeDuration
{
return [[NSUserDefaults standardUserDefaults] integerForKey:EASY_WAKE_DURATION_KEY];
}
+ (void)setEasyWakeDuration:(int)duration
{
[[NSUserDefaults standardUserDefaults] setInteger:duration forKey:EASY_WAKE_DURATION_KEY];
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Advanced Preferences
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ (BOOL)wakeFromSleep
{
return [[NSUserDefaults standardUserDefaults] boolForKey:WAKE_FROM_SLEEP_KEY];
}
+ (void)setWakeFromSleep:(BOOL)flag
{
[[NSUserDefaults standardUserDefaults] setBool:flag forKey:WAKE_FROM_SLEEP_KEY];
}
+ (BOOL)anyKeyStops
{
return [[NSUserDefaults standardUserDefaults] boolForKey:ANY_KEY_STOPS_KEY];
}
+ (void)setAnyKeyStops:(BOOL)flag
{
[[NSUserDefaults standardUserDefaults] setBool:flag forKey:ANY_KEY_STOPS_KEY];
}
+ (BOOL)launchAtLogin
{
return [[NSUserDefaults standardUserDefaults] boolForKey:LAUNCH_AT_LOGIN_KEY];
}
+ (void)setLaunchAtLogin:(BOOL)flag
{
[[NSUserDefaults standardUserDefaults] setBool:flag forKey:LAUNCH_AT_LOGIN_KEY];
}
+ (BOOL)supportAppleRemote
{
return [[NSUserDefaults standardUserDefaults] boolForKey:APPLE_REMOTE_KEY];
}
+ (void)setSupportAppleRemote:(BOOL)flag
{
[[NSUserDefaults standardUserDefaults] setBool:flag forKey:APPLE_REMOTE_KEY];
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma mark Hidden Preferences
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+ (BOOL)isFirstRun
{
return [[NSUserDefaults standardUserDefaults] boolForKey:FIRST_RUN_KEY];
}
+ (void)setIsFirstRun:(BOOL)flag
{
[[NSUserDefaults standardUserDefaults] setBool:flag forKey:FIRST_RUN_KEY];
}
+ (NSString *)xmlPath
{
return [[NSUserDefaults standardUserDefaults] stringForKey:XML_PATH_KEY];
}
+ (BOOL)digitalAudio
{
return [[NSUserDefaults standardUserDefaults] boolForKey:DIGITAL_AUDIO_KEY];
}
@end