Merged [21073]: When encoding an icon to JPEG, start off at 100% quality. If that...
[adiumx.git] / Source / ESAccountPasswordPromptController.m
blob21af98fb02404dfe27296a3b7ce87ee4e2613382
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 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 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                                                                                           notifyingTarget:inTarget
59                                                                                                          selector:inSelector
60                                                                                                           context:inContext])) {
61                         [passwordPromptControllerDict setObject:controller
62                                                                                          forKey:identifier];
63                 }
64         }
65         
66     //bring the window front
67         [controller showWindowInFrontIfAllowed:YES];
70 - (id)initWithWindowNibName:(NSString *)windowNibName forAccount:(AIAccount *)inAccount notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext
72     if ((self = [super initWithWindowNibName:windowNibName notifyingTarget:inTarget selector:inSelector context:inContext])) {
73                 account = [inAccount retain];
74         }
76     return self;
79 - (void)dealloc
81     [account release];
82         
83         [super dealloc];
86 /*!
87  * @brief Our window will close
88  *
89  * Remove this controller from our dictionary of controllers
90  */
91 - (void)windowWillClose:(id)sender
93         NSString        *identifier = [account internalObjectID];
95         [passwordPromptControllerDict removeObjectForKey:identifier];
97         [super windowWillClose:sender];
101  * @brief Window laoded
103  * Perform initial configuration
104  */
105 - (void)windowDidLoad
107         [[self window] setTitle:ACCOUNT_PASSWORD_REQUIRED];
108         
109     [textField_account setStringValue:[account formattedUID]];
110         [imageView_service setImage:[AIServiceIcons serviceIconForService:[account service]
111                                                                                                                                  type:AIServiceIconLarge
112                                                                                                                         direction:AIIconNormal]];
113         
114         [checkBox_savePassword setState:[[account preferenceForKey:[self savedPasswordKey] 
115                                                                                                                  group:GROUP_ACCOUNT_STATUS] boolValue]];
117         [super windowDidLoad];
121  * @brief The key 
122  */
123 - (NSString *)savedPasswordKey
125         return @"SavedPassword";
128 //Save a password; pass nil to forget the password
129 - (void)savePassword:(NSString *)password
131         if (password) {
132                 [[adium accountController] setPassword:password forAccount:account];    
133         } else {
134                 [[adium accountController] forgetPasswordForAccount:account];   
135         }
138 @end