2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
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.
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.
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.
19 #import "AIAccountController.h"
21 #import <Adium/AIContactControllerProtocol.h>
22 #import <Adium/AIContentControllerProtocol.h>
23 #import <Adium/AILoginControllerProtocol.h>
24 #import <Adium/AIPreferenceControllerProtocol.h>
25 #import "AIStatusController.h"
26 #import <AIUtilities/AIDictionaryAdditions.h>
27 #import <AIUtilities/AIMenuAdditions.h>
28 #import <AIUtilities/AIObjectAdditions.h>
29 #import <AIUtilities/AIImageAdditions.h>
30 #import <Adium/AIAccount.h>
31 #import <Adium/AIChat.h>
32 #import <Adium/AIContentMessage.h>
33 #import <Adium/AIContentObject.h>
34 #import <Adium/AIListContact.h>
35 #import <Adium/AIListObject.h>
36 #import <Adium/AIMetaContact.h>
37 #import <Adium/AIService.h>
38 #import <Adium/AIServiceIcons.h>
39 #import <Adium/AIStatusIcons.h>
40 #import "AdiumServices.h"
41 #import "AdiumPasswords.h"
42 #import "AdiumAccounts.h"
43 #import "AdiumPreferredAccounts.h"
45 #define ACCOUNT_DEFAULT_PREFS @"AccountPrefs"
47 @implementation AIAccountController
52 if ((self = [super init])) {
53 adiumServices = [[AdiumServices alloc] init];
54 adiumPasswords = [[AdiumPasswords alloc] init];
55 adiumAccounts = [[AdiumAccounts alloc] init];
56 adiumPreferredAccounts = [[AdiumPreferredAccounts alloc] init];
62 //Finish initialization once other controllers have set themselves up
63 - (void)controllerDidLoad
65 //Default account preferences
66 [[adium preferenceController] registerDefaults:[NSDictionary dictionaryNamed:ACCOUNT_DEFAULT_PREFS forClass:[self class]]
67 forGroup:PREF_GROUP_ACCOUNTS];
69 //Finish prepping the accounts
70 [adiumAccounts controllerDidLoad];
74 - (void)controllerWillClose
76 //Disconnect all accounts
77 [self disconnectAllAccounts];
82 [adiumServices release];
83 [adiumPasswords release];
84 [adiumAccounts release];
85 [adiumPreferredAccounts release];
92 - (void)registerService:(AIService *)inService {
93 [adiumServices registerService:inService];
95 - (NSArray *)services {
96 return [adiumServices services];
98 - (NSSet *)activeServicesIncludingCompatibleServices:(BOOL)includeCompatible {
99 return [adiumServices activeServicesIncludingCompatibleServices:includeCompatible];
101 - (AIService *)serviceWithUniqueID:(NSString *)uniqueID {
102 return [adiumServices serviceWithUniqueID:uniqueID];
104 - (AIService *)firstServiceWithServiceID:(NSString *)serviceID {
105 return [adiumServices firstServiceWithServiceID:serviceID];
109 #pragma mark Passwords
110 - (void)setPassword:(NSString *)inPassword forAccount:(AIAccount *)inAccount {
111 [adiumPasswords setPassword:inPassword forAccount:inAccount];
113 - (void)forgetPasswordForAccount:(AIAccount *)inAccount {
114 [adiumPasswords forgetPasswordForAccount:inAccount];
116 - (NSString *)passwordForAccount:(AIAccount *)inAccount {
117 return [adiumPasswords passwordForAccount:inAccount];
119 - (void)passwordForAccount:(AIAccount *)inAccount notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext {
120 [adiumPasswords passwordForAccount:inAccount notifyingTarget:inTarget selector:inSelector context:inContext];
122 - (void)setPassword:(NSString *)inPassword forProxyServer:(NSString *)server userName:(NSString *)userName {
123 [adiumPasswords setPassword:inPassword forProxyServer:server userName:userName];
125 - (NSString *)passwordForProxyServer:(NSString *)server userName:(NSString *)userName {
126 return [adiumPasswords passwordForProxyServer:server userName:userName];
128 - (void)passwordForProxyServer:(NSString *)server userName:(NSString *)userName notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext {
129 [adiumPasswords passwordForProxyServer:server userName:userName notifyingTarget:inTarget selector:inSelector context:inContext];
133 #pragma mark Accounts
134 - (NSArray *)accounts {
135 return [adiumAccounts accounts];
137 - (NSArray *)accountsCompatibleWithService:(AIService *)service {
138 return [adiumAccounts accountsCompatibleWithService:service];
140 - (AIAccount *)accountWithInternalObjectID:(NSString *)objectID {
141 return [adiumAccounts accountWithInternalObjectID:objectID];
143 - (AIAccount *)createAccountWithService:(AIService *)service UID:(NSString *)inUID {
144 return [adiumAccounts createAccountWithService:service UID:inUID];
146 - (void)addAccount:(AIAccount *)inAccount {
147 [adiumAccounts addAccount:inAccount];
149 - (void)deleteAccount:(AIAccount *)inAccount {
150 [adiumAccounts deleteAccount:inAccount];
152 - (int)moveAccount:(AIAccount *)account toIndex:(int)destIndex {
153 return [adiumAccounts moveAccount:account toIndex:destIndex];
155 - (void)accountDidChangeUID:(AIAccount *)inAccount {
156 [adiumAccounts accountDidChangeUID:inAccount];
160 #pragma mark Preferred Accounts
161 - (AIAccount *)preferredAccountForSendingContentType:(NSString *)inType toContact:(AIListContact *)inContact {
162 return [adiumPreferredAccounts preferredAccountForSendingContentType:inType toContact:inContact];
164 - (AIAccount *)preferredAccountForSendingContentType:(NSString *)inType toContact:(AIListContact *)inContact includeOffline:(BOOL)includeOffline {
165 return [adiumPreferredAccounts preferredAccountForSendingContentType:inType toContact:inContact includeOffline:includeOffline];
167 - (AIAccount *)firstAccountAvailableForSendingContentType:(NSString *)inType toContact:(AIListContact *)inContact includeOffline:(BOOL)includeOffline {
168 return [adiumPreferredAccounts firstAccountAvailableForSendingContentType:inType toContact:inContact includeOffline:includeOffline];
171 - (void)disconnectAllAccounts
173 NSEnumerator *enumerator;
176 enumerator = [[self accounts] objectEnumerator];
177 while ((account = [enumerator nextObject])) {
178 if ([account online])
179 [account disconnect];
183 //XXX - Re-evaluate this method and its presence in the core
184 - (BOOL)oneOrMoreConnectedAccounts
186 NSEnumerator *enumerator;
189 enumerator = [[self accounts] objectEnumerator];
190 while ((account = [enumerator nextObject])) {
191 if ([account online]) {
199 //XXX - Re-evaluate this method and its presence in the core
200 - (BOOL)oneOrMoreConnectedOrConnectingAccounts
202 NSEnumerator *enumerator;
205 enumerator = [[self accounts] objectEnumerator];
206 while ((account = [enumerator nextObject])) {
207 if ([account online] || [account integerStatusObjectForKey:@"Connecting"]) {
217 @implementation AIAccountController (AIAccountControllerObjectSpecifier)
218 - (NSScriptObjectSpecifier *) objectSpecifier {
219 id classDescription = [NSClassDescription classDescriptionForClass:[NSApplication class]];
220 NSScriptObjectSpecifier *container = [[NSApplication sharedApplication] objectSpecifier];
221 return [[[NSPropertySpecifier alloc] initWithContainerClassDescription:classDescription containerSpecifier:container key:@"accountController"] autorelease];