Merged [15040]: Trying some magic: 5 seconds after the last unreachable host is repor...
[adiumx.git] / Source / ESApplescriptabilityController.m
blobae8c74e186ddf97407e38e62dba68acbcb95d4d6
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 #import "AIAccountController.h"
18 #import "AIContactController.h"
19 #import "AIContentController.h"
20 #import "AIInterfaceController.h"
21 #import "AIPreferenceController.h"
22 #import "AIStatusController.h"
23 #import "ESApplescriptabilityController.h"
24 #import <AIUtilities/AIAttributedStringAdditions.h>
25 #import <Adium/AIAccount.h>
26 #import <Adium/AIContentMessage.h>
27 #import <Adium/AIHTMLDecoder.h>
29 @implementation ESApplescriptabilityController
31 //init
32 - (void)initController
37 //close
38 - (void)closeController
40         
43 #pragma mark Convenience
44 - (NSArray *)accounts
46         return ([[adium accountController] accountArray]);
48 - (NSArray *)contacts
50         return ([[adium contactController] allContactsInGroup:nil
51                                                                                                 subgroups:YES
52                                                                                                 onAccount:nil]);
54 - (NSArray *)chats
56         return ([[[adium contentController] openChats] allObjects]);
59 #pragma mark Attributes
60 #warning Quite a bit in here is broken and needs to be rewritten for the new status system -eds
61 - (NSTimeInterval)myIdleTime
63         NSDate  *idleSince = [[adium preferenceController] preferenceForKey:@"IdleSince" group:GROUP_ACCOUNT_STATUS];
64         return (-[idleSince timeIntervalSinceNow]);
66 - (void)setMyIdleTime:(NSTimeInterval)timeInterval
68         [[adium notificationCenter] postNotificationName:Adium_RequestSetManualIdleTime 
69                                                                                           object:(timeInterval ? [NSNumber numberWithDouble:timeInterval] : nil)
70                                                                                         userInfo:nil];
73 - (NSData *)defaultImageData
75         return ([[adium preferenceController] preferenceForKey:KEY_USER_ICON 
76                                                                                                          group:GROUP_ACCOUNT_STATUS]);
77                         
79 - (void)setDefaultImageData:(NSData *)newDefaultImageData
81         [[adium preferenceController] setPreference:newDefaultImageData
82                                                                                  forKey:KEY_USER_ICON 
83                                                                                   group:GROUP_ACCOUNT_STATUS];  
86 - (AIStatus *)myStatus
88         return [[adium statusController] activeStatusState];
91 //Incomplete - make AIStatus scriptable, pass that in
92 - (void)setMyStatus:(AIStatus *)newStatus
94         [[adium statusController] setActiveStatusState:newStatus];
97 - (AIStatusTypeApplescript)myStatusTypeApplescript
99         return [[self myStatus] statusTypeApplescript];
100         
103 - (void)setMyStatusTypeApplescript:(AIStatusTypeApplescript)newStatusType
105         AIStatus *newStatus = [[self myStatus] mutableCopy];
106         
107         [newStatus setStatusTypeApplescript:newStatusType];
108         [self setMyStatus:newStatus];
109         
110         [newStatus release];
113 - (NSString *)myStatusMessageString
115         return [[self myStatus] statusMessageString];
118 - (void)setMyStatusMessageString:(NSString *)inString
120         AIStatus *newStatus = [[self myStatus] mutableCopy];
121         
122         [newStatus setStatusMessageString:inString];
123         [self setMyStatus:newStatus];
124         
125         [newStatus release];    
128 #pragma mark Controller convenience
129 - (AIInterfaceController *)interfaceController{
130     return([adium interfaceController]);
134 - (AIChat *)createChatCommand:(NSScriptCommand *)command 
136         NSDictionary    *evaluatedArguments = [command evaluatedArguments];
137         NSString                *UID = [evaluatedArguments objectForKey:@"UID"];
138         NSString                *serviceID = [evaluatedArguments objectForKey:@"serviceID"];
139         AIListContact   *contact;
140         AIChat                  *chat = nil;
142         contact = [[adium contactController] preferredContactWithUID:UID
143                                                                                                         andServiceID:serviceID 
144                                                                                    forSendingContentType:CONTENT_MESSAGE_TYPE];
146         if(contact){
147                 //Open the chat and set it as active
148                 chat = [[adium contentController] openChatWithContact:contact];
149                 [[adium interfaceController] setActiveChat:chat];
150         }
151         
152         return chat;
154 @end