2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
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.
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.
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.
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;
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];
41 if (!proxyPasswordPromptControllerDict) proxyPasswordPromptControllerDict = [[NSMutableDictionary alloc] init];
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];
48 if ((controller = [[self alloc] initWithWindowNibName:PROXY_PASSWORD_PROMPT_NIB
49 forProxyServer:inServer
51 notifyingTarget:inTarget
53 context:inContext])) {
54 [proxyPasswordPromptControllerDict setObject:controller
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];
83 * @brief Our window will close
85 * Remove this controller from our dictionary of controllers
87 - (void)windowWillClose:(id)sender
89 NSString *identifier = [NSString stringWithFormat:@"%@.%@.%x",server,userName,target];
91 [proxyPasswordPromptControllerDict removeObjectForKey:identifier];
93 [super windowWillClose:sender];
98 [[self window] setTitle:PROXY_PASSWORD_REQUIRED];
100 [textField_server setStringValue:([server length] ? server : NONE)];
101 [textField_userName setStringValue:([userName length] ? userName : NONE)];
103 [super windowDidLoad];
107 * @brief Not actually used... do we need this?
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.
120 - (void)savePassword:(NSString *)password
122 [[adium accountController] setPassword:password forProxyServer:server userName:userName];