2 // AIGuestAccountWindowController.m
5 // Created by Evan Schoenberg on 4/9/06.
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;
22 static AIGuestAccountWindowController *sharedGuestAccountWindowController = nil;
24 @implementation AIGuestAccountWindowController
25 + (void)showGuestAccountWindow
28 if (!sharedGuestAccountWindowController) {
29 sharedGuestAccountWindowController = [[self alloc] initWithWindowNibName:@"GuestAccountWindow"];
32 [[sharedGuestAccountWindowController window] makeKeyAndOrderFront:nil];
35 - (NSString *)adiumFrameAutosaveName
37 return @"GuestAccountWindow";
42 [[self window] setTitle:AILocalizedString(@"Connect Guest Account",nil)];
47 [super windowDidLoad];
49 [popUp_service setMenu:[AIServiceMenu menuOfServicesWithTarget:self
53 [self selectServiceType:nil];
54 [label_password setLocalizedString:AILocalizedString(@"Password:", nil)];
55 [label_service setLocalizedString:AILocalizedString(@"Service:", nil)];
56 [button_okay setLocalizedString:AILocalizedString(@"Connect", nil)];
57 [button_cancel setLocalizedString:AILocalizedString(@"Cancel", nil)];
58 [button_advanced setLocalizedString:[AILocalizedString(@"Advanced", nil) stringByAppendingEllipsis]];
61 - (void)windowWillClose:(id)sender
63 [super windowWillClose:sender];
65 [sharedGuestAccountWindowController autorelease]; sharedGuestAccountWindowController = nil;
68 - (AIService *)service
70 return [[popUp_service selectedItem] representedObject];
75 NSString *UID = [textField_name stringValue];
77 //Use the default user name if possible, if no UID is specified
78 if (!UID || ![UID length]) UID = [[self service] defaultUserName];
83 - (AIAccount *)account
86 account = [[[adium accountController] createAccountWithService:[self service]
87 UID:[self UID]] retain];
89 if (([self service] != [account service]) ||
90 (![[self UID] isEqualToString:[account UID]])) {
93 account = [[adium accountController] createAccountWithService:[self service]
101 - (void)selectServiceType:(id)sender
103 AIService *service = [self service];
104 [label_name setStringValue:[[service userNameLabel] stringByAppendingString:AILocalizedString(@":", "Colon which will be appended after a label such as 'User Name', before an input field")]];
106 [textField_name setFormatter:
107 [AIStringFormatter stringFormatterAllowingCharacters:[service allowedCharactersForAccountName]
108 length:[service allowedLengthForAccountName]
109 caseSensitive:[service caseSensitive]
110 errorMessage:AILocalizedString(@"The characters you're entering are not valid for an account name on this service.", nil)]];
112 NSString *placeholder = [service defaultUserName];
113 if (!placeholder || ![placeholder length]) placeholder = [service UIDPlaceholder];
114 [[textField_name cell] setPlaceholderString:(placeholder ? placeholder : @"")];
117 - (IBAction)okay:(id)sender
119 AIAccount *theAccount = [self account];
120 [theAccount setIsTemporary:YES];
122 [[adium accountController] addAccount:theAccount];
123 [theAccount setPasswordTemporarily:[textField_password secureStringValue]];
125 //Connect the account
126 [theAccount setPreference:[NSNumber numberWithBool:YES] forKey:@"Online" group:GROUP_ACCOUNT_STATUS];
128 [[self window] performClose:nil];
131 - (IBAction)displayAdvanced:(id)sender
133 [AIEditAccountWindowController editAccount:[self account]
134 onWindow:[self window]
135 notifyingTarget:self];
138 - (void)editAccountSheetDidEndForAccount:(AIAccount *)inAccount withSuccess:(BOOL)inSuccess
140 //If the AIEditAccountWindowController changes the account object, update to follow suit
141 if (inAccount != account) {
143 account = [inAccount retain];
146 //Make sure our UID is still accurate
147 if (![[inAccount UID] isEqualToString:[self UID]]) {
148 [textField_name setStringValue:[inAccount UID]];