Allow localization of the Alert Text label in the Display an Alert action
[adiumx.git] / Source / AIGuestAccountWindowController.m
bloba4d25ef4f889fe4c454cd2bb0da59cf9a05fe938
1 //
2 //  AIGuestAccountWindowController.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 4/9/06.
6 //
8 #import "AIGuestAccountWindowController.h"
9 #import "AIEditAccountWindowController.h"
10 #import <Adium/AIAccountControllerProtocol.h>
11 #import <Adium/AIAccount.h>
12 #import <Adium/AIService.h>
13 #import "AIServiceMenu.h"
14 #import <AIUtilities/AIStringAdditions.h>
15 #import <AIUtilities/AIStringFormatter.h>
16 #import <AIUtilities/AITextFieldAdditions.h>
18 @interface AIGuestAccountWindowController (PRIVATE)
19 - (void)selectServiceType:(id)sender;
20 @end
22 static AIGuestAccountWindowController *sharedGuestAccountWindowController = nil;
24 @implementation AIGuestAccountWindowController
25 + (void)showGuestAccountWindow
27         //Create the window
28         if (!sharedGuestAccountWindowController) {
29                 sharedGuestAccountWindowController = [[self alloc] initWithWindowNibName:@"GuestAccountWindow"];
30         }
32         [[sharedGuestAccountWindowController window] makeKeyAndOrderFront:nil];
35 - (NSString *)adiumFrameAutosaveName
37         return @"GuestAccountWindow";
40 - (void)awakeFromNib
42         [[self window] setTitle:AILocalizedString(@"Connect Guest Account", "Title for the window shown when adding a guest (temporary) account")];
45 - (void)dealloc
47         [account release];
48         
49         [super dealloc];
52 - (void)windowDidLoad
54         [super windowDidLoad];
56         [popUp_service setMenu:[AIServiceMenu menuOfServicesWithTarget:self
57                                                                                                 activeServicesOnly:NO
58                                                                                                    longDescription:YES
59                                                                                                                         format:nil]];
60         [self selectServiceType:nil];
61         [label_password setLocalizedString:AILocalizedString(@"Password:", nil)];
62         [label_service setLocalizedString:AILocalizedString(@"Service:", nil)];
63         [button_okay setLocalizedString:AILocalizedString(@"Connect", nil)];
64         [button_cancel setLocalizedString:AILocalizedString(@"Cancel", nil)];
65         [button_advanced setLocalizedString:[AILocalizedString(@"Advanced", nil) stringByAppendingEllipsis]];
68 - (void)windowWillClose:(id)sender
70         [super windowWillClose:sender];
71         
72         [sharedGuestAccountWindowController autorelease]; sharedGuestAccountWindowController = nil;
75 - (AIService *)service
77         return [[popUp_service selectedItem] representedObject];
80 - (NSString *)UID
82         NSString *UID = [textField_name stringValue];
83         
84         //Use the default user name if possible, if no UID is specified
85         if (!UID || ![UID length]) UID = [[self service] defaultUserName];
87         return UID;
90 - (AIAccount *)account
92         if (!account) {
93                 account = [[[adium accountController] createAccountWithService:[self service]
94                                                                                                                                    UID:[self UID]] retain];
95         } else {
96                 if (([self service] != [account service]) ||
97                         (![[self UID] isEqualToString:[account UID]])) {
98                         [account release];
100                         account = [[[adium accountController] createAccountWithService:[self service]
101                                                                                                                                            UID:[self UID]] retain];
102                 }
103         }
104         
105         return account;
108 - (void)selectServiceType:(id)sender
110         AIService *service = [self service];
111         [label_name setStringValue:[[service userNameLabel] stringByAppendingString:AILocalizedString(@":", "Colon which will be appended after a label such as 'User Name', before an input field")]];
112         
113         [textField_name setFormatter:
114                 [AIStringFormatter stringFormatterAllowingCharacters:[service allowedCharactersForAccountName]
115                                                                                                           length:[service allowedLengthForAccountName]
116                                                                                            caseSensitive:[service caseSensitive]
117                                                                                                 errorMessage:AILocalizedString(@"The characters you're entering are not valid for an account name on this service.", nil)]];
118         
119         NSString *placeholder = [service defaultUserName];
120         if (!placeholder || ![placeholder length]) placeholder = [service UIDPlaceholder];
121         [[textField_name cell] setPlaceholderString:(placeholder ? placeholder : @"")];
124 - (IBAction)okay:(id)sender
126         AIAccount       *theAccount = [self account];
127         [theAccount setIsTemporary:YES];
128         
129         [[adium accountController] addAccount:theAccount];
130         [theAccount setPasswordTemporarily:[textField_password secureStringValue]];
132         //Connect the account
133         [theAccount setPreference:[NSNumber numberWithBool:YES] forKey:@"Online" group:GROUP_ACCOUNT_STATUS];
134         
135         [[self window] performClose:nil];
138 - (IBAction)displayAdvanced:(id)sender
140         [AIEditAccountWindowController editAccount:[self account]
141                                                                           onWindow:[self window]
142                                                            notifyingTarget:self];       
145 - (void)editAccountSheetDidEndForAccount:(AIAccount *)inAccount withSuccess:(BOOL)inSuccess
147         //If the AIEditAccountWindowController changes the account object, update to follow suit
148         if (inAccount != account) {
149                 [account release];
150                 account = [inAccount retain];
151         }
152         
153         //Make sure our UID is still accurate
154         if (![[inAccount UID] isEqualToString:[self UID]]) {
155                 [textField_name setStringValue:[inAccount UID]];
156         }
159 @end