-
Notifications
You must be signed in to change notification settings - Fork 1
/
CurrentAlarms.m
651 lines (579 loc) · 23.5 KB
/
CurrentAlarms.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/* Copyright © 2003, Leaky Puppy Software, Net Monkey Inc.
This file is part of Fob.
Fob is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Fob is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Fob; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
// CurrentAlarms.m
// Fob
//
// Created by Thomas Finley on Sat Jan 11 2003.
// Copyright (c) 2003 Leaky Puppy Software, for Net Monkey Inc. All rights reserved.
// This program is distributed under the terms of the GNU General Public License.
#import "CurrentAlarms.h"
#import "Alarm.h"
#import "TimeInputController.h"
#import "prefs.h"
#import "PresetAlarms.h"
#import "AttentionGrabber.h"
#import "DoneAction.h"
#import "ZoomSwitcher.h"
#import "DoneActionInputController.h"
CurrentAlarms * defaultCurrentDatabase = nil;
@implementation CurrentAlarms
- (void)awakeFromNib {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSAssert(!defaultCurrentDatabase, @"More than one CurrentAlarms instance awoken from a nib file!");
defaultCurrentDatabase = self;
lastSelectedAlarm = nil;
[presetTable setDoubleAction:@selector(doubleClickPresets:)];
[presetTable setTarget:self];
[currentTable setDoubleAction:@selector(doubleClickCurrent:)];
[currentTable setTarget:self];
[littleCurrentTable setDoubleAction:@selector(doubleClickCurrent:)];
[littleCurrentTable setTarget:self];
// Self listening, and paused collection listening.
[nc addObserver:self
selector:@selector(handleAlarmsChanged:)
name:@"FobAlarmAdded"
object:self];
[nc addObserver:self
selector:@selector(handleAlarmsChanged:)
name:@"FobAlarmRemoved"
object:self];
[nc addObserver:self
selector:@selector(handleAlarmsChanged:)
name:@"FobAlarmAdded"
object:paused];
[nc addObserver:self
selector:@selector(handleAlarmsChanged:)
name:@"FobAlarmRemoved"
object:paused];
// Table listening.
[nc addObserver:self
selector:@selector(handleTableDelete:)
name:@"FobTableDelete"
object:currentTable];
[nc addObserver:self
selector:@selector(handleTableDelete:)
name:@"FobTableDelete"
object:littleCurrentTable];
// Time view listening.
/*[nc addObserver:self
selector:@selector(handleTimeChanged:)
name:@"FobTimeUserChanged"
object:timeView];*/
// Alarm listening.
[nc addObserver:self
selector:@selector(handleAlarmTick:)
name:@"FobAlarmTick"
object:nil];
[nc addObserver:self
selector:@selector(handleAlarmDone:)
name:@"FobAlarmDone"
object:nil];
// We want to change the view when the table selections change.
[nc addObserver:self
selector:@selector(handleTableSelection:)
name:@"NSTableViewSelectionDidChangeNotification"
object:nil];
// We want to change the view when the done action changes.
[nc addObserver:self
selector:@selector(handleDoneActionChange:)
name:@"FobDoneActionChange"
object:nil];
[nc addObserver:self
selector:@selector(handleQuit:)
name:@"NSApplicationWillTerminateNotification"
object:nil];
[currentTable reloadData];
[littleCurrentTable reloadData];
}
- (id)init {
if (self = [super init]) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *pausedArray = correspondingObjectArray([defaults objectForKey:FobPausedAlarmsKey]);
NSEnumerator *enumerator = [pausedArray objectEnumerator];
Alarm *pausedAlarm;
alarms = [correspondingObjectArray([defaults objectForKey:FobActiveAlarmsKey]) retain];
[alarms sortUsingSelector:@selector(timeCompare:)];
paused = [[AlarmCollection alloc] init];
while (pausedAlarm = [enumerator nextObject])
[paused add:pausedAlarm];
oldAlarm = lastSelectedAlarm = nil;
activeAlarmColor = [[NSColor blackColor] retain];
pausedAlarmColor = [[NSColor grayColor] retain];
}
return self;
}
- (void)dealloc {
[self reformCurrentDefaults];
[paused release];
[activeAlarmColor release];
[pausedAlarmColor release];
[super dealloc];
}
/* Fob has the option to display a miniaturized version of itself. This is accomplished by creating a second, smaller window, with an alternate display. This returns the "current" alarm table for the present view, whether that present current table is in the big window or in the miniaturized window. */
- (NSTableView *)displayedTableView {
return [[currentTable window] isVisible] ? currentTable : littleCurrentTable;
}
/* This returns an alarm at a given row within the table of current alarms. */
- (Alarm *)alarmAtRow:(unsigned)row {
int c = [alarms count];
return row < c ? [alarms objectAtIndex:row] :
[[paused alarms] objectAtIndex:row-c];
}
/* Given an alarm, this returns the row that alarm is at. If the alarm is not present, the results are undefined. */
- (int)rowForAlarm:(Alarm *)alarm {
int row = [self findEntryForAlarm:alarm];
return row>=0 ? row : [paused findEntryForAlarm:alarm]+[alarms count];
}
/* This returns an array of those alarms that are selected within the table of current alarms. */
- (NSArray *)selectedAlarms {
NSTableView *table = [self displayedTableView];
int toGet = [table numberOfSelectedRows], i;
NSMutableArray * array = [NSMutableArray arrayWithCapacity:toGet];
for (i=0; toGet; i++) {
if ([table isRowSelected:i]) {
[array addObject:[self alarmAtRow:i]];
toGet--;
}
}
return array;
}
+ (CurrentAlarms *)defaultDatabase {
return defaultCurrentDatabase;
}
/* This will add an alarm. The alarm added must have some time left.. */
- (void)rawAdd:(Alarm *)alarm {
if (![alarm millisecondsRemaining]) {
NSBeginAlertSheet(NSLocalizedString(@"CurrentNonzeroTimeTitle", nil),
nil, nil, nil, window,
nil, nil, nil, nil,
NSLocalizedString(@"CurrentNonzeroTimeMessage", nil));
return;
}
[alarm start]; // Make sure it's started!
[super add:alarm];
}
- (int)add:(Alarm *)alarm {
[self rawAdd:alarm];
[self reformCurrentDefaults];
return 0;
}
- (void)pause:(Alarm *)alarm {
//NSLog(@"Pausing %@", alarm);
if (![alarm millisecondsRemaining]) {
NSBeginAlertSheet(NSLocalizedString(@"PauseZeroTimeTitle", nil),
nil, nil, nil, window,
nil, nil, nil, nil,
NSLocalizedString(@"PauseZeroTimeMessage", nil));
return;
}
[alarm pause];
if ([paused findEntryForAlarm:alarm] >= 0) return;
[paused add:alarm];
NSAssert([self remove:alarm], @"Attempted to pause a paused alarm!");
//int rowPaused = [paused findEntryForAlarm:alarm];
//[currentTable deselectRow:rowCurrent];
//[currentTable selectRow:rowPaused+[alarms count] byExtendingSelection:YES];
}
- (void)unpause:(Alarm *)alarm {
//NSLog(@"Unpausing %@", alarm);
if ([self findEntryForAlarm:alarm] >= 0) return;
[self rawAdd:alarm];
NSAssert([paused remove:alarm], @"Attempted to unpause an active alarm!");
}
- (void)rewind:(Alarm *)alarm {
//NSLog(@"Rewinding %@", alarm);
if ([self findEntryForAlarm:alarm] >= 0) {
// It's an active alarm.
[alarm retain];
NSAssert([self remove:alarm], @"Can't remove the alarm during rewind!");
[alarm rewind];
[self rawAdd:alarm];
[alarm release];
} else if ([paused findEntryForAlarm:alarm] >= 0) {
// It's a paused alarm.
[alarm retain];
NSAssert([paused remove:alarm], @"Can't remove the paused alarm during rewind!");
[alarm rewind];
[paused add:alarm];
[alarm release];
}
}
- (void)setTime:(Alarm *)alarm toMilliseconds:(long long)ms {
//NSLog(@"Setting time for %@ to %ld", alarm, ms);
ms -= 1000; // For some reason a second is added if there is not an adjustment.
if ([self findEntryForAlarm:alarm] >= 0) {
// It's an active alarm.
NSAssert([self remove:alarm], @"Can't remove the alarm during rewind!");
[alarm setMillisecondsRemaining:ms];
[self rawAdd:alarm];
} else if ([paused findEntryForAlarm:alarm] >= 0) {
// It's a paused alarm.
NSAssert([paused remove:alarm], @"Can't remove the paused alarm during rewind!");
[alarm setMillisecondsRemaining:ms];
[paused add:alarm];
}
}
- (void)handleTimeChanged:(NSNotification *)note {
long long ms = [timeView milliseconds];
NSArray *selected = [self selectedAlarms];
NSEnumerator *enumerator = [selected objectEnumerator];
NSTableView *tv = [self displayedTableView];
Alarm *alarm;
while (alarm = [enumerator nextObject])
[self setTime:alarm toMilliseconds:ms];
[tv deselectAll:nil];
enumerator = [selected objectEnumerator];
while (alarm = [enumerator nextObject])
[tv selectRow:[self rowForAlarm:alarm] byExtendingSelection:YES];
[self reformCurrentDefaults];
}
- (NSArray *)pausedAlarms {
return [paused alarms];
}
// Table methods.
- (int)numberOfRowsInTableView:(NSTableView *)aTableView {
return [alarms count] + [[paused alarms] count];
}
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex {
NSString *identifier = [aTableColumn identifier];
Alarm *alarm = [self alarmAtRow:rowIndex];
return [alarm valueForKey:identifier];
}
- (void)tableView:(NSTableView *)aTableView
willDisplayCell:(id)aCell
forTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex {
NSFont *font = [aCell font];
NSFontManager *manager = [NSFontManager sharedFontManager];
if (rowIndex < [alarms count]) {
font = [manager convertFont:font toNotHaveTrait:NSBoldFontMask];
[aCell setTextColor:activeAlarmColor];
} else {
font = [manager convertFont:font toHaveTrait:NSBoldFontMask];
[aCell setTextColor:pausedAlarmColor];
}
[aCell setFont:font];
}
- (void)handleTableSelection:(NSNotification *)note {
NSTableView *table = [note object];
AlarmCollection *collection;
int selected = [table numberOfSelectedRows];
if (selected == 0) { // Switch to the other table. Perhaps it has selections?
table = table == presetTable ? currentTable : presetTable;
selected = [table numberOfSelectedRows]; // Try again.
}
collection = (table == presetTable) ? (AlarmCollection*) presetAlarms : (AlarmCollection*) self;
if (selected > 1) return;
if (selected == 1) {
// If this is the only item selected, we want the alarm displayed in the clock display.
int row = [table selectedRow];
//if (!oldAlarm) oldAlarm = [[inputController displayedAlarm] retain];
[lastSelectedAlarm autorelease];
if (collection == self)
lastSelectedAlarm = [[self alarmAtRow:row] retain];
else
lastSelectedAlarm = [[[presetAlarms alarms] objectAtIndex:row] retain];
[inputController setDisplayedAlarm:lastSelectedAlarm];
if (table == currentTable)
[timeView setMilliseconds:[lastSelectedAlarm millisecondsRemaining]+999];
} else {
[lastSelectedAlarm autorelease];
lastSelectedAlarm = [lastSelectedAlarm copy];
[lastSelectedAlarm pause];
[inputController setDisplayedAlarm:lastSelectedAlarm];
/* In an older version of Fob, when you deselected an alarm, the alarm that was displayed before _anything_ was selected was again displayed. This is perhaps desirable behavior, but in the light of other changes it is incompatible with some other desirable behavior I wish to have, ie the ability to change deleted alarms. The oldAlarm variable is not really needed anymore. This is new as of Fob 1.0.2. */
/* if (!oldAlarm) return;
[inputController setDisplayedAlarm:oldAlarm];
[oldAlarm release];
oldAlarm = nil;
[lastSelectedAlarm release];
lastSelectedAlarm = nil; */
}
}
- (void)handleDoneActionChange:(NSNotification *)note {
// Is anything being shown?
if (!lastSelectedAlarm) return;
// Check if this is a current alarm.
if ([lastSelectedAlarm millisecondsRemaining] && [lastSelectedAlarm paused]) return;
[lastSelectedAlarm setDoneAction:[[note object] displayedDoneAction]];
}
// Action methods.
- (void)reformCurrentDefaults {
[[NSUserDefaults standardUserDefaults] setObject:correspondingDataArray(alarms)
forKey:FobActiveAlarmsKey];
[[NSUserDefaults standardUserDefaults] setObject:correspondingDataArray([paused alarms])
forKey:FobPausedAlarmsKey];
}
- (IBAction)addSelectedPresets:(id)source {
NSArray * presets = [presetAlarms selectedAlarms];
int i;
for (i=0; i<[presets count]; i++)
[self rawAdd:[[presets objectAtIndex:i] copy]];
[self reformCurrentDefaults];
}
- (IBAction)addToCurrent:(id)source {
Alarm *alarm = [inputController displayedAlarm];
[self add:alarm];
}
- (IBAction)removeFromCurrent:(id)source {
NSTableView *table = [self displayedTableView];
int toRemove = [table numberOfSelectedRows], i;
for (i=[table numberOfRows]-1; toRemove; i--) {
if ([table isRowSelected:i]) {
[[[self alarmAtRow:i] doneAction] stop]; // Easiest way.
[table deselectRow:i]; // Jon Zap.
[self removeAlarmAtIndex:i];
toRemove--;
}
}
[self reformCurrentDefaults];
}
- (void)removeAlarmAtIndex:(int)index {
int c = [alarms count];
[[self alarmAtRow:index] pause];
if (index < c) [super removeAlarmAtIndex:index];
else [paused removeAlarmAtIndex:index-c];
}
- (void)handleAlarmsChanged:(NSNotification *)note {
[littleCurrentTable reloadData];
[currentTable reloadData];
}
- (void)handleTableDelete:(NSNotification *)note {
[self removeFromCurrent:[note object]];
}
- (void)handleAlarmTick:(NSNotification *)note {
[littleCurrentTable reloadData];
[currentTable reloadData];
if ([note object] == lastSelectedAlarm) {
[timeView setMilliseconds:[lastSelectedAlarm millisecondsRemaining]+999];
}
}
- (void)handleAlarmDone:(NSNotification *)note {
Alarm *alarm = [note object];
if ([alarm repeats]) {
// This is a repeating alarm. Rewind it.
NSArray *selected = [self selectedAlarms];
NSEnumerator *enumerator = [selected objectEnumerator];
NSTableView *tv = [self displayedTableView];
[((DoneAction*)[[alarm doneAction] copy]) play];
[tv deselectAll:nil];
[self rewind:alarm];
enumerator = [selected objectEnumerator];
while (alarm = [enumerator nextObject])
[tv selectRow:[self rowForAlarm:alarm] byExtendingSelection:YES];
}
[self handleAlarmTick:note];
}
- (IBAction)clearDue:(id)sender {
while ([alarms count] && [((Alarm*)[alarms objectAtIndex:0]) paused])
[self removeAlarmAtIndex:0];
[AttentionGrabber giveUpAttention];
[self reformCurrentDefaults];
//[window setLevel:NSScreenSaverWindowLevel];
//[window setLevel:NSNormalWindowLevel];
}
- (IBAction)doubleClickPresets:(id)sender {
int row = [sender clickedRow];
[self add:[[[presetAlarms alarms] objectAtIndex:row] copy]];
}
- (IBAction)pauseSelected:(id)sender {
NSArray *selected = [self selectedAlarms];
NSEnumerator *enumerator = [selected objectEnumerator];
NSTableView *tv = [self displayedTableView];
Alarm *alarm;
while (alarm = [enumerator nextObject])
[self pause:alarm];
[tv deselectAll:nil];
enumerator = [selected objectEnumerator];
while (alarm = [enumerator nextObject])
[tv selectRow:[self rowForAlarm:alarm] byExtendingSelection:YES];
[self reformCurrentDefaults];
}
- (IBAction)unpauseSelected:(id)sender {
NSArray *selected = [self selectedAlarms];
NSEnumerator *enumerator = [selected objectEnumerator];
NSTableView *tv = [self displayedTableView];
Alarm *alarm;
while (alarm = [enumerator nextObject])
[self unpause:alarm];
[tv deselectAll:nil];
enumerator = [selected objectEnumerator];
while (alarm = [enumerator nextObject])
[tv selectRow:[self rowForAlarm:alarm] byExtendingSelection:YES];
[self reformCurrentDefaults];
}
- (IBAction)rewindLastDue:(id)sender {
unsigned int i=0;
for (i=0; i<[alarms count]; i++)
if (![((Alarm*)[alarms objectAtIndex:i]) paused])
break;
if (i-- == 0) return; // No alarm at all is due.
Alarm *a = ((Alarm*)[alarms objectAtIndex:i]);
// Get the last due alarm.
[self rewind:a];
[self reformCurrentDefaults];
}
- (IBAction)rewindSelected:(id)sender {
NSArray *selected = [self selectedAlarms];
if ([selected count]) {
// We have selected alarms. Rewind those.
NSEnumerator *enumerator = [selected objectEnumerator];
NSTableView *tv = [self displayedTableView];
Alarm *alarm;
while (alarm = [enumerator nextObject])
[self rewind:alarm];
[tv deselectAll:nil];
enumerator = [selected objectEnumerator];
while (alarm = [enumerator nextObject])
[tv selectRow:[self rowForAlarm:alarm] byExtendingSelection:YES];
[self reformCurrentDefaults];
} else {
// We do not have selected alarms. Rewind the last due alarm.
[self rewindLastDue:sender];
}
}
- (IBAction)doubleClickCurrent:(id)sender {
int row = [sender clickedRow];
if (row < [alarms count]) {
// This must be an active alarm. Pause it!
[self pauseSelected:sender];
} else {
// This must be a paused alarm. Reactivate it!
[self unpauseSelected:sender];
}
}
/* METHODS FOR ADDING TEXTUAL ALARMS. */
- (IBAction)beginTextAlarmSheet:(id)source {
Alarm *alarm = [inputController displayedAlarm];
if ([[textAlarmTime stringValue] length] == 0) {
NSString *timeString = [alarm timeString];
if ([timeString compare:NSLocalizedString(@"DoneAlarmDescriber", nil)] == NSOrderedSame)
timeString = @"0:00";
[textAlarmTime setStringValue:timeString];
}
if ([[textAlarmTitle stringValue] length] == 0) {
[textAlarmTitle setStringValue:[alarm title]];
}
// Show the sheet.
[NSApp beginSheet:textAlarmWindow
modalForWindow:[[FobController defaultController] currentWindow]
modalDelegate:self
didEndSelector:@selector(textAlarmEnded:returnCode:contextInfo:)
contextInfo:nil];
[textAlarmTime lockFocus];
}
- (IBAction)endTextAlarmSheet:(id)sender {
// Hide the sheet.
[textAlarmWindow orderOut:sender];
// Return to normal event handling.
[NSApp endSheet:textAlarmWindow returnCode:[sender tag]];
}
- (void)textAlarmEnded:(NSWindow *)sheet
returnCode:(int)returnCode
contextInfo:(id)contextInfo {
if (returnCode == 1) {
// Cancel was selected!
return;
}
// Extract the title.
NSString *title = [textAlarmTitle stringValue];
if ([title length]==0) title = NSLocalizedString(@"DefaultAlarmLabel", nil);
// Extract the time.
int time = 0, tempTime = 0;
NSString *timeString = [[textAlarmTime stringValue] lowercaseString];
NSScanner *timeScan = [NSScanner localizedScannerWithString:timeString];
NSCharacterSet *numberSkip =
[NSCharacterSet characterSetWithCharactersInString:@"0123456789hms"],
*emptySet = [NSCharacterSet characterSetWithCharactersInString:@""];
[timeScan setCharactersToBeSkipped:emptySet];
while (![timeScan isAtEnd]) {
int timeToken = 0;
[timeScan scanUpToCharactersFromSet:numberSkip intoString:nil];
if ([timeScan scanInt:&timeToken]) {
tempTime *= 60;
tempTime += timeToken;
} else {
if ([timeScan isAtEnd]) break;
switch ([timeString characterAtIndex:[timeScan scanLocation]]) {
case 'h':
tempTime *= 60;
case 'm':
tempTime *= 60;
default:
time += tempTime;
tempTime = 0;
}
[timeScan setScanLocation:[timeScan scanLocation]+1];
[timeScan scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet]
intoString:nil];
}
}
time += tempTime;
if (time <= 0 || time >= 12*3600) {
NSBeginAlertSheet(NSLocalizedString(@"TimeOutOfRangeTitle", nil),
nil, nil, nil, window,
nil, nil, nil, nil,
NSLocalizedString(@"TimeOutOfRangeMessage", nil));
return;
}
// We are going to make an alarm sort of like the one displayed, except with a
// different title and time remaining (same done action)
Alarm *alarm = [Alarm alarmWithTitle:title forSecondDuration:time];
[alarm setDoneAction:[[[[inputController displayedAlarm] doneAction] copy] autorelease]];
[self add:alarm];
}
/* INTERFACE VALIDATION METHODS. */
- (BOOL)validateItem:(id)item {
SEL action = [item action];
NSTableView *tv = [self displayedTableView];
if (action == @selector(addToCurrent:)) {
return [inputController milliseconds] != 0;
} else if (action == @selector(addSelectedPresets:)) {
return [presetTable numberOfSelectedRows];
} else if (action == @selector(pauseSelected:)) {
switch ([tv numberOfSelectedRows]) {
case 0:
// Can't pause anything!
return NO;
case 1:
// Can only pause non-paused ones.
return [tv selectedRow] < [alarms count];
default:
return [[[tv selectedRowEnumerator] nextObject] intValue] < [alarms count];
}
} else if (action == @selector(unpauseSelected:)) {
switch ([tv numberOfSelectedRows]) {
case 0:
// Can't unpause anything!
return NO;
case 1:
// Can only unpause paused ones.
return [tv selectedRow] >= [alarms count];
default:
return [[[[tv selectedRowEnumerator] allObjects] lastObject] intValue]
>= [alarms count];
}
} else if (action == @selector(rewindSelected:)) {
//return [tv numberOfSelectedRows];
return YES;
}
// By default, validate everything as enabled.
return YES;
}
- (BOOL)validateMenuItem:(NSMenuItem *)anItem {
return [self validateItem:anItem];
}
- (BOOL)validateToolbarItem:(NSToolbarItem *)anItem {
return [self validateItem:anItem];
}
- (void)handleQuit:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults boolForKey:FobClearDueOnQuitKey]) {
[self clearDue:sender];
}
}
@end