| 321 | | unsigned int ip = 0; |
|---|
| 322 | | BOOL ipAddress = ( sscanf( [server UTF8String], "%u.%u.%u.%u", &ip, &ip, &ip, &ip ) == 4 ); |
|---|
| 323 | | |
|---|
| 324 | | if( ! ipAddress ) { |
|---|
| 325 | | NSArray *parts = [server componentsSeparatedByString:@"."]; |
|---|
| 326 | | unsigned count = [parts count]; |
|---|
| 327 | | if( count > 2 ) |
|---|
| 328 | | server = [NSString stringWithFormat:@"%@.%@", [parts objectAtIndex:(count - 2)], [parts objectAtIndex:(count - 1)]]; |
|---|
| 329 | | } |
|---|
| 330 | | |
|---|
| 331 | | [newServers addObject:server]; |
|---|
| | 321 | server = [server stringWithDomainNameSegmentOfAddress]; |
|---|
| | 322 | if( [server length] ) |
|---|
| | 323 | [newServers addObject:server]; |
|---|
| | 1017 | - (void) _importOldBuddyList { |
|---|
| | 1018 | NSArray *list = [[NSUserDefaults standardUserDefaults] objectForKey:@"JVChatBuddies"]; |
|---|
| | 1019 | if( ! [list count] ) return; |
|---|
| | 1020 | |
|---|
| | 1021 | NSEnumerator *enumerator = [list objectEnumerator]; |
|---|
| | 1022 | NSString *identifier = nil; |
|---|
| | 1023 | |
|---|
| | 1024 | while( ( identifier = [enumerator nextObject] ) ) { |
|---|
| | 1025 | ABPerson *person = (ABPerson *)[[ABAddressBook sharedAddressBook] recordForUniqueId:identifier]; |
|---|
| | 1026 | if( ! person ) continue; |
|---|
| | 1027 | |
|---|
| | 1028 | JVBuddy *buddy = [[JVBuddy allocWithZone:[self zone]] init]; |
|---|
| | 1029 | |
|---|
| | 1030 | [buddy setPicture:[[[NSImage alloc] initWithData:[person imageData]] autorelease]]; |
|---|
| | 1031 | [buddy setGivenNickname:[person valueForProperty:kABNicknameProperty]]; |
|---|
| | 1032 | [buddy setFirstName:[person valueForProperty:kABFirstNameProperty]]; |
|---|
| | 1033 | [buddy setLastName:[person valueForProperty:kABLastNameProperty]]; |
|---|
| | 1034 | |
|---|
| | 1035 | ABMultiValue *value = [person valueForProperty:kABEmailProperty]; |
|---|
| | 1036 | [buddy setPrimaryEmail:[value valueAtIndex:[value indexForIdentifier:[value primaryIdentifier]]]]; |
|---|
| | 1037 | |
|---|
| | 1038 | [buddy setSpeechVoice:[person valueForProperty:@"cc.javelin.colloquy.JVBuddy.TTSvoice"]]; |
|---|
| | 1039 | |
|---|
| | 1040 | [buddy setAddressBookPersonRecord:person]; |
|---|
| | 1041 | |
|---|
| | 1042 | value = [person valueForProperty:@"IRCNickname"]; |
|---|
| | 1043 | unsigned count = [value count]; |
|---|
| | 1044 | |
|---|
| | 1045 | for( unsigned i = 0; i < count; i++ ) { |
|---|
| | 1046 | NSString *nick = [value valueAtIndex:i]; |
|---|
| | 1047 | NSString *server = [[value labelAtIndex:i] stringWithDomainNameSegmentOfAddress]; |
|---|
| | 1048 | if( ! [nick length] || ! [server length] ) |
|---|
| | 1049 | continue; |
|---|
| | 1050 | |
|---|
| | 1051 | MVChatUserWatchRule *rule = [[MVChatUserWatchRule allocWithZone:nil] init]; |
|---|
| | 1052 | [rule setNickname:nick]; |
|---|
| | 1053 | [rule setApplicableServerDomains:[NSArray arrayWithObject:server]]; |
|---|
| | 1054 | |
|---|
| | 1055 | [buddy addWatchRule:rule]; |
|---|
| | 1056 | |
|---|
| | 1057 | [rule release]; |
|---|
| | 1058 | } |
|---|
| | 1059 | |
|---|
| | 1060 | if( buddy && [[buddy watchRules] count] ) |
|---|
| | 1061 | [self addBuddy:buddy]; |
|---|
| | 1062 | |
|---|
| | 1063 | [buddy release]; |
|---|
| | 1064 | } |
|---|
| | 1065 | |
|---|
| | 1066 | [self save]; |
|---|
| | 1067 | |
|---|
| | 1068 | [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"JVChatBuddies"]; |
|---|
| | 1069 | } |
|---|
| | 1070 | |
|---|