Added Deployment-Debug_PPC-Only build style to FriBidi. Fixes #9021
[adiumx.git] / Source / ESAccountPasswordPromptController.m
blob9e7282451c337a3872839296ba75fd7ca84a2729
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 #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;
28 @end
30 /*!
31  * @class ESAccountPasswordPromptController
32  * @brief Account password prompt window controller
33  * 
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.
36  *
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.
39  */
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
45 {       
46         ESAccountPasswordPromptController       *controller = nil;
47         NSString                                                        *identifier = [inAccount internalObjectID];
48         
49         if (!passwordPromptControllerDict) passwordPromptControllerDict = [[NSMutableDictionary alloc] init];
50         
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];
55         } else {
56                 if ((controller = [[self alloc] initWithWindowNibName:ACCOUNT_PASSWORD_PROMPT_NIB 
57                                                                                                    forAccount:inAccount 
58                                                                                                          password:inPassword
59                                                                                           notifyingTarget:inTarget
60                                                                                                          selector:inSelector
61                                                                                                           context:inContext])) {
62                         [passwordPromptControllerDict setObject:controller
63                                                                                          forKey:identifier];
64                 }
65         }
66         
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
74                                                                         password:inPassword
75                                                          notifyingTarget:inTarget
76                                                                         selector:inSelector
77                                                                          context:inContext])) {
78                 account = [inAccount retain];
79         }
81     return self;
84 - (void)dealloc
86     [account release];
87         
88         [super dealloc];
91 /*!
92  * @brief Our window will close
93  *
94  * Remove this controller from our dictionary of controllers
95  */
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
109  */
110 - (void)windowDidLoad
112         [[self window] setTitle:ACCOUNT_PASSWORD_REQUIRED];
113         
114     [textField_account setStringValue:[account formattedUID]];
115         [imageView_service setImage:[AIServiceIcons serviceIconForService:[account service]
116                                                                                                                                  type:AIServiceIconLarge
117                                                                                                                         direction:AIIconNormal]];
118         
119         [checkBox_savePassword setState:[[account preferenceForKey:[self savedPasswordKey] 
120                                                                                                                  group:GROUP_ACCOUNT_STATUS] boolValue]];
122         [super windowDidLoad];
126  * @brief The key 
127  */
128 - (NSString *)savedPasswordKey
130         return @"SavedPassword";
133 //Save a password; pass nil to forget the password
134 - (void)savePassword:(NSString *)inPassword
136         if (inPassword) {
137                 [[adium accountController] setPassword:inPassword forAccount:account];  
138         } else {
139                 [[adium accountController] forgetPasswordForAccount:account];   
140         }
143 @end