Merged [14875]:
[adiumx.git] / Source / AIPasswordPromptController.m
bloba11e0b5c48c51019a897703775de6ff7b3c4d219
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
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.
8  * 
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.
12  * 
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.
15  */
17 // $Id$
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];
31         }
33     return(self);
36 - (void)setTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
38         if (inTarget != target) {
39                 [target release];
40                 target = [inTarget retain];
41         }
42         
43         selector = inSelector;
44         
45         if (inContext != context) {
46                 [context release];
47                 context = [inContext retain];
48         }
52 - (void)dealloc
54     [target release];
55         [context release];
56         
57     [super dealloc];
60 - (void)windowDidLoad
62         [[self window] center];
63         
64         [super windowDidLoad];
67 - (NSString *)savedPasswordKey
69         return nil;
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];
84         //save password?
85         if(savePassword && password && [password length]) {
86                 [self savePassword:password];
87         }
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];
99     }
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];
122     [self autorelease];
125 - (void)windowDidBecomeKey:(NSNotification *)aNotification
127         [[self window] performSelector:@selector(makeFirstResponder:)
128                                                 withObject:textField_password
129                                                 afterDelay:0];
132 @end