| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | #import "GBFireImporter.h" |
| 18 | #import <Adium/AIContactControllerProtocol.h> |
| 19 | #import <Adium/AIPreferenceControllerProtocol.h> |
| 20 | #import <Adium/AIAccountControllerProtocol.h> |
| 21 | |
| 22 | #import <AIUtilities/AIFileManagerAdditions.h> |
| 23 | #import "AIAccount.h" |
| 24 | #import <Adium/AIStatus.h> |
| 25 | #import "AIHTMLDecoder.h" |
| 26 | #import "AIStatusController.h" |
| 27 | |
| 28 | #import "AIListGroup.h" |
| 29 | #import <Adium/AIListContact.h> |
| 30 | #import "AIMetaContact.h" |
| 31 | #import "GBFireLogImporter.h" |
| 32 | |
| 33 | #define FIRECONFIGURATION2 @"FireConfiguration2.plist" |
| 34 | #define FIRECONFIGURATION @"FireConfiguration.plist" |
| 35 | #define ACCOUNTS2 @"Accounts2.plist" |
| 36 | #define ACCOUNTS @"Accounts.plist" |
| 37 | |
| 38 | @interface GBFireImportedBuddy : AIObject{ |
| 39 | AIListContact *contact; |
| 40 | |
| 41 | AIAccount *account; |
| 42 | NSString *groupName; |
| 43 | NSString *screenname; |
| 44 | NSString *displayName; |
| 45 | BOOL blocked; |
| 46 | } |
| 47 | |
| 48 | - (id)initScreenname:(NSString *)screen forAccount:(AIAccount *)acct; |
| 49 | - (AIAccount *)account; |
| 50 | - (void)setGroup:(NSString *)group; |
| 51 | - (void)setBlocked:(BOOL)block; |
| 52 | - (void)setDisplayName:(NSString *)alias; |
| 53 | - (AIListContact *)createContact; |
| 54 | - (AIListContact *)contact; |
| 55 | @end |
| 56 | |
| 57 | @implementation GBFireImportedBuddy |
| 58 | - (id)initScreenname:(NSString *)screen forAccount:(AIAccount *)acct |
| 59 | { |
| 60 | self = [super init]; |
| 61 | if(!self) |
| 62 | return nil0; |
| 63 | |
| 64 | screenname = [screen retain]; |
| 65 | account = [acct retain]; |
| 66 | groupName = nil0; |
| 67 | displayName = nil0; |
| 68 | blocked = NO( BOOL ) 0; |
| 69 | |
| 70 | return self; |
| 71 | } |
| 72 | |
| 73 | - (void)dealloc |
| 74 | { |
| 75 | [screenname release]; |
| 76 | [account release]; |
| 77 | [groupName release]; |
| 78 | [displayName release]; |
| 79 | [super dealloc]; |
| 80 | } |
| 81 | |
| 82 | - (AIAccount *)account |
| 83 | { |
| 84 | return account; |
| 85 | } |
| 86 | |
| 87 | - (void)setGroup:(NSString *)group |
| 88 | { |
| 89 | [groupName release]; |
| 90 | groupName = [group retain]; |
| 91 | } |
| 92 | |
| 93 | - (void)setBlocked:(BOOL)block |
| 94 | { |
| 95 | blocked = block; |
| 96 | } |
| 97 | |
| 98 | - (void)setDisplayName:(NSString *)alias |
| 99 | { |
| 100 | [displayName release]; |
| 101 | displayName = [alias retain]; |
| 102 | } |
| 103 | |
| 104 | - (AIListContact *)createContact |
| 105 | { |
| 106 | if(contact != nil0) |
| 107 | return contact; |
| 108 | |
| 109 | id <AIContactController> contactController = [adium contactController]; |
| 110 | |
| 111 | contact = [contactController contactWithService:[account service] account:account UID:screenname]; |
| 112 | if(displayName != nil0) |
| 113 | [contact setDisplayName:displayName]; |
| 114 | if(blocked) |
| 115 | [contact setIsBlocked:YES( BOOL ) 1 updateList:YES( BOOL ) 1]; |
| 116 | if(groupName) |
| 117 | [contact setRemoteGroupName:groupName]; |
| 118 | |
| 119 | return contact; |
| 120 | } |
| 121 | |
| 122 | - (AIListContact *)contact |
| 123 | { |
| 124 | return contact; |
| 125 | } |
| 126 | @end |
| 127 | |
| 128 | @interface GBFireImporter (private) |
| 129 | - (BOOL)importFireConfiguration; |
| 130 | - (BOOL)import2:(NSString *)fireDir; |
| 131 | - (BOOL)import1:(NSString *)fireDir; |
| 132 | @end |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | @implementation GBFireImporter |
| 143 | |
| 144 | - (id)init |
| 145 | { |
| 146 | self = [super init]; |
| 147 | if(!self) |
| 148 | return nil0; |
| 149 | |
| 150 | accountUIDtoAccount = [[NSMutableDictionary alloc] init]; |
| 151 | aliasToContacts = [[NSMutableDictionary alloc] init]; |
| 152 | buddiesToContact = [[NSMutableDictionary alloc] init]; |
| 153 | personLists = [[NSMutableArray alloc] init]; |
| 154 | |
| 155 | NSEnumerator *serviceEnum = [[[adium accountController] services] objectEnumerator]; |
| 156 | AIService *service = nil0; |
| 157 | serviceDict = [[NSMutableDictionary alloc] init]; |
| 158 | while ((service = [serviceEnum nextObject]) != nil0) |
| 159 | { |
| 160 | [serviceDict setObject:service forKey:[service serviceID]]; |
| 161 | } |
| 162 | [serviceDict setObject:[serviceDict objectForKey:@"Bonjour"] forKey:@"Rendezvous"]; |
| 163 | [serviceDict setObject:[serviceDict objectForKey:@"GTalk"] forKey:@"GoogleTalk"]; |
| 164 | [serviceDict setObject:[serviceDict objectForKey:@"Yahoo!"] forKey:@"Yahoo"]; |
| 165 | |
| 166 | return self; |
| 167 | } |
| 168 | |
| 169 | - (void)dealloc |
| 170 | { |
| 171 | [accountUIDtoAccount release]; |
| 172 | [aliasToContacts release]; |
| 173 | [buddiesToContact release]; |
| 174 | [personLists release]; |
| 175 | [serviceDict release]; |
| 176 | [super dealloc]; |
| 177 | } |
| 178 | |
| 179 | - (void)accountConnected:(NSNotification *)notification |
| 180 | { |
| 181 | id <AIContactController> contactController = [adium contactController]; |
| 182 | AIAccount *acct = [notification object]; |
| 183 | |
| 184 | NSEnumerator *personEnum = [[NSArray arrayWithArray:personLists] objectEnumerator]; |
| 185 | NSArray *personContacts = nil0; |
| 186 | while((personContacts = [personEnum nextObject]) != nil0) |
| 187 | { |
| 188 | BOOL aBuddyNotCreated = NO( BOOL ) 0; |
| 189 | BOOL aBuddyCreated = NO( BOOL ) 0; |
| 190 | NSEnumerator *contactEnum = [personContacts objectEnumerator]; |
| 191 | GBFireImportedBuddy *buddy = nil0; |
| 192 | NSMutableArray *thisMetaContact = [[NSMutableArray alloc] init]; |
| 193 | while((buddy = [contactEnum nextObject]) != nil0) |
| 194 | { |
| 195 | AIListContact *contact = [buddy contact]; |
| 196 | if(contact != nil0) |
| 197 | { |
| 198 | [thisMetaContact addObject:contact]; |
| 199 | continue; |
| 200 | } |
| 201 | if([buddy account] == acct) |
| 202 | { |
| 203 | contact = [buddy createContact]; |
| 204 | [thisMetaContact addObject:contact]; |
| 205 | aBuddyCreated = YES( BOOL ) 1; |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | aBuddyNotCreated = YES( BOOL ) 1; |
| 210 | } |
| 211 | } |
| 212 | if(aBuddyCreated && [thisMetaContact count] > 1) |
| 213 | [contactController groupListContacts:thisMetaContact]; |
| 214 | if(!aBuddyNotCreated) |
| 215 | [personLists removeObject:personContacts]; |
| 216 | [thisMetaContact release]; |
| 217 | } |
| 218 | [[adium notificationCenter] removeObserver:self name:ACCOUNT_CONNECTED@ "Account_Connected" object:acct]; |
| 219 | [self autorelease]; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | + (BOOL)importFireConfiguration |
| 227 | { |
| 228 | GBFireImporter *importer = [[GBFireImporter alloc] init]; |
| 229 | BOOL ret = [importer importFireConfiguration]; |
| 230 | |
| 231 | [importer release]; |
| 232 | return ret; |
| 233 | } |
| 234 | |
| 235 | - (BOOL)importFireConfiguration |
| 236 | { |
| 237 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
| 238 | NSString *fireDir = [[[NSFileManager defaultManager] userApplicationSupportFolder] stringByAppendingPathComponent:@"Fire"]; |
| 239 | BOOL version2Succeeded = NO( BOOL ) 0; |
| 240 | BOOL version1Succeeded = NO( BOOL ) 0; |
| 241 | BOOL ret = YES( BOOL ) 1; |
| 242 | |
| 243 | version2Succeeded = [self import2:fireDir]; |
| 244 | |
| 245 | if(!version2Succeeded) |
| 246 | |
| 247 | version1Succeeded = [self import1:fireDir]; |
| 248 | |
| 249 | if(!version2Succeeded && !version1Succeeded) |
| 250 | |
| 251 | ret = NO( BOOL ) 0; |
| 252 | |
| 253 | [pool release]; |
| 254 | [GBFireLogImporter importLogs]; |
| 255 | return ret; |
| 256 | } |
| 257 | |
| 258 | - (AIService *)translateServiceName:(NSString *)serviceName screenName:(NSString *)screenName; |
| 259 | { |
| 260 | if([serviceName isEqualTo:@"Jabber"] && [screenName hasSuffix:@"@gmail.com"]) |
| 261 | serviceName = @"GoogleTalk"; |
| 262 | |
| 263 | return [serviceDict objectForKey:serviceName]; |
| 264 | } |
| 265 | |
| 266 | - (int)checkPort:(int)port forService:(AIService *)service |
| 267 | { |
| 268 | if(port == 0) |
| 269 | return 0; |
| 270 | if([[service serviceID] isEqualTo:@"AIM"] && port == 9898) |
| 271 | return 0; |
| 272 | if([[service serviceID] isEqualTo:@"GTalk"] && port == 5223) |
| 273 | return 0; |
| 274 | return port; |
| 275 | } |
| 276 | |
| 277 | - (NSString *)checkHost:(NSString *)host forService:(AIService *)service |
| 278 | { |
| 279 | if(host == nil0) |
| 280 | return nil0; |
| 281 | if([[service serviceID] isEqualTo:@"AIM"] && [host hasPrefix:@"toc"]) |
| 282 | return nil0; |
| 283 | return host; |
| 284 | } |
| 285 | |
| 286 | - (void)importAccounts2:(NSArray *)accountsDict |
| 287 | { |
| 288 | NSEnumerator *accountEnum = [accountsDict objectEnumerator]; |
| 289 | NSDictionary *account = nil0; |
| 290 | while((account = [accountEnum nextObject]) != nil0) |
| 291 | { |
| 292 | NSString *serviceName = [account objectForKey:@"ServiceName"]; |
| 293 | NSString *accountName = [account objectForKey:@"Username"]; |
| 294 | if(![serviceName length] || ![accountName length]) |
| 295 | continue; |
| 296 | AIService *service = [self translateServiceName:serviceName screenName:accountName]; |
| 297 | if(service == nil0) |
| 298 | |
| 299 | continue; |
| 300 | AIAccount *newAcct = [[adium accountController] createAccountWithService:service |
| 301 | UID:accountName]; |
| 302 | if(newAcct == nil0) |
| 303 | continue; |
| 304 | |
| 305 | [newAcct setPreference:[account objectForKey:@"AutoLogin"] |
| 306 | forKey:@"Online" |
| 307 | group:GROUP_ACCOUNT_STATUS@ "Account Status"]; |
| 308 | |
| 309 | NSDictionary *properties = [account objectForKey:@"Properties"]; |
| 310 | NSString *connectHost = [properties objectForKey:@"server"]; |
| 311 | if([self checkHost:connectHost forService:service]) |
| 312 | [newAcct setPreference:connectHost |
| 313 | forKey:KEY_CONNECT_HOST@ "Connect Host" |
| 314 | group:GROUP_ACCOUNT_STATUS@ "Account Status"]; |
| 315 | |
| 316 | int port = [[properties objectForKey:@"port"] intValue]; |
| 317 | if([self checkPort:port forService:service]) |
| 318 | [newAcct setPreference:[NSNumber numberWithInt:port] |
| 319 | forKey:KEY_CONNECT_PORT@ "Connect Port" |
| 320 | group:GROUP_ACCOUNT_STATUS@ "Account Status"]; |
| 321 | |
| 322 | [accountUIDtoAccount setObject:newAcct forKey:[account objectForKey:@"UniqueID"]]; |
| 323 | [[adium accountController] addAccount:newAcct]; |
| 324 | [[adium notificationCenter] addObserver:self |
| 325 | selector:@selector(accountConnected:) |
| 326 | name:ACCOUNT_CONNECTED@ "Account_Connected" |
| 327 | object:newAcct]; |
| 328 | |
| 329 | [self retain]; |
| 330 | [newAcct setShouldBeOnline:YES( BOOL ) 1]; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | - (void)importAways2:(NSArray *)awayList |
| 335 | { |
| 336 | NSEnumerator *awayEnum = [awayList objectEnumerator]; |
| 337 | NSDictionary *away = nil0; |
| 338 | while((away = [awayEnum nextObject]) != nil0) |
| 339 | { |
| 340 | NSString *title = [away objectForKey:@"Title"]; |
| 341 | BOOL isDefault = [[away objectForKey:@"isIdleMessage"] boolValue]; |
| 342 | BOOL goIdle = [[away objectForKey:@"idleMessage"] boolValue]; |
| 343 | NSString *attrMessage = [away objectForKey:@"message"]; |
| 344 | int fireType = [[away objectForKey:@"messageType"] intValue]; |
| 345 | AIStatusType adiumType = 0; |
| 346 | |
| 347 | switch(fireType) |
| 348 | { |
| 349 | case 0: |
| 350 | case 1: |
| 351 | adiumType = AIAvailableStatusType; |
| 352 | break; |
| 353 | case 4: |
| Although the value stored to 'adiumType' is used in the enclosing expression, the value is never actually read from 'adiumType' |
| 354 | adiumType = AIInvisibleStatusType; |
| 355 | case 3: |
| 356 | case 2: |
| 357 | default: |
| 358 | adiumType = AIAwayStatusType; |
| 359 | } |
| 360 | |
| 361 | AIStatus *newStatus = [AIStatus statusOfType:adiumType]; |
| 362 | [newStatus setTitle:title]; |
| 363 | [newStatus setStatusMessage:[AIHTMLDecoder decodeHTML:attrMessage]]; |
| 364 | [newStatus setAutoReplyIsStatusMessage:YES( BOOL ) 1]; |
| 365 | [newStatus setShouldForceInitialIdleTime:goIdle]; |
| 366 | if(isDefault) |
| 367 | [[adium preferenceController] setPreference:[newStatus uniqueStatusID] |
| 368 | forKey:KEY_STATUS_AUTO_AWAY_STATUS_STATE_ID@ "Auto Away Status State ID" |
| 369 | group:PREF_GROUP_STATUS_PREFERENCES@ "Status Preferences"]; |
| 370 | [[adium statusController] addStatusState:newStatus]; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | NSComparisonResult groupSort(id left, id right, void *context) |
| 375 | { |
| 376 | NSNumber *leftNum = [left objectForKey:@"position"]; |
| 377 | NSNumber *rightNum = [right objectForKey:@"position"]; |
| 378 | NSComparisonResult ret = NSOrderedSame; |
| 379 | |
| 380 | if(leftNum == nil0) |
| 381 | { |
| 382 | if(rightNum != nil0) |
| 383 | ret = NSOrderedAscending; |
| 384 | } |
| 385 | else if (rightNum == nil0) |
| 386 | ret = NSOrderedDescending; |
| 387 | else |
| 388 | ret = [leftNum compare:rightNum]; |
| 389 | |
| 390 | return ret; |
| 391 | } |
| 392 | |
| 393 | - (void)importGroups2:(NSDictionary *)groupList |
| 394 | { |
| 395 | id <AIContactController> contactController = [adium contactController]; |
| 396 | |
| 397 | |
| 398 | NSEnumerator *groupEnum = [groupList keyEnumerator]; |
| 399 | NSString *groupName = nil0; |
| 400 | NSMutableArray *groupArray = [NSMutableArray array]; |
| 401 | while((groupName = [groupEnum nextObject]) != nil0) |
| 402 | { |
| 403 | NSMutableDictionary *groupDict = [[groupList objectForKey:groupName] mutableCopy]; |
| 404 | [groupDict setObject:groupName forKey:@"Name"]; |
| 405 | [groupArray addObject:groupDict]; |
| 406 | [groupDict release]; |
| 407 | } |
| 408 | [groupArray sortUsingFunction:groupSort context:NULL( ( void * ) 0 )]; |
| 409 | groupEnum = [groupArray objectEnumerator]; |
| 410 | NSDictionary *group = nil0; |
| 411 | while((group = [groupEnum nextObject]) != nil0) |
| 412 | { |
| 413 | AIListGroup *newGroup = [contactController groupWithUID:[group objectForKey:@"Name"]]; |
| 414 | NSNumber *expanded = [group objectForKey:@"groupexpanded"]; |
| 415 | if(expanded != nil0) |
| 416 | [newGroup setExpanded:[expanded boolValue]]; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | - (void)importBuddies2:(NSArray *)buddyArray |
| 421 | { |
| 422 | NSEnumerator *buddyEnum = [buddyArray objectEnumerator]; |
| 423 | NSDictionary *buddy = nil0; |
| 424 | while((buddy = [buddyEnum nextObject]) != nil0) |
| 425 | { |
| 426 | NSNumber *inList = [buddy objectForKey:@"BuddyInList"]; |
| 427 | if(inList == nil0 || [inList boolValue] == NO( BOOL ) 0) |
| 428 | continue; |
| 429 | |
| 430 | NSNumber *accountNumber = [buddy objectForKey:@"account"]; |
| 431 | AIAccount *account = [accountUIDtoAccount objectForKey:accountNumber]; |
| 432 | if(account == nil0) |
| 433 | continue; |
| 434 | |
| 435 | NSString *buddyName = [buddy objectForKey:@"buddyname"]; |
| 436 | if([buddyName length] == 0) |
| 437 | continue; |
| 438 | |
| 439 | GBFireImportedBuddy *newContact = [[GBFireImportedBuddy alloc] initScreenname:buddyName forAccount:account]; |
| 440 | |
| 441 | NSMutableDictionary *accountBuddyList = [buddiesToContact objectForKey:accountNumber]; |
| 442 | if(accountBuddyList == nil0) |
| 443 | { |
| 444 | accountBuddyList = [NSMutableDictionary dictionary]; |
| 445 | [buddiesToContact setObject:accountBuddyList forKey:accountNumber]; |
| 446 | } |
| 447 | [accountBuddyList setObject:newContact forKey:buddyName]; |
| 448 | |
| 449 | NSString *alias = [buddy objectForKey:@"displayname"]; |
| 450 | if([alias length] != 0) |
| 451 | { |
| 452 | [newContact setDisplayName:alias]; |
| 453 | NSMutableArray *contactArray = [aliasToContacts objectForKey:alias]; |
| 454 | if(contactArray == nil0) |
| 455 | { |
| 456 | contactArray = [NSMutableArray array]; |
| 457 | [aliasToContacts setObject:contactArray forKey:alias]; |
| 458 | } |
| 459 | [contactArray addObject:newContact]; |
| 460 | } |
| 461 | |
| 462 | BOOL blocked = [[buddy objectForKey:@"BuddyBlocked"] boolValue]; |
| 463 | if(blocked) |
| 464 | [newContact setBlocked:YES( BOOL ) 1]; |
| 465 | |
| 466 | |
| 467 | NSString *groupName = ([[buddy objectForKey:@"Groups"] count] ? [[buddy objectForKey:@"Groups"] objectAtIndex:0] : nil0); |
| 468 | if([groupName length] != 0) |
| 469 | [newContact setGroup:groupName]; |
| 470 | [newContact release]; |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | - (void)importPersons2:(NSArray *)personArray |
| 475 | { |
| 476 | NSEnumerator *personEnum = [personArray objectEnumerator]; |
| 477 | NSDictionary *person = nil0; |
| 478 | while((person = [personEnum nextObject]) != nil0) |
| 479 | { |
| 480 | NSString *personName = [person objectForKey:@"Name"]; |
| 481 | if([personName length] == 0) |
| 482 | continue; |
| 483 | |
| 484 | if([personName hasPrefix:@"Screenname:"]) |
| 485 | continue; |
| 486 | |
| 487 | NSArray *buddyArray = [person objectForKey:@"Buddies"]; |
| 488 | if([buddyArray count] == 0) |
| 489 | |
| 490 | continue; |
| 491 | |
| 492 | NSEnumerator *buddyEnum = [buddyArray objectEnumerator]; |
| 493 | NSDictionary *buddyInfo = nil0; |
| 494 | NSMutableArray *buddies = [NSMutableArray array]; |
| 495 | while ((buddyInfo = [buddyEnum nextObject]) != nil0) |
| 496 | { |
| 497 | NSNumber *buddyAccount = [buddyInfo objectForKey:@"BuddyAccount"]; |
| 498 | NSString *buddySN = [buddyInfo objectForKey:@"BuddyName"]; |
| 499 | |
| 500 | if(buddyAccount == nil0 || buddySN == nil0) |
| 501 | continue; |
| 502 | |
| 503 | GBFireImportedBuddy *contact = [[buddiesToContact objectForKey:buddyAccount] objectForKey:buddySN]; |
| 504 | if(contact == nil0) |
| 505 | |
| 506 | continue; |
| 507 | |
| 508 | [buddies addObject:contact]; |
| 509 | } |
| 510 | [personLists addObject:buddies]; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | - (void)createMetaContacts |
| 515 | { |
| 516 | NSEnumerator *metaContantEnum = [aliasToContacts objectEnumerator]; |
| 517 | NSArray *contacts = nil0; |
| 518 | while ((contacts = [metaContantEnum nextObject]) != nil0) |
| 519 | [personLists addObject:contacts]; |
| 520 | } |
| 521 | |
| 522 | - (BOOL)import2:(NSString *)fireDir |
| 523 | { |
| 524 | NSString *configPath = [fireDir stringByAppendingPathComponent:FIRECONFIGURATION2@ "FireConfiguration2.plist"]; |
| 525 | NSString *accountPath = [fireDir stringByAppendingPathComponent:ACCOUNTS2@ "Accounts2.plist"]; |
| 526 | NSDictionary *configDict = [NSDictionary dictionaryWithContentsOfFile:configPath]; |
| 527 | NSDictionary *accountDict = [NSDictionary dictionaryWithContentsOfFile:accountPath]; |
| 528 | |
| 529 | if(configDict == nil0 || accountDict == nil0) |
| 530 | |
| 531 | return NO( BOOL ) 0; |
| 532 | |
| 533 | |
| 534 | [self importAccounts2:[accountDict objectForKey:@"Accounts"]]; |
| 535 | |
| 536 | |
| 537 | [self importAways2:[configDict objectForKey:@"awayMessages"]]; |
| 538 | |
| 539 | |
| 540 | [self importGroups2:[configDict objectForKey:@"groups"]]; |
| 541 | |
| 542 | |
| 543 | [self importBuddies2:[configDict objectForKey:@"buddies"]]; |
| 544 | |
| 545 | |
| 546 | NSArray *personArray = [configDict objectForKey:@"persons"]; |
| 547 | if([personArray count] > 0) |
| 548 | [self importPersons2:personArray]; |
| 549 | else |
| 550 | [self createMetaContacts]; |
| 551 | |
| 552 | return YES( BOOL ) 1; |
| 553 | } |
| 554 | |
| 555 | - (void)importAccounts1:(NSDictionary *)accountsDict |
| 556 | { |
| 557 | NSEnumerator *serviceNameEnum = [accountsDict keyEnumerator]; |
| 558 | NSString *serviceName = nil0; |
| 559 | while ((serviceName = [serviceNameEnum nextObject]) != nil0) |
| 560 | { |
| 561 | if(![serviceName length]) |
| 562 | continue; |
| 563 | |
| 564 | NSEnumerator *accountEnum = [[accountsDict objectForKey:serviceName] objectEnumerator]; |
| 565 | NSDictionary *account = nil0; |
| 566 | |
| 567 | while((account = [accountEnum nextObject]) != nil0) |
| 568 | { |
| 569 | NSString *accountName = [account objectForKey:@"userName"]; |
| 570 | if(![accountName length]) |
| 571 | continue; |
| 572 | AIService *service = [self translateServiceName:serviceName screenName:accountName]; |
| 573 | AIAccount *newAcct = [[adium accountController] createAccountWithService:service |
| 574 | UID:accountName]; |
| 575 | if(newAcct == nil0) |
| 576 | continue; |
| 577 | |
| 578 | [newAcct setPreference:[account objectForKey:@"autoLogin"] |
| 579 | forKey:@"Online" |
| 580 | group:GROUP_ACCOUNT_STATUS@ "Account Status"]; |
| 581 | |
| 582 | NSString *connectHost = [account objectForKey:@"server"]; |
| 583 | if([self checkHost:connectHost forService:service]) |
| 584 | [newAcct setPreference:connectHost |
| 585 | forKey:KEY_CONNECT_HOST@ "Connect Host" |
| 586 | group:GROUP_ACCOUNT_STATUS@ "Account Status"]; |
| 587 | |
| 588 | int port = [[account objectForKey:@"port"] intValue]; |
| 589 | if([self checkPort:port forService:service]) |
| 590 | [newAcct setPreference:[NSNumber numberWithInt:port] |
| 591 | forKey:KEY_CONNECT_PORT@ "Connect Port" |
| 592 | group:GROUP_ACCOUNT_STATUS@ "Account Status"]; |
| 593 | |
| 594 | [accountUIDtoAccount setObject:newAcct forKey:[NSString stringWithFormat:@"%@-%@@%@", serviceName, accountName, connectHost]]; |
| 595 | [[adium accountController] addAccount:newAcct]; |
| 596 | [[adium notificationCenter] addObserver:self |
| 597 | selector:@selector(accountConnected:) |
| 598 | name:ACCOUNT_CONNECTED@ "Account_Connected" |
| 599 | object:newAcct]; |
| 600 | |
| 601 | [self retain]; |
| 602 | [newAcct setShouldBeOnline:YES( BOOL ) 1]; |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | - (void)importAways1:(NSArray *)awayList |
| 608 | { |
| 609 | NSEnumerator *awayEnum = [awayList objectEnumerator]; |
| 610 | NSDictionary *away = nil0; |
| 611 | while((away = [awayEnum nextObject]) != nil0) |
| 612 | { |
| 613 | NSString *title = [away objectForKey:@"Title"]; |
| 614 | BOOL isDefault = [[away objectForKey:@"isIdleMessage"] boolValue]; |
| 615 | BOOL goIdle = [[away objectForKey:@"idleMessage"] boolValue]; |
| 616 | NSString *message = [away objectForKey:@"message"]; |
| 617 | int fireType = [[away objectForKey:@"messageType"] intValue]; |
| 618 | AIStatusType adiumType = 0; |
| 619 | |
| 620 | switch(fireType) |
| 621 | { |
| 622 | case 0: |
| 623 | case 1: |
| 624 | adiumType = AIAvailableStatusType; |
| 625 | break; |
| 626 | case 4: |
| 627 | adiumType = AIInvisibleStatusType; |
| 628 | case 3: |
| 629 | case 2: |
| 630 | default: |
| 631 | adiumType = AIAwayStatusType; |
| 632 | } |
| 633 | |
| 634 | AIStatus *newStatus = [AIStatus statusOfType:adiumType]; |
| 635 | [newStatus setTitle:title]; |
| 636 | [newStatus setStatusMessage:[[[NSAttributedString alloc] initWithString:message] autorelease]]; |
| 637 | [newStatus setAutoReplyIsStatusMessage:YES( BOOL ) 1]; |
| 638 | [newStatus setShouldForceInitialIdleTime:goIdle]; |
| 639 | if(isDefault) |
| 640 | [[adium preferenceController] setPreference:[newStatus uniqueStatusID] |
| 641 | forKey:KEY_STATUS_AUTO_AWAY_STATUS_STATE_ID@ "Auto Away Status State ID" |
| 642 | group:PREF_GROUP_STATUS_PREFERENCES@ "Status Preferences"]; |
| 643 | [[adium statusController] addStatusState:newStatus]; |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | - (void)importBuddies1:(NSArray *)buddyArray |
| 648 | toGroup:(NSString *)groupName |
| 649 | { |
| 650 | NSEnumerator *buddyEnum = [buddyArray objectEnumerator]; |
| 651 | NSDictionary *buddy = nil0; |
| 652 | while((buddy = [buddyEnum nextObject]) != nil0) |
| 653 | { |
| 654 | NSString *buddyName = [buddy objectForKey:@"buddyname"]; |
| 655 | if([buddyName length] == 0) |
| 656 | continue; |
| 657 | |
| 658 | NSDictionary *permissionsDict = [buddy objectForKey:@"BuddyPermissions"]; |
| 659 | NSMutableArray *accounts = [NSMutableArray array]; |
| 660 | if(permissionsDict != nil0) |
| 661 | { |
| 662 | NSEnumerator *permissionsEnum = [permissionsDict keyEnumerator]; |
| 663 | NSString *accountKey = nil0; |
| 664 | while ((accountKey = [permissionsEnum nextObject]) != nil0) |
| 665 | { |
| 666 | AIAccount *acct = [accountUIDtoAccount objectForKey:accountKey]; |
| 667 | if(acct != nil0 && [[[permissionsDict objectForKey:accountKey] objectForKey:@"BuddyinList"] boolValue]) |
| 668 | [accounts addObject:acct]; |
| 669 | } |
| 670 | } |
| 671 | else |
| 672 | { |
| 673 | NSEnumerator *acctEnum = [accountUIDtoAccount objectEnumerator]; |
| 674 | AIAccount *acct = nil0; |
| 675 | while ((acct = [acctEnum nextObject]) != nil0) |
| 676 | { |
| 677 | if([[acct serviceClass] isEqualToString:[buddy objectForKey:@"service"]]) |
| 678 | [accounts addObject:acct]; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | NSEnumerator *accountEnum = [accounts objectEnumerator]; |
| 683 | AIAccount *account = nil0; |
| 684 | while ((account = [accountEnum nextObject]) != nil0) |
| 685 | { |
| 686 | GBFireImportedBuddy *newContact = [[GBFireImportedBuddy alloc] initScreenname:buddyName forAccount:account]; |
| 687 | if(newContact == nil0) |
| 688 | continue; |
| 689 | |
| 690 | NSString *alias = [buddy objectForKey:@"displayname"]; |
| 691 | if([alias length] != 0) |
| 692 | { |
| 693 | [newContact setDisplayName:alias]; |
| 694 | NSMutableArray *contactArray = [aliasToContacts objectForKey:alias]; |
| 695 | if(contactArray == nil0) |
| 696 | { |
| 697 | contactArray = [NSMutableArray array]; |
| 698 | [aliasToContacts setObject:contactArray forKey:alias]; |
| 699 | } |
| 700 | [contactArray addObject:newContact]; |
| 701 | } |
| 702 | |
| 703 | if([groupName length] != 0) |
| 704 | [newContact setGroup:groupName]; |
| 705 | [newContact release]; |
| 706 | } |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | - (void)importGroups1:(NSDictionary *)groupList |
| 711 | { |
| 712 | id <AIContactController> contactController = [adium contactController]; |
| 713 | |
| 714 | |
| 715 | NSEnumerator *groupEnum = [groupList keyEnumerator]; |
| 716 | NSString *groupName = nil0; |
| 717 | NSMutableArray *groupArray = [NSMutableArray array]; |
| 718 | while((groupName = [groupEnum nextObject]) != nil0) |
| 719 | { |
| 720 | NSMutableDictionary *groupDict = [[groupList objectForKey:groupName] mutableCopy]; |
| 721 | [groupDict setObject:groupName forKey:@"Name"]; |
| 722 | [groupArray addObject:groupDict]; |
| 723 | [groupDict release]; |
| 724 | } |
| 725 | [groupArray sortUsingFunction:groupSort context:NULL( ( void * ) 0 )]; |
| 726 | groupEnum = [groupArray objectEnumerator]; |
| 727 | NSDictionary *group = nil0; |
| 728 | while((group = [groupEnum nextObject]) != nil0) |
| 729 | { |
| 730 | NSString *groupName = [group objectForKey:@"Name"]; |
| 731 | AIListGroup *newGroup = [contactController groupWithUID:groupName]; |
| 732 | NSNumber *expanded = [group objectForKey:@"groupexpanded"]; |
| 733 | if(expanded != nil0) |
| 734 | [newGroup setExpanded:[expanded boolValue]]; |
| 735 | [self importBuddies1:[group objectForKey:@"buddies"] |
| 736 | toGroup:groupName]; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | - (BOOL)import1:(NSString *)fireDir |
| 741 | { |
| 742 | NSString *configPath = [fireDir stringByAppendingPathComponent:FIRECONFIGURATION@ "FireConfiguration.plist"]; |
| 743 | NSString *accountPath = [fireDir stringByAppendingPathComponent:ACCOUNTS@ "Accounts.plist"]; |
| 744 | NSDictionary *configDict = [NSDictionary dictionaryWithContentsOfFile:configPath]; |
| 745 | NSDictionary *accountDict = [NSDictionary dictionaryWithContentsOfFile:accountPath]; |
| 746 | |
| 747 | if(configDict == nil0 || accountDict == nil0) |
| 748 | |
| 749 | return NO( BOOL ) 0; |
| 750 | |
| 751 | |
| 752 | [self importAccounts1:accountDict]; |
| 753 | |
| 754 | |
| 755 | [self importAways1:[configDict objectForKey:@"awayMessages"]]; |
| 756 | |
| 757 | |
| 758 | [self importGroups1:[configDict objectForKey:@"groups"]]; |
| 759 | |
| 760 | |
| 761 | [self createMetaContacts]; |
| 762 | |
| 763 | return YES( BOOL ) 1; |
| 764 | } |
| 765 | |
| 766 | @end |