AIHyperlinks universal building
[adiumx.git] / Source / ESProxyPasswordPromptController.m
blob41b102308146aea47b03b5a5a675f2ff7eb16918
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 "AIAccountController.h"
18 #import "AIContactController.h"
19 #import "AIContentController.h"
20 #import "ESProxyPasswordPromptController.h"
21 #import <AIUtilities/ESURLAdditions.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 showWindow:nil];
61         [[controller window] makeKeyAndOrderFront:nil]; 
64 - (id)initWithWindowNibName:(NSString *)windowNibName forProxyServer:(NSString *)inServer userName:(NSString *)inUserName notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
66         if((self = [super initWithWindowNibName:windowNibName notifyingTarget:inTarget selector:inSelector context:inContext])) {
67                 server   = [inServer   retain];
68                 userName = [inUserName retain];
69         }
71         return self;
74 - (void)dealloc
76         [server   release];
77         [userName release];
78         
79         [super dealloc];
83  * @brief Our window will close
84  *
85  * Remove this controller from our dictionary of controllers
86  */
87 - (void)windowWillClose:(id)sender
89         NSString        *identifier = [NSString stringWithFormat:@"%@.%@.%x",server,userName,target];
91         [proxyPasswordPromptControllerDict removeObjectForKey:identifier];
92         
93         [super windowWillClose:sender];
96 - (void)windowDidLoad
98         [[self window] setTitle:PROXY_PASSWORD_REQUIRED];
100         [textField_server setStringValue:([server length] ? server : NONE)];
101         [textField_userName setStringValue:([userName length] ? userName : NONE)];
102         
103         [super windowDidLoad];
107  * @brief Not actually used... do we need this?
108  */
109 - (NSString *)savedPasswordKey
111         return @"SavedProxyPassword";
115  * @brief Save a password; pass nil to forget the password
117  * Called with nil when Save Password becomes unchecked, or called with the password when it is checked as the window
118  * closes after the user presses Okay.
119  */
120 - (void)savePassword:(NSString *)password
122         [[adium accountController] setPassword:password forProxyServer:server userName:userName];
126 @end