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 <Adium/AIPreferenceControllerProtocol.h>
18 #import "AISoundController.h"
19 #import "ESAnnouncerAbstractDetailPane.h"
20 #import "ESAnnouncerPlugin.h"
21 #import <Adium/AIContactAlertsControllerProtocol.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)];
46 [label_voice setLocalizedString:AILocalizedString(@"Voice:", nil)];
48 [popUp_voices setMenu:[self voicesMenu]];
52 * @brief Configure for the action
54 - (void)configureForActionDetails:(NSDictionary *)inDetails listObject:(AIListObject *)inObject
56 BOOL speakTime, speakContactName;
58 NSNumber *pitchNumber, *rateNumber;
60 if (!inDetails) inDetails = [[adium preferenceController] preferenceForKey:[self defaultDetailsKey]
61 group:PREF_GROUP_ANNOUNCER];
63 speakTime = [[inDetails objectForKey:KEY_ANNOUNCER_TIME] boolValue];
64 speakContactName = [[inDetails objectForKey:KEY_ANNOUNCER_SENDER] boolValue];
66 if ((voice = [inDetails objectForKey:KEY_VOICE_STRING])) {
67 [popUp_voices selectItemWithTitle:voice];
69 [popUp_voices selectItemAtIndex:0]; //"Default"
72 if ((pitchNumber = [inDetails objectForKey:KEY_PITCH])) {
73 [slider_pitch setFloatValue:[pitchNumber floatValue]];
75 [slider_pitch setFloatValue:[[adium soundController] defaultPitch]];
78 [checkBox_customPitch setState:[[inDetails objectForKey:KEY_PITCH_CUSTOM] boolValue]];
80 if ((rateNumber = [inDetails objectForKey:KEY_RATE])) {
81 [slider_rate setFloatValue:[rateNumber floatValue]];
83 [slider_rate setFloatValue:[[adium soundController] defaultRate]];
86 [checkBox_customRate setState:[[inDetails objectForKey:KEY_RATE_CUSTOM] boolValue]];
88 [checkBox_speakEventTime setState:speakTime];
89 [checkBox_speakContactName setState:speakContactName];
91 [self configureControlDimming];
94 - (void)configureControlDimming
96 [super configureControlDimming];
98 [slider_rate setEnabled:[checkBox_customRate state]];
99 [slider_pitch setEnabled:[checkBox_customPitch state]];
103 * @brief Configure controls specially for message events.
105 * Speaking of the name is only disable-able for message events.
107 - (void)configureForEventID:(NSString *)eventID listObject:(AIListObject *)inObject
109 if ([[adium contactAlertsController] isMessageEvent:eventID]) {
110 [checkBox_speakContactName setEnabled:YES];
112 [checkBox_speakContactName setEnabled:NO];
113 [checkBox_speakContactName setState:NSOnState];
118 * @brief Return action details
120 * Should be overridden, with the subclass returning [self actionDetailsDromDict:actionDetails]
121 * where actionDetails is the dictionary of what it itself needs to store
123 - (NSDictionary *)actionDetails
125 NSDictionary *actionDetails = [self actionDetailsFromDict:nil];
127 //Save the preferred settings for future use as defaults
128 [[adium preferenceController] setPreference:actionDetails
129 forKey:[self defaultDetailsKey]
130 group:PREF_GROUP_ANNOUNCER];
132 return actionDetails;
136 * @brief Used by subclasses; adds the general information managed by the superclass to the details dictionary.
138 - (NSDictionary *)actionDetailsFromDict:(NSMutableDictionary *)actionDetails
140 NSNumber *speakTime, *speakContactName, *pitch, *rate;
143 if (!actionDetails) actionDetails = [NSMutableDictionary dictionary];
145 speakTime = [NSNumber numberWithBool:([checkBox_speakEventTime state] == NSOnState)];
146 speakContactName = [NSNumber numberWithBool:([checkBox_speakContactName state] == NSOnState)];
148 voice = [[popUp_voices selectedItem] representedObject];
149 pitch = [NSNumber numberWithFloat:[slider_pitch floatValue]];
150 rate = [NSNumber numberWithFloat:[slider_rate floatValue]];
153 [actionDetails setObject:voice
154 forKey:KEY_VOICE_STRING];
157 if ([pitch floatValue] != [[adium soundController] defaultPitch]) {
158 [actionDetails setObject:pitch
162 if ([rate floatValue] != [[adium soundController] defaultRate]) {
163 [actionDetails setObject:rate
166 [actionDetails setObject:[NSNumber numberWithBool:[checkBox_customRate state]]
167 forKey:KEY_RATE_CUSTOM];
168 [actionDetails setObject:[NSNumber numberWithBool:[checkBox_customPitch state]]
169 forKey:KEY_PITCH_CUSTOM];
171 [actionDetails setObject:speakTime
172 forKey:KEY_ANNOUNCER_TIME];
173 [actionDetails setObject:speakContactName
174 forKey:KEY_ANNOUNCER_SENDER];
176 return actionDetails;
180 * @brief Key on which to store our defaults
182 * Must be overridden by subclasses
184 - (NSString *)defaultDetailsKey
190 * @brief Speech voices menu
192 - (NSMenu *)voicesMenu
194 NSArray *voicesArray;
195 NSMenu *voicesMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] init];
196 NSMenuItem *menuItem;
197 NSEnumerator *enumerator;
200 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:AILocalizedString(@"Use System Default",nil)
203 keyEquivalent:@""] autorelease];
204 [voicesMenu addItem:menuItem];
205 [voicesMenu addItem:[NSMenuItem separatorItem]];
207 voicesArray = [[[adium soundController] voices] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
208 enumerator = [voicesArray objectEnumerator];
209 while ((voice = [enumerator nextObject])) {
210 menuItem = [[[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:voice
213 keyEquivalent:@""] autorelease];
214 [menuItem setRepresentedObject:voice];
215 [voicesMenu addItem:menuItem];
222 * @brief Preference changed
224 -(IBAction)changePreference:(id)sender
226 //If the Default voice is selected, also set the pitch and rate to defaults
227 if (sender == popUp_voices) {
228 if (![[popUp_voices selectedItem] representedObject]) {
229 [slider_pitch setFloatValue:[[adium soundController] defaultPitch]];
230 [slider_rate setFloatValue:[[adium soundController] defaultRate]];
234 if (sender == popUp_voices ||
235 (sender == slider_pitch || sender == checkBox_customPitch) ||
236 (sender == slider_rate || sender == checkBox_customRate)) {
237 [[adium soundController] speakDemoTextForVoice:[[popUp_voices selectedItem] representedObject]
238 withPitch:([checkBox_customPitch state] ? [slider_pitch floatValue] : 0.0)
239 andRate:([checkBox_customRate state] ? [slider_rate floatValue] : 0.0)];
242 [super changePreference:sender];