Added a debug log to investigate #8685, as it worksforme. Refs #8685
[adiumx.git] / Source / AIDockBehaviorPlugin.m
blobef7176f76ecff8eac74df85624a95c0231efefcc
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 "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;
31 @end
33 /*!
34  * @class AIDockBehaviorPlugin
35  * @brief Bounce Dock action component
36  */
37 @implementation AIDockBehaviorPlugin
39 /*!
40  * @brief Install
41  */
42 - (void)installPlugin
44         //Install our contact alert
45         [[adium contactAlertsController] registerActionID:AIDockBehavior_ALERT_IDENTIFIER withHandler:self];
48 /*!
49  * @brief Short description
50  * @result A short localized description of the action
51  */
52 - (NSString *)shortDescriptionForActionID:(NSString *)actionID
54         return AIDockBehavior_ALERT_SHORT;
57 /*!
58  * @brief Long description
59  * @result A longer localized description of the action which should take into account the details dictionary as appropraite.
60  */
61 - (NSString *)longDescriptionForActionID:(NSString *)actionID withDetails:(NSDictionary *)details
63         int behavior = [[details objectForKey:KEY_DOCK_BEHAVIOR_TYPE] intValue];
64         return [NSString stringWithFormat:AIDockBehavior_ALERT_LONG, [[[adium dockController] descriptionForBehavior:behavior] lowercaseString]];
67 /*!
68  * @brief Image
69  */
70 - (NSImage *)imageForActionID:(NSString *)actionID
72         return [NSImage imageNamed:@"DockAlert" forClass:[self class]];
75 /*!
76  * @brief Details pane
77  * @result An <tt>AIModularPane</tt> to use for configuring this action, or nil if no configuration is possible.
78  */
79 - (AIModularPane *)detailsPaneForActionID:(NSString *)actionID
81         return [ESDockAlertDetailPane actionDetailsPane];
84 /*!
85  * @brief Perform an action
86  *
87  * Bounce the dock icon
88  *
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.
94  */
95 - (BOOL)performActionID:(NSString *)actionID forListObject:(AIListObject *)listObject withDetails:(NSDictionary *)details triggeringEventID:(NSString *)eventID userInfo:(id)userInfo
97         if ([[adium dockController] performBehavior:[[details objectForKey:KEY_DOCK_BEHAVIOR_TYPE] intValue]]) {
98                 //The behavior will continue into the future
99                 if ([[adium contactAlertsController] isMessageEvent:eventID]) {
100                         AIChat *chat = [userInfo objectForKey:@"AIChat"];
101                         
102                         if (chat == [[adium interfaceController] activeChat]) {
103                                 //If this is the active chat, stop the bouncing immediately
104                                 [self stopBouncing:nil];
105         
106                         } else {
107                                 [self observeToStopBouncingForChat:chat];
108                         }
109                 }
110         }
111         
112         return YES;
116  * @brief Begin watching for this chat to close or become active so we'll know to stop bouncing
117  */
118 - (void)observeToStopBouncingForChat:(AIChat *)chat
120         [[adium notificationCenter] addObserver:self
121                                                                    selector:@selector(stopBouncing:)
122                                                                            name:Chat_WillClose
123                                                                          object:chat];
125         [[adium notificationCenter] addObserver:self
126                                                                    selector:@selector(stopBouncing:)
127                                                                            name:Chat_BecameActive
128                                                                          object:chat];
132  * @brief Remove our observers and stop bouncing
134  * We remove all observers because no matter how many chats we were watching, we will stop bouncing; subsequently, stopping a bounce
135  * would be inappropriate as it would not be associated with the chat or event which triggered a later bounce.
136  */
137 - (void)stopBouncing:(NSNotification *)inNotification
139         [[adium notificationCenter] removeObserver:self
140                                                                                   name:Chat_WillClose
141                                                                                 object:nil];
142         [[adium notificationCenter] removeObserver:self
143                                                                                   name:Chat_BecameActive
144                                                                                 object:nil];
146         [[adium dockController] performBehavior:AIDockBehaviorStopBouncing];
150  * @brief Allow multiple actions?
152  * If this method returns YES, every one of this action associated with the triggering event will be executed.
153  * If this method returns NO, only the first will be.
155  * Don't allow multiple dock actions to occur.  While a series of "Bounce every 5 seconds," "Bounce every 10 seconds,"
156  * and so on actions could be combined sanely, a series of "Bounce once" would make the dock go crazy.
157  */
158 - (BOOL)allowMultipleActionsWithID:(NSString *)actionID
160         return NO;
163 @end