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.
19 #import "AIPasswordPromptController.h"
20 #import <AIUtilities/AITextFieldAdditions.h>
22 #define PASSWORD_PROMPT_NIB @"PasswordPrompt"
23 #define KEY_PASSWORD_WINDOW_FRAME @"Password Prompt Frame"
25 @implementation AIPasswordPromptController
27 - (id)initWithWindowNibName:(NSString *)windowNibName notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
29 if((self = [super initWithWindowNibName:windowNibName])) {
30 [self setTarget:inTarget selector:inSelector context:inContext];
36 - (void)setTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
38 if (inTarget != target) {
40 target = [inTarget retain];
43 selector = inSelector;
45 if (inContext != context) {
47 context = [inContext retain];
62 [[self window] center];
64 [super windowDidLoad];
67 - (NSString *)savedPasswordKey
72 - (IBAction)cancel:(id)sender
74 //close up and notify our caller (pass nil to signify no password)
75 [self closeWindow:nil];
76 [target performSelector:selector withObject:nil withObject:context];
79 - (IBAction)okay:(id)sender
81 NSString *password = [textField_password secureStringValue];
82 BOOL savePassword = [checkBox_savePassword state];
85 if(savePassword && password && [password length]) {
86 [self savePassword:password];
89 //close up and notify our caller
90 [self closeWindow:nil];
91 [target performSelector:selector withObject:password withObject:context];
94 - (IBAction)togglePasswordSaved:(id)sender
96 if([sender state] == NSOffState){
97 //Forget any saved passwords
98 [self savePassword:nil];
102 - (void)savePassword:(NSString *)password
104 //abstract method. subclasses can do things here.
107 - (void)textDidChange:(NSNotification *)notification
109 //if the password field is empty, disable the OK button.
110 //otherwise, enable it.
111 [button_OK setEnabled:([[textField_password secureStringValue] length] != 0)];
114 // called as the window closes
115 - (void)windowWillClose:(id)sender
117 [NSObject cancelPreviousPerformRequestsWithTarget:[self window]
118 selector:@selector(makeFirstResponder:)
119 object:textField_password];
121 [super windowWillClose:sender];
125 - (void)windowDidBecomeKey:(NSNotification *)aNotification
127 [[self window] performSelector:@selector(makeFirstResponder:)
128 withObject:textField_password