Merged [15040]: Trying some magic: 5 seconds after the last unreachable host is repor...
[adiumx.git] / Source / AIEventSoundsPlugin.m
blob68c2bdeec4ac17f3e487864b9bffcc2f5f0bd0d6
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 "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;
32 @end
34 /*!
35  * @class AIEventSoundsPlugin
36  *
37  * @brief Component for the Play Sound action
38  */
39 @implementation AIEventSoundsPlugin
41 /*!
42  * @brief Install
43  */
44 - (void)installPlugin
46     //Install our contact alert
47         [[adium contactAlertsController] registerActionID:SOUND_ALERT_IDENTIFIER withHandler:self];
50 /*!
51  * @brief Short description
52  * @result A short localized description of the action
53  */
54 - (NSString *)shortDescriptionForActionID:(NSString *)actionID
56         return(EVENT_SOUNDS_ALERT_SHORT);
59 /*!
60  * @brief Long description
61  * @result A longer localized description of the action which should take into account the details dictionary as appropraite.
62  */
63 - (NSString *)longDescriptionForActionID:(NSString *)actionID withDetails:(NSDictionary *)details
65         NSString        *fileName = [[[details objectForKey:KEY_ALERT_SOUND_PATH] lastPathComponent] stringByDeletingPathExtension];
66         
67         if(fileName && [fileName length]){
68                 return([NSString stringWithFormat:EVENT_SOUNDS_ALERT_LONG, fileName]);
69         }else{
70                 return(EVENT_SOUNDS_ALERT_SHORT);
71         }
74 /*!
75  * @brief Image
76  */
77 - (NSImage *)imageForActionID:(NSString *)actionID
79         return([NSImage imageNamed:@"SoundAlert" forClass:[self class]]);
82 /*!
83  * @brief Details pane
84  * @result An <tt>AIModularPane</tt> to use for configuring this action, or nil if no configuration is possible.
85  */
86 - (AIModularPane *)detailsPaneForActionID:(NSString *)actionID
88         return([ESEventSoundAlertDetailPane actionDetailsPane]);
91 /*!
92  * @brief Perform an action
93  *
94  * Play a sound
95  *
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.
101  */
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.
115  */
116 - (BOOL)allowMultipleActionsWithID:(NSString *)actionID
118         return(NO);
122  * @brief Alert was selected in the preferences
124  *  Play the sound for this alert when the alert is selected
125  */
126 - (void)performPreviewForAlert:(NSDictionary *)alert
128         NSString        *soundPath = [[[alert objectForKey:KEY_ACTION_DETAILS] objectForKey:KEY_ALERT_SOUND_PATH] stringByExpandingBundlePath];
129         [[adium soundController] playSoundAtPath:soundPath];
132 @end