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 <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;
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 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 notifyingTarget:inTarget selector:inSelector context:inContext])) {
66 server = [inServer retain];
67 userName = [inUserName retain];
82 * @brief Our window will close
84 * Remove this controller from our dictionary of controllers
86 - (void)windowWillClose:(id)sender
88 NSString *identifier = [NSString stringWithFormat:@"%@.%@.%x",server,userName,target];
90 [proxyPasswordPromptControllerDict removeObjectForKey:identifier];
92 [super windowWillClose:sender];
97 [[self window] setTitle:PROXY_PASSWORD_REQUIRED];
99 [textField_server setStringValue:([server length] ? server : NONE)];
100 [textField_userName setStringValue:([userName length] ? userName : NONE)];
102 [super windowDidLoad];
106 * @brief Not actually used... do we need this?
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.
119 - (void)savePassword:(NSString *)password
121 [[adium accountController] setPassword:password forProxyServer:server userName:userName];