Changeset 4819

Show
Ignore:
Timestamp:
06/05/07 00:50:26 (1 year ago)
Author:
morris
Message:

More autoreconnect fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/WCConnectionController.h

    r4775 r4819  
    5959 
    6060- (BOOL)beginConfirmDisconnectSheetModalForWindow:(NSWindow *)window modalDelegate:(id)delegate didEndSelector:(SEL)selector contextInfo:(void *)contextInfo; 
     61- (BOOL)validateAction:(SEL)selector; 
    6162 
    6263- (IBAction)disconnect:(id)sender; 
  • WiredClient/trunk/WCConnectionController.m

    r4813 r4819  
    373373 
    374374 
    375 #pragma mark - 
    376  
    377 - (BOOL)validateMenuItem:(NSMenuItem *)item { 
    378         SEL                     selector; 
     375- (BOOL)validateAction:(SEL)selector { 
    379376        BOOL            connected; 
    380          
     377 
    381378        if(![self connection]) 
    382379                return NO; 
    383380         
    384         selector = [item action]; 
    385381        connected = [[self connection] isConnected]; 
    386382         
     
    388384                return (connected && ![[self connection] isDisconnecting]); 
    389385        else if(selector == @selector(reconnect:)) 
    390                 return (!connected && ![[self connection] isReconnecting]); 
     386                return (!connected && ![[self connection] isManuallyReconnecting]); 
    391387        else if(selector == @selector(files:) || selector == @selector(postNews:) || selector == @selector(broadcast:)) 
    392388                return connected; 
    393389         
    394390        return YES; 
     391} 
     392 
     393 
     394 
     395#pragma mark - 
     396 
     397- (BOOL)validateMenuItem:(NSMenuItem *)item { 
     398        return [self validateAction:[item action]]; 
    395399} 
    396400 
  • WiredClient/trunk/WCPublicChat.m

    r4813 r4819  
    538538 
    539539- (BOOL)validateToolbarItem:(NSToolbarItem *)item { 
    540         SEL                     selector; 
    541         BOOL            connected; 
    542          
    543         selector = [item action]; 
    544         connected = [[self connection] isConnected]; 
    545          
    546         if(selector == @selector(reconnect:)) 
    547                 return !connected; 
    548         else if(selector == @selector(disconnect:)) 
    549                 return (connected && ![[self connection] isDisconnecting] && [NSApp isActive]); 
    550         else if(selector == @selector(files:)) 
    551                 return connected; 
    552  
    553         return YES; 
     540        return [super validateAction:[item action]]; 
    554541} 
    555542 
  • WiredClient/trunk/WCServerConnection.h

    r4813 r4819  
    7070        BOOL                                                                                    _closingWindow; 
    7171        BOOL                                                                                    _disconnecting; 
    72         BOOL                                                                                    _reconnecting; 
     72        BOOL                                                                                    _manuallyReconnecting; 
     73        BOOL                                                                                    _shouldAutoReconnect; 
    7374        BOOL                                                                                    _autoReconnecting; 
    7475        BOOL                                                                                    _hidden; 
    75         BOOL                                                                                    _kicked; 
    7676} 
    7777 
     
    161161- (BOOL)isDisconnecting; 
    162162- (BOOL)isReconnecting; 
     163- (BOOL)isManuallyReconnecting; 
    163164- (BOOL)isAutoReconnecting; 
    164165- (BOOL)isHidden; 
  • WiredClient/trunk/WCServerConnection.m

    r4816 r4819  
    5353- (void)_connect; 
    5454- (void)_login; 
    55 - (void)_autoReconnect; 
    5655 
    5756@end 
     
    127126                         selector:@selector(connectionReceivedError:) 
    128127                                 name:WCConnectionReceivedError]; 
    129  
    130         [self addObserver:self 
    131                          selector:@selector(serverConnectionWillReconnect:) 
    132                                  name:WCServerConnectionWillReconnect]; 
    133128 
    134129        [self addObserver:self 
     
    229224        [_link sendCommand:WCUserCommand withArgument:user]; 
    230225        [_link sendCommand:WCPassCommand withArgument:password]; 
    231 } 
    232  
    233  
    234  
    235 - (void)_autoReconnect { 
    236         _autoReconnecting = YES; 
    237          
    238         [self postNotificationName:WCServerConnectionWillReconnect object:self]; 
    239  
    240         [self connect]; 
    241226} 
    242227 
     
    308293 
    309294- (void)windowWillClose:(NSNotification *)notification { 
    310         if(!_dismissingWindow && !_reconnecting && [[notification object] isOnScreen]) { 
     295        if(!_dismissingWindow && [[notification object] isOnScreen]) { 
    311296                _closingWindow = YES; 
    312297                 
     
    405390 
    406391- (void)connectionDidTerminate:(NSNotification *)notification { 
    407         [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(_autoReconnect) object:NULL]; 
     392        [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(autoReconnect) object:NULL]; 
    408393         
    409394        [_progressIndicator stopAnimation:self]; 
     
    418403 
    419404- (void)connectionDidClose:(NSNotification *)notification { 
     405        NSString        *reason; 
    420406        WCError         *error; 
    421407        float           time; 
     
    427413 
    428414        if(!_loginFailed) { 
    429                 if(_autoReconnecting) { 
    430                         [self close]; 
     415                error = [[notification userInfo] objectForKey:WCErrorKey]; 
     416                 
     417                if(!error) 
     418                        error = [WCError errorWithDomain:WCWiredClientErrorDomain code:WCWiredClientServerDisconnected]; 
     419                 
     420                if(_manuallyReconnecting || _autoReconnecting) { 
     421                        reason = [error localizedFailureReason]; 
     422                         
     423                        if([reason length] > 0) 
     424                                [[self chat] printEvent:[reason substringWithRange:NSMakeRange(0, [reason length] - 1)]]; 
    431425                } else { 
    432                         error = [[notification userInfo] objectForKey:WCErrorKey]; 
     426                        if([[self window] isMiniaturized]) 
     427                                [self showWindow:self]; 
    433428                         
    434                         if(!error) 
    435                                 error = [WCError errorWithDomain:WCWiredClientErrorDomain code:WCWiredClientServerDisconnected]; 
    436                          
    437                         if(error) { 
    438                                 if([[self window] isMiniaturized]) 
    439                                         [self showWindow:self]; 
    440                                  
    441                                 if([[self window] isVisible]) { 
    442                                         [self triggerEvent:WCEventsError info1:error]; 
    443                                         [[error alert] beginSheetModalForWindow:[self window]]; 
    444                                 } 
     429                        if([[self window] isVisible]) { 
     430                                [self triggerEvent:WCEventsError info1:error]; 
     431                                [[error alert] beginSheetModalForWindow:[self window]]; 
    445432                        } 
    446433                         
     
    453440                } 
    454441                 
    455                 if([WCSettings boolForKey:WCAutoReconnect] && _userID > 0 && !_kicked && !_disconnecting) { 
     442                if([WCSettings boolForKey:WCAutoReconnect] && _shouldAutoReconnect) { 
    456443                        time = (100.0 + (random() % 200)) / 10.0; 
    457444//                      time = [WCSettings floatForKey:WCAutoReconnectTime]; 
     
    460447                                [self name], time]]; 
    461448         
    462                         [self performSelector:@selector(_autoReconnect) afterDelay:time]; 
     449                        [self performSelector:@selector(autoReconnect) afterDelay:time]; 
    463450                } 
     451                 
     452                _manuallyReconnecting = NO; 
     453                _autoReconnecting = NO; 
    464454        } 
    465455         
     
    489479                [_link disconnect]; 
    490480        } 
    491 } 
    492  
    493  
    494  
    495 - (void)serverConnectionWillReconnect:(NSNotification *)notification { 
    496         _reconnecting = YES; 
    497481} 
    498482 
     
    528512        [[self window] setTitle:[self name] withSubtitle:NSLS(@"Connect", @"Connect window title")]; 
    529513         
    530         if(_reconnecting) { 
    531  
     514        if([self isReconnecting]) { 
    532515                [[self chat] printEvent:[NSSWF:NSLS(@"Reconnected to %@", @"Reconnected chat message"), 
    533516                        [self name]]]; 
     
    547530        [_link sendCommand:WCPrivilegesCommand]; 
    548531 
    549         _dismissingWindow = YES; 
     532        _dismissingWindow              = YES; 
    550533        [[self window] close]; 
    551         _dismissingWindow = NO; 
    552          
    553         _reconnecting = NO; 
    554         _autoReconnecting = NO; 
     534        _dismissingWindow               = NO; 
     535         
     536        _manuallyReconnecting   = NO; 
     537        _autoReconnecting               = NO; 
     538        _shouldAutoReconnect    = YES; 
    555539         
    556540        [self triggerEvent:WCEventsServerConnected]; 
     
    610594 
    611595- (void)chatSelfWasKicked:(NSNotification *)notification { 
    612         _kicked = YES
     596        _shouldAutoReconnect = NO
    613597} 
    614598 
     
    940924        [_progressIndicator startAnimation:self]; 
    941925         
    942         _connectionID   = [[self class] _connectionID]; 
    943          
    944         _sentLogin              = NO; 
    945         _loginFailed    = NO; 
    946         _disconnecting  = NO; 
    947         _kicked                 = NO; 
     926        _connectionID                   = [[self class] _connectionID]; 
     927         
     928        _sentLogin                              = NO; 
     929        _loginFailed                    = NO; 
     930        _disconnecting                  = NO; 
    948931         
    949932        [self _connect]; 
     
    953936 
    954937- (void)disconnect { 
    955         _disconnecting = YES; 
     938        _disconnecting                  = YES; 
     939        _shouldAutoReconnect    = NO; 
    956940         
    957941        [_link disconnect]; 
     
    967951 
    968952- (void)reconnect { 
    969         _autoReconnecting = NO; 
    970          
    971         [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(_autoReconnect) object:NULL]; 
    972          
    973         [self postNotificationName:WCServerConnectionWillReconnect object:self]; 
    974  
    975         [self showWindow:self]; 
    976          
    977         [self connect]; 
     953        if(![self isConnected] && !_manuallyReconnecting) { 
     954                _autoReconnecting               = NO; 
     955                _manuallyReconnecting   = YES; 
     956                _shouldAutoReconnect    = YES; 
     957                 
     958                [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(autoReconnect) object:NULL]; 
     959                 
     960                [self postNotificationName:WCServerConnectionWillReconnect object:self]; 
     961 
     962                [self connect]; 
     963        } 
     964
     965 
     966 
     967 
     968- (void)autoReconnect { 
     969        if(![self isConnected] && !_autoReconnecting) { 
     970                _autoReconnecting               = YES; 
     971                _manuallyReconnecting   = NO; 
     972                 
     973                [self postNotificationName:WCServerConnectionWillReconnect object:self]; 
     974 
     975                [self connect]; 
     976        } 
    978977} 
    979978 
     
    10591058 
    10601059- (BOOL)isReconnecting { 
    1061         return _reconnecting; 
     1060        return (_manuallyReconnecting || _autoReconnecting); 
     1061
     1062 
     1063 
     1064 
     1065- (BOOL)isManuallyReconnecting { 
     1066        return _manuallyReconnecting; 
    10621067} 
    10631068