Fixed line width in the messages advanced prefs
[adiumx.git] / Source / AIAccountController.m
blob3ebf7f3b3b29319cc70028e166bae805f88ded6b
1 /* 
2  * Adium is the legal property of its developers, whose names are listed in the copyright file included
3  * with this source distribution.
4  * 
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.
8  * 
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.
12  * 
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.
15  */
17 // $Id$
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
50 //init
51 - (id)init
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];
58         }
59         
60         return self;
63 //Finish initialization once other controllers have set themselves up
64 - (void)controllerDidLoad
65 {   
66         //Default account preferences
67         [[adium preferenceController] registerDefaults:[NSDictionary dictionaryNamed:ACCOUNT_DEFAULT_PREFS forClass:[self class]]
68                                                                                   forGroup:PREF_GROUP_ACCOUNTS];
69         
70         //Finish prepping the accounts
71         [adiumAccounts controllerDidLoad];
74 //close
75 - (void)controllerWillClose
77     //Disconnect all accounts
78     [self disconnectAllAccounts];
81 - (void)dealloc
83         [adiumServices release];
84         [adiumPasswords release];
85         [adiumAccounts release];
86         [adiumPreferredAccounts release];
88         [super dealloc];
91 //Services
92 #pragma mark Services
93 - (void)registerService:(AIService *)inService {
94         [adiumServices registerService:inService];
96 - (NSArray *)services {
97         return [adiumServices services];
99 - (NSSet *)activeServicesIncludingCompatibleServices:(BOOL)includeCompatible {
100         return [adiumServices activeServicesIncludingCompatibleServices:includeCompatible];
102 - (AIService *)serviceWithUniqueID:(NSString *)uniqueID {
103         return [adiumServices serviceWithUniqueID:uniqueID];
105 - (AIService *)firstServiceWithServiceID:(NSString *)serviceID {
106         return [adiumServices firstServiceWithServiceID:serviceID];
109 //Passwords
110 #pragma mark Passwords
111 - (void)setPassword:(NSString *)inPassword forAccount:(AIAccount *)inAccount {
112         [adiumPasswords setPassword:inPassword forAccount:inAccount];
114 - (void)forgetPasswordForAccount:(AIAccount *)inAccount {
115         [adiumPasswords forgetPasswordForAccount:inAccount];
117 - (NSString *)passwordForAccount:(AIAccount *)inAccount {
118         return [adiumPasswords passwordForAccount:inAccount];
120 - (void)passwordForAccount:(AIAccount *)inAccount forcePromptDisplay:(BOOL)forceDisplay notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext {
121         [adiumPasswords passwordForAccount:inAccount forcePromptDisplay:forceDisplay notifyingTarget:inTarget selector:inSelector context:inContext];
123 - (void)setPassword:(NSString *)inPassword forProxyServer:(NSString *)server userName:(NSString *)userName {
124         [adiumPasswords setPassword:inPassword forProxyServer:server userName:userName];
126 - (NSString *)passwordForProxyServer:(NSString *)server userName:(NSString *)userName {
127         return [adiumPasswords passwordForProxyServer:server userName:userName];
129 - (void)passwordForProxyServer:(NSString *)server userName:(NSString *)userName notifyingTarget:(id)inTarget selector:(SEL)inSelector context:(id)inContext {
130         [adiumPasswords passwordForProxyServer:server userName:userName notifyingTarget:inTarget selector:inSelector context:inContext];
133 //Accounts
134 #pragma mark Accounts
135 - (NSArray *)accounts {
136         return [adiumAccounts accounts];
138 - (NSArray *)accountsCompatibleWithService:(AIService *)service {
139         return [adiumAccounts accountsCompatibleWithService:service];
142  @brief Returns a list of accounts with a given status.
143  This method returns a list of account that all share some specific status object. It
144  was created so that status objects of AppleScript might know who was using them, and
145  could dynamically change its properties. As it uses NSPredicate, it only works in 10.4
146  and above.
147  */
148 - (NSArray *)accountsWithCurrentStatus:(AIStatus *)status {
149         return [[self accounts] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"status == %@", status]];
151 - (AIAccount *)accountWithInternalObjectID:(NSString *)objectID {
152         return [adiumAccounts accountWithInternalObjectID:objectID];
154 - (AIAccount *)createAccountWithService:(AIService *)service UID:(NSString *)inUID {
155         return [adiumAccounts createAccountWithService:service UID:inUID];
157 - (void)addAccount:(AIAccount *)inAccount {
158         [adiumAccounts addAccount:inAccount];
160 - (id<AIAccountControllerRemoveConfirmationDialog>)deleteAccount:(AIAccount *)inAccount {
161         return [inAccount confirmationDialogForAccountDeletionForAccountsList:adiumAccounts];
163 - (int)moveAccount:(AIAccount *)account toIndex:(int)destIndex {
164         return [adiumAccounts moveAccount:account toIndex:destIndex];
166 - (void)accountDidChangeUID:(AIAccount *)inAccount {
167         [adiumAccounts accountDidChangeUID:inAccount];
170 //Preferred Accounts
171 #pragma mark Preferred Accounts
172 - (AIAccount *)preferredAccountForSendingContentType:(NSString *)inType toContact:(AIListContact *)inContact {
173         return [adiumPreferredAccounts preferredAccountForSendingContentType:inType toContact:inContact];
175 - (AIAccount *)preferredAccountForSendingContentType:(NSString *)inType toContact:(AIListContact *)inContact includeOffline:(BOOL)includeOffline {
176         return [adiumPreferredAccounts preferredAccountForSendingContentType:inType toContact:inContact includeOffline:includeOffline];
178 - (AIAccount *)firstAccountAvailableForSendingContentType:(NSString *)inType toContact:(AIListContact *)inContact includeOffline:(BOOL)includeOffline {
179         return [adiumPreferredAccounts firstAccountAvailableForSendingContentType:inType toContact:inContact includeOffline:includeOffline];
182 - (void)disconnectAllAccounts
184     NSEnumerator                *enumerator;
185     AIAccount                   *account;
187     enumerator = [[self accounts] objectEnumerator];
188     while ((account = [enumerator nextObject])) {
189         if ([account online]) 
190                         [account disconnect];
191     }
194 //XXX - Re-evaluate this method and its presence in the core
195 - (BOOL)oneOrMoreConnectedAccounts
197         NSEnumerator            *enumerator;
198     AIAccount                   *account;
200     enumerator = [[self accounts] objectEnumerator];
201     while ((account = [enumerator nextObject])) {
202         if ([account online]) {
203                         return YES;
204         }
205     }
206         
207         return NO;
210 //XXX - Re-evaluate this method and its presence in the core
211 - (BOOL)oneOrMoreConnectedOrConnectingAccounts
213         NSEnumerator            *enumerator;
214     AIAccount                   *account;
215         
216     enumerator = [[self accounts] objectEnumerator];
217     while ((account = [enumerator nextObject])) {
218         if ([account online] || [account integerStatusObjectForKey:@"Connecting"] || [account statusObjectForKey:@"Waiting to Reconnect"]) {
219                         return YES;
220         }
221     }   
223         return NO;      
226 #pragma mark Editing
227 - (void)editAccount:(AIAccount *)account onWindow:(NSWindow *)window notifyingTarget:(id)target
229         [AIEditAccountWindowController editAccount:account
230                                                                           onWindow:window
231                                                            notifyingTarget:target];     
234 @end
236 @implementation AIAccountController (AIAccountControllerObjectSpecifier)
237 - (NSScriptObjectSpecifier *) objectSpecifier {
238         id classDescription = [NSClassDescription classDescriptionForClass:[NSApplication class]];
239         NSScriptObjectSpecifier *container = [[NSApplication sharedApplication] objectSpecifier];
240         return [[[NSPropertySpecifier alloc] initWithContainerClassDescription:classDescription containerSpecifier:container key:@"accountController"] autorelease];
242 @end