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 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | /*
* Adium is the legal property of its developers, whose names are listed in the copyright file included
* with this source distribution.
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program; if not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <Adium/AIContactControllerProtocol.h>
#import "ESAccountEvents.h"
#import <Adium/AIContactAlertsControllerProtocol.h>
#import <AIUtilities/AIImageAdditions.h>
#import <Adium/AIAccount.h>
#define ACCOUNT_CONNECTION_STATUS_GROUPING 4.0
/*!
* @class ESAccountEvents
* @brief Component to handle account-related Contact Alerts events
*/
@implementation ESAccountEvents
/*!
* @brief Install
*/
- (void)installPlugin
{
accountConnectionStatusGroupingOnlineTimer = nil;
accountConnectionStatusGroupingOfflineTimer = nil;
//Register the events we generate
[adium.contactAlertsController registerEventID:ACCOUNT_CONNECTED withHandler:self inGroup:AIAccountsEventHandlerGroup globalOnly:YES];
[adium.contactAlertsController registerEventID:ACCOUNT_DISCONNECTED withHandler:self inGroup:AIAccountsEventHandlerGroup globalOnly:YES];
[adium.contactAlertsController registerEventID:ACCOUNT_RECEIVED_EMAIL withHandler:self inGroup:AIOtherEventHandlerGroup globalOnly:YES];
//Observe status changes
[[AIContactObserverManager sharedManager] registerListObjectObserver:self];
}
- (void)uninstallPlugin
{
[[AIContactObserverManager sharedManager] unregisterListObjectObserver:self];
}
/*!
* @brief Short description for an event
*
* We're global-only, so no short descriptions are needed.
*/
- (NSString *)shortDescriptionForEventID:(NSString *)eventID { return @""; }
/*!
* @brief Global short description for an event
*/
- (NSString *)globalShortDescriptionForEventID:(NSString *)eventID
{
NSString *description;
if ([eventID isEqualToString:ACCOUNT_CONNECTED]) {
description = AILocalizedString(@"You connect",nil);
} else if ([eventID isEqualToString:ACCOUNT_DISCONNECTED]) {
description = AILocalizedString(@"You disconnect",nil);
} else if ([eventID isEqualToString:ACCOUNT_RECEIVED_EMAIL]) {
description = AILocalizedString(@"New email notification",nil);
} else {
description = @"";
}
return description;
}
/*!
* @brief English, non-translated global short description for an event
*
* This exists because old X(tras) relied upon matching the description of event IDs, and I don't feel like making
* a converter for old packs. If anyone wants to fix this situation, please feel free :)
*
* @result English global short description which should only be used internally
*/
- (NSString *)englishGlobalShortDescriptionForEventID:(NSString *)eventID
{
NSString *description;
if ([eventID isEqualToString:ACCOUNT_CONNECTED]) {
description = @"Connected";
} else if ([eventID isEqualToString:ACCOUNT_DISCONNECTED]) {
description = @"Disconnected";
} else if ([eventID isEqualToString:ACCOUNT_RECEIVED_EMAIL]) {
description = @"New Mail Received";
} else {
description = @"";
}
return description;
}
/*!
* @brief Long description for an event
*/
- (NSString *)longDescriptionForEventID:(NSString *)eventID forListObject:(AIListObject *)listObject
{
NSString *description;
if ([eventID isEqualToString:ACCOUNT_CONNECTED]) {
description = AILocalizedString(@"When you connect",nil);
} else if ([eventID isEqualToString:ACCOUNT_DISCONNECTED]) {
description = AILocalizedString(@"When you disconnect",nil);
} else if ([eventID isEqualToString:ACCOUNT_RECEIVED_EMAIL]) {
description = AILocalizedString(@"When you receive a new email notification",nil);
} else {
description = @"";
}
return description;
}
/*!
* @brief Natural language description for an event
*
* @param eventID The event identifier
* @param listObject The listObject triggering the event
* @param userInfo Event-specific userInfo
* @param includeSubject If YES, return a full sentence. If not, return a fragment.
* @result The natural language description.
*/
- (NSString *)naturalLanguageDescriptionForEventID:(NSString *)eventID
listObject:(AIListObject *)listObject
userInfo:(id)userInfo
includeSubject:(BOOL)includeSubject
{
NSString *description = nil;
if (includeSubject) {
NSString *format = nil;
if ([eventID isEqualToString:ACCOUNT_CONNECTED]) {
format = AILocalizedString(@"%@ connected",nil);
} else if ([eventID isEqualToString:ACCOUNT_DISCONNECTED]) {
format = AILocalizedString(@"%@ disconnected",nil);
} else if ([eventID isEqualToString:ACCOUNT_RECEIVED_EMAIL]) {
format = AILocalizedString(@"%@ received new email",nil);
}
if (format) {
description = [NSString stringWithFormat:format,listObject.formattedUID];
}
} else {
if ([eventID isEqualToString:ACCOUNT_CONNECTED]) {
description = AILocalizedString(@"connected",nil);
} else if ([eventID isEqualToString:ACCOUNT_DISCONNECTED]) {
description = AILocalizedString(@"disconnected",nil);
} else if ([eventID isEqualToString:ACCOUNT_RECEIVED_EMAIL]) {
if (userInfo && [userInfo isKindOfClass:[NSString class]]) {
description = [[(NSString *)userInfo copy] autorelease];
} else {
description = AILocalizedString(@"received new email",nil);
}
}
}
return description;
}
- (NSImage *)imageForEventID:(NSString *)eventID
{
static NSImage *eventImage = nil;
if (!eventImage) eventImage = [[NSImage imageNamed:@"pref-accounts" forClass:[self class]] retain];
return eventImage;
}
- (NSString *)descriptionForCombinedEventID:(NSString *)eventID
forListObject:(AIListObject *)listObject
forChat:(AIChat *)chat
withCount:(NSUInteger)count
{
NSString *format;
if ([eventID isEqualToString:ACCOUNT_CONNECTED]) {
format = AILocalizedString(@"%u accounts connected",nil);
} else if ([eventID isEqualToString:ACCOUNT_DISCONNECTED]) {
format = AILocalizedString(@"%u accounts disconnected",nil);
} else if ([eventID isEqualToString:ACCOUNT_RECEIVED_EMAIL]) {
format = AILocalizedString(@"%u accounts received new email",nil);
}
return format ? [NSString stringWithFormat:format, count] : @"";
}
#pragma mark Aggregation and event generation
/*!
* @brief Update list object
*
* We aggregate account connection events to avoid a quick sign on/sign off from triggering the event
*/
- (NSSet *)updateListObject:(AIListObject *)inObject keys:(NSSet *)inModifiedKeys silent:(BOOL)silent
{
if ([inObject isKindOfClass:[AIAccount class]]) { //We only care about accounts
if ([inModifiedKeys containsObject:@"Online"]) {
if ([[inObject numberValueForProperty:@"Online"] boolValue]) {
if (accountConnectionStatusGroupingOnlineTimer) {
[accountConnectionStatusGroupingOnlineTimer invalidate]; [accountConnectionStatusGroupingOnlineTimer release];
}
accountConnectionStatusGroupingOnlineTimer = [[NSTimer scheduledTimerWithTimeInterval:ACCOUNT_CONNECTION_STATUS_GROUPING
target:self
selector:@selector(accountConnection:)
userInfo:inObject
repeats:NO] retain];
} else {
if (accountConnectionStatusGroupingOfflineTimer) {
[accountConnectionStatusGroupingOfflineTimer invalidate]; [accountConnectionStatusGroupingOfflineTimer release];
}
accountConnectionStatusGroupingOfflineTimer = [[NSTimer scheduledTimerWithTimeInterval:ACCOUNT_CONNECTION_STATUS_GROUPING
target:self
selector:@selector(accountDisconnection:)
userInfo:inObject
repeats:NO] retain];
}
}
}
return nil;
}
/*!
* @brief Called an account connects and remains online for ACCOUNT_CONNECTION_STATUS_GROUPING
*/
- (void)accountConnection:(NSTimer *)timer
{
[adium.contactAlertsController generateEvent:ACCOUNT_CONNECTED
forListObject:[timer userInfo]
userInfo:nil
previouslyPerformedActionIDs:nil];
[accountConnectionStatusGroupingOnlineTimer release]; accountConnectionStatusGroupingOnlineTimer = nil;
}
/*!
* @brief Called an account disconnects and remains offline for ACCOUNT_CONNECTION_STATUS_GROUPING
*/
- (void)accountDisconnection:(NSTimer *)timer
{
[adium.contactAlertsController generateEvent:ACCOUNT_DISCONNECTED
forListObject:[timer userInfo]
userInfo:nil
previouslyPerformedActionIDs:nil];
[accountConnectionStatusGroupingOfflineTimer release]; accountConnectionStatusGroupingOfflineTimer = nil;
}
@end
|