William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | //
// AIGuestAccountWindowController.m
// Adium
//
// Created by Evan Schoenberg on 4/9/06.
//
#import "AIGuestAccountWindowController.h"
#import "AIEditAccountWindowController.h"
#import <Adium/AIAccountControllerProtocol.h>
#import <Adium/AIAccount.h>
#import <Adium/AIService.h>
#import "AIServiceMenu.h"
#import <AIUtilities/AIStringAdditions.h>
#import <AIUtilities/AIStringFormatter.h>
@interface AIGuestAccountWindowController ()
- (void)selectServiceType:(id)sender;
@end
static AIGuestAccountWindowController *sharedGuestAccountWindowController = nil;
@implementation AIGuestAccountWindowController
+ (void)showGuestAccountWindow
{
//Create the window
if (!sharedGuestAccountWindowController) {
sharedGuestAccountWindowController = [[self alloc] initWithWindowNibName:@"GuestAccountWindow"];
}
[[sharedGuestAccountWindowController window] makeKeyAndOrderFront:nil];
}
- (NSString *)adiumFrameAutosaveName
{
return @"GuestAccountWindow";
}
- (void)awakeFromNib
{
[[self window] setTitle:AILocalizedString(@"Connect Guest Account", "Title for the window shown when adding a guest (temporary) account")];
}
- (void)dealloc
{
[account release];
[super dealloc];
}
- (void)windowDidLoad
{
[super windowDidLoad];
[popUp_service setMenu:[AIServiceMenu menuOfServicesWithTarget:self
activeServicesOnly:NO
longDescription:YES
format:nil]];
[self selectServiceType:nil];
[label_password setLocalizedString:AILocalizedString(@"Password:", nil)];
[label_service setLocalizedString:AILocalizedString(@"Service:", nil)];
[button_okay setLocalizedString:AILocalizedString(@"Connect", nil)];
[button_cancel setLocalizedString:AILocalizedString(@"Cancel", nil)];
[button_advanced setLocalizedString:[AILocalizedString(@"Advanced", nil) stringByAppendingEllipsis]];
}
- (void)windowWillClose:(id)sender
{
[super windowWillClose:sender];
[sharedGuestAccountWindowController autorelease]; sharedGuestAccountWindowController = nil;
}
- (AIService *)service
{
return [[popUp_service selectedItem] representedObject];
}
- (NSString *)UID
{
NSString *UID = [textField_name stringValue];
//Use the default user name if possible, if no UID is specified
if (!UID || ![UID length]) UID = [self.service defaultUserName];
return UID;
}
- (AIAccount *)account
{
if (!account) {
account = [[adium.accountController createAccountWithService:self.service
UID:self.UID] retain];
} else {
if ((self.service != account.service) ||
(![self.UID isEqualToString:account.UID])) {
[account release];
account = [[adium.accountController createAccountWithService:self.service
UID:self.UID] retain];
}
}
return account;
}
- (void)selectServiceType:(id)sender
{
AIService *service = self.service;
[label_name setStringValue:[[service userNameLabel] stringByAppendingString:AILocalizedString(@":", "Colon which will be appended after a label such as 'User Name', before an input field")]];
[textField_name setFormatter:
[AIStringFormatter stringFormatterAllowingCharacters:[service allowedCharactersForAccountName]
length:[service allowedLengthForAccountName]
caseSensitive:[service caseSensitive]
errorMessage:AILocalizedString(@"The characters you're entering are not valid for an account name on this service.", nil)]];
NSString *placeholder = [service defaultUserName];
if (!placeholder || ![placeholder length]) placeholder = [service UIDPlaceholder];
[[textField_name cell] setPlaceholderString:(placeholder ? placeholder : @"")];
}
- (IBAction)okay:(id)sender
{
AIAccount *theAccount = self.account;
[theAccount setIsTemporary:YES];
[adium.accountController addAccount:theAccount];
[theAccount setPasswordTemporarily:[textField_password stringValue]];
//Connect the account
[theAccount setPreference:[NSNumber numberWithBool:YES] forKey:@"Online" group:GROUP_ACCOUNT_STATUS];
[[self window] performClose:nil];
}
- (IBAction)displayAdvanced:(id)sender
{
[AIEditAccountWindowController editAccount:self.account
onWindow:[self window]
notifyingTarget:self];
}
- (void)editAccountSheetDidEndForAccount:(AIAccount *)inAccount withSuccess:(BOOL)inSuccess
{
//If the AIEditAccountWindowController changes the account object, update to follow suit
if (inAccount != account) {
[account release];
account = [inAccount retain];
}
//Make sure our UID is still accurate
if (![inAccount.UID isEqualToString:self.UID]) {
[textField_name setStringValue:inAccount.UID];
}
}
@end
|