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 "AIDockBehaviorPlugin.h"
18 #import "AIDockController.h"
19 #import <Adium/AIContactAlertsControllerProtocol.h>
20 #import "ESDockAlertDetailPane.h"
21 #import <Adium/AIInterfaceControllerProtocol.h>
22 #import <Adium/AIChat.h>
23 #import <AIUtilities/AIImageAdditions.h>
25 #define AIDockBehavior_ALERT_SHORT AILocalizedString(@"Bounce the dock icon",nil)
26 #define AIDockBehavior_ALERT_LONG AILocalizedString(@"Bounce the dock icon %@","%@ will be repalced with a string like 'one time' or 'repeatedly'.")
28 @interface AIDockBehaviorPlugin (PRIVATE)
29 - (void)observeToStopBouncingForChat:(AIChat *)chat;
30 - (void)stopBouncing:(NSNotification *)inNotification;
34 * @class AIDockBehaviorPlugin
35 * @brief Bounce Dock action component
37 @implementation AIDockBehaviorPlugin
44 //Install our contact alert
45 [[adium contactAlertsController] registerActionID:AIDockBehavior_ALERT_IDENTIFIER withHandler:self];
49 * @brief Short description
50 * @result A short localized description of the action
52 - (NSString *)shortDescriptionForActionID:(NSString *)actionID
54 return AIDockBehavior_ALERT_SHORT;
58 * @brief Long description
59 * @result A longer localized description of the action which should take into account the details dictionary as appropraite.
61 - (NSString *)longDescriptionForActionID:(NSString *)actionID withDetails:(NSDictionary *)details
63 int behavior = [[details objectForKey:KEY_AIDockBehavior_TYPE] intValue];
64 return [NSString stringWithFormat:AIDockBehavior_ALERT_LONG, [[[adium dockController] descriptionForBehavior:behavior] lowercaseString]];
70 - (NSImage *)imageForActionID:(NSString *)actionID
72 return [NSImage imageNamed:@"DockAlert" forClass:[self class]];
77 * @result An <tt>AIModularPane</tt> to use for configuring this action, or nil if no configuration is possible.
79 - (AIModularPane *)detailsPaneForActionID:(NSString *)actionID
81 return [ESDockAlertDetailPane actionDetailsPane];
85 * @brief Perform an action
87 * Bounce the dock icon
89 * @param actionID The ID of the action to perform
90 * @param listObject The listObject associated with the event triggering the action. It may be nil
91 * @param details If set by the details pane when the action was created, the details dictionary for this particular action
92 * @param eventID The eventID which triggered this action
93 * @param userInfo Additional information associated with the event; userInfo's type will vary with the actionID.
95 - (void)performActionID:(NSString *)actionID forListObject:(AIListObject *)listObject withDetails:(NSDictionary *)details triggeringEventID:(NSString *)eventID userInfo:(id)userInfo
97 if ([[adium dockController] performBehavior:[[details objectForKey:KEY_AIDockBehavior_TYPE] intValue]]) {
98 //The behavior will continue into the future
99 if ([[adium contactAlertsController] isMessageEvent:eventID]) {
100 AIChat *chat = [userInfo objectForKey:@"AIChat"];
102 if (chat == [[adium interfaceController] activeChat]) {
103 //If this is the active chat, stop the bouncing immediately
104 [self stopBouncing:nil];
107 [self observeToStopBouncingForChat:chat];
114 * @brief Begin watching for this chat to close or become active so we'll know to stop bouncing
116 - (void)observeToStopBouncingForChat:(AIChat *)chat
118 [[adium notificationCenter] addObserver:self
119 selector:@selector(stopBouncing:)
123 [[adium notificationCenter] addObserver:self
124 selector:@selector(stopBouncing:)
125 name:Chat_BecameActive
130 * @brief Remove our observers and stop bouncing
132 * We remove all observers because no matter how many chats we were watching, we will stop bouncing; subsequently, stopping a bounce
133 * would be inappropriate as it would not be associated with the chat or event which triggered a later bounce.
135 - (void)stopBouncing:(NSNotification *)inNotification
137 [[adium notificationCenter] removeObserver:self
140 [[adium notificationCenter] removeObserver:self
141 name:Chat_BecameActive
144 [[adium dockController] performBehavior:AIDockBehaviorStopBouncing];
148 * @brief Allow multiple actions?
150 * If this method returns YES, every one of this action associated with the triggering event will be executed.
151 * If this method returns NO, only the first will be.
153 * Don't allow multiple dock actions to occur. While a series of "Bounce every 5 seconds," "Bounce every 10 seconds,"
154 * and so on actions could be combined sanely, a series of "Bounce once" would make the dock go crazy.
156 - (BOOL)allowMultipleActionsWithID:(NSString *)actionID