Changeset 3488

Show
Ignore:
Timestamp:
12/26/06 16:05:10 (2 years ago)
Author:
timothy
Message:

Hooks up the create buddy interface to the new buddy list code. The buddy list has returned!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Controllers/MVBuddyListController.h

    r3484 r3488  
    2727        IBOutlet NSWindow *newPersonWindow; 
    2828        IBOutlet NSTextField *nickname; 
    29         IBOutlet NSPopUpButton *server
     29        IBOutlet NSTableView *servers
    3030        IBOutlet NSTextField *firstName; 
    3131        IBOutlet NSTextField *lastName; 
     
    3434        IBOutlet NSButton *addButton; 
    3535 
     36        NSString *_addPerson; 
     37        NSMutableSet *_addServers; 
     38 
    3639        NSMutableSet *_buddyList; 
    3740        NSMutableSet *_onlineBuddies; 
    3841        NSMutableArray *_buddyOrder; 
    39         NSString *_addPerson; 
    4042 
    4143        BOOL _showFullNames; 
  • trunk/Controllers/MVBuddyListController.m

    r3484 r3488  
    1111static MVBuddyListController *sharedInstance = nil; 
    1212 
    13 @interface ABPerson (ABPersonPrivate) 
    14 + (ABPerson *) personFromDictionary:(NSDictionary *) dictionary; 
    15 - (NSDictionary *) dictionaryRepresentation; 
    16 @end 
    17  
    18 #pragma mark - 
    19  
    2013@interface MVBuddyListController (MVBuddyListControllerPrivate) 
    2114- (void) _loadBuddyList; 
     
    3023 
    3124@implementation MVBuddyListController 
    32 + (void) initialize { 
    33         [ABPerson addPropertiesAndTypes:[NSDictionary dictionaryWithObjectsAndKeys: 
    34                 [NSNumber numberWithUnsignedInt:kABMultiStringProperty], JVBuddyAddressBookIRCNicknameProperty, 
    35                 [NSNumber numberWithUnsignedInt:kABStringProperty], JVBuddyAddressBookSpeechVoiceProperty, nil]]; 
    36 } 
    37  
    3825+ (MVBuddyListController *) sharedBuddyList { 
    3926        return ( sharedInstance ? sharedInstance : ( sharedInstance = [[self alloc] initWithWindowNibName:nil] ) ); 
     
    8774        [_oldPositions release]; 
    8875        [_addPerson release]; 
     76        [_addServers release]; 
    8977 
    9078        _onlineBuddies = nil; 
     
    9381        _oldPositions = nil; 
    9482        _addPerson = nil; 
     83        _addServers = nil; 
    9584 
    9685        [super dealloc]; 
     
    113102        [theColumn setDataCell:prototypeCell]; 
    114103 
    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]; 
    117111 
    118112        [pickerView setAllowsMultipleSelection:NO]; 
     
    203197        } 
    204198 
    205         [_addPerson autorelease]; 
     199        [_addPerson release]; 
    206200        _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]; 
    224201 
    225202        [[NSApplication sharedApplication] beginSheet:pickerWindow modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; 
     
    240217 
    241218        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]; 
    252223} 
    253224 
     
    260231        } 
    261232 
    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]; 
    272262 
    273263        [[NSApplication sharedApplication] beginSheet:newPersonWindow modalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL]; 
     
    280270        } 
    281271 
    282         [_addPerson autorelease]; 
     272        [_addPerson release]; 
    283273        _addPerson = nil; 
     274 
     275        [_addServers release]; 
     276        _addServers = nil; 
    284277} 
    285278 
     
    290283        } 
    291284 
    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]; 
    359307        _addPerson = nil; 
     308 
     309        [_addServers release]; 
     310        _addServers = nil; 
    360311} 
    361312 
    362313- (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]; 
    364316        else [addButton setEnabled:NO]; 
    365317} 
     
    388340 
    389341- (void) setNewBuddyServer:(MVChatConnection *) connection { 
    390         [server selectItemWithTitle:[connection server]]; 
     342         
    391343} 
    392344 
     
    606558 
    607559- (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; 
    609569 
    610570        if( [[column identifier] isEqualToString:@"buddy"] ) { 
     
    625585 
    626586- (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 
    628597        if( [[column identifier] isEqualToString:@"buddy"] ) { 
    629598                JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; 
     
    693662 
    694663- (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 
    696683        JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; 
    697684        id users = [buddy users]; 
     
    712699 
    713700- (NSMenu *) tableView:(MVTableView *) tableView menuForTableColumn:(NSTableColumn *) tableColumn row:(int) row { 
     701        if( tableView != buddies ) return nil; 
     702 
    714703        NSMenu *menu = [[actionMenu copyWithZone:[self zone]] autorelease]; 
    715704        JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; 
     
    745734 
    746735- (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 
    748738        NSMutableString *ret = [NSMutableString string]; 
    749739        JVBuddy *buddy = [_buddyOrder objectAtIndex:row]; 
     
    769759 
    770760- (void) tableViewSelectionDidChange:(NSNotification *) notification { 
     761        if( [notification object] != buddies ) return; 
     762 
    771763        BOOL enabled = ! ( [buddies selectedRow] == -1 ); 
    772764        [sendMessageButton setEnabled:enabled]; 
     
    776768 
    777769- (NSDragOperation) tableView:(NSTableView *) tableView validateDrop:(id <NSDraggingInfo>) info proposedRow:(int) row proposedDropOperation:(NSTableViewDropOperation) operation { 
     770        if( tableView != buddies ) return NSDragOperationNone; 
     771 
    778772        if( operation == NSTableViewDropOn && row != -1 ) 
    779773                return NSDragOperationMove; 
     
    782776 
    783777- (BOOL) tableView:(NSTableView *) tableView acceptDrop:(id <NSDraggingInfo>) info row:(int) row dropOperation:(NSTableViewDropOperation) operation { 
     778        if( tableView != buddies ) return NO; 
     779 
    784780        NSPasteboard *board = [info draggingPasteboard]; 
    785781        if( [board availableTypeFromArray:[NSArray arrayWithObject:NSFilenamesPboardType]] ) { 
     
    801797 
    802798- (NSRange) tableView:(MVTableView *) tableView rowsInRect:(NSRect) rect defaultRange:(NSRange) defaultRange { 
     799        if( tableView != buddies ) return defaultRange; 
     800 
    803801        if( _animating ) return NSMakeRange( 0, [_buddyOrder count] ); 
    804802        else return defaultRange; 
     
    979977                [self _manuallySortAndUpdate]; 
    980978        } 
     979 
     980        [buddy registerWithApplicableConnections]; 
    981981} 
    982982 
  • trunk/Languages/English.lproj/MVBuddyList.nib/info.nib

    r3205 r3488  
    1010                <string>552 603 220 194 0 0 1280 832 </string> 
    1111                <key>168</key> 
    12                 <string>460 587 132 87 0 0 1440 878 </string> 
     12                <string>460 587 132 99 0 0 1440 878 </string> 
    1313        </dict> 
    1414        <key>IBFramework Version</key> 
    15         <string>443.0</string> 
     15        <string>454.0</string> 
    1616        <key>IBLockedObjects</key> 
    1717        <array/> 
    1818        <key>IBOpenObjects</key> 
    1919        <array> 
     20                <integer>115</integer> 
     21                <integer>80</integer> 
    2022                <integer>168</integer> 
    21                 <integer>41</integer> 
    22                 <integer>80</integer> 
    2323        </array> 
    2424        <key>IBSystem Version</key> 
    25         <string>8I1119</string> 
     25        <string>9A321</string> 
    2626</dict> 
    2727</plist> 
  • trunk/Models/JVBuddy.h

    r3487 r3488  
    8383 
    8484- (ABPerson *) addressBookPersonRecord; 
     85- (void) setAddressBookPersonRecord:(ABPerson *) record; 
    8586- (void) editInAddressBook; 
    8687- (void) viewInAddressBook; 
  • trunk/Models/JVBuddy.m

    r3487 r3488  
    3030#pragma mark - 
    3131 
    32 - (id) initWithDictionaryRepresentation:(NSDictionary *) dictionary
     32- (id) init
    3333        if( ( self = [super init] ) ) { 
    3434                _rules = [[NSMutableArray allocWithZone:nil] initWithCapacity:5]; 
    3535                _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] ) ) { 
    3747                NSData *data = [dictionary objectForKey:@"picture"]; 
    3848                if( [data isKindOfClass:[NSData class]] && [data length] ) 
     
    6070 
    6171                string = [dictionary objectForKey:@"uniqueIdentifier"]; 
    62                 if( [string isKindOfClass:[NSString class]] ) 
     72                if( [string isKindOfClass:[NSString class]] ) { 
     73                        [_uniqueIdentifier release]; 
    6374                        _uniqueIdentifier = [string copyWithZone:nil]; 
    64                 if( ! [_uniqueIdentifier length] ) 
     75                } 
     76 
     77                if( ! [_uniqueIdentifier length] ) { 
     78                        [_uniqueIdentifier release]; 
    6579                        _uniqueIdentifier = [[NSString locallyUniqueString] retain]; 
     80                } 
    6681 
    6782                string = [dictionary objectForKey:@"addressBookPersonRecord"]; 
     
    7691                        [rule release]; 
    7792                } 
    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]; 
    8393        } 
    8494 
     
    431441} 
    432442 
     443- (void) setAddressBookPersonRecord:(ABPerson *) record { 
     444        id old = _person; 
     445        _person = [record retain]; 
     446        [old release]; 
     447} 
     448 
    433449- (void) editInAddressBook { 
    434450        if( ! _person ) return;