Changeset 3520

Show
Ignore:
Timestamp:
01/01/07 01:03:45 (2 years ago)
Author:
timothy
Message:

Allow creation of connections that have the same server address but different nicknames, ports, usernames or passwords. #52 #550

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Controllers/MVConnectionsController.m

    r3491 r3520  
    319319 
    320320- (IBAction) connectNewConnection:(id) sender { 
    321         MVChatConnection *connection = nil; 
    322  
    323321        if( ! [[newNickname stringValue] length] ) { 
    324322                [[self window] makeFirstResponder:newNickname]; 
     
    365363 
    366364        NSEnumerator *enumerator = [_bookmarks objectEnumerator]; 
    367         id data = nil; 
    368  
    369         while( ( data = [enumerator nextObject] ) ) { 
    370                 if( [[(MVChatConnection *)[data objectForKey:@"connection"] server] isEqualToString:[newAddress stringValue]] && 
    371                         [[(MVChatConnection *)[data objectForKey:@"connection"] nickname] isEqualToString:[newNickname stringValue]] ) { 
    372                         if( [(MVChatConnection *)[data objectForKey:@"connection"] isConnected] ) { 
     365        NSDictionary *info = nil; 
     366 
     367        while( ( info = [enumerator nextObject] ) ) { 
     368                MVChatConnection *connection = [info objectForKey:@"connection"]; 
     369 
     370                if( [[connection server] isEqualToString:[newAddress stringValue]] && [connection serverPort] == [newPort intValue] && 
     371                        [[connection nickname] isEqualToString:[newNickname stringValue]] && 
     372                        [[connection username] isEqualToString:[newUsername stringValue]] && 
     373                        [[connection password] isEqualToString:[newServerPassword stringValue]] ) { 
     374                        if( [connection isConnected] ) { 
    373375                                NSRunCriticalAlertPanel( NSLocalizedString( @"Already connected", "already connected dialog title" ), NSLocalizedString( @"The chat server with the nickname you specified is already connected to from this computer. Use another nickname if you desire multiple connections.", "chat already connected message" ), nil, nil, nil ); 
    374376                                [openConnection makeFirstResponder:newNickname]; 
    375377                        } else { 
    376                                 [connections selectRow:[_bookmarks indexOfObject:data] byExtendingSelection:NO]; 
     378                                [connections selectRow:[_bookmarks indexOfObject:info] byExtendingSelection:NO]; 
    377379                                [self _connect:nil]; 
    378380                                [[self window] makeKeyAndOrderFront:nil]; 
    379381                                [openConnection orderOut:nil]; 
    380382                        } 
     383 
    381384                        return; 
    382385                } 
     
    387390        MVChatConnectionType type = ( [[newType selectedItem] tag] == 1 ? MVChatConnectionIRCType : MVChatConnectionSILCType ); 
    388391 
    389         connection = [[[MVChatConnection alloc] initWithType:type] autorelease]; 
     392        MVChatConnection *connection = [[[MVChatConnection alloc] initWithType:type] autorelease]; 
    390393        [connection setEncoding:[[NSUserDefaults standardUserDefaults] integerForKey:@"JVChatEncoding"]]; 
    391394        [connection setOutgoingChatFormat:[[NSUserDefaults standardUserDefaults] integerForKey:@"JVChatFormat"]]; 
     
    709712- (void) handleURL:(NSURL *) url andConnectIfPossible:(BOOL) connect { 
    710713        if( [MVChatConnection supportsURLScheme:[url scheme]] ) { 
    711                 MVChatConnection *connection = nil; 
    712714                NSString *target = nil; 
    713715                BOOL handled = NO; 
     
    720722 
    721723                NSEnumerator *enumerator = [_bookmarks objectEnumerator]; 
    722                 id data = nil; 
    723  
    724                 while( ( data = [enumerator nextObject] ) ) { 
    725                         connection = [data objectForKey:@"connection"]; 
    726                         if( [[connection server] isEqualToString:[url host]] 
    727                                 && ( ! [url user] || [[connection nickname] isEqualToString:[url user]] ) 
    728                                 && ( ! [connection serverPort] || ! [[url port] unsignedShortValue] || [connection serverPort] == [[url port] unsignedShortValue] ) ) { 
     724                NSDictionary *info = nil; 
     725 
     726                while( ( info = [enumerator nextObject] ) ) { 
     727                        MVChatConnection *connection = [info objectForKey:@"connection"]; 
     728 
     729                        if( [[connection server] isEqualToString:[url host]] && 
     730                                ( ! [[url user] length] || [[connection nickname] isEqualToString:[url user]] ) && 
     731                                ( ! [[url port] unsignedShortValue] || [connection serverPort] == [[url port] unsignedShortValue] ) ) { 
    729732 
    730733                                if( ! [connection isConnected] && connect ) { 
     
    737740                                else [[self window] orderFront:nil]; 
    738741 
    739                                 [connections selectRow:[_bookmarks indexOfObject:data] byExtendingSelection:NO]; 
     742                                [connections selectRow:[_bookmarks indexOfObject:info] byExtendingSelection:NO]; 
     743 
    740744                                handled = YES; 
    741745                                break; 
     
    743747                } 
    744748 
    745                 if( ! handled && ! [url user] ) { 
     749                if( ! handled && ! [[url user] length] ) { 
    746750                        [newAddress setObjectValue:[url host]]; 
    747751 
     
    754758 
    755759                        handled = YES; 
    756                 } else if( ! handled && [url user] ) { 
    757                         connection = [[[MVChatConnection alloc] initWithURL:url] autorelease]; 
     760                } else if( ! handled && [[url user] length] ) { 
     761                        MVChatConnection *connection = [[[MVChatConnection alloc] initWithURL:url] autorelease]; 
    758762                        [connection setEncoding:[[NSUserDefaults standardUserDefaults] integerForKey:@"JVChatEncoding"]]; 
    759763                        [connection setOutgoingChatFormat:[[NSUserDefaults standardUserDefaults] integerForKey:@"JVChatFormat"]];