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 "ESAccountPasswordPromptController.h"
19 #import <Adium/AIAccount.h>
20 #import <Adium/AIService.h>
21 #import <Adium/AIServiceIcons.h>
23 #define ACCOUNT_PASSWORD_PROMPT_NIB @"PasswordPrompt"
24 #define ACCOUNT_PASSWORD_REQUIRED AILocalizedString(@"Connecting Account","Password prompt window title")
26 @interface ESAccountPasswordPromptController (PRIVATE)
27 - (id)initWithWindowNibName:(NSString *)windowNibName forAccount:(AIAccount *)inAccount password:(NSString *)password notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext;
31 * @class ESAccountPasswordPromptController
32 * @brief Account password prompt window controller
34 * This AIPasswordPromptController subclass is responsible for requesting an account's password from the user when it
35 * attempts to connect and the password isn't saved. The user has the option of saving the password for future use.
37 * Only one password prompt window per account is shown; an attempt to show a prompt for an account which already has
38 * an open account results in the existing account becoming key and front.
40 @implementation ESAccountPasswordPromptController
42 static NSMutableDictionary *passwordPromptControllerDict = nil;
44 + (void)showPasswordPromptForAccount:(AIAccount *)inAccount password:(NSString *)inPassword notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
46 ESAccountPasswordPromptController *controller = nil;
47 NSString *identifier = [inAccount internalObjectID];
49 if (!passwordPromptControllerDict) passwordPromptControllerDict = [[NSMutableDictionary alloc] init];
51 if ((controller = [passwordPromptControllerDict objectForKey:identifier])) {
52 //Update the existing controller for this account to have the new target, selector, and context
53 [controller setTarget:inTarget selector:inSelector context:inContext];
56 if ((controller = [[self alloc] initWithWindowNibName:ACCOUNT_PASSWORD_PROMPT_NIB
59 notifyingTarget:inTarget
61 context:inContext])) {
62 [passwordPromptControllerDict setObject:controller
67 //bring the window front
68 [controller showWindowInFrontIfAllowed:YES];
71 - (id)initWithWindowNibName:(NSString *)windowNibName forAccount:(AIAccount *)inAccount password:(NSString *)inPassword notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
73 if ((self = [super initWithWindowNibName:windowNibName
75 notifyingTarget:inTarget
77 context:inContext])) {
78 account = [inAccount retain];
92 * @brief Our window will close
94 * Remove this controller from our dictionary of controllers
96 - (void)windowWillClose:(id)sender
98 NSString *identifier = [account internalObjectID];
100 [passwordPromptControllerDict removeObjectForKey:identifier];
102 [super windowWillClose:sender];
106 * @brief Window laoded
108 * Perform initial configuration
110 - (void)windowDidLoad
112 [[self window] setTitle:ACCOUNT_PASSWORD_REQUIRED];
114 [textField_account setStringValue:[account formattedUID]];
115 [imageView_service setImage:[AIServiceIcons serviceIconForService:[account service]
116 type:AIServiceIconLarge
117 direction:AIIconNormal]];
119 [checkBox_savePassword setState:[[account preferenceForKey:[self savedPasswordKey]
120 group:GROUP_ACCOUNT_STATUS] boolValue]];
122 [super windowDidLoad];
128 - (NSString *)savedPasswordKey
130 return @"SavedPassword";
133 //Save a password; pass nil to forget the password
134 - (void)savePassword:(NSString *)inPassword
137 [[adium accountController] setPassword:inPassword forAccount:account];
139 [[adium accountController] forgetPasswordForAccount:account];