source: releases/Pester/1.1b5/Source/PSSpeechAlert.m@ 442

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

Pester 1.1b3

File size: 2.4 KB
Line 
1//
2// PSSpeechAlert.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 "PSSpeechAlert.h"
10#import "PSAlarmAlertController.h"
11#import "NSDictionary-NJRExtensions.h"
12#import "SUSpeaker.h"
13
14// property list keys
15static NSString * const PLAlertVoice = @"voice"; // NSString
16
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) {
27 voice = [aVoice retain];
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
40- (NSString *)voice;
41{
42 return voice;
43}
44
45- (void)_stopSpeaking:(NSNotification *)notification;
46{
47 [speaker stopSpeaking]; // triggers didFinishSpeaking:
48}
49
50- (void)triggerForAlarm:(PSAlarm *)anAlarm;
51{
52 [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(_stopSpeaking:) name: PSAlarmAlertStopNotification object: nil];
53
54 if ( (speaker = [[SUSpeaker alloc] init]) == nil) return;
55 alarm = anAlarm;
56 [speaker setDelegate: self];
57 unsigned voiceIndex = [[SUSpeaker voiceNames] indexOfObject: voice];
58 if (voiceIndex == NSNotFound)
59 voiceIndex = [[SUSpeaker voiceNames] indexOfObject: [SUSpeaker defaultVoice]];
60 [speaker setVoice: voiceIndex + 1];
61 [speaker speakText: [alarm message]];
62}
63
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) {
83 voice = [[dict objectForRequiredKey: PLAlertVoice] retain];
84 }
85 return self;
86}
87
88@end
89
90@implementation PSSpeechAlert (SUSpeakerDelegate)
91
92- (void)didFinishSpeaking:(SUSpeaker *)aSpeaker;
93{
94 [self completedForAlarm: alarm];
95 [speaker release]; speaker = nil;
96}
97
98@end
Note: See TracBrowser for help on using the repository browser.