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"
44 #import "AIEditAccountWindowController.h"
46 #define ACCOUNT_DEFAULT_PREFS @"AccountPrefs"
48 @implementation AIAccountController
53 if ((self = [super init])) {
54 adiumServices = [[AdiumServices alloc] init];
55 adiumPasswords = [[AdiumPasswords alloc] init];
56 adiumAccounts = [[AdiumAccounts alloc] init];
57 adiumPreferredAccounts = [[AdiumPreferredAccounts alloc] init];
63 //Finish initialization once other controllers have set themselves up
64 - (void)controllerDidLoad
66 //Default account preferences
67 [[adium preferenceController] registerDefaults:[NSDictionary dictionaryNamed:ACCOUNT_DEFAULT_PREFS forClass:[self class]]
68 forGroup:PREF_GROUP_ACCOUNTS];
70 //Finish prepping the accounts
71 [adiumAccounts controllerDidLoad];
73 [adiumPasswords controllerDidLoad];
77 - (void)controllerWillClose
79 //Disconnect all accounts
80 [self disconnectAllAccounts];
85 [adiumServices release];
86 [adiumPasswords release];
87 [adiumAccounts release];
88 [adiumPreferredAccounts release];
95 - (void)registerService:(AIService *)inService {
96 [adiumServices registerService:inService];
98 - (NSArray *)services {
99 return [adiumServices services];
101 - (NSSet *)activeServicesIncludingCompatibleServices:(BOOL)includeCompatible {
102 return [adiumServices activeServicesIncludingCompatibleServices:includeCompatible];
104 - (AIService *)serviceWithUniqueID:(NSString *)uniqueID {
105 return [adiumServices serviceWithUniqueID:uniqueID];
107 - (AIService *)firstServiceWithServiceID:(NSString *)serviceID {
108 return [adiumServices firstServiceWithServiceID:serviceID];
112 #pragma mark Passwords
113 - (void)setPassword:(NSString *)inPassword forAccount:(AIAccount *)inAccount {
114 [adiumPasswords setPassword:inPassword forAccount:inAccount];
116 - (void)forgetPasswordForAccount:(AIAccount *)inAccount {
117 [adiumPasswords forgetPasswordForAccount:inAccount];
119 - (NSString *)passwordForAccount:(AIAccount *)inAccount {
120 return [adiumPasswords passwordForAccount:inAccount];
122 - (void)passwordForAccount:(AIAccount *)inAccount promptOption:(AIPromptOption)promptOption notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext {
123 [adiumPasswords passwordForAccount:inAccount promptOption:promptOption notifyingTarget:inTarget selector:inSelector context:inContext];
125 - (void)setPassword:(NSString *)inPassword forProxyServer:(NSString *)server userName:(NSString *)userName {
126 [adiumPasswords setPassword:inPassword forProxyServer:server userName:userName];
128 - (NSString *)passwordForProxyServer:(NSString *)server userName:(NSString *)userName {
129 return [adiumPasswords passwordForProxyServer:server userName:userName];
131 - (void)passwordForProxyServer:(NSString *)server userName:(NSString *)userName notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext {
132 [adiumPasswords passwordForProxyServer:server userName:userName notifyingTarget:inTarget selector:inSelector context:inContext];
136 #pragma mark Accounts
137 - (NSArray *)accounts {
138 return [adiumAccounts accounts];
140 - (NSArray *)accountsCompatibleWithService:(AIService *)service {
141 return [adiumAccounts accountsCompatibleWithService:service];
144 @brief Returns a list of accounts with a given status.
145 This method returns a list of account that all share some specific status object. It
146 was created so that status objects of AppleScript might know who was using them, and
147 could dynamically change its properties. As it uses NSPredicate, it only works in 10.4
150 - (NSArray *)accountsWithCurrentStatus:(AIStatus *)status {
151 return [[self accounts] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"status == %@", status]];
153 - (AIAccount *)accountWithInternalObjectID:(NSString *)objectID {
154 return [adiumAccounts accountWithInternalObjectID:objectID];
156 - (AIAccount *)createAccountWithService:(AIService *)service UID:(NSString *)inUID {
157 return [adiumAccounts createAccountWithService:service UID:inUID];
159 - (void)addAccount:(AIAccount *)inAccount {
160 [adiumAccounts addAccount:inAccount];
162 - (id<AIAccountControllerRemoveConfirmationDialog>)deleteAccount:(AIAccount *)inAccount {
163 return [inAccount confirmationDialogForAccountDeletionForAccountsList:adiumAccounts];
165 - (int)moveAccount:(AIAccount *)account toIndex:(int)destIndex {
166 return [adiumAccounts moveAccount:account toIndex:destIndex];
168 - (void)accountDidChangeUID:(AIAccount *)inAccount {
169 [adiumAccounts accountDidChangeUID:inAccount];
173 #pragma mark Preferred Accounts
174 - (AIAccount *)preferredAccountForSendingContentType:(NSString *)inType toContact:(AIListContact *)inContact {
175 return [adiumPreferredAccounts preferredAccountForSendingContentType:inType toContact:inContact];
177 - (AIAccount *)preferredAccountForSendingContentType:(NSString *)inType toContact:(AIListContact *)inContact includeOffline:(BOOL)includeOffline {
178 return [adiumPreferredAccounts preferredAccountForSendingContentType:inType toContact:inContact includeOffline:includeOffline];
180 - (AIAccount *)firstAccountAvailableForSendingContentType:(NSString *)inType toContact:(AIListContact *)inContact includeOffline:(BOOL)includeOffline {
181 return [adiumPreferredAccounts firstAccountAvailableForSendingContentType:inType toContact:inContact includeOffline:includeOffline];
184 - (void)disconnectAllAccounts
186 NSEnumerator *enumerator;
189 enumerator = [[self accounts] objectEnumerator];
190 while ((account = [enumerator nextObject])) {
191 if ([account online])
192 [account disconnect];
196 //XXX - Re-evaluate this method and its presence in the core
197 - (BOOL)oneOrMoreConnectedAccounts
199 NSEnumerator *enumerator;
202 enumerator = [[self accounts] objectEnumerator];
203 while ((account = [enumerator nextObject])) {
204 if ([account online]) {
212 //XXX - Re-evaluate this method and its presence in the core
213 - (BOOL)oneOrMoreConnectedOrConnectingAccounts
215 NSEnumerator *enumerator;
218 enumerator = [[self accounts] objectEnumerator];
219 while ((account = [enumerator nextObject])) {
220 if ([account online] || [account integerStatusObjectForKey:@"Connecting"] || [account statusObjectForKey:@"Waiting to Reconnect"]) {
229 - (void)editAccount:(AIAccount *)account onWindow:(NSWindow *)window notifyingTarget:(id)target
231 [AIEditAccountWindowController editAccount:account
233 notifyingTarget:target];
238 @implementation AIAccountController (AIAccountControllerObjectSpecifier)
239 - (NSScriptObjectSpecifier *) objectSpecifier {
240 id classDescription = [NSClassDescription classDescriptionForClass:[NSApplication class]];
241 NSScriptObjectSpecifier *container = [[NSApplication sharedApplication] objectSpecifier];
242 return [[[NSPropertySpecifier alloc] initWithContainerClassDescription:classDescription containerSpecifier:container key:@"accountController"] autorelease];