We need a b8 before we can release since we've had some significant changes since...
[adiumx.git] / Source / AIApplication.m
bloba0378ba20a41aaede3e3d7be6c39c522e24df715
1 //
2 //  AIApplication.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 7/6/06.
6 //
8 #import "AIApplication.h"
9 #import <Adium/AIObject.h>
10 #import <Adium/AIDockControllerProtocol.h>
11 #import <Adium/AIAdiumProtocol.h>
12 #import "AIMessageWindow.h"
13 #import "AIAccountControllerProtocol.h"
14 #import "AIUtilities/AIArrayAdditions.h"
15 #import "AIInterfaceControllerProtocol.h"
16 #import "AIStatus.h"
17 #import "AIStatusGroup.h"
18 #import "AIStatusControllerProtocol.h"
19 #import "AIChatControllerProtocol.h"
20 #import "AIContactControllerProtocol.h"
22 @implementation AIApplication
23 /*!
24  * @brief Intercept applicationIconImage so we can return a base application icon
25  *
26  * The base application icon doesn't have any badges, labels, or animation states.
27  */
28 - (NSImage *)applicationIconImage
30         NSImage *applicationIconImage = [[[AIObject sharedAdiumInstance] dockController] baseApplicationIconImage];
32         return (applicationIconImage ? applicationIconImage : [super applicationIconImage]);
35 - (NSArray *)services
37         return [[[AIObject sharedAdiumInstance] accountController] services];
40 - (NSArray *)orderedWindows
42         //build a list of the windows, in order
43         return [super windows];
46 - (void)setOrderedWindows:(NSArray *)ow
48         //for some reason, when I call make new window at end, this method is called
49         NSLog(@"setOrderedWindows: %@\n%@",[self orderedWindows],ow);
50         [[NSScriptCommand currentCommand] setScriptErrorNumber:errOSACantAssign];
51         [[NSScriptCommand currentCommand] setScriptErrorString:@"Can't create window. At least, not like that."];
54 - (void)insertInOrderedWindows:(NSWindow *)w
56         [[NSScriptCommand currentCommand] setScriptErrorNumber:errOSACantAssign];
57         [[NSScriptCommand currentCommand] setScriptErrorString:@"Can't create window. At least, not like that."];
59 - (void)insertObject:(NSWindow *)w inOrderedWindowsAtIndex:(unsigned int)index
61         [[NSScriptCommand currentCommand] setScriptErrorNumber:errOSACantAssign];
62         [[NSScriptCommand currentCommand] setScriptErrorString:@"Can't create window. At least, not like that."];
64 - (NSArray *)chatWindows
66         NSArray *windows = [self orderedWindows];
67         NSMutableArray *chatWindows = [[[NSMutableArray alloc] init] autorelease];
68         for (int i=0;i<[windows count];i++)
69                 if ([[windows objectAtIndex:i] isKindOfClass:[AIMessageWindow class]])
70                         [chatWindows addObject:[windows objectAtIndex:i]];
71         return chatWindows;
73 - (NSArray *)chats
75         return [[[[AIObject sharedAdiumInstance] chatController] openChats] allObjects];
77 - (NSArray *)accounts
79         return [[[AIObject sharedAdiumInstance] accountController] accounts];
81 - (NSArray *)contacts
83         return [[[AIObject sharedAdiumInstance] contactController] allContacts];
85 - (NSArray *)statuses
87         return [[[[AIObject sharedAdiumInstance] statusController] flatStatusSet] allObjects];
90 - (void)setIsActive:(BOOL)val
92         [[NSScriptCommand currentCommand] setScriptErrorNumber:errOSACantAssign];
94 - (void)scriptingGoOnline:(NSScriptCommand *)c
96         //tell every account to go online
97         [[self accounts] makeObjectsPerformSelector:@selector(scriptingGoOnline:) withObject:c];
99 - (void)scriptingGoAvailable:(NSScriptCommand *)c
101         //tell every account to go available
102         [[self accounts] makeObjectsPerformSelector:@selector(scriptingGoAvailable:) withObject:c];
104 - (void)scriptingGoOffline:(NSScriptCommand *)c
106         //tell every account to go offline
107         [[self accounts] makeObjectsPerformSelector:@selector(scriptingGoOffline:) withObject:c];
109 - (void)scriptingGoAway:(NSScriptCommand *)c
111         //tell every account to go away
112         [[self accounts] makeObjectsPerformSelector:@selector(scriptingGoAway:) withObject:c];
114 - (void)scriptingGoInvisible:(NSScriptCommand *)c
116         //tell every account to go invisible
117         [[self accounts] makeObjectsPerformSelector:@selector(scriptingGoInvisible:) withObject:c];
120  * @brief Returns the active chat.
121  * In actuality, this returns the most recently active chat, which will return a chat even if all chat windows are closed.
122  * For some reason [AIInterfaceController activeChat] doesn't work like I would have expected it to.
123  */
124 - (AIChat *)activeChat
126         return [[[AIObject sharedAdiumInstance] interfaceController] mostRecentActiveChat];
129 #pragma mark Status
131 - (id)makeStatusWithProperties:(NSDictionary *)keyDictionary
133         //ready the arguments!
134         AIStatusTypeApplescript type;
135         NSDictionary *properties = [keyDictionary objectForKey:@"KeyDictionary"];
136         if (!properties || ![properties objectForKey:@"statusTypeApplescript"])
137                 type = AIAvailableStatusTypeAS;
138         else
139                 type = [[properties objectForKey:@"statusTypeApplescript"] unsignedIntValue];
140         
141         AIStatusType realType;
142         switch (type) {
143                 case AIAvailableStatusTypeAS:
144                         realType = AIAvailableStatusType;
145                         break;
146                 case AIAwayStatusTypeAS:
147                         realType = AIAwayStatusType;
148                         break;
149                 case AIInvisibleStatusTypeAS:
150                         realType = AIInvisibleStatusType;
151                         break;
152                 case AIOfflineStatusTypeAS:
153                 default:
154                         realType = AIOfflineStatusType;
155                         break;
156         }
157         
158         AIStatus *status = [AIStatus statusOfType:realType];
159         if ([properties objectForKey:@"scriptingTitle"])
160                 [status setTitle:[properties objectForKey:@"scriptingTitle"]];
161         if ([properties objectForKey:@"scriptingMessage"]) {
162                 if ([[properties objectForKey:@"scriptingMessage"] isKindOfClass:[NSString class]])
163                         [status setStatusMessageString:[properties objectForKey:@"scriptingMessage"]];
164                 else
165                         [status setStatusMessage:[properties objectForKey:@"scriptingMessage"]];
166         }
167         if ([properties objectForKey:@"scriptingAutoreply"]) {
168                 if ([[properties objectForKey:@"scriptingAutoreply"] isKindOfClass:[NSString class]])
169                         [status setAutoReplyString:[properties objectForKey:@"scriptingAutoreply"]];
170                 else
171                         [status setAutoReply:[properties objectForKey:@"scriptingAutoreply"]];
172         }
173         
174         if ([keyDictionary objectForKey:@"Location"]) {
175                 NSPositionalSpecifier *location = [keyDictionary objectForKey:@"Location"];
176                 unsigned int index = [location insertionIndex];
177                 [[[[AIObject sharedAdiumInstance] statusController] rootStateGroup] addStatusItem:status atIndex:index];
178         } else {
179                 [[[AIObject sharedAdiumInstance] statusController] addStatusState:status];
180         }
181         
182         return status;
184 - (void)insertObject:(AIStatus *)status inStatusesAtIndex:(unsigned int)i
186         [self insertInStatuses:status atIndex:i];
188 - (void)removeObjectFromStatusesAtIndex:(unsigned int)i
190         [self removeFromStatusesAtIndex:i];
192 - (void)replaceObjectInStatusesAtIndex:(unsigned int)i withObject:(AIStatus *)status
194         [self replaceInStatuses:status atIndex:i];
196 - (void)insertInStatuses:(AIStatus *)status
198         [[[AIObject sharedAdiumInstance] statusController] addStatusState:status];
200 - (void)insertInStatuses:(AIStatus *)status atIndex:(unsigned int)i
202         [[[[AIObject sharedAdiumInstance] statusController] rootStateGroup] addStatusItem:status atIndex:i];
204 - (void)removeFromStatusesAtIndex:(unsigned int)i
206         [[[[AIObject sharedAdiumInstance] statusController] rootStateGroup] removeStatusItem:[[self statuses] objectAtIndex:i]];
208 - (void)replaceInStatuses:(AIStatus *)status atIndex:(unsigned int)i
210         NSLog(@"%s NOT IMPLEMENTED",__PRETTY_FUNCTION__);
212 - (AIStatus *)valueInStatusesWithUniqueID:(id)uniqueID
214         return [[[AIObject sharedAdiumInstance] statusController] statusStateWithUniqueStatusID:uniqueID];
217 - (NSObject<AIAdium> *)adium
219         return [AIObject sharedAdiumInstance];
222 @end