Put NSAutoreleasePool usage around other distributed notification observer methods
[adiumx.git] / Source / ESProxyPasswordPromptController.m
blob2abbe9465805aea8643ee34f095305b2479d1ed1
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 <Adium/AIAccountControllerProtocol.h>
18 #import <Adium/AIContactControllerProtocol.h>
19 #import <Adium/AIContentControllerProtocol.h>
20 #import "ESProxyPasswordPromptController.h"
21 #import <AIUtilities/AIURLAdditions.h>
23 #define PROXY_PASSWORD_PROMPT_NIB               @"ProxyPasswordPrompt"
24 #define PROXY_PASSWORD_REQUIRED                 AILocalizedString(@"Accessing Proxy","Proxy password prompt window title")
26 #define NONE                                                    AILocalizedString(@"<None>", "Placeholder shown when no information is available")
28 @interface ESProxyPasswordPromptController (PRIVATE)
29 - (id)initWithWindowNibName:(NSString *)windowNibName forProxyServer:(NSString *)inServer userName:(NSString *)inUserName notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext;
30 @end
32 @implementation ESProxyPasswordPromptController
34 static NSMutableDictionary      *proxyPasswordPromptControllerDict = nil;
36 + (void)showPasswordPromptForProxyServer:(NSString *)inServer userName:(NSString *)inUserName notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
38         ESProxyPasswordPromptController         *controller = nil;
39         NSString                                                        *identifier = [NSString stringWithFormat:@"%@.%@.%x",inServer,inUserName,inTarget];
40         
41         if (!proxyPasswordPromptControllerDict) proxyPasswordPromptControllerDict = [[NSMutableDictionary alloc] init];
42         
43         if ((controller = [proxyPasswordPromptControllerDict objectForKey:identifier])) {
44                 //Update the existing controller for this account to have the new target, selector, and context
45                 [controller setTarget:inTarget selector:inSelector context:inContext];
46                 
47         } else {
48                 if ((controller = [[self alloc] initWithWindowNibName:PROXY_PASSWORD_PROMPT_NIB
49                                                                                            forProxyServer:inServer
50                                                                                                          userName:inUserName
51                                                                                           notifyingTarget:inTarget
52                                                                                                          selector:inSelector
53                                                                                                           context:inContext])) {
54                         [proxyPasswordPromptControllerDict setObject:controller
55                                                                                                   forKey:identifier];
56                 }
57         }
58         
59     //bring the window front
60         [controller showWindowInFrontIfAllowed:YES];
63 - (id)initWithWindowNibName:(NSString *)windowNibName forProxyServer:(NSString *)inServer userName:(NSString *)inUserName notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
65         if ((self = [super initWithWindowNibName:windowNibName password:nil notifyingTarget:inTarget selector:inSelector context:inContext])) {
66                 server   = [inServer   retain];
67                 userName = [inUserName retain];
68         }
70         return self;
73 - (void)dealloc
75         [server   release];
76         [userName release];
77         
78         [super dealloc];
81 /*!
82  * @brief Our window will close
83  *
84  * Remove this controller from our dictionary of controllers
85  */
86 - (void)windowWillClose:(id)sender
88         NSString        *identifier = [NSString stringWithFormat:@"%@.%@.%x",server,userName,target];
90         [proxyPasswordPromptControllerDict removeObjectForKey:identifier];
91         
92         [super windowWillClose:sender];
95 - (void)windowDidLoad
97         [[self window] setTitle:PROXY_PASSWORD_REQUIRED];
99         [textField_server setStringValue:([server length] ? server : NONE)];
100         [textField_userName setStringValue:([userName length] ? userName : NONE)];
101         
102         [super windowDidLoad];
106  * @brief Not actually used... do we need this?
107  */
108 - (NSString *)savedPasswordKey
110         return @"SavedProxyPassword";
114  * @brief Save a password; pass nil to forget the password
116  * Called with nil when Save Password becomes unchecked, or called with the password when it is checked as the window
117  * closes after the user presses Okay.
118  */
119 - (void)savePassword:(NSString *)inPassword
121         [[adium accountController] setPassword:inPassword forProxyServer:server userName:userName];
125 @end