Put NSAutoreleasePool usage around other distributed notification observer methods
[adiumx.git] / Source / AIContactInfoWindowPlugin.m
blobfe17ff113c8cd4dfc8338c9ef434d81807ab0a87
1 //
2 //  AIContactInfoWindowPlugin.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 7/27/06.
6 //
8 #import "AIContactInfoWindowPlugin.h"
9 #import "AIContactInfoWindowController.h"
10 #import "ESShowContactInfoPromptController.h"
12 #import <Adium/AIAccountControllerProtocol.h>
13 #import <Adium/AIContactControllerProtocol.h>
14 #import <Adium/AIMenuControllerProtocol.h>
15 #import <Adium/AIInterfaceControllerProtocol.h>
16 #import <Adium/AIToolbarControllerProtocol.h>
18 #import <Adium/AIListObject.h>
19 #import <AIUtilities/AIImageAdditions.h>
20 #import <AIUtilities/AIMenuAdditions.h>
21 #import <AIUtilities/AIStringAdditions.h>
22 #import <AIUtilities/AIToolbarUtilities.h>
24 #define VIEW_CONTACTS_INFO                              AILocalizedString(@"Get Info",nil)
25 #define VIEW_CONTACTS_INFO_WITH_PROMPT  [AILocalizedString(@"Get Info for Contact", nil) stringByAppendingEllipsis]
26 #define GET_INFO_MASK                                   (NSCommandKeyMask | NSShiftKeyMask)
27 #define ALTERNATE_GET_INFO_MASK                 (NSCommandKeyMask | NSShiftKeyMask | NSControlKeyMask)
29 #define TITLE_SHOW_INFO                                 AILocalizedString(@"Show Info",nil)
30 #define TOOLTIP_SHOW_INFO                               AILocalizedString(@"Show information about this contact or group and change settings specific to it","Tooltip for the Show Info toolbar button")
32 @interface AIContactInfoWindowPlugin (PRIVATE)
33 - (void)prepareContactInfo;
34 @end
36 @implementation AIContactInfoWindowPlugin
37 - (void)installPlugin
39         [self prepareContactInfo];
42 //Contact Info --------------------------------------------------------------------------------
43 #pragma mark Contact Info
44 //Show info for the selected contact
45 - (IBAction)showContactInfo:(id)sender
47         AIListObject *listObject = nil;
48         
49         if ((sender == menuItem_getInfoContextualContact) || (sender == menuItem_getInfoContextualGroup)) {
50                 listObject = [[adium menuController] currentContextMenuObject];
51         } else {
52                 listObject = [[adium interfaceController] selectedListObject];
53         }
54         
55         if (listObject) {
56                 [NSApp activateIgnoringOtherApps:YES];
57                 [[[AIContactInfoWindowController showInfoWindowForListObject:listObject] window] makeKeyAndOrderFront:nil];
58         }
61 - (void)showSpecifiedContactInfo:(id)sender
63         [ESShowContactInfoPromptController showPrompt];
66 //Prepare the contact info menu and toolbar items
67 - (void)prepareContactInfo
69         //Add our get info contextual menu item
70         menuItem_getInfoContextualContact = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:VIEW_CONTACTS_INFO
71                                                                                                                                                                                          target:self
72                                                                                                                                                                                          action:@selector(showContactInfo:)
73                                                                                                                                                                           keyEquivalent:@""];
74         [[adium menuController] addContextualMenuItem:menuItem_getInfoContextualContact
75                                                                            toLocation:Context_Contact_Manage];
76         
77         menuItem_getInfoContextualGroup = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:VIEW_CONTACTS_INFO
78                                                                                                                                                                                    target:self
79                                                                                                                                                                                    action:@selector(showContactInfo:)
80                                                                                                                                                                         keyEquivalent:@""];
81         [[adium menuController] addContextualMenuItem:menuItem_getInfoContextualGroup
82                                                                            toLocation:Context_Group_Manage];
83         
84         //Install the standard Get Info menu item which will always be command-shift-I
85         menuItem_getInfo = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:VIEW_CONTACTS_INFO
86                                                                                                                                                         target:self
87                                                                                                                                                         action:@selector(showContactInfo:)
88                                                                                                                                          keyEquivalent:@"i"];
89         [menuItem_getInfo setKeyEquivalentModifierMask:GET_INFO_MASK];
90         [[adium menuController] addMenuItem:menuItem_getInfo toLocation:LOC_Contact_Info];
91         
92         /* Install the alternate Get Info menu item which will be alternately command-I and command-shift-I, in the contact list
93                 * and in all other places, respectively.
94                 */
95         menuItem_getInfoAlternate = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:VIEW_CONTACTS_INFO
96                                                                                                                                                                          target:self
97                                                                                                                                                                          action:@selector(showContactInfo:)
98                                                                                                                                                           keyEquivalent:@"i"];
99         [menuItem_getInfoAlternate setKeyEquivalentModifierMask:ALTERNATE_GET_INFO_MASK];
100         [menuItem_getInfoAlternate setAlternate:YES];
101         [[adium menuController] addMenuItem:menuItem_getInfoAlternate toLocation:LOC_Contact_Info];
102         
103         //Register for the contact list notifications
104         [[adium notificationCenter] addObserver:self selector:@selector(contactListDidBecomeMain:)
105                                                                            name:Interface_ContactListDidBecomeMain
106                                                                          object:nil];
107         [[adium notificationCenter] addObserver:self selector:@selector(contactListDidResignMain:)
108                                                                            name:Interface_ContactListDidResignMain
109                                                                          object:nil];
110         
111         //Watch changes in viewContactInfoMenuItem_alternate's menu so we can maintain its alternate status
112         //(it will expand into showing both the normal and the alternate items when the menu changes)
113         [[adium notificationCenter] addObserver:self selector:@selector(menuChanged:)
114                                                                            name:AIMenuDidChnge
115                                                                          object:[menuItem_getInfoAlternate menu]];
116         
117         //Install the Get Info (prompting for a contact name) menu item
118         menuItem_getInfoWithPrompt = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:VIEW_CONTACTS_INFO_WITH_PROMPT
119                                                                                                                                                                           target:self
120                                                                                                                                                                           action:@selector(showSpecifiedContactInfo:)
121                                                                                                                                                            keyEquivalent:@"i"];
122         [menuItem_getInfoWithPrompt setKeyEquivalentModifierMask:(NSCommandKeyMask | NSAlternateKeyMask)];
123         [[adium menuController] addMenuItem:menuItem_getInfoWithPrompt toLocation:LOC_Contact_Info];
124         
125         //Add our get info toolbar item
126         NSToolbarItem   *toolbarItem = [AIToolbarUtilities toolbarItemWithIdentifier:@"ShowInfo"
127                                                                                                                                                    label:AILocalizedString(@"Info",nil)
128                                                                                                                                         paletteLabel:TITLE_SHOW_INFO
129                                                                                                                                                  toolTip:TOOLTIP_SHOW_INFO
130                                                                                                                                                   target:self
131                                                                                                                                  settingSelector:@selector(setImage:)
132                                                                                                                                          itemContent:[NSImage imageNamed:@"pref-personal" forClass:[self class] loadLazily:YES]
133                                                                                                                                                   action:@selector(showContactInfo:)
134                                                                                                                                                         menu:nil];
135         [[adium toolbarController] registerToolbarItem:toolbarItem forToolbarType:@"ListObject"];
138 //Always be able to show the inspector
139 - (BOOL)validateMenuItem:(NSMenuItem *)menuItem
141         if ((menuItem == menuItem_getInfo) || (menuItem == menuItem_getInfoAlternate)) {
142                 return [[adium interfaceController] selectedListObject] != nil;
143                 
144         } else if ((menuItem == menuItem_getInfoContextualContact) || (menuItem == menuItem_getInfoContextualGroup)) {
145                 return [[adium menuController] currentContextMenuObject] != nil;
146                 
147         } else if (menuItem == menuItem_getInfoWithPrompt) {
148                 return [[adium accountController] oneOrMoreConnectedAccounts];
149         }
150         
151         return YES;
154 - (void)contactListDidBecomeMain:(NSNotification *)notification
156     [[adium menuController] removeItalicsKeyEquivalent];
157     [menuItem_getInfoAlternate setKeyEquivalentModifierMask:(NSCommandKeyMask)];
158         [menuItem_getInfoAlternate setAlternate:YES];
161 - (void)contactListDidResignMain:(NSNotification *)notification
163     //set our alternate modifier mask back to the obscure combination
164     [menuItem_getInfoAlternate setKeyEquivalent:@"i"];
165     [menuItem_getInfoAlternate setKeyEquivalentModifierMask:ALTERNATE_GET_INFO_MASK];
166     [menuItem_getInfoAlternate setAlternate:YES];
167         
168     //Now give the italics its combination back
169     [[adium menuController] restoreItalicsKeyEquivalent];
172 - (void)menuChanged:(NSNotification *)notification
174         [NSMenu updateAlternateMenuItem:menuItem_getInfoAlternate];
177 @end