2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "AIPreferenceController.h"
18 #import "AISoundController.h"
19 #import "ESAnnouncerAbstractDetailPane.h"
20 #import "ESAnnouncerPlugin.h"
21 #import "ESContactAlertsController.h"
22 #import <AIUtilities/AIMenuAdditions.h>
23 #import <Adium/AILocalizationButton.h>
25 @interface ESAnnouncerAbstractDetailPane (PRIVATE)
26 - (NSMenu *)voicesMenu;
30 * @class ESAnnouncerAbstractDetailPane
31 * @brief Abstract superclass for Announcer action (Speak Event and Speak Text) detail panes
33 @implementation ESAnnouncerAbstractDetailPane
36 * @brief View did load
42 [checkBox_speakEventTime setTitle:SPEAK_EVENT_TIME];
43 [checkBox_speakContactName setLocalizedString:AILocalizedString(@"Speak Name",nil)];
44 [checkBox_customPitch setLocalizedString:AILocalizedString(@"Use custom pitch:",nil)];
45 [checkBox_customRate setLocalizedString:AILocalizedString(@"Use custom rate:",nil)];
47 [popUp_voices setMenu:[self voicesMenu]];
51 * @brief Configure for the action
53 - (void)configureForActionDetails:(NSDictionary *)inDetails listObject:(AIListObject *)inObject
55 BOOL speakTime, speakContactName;
57 NSNumber *pitchNumber, *rateNumber;
59 if(!inDetails) inDetails = [[adium preferenceController] preferenceForKey:[self defaultDetailsKey]
60 group:PREF_GROUP_ANNOUNCER];
62 speakTime = [[inDetails objectForKey:KEY_ANNOUNCER_TIME] boolValue];
63 speakContactName = [[inDetails objectForKey:KEY_ANNOUNCER_SENDER] boolValue];
65 if(voice = [inDetails objectForKey:KEY_VOICE_STRING]) {
66 [popUp_voices selectItemWithTitle:voice];
68 [popUp_voices selectItemAtIndex:0]; //"Default"
71 if(pitchNumber = [inDetails objectForKey:KEY_PITCH]) {
72 [slider_pitch setFloatValue:[pitchNumber floatValue]];
74 [slider_pitch setFloatValue:[[adium soundController] defaultPitch]];
77 [checkBox_customPitch setState:[[inDetails objectForKey:KEY_PITCH_CUSTOM] boolValue]];
79 if(rateNumber = [inDetails objectForKey:KEY_RATE]) {
80 [slider_rate setFloatValue:[rateNumber floatValue]];
82 [slider_rate setFloatValue:[[adium soundController] defaultRate]];
85 [checkBox_customRate setState:[[inDetails objectForKey:KEY_RATE_CUSTOM] boolValue]];
87 [checkBox_speakEventTime setState:speakTime];
88 [checkBox_speakContactName setState:speakContactName];
90 [self configureControlDimming];
93 - (void)configureControlDimming
95 [super configureControlDimming];
97 [slider_rate setEnabled:[checkBox_customRate state]];
98 [slider_pitch setEnabled:[checkBox_customPitch state]];
102 * @brief Configure controls specially for message events.
104 * Speaking of the name is only disable-able for message events.
106 - (void)configureForEventID:(NSString *)eventID listObject:(AIListObject *)inObject
108 if([[adium contactAlertsController] isMessageEvent:eventID]){
109 [checkBox_speakContactName setEnabled:YES];
111 [checkBox_speakContactName setEnabled:NO];
112 [checkBox_speakContactName setState:NSOnState];
117 * @brief Return action details
119 * Should be overridden, with the subclass returning [self actionDetailsDromDict:actionDetails]
120 * where actionDetails is the dictionary of what it itself needs to store
122 - (NSDictionary *)actionDetails
124 NSDictionary *actionDetails = [self actionDetailsFromDict:nil];
126 //Save the preferred settings for future use as defaults
127 [[adium preferenceController] setPreference:actionDetails
128 forKey:[self defaultDetailsKey]
129 group:PREF_GROUP_ANNOUNCER];
131 return(actionDetails);
135 * @brief Used by subclasses; adds the general information managed by the superclass to the details dictionary.
137 - (NSDictionary *)actionDetailsFromDict:(NSMutableDictionary *)actionDetails
139 NSNumber *speakTime, *speakContactName, *pitch, *rate;
142 if(!actionDetails) actionDetails = [NSMutableDictionary dictionary];
144 speakTime = [NSNumber numberWithBool:([checkBox_speakEventTime state] == NSOnState)];
145 speakContactName = [NSNumber numberWithBool:([checkBox_speakContactName state] == NSOnState)];
147 voice = [[popUp_voices selectedItem] representedObject];
148 pitch = [NSNumber numberWithFloat:[slider_pitch floatValue]];
149 rate = [NSNumber numberWithFloat:[slider_rate floatValue]];
152 [actionDetails setObject:voice
153 forKey:KEY_VOICE_STRING];
156 if([pitch floatValue] != [[adium soundController] defaultPitch]){
157 [actionDetails setObject:pitch
161 if([rate floatValue] != [[adium soundController] defaultRate]){
162 [actionDetails setObject:rate
165 [actionDetails setObject:[NSNumber numberWithBool:[checkBox_customRate state]]
166 forKey:KEY_RATE_CUSTOM];
167 [actionDetails setObject:[NSNumber numberWithBool:[checkBox_customPitch state]]
168 forKey:KEY_PITCH_CUSTOM];
170 [actionDetails setObject:speakTime
171 forKey:KEY_ANNOUNCER_TIME];
172 [actionDetails setObject:speakContactName
173 forKey:KEY_ANNOUNCER_SENDER];
175 return actionDetails;
179 * @brief Key on which to store our defaults
181 * Must be overridden by subclasses
183 - (NSString *)defaultDetailsKey
189 * @brief Speech voices menu
191 - (NSMenu *)voicesMenu
193 NSArray *voicesArray;
194 NSMenu *voicesMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
195 NSMenuItem *menuItem;
196 NSEnumerator *enumerator;
199 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:AILocalizedString(@"Use System Default",nil)
202 keyEquivalent:@""] autorelease];
203 [voicesMenu addItem:menuItem];
204 [voicesMenu addItem:[NSMenuItem separatorItem]];
206 voicesArray = [[[adium soundController] voices] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
207 enumerator = [voicesArray objectEnumerator];
208 while(voice = [enumerator nextObject]){
209 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:voice
212 keyEquivalent:@""] autorelease];
213 [menuItem setRepresentedObject:voice];
214 [voicesMenu addItem:menuItem];
221 * @brief Preference changed
223 -(IBAction)changePreference:(id)sender
225 //If the Default voice is selected, also set the pitch and rate to defaults
226 if(sender == popUp_voices){
227 if(![[popUp_voices selectedItem] representedObject]){
228 [slider_pitch setFloatValue:[[adium soundController] defaultPitch]];
229 [slider_rate setFloatValue:[[adium soundController] defaultRate]];
233 if(sender == popUp_voices ||
234 sender == slider_pitch ||
235 sender == slider_rate){
236 [[adium soundController] speakDemoTextForVoice:[[popUp_voices selectedItem] representedObject]
237 withPitch:[slider_pitch floatValue]
238 andRate:[slider_rate floatValue]];
241 [super changePreference:sender];