source: releases/Pester/1.1b1/Source/PSSpeechAlert.m@ 501

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

Updated for Pester 1.1a5 (very limited release).

Pester 1.1a4 was never released.

File size: 2.2 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 [speaker setVoice: [[SUSpeaker voiceNames] indexOfObject: voice] + 1];
58 [speaker speakText: [alarm message]];
59}
60
61- (NSAttributedString *)actionDescription;
62{
63 NSMutableAttributedString *string = [[@"Speak message with voice " small] mutableCopy];
64 [string appendAttributedString: [voice underlined]];
65 return [string autorelease];
66}
67
68#pragma mark property list serialization (Pester 1.1)
69
70- (NSDictionary *)propertyListRepresentation;
71{
72 NSMutableDictionary *plAlert = [[super propertyListRepresentation] mutableCopy];
73 [plAlert setObject: voice forKey: PLAlertVoice];
74 return [plAlert autorelease];
75}
76
77- (id)initWithPropertyList:(NSDictionary *)dict;
78{
79 if ( (self = [self init]) != nil) {
80 voice = [dict objectForRequiredKey: PLAlertVoice];
81 }
82 return self;
83}
84
85@end
86
87@implementation PSSpeechAlert (SUSpeakerDelegate)
88
89- (void)didFinishSpeaking:(SUSpeaker *)aSpeaker;
90{
91 [self completedForAlarm: alarm];
92 [speaker release]; speaker = nil;
93}
94
95@end
Note: See TracBrowser for help on using the repository browser.