|
@@ -19,6 +19,7 @@
|
19
|
19
|
#define CONFIG_MILITARY_TIME @"military_time"
|
20
|
20
|
#define CONFIG_SHOW_DATE @"show_date"
|
21
|
21
|
#define CONFIG_ALARM_TIME @"alarm_time"
|
|
22
|
+#define CONFIG_ALARM_MODE @"alarm_mode"
|
22
|
23
|
|
23
|
24
|
#define MOUSE_CENTER_X 67
|
24
|
25
|
#define MOUSE_CENTER_Y 47
|
|
@@ -52,6 +53,8 @@
|
52
|
53
|
@property (weak) IBOutlet NSMenuItem *keepOnTopItem;
|
53
|
54
|
@property (weak) IBOutlet NSMenuItem *setAlarmItem;
|
54
|
55
|
@property (weak) IBOutlet NSMenuItem *showDateItem;
|
|
56
|
+@property (weak) IBOutlet NSMenuItem *alarmModeItem;
|
|
57
|
+@property (weak) IBOutlet NSMenuItem *alarmTextItem;
|
55
|
58
|
|
56
|
59
|
@property (weak) IBOutlet NSMenuItem *changeSize1;
|
57
|
60
|
@property (weak) IBOutlet NSMenuItem *changeSize2;
|
|
@@ -154,6 +157,8 @@
|
154
|
157
|
self.alarmDatePicker.dateValue = [defaults objectForKey:CONFIG_ALARM_TIME];
|
155
|
158
|
}
|
156
|
159
|
self.setAlarmItem.view = self.alarmDatePicker;
|
|
160
|
+ NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:self.alarmDatePicker.dateValue];
|
|
161
|
+ [self.alarmTextItem setTitle:[NSString stringWithFormat:@"%02ld:%02ld", (long)[components hour], (long)[components minute]]];
|
157
|
162
|
|
158
|
163
|
// load show date state
|
159
|
164
|
if ([defaults objectForKey:CONFIG_SHOW_DATE] == nil) {
|
|
@@ -167,11 +172,37 @@
|
167
|
172
|
self.showDateItem.state = NSOffState;
|
168
|
173
|
}
|
169
|
174
|
|
|
175
|
+ if ([defaults objectForKey:CONFIG_ALARM_MODE] != nil) {
|
|
176
|
+ if ([defaults boolForKey:CONFIG_ALARM_MODE] == YES) {
|
|
177
|
+ [self.alarmModeItem setState:NSOnState];
|
|
178
|
+ [[self.mainView render] drawAlarmDate:self.alarmDatePicker.dateValue];
|
|
179
|
+ }
|
|
180
|
+ }
|
|
181
|
+
|
170
|
182
|
[[self.mainView render] drawDate:showDate];
|
171
|
183
|
|
172
|
184
|
[self setFrame:frame display:YES];
|
173
|
185
|
}
|
174
|
186
|
|
|
187
|
+- (IBAction)toggleAlarm:(id)sender {
|
|
188
|
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
189
|
+
|
|
190
|
+ if (self.alarmModeItem.state == NSOnState) {
|
|
191
|
+ // Turn off alarm
|
|
192
|
+ [self.alarmModeItem setState:NSOffState];
|
|
193
|
+ [[self.mainView render] drawAlarmDate:nil];
|
|
194
|
+ [defaults setBool:NO forKey:CONFIG_ALARM_MODE];
|
|
195
|
+ } else {
|
|
196
|
+ // Turn on alarm
|
|
197
|
+ [self.alarmModeItem setState:NSOnState];
|
|
198
|
+ [[self.mainView render] drawAlarmDate:self.alarmDatePicker.dateValue];
|
|
199
|
+ [defaults setBool:YES forKey:CONFIG_ALARM_MODE];
|
|
200
|
+ }
|
|
201
|
+
|
|
202
|
+ [defaults synchronize];
|
|
203
|
+ self.mainView.needsDisplay = YES;
|
|
204
|
+}
|
|
205
|
+
|
175
|
206
|
- (void)drawAnimation:(NSNumber *)anim {
|
176
|
207
|
if ([anim integerValue] > (3 * ANIMATION_SHADOW_HACK)) {
|
177
|
208
|
[[self.mainView render] drawAnimation:0]; // reset
|
|
@@ -194,7 +225,7 @@
|
194
|
225
|
|
195
|
226
|
// Check if a second went by
|
196
|
227
|
NSDate *now = [NSDate date];
|
197
|
|
- NSDateComponents *components = [[NSCalendar currentCalendar] components:NSSecondCalendarUnit fromDate:now];
|
|
228
|
+ NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:now];
|
198
|
229
|
static NSInteger lastSec = -1;
|
199
|
230
|
if (lastSec == [components second]) {
|
200
|
231
|
return;
|
|
@@ -204,11 +235,13 @@
|
204
|
235
|
[[self.mainView render] drawWithDate:now];
|
205
|
236
|
[[self.mainView render] blinkDots];
|
206
|
237
|
|
207
|
|
- NSTimeInterval in = [now timeIntervalSinceDate:self.alarmDatePicker.dateValue];
|
208
|
|
- if ((in >= -0.5) && (in <= 0.5)) {
|
209
|
|
- // We have reached the alarm time
|
210
|
|
- NSLog(@"Alarm time reached!");
|
211
|
|
- [self drawAnimation:[NSNumber numberWithInteger:1]];
|
|
238
|
+ if (self.alarmModeItem.state == NSOnState) {
|
|
239
|
+ NSDateComponents *alarmComponents = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:self.alarmDatePicker.dateValue];
|
|
240
|
+ if (([components minute] == [alarmComponents minute]) && ([components hour] == [alarmComponents hour]) && ([components second] == 0)) {
|
|
241
|
+ // We have reached the alarm time
|
|
242
|
+ NSLog(@"Alarm time reached!");
|
|
243
|
+ [self drawAnimation:[NSNumber numberWithInteger:1]];
|
|
244
|
+ }
|
212
|
245
|
}
|
213
|
246
|
|
214
|
247
|
self.mainView.needsDisplay = YES;
|
|
@@ -235,8 +268,14 @@
|
235
|
268
|
}
|
236
|
269
|
|
237
|
270
|
- (IBAction)alarmDateSelected:(id)sender {
|
238
|
|
- [[self.mainView render] drawAlarmDate:self.alarmDatePicker.dateValue];
|
239
|
|
- self.mainView.needsDisplay = YES;
|
|
271
|
+ // Update text representation
|
|
272
|
+ NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:self.alarmDatePicker.dateValue];
|
|
273
|
+ [self.alarmTextItem setTitle:[NSString stringWithFormat:@"%02ld:%02ld", (long)[components hour], (long)[components minute]]];
|
|
274
|
+
|
|
275
|
+ if (self.alarmModeItem.state == NSOnState) {
|
|
276
|
+ [[self.mainView render] drawAlarmDate:self.alarmDatePicker.dateValue];
|
|
277
|
+ self.mainView.needsDisplay = YES;
|
|
278
|
+ }
|
240
|
279
|
|
241
|
280
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
242
|
281
|
[defaults setObject:self.alarmDatePicker.dateValue forKey:CONFIG_ALARM_TIME];
|