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