Put NSAutoreleasePool usage around other distributed notification observer methods
[adiumx.git] / Source / AIEventSoundsPlugin.m
blob269ea9b4f5f2086dee31e54430ded8cec643e934
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
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.
8  * 
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.
12  * 
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.
15  */
17 #import "AIEventSoundsPlugin.h"
18 #import "AISoundController.h"
19 #import <Adium/AIContactAlertsControllerProtocol.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;
33 @end
35 /*!
36  * @class AIEventSoundsPlugin
37  *
38  * @brief Component for the Play Sound action
39  */
40 @implementation AIEventSoundsPlugin
42 /*!
43  * @brief Install
44  */
45 - (void)installPlugin
47     //Install our contact alert
48         [[adium contactAlertsController] registerActionID:SOUND_ALERT_IDENTIFIER withHandler:self];
51 /*!
52  * @brief Short description
53  * @result A short localized description of the action
54  */
55 - (NSString *)shortDescriptionForActionID:(NSString *)actionID
57         return EVENT_SOUNDS_ALERT_SHORT;
60 /*!
61  * @brief Long description
62  * @result A longer localized description of the action which should take into account the details dictionary as appropraite.
63  */
64 - (NSString *)longDescriptionForActionID:(NSString *)actionID withDetails:(NSDictionary *)details
66         NSString        *fileName = [[[details objectForKey:KEY_ALERT_SOUND_PATH] lastPathComponent] stringByDeletingPathExtension];
67         
68         if (fileName && [fileName length]) {
69                 return [NSString stringWithFormat:EVENT_SOUNDS_ALERT_LONG, fileName];
70         } else {
71                 return EVENT_SOUNDS_ALERT_SHORT;
72         }
75 /*!
76  * @brief Image
77  */
78 - (NSImage *)imageForActionID:(NSString *)actionID
80         return [NSImage imageNamed:@"SoundAlert" forClass:[self class]];
83 /*!
84  * @brief Details pane
85  * @result An <tt>AIModularPane</tt> to use for configuring this action, or nil if no configuration is possible.
86  */
87 - (AIModularPane *)detailsPaneForActionID:(NSString *)actionID
89         return [ESEventSoundAlertDetailPane actionDetailsPane];
92 /*!
93  * @brief Perform an action
94  *
95  * Play a sound
96  *
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.
102  */
103 - (BOOL)performActionID:(NSString *)actionID forListObject:(AIListObject *)listObject withDetails:(NSDictionary *)details triggeringEventID:(NSString *)eventID userInfo:(id)userInfo
105         BOOL shouldPlay = ![listObject soundsAreMuted];
106         if (shouldPlay) {
107                 NSString        *soundPath = [[details objectForKey:KEY_ALERT_SOUND_PATH] stringByExpandingBundlePath];
108                 [[adium soundController] playSoundAtPath:soundPath];
109         }
110         
111         return shouldPlay;
115  * @brief Allow multiple actions?
117  * If this method returns YES, every one of this action associated with the triggering event will be executed.
118  * If this method returns NO, only the first will be.
120  * Don't allow multiple sounds to be played for a single event.
121  */
122 - (BOOL)allowMultipleActionsWithID:(NSString *)actionID
124         return NO;
128  * @brief Alert was selected in the preferences
130  *  Play the sound for this alert when the alert is selected
131  */
132 - (void)performPreviewForAlert:(NSDictionary *)alert
134         NSString        *soundPath = [[[alert objectForKey:KEY_ACTION_DETAILS] objectForKey:KEY_ALERT_SOUND_PATH] stringByExpandingBundlePath];
135         [[adium soundController] playSoundAtPath:soundPath];
138 @end