| author | Rudy Richter |
| Sat Aug 01 20:43:39 2009 -0400 (2009-08-01) | |
| changeset 4259 | 0e9b6b0b1e25 |
| parent 4246 | 4f52d1d98978 |
| child 4666 | 59b81a267426 |
| child 4827 | e3adc3ee14e1 |
| permissions | -rw-r--r-- |
| boredzo@2402 | 1 |
// |
| boredzo@2402 | 2 |
// GrowlSpeechPrefs.m |
| boredzo@2402 | 3 |
// Display Plugins |
| boredzo@2402 | 4 |
// |
| boredzo@2402 | 5 |
// Created by Ingmar Stein on 15.11.04. |
| ingmarstein@3040 | 6 |
// Copyright 2004-2006 The Growl Project. All rights reserved. |
| boredzo@2402 | 7 |
// |
| boredzo@2402 | 8 |
|
| boredzo@2402 | 9 |
#import "GrowlSpeechPrefs.h" |
| boredzo@2402 | 10 |
#import "GrowlSpeechDefines.h" |
| boredzo@2402 | 11 |
#import <AppKit/NSSpeechSynthesizer.h> |
| boredzo@2402 | 12 |
|
| boredzo@2402 | 13 |
@implementation GrowlSpeechPrefs |
| boredzo@2402 | 14 |
- (NSString *) mainNibName {
|
| boredzo@2402 | 15 |
return @"GrowlSpeechPrefs"; |
| boredzo@2402 | 16 |
} |
| boredzo@2402 | 17 |
|
| boredzo@2402 | 18 |
- (void) awakeFromNib {
|
| boredzo@2402 | 19 |
NSArray *availableVoices = [NSSpeechSynthesizer availableVoices]; |
| boredzo@2402 | 20 |
NSEnumerator *voiceEnum = [availableVoices objectEnumerator]; |
| boredzo@2402 | 21 |
NSMutableArray *voiceAttributes = [[NSMutableArray alloc] initWithCapacity:[availableVoices count]]; |
| boredzo@2402 | 22 |
NSString *voiceIdentifier; |
| boredzo@2402 | 23 |
while ((voiceIdentifier=[voiceEnum nextObject])) {
|
| boredzo@2402 | 24 |
[voiceAttributes addObject:[NSSpeechSynthesizer attributesForVoice:voiceIdentifier]]; |
| boredzo@2402 | 25 |
} |
| boredzo@2402 | 26 |
[self setVoices:voiceAttributes]; |
| boredzo@2402 | 27 |
[voiceAttributes release]; |
| boredzo@2402 | 28 |
|
| boredzo@2402 | 29 |
NSString *voice = nil; |
| boredzo@2402 | 30 |
READ_GROWL_PREF_VALUE(GrowlSpeechVoicePref, GrowlSpeechPrefDomain, NSString *, &voice); |
| Rudy@4246 | 31 |
NSUInteger row = NSNotFound; |
| boredzo@2402 | 32 |
if (voice) {
|
| Rudy@4259 | 33 |
CFMakeCollectable(voice); |
| boredzo@2402 | 34 |
row = [availableVoices indexOfObject:voice]; |
| boredzo@2402 | 35 |
[voice release]; |
| evands@3622 | 36 |
} |
| evands@3622 | 37 |
|
| evands@3622 | 38 |
if (row == NSNotFound) |
| boredzo@2402 | 39 |
row = [availableVoices indexOfObject:[NSSpeechSynthesizer defaultVoice]]; |
| evands@3622 | 40 |
|
| evands@3622 | 41 |
if ((row == NSNotFound) && ([availableVoices count])) |
| evands@3622 | 42 |
row = 1; |
| evands@3622 | 43 |
|
| evands@3622 | 44 |
if (row != NSNotFound) {
|
| evands@3622 | 45 |
[voiceList selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO]; |
| evands@3622 | 46 |
[voiceList scrollRowToVisible:row]; |
| evands@3622 | 47 |
} |
| bgannin@3593 | 48 |
[voiceList setDoubleAction:@selector(previewVoice:)]; |
| boredzo@2402 | 49 |
} |
| boredzo@2402 | 50 |
|
| boredzo@2402 | 51 |
- (NSArray *) voices {
|
| boredzo@2402 | 52 |
return voices; |
| boredzo@2402 | 53 |
} |
| boredzo@2402 | 54 |
|
| boredzo@2402 | 55 |
- (void) setVoices:(NSArray *)theVoices {
|
| boredzo@2402 | 56 |
[voices release]; |
| boredzo@2402 | 57 |
voices = [theVoices retain]; |
| boredzo@2402 | 58 |
} |
| boredzo@2402 | 59 |
|
| boredzo@2402 | 60 |
- (void) dealloc {
|
| boredzo@2402 | 61 |
[voices release]; |
| boredzo@2402 | 62 |
[super dealloc]; |
| boredzo@2402 | 63 |
} |
| boredzo@2402 | 64 |
|
| bgannin@3593 | 65 |
- (IBAction) previewVoice:(id)sender {
|
| bgannin@3593 | 66 |
|
| Rudy@4246 | 67 |
NSInteger row = [sender selectedRow]; |
| bgannin@3593 | 68 |
|
| bgannin@3593 | 69 |
if (row != -1) {
|
| bgannin@3593 | 70 |
if(lastPreview != nil && [lastPreview isSpeaking]) {
|
| bgannin@3593 | 71 |
[lastPreview stopSpeaking]; |
| bgannin@3593 | 72 |
} |
| bgannin@3593 | 73 |
NSString *voice = [[voices objectAtIndex:row] objectForKey:NSVoiceIdentifier]; |
| bgannin@3593 | 74 |
NSSpeechSynthesizer *quickVoice = [[NSSpeechSynthesizer alloc] initWithVoice:voice]; |
| evands@3642 | 75 |
[quickVoice startSpeakingString:[NSString stringWithFormat:NSLocalizedString(@"This is a preview of the %@ voice.", nil), [[voices objectAtIndex:row] objectForKey:NSVoiceName]]]; |
| bgannin@3593 | 76 |
lastPreview = quickVoice; |
| bgannin@3593 | 77 |
} |
| bgannin@3593 | 78 |
} |
| bgannin@3593 | 79 |
|
| boredzo@2402 | 80 |
- (IBAction) voiceClicked:(id)sender {
|
| Rudy@4246 | 81 |
NSInteger row = [sender selectedRow]; |
| boredzo@2402 | 82 |
|
| bgannin@3593 | 83 |
if (row != -1) {
|
| boredzo@2402 | 84 |
NSString *voice = [[voices objectAtIndex:row] objectForKey:NSVoiceIdentifier]; |
| boredzo@2402 | 85 |
WRITE_GROWL_PREF_VALUE(GrowlSpeechVoicePref, voice, GrowlSpeechPrefDomain); |
| boredzo@2402 | 86 |
UPDATE_GROWL_PREFS(); |
| boredzo@2402 | 87 |
} |
| boredzo@2402 | 88 |
} |
| boredzo@2402 | 89 |
|
| boredzo@2402 | 90 |
@end |