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 againadium / Plugins / Purple Service / ESPurpleYahooAccount.m
1 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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | /*
* 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/AIAccountControllerProtocol.h>
#import <Adium/AIStatusControllerProtocol.h>
#import "ESPurpleYahooAccount.h"
#import "ESPurpleYahooAccountViewController.h"
#import <AdiumLibpurple/SLPurpleCocoaAdapter.h>
#import <Adium/AIHTMLDecoder.h>
#import <Adium/AIListContact.h>
#import <Adium/AIStatus.h>
#import <Adium/ESFileTransfer.h>
#import <libpurple/libymsg.h>
#import <libpurple/yahoo_friend.h>
@implementation ESPurpleYahooAccount
- (const char*)protocolPlugin
{
return "prpl-yahoo";
}
- (void)configurePurpleAccount
{
[super configurePurpleAccount];
purple_account_set_string(account, "room_list_locale", [[self preferenceForKey:KEY_YAHOO_ROOM_LIST_LOCALE
group:GROUP_ACCOUNT_STATUS] UTF8String]);
}
- (NSString *)stringByRemovingYahooSuffix:(NSString *)inString
{
if ((inString && ([inString length] > 0))) {
//If inString contains @yahoo., we consider this to be an email address suffix such as @yahoo.com or @yahoo.it, and delete it and everything after it. Thus, jdoe@yahoo.com becomes simply jdoe.
//However, we must leave other suffixes, such as sbcglobal.net, alone. We can't simply match @, or we would delete the @sbcglobal.net suffix and leave the user unable to connect with it.
NSRange yahooRange = [inString rangeOfString:@"@yahoo."
options:NSLiteralSearch];
if (yahooRange.location != NSNotFound) {
//Future expansion: Only delete if “@yahoo.” is followed by a known TLD and (if appropriate) 2LD, in order to support oddball suffixes such as “@yahoo.example.com”. I don't know whether any such suffixes exist. —boredzo
inString = [inString substringToIndex:yahooRange.location];
}
}
return inString;
}
/*!
* @brief The UID will be changed. The account has a chance to perform modifications
*
* Remove @yahoo.com from the proposedUID - a common mistake is to include it in the yahoo ID
*
* @param proposedUID The proposed, pre-filtered UID (filtered means it has no characters invalid for this servce)
* @result The UID to use; the default implementation just returns proposedUID.
*/
- (NSString *)accountWillSetUID:(NSString *)proposedUID
{
return [self stringByRemovingYahooSuffix:proposedUID];
}
/*!
* @brief Name to use when creating a PurpleAccount for this CBPurpleAccount
*/
- (const char *)purpleAccountName
{
return [[self stringByRemovingYahooSuffix:self.formattedUID] UTF8String];
}
- (NSSet *)supportedPropertyKeys
{
static NSMutableSet *supportedPropertyKeys = nil;
if (!supportedPropertyKeys) {
supportedPropertyKeys = [[NSMutableSet alloc] initWithObjects:
@"AvailableMessage",
@"Invisible",
nil];
[supportedPropertyKeys unionSet:[super supportedPropertyKeys]];
}
return supportedPropertyKeys;
}
/*!
* @brief Should set aliases serverside?
*
* Yahoo supports serverside aliases.
*/
- (BOOL)shouldSetAliasesServerside
{
return YES;
}
#pragma mark Connection
- (NSString *)connectionStringForStep:(NSInteger)step
{
switch (step)
{
case 0:
return AILocalizedString(@"Connecting",nil);
break;
}
return nil;
}
#pragma mark Encoding
- (NSString *)encodedAttributedString:(NSAttributedString *)inAttributedString forListObject:(AIListObject *)inListObject
{
return [AIHTMLDecoder encodeHTML:inAttributedString
headers:NO
fontTags:YES
includingColorTags:YES
closeFontTags:YES
styleTags:YES
closeStyleTagsOnFontChange:YES
encodeNonASCII:NO
encodeSpaces:NO
imagesPath:nil
attachmentsAsText:YES
onlyIncludeOutgoingImages:NO
simpleTagsOnly:YES
bodyBackground:NO
allowJavascriptURLs:YES];
}
#pragma mark File transfer
- (BOOL)canSendFolders
{
return NO;
}
- (void)beginSendOfFileTransfer:(ESFileTransfer *)fileTransfer
{
[super _beginSendOfFileTransfer:fileTransfer];
}
- (void)acceptFileTransferRequest:(ESFileTransfer *)fileTransfer
{
[super acceptFileTransferRequest:fileTransfer];
}
- (void)rejectFileReceiveRequest:(ESFileTransfer *)fileTransfer
{
[super rejectFileReceiveRequest:fileTransfer];
}
- (void)cancelFileTransfer:(ESFileTransfer *)fileTransfer
{
[super cancelFileTransfer:fileTransfer];
}
#pragma mark Status Messages
/*!
* @brief Status name to use for a Purple buddy
*/
- (NSString *)statusNameForPurpleBuddy:(PurpleBuddy *)buddy
{
NSString *statusName = nil;
PurplePresence *presence = purple_buddy_get_presence(buddy);
PurpleStatus *status = purple_presence_get_active_status(presence);
const char *purpleStatusID = purple_status_get_id(status);
if (!purpleStatusID) return nil;
if (!strcmp(purpleStatusID, YAHOO_STATUS_TYPE_BRB)) {
statusName = STATUS_NAME_BRB;
} else if (!strcmp(purpleStatusID, YAHOO_STATUS_TYPE_BUSY)) {
statusName = STATUS_NAME_BUSY;
} else if (!strcmp(purpleStatusID, YAHOO_STATUS_TYPE_NOTATHOME)) {
statusName = STATUS_NAME_NOT_AT_HOME;
} else if (!strcmp(purpleStatusID, YAHOO_STATUS_TYPE_NOTATDESK)) {
statusName = STATUS_NAME_NOT_AT_DESK;
} else if (!strcmp(purpleStatusID, YAHOO_STATUS_TYPE_NOTINOFFICE)) {
statusName = STATUS_NAME_NOT_IN_OFFICE;
} else if (!strcmp(purpleStatusID, YAHOO_STATUS_TYPE_ONPHONE)) {
statusName = STATUS_NAME_PHONE;
} else if (!strcmp(purpleStatusID, YAHOO_STATUS_TYPE_ONVACATION)) {
statusName = STATUS_NAME_VACATION;
} else if (!strcmp(purpleStatusID, YAHOO_STATUS_TYPE_OUTTOLUNCH)) {
statusName = STATUS_NAME_LUNCH;
} else if (!strcmp(purpleStatusID, YAHOO_STATUS_TYPE_STEPPEDOUT)) {
statusName = STATUS_NAME_STEPPED_OUT;
} else if (!strcmp(purpleStatusID, YAHOO_STATUS_TYPE_INVISIBLE)) {
statusName = STATUS_NAME_INVISIBLE;
}
return statusName;
}
/*!
* @brief Update the status message and away state of the contact
*/
- (void)updateStatusForContact:(AIListContact *)theContact toStatusType:(NSNumber *)statusTypeNumber statusName:(NSString *)statusName statusMessage:(NSAttributedString *)statusMessage isMobile:(BOOL)isMobile
{
NSString *statusMessageString = [statusMessage string];
char *normalized = g_strdup(purple_normalize(account, [theContact.UID UTF8String]));
YahooData *od;
YahooFriend *f;
/* Grab the idle time while we have a chance */
if ((purple_account_is_connected(account)) &&
(od = purple_account_get_connection(account)->proto_data) &&
(f = g_hash_table_lookup(od->friends, normalized))) {
if (f->status == YAHOO_STATUS_IDLE) {
//Now idle
NSInteger idle = f->idle;
NSDate *idleSince;
if (idle != -1) {
idleSince = [NSDate dateWithTimeIntervalSinceNow:-idle];
} else {
idleSince = [NSDate date];
}
[theContact setValue:idleSince
forProperty:@"IdleSince"
notify:NotifyLater];
} else if (f->status == YAHOO_STATUS_INVISIBLE) {
statusTypeNumber = [NSNumber numberWithInteger:AIInvisibleStatusType]; /* Invisible has a special status type */
}
}
g_free(normalized);
//Yahoo doesn't have an explicit mobile state; instead the status message is automatically set to indicate mobility.
if (statusMessageString && ([statusMessageString isEqualToString:@"I'm on SMS"] ||
([statusMessageString rangeOfString:@"I'm mobile"].location != NSNotFound))) {
[theContact setIsMobile:YES notify:NotifyLater];
} else if (theContact.isMobile) {
[theContact setIsMobile:NO notify:NotifyLater];
}
[super updateStatusForContact:theContact
toStatusType:statusTypeNumber
statusName:statusName
statusMessage:statusMessage
isMobile:isMobile];
}
/*!
* @brief Return the purple status ID to be used for a status
*
* Most subclasses should override this method; these generic values may be appropriate for others.
*
* Active services provided nonlocalized status names. An AIStatus is passed to this method along with a pointer
* to the status message. This method should handle any status whose statusNname this service set as well as any statusName
* defined in AIStatusController.h (which will correspond to the services handled by Adium by default).
* It should also handle a status name not specified in either of these places with a sane default, most likely by loooking at
* statusState.statusType for a general idea of the status's type.
*
* @param statusState The status for which to find the purple status ID
* @param arguments Prpl-specific arguments which will be passed with the state. Message is handled automatically.
*
* @result The purple status ID
*/
- (const char *)purpleStatusIDForStatus:(AIStatus *)statusState
arguments:(NSMutableDictionary *)arguments
{
const char *statusID = NULL;
NSString *statusName = statusState.statusName;
NSString *statusMessageString = [statusState statusMessageString];
if (!statusMessageString) statusMessageString = @"";
switch (statusState.statusType) {
case AIAvailableStatusType:
statusID = YAHOO_STATUS_TYPE_AVAILABLE;
break;
case AIAwayStatusType:
{
if (([statusName isEqualToString:STATUS_NAME_BRB]) ||
([statusMessageString caseInsensitiveCompare:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_BRB]] == NSOrderedSame))
statusID = YAHOO_STATUS_TYPE_BRB;
else if (([statusName isEqualToString:STATUS_NAME_BUSY]) ||
([statusMessageString caseInsensitiveCompare:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_BUSY]] == NSOrderedSame))
statusID = YAHOO_STATUS_TYPE_BUSY;
else if (([statusName isEqualToString:STATUS_NAME_NOT_AT_HOME]) ||
([statusMessageString caseInsensitiveCompare:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_NOT_AT_HOME]] == NSOrderedSame))
statusID = YAHOO_STATUS_TYPE_NOTATHOME;
else if (([statusName isEqualToString:STATUS_NAME_NOT_AT_DESK]) ||
([statusMessageString caseInsensitiveCompare:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_NOT_AT_DESK]] == NSOrderedSame))
statusID = YAHOO_STATUS_TYPE_NOTATDESK;
else if (([statusName isEqualToString:STATUS_NAME_PHONE]) ||
([statusMessageString caseInsensitiveCompare:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_PHONE]] == NSOrderedSame))
statusID = YAHOO_STATUS_TYPE_ONPHONE;
else if (([statusName isEqualToString:STATUS_NAME_VACATION]) ||
([statusMessageString caseInsensitiveCompare:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_VACATION]] == NSOrderedSame))
statusID = YAHOO_STATUS_TYPE_ONVACATION;
else if (([statusName isEqualToString:STATUS_NAME_LUNCH]) ||
([statusMessageString caseInsensitiveCompare:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_LUNCH]] == NSOrderedSame))
statusID = YAHOO_STATUS_TYPE_OUTTOLUNCH;
else if (([statusName isEqualToString:STATUS_NAME_STEPPED_OUT]) ||
([statusMessageString caseInsensitiveCompare:[adium.statusController localizedDescriptionForCoreStatusName:STATUS_NAME_STEPPED_OUT]] == NSOrderedSame))
statusID = YAHOO_STATUS_TYPE_STEPPEDOUT;
break;
}
case AIInvisibleStatusType:
statusID = YAHOO_STATUS_TYPE_INVISIBLE;
break;
case AIOfflineStatusType:
break;
}
//If we didn't get a purple status ID, request one from super
if (statusID == NULL) statusID = [super purpleStatusIDForStatus:statusState arguments:arguments];
return statusID;
}
- (BOOL)shouldAddMusicalNoteToNowPlayingStatus
{
return NO;
}
#pragma mark Contact List Menu Items
- (NSString *)titleForContactMenuLabel:(const char *)label forContact:(AIListContact *)inContact
{
if (!strcmp(label, _("Add Buddy"))) {
//We handle Add Buddy ourselves
return nil;
} else if (!strcmp(label, _("Join in Chat"))) {
return [NSString stringWithFormat:AILocalizedString(@"Join %@'s Chat",nil),inContact.formattedUID];
} else if (!strcmp(label, _("Initiate Conference"))) {
return [NSString stringWithFormat:AILocalizedString(@"Initiate Conference with %@",nil), inContact.formattedUID];
} else if (!strcmp(label, _("Presence Settings"))) {
return [NSString stringWithFormat:AILocalizedString(@"Presence Settings for %@",nil), inContact.formattedUID];
} else if (!strcmp(label, _("Appear Online"))) {
return [NSString stringWithFormat:AILocalizedString(@"Appear Online to %@",nil), inContact.formattedUID];
} else if (!strcmp(label, _("Appear Offline"))) {
return [NSString stringWithFormat:AILocalizedString(@"Appear Offline to %@",nil), inContact.formattedUID];
} else if (!strcmp(label, _("Appear Permanently Offline"))) {
return [NSString stringWithFormat:AILocalizedString(@"Always Appear Offline to %@",nil), inContact.formattedUID];
} else if (!strcmp(label, _("Don't Appear Permanently Offline"))) {
return [NSString stringWithFormat:AILocalizedString(@"Don't Always Appear Offline to %@",nil), inContact.formattedUID];
} else if (!strcmp(label, _("View Webcam"))) {
//return [NSString stringWithFormat:AILocalizedString(@"View %@'s Webcam",nil), inContact.formattedUID];
return nil;
} else if (!strcmp(label, _("Start Doodling"))) {
return nil;
}
return [super titleForContactMenuLabel:label forContact:inContact];
}
#pragma mark Account Action Menu Items
- (NSString *)titleForAccountActionMenuLabel:(const char *)label
{
/* The Yahoo actions are "Activate ID" (or perhaps "Active ID," depending on where in the code you look)
* and "Join User in Chat...". These are dumb. Additionally, Join User in Chat doesn't work as of purple 1.1.4. */
return nil;
}
@end
|