Added `-[NSArray validateAsPropertyList]` and `-[NSDictionary validateAsPropertyList...
[adiumx.git] / Source / SMContactListShowBehaviorPlugin.m
blobe7b8696e00a266e5b58e677cb729141144006250
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 "SMContactListShowBehaviorPlugin.h"
18 #import "SMContactListShowDetailsPane.h"
19 #import <Adium/AIContactAlertsControllerProtocol.h>
20 #import "AICoreComponentLoader.h"
21 #import "AISCLViewPlugin.h"
22 #import "AIListWindowController.h"
23 #import <AIUtilities/AIImageAdditions.h>
25 #define SHOW_CONTACT_LIST_BEHAVIOR_ALERT_SHORT  AILocalizedString(@"Show the contact list window",nil)
26 #define SHOW_CONTACT_LIST_BEHAVIOR_ALERT_LONG   AILocalizedString(@"Show the contact list window for %.1f seconds",nil)
28 /*!
29  * @class SMContactListShowBehaviorPlugin
30  * @brief Show hidden contact list action component
31  */
32 @implementation SMContactListShowBehaviorPlugin
34 /*!
35  * @brief Install
36  */
37 - (void)installPlugin
39         //Install our contact alert
40         [[adium contactAlertsController] registerActionID:SHOW_CONTACT_LIST_BEHAVIOR_ALERT_IDENTIFIER withHandler:self];
43 /*!
44  * @brief Short description
45  * @result A short localized description of the action
46  */
47 - (NSString *)shortDescriptionForActionID:(NSString *)actionID
49         return SHOW_CONTACT_LIST_BEHAVIOR_ALERT_SHORT;
52 /*!
53  * @brief Long description
54  * @result A longer localized description of the action which should take into account the details dictionary as appropraite.
55  */
56 - (NSString *)longDescriptionForActionID:(NSString *)actionID withDetails:(NSDictionary *)details
58         double seconds = [[details objectForKey:KEY_SECONDS_TO_SHOW_LIST] doubleValue];
59         return [NSString stringWithFormat:SHOW_CONTACT_LIST_BEHAVIOR_ALERT_LONG, seconds];
62 /*!
63  * @brief Image
64  */
65 - (NSImage *)imageForActionID:(NSString *)actionID
67         return [NSImage imageNamed:@"pref-contactList" forClass:[self class]];
70 /*!
71  * @brief Details pane
72  * @result An <tt>AIModularPane</tt> to use for configuring this action, or nil if no configuration is possible.
73  */
74 - (AIModularPane *)detailsPaneForActionID:(NSString *)actionID
76         return [SMContactListShowDetailsPane actionDetailsPane];
79 /*!
80  * @brief Perform an action
81  *
82  * Bounce the dock icon
83  *
84  * @param actionID The ID of the action to perform
85  * @param listObject The listObject associated with the event triggering the action. It may be nil
86  * @param details If set by the details pane when the action was created, the details dictionary for this particular action
87  * @param eventID The eventID which triggered this action
88  * @param userInfo Additional information associated with the event; userInfo's type will vary with the actionID.
89  */
90 - (BOOL)performActionID:(NSString *)actionID forListObject:(AIListObject *)listObject withDetails:(NSDictionary *)details triggeringEventID:(NSString *)eventID userInfo:(id)userInfo
92         NSTimeInterval secondsToShow = [[details objectForKey:KEY_SECONDS_TO_SHOW_LIST] doubleValue];
93         AISCLViewPlugin *contactListViewPlugin = (AISCLViewPlugin *)[[adium componentLoader] pluginWithClassName:@"AISCLViewPlugin"];
94         AIListWindowController *windowController = [contactListViewPlugin contactListWindowController];
96         [windowController setPreventHiding:YES];
97         
98         if ([windowController windowShouldHideOnDeactivate]) {
99                 [[windowController window] setHidesOnDeactivate:NO];
100                 [[windowController window] orderFront:self];
101         } else {
102                 [windowController slideWindowOnScreen];
103         }
105         [NSObject cancelPreviousPerformRequestsWithTarget:self
106                                                                                          selector:@selector(hideContactList:)
107                                                                                            object:nil];
108         [self performSelector:@selector(hideContactList:)
109                            withObject:nil
110                            afterDelay:secondsToShow];
111         
112         return YES;
117  * @brief Show the contact list after the time specified has elapsed
118  */
119 - (void)hideContactList:(NSTimer *)timer {
120         AISCLViewPlugin                 *contactListViewPlugin = (AISCLViewPlugin *)[[adium componentLoader] pluginWithClassName:@"AISCLViewPlugin"];
121         AIListWindowController  *windowController = [contactListViewPlugin contactListWindowController];
122         
123         [windowController setPreventHiding:NO];
125         if ([windowController windowShouldHideOnDeactivate] && ![NSApp isActive]) {
126                 [[windowController window] orderOut:self];
128         } else if ([windowController shouldSlideWindowOffScreen]) {
129                 [windowController slideWindowOffScreenEdges:[windowController slidableEdgesAdjacentToWindow]];
130         }
135  * @brief Allow multiple actions?
137  * If this method returns YES, every one of this action associated with the triggering event will be executed.
138  * If this method returns NO, only the first will be.
140  * Don't allow multiple dock actions to occur.  The contact list can only show itself once.
141  */
142 - (BOOL)allowMultipleActionsWithID:(NSString *)actionID
144         return NO;
147 @end