William Bowling is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this again1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | //
// AIApplication.m
// Adium
//
// Created by Evan Schoenberg on 7/6/06.
//
#import "AIApplication.h"
#import <Adium/AIDockControllerProtocol.h>
#import "AIMessageWindow.h"
#import "AIURLHandlerPlugin.h"
#import "AIAccountControllerProtocol.h"
#import "AIUtilities/AIArrayAdditions.h"
#import "AIInterfaceControllerProtocol.h"
#import "AIStatus.h"
#import "AIStatusGroup.h"
#import "AIStatusControllerProtocol.h"
#import "AIChatControllerProtocol.h"
#import "AIContactControllerProtocol.h"
#import <Adium/AIListContact.h>
#import <Adium/AIListGroup.h>
@implementation AIApplication
/*!
* @brief Intercept applicationIconImage so we can return a base application icon
*
* The base application icon doesn't have any badges, labels, or animation states.
*/
- (NSImage *)applicationIconImage
{
return [adium.dockController baseApplicationIconImage] ?: [super applicationIconImage];
}
- (NSArray *)services
{
return adium.accountController.services;
}
- (NSArray *)orderedWindows
{
//build a list of the windows, in order
return [super windows];
}
- (void)setOrderedWindows:(NSArray *)ow
{
//for some reason, when I call make new window at end, this method is called
NSLog(@"setOrderedWindows: %@\n%@",[self orderedWindows],ow);
[[NSScriptCommand currentCommand] setScriptErrorNumber:errOSACantAssign];
[[NSScriptCommand currentCommand] setScriptErrorString:@"Can't create window. At least, not like that."];
}
- (void)insertInOrderedWindows:(NSWindow *)w
{
[[NSScriptCommand currentCommand] setScriptErrorNumber:errOSACantAssign];
[[NSScriptCommand currentCommand] setScriptErrorString:@"Can't create window. At least, not like that."];
}
- (void)insertObject:(NSWindow *)w inOrderedWindowsAtIndex:(NSUInteger)index
{
[[NSScriptCommand currentCommand] setScriptErrorNumber:errOSACantAssign];
[[NSScriptCommand currentCommand] setScriptErrorString:@"Can't create window. At least, not like that."];
}
- (NSArray *)chatWindows
{
NSArray *windows = [self orderedWindows];
NSMutableArray *chatWindows = [[[NSMutableArray alloc] init] autorelease];
for (NSInteger i=0;i<[windows count];i++)
if ([[windows objectAtIndex:i] isKindOfClass:[AIMessageWindow class]])
[chatWindows addObject:[windows objectAtIndex:i]];
return chatWindows;
}
- (AIMessageWindow *)valueInChatWindowsWithUniqueID:(NSNumber *)uniqueID
{
for (NSWindow *window in [self orderedWindows])
if ([window isKindOfClass:[AIMessageWindow class]])
if ([window hash] == [uniqueID unsignedIntValue])
return (AIMessageWindow *)window;
return nil;
}
- (NSArray *)chats
{
return [adium.chatController.openChats allObjects];
}
- (NSArray *)accounts
{
return adium.accountController.accounts;
}
- (NSArray *)contacts
{
return adium.contactController.allContacts;
}
- (void)insertObject:(AIListObject *)contact inContactsAtIndex:(NSInteger)index
{
//Intentially unimplemented. This should never be called (contacts are created a different way), but is required for KVC-compliance.
}
- (void)removeObjectFromContactsAtIndex:(NSInteger)index
{
AIListObject *object = [self.contacts objectAtIndex:index];
for (AIListGroup *group in object.groups) {
[object removeFromGroup:group];
}
}
- (NSArray *)statuses
{
return [adium.statusController.flatStatusSet allObjects];
}
- (NSArray *)contactGroups
{
return adium.contactController.allGroups;
}
- (void)setIsActive:(BOOL)val
{
[[NSScriptCommand currentCommand] setScriptErrorNumber:errOSACantAssign];
}
- (void)scriptingGoOnline:(NSScriptCommand *)c
{
//tell every account to go online
[[self accounts] makeObjectsPerformSelector:@selector(scriptingGoOnline:) withObject:c];
}
- (void)scriptingGoAvailable:(NSScriptCommand *)c
{
//tell every account to go available
[[self accounts] makeObjectsPerformSelector:@selector(scriptingGoAvailable:) withObject:c];
}
- (void)scriptingGoOffline:(NSScriptCommand *)c
{
//tell every account to go offline
[[self accounts] makeObjectsPerformSelector:@selector(scriptingGoOffline:) withObject:c];
}
- (void)scriptingGoAway:(NSScriptCommand *)c
{
//tell every account to go away
[[self accounts] makeObjectsPerformSelector:@selector(scriptingGoAway:) withObject:c];
}
- (void)scriptingGoInvisible:(NSScriptCommand *)c
{
//tell every account to go invisible
[[self accounts] makeObjectsPerformSelector:@selector(scriptingGoInvisible:) withObject:c];
}
/**
* @brief Returns the active chat.
* In actuality, this returns the most recently active chat, which will return a chat even if all chat windows are closed.
* For some reason [AIInterfaceController activeChat] doesn't work like I would have expected it to.
*/
- (AIChat *)activeChat
{
return [adium.interfaceController mostRecentActiveChat];
}
#pragma mark Status
- (id)makeStatusWithProperties:(NSDictionary *)keyDictionary
{
//ready the arguments!
AIStatusTypeApplescript type;
NSDictionary *properties = [keyDictionary objectForKey:@"KeyDictionary"];
if (!properties || ![properties objectForKey:@"statusTypeApplescript"])
type = AIAvailableStatusTypeAS;
else
type = [[properties objectForKey:@"statusTypeApplescript"] unsignedIntegerValue];
AIStatusType realType;
switch (type) {
case AIAvailableStatusTypeAS:
realType = AIAvailableStatusType;
break;
case AIAwayStatusTypeAS:
realType = AIAwayStatusType;
break;
case AIInvisibleStatusTypeAS:
realType = AIInvisibleStatusType;
break;
case AIOfflineStatusTypeAS:
default:
realType = AIOfflineStatusType;
break;
}
AIStatus *status = [AIStatus statusOfType:realType];
if ([properties objectForKey:@"scriptingTitle"])
[status setTitle:[properties objectForKey:@"scriptingTitle"]];
if ([properties objectForKey:@"scriptingMessage"]) {
if ([[properties objectForKey:@"scriptingMessage"] isKindOfClass:[NSString class]])
[status setStatusMessageString:[properties objectForKey:@"scriptingMessage"]];
else
[status setStatusMessage:[properties objectForKey:@"scriptingMessage"]];
}
if ([properties objectForKey:@"scriptingAutoreply"]) {
if ([[properties objectForKey:@"scriptingAutoreply"] isKindOfClass:[NSString class]])
[status setAutoReplyString:[properties objectForKey:@"scriptingAutoreply"]];
else
[status setAutoReply:[properties objectForKey:@"scriptingAutoreply"]];
}
if ([keyDictionary objectForKey:@"Location"]) {
NSPositionalSpecifier *location = [keyDictionary objectForKey:@"Location"];
NSUInteger index = [location insertionIndex];
[[adium.statusController rootStateGroup] addStatusItem:status atIndex:index];
} else {
[adium.statusController addStatusState:status];
}
return status;
}
- (AIStatus *)valueInStatusesWithUniqueID:(id)uniqueID
{
return [adium.statusController statusStateWithUniqueStatusID:uniqueID];
}
- (AIStatus *)globalStatus
{
return adium.statusController.activeStatusState;
}
- (void)setGlobalStatus:(AIStatus *)inGlobalStatus
{
return [adium.statusController setActiveStatusState:inGlobalStatus];
}
- (id)scriptingGetURL:(NSScriptCommand *)command
{
NSString *url = [command directParameter];
[[NSNotificationCenter defaultCenter] postNotificationName:AIURLHandleNotification object:url];
return nil;
}
#pragma mark Debugging
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
NSLog(@"*** setValue:%@ forUndefinedKey:%@ ***", value, key);
[super setValue:value forUndefinedKey:key];
}
@end
|