source: releases/Pester/1.1b1/Source/PSAlarmAlertController.m@ 669

Last change on this file since 669 was 61, checked in by Nicholas Riley, 22 years ago

Pester 1.1b1.

PSPowerManager: Fixed delegate method selectors to better reflect what
is going on (Apple's docs in IOKit Fundamentals help with this; the
kIOMessage*Sleep constants are really poorly named).

VERSION: Updated for 1.1b1.

PSSpeechAlert.h: Fixed company name.

PSAlert.[hm]: Added -prepareForAlarm: to support PSWakeAlert.

PSTimer.[hm]: Replacement for NSTimer that works properly across
sleep/wake cycles and will schedule wake timers.

PSAlerts.[hm]: Added -prepareForAlarm: to support PSWakeAlert.

Read Me.rtfd: Updated for 1.1b1.

PSAlarm.[hm]: Added -setWakeUp:, invoke -[PSAlerts prepareForAlarm],
replaced alarm timer NSTimer with PSTimer.

PSApplication.[hm]: Replaced dock update timer NSTimer with PSTimer.
Uncovered some issues, need to fix later. Enable alarm discard for
beta release.

PSWakeAlert.[hm]: Shared alert implementation for wakeup. Doesn't do
anything at trigger time, but uses new preparation interface to work
at alarm set time (should work for repeating alarms too, but I didn't
bother to test...)

PSAlarmSetController.m: Added support for PSWakeAlert. Save default
alert information on quit. Removed debug statements on hide/unhide;
it works fine regardless of whether the app is explicitly hidden or
the window hides itself.

PSAlarms.m: PSTimer support - invoke +[PSTimer setUp] to initialize
timer list.

File size: 3.0 KB
Line 
1//
2// PSAlarmAlertController.m
3// Pester
4//
5// Created by Nicholas Riley on Sat Oct 26 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "PSAlarmAlertController.h"
10#import "PSAlert.h"
11#import "PSAlerts.h"
12
13NSString * const PSAlarmAlertStopNotification = @"PSAlarmAlertStopNotification";
14
15@implementation PSAlarmAlertController
16
17+ (PSAlarmAlertController *)controllerWithTimerExpiredNotification:(NSNotification *)notification;
18{
19 return [[[self alloc] initWithAlarm: [notification object]] autorelease];
20}
21
22+ (IBAction)stopAlerts:(id)sender;
23{
24 [[NSNotificationCenter defaultCenter] postNotificationName: PSAlarmAlertStopNotification object: nil];
25}
26
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
52- (id)initWithAlarm:(PSAlarm *)alarm;
53{
54 if ( (self = [super init]) != nil) {
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 }
74 }
75 return self;
76}
77
78- (void)dealloc;
79{
80 NSLog(@"%@ dealloc", self);
81 [pendingAlerts release];
82 [super dealloc];
83}
84
85@end
Note: See TracBrowser for help on using the repository browser.