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 <Adium/AIListObject.h>
22 #import <AIUtilities/AIStringAdditions.h>
23 #import <AIUtilities/AIImageAdditions.h>
25 #define EVENT_SOUNDS_ALERT_SHORT AILocalizedString(@"Play a sound",nil)
26 #define EVENT_SOUNDS_ALERT_LONG AILocalizedString(@"Play the sound \"%@\"",nil)
28 #define SOUND_ALERT_IDENTIFIER @"PlaySound"
30 @interface AIEventSoundsPlugin (PRIVATE)
31 - (void)eventNotification:(NSNotification *)notification;
32 - (void)preferencesChanged:(NSNotification *)notification;
36 * @class AIEventSoundsPlugin
38 * @brief Component for the Play Sound action
40 @implementation AIEventSoundsPlugin
47 //Install our contact alert
48 [[adium contactAlertsController] registerActionID:SOUND_ALERT_IDENTIFIER withHandler:self];
52 * @brief Short description
53 * @result A short localized description of the action
55 - (NSString *)shortDescriptionForActionID:(NSString *)actionID
57 return EVENT_SOUNDS_ALERT_SHORT;
61 * @brief Long description
62 * @result A longer localized description of the action which should take into account the details dictionary as appropraite.
64 - (NSString *)longDescriptionForActionID:(NSString *)actionID withDetails:(NSDictionary *)details
66 NSString *fileName = [[[details objectForKey:KEY_ALERT_SOUND_PATH] lastPathComponent] stringByDeletingPathExtension];
68 if (fileName && [fileName length]) {
69 return [NSString stringWithFormat:EVENT_SOUNDS_ALERT_LONG, fileName];
71 return EVENT_SOUNDS_ALERT_SHORT;
78 - (NSImage *)imageForActionID:(NSString *)actionID
80 return [NSImage imageNamed:@"SoundAlert" forClass:[self class]];
85 * @result An <tt>AIModularPane</tt> to use for configuring this action, or nil if no configuration is possible.
87 - (AIModularPane *)detailsPaneForActionID:(NSString *)actionID
89 return [ESEventSoundAlertDetailPane actionDetailsPane];
93 * @brief Perform an action
97 * @param actionID The ID of the action to perform
98 * @param listObject The listObject associated with the event triggering the action. It may be nil
99 * @param details If set by the details pane when the action was created, the details dictionary for this particular action
100 * @param eventID The eventID which triggered this action
101 * @param userInfo Additional information associated with the event; userInfo's type will vary with the actionID.
103 - (void)performActionID:(NSString *)actionID forListObject:(AIListObject *)listObject withDetails:(NSDictionary *)details triggeringEventID:(NSString *)eventID userInfo:(id)userInfo
105 if (![listObject soundsAreMuted]) {
106 NSString *soundPath = [[details objectForKey:KEY_ALERT_SOUND_PATH] stringByExpandingBundlePath];
107 [[adium soundController] playSoundAtPath:soundPath];
112 * @brief Allow multiple actions?
114 * If this method returns YES, every one of this action associated with the triggering event will be executed.
115 * If this method returns NO, only the first will be.
117 * Don't allow multiple sounds to be played for a single event.
119 - (BOOL)allowMultipleActionsWithID:(NSString *)actionID
125 * @brief Alert was selected in the preferences
127 * Play the sound for this alert when the alert is selected
129 - (void)performPreviewForAlert:(NSDictionary *)alert
131 NSString *soundPath = [[[alert objectForKey:KEY_ACTION_DETAILS] objectForKey:KEY_ALERT_SOUND_PATH] stringByExpandingBundlePath];
132 [[adium soundController] playSoundAtPath:soundPath];