Changeset 3488
- Timestamp:
- 12/26/06 16:05:10 (2 years ago)
- Files:
-
- trunk/Controllers/MVBuddyListController.h (modified) (2 diffs)
- trunk/Controllers/MVBuddyListController.m (modified) (21 diffs)
- trunk/Languages/English.lproj/MVBuddyList.nib/classes.nib (added)
- trunk/Languages/English.lproj/MVBuddyList.nib/info.nib (modified) (1 diff)
- trunk/Languages/English.lproj/MVBuddyList.nib/keyedobjects.nib (added)
- trunk/Models/JVBuddy.h (modified) (1 diff)
- trunk/Models/JVBuddy.m (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Controllers/MVBuddyListController.h
r3484 r3488 27 27 IBOutlet NSWindow *newPersonWindow; 28 28 IBOutlet NSTextField *nickname; 29 IBOutlet NS PopUpButton *server;29 IBOutlet NSTableView *servers; 30 30 IBOutlet NSTextField *firstName; 31 31 IBOutlet NSTextField *lastName; … … 34 34 IBOutlet NSButton *addButton; 35 35 36 NSString *_addPerson; 37 NSMutableSet *_addServers; 38 36 39 NSMutableSet *_buddyList; 37 40 NSMutableSet *_onlineBuddies; 38 41 NSMutableArray *_buddyOrder; 39 NSString *_addPerson;40 42 41 43 BOOL _showFullNames; trunk/Controllers/MVBuddyListController.m
r3484 r3488 11 11 static MVBuddyListController *sharedInstance = nil; 12 12 13 @interface ABPerson (ABPersonPrivate)14 + (ABPerson *) personFromDictionary:(NSDictionary *) dictionary;15 - (NSDictionary *) dictionaryRepresentation;16 @end17 18 #pragma mark -19 20 13 @interface MVBuddyListController (MVBuddyListControllerPrivate) 21 14 - (void) _loadBuddyList; … … 30 23 31 24 @implementation MVBuddyListController 32 + (void) initialize {33 [ABPerson addPropertiesAndTypes:[NSDictionary dictionaryWithObjectsAndKeys:34 [NSNumber numberWithUnsignedInt:kABMultiStringProperty], JVBuddyAddressBookIRCNicknameProperty,35 [NSNumber numberWithUnsignedInt:kABStringProperty], JVBuddyAddressBookSpeechVoiceProperty, nil]];36 }37 38 25 + (MVBuddyListController *) sharedBuddyList { 39 26 return ( sharedInstance ? sharedInstance : ( sharedInstance = [[self alloc] initWithWindowNibName:nil] ) ); … … 87 74 [_oldPositions release]; 88 75 [_addPerson release]; 76 [_addServers release]; 89 77 90 78 _onlineBuddies = nil; … … 93 81 _oldPositions = nil; 94 82 _addPerson = nil; 83 _addServers = nil; 95 84 96 85 [super dealloc]; … … 113 102 [theColumn setDataCell:prototypeCell]; 114 103 115 [pickerView addProperty:JVBuddyAddressBookIRCNicknameProperty]; 116 [pickerView setColumnTitle:NSLocalizedString( @"IRC Nickname", "irc nickname buddy picker column title" ) forProperty:JVBuddyAddressBookIRCNicknameProperty]; 104 [pickerView addProperty:kABNicknameProperty]; 105 [pickerView addProperty:kABAIMInstantProperty]; 106 [pickerView addProperty:kABJabberInstantProperty]; 107 [pickerView addProperty:kABMSNInstantProperty]; 108 [pickerView addProperty:kABYahooInstantProperty]; 109 [pickerView addProperty:kABICQInstantProperty]; 110 [pickerView addProperty:kABEmailProperty]; 117 111 118 112 [pickerView setAllowsMultipleSelection:NO]; … … 203 197 } 204 198 205 [_addPerson autorelease];199 [_addPerson release]; 206 200 _addPerson = nil; 207 208 NSEnumerator *enumerator = [[[MVConnectionsController defaultController] connections] objectEnumerator];209 MVChatConnection *connection = nil;210 NSMenu *menu = [[[NSMenu alloc] initWithTitle:@""] autorelease];211 NSMenuItem *item = nil;212 213 while( ( connection = [enumerator nextObject] ) ) {214 item = [[[NSMenuItem alloc] initWithTitle:[connection server] action:NULL keyEquivalent:@""] autorelease];215 [menu addItem:item];216 }217 218 [server setMenu:menu];219 220 [firstName setObjectValue:@""];221 [lastName setObjectValue:@""];222 [email setObjectValue:@""];223 [image setImage:nil];224 201 225 202 [[NSApplication sharedApplication] beginSheet:pickerWindow modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; … … 240 217 241 218 ABPerson *person = [[pickerView selectedRecords] lastObject]; 242 243 if( ! [(NSDictionary *)[person valueForProperty:JVBuddyAddressBookIRCNicknameProperty] count] ) { 244 [_addPerson autorelease]; 245 _addPerson = [[person uniqueId] copy]; 246 [self showNewPersonSheet:nil]; 247 } else { 248 // JVBuddy *buddy = [JVBuddy buddyWithPerson:person]; 249 // [self _addBuddyToList:buddy]; 250 [self save]; 251 } 219 [_addPerson release]; 220 _addPerson = [[person uniqueId] copy]; 221 222 [self showNewPersonSheet:nil]; 252 223 } 253 224 … … 260 231 } 261 232 262 ABPerson *person = nil; 263 if( _addPerson ) person = (ABPerson *)[[ABAddressBook sharedAddressBook] recordForUniqueId:_addPerson]; 264 if( person ) { 265 [firstName setObjectValue:[person valueForProperty:kABFirstNameProperty]]; 266 [lastName setObjectValue:[person valueForProperty:kABLastNameProperty]]; 267 ABMultiValue *value = [person valueForProperty:kABEmailProperty]; 268 unsigned index = [value indexForIdentifier:[value primaryIdentifier]]; 269 if( index != NSNotFound ) [email setObjectValue:[value valueAtIndex:index]]; 270 [image setImage:[[[NSImage alloc] initWithData:[person imageData]] autorelease]]; 271 } 233 [_addServers release]; 234 _addServers = [[NSMutableSet allocWithZone:nil] init]; 235 236 [servers reloadData]; 237 238 if( _addPerson ) { 239 ABPerson *person = (ABPerson *)[[ABAddressBook sharedAddressBook] recordForUniqueId:_addPerson]; 240 if( person ) { 241 [nickname setObjectValue:[person valueForProperty:kABNicknameProperty]]; 242 [firstName setObjectValue:[person valueForProperty:kABFirstNameProperty]]; 243 [lastName setObjectValue:[person valueForProperty:kABLastNameProperty]]; 244 245 ABMultiValue *value = [person valueForProperty:kABEmailProperty]; 246 unsigned index = [value indexForIdentifier:[value primaryIdentifier]]; 247 if( index != NSNotFound ) [email setObjectValue:[value valueAtIndex:index]]; 248 249 [image setImage:[[[NSImage alloc] initWithData:[person imageData]] autorelease]]; 250 } 251 } else { 252 [nickname setObjectValue:@""]; 253 [firstName setObjectValue:@""]; 254 [lastName setObjectValue:@""]; 255 [email setObjectValue:@""]; 256 [image setImage:nil]; 257 } 258 259 if( [[nickname stringValue] length] && [_addServers count] ) 260 [addButton setEnabled:YES]; 261 else [addButton setEnabled:NO]; 272 262 273 263 [[NSApplication sharedApplication] beginSheet:newPersonWindow modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; … … 280 270 } 281 271 282 [_addPerson autorelease];272 [_addPerson release]; 283 273 _addPerson = nil; 274 275 [_addServers release]; 276 _addServers = nil; 284 277 } 285 278 … … 290 283 } 291 284 292 ABPerson *person = nil; 293 if( _addPerson ) person = (ABPerson *)[[ABAddressBook sharedAddressBook] recordForUniqueId:_addPerson]; 294 if( ! person ) { 295 NSMutableDictionary *info = [NSMutableDictionary dictionary]; 296 NSMutableDictionary *sub = nil; 297 298 if( [(NSString *)[firstName objectValue] length] || [(NSString *)[lastName objectValue] length] || [(NSString *)[email objectValue] length] ) { 299 [info setObject:[firstName objectValue] forKey:kABFirstNameProperty]; 300 } else [info setObject:[nickname objectValue] forKey:kABFirstNameProperty]; 301 302 if( [(NSString *)[lastName objectValue] length] ) 303 [info setObject:[lastName objectValue] forKey:kABLastNameProperty]; 304 305 if( [(NSString *)[email objectValue] length] ) { 306 sub = [NSMutableDictionary dictionary]; 307 [sub setObject:[NSArray arrayWithObject:kABOtherLabel] forKey:@"labels"]; 308 [sub setObject:[NSArray arrayWithObject:[email objectValue]] forKey:@"values"]; 309 [info setObject:sub forKey:kABEmailProperty]; 310 } 311 312 sub = [NSMutableDictionary dictionary]; 313 [sub setObject:[NSArray arrayWithObject:[server titleOfSelectedItem]] forKey:@"labels"]; 314 [sub setObject:[NSArray arrayWithObject:[nickname objectValue]] forKey:@"values"]; 315 [info setObject:sub forKey:JVBuddyAddressBookIRCNicknameProperty]; 316 317 [info setObject:[NSString stringWithFormat:NSLocalizedString( @"IRC Nickname: %@ (%@)", "new buddy card note" ), [nickname objectValue], [server titleOfSelectedItem]] forKey:kABNoteProperty]; 318 319 person = [ABPerson personFromDictionary:info]; 320 321 [person setImageData:[[image image] TIFFRepresentation]]; 322 323 [[ABAddressBook sharedAddressBook] addRecord:person]; 324 [[ABAddressBook sharedAddressBook] save]; 325 } else { 326 ABMutableMultiValue *value = [[[ABMutableMultiValue alloc] init] autorelease]; 327 [value addValue:[nickname objectValue] withLabel:[server titleOfSelectedItem]]; 328 [person setValue:value forProperty:JVBuddyAddressBookIRCNicknameProperty]; 329 330 if( [(NSString *)[firstName objectValue] length] || [(NSString *)[lastName objectValue] length] || [(NSString *)[email objectValue] length] ) { 331 [person setValue:[firstName objectValue] forProperty:kABFirstNameProperty]; 332 } else [person setValue:[nickname objectValue] forProperty:kABFirstNameProperty]; 333 [person setValue:[lastName objectValue] forProperty:kABLastNameProperty]; 334 335 ABMutableMultiValue *emailValue = [[[person valueForProperty:kABEmailProperty] mutableCopy] autorelease]; 336 unsigned index = [emailValue indexForIdentifier:[emailValue primaryIdentifier]]; 337 if( emailValue && index != NSNotFound ) { 338 [emailValue replaceValueAtIndex:index withValue:[email objectValue]]; 339 } else if( [(NSString *)[email objectValue] length] ) { 340 emailValue = [[[ABMutableMultiValue alloc] init] autorelease]; 341 [emailValue addValue:[email objectValue] withLabel:kABOtherLabel]; 342 } 343 344 if( [emailValue count] ) 345 [person setValue:emailValue forProperty:kABEmailProperty]; 346 347 [person setImageData:[[image image] TIFFRepresentation]]; 348 349 [[ABAddressBook sharedAddressBook] save]; 350 } 351 352 if( person ) { 353 // JVBuddy *buddy = [JVBuddy buddyWithPerson:person]; 354 // [self _addBuddyToList:buddy]; 355 [self save]; 356 } 357 358 [_addPerson autorelease]; 285 JVBuddy *buddy = [[JVBuddy allocWithZone:nil] init]; 286 287 [buddy setGivenNickname:[nickname stringValue]]; 288 [buddy setFirstName:[firstName stringValue]]; 289 [buddy setLastName:[lastName stringValue]]; 290 [buddy setPrimaryEmail:[email stringValue]]; 291 [buddy setPicture:[image image]]; 292 293 if( _addPerson ) { 294 ABPerson *person = (ABPerson *)[[ABAddressBook sharedAddressBook] recordForUniqueId:_addPerson]; 295 if( person ) [buddy setAddressBookPersonRecord:person]; 296 } 297 298 MVChatUserWatchRule *rule = [[MVChatUserWatchRule allocWithZone:nil] init]; 299 [rule setNickname:[nickname stringValue]]; 300 [rule setApplicableServerDomains:[_addServers allObjects]]; 301 [buddy addWatchRule:rule]; 302 303 [self _addBuddyToList:buddy]; 304 [self save]; 305 306 [_addPerson release]; 359 307 _addPerson = nil; 308 309 [_addServers release]; 310 _addServers = nil; 360 311 } 361 312 362 313 - (void) controlTextDidChange:(NSNotification *) notification { 363 if( [(NSString *)[nickname objectValue] length] >= 1 ) [addButton setEnabled:YES]; 314 if( [[nickname stringValue] length] && [_addServers count] ) 315 [addButton setEnabled:YES]; 364 316 else [addButton setEnabled:NO]; 365 317 } … … 388 340 389 341 - (void) setNewBuddyServer:(MVChatConnection *) connection { 390 [server selectItemWithTitle:[connection server]];342 391 343 } 392 344 … … 606 558 607 559 - (id) tableView:(NSTableView *) view objectValueForTableColumn:(NSTableColumn *) column row:(int) row { 608 if( row == -1 || row >= (int)[_buddyOrder count] ) return nil; 560 if( view == servers ) { 561 MVChatConnection *connection = [[[MVConnectionsController defaultController] connections] objectAtIndex:row]; 562 if( [[column identifier] isEqualToString:@"domain"] ) 563 return [connection server]; 564 return nil; 565 } 566 567 if( view != buddies || row == -1 || row >= (int)[_buddyOrder count] ) 568 return nil; 609 569 610 570 if( [[column identifier] isEqualToString:@"buddy"] ) { … … 625 585 626 586 - (void) tableView:(NSTableView *) view willDisplayCell:(id) cell forTableColumn:(NSTableColumn *) column row:(int) row { 627 if( row == -1 || row >= (int)[_buddyOrder count] ) return; 587 if( view == servers ) { 588 MVChatConnection *connection = [[[MVConnectionsController defaultController] connections] objectAtIndex:row]; 589 if( [[column identifier] isEqualToString:@"check"] ) 590 [cell setState:( [_addServers containsObject:[connection server]] )]; 591 return; 592 } 593 594 if( view != buddies || row == -1 || row >= (int)[_buddyOrder count] ) 595 return; 596 628 597 if( [[column identifier] isEqualToString:@"buddy"] ) { 629 598 JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; … … 693 662 694 663 - (void) tableView:(NSTableView *) tableView setObjectValue:(id) object forTableColumn:(NSTableColumn *) tableColumn row:(int) row { 695 if( row == -1 || row >= (int)[_buddyOrder count] ) return; 664 if( tableView == servers ) { 665 if( [[tableColumn identifier] isEqualToString:@"check"] ) { 666 if( [object isKindOfClass:[NSNumber class]] ) { 667 MVChatConnection *connection = [[[MVConnectionsController defaultController] connections] objectAtIndex:row]; 668 if( [object boolValue] ) [_addServers addObject:[connection server]]; 669 else [_addServers removeObject:[connection server]]; 670 671 if( [[nickname stringValue] length] && [_addServers count] ) 672 [addButton setEnabled:YES]; 673 else [addButton setEnabled:NO]; 674 } 675 } 676 677 return; 678 } 679 680 if( tableView != buddies || row == -1 || row >= (int)[_buddyOrder count] ) 681 return; 682 696 683 JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; 697 684 id users = [buddy users]; … … 712 699 713 700 - (NSMenu *) tableView:(MVTableView *) tableView menuForTableColumn:(NSTableColumn *) tableColumn row:(int) row { 701 if( tableView != buddies ) return nil; 702 714 703 NSMenu *menu = [[actionMenu copyWithZone:[self zone]] autorelease]; 715 704 JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; … … 745 734 746 735 - (NSString *) tableView:(MVTableView *) tableView toolTipForTableColumn:(NSTableColumn *) column row:(int) row { 747 if( row == -1 || row >= (int)[_buddyOrder count] ) return nil; 736 if( tableView != buddies || row == -1 || row >= (int)[_buddyOrder count] ) return nil; 737 748 738 NSMutableString *ret = [NSMutableString string]; 749 739 JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; … … 769 759 770 760 - (void) tableViewSelectionDidChange:(NSNotification *) notification { 761 if( [notification object] != buddies ) return; 762 771 763 BOOL enabled = ! ( [buddies selectedRow] == -1 ); 772 764 [sendMessageButton setEnabled:enabled]; … … 776 768 777 769 - (NSDragOperation) tableView:(NSTableView *) tableView validateDrop:(id <NSDraggingInfo>) info proposedRow:(int) row proposedDropOperation:(NSTableViewDropOperation) operation { 770 if( tableView != buddies ) return NSDragOperationNone; 771 778 772 if( operation == NSTableViewDropOn && row != -1 ) 779 773 return NSDragOperationMove; … … 782 776 783 777 - (BOOL) tableView:(NSTableView *) tableView acceptDrop:(id <NSDraggingInfo>) info row:(int) row dropOperation:(NSTableViewDropOperation) operation { 778 if( tableView != buddies ) return NO; 779 784 780 NSPasteboard *board = [info draggingPasteboard]; 785 781 if( [board availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] ) { … … 801 797 802 798 - (NSRange) tableView:(MVTableView *) tableView rowsInRect:(NSRect) rect defaultRange:(NSRange) defaultRange { 799 if( tableView != buddies ) return defaultRange; 800 803 801 if( _animating ) return NSMakeRange( 0, [_buddyOrder count] ); 804 802 else return defaultRange; … … 979 977 [self _manuallySortAndUpdate]; 980 978 } 979 980 [buddy registerWithApplicableConnections]; 981 981 } 982 982 trunk/Languages/English.lproj/MVBuddyList.nib/info.nib
r3205 r3488 10 10 <string>552 603 220 194 0 0 1280 832 </string> 11 11 <key>168</key> 12 <string>460 587 132 870 0 1440 878 </string>12 <string>460 587 132 99 0 0 1440 878 </string> 13 13 </dict> 14 14 <key>IBFramework Version</key> 15 <string>4 43.0</string>15 <string>454.0</string> 16 16 <key>IBLockedObjects</key> 17 17 <array/> 18 18 <key>IBOpenObjects</key> 19 19 <array> 20 <integer>115</integer> 21 <integer>80</integer> 20 22 <integer>168</integer> 21 <integer>41</integer>22 <integer>80</integer>23 23 </array> 24 24 <key>IBSystem Version</key> 25 <string> 8I1119</string>25 <string>9A321</string> 26 26 </dict> 27 27 </plist> trunk/Models/JVBuddy.h
r3487 r3488 83 83 84 84 - (ABPerson *) addressBookPersonRecord; 85 - (void) setAddressBookPersonRecord:(ABPerson *) record; 85 86 - (void) editInAddressBook; 86 87 - (void) viewInAddressBook; trunk/Models/JVBuddy.m
r3487 r3488 30 30 #pragma mark - 31 31 32 - (id) init WithDictionaryRepresentation:(NSDictionary *) dictionary{32 - (id) init { 33 33 if( ( self = [super init] ) ) { 34 34 _rules = [[NSMutableArray allocWithZone:nil] initWithCapacity:5]; 35 35 _users = [[NSMutableArray allocWithZone:nil] initWithCapacity:5]; 36 36 _uniqueIdentifier = [[NSString locallyUniqueString] retain]; 37 38 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( _registerWithConnection: ) name:MVChatConnectionDidConnectNotification object:nil]; 39 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( _disconnected: ) name:MVChatConnectionDidDisconnectNotification object:nil]; 40 } 41 42 return self; 43 } 44 45 - (id) initWithDictionaryRepresentation:(NSDictionary *) dictionary { 46 if( ( self = [self init] ) ) { 37 47 NSData *data = [dictionary objectForKey:@"picture"]; 38 48 if( [data isKindOfClass:[NSData class]] && [data length] ) … … 60 70 61 71 string = [dictionary objectForKey:@"uniqueIdentifier"]; 62 if( [string isKindOfClass:[NSString class]] ) 72 if( [string isKindOfClass:[NSString class]] ) { 73 [_uniqueIdentifier release]; 63 74 _uniqueIdentifier = [string copyWithZone:nil]; 64 if( ! [_uniqueIdentifier length] ) 75 } 76 77 if( ! [_uniqueIdentifier length] ) { 78 [_uniqueIdentifier release]; 65 79 _uniqueIdentifier = [[NSString locallyUniqueString] retain]; 80 } 66 81 67 82 string = [dictionary objectForKey:@"addressBookPersonRecord"]; … … 76 91 [rule release]; 77 92 } 78 79 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( _registerWithConnection: ) name:MVChatConnectionDidConnectNotification object:nil];80 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( _disconnected: ) name:MVChatConnectionDidDisconnectNotification object:nil];81 82 [self registerWithApplicableConnections];83 93 } 84 94 … … 431 441 } 432 442 443 - (void) setAddressBookPersonRecord:(ABPerson *) record { 444 id old = _person; 445 _person = [record retain]; 446 [old release]; 447 } 448 433 449 - (void) editInAddressBook { 434 450 if( ! _person ) return;
