source: releases/Pester/1.1b1/Source/PSAlerts.m@ 594

Last change on this file since 594 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.5 KB
Line 
1//
2// PSAlerts.m
3// Pester
4//
5// Created by Nicholas Riley on Sat Dec 21 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "PSAlerts.h"
10#import "PSAlert.h"
11#import "PSDockBounceAlert.h"
12#import "PSNotifierAlert.h"
13#import "PSBeepAlert.h"
14
15// property list keys
16static NSString * const PLAlerts = @"alerts"; // NSString
17
18@implementation PSAlerts
19
20#pragma mark initialize-release
21
22- (id)init;
23{
24 if ( (self = [super init]) != nil) {
25 alerts = [[NSMutableArray alloc] initWithCapacity: 4];
26 }
27 return self;
28}
29
30- (id)initWithPesterVersion1Alerts;
31{
32 if ( (self = [self init]) != nil) {
33 [self addAlert: [PSDockBounceAlert alert]];
34 [self addAlert: [PSNotifierAlert alert]];
35 [self addAlert: [PSBeepAlert alertWithRepetitions: 1]];
36 }
37 return self;
38}
39
40- (void)dealloc;
41{
42 [alerts release]; alerts = nil;
43}
44
45#pragma mark accessing
46
47- (void)addAlert:(PSAlert *)alert;
48{
49 [alerts addObject: alert];
50 if ([alert requiresPesterFrontmost])
51 requirePesterFrontmost = YES;
52}
53
54- (void)removeAlerts;
55{
56 [alerts removeAllObjects];
57 requirePesterFrontmost = NO;
58}
59
60- (NSEnumerator *)alertEnumerator;
61{
62 return [alerts objectEnumerator];
63}
64
65- (NSArray *)allAlerts;
66{
67 return [[alerts copy] autorelease];
68}
69
70- (BOOL)requirePesterFrontmost;
71{
72 return requirePesterFrontmost;
73}
74
75#pragma mark actions
76
77- (void)prepareForAlarm:(PSAlarm *)alarm;
78{
79 [alerts makeObjectsPerformSelector: @selector(prepareForAlarm:) withObject: alarm];
80}
81
82- (void)triggerForAlarm:(PSAlarm *)alarm;
83{
84 [alerts makeObjectsPerformSelector: @selector(triggerForAlarm:) withObject: alarm];
85}
86
87#pragma mark printing
88
89- (NSAttributedString *)prettyList;
90{
91 NSMutableAttributedString *string = [[NSMutableAttributedString alloc] init];
92 NSEnumerator *e = [self alertEnumerator];
93 PSAlert *alert;
94 unsigned int length;
95 while ( (alert = [e nextObject]) != nil) {
96 [string appendAttributedString: [@"¥ " small]];
97 [string appendAttributedString: [alert actionDescription]];
98 [string appendAttributedString: [@"\n" small]];
99 }
100 if ( (length = [string length]) == 0) {
101 [string release];
102 return nil;
103 } else {
104 NSMutableParagraphStyle *paraStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
105 [string deleteCharactersInRange: NSMakeRange(length - 1, 1)]; // remove trailing newline
106 [paraStyle setHeadIndent: [[string attribute: NSFontAttributeName atIndex: 0 effectiveRange: NULL] widthOfString: @"¥ "]];
107 [string addAttribute: NSParagraphStyleAttributeName value: paraStyle range: NSMakeRange(0, length - 1)];
108 [paraStyle release]; paraStyle = nil;
109 return [string autorelease];
110 }
111}
112
113#pragma mark property list serialization (Pester 1.1)
114
115- (NSDictionary *)propertyListRepresentation;
116{
117 NSMutableArray *plAlerts = [[NSMutableArray alloc] initWithCapacity: [alerts count]];
118 NSEnumerator *e = [self alertEnumerator];
119 PSAlert *alert;
120 while ( (alert = [e nextObject]) != nil) {
121 [plAlerts addObject: [alert propertyListRepresentation]];
122 }
123 return [NSDictionary dictionaryWithObject: plAlerts forKey: PLAlerts];
124}
125
126- (id)initWithPropertyList:(NSDictionary *)dict;
127{
128 if ( (self = [self init]) != nil) {
129 NSArray *plAlerts = [dict objectForKey: PLAlerts];
130 NSEnumerator *e = [plAlerts objectEnumerator];
131 NSDictionary *alertDict;
132 while ( (alertDict = [e nextObject]) != nil) {
133 [self addAlert: [[PSAlert alloc] initWithPropertyList: alertDict]];
134 }
135 }
136 return self;
137}
138
139@end
Note: See TracBrowser for help on using the repository browser.