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 "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 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 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
58 notifyingTarget:inTarget
60 context:inContext])) {
61 [passwordPromptControllerDict setObject:controller
66 //bring the window front
67 [controller showWindow:nil];
68 [[controller window] makeKeyAndOrderFront:nil];
71 - (id)initWithWindowNibName:(NSString *)windowNibName forAccount:(AIAccount *)inAccount notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
73 if((self = [super initWithWindowNibName:windowNibName notifyingTarget:inTarget selector:inSelector context:inContext])) {
74 account = [inAccount retain];
88 * @brief Our window will close
90 * Remove this controller from our dictionary of controllers
92 - (void)windowWillClose:(id)sender
94 NSString *identifier = [account internalObjectID];
96 [passwordPromptControllerDict removeObjectForKey:identifier];
98 [super windowWillClose:sender];
102 * @brief Window laoded
104 * Perform initial configuration
106 - (void)windowDidLoad
108 [[self window] setTitle:ACCOUNT_PASSWORD_REQUIRED];
110 [textField_account setStringValue:[account formattedUID]];
111 [imageView_service setImage:[AIServiceIcons serviceIconForService:[account service]
112 type:AIServiceIconLarge
113 direction:AIIconNormal]];
115 [checkBox_savePassword setState:[[account preferenceForKey:[self savedPasswordKey]
116 group:GROUP_ACCOUNT_STATUS] boolValue]];
118 [super windowDidLoad];
124 - (NSString *)savedPasswordKey
126 return @"SavedPassword";
129 //Save a password; pass nil to forget the password
130 - (void)savePassword:(NSString *)password
133 [[adium accountController] setPassword:password forAccount:account];
135 [[adium accountController] forgetPasswordForAccount:account];