[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
|
---|
| 15 | static 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];
|
---|
| 57 | [speaker setVoice: [[SUSpeaker voiceNames] indexOfObject: voice] + 1];
|
---|
| 58 | [speaker speakText: [alarm message]];
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[53] | 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 |
|
---|
[34] | 85 | @end
|
---|
| 86 |
|
---|
| 87 | @implementation PSSpeechAlert (SUSpeakerDelegate)
|
---|
| 88 |
|
---|
[53] | 89 | - (void)didFinishSpeaking:(SUSpeaker *)aSpeaker;
|
---|
[34] | 90 | {
|
---|
[53] | 91 | [self completedForAlarm: alarm];
|
---|
| 92 | [speaker release]; speaker = nil;
|
---|
[34] | 93 | }
|
---|
| 94 |
|
---|
| 95 | @end |
---|