Ignore:
Timestamp:
10/20/02 06:31:58 (22 years ago)
Author:
Nicholas Riley
Message:

Pester 1.0d2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/PSAlarmSetController.m

    r21 r24  
    3939    // [timeDate setFormatter: [[NJRDateFormatter alloc] initWithDateFormat: [defaults objectForKey: NSShortDateFormatString] allowNaturalLanguage: YES]];
    4040    [self inAtChanged: nil];
     41    alarm = [[PSAlarm alloc] init];
     42    [[self window] makeKeyAndOrderFront: nil];
     43}
     44
     45- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag;
     46{
     47    if (!flag) [self showWindow: self];
     48    return YES;
    4149}
    4250
     
    6674- (void)setAlarmDateAndInterval:(id)sender;
    6775{
    68     [alarmDate release];
    69     alarmDate = nil;
    70     alarmInterval = 0;
    7176    if (isIn) {
    72         alarmInterval = [[self objectValueForTextField: timeInterval whileEditing: sender] intValue] * [timeIntervalUnits selectedTag];
    73         if (alarmInterval == 0) {
    74             [self setStatus: @"Please specify an alarm interval."]; return;
    75         }
    76         alarmDate = [NSCalendarDate dateWithTimeIntervalSinceNow: alarmInterval];
    77         [alarmDate retain];
     77        [alarm setInterval:
     78            [[self objectValueForTextField: timeInterval whileEditing: sender] intValue] *
     79                [timeIntervalUnits selectedTag]];
    7880    } else {
    79         NSDate *time = [self objectValueForTextField: timeOfDay whileEditing: sender];
    80         NSDate *date = [self objectValueForTextField: timeDate whileEditing: sender];
    81         NSCalendarDate *calTime, *calDate;
    82         if (time == nil && date == nil) {
    83             [self setStatus: @"Please specify an alarm date and time."]; return;
    84         }
    85         if (time == nil) {
    86             [self setStatus: @"Please specify an alarm time."]; return;
    87         }
    88         if (date == nil) {
    89             [self setStatus: @"Please specify an alarm date."]; return;
    90         }
    91         // XXX if calTime's date is different from the default date, complain
    92         calTime = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate: [time timeIntervalSinceReferenceDate]];
    93         calDate = [NSCalendarDate dateWithTimeIntervalSinceReferenceDate: [date timeIntervalSinceReferenceDate]];
    94         if (time == nil || date == nil) {
    95             [self setStatus: @"Please specify a reasonable date and time."];
    96         }
    97         alarmDate = [[NSCalendarDate alloc] initWithYear: [calDate yearOfCommonEra]
    98                                                    month: [calDate monthOfYear]
    99                                                      day: [calDate dayOfMonth]
    100                                                     hour: [calTime hourOfDay]
    101                                                   minute: [calTime minuteOfHour]
    102                                                   second: [calTime secondOfMinute]
    103                                                 timeZone: nil];
    104         alarmInterval = [alarmDate timeIntervalSinceNow];
    105         if (alarmInterval <= 0) {
    106             [self setStatus: @"Please specify an alarm time in the future."];
    107             [alarmDate release];
    108             alarmDate = nil;
    109             return;
    110         }
     81        [alarm setForDate: [self objectValueForTextField: timeDate whileEditing: sender]
     82                   atTime: [self objectValueForTextField: timeOfDay whileEditing: sender]];
    11183    }
    11284}
     
    11890// Be careful not to hook up any of the text fields' actions to update: because we handle them in controlTextDidChange: instead.  If we could get the active text field somehow via public API (guess we could use controlTextDidBegin/controlTextDidEndEditing) then we'd not need to overload the update sender for this purpose.  Or, I guess, we could use another method other than update.  It should not be this hard to implement what is essentially standard behavior.  Sigh.
    11991
     92- (IBAction)updateDateDisplay:(id)sender;
     93{
     94    if ([alarm isValid]) {
     95        [self setStatus: [[alarm date] descriptionWithCalendarFormat: @"Alarm will be set for %X on %x" timeZone: nil locale: nil]];
     96        [setButton setEnabled: YES];
     97    } else {
     98        [setButton setEnabled: NO];
     99    }
     100}
     101
    120102- (IBAction)update:(id)sender;
    121103{
    122104    // NSLog(@"update: %@", sender);
    123105    [self setAlarmDateAndInterval: sender];
    124     if (alarmDate != nil) {
    125         [self setStatus: [alarmDate descriptionWithCalendarFormat: @"Alarm will be set for %X on %x" timeZone: nil locale: nil]];
    126         [setButton setEnabled: YES];
    127     } else {
    128         [setButton setEnabled: NO];
    129     }
     106    [self updateDateDisplay: sender];
    130107}
    131108
     
    183160    PSAlarmNotifierController *notifier = [PSAlarmNotifierController alloc];
    184161    NSTimer *timer;
     162    NSTimeInterval interval;
    185163    [self setAlarmDateAndInterval: sender];
    186     if (notifier == nil || alarmDate == nil) {
     164    if (notifier == nil || ( (interval = [alarm interval]) == 0)) {
    187165        [self setStatus: @"Unable to set alarm (time just passed?)"];
    188166        return;
    189167    }
     168    [alarm setMessage: [messageField stringValue]];
    190169    // XXX should use alarm object instead for userInfo
    191     timer = [NSTimer scheduledTimerWithTimeInterval: alarmInterval
     170    timer = [NSTimer scheduledTimerWithTimeInterval: interval
    192171                                             target: notifier
    193172                                           selector: @selector(initWithTimer:)
    194                                            userInfo: [messageField stringValue]
     173                                           userInfo: alarm
    195174                                            repeats: NO];
    196     [self setStatus: [alarmDate descriptionWithCalendarFormat: @"Alarm set for %x at %X" timeZone: nil locale: nil]];
     175    [self setStatus: [[alarm date] descriptionWithCalendarFormat: @"Alarm set for %x at %X" timeZone: nil locale: nil]];
    197176    [[self window] close];
    198177}
Note: See TracChangeset for help on using the changeset viewer.