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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | /*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// $Id$
#import "AIAccountController.h"
#import <Adium/AIContactControllerProtocol.h>
#import <Adium/AIContentControllerProtocol.h>
#import <Adium/AILoginControllerProtocol.h>
#import "AIStatusController.h"
#import <AIUtilities/AIDictionaryAdditions.h>
#import <AIUtilities/AIMenuAdditions.h>
#import <AIUtilities/AIObjectAdditions.h>
#import <AIUtilities/AIImageAdditions.h>
#import <Adium/AIAccount.h>
#import <Adium/AIChat.h>
#import <Adium/AIContentMessage.h>
#import <Adium/AIContentObject.h>
#import <Adium/AIListContact.h>
#import <Adium/AIListObject.h>
#import <Adium/AIMetaContact.h>
#import <Adium/AIService.h>
#import <Adium/AIServiceIcons.h>
#import <Adium/AIStatusIcons.h>
#import "AdiumServices.h"
#import "AdiumPasswords.h"
#import "AdiumAccounts.h"
#import "AdiumPreferredAccounts.h"
#import "AIEditAccountWindowController.h"
#define ACCOUNT_DEFAULT_PREFS @"AccountPrefs"
@implementation AIAccountController
//init
- (id)init
{
if ((self = [super init])) {
adiumServices = [[AdiumServices alloc] init];
adiumPasswords = [[AdiumPasswords alloc] init];
adiumAccounts = [[AdiumAccounts alloc] init];
adiumPreferredAccounts = [[AdiumPreferredAccounts alloc] init];
}
return self;
}
//Finish initialization once other controllers have set themselves up
- (void)controllerDidLoad
{
//Default account preferences
[adium.preferenceController registerDefaults:[NSDictionary dictionaryNamed:ACCOUNT_DEFAULT_PREFS forClass:[self class]]
forGroup:PREF_GROUP_ACCOUNTS];
//Finish prepping the accounts
[adiumAccounts controllerDidLoad];
[adiumPasswords controllerDidLoad];
}
//close
- (void)controllerWillClose
{
//Disconnect all accounts
[self disconnectAllAccounts];
}
- (void)dealloc
{
[adiumServices release];
[adiumPasswords release];
[adiumAccounts release];
[adiumPreferredAccounts release];
[super dealloc];
}
//Services
#pragma mark Services
- (void)registerService:(AIService *)inService {
[adiumServices registerService:inService];
}
- (NSArray *)services {
return [adiumServices services];
}
- (NSSet *)activeServicesIncludingCompatibleServices:(BOOL)includeCompatible {
return [adiumServices activeServicesIncludingCompatibleServices:includeCompatible];
}
- (AIService *)serviceWithUniqueID:(NSString *)uniqueID {
return [adiumServices serviceWithUniqueID:uniqueID];
}
- (AIService *)firstServiceWithServiceID:(NSString *)serviceID {
return [adiumServices firstServiceWithServiceID:serviceID];
}
//Passwords
#pragma mark Passwords
- (void)setPassword:(NSString *)inPassword forAccount:(AIAccount *)inAccount {
[adiumPasswords setPassword:inPassword forAccount:inAccount];
}
- (void)forgetPasswordForAccount:(AIAccount *)inAccount {
[adiumPasswords forgetPasswordForAccount:inAccount];
}
- (NSString *)passwordForAccount:(AIAccount *)inAccount {
return [adiumPasswords passwordForAccount:inAccount];
}
- (void)passwordForAccount:(AIAccount *)inAccount promptOption:(AIPromptOption)promptOption notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext {
[adiumPasswords passwordForAccount:inAccount promptOption:promptOption notifyingTarget:inTarget selector:inSelector context:inContext];
}
- (void)setPassword:(NSString *)inPassword forProxyServer:(NSString *)server userName:(NSString *)userName {
[adiumPasswords setPassword:inPassword forProxyServer:server userName:userName];
}
- (NSString *)passwordForProxyServer:(NSString *)server userName:(NSString *)userName {
return [adiumPasswords passwordForProxyServer:server userName:userName];
}
- (void)passwordForProxyServer:(NSString *)server userName:(NSString *)userName notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext {
[adiumPasswords passwordForProxyServer:server userName:userName notifyingTarget:inTarget selector:inSelector context:inContext];
}
- (void)passwordForType:(AISpecialPasswordType)inType forAccount:(AIAccount *)inAccount promptOption:(AIPromptOption)inOption name:(NSString *)inName notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext {
[adiumPasswords passwordForType:inType forAccount:inAccount promptOption:inOption name:inName notifyingTarget:inTarget selector:inSelector context:inContext];
}
- (NSString *)passwordForType:(AISpecialPasswordType)inType forAccount:(AIAccount *)inAccount name:(NSString *)inName {
return [adiumPasswords passwordForType:inType forAccount:inAccount name:inName];
}
- (void)setPassword:(NSString *)inPassword forType:(AISpecialPasswordType)inType forAccount:(AIAccount *)inAccount name:(NSString *)inName {
[adiumPasswords setPassword:inPassword forType:inType forAccount:inAccount name:inName];
}
//Accounts
#pragma mark Accounts
- (NSArray *)accounts {
return [adiumAccounts accounts];
}
- (NSArray *)accountsCompatibleWithService:(AIService *)service {
return [adiumAccounts accountsCompatibleWithService:service];
}
/**
@brief Returns a list of accounts with a given status.
This method returns a list of account that all share some specific AIStatus object. It
was created so that AppleScript's statuses might know who was using them, and
could dynamically change its properties. As it uses NSPredicate, it only works in 10.4
and above.
*/
- (NSArray *)accountsWithCurrentStatus:(AIStatus *)status {
return [[self accounts] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"status == %@", status]];
}
- (AIAccount *)accountWithInternalObjectID:(NSString *)objectID {
return [adiumAccounts accountWithInternalObjectID:objectID];
}
- (AIAccount *)createAccountWithService:(AIService *)service UID:(NSString *)inUID {
return [adiumAccounts createAccountWithService:service UID:inUID];
}
- (void)addAccount:(AIAccount *)inAccount {
[adiumAccounts addAccount:inAccount];
}
- (void)deleteAccount:(AIAccount *)inAccount {
[adiumAccounts deleteAccount:inAccount];
}
- (NSUInteger)moveAccount:(AIAccount *)account toIndex:(NSUInteger)destIndex {
return [adiumAccounts moveAccount:account toIndex:destIndex];
}
- (void)accountDidChangeUID:(AIAccount *)inAccount {
[adiumAccounts accountDidChangeUID:inAccount];
}
//Preferred Accounts
#pragma mark Preferred Accounts
- (AIAccount *)preferredAccountForSendingContentType:(NSString *)inType toContact:(AIListContact *)inContact {
AIAccount *account = [adiumPreferredAccounts preferredAccountForSendingContentType:inType toContact:inContact];
NSAssert([account.service.serviceClass isEqualToString:inContact.service.serviceClass], @"Wrong account for the contact; differing services.");
return account;
}
- (void)disconnectAllAccounts
{
for (AIAccount *account in self.accounts) {
if (account.online)
[account disconnect];
}
}
//XXX - Re-evaluate this method and its presence in the core
- (BOOL)oneOrMoreConnectedAccounts
{
for (AIAccount *account in self.accounts) {
if (account.online) {
return YES;
}
}
return NO;
}
//XXX - Re-evaluate this method and its presence in the core
- (BOOL)oneOrMoreConnectedOrConnectingAccounts
{
for (AIAccount *account in self.accounts) {
if (account.online || [account boolValueForProperty:@"Connecting"] || [account valueForProperty:@"Waiting to Reconnect"]) {
return YES;
}
}
return NO;
}
#pragma mark Editing
- (void)editAccount:(AIAccount *)account onWindow:(NSWindow *)window notifyingTarget:(id)target
{
[AIEditAccountWindowController editAccount:account
onWindow:window
notifyingTarget:target];
}
@end
@implementation AIAccountController (AIAccountControllerObjectSpecifier)
- (NSScriptObjectSpecifier *) objectSpecifier {
id classDescription = [NSClassDescription classDescriptionForClass:[NSApplication class]];
NSScriptObjectSpecifier *container = [[NSApplication sharedApplication] objectSpecifier];
return [[[NSPropertySpecifier alloc] initWithContainerClassDescription:classDescription containerSpecifier:container key:@"accountController"] autorelease];
}
@end
|