Added `-[NSArray validateAsPropertyList]` and `-[NSDictionary validateAsPropertyList...
[adiumx.git] / Source / ESApplescriptContactAlertPlugin.m
blob7e8f443ce01d4167d26bf473e7de46a846bd66b8
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 "ESApplescriptContactAlertPlugin.h"
18 #import <Adium/AIContactAlertsControllerProtocol.h>
19 #import "ESPanelApplescriptDetailPane.h"
20 #import "ESApplescriptabilityController.h"
21 #import <AIUtilities/AIImageAdditions.h>
23 #define APPLESCRIPT_ALERT_SHORT AILocalizedString(@"Run an AppleScript",nil)
24 #define APPLESCRIPT_ALERT_LONG AILocalizedString(@"Run the AppleScript \"%@\"","%@ will be replaced by the name of the AppleScript to run.")
26 /*!
27  * @class ESApplescriptContactAlertPlugin
28  * @brief Component which provides a "Run an Applescript" Action
29  */
30 @implementation ESApplescriptContactAlertPlugin
32 - (void)installPlugin
34     //Install our contact alert
35         [[adium contactAlertsController] registerActionID:APPLESCRIPT_CONTACT_ALERT_IDENTIFIER withHandler:self];
38 /*!
39  * @brief Short description
40  * @result A short localized description of the action
41  */
42 - (NSString *)shortDescriptionForActionID:(NSString *)actionID
44         return APPLESCRIPT_ALERT_SHORT;
47 /*!
48  * @brief Long description
49  * @result A longer localized description of the action which should take into account the details dictionary as appropraite.
50  */
51 - (NSString *)longDescriptionForActionID:(NSString *)actionID withDetails:(NSDictionary *)details
53         NSString        *scriptName = [[[details objectForKey:KEY_APPLESCRIPT_TO_RUN] lastPathComponent] stringByDeletingPathExtension];
54         
55         if (scriptName && [scriptName length]) {
56                 return [NSString stringWithFormat:APPLESCRIPT_ALERT_LONG, scriptName];
57         } else {
58                 return APPLESCRIPT_ALERT_SHORT;
59         }
62 /*!
63  * @brief Image
64  */
65 - (NSImage *)imageForActionID:(NSString *)actionID
67         return [NSImage imageNamed:@"ApplescriptAlert" 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 [ESPanelApplescriptDetailPane actionDetailsPane];
79 /*!
80  * @brief Perform an action
81  *
82  * @param actionID The ID of the action to perform
83  * @param listObject The listObject associated with the event triggering the action. It may be nil
84  * @param details If set by the details pane when the action was created, the details dictionary for this particular action
85  * @param eventID The eventID which triggered this action
86  * @param userInfo Additional information associated with the event; userInfo's type will vary with the actionID.
87  */
88 - (BOOL)performActionID:(NSString *)actionID forListObject:(AIListObject *)listObject withDetails:(NSDictionary *)details triggeringEventID:(NSString *)eventID userInfo:(id)userInfo
90         NSString                *path = [details objectForKey:KEY_APPLESCRIPT_TO_RUN];
92         if (path) {
93                 [[adium applescriptabilityController] runApplescriptAtPath:path
94                                                                                                                   function:nil
95                                                                                                                  arguments:nil
96                                                                                                    notifyingTarget:nil
97                                                                                                                   selector:NULL
98                                                                                                                   userInfo:nil];
99         }
101         return (path != nil);
105  * @brief Allow multiple actions?
107  * If this method returns YES, every one of this action associated with the triggering event will be executed.
108  * If this method returns NO, only the first will be.
110  * Allow multiple applescript actions to be taken.
111  */
112 - (BOOL)allowMultipleActionsWithID:(NSString *)actionID
114         return YES;
117 @end