source: trunk/Cocoa/Pester/Source/PSSpeechAlert.m@ 102

Last change on this file since 102 was 102, checked in by Nicholas Riley, 21 years ago

Pester 1.1b3

File size: 2.4 KB
RevLine 
[34]1//
2// PSSpeechAlert.m
3// Pester
4//
5// Created by Nicholas Riley on Sat Oct 26 2002.
[53]6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
[34]7//
8
9#import "PSSpeechAlert.h"
10#import "PSAlarmAlertController.h"
[53]11#import "NSDictionary-NJRExtensions.h"
12#import "SUSpeaker.h"
[34]13
[53]14// property list keys
15static NSString * const PLAlertVoice = @"voice"; // NSString
16
[34]17@implementation PSSpeechAlert
18
19+ (PSSpeechAlert *)alertWithVoice:(NSString *)aVoice;
20{
21 return [[[self alloc] initWithVoice: aVoice] autorelease];
22}
23
24- (id)initWithVoice:(NSString *)aVoice;
25{
26 if ( (self = [super init]) != nil) {
[53]27 voice = [aVoice retain];
[34]28 }
29 return self;
30}
31
32- (void)dealloc;
33{
34 [[NSNotificationCenter defaultCenter] removeObserver: self];
35 [speaker release]; speaker = nil;
36 [voice release]; voice = nil;
37 [super dealloc];
38}
39
[53]40- (NSString *)voice;
41{
42 return voice;
43}
44
[34]45- (void)_stopSpeaking:(NSNotification *)notification;
46{
[53]47 [speaker stopSpeaking]; // triggers didFinishSpeaking:
[34]48}
49
[53]50- (void)triggerForAlarm:(PSAlarm *)anAlarm;
[34]51{
52 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(_stopSpeaking:) name: PSAlarmAlertStopNotification object: nil];
53
54 if ( (speaker = [[SUSpeaker alloc] init]) == nil) return;
[53]55 alarm = anAlarm;
[34]56 [speaker setDelegate: self];
[102]57 unsigned voiceIndex = [[SUSpeaker voiceNames] indexOfObject: voice];
58 if (voiceIndex == NSNotFound)
59 voiceIndex = [[SUSpeaker voiceNames] indexOfObject: [SUSpeaker defaultVoice]];
60 [speaker setVoice: voiceIndex + 1];
[34]61 [speaker speakText: [alarm message]];
62}
63
[53]64- (NSAttributedString *)actionDescription;
65{
66 NSMutableAttributedString *string = [[@"Speak message with voice " small] mutableCopy];
67 [string appendAttributedString: [voice underlined]];
68 return [string autorelease];
69}
70
71#pragma mark property list serialization (Pester 1.1)
72
73- (NSDictionary *)propertyListRepresentation;
74{
75 NSMutableDictionary *plAlert = [[super propertyListRepresentation] mutableCopy];
76 [plAlert setObject: voice forKey: PLAlertVoice];
77 return [plAlert autorelease];
78}
79
80- (id)initWithPropertyList:(NSDictionary *)dict;
81{
82 if ( (self = [self init]) != nil) {
[102]83 voice = [[dict objectForRequiredKey: PLAlertVoice] retain];
[53]84 }
85 return self;
86}
87
[34]88@end
89
90@implementation PSSpeechAlert (SUSpeakerDelegate)
91
[53]92- (void)didFinishSpeaking:(SUSpeaker *)aSpeaker;
[34]93{
[53]94 [self completedForAlarm: alarm];
95 [speaker release]; speaker = nil;
[34]96}
97
98@end
Note: See TracBrowser for help on using the repository browser.