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 "AIEventSoundsPlugin.h"
18 #import "AISoundController.h"
19 #import "ESContactAlertsController.h"
20 #import "ESEventSoundAlertDetailPane.h"
21 #import <AIUtilities/AIStringAdditions.h>
22 #import <AIUtilities/ESImageAdditions.h>
24 #define EVENT_SOUNDS_ALERT_SHORT AILocalizedString(@"Play a sound",nil)
25 #define EVENT_SOUNDS_ALERT_LONG AILocalizedString(@"Play the sound \"%@\"",nil)
27 #define SOUND_ALERT_IDENTIFIER @"PlaySound"
29 @interface AIEventSoundsPlugin (PRIVATE)
30 - (void)eventNotification:(NSNotification *)notification;
31 - (void)preferencesChanged:(NSNotification *)notification;
35 * @class AIEventSoundsPlugin
37 * @brief Component for the Play Sound action
39 @implementation AIEventSoundsPlugin
46 //Install our contact alert
47 [[adium contactAlertsController] registerActionID:SOUND_ALERT_IDENTIFIER withHandler:self];
51 * @brief Short description
52 * @result A short localized description of the action
54 - (NSString *)shortDescriptionForActionID:(NSString *)actionID
56 return(EVENT_SOUNDS_ALERT_SHORT);
60 * @brief Long description
61 * @result A longer localized description of the action which should take into account the details dictionary as appropraite.
63 - (NSString *)longDescriptionForActionID:(NSString *)actionID withDetails:(NSDictionary *)details
65 NSString *fileName = [[[details objectForKey:KEY_ALERT_SOUND_PATH] lastPathComponent] stringByDeletingPathExtension];
67 if(fileName && [fileName length]){
68 return([NSString stringWithFormat:EVENT_SOUNDS_ALERT_LONG, fileName]);
70 return(EVENT_SOUNDS_ALERT_SHORT);
77 - (NSImage *)imageForActionID:(NSString *)actionID
79 return([NSImage imageNamed:@"SoundAlert" forClass:[self class]]);
84 * @result An <tt>AIModularPane</tt> to use for configuring this action, or nil if no configuration is possible.
86 - (AIModularPane *)detailsPaneForActionID:(NSString *)actionID
88 return([ESEventSoundAlertDetailPane actionDetailsPane]);
92 * @brief Perform an action
96 * @param actionID The ID of the action to perform
97 * @param listObject The listObject associated with the event triggering the action. It may be nil
98 * @param details If set by the details pane when the action was created, the details dictionary for this particular action
99 * @param eventID The eventID which triggered this action
100 * @param userInfo Additional information associated with the event; userInfo's type will vary with the actionID.
102 - (void)performActionID:(NSString *)actionID forListObject:(AIListObject *)listObject withDetails:(NSDictionary *)details triggeringEventID:(NSString *)eventID userInfo:(id)userInfo
104 NSString *soundPath = [[details objectForKey:KEY_ALERT_SOUND_PATH] stringByExpandingBundlePath];
105 [[adium soundController] playSoundAtPath:soundPath];
109 * @brief Allow multiple actions?
111 * If this method returns YES, every one of this action associated with the triggering event will be executed.
112 * If this method returns NO, only the first will be.
114 * Don't allow multiple sounds to be played for a single event.
116 - (BOOL)allowMultipleActionsWithID:(NSString *)actionID
122 * @brief Alert was selected in the preferences
124 * Play the sound for this alert when the alert is selected
126 - (void)performPreviewForAlert:(NSDictionary *)alert
128 NSString *soundPath = [[[alert objectForKey:KEY_ACTION_DETAILS] objectForKey:KEY_ALERT_SOUND_PATH] stringByExpandingBundlePath];
129 [[adium soundController] playSoundAtPath:soundPath];