Ignore:
Timestamp:
01/02/03 05:30:03 (21 years ago)
Author:
Nicholas Riley
Message:

Updated for Pester 1.1a5 (very limited release).

Pester 1.1a4 was never released.

Location:
trunk/Cocoa/Pester/Source
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source

    • Property svn:ignore
      •  

        old new  
        11build
         2.gdb_history
  • trunk/Cocoa/Pester/Source/PSAlarmAlertController.m

    r40 r53  
    88
    99#import "PSAlarmAlertController.h"
     10#import "PSAlert.h"
     11#import "PSAlerts.h"
    1012
    1113NSString * const PSAlarmAlertStopNotification = @"PSAlarmAlertStopNotification";
     
    2325}
    2426
     27- (void)_resumeAlarm:(PSAlarm *)alarm;
     28{
     29    [[NSNotificationCenter defaultCenter] removeObserver: self];
     30    [alarm setTimer]; // if snooze not set and not repeating, alarm will die
     31    if (frontmostApp.highLongOfPSN != 0 || frontmostApp.lowLongOfPSN != 0) {
     32        SetFrontProcess(&frontmostApp);
     33        if (appWasHidden)
     34            [NSApp hide: self];
     35    }
     36}
     37
     38- (void)_alertCompleted:(NSNotification *)notification;
     39{
     40    PSAlert *alert = [[notification userInfo] objectForKey: @"alert"];
     41    unsigned count = [pendingAlerts count];
     42    [pendingAlerts removeObject: alert];
     43    NSLog(@"removed: %@; still pending: %@", alert, [pendingAlerts description]);
     44    NSLog(@"alarm: %@ retainCount %d", [notification object], [[notification object] retainCount]);
     45    NSAssert2([pendingAlerts count] == count - 1, @"alert not in set: %@\n%@", alert, notification);
     46    if ([pendingAlerts count] == 0) {
     47        [self _resumeAlarm: [notification object]];
     48        [self release];
     49    }
     50}
     51
    2552- (id)initWithAlarm:(PSAlarm *)alarm;
    2653{
    2754    if ( (self = [super init]) != nil) {
    28         [[alarm alerts] makeObjectsPerformSelector: @selector(triggerForAlarm:)
    29                                         withObject: alarm];
    30         [NSApp activateIgnoringOtherApps: YES];
     55        PSAlerts *alerts = [alarm alerts];
     56        NSArray *allAlerts = [alerts allAlerts];
     57        if ([allAlerts count] == 0) {
     58            [self _resumeAlarm: alarm];
     59        } else {
     60            pendingAlerts = [[NSMutableSet alloc] init];
     61            [pendingAlerts addObjectsFromArray: allAlerts];
     62            [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(_alertCompleted:)
     63                                                         name: PSAlarmAlertCompletedNotification object: alarm];
     64            [self retain]; // release in _alertCompleted:
     65        }
     66        [alerts triggerForAlarm: alarm];
     67        if ([alerts requirePesterFrontmost] && ![NSApp isActive]) { // restore frontmost process afterward
     68            NSDictionary *activeProcessInfo = [[NSWorkspace sharedWorkspace] activeApplication];
     69            frontmostApp.highLongOfPSN = [[activeProcessInfo objectForKey: @"NSApplicationProcessSerialNumberHigh"] longValue];
     70            frontmostApp.lowLongOfPSN = [[activeProcessInfo objectForKey: @"NSApplicationProcessSerialNumberLow"] longValue];
     71            appWasHidden = [NSApp isHidden];
     72            [NSApp activateIgnoringOtherApps: YES];
     73        }
    3174    }
    3275    return self;
    3376}
    3477
     78- (void)dealloc;
     79{
     80    NSLog(@"%@ dealloc", self);
     81    [pendingAlerts release];
     82    [super dealloc];
     83}
     84
    3585@end
Note: See TracChangeset for help on using the changeset viewer.