Changeset 4819
- Timestamp:
- 06/05/07 00:50:26 (1 year ago)
- Files:
-
- WiredClient/trunk/WCConnectionController.h (modified) (1 diff)
- WiredClient/trunk/WCConnectionController.m (modified) (2 diffs)
- WiredClient/trunk/WCPublicChat.m (modified) (1 diff)
- WiredClient/trunk/WCServerConnection.h (modified) (2 diffs)
- WiredClient/trunk/WCServerConnection.m (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
WiredClient/trunk/WCConnectionController.h
r4775 r4819 59 59 60 60 - (BOOL)beginConfirmDisconnectSheetModalForWindow:(NSWindow *)window modalDelegate:(id)delegate didEndSelector:(SEL)selector contextInfo:(void *)contextInfo; 61 - (BOOL)validateAction:(SEL)selector; 61 62 62 63 - (IBAction)disconnect:(id)sender; WiredClient/trunk/WCConnectionController.m
r4813 r4819 373 373 374 374 375 #pragma mark - 376 377 - (BOOL)validateMenuItem:(NSMenuItem *)item { 378 SEL selector; 375 - (BOOL)validateAction:(SEL)selector { 379 376 BOOL connected; 380 377 381 378 if(![self connection]) 382 379 return NO; 383 380 384 selector = [item action];385 381 connected = [[self connection] isConnected]; 386 382 … … 388 384 return (connected && ![[self connection] isDisconnecting]); 389 385 else if(selector == @selector(reconnect:)) 390 return (!connected && ![[self connection] is Reconnecting]);386 return (!connected && ![[self connection] isManuallyReconnecting]); 391 387 else if(selector == @selector(files:) || selector == @selector(postNews:) || selector == @selector(broadcast:)) 392 388 return connected; 393 389 394 390 return YES; 391 } 392 393 394 395 #pragma mark - 396 397 - (BOOL)validateMenuItem:(NSMenuItem *)item { 398 return [self validateAction:[item action]]; 395 399 } 396 400 WiredClient/trunk/WCPublicChat.m
r4813 r4819 538 538 539 539 - (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]]; 554 541 } 555 542 WiredClient/trunk/WCServerConnection.h
r4813 r4819 70 70 BOOL _closingWindow; 71 71 BOOL _disconnecting; 72 BOOL _reconnecting; 72 BOOL _manuallyReconnecting; 73 BOOL _shouldAutoReconnect; 73 74 BOOL _autoReconnecting; 74 75 BOOL _hidden; 75 BOOL _kicked;76 76 } 77 77 … … 161 161 - (BOOL)isDisconnecting; 162 162 - (BOOL)isReconnecting; 163 - (BOOL)isManuallyReconnecting; 163 164 - (BOOL)isAutoReconnecting; 164 165 - (BOOL)isHidden; WiredClient/trunk/WCServerConnection.m
r4816 r4819 53 53 - (void)_connect; 54 54 - (void)_login; 55 - (void)_autoReconnect;56 55 57 56 @end … … 127 126 selector:@selector(connectionReceivedError:) 128 127 name:WCConnectionReceivedError]; 129 130 [self addObserver:self131 selector:@selector(serverConnectionWillReconnect:)132 name:WCServerConnectionWillReconnect];133 128 134 129 [self addObserver:self … … 229 224 [_link sendCommand:WCUserCommand withArgument:user]; 230 225 [_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];241 226 } 242 227 … … 308 293 309 294 - (void)windowWillClose:(NSNotification *)notification { 310 if(!_dismissingWindow && !_reconnecting &&[[notification object] isOnScreen]) {295 if(!_dismissingWindow && [[notification object] isOnScreen]) { 311 296 _closingWindow = YES; 312 297 … … 405 390 406 391 - (void)connectionDidTerminate:(NSNotification *)notification { 407 [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector( _autoReconnect) object:NULL];392 [[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(autoReconnect) object:NULL]; 408 393 409 394 [_progressIndicator stopAnimation:self]; … … 418 403 419 404 - (void)connectionDidClose:(NSNotification *)notification { 405 NSString *reason; 420 406 WCError *error; 421 407 float time; … … 427 413 428 414 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)]]; 431 425 } else { 432 error = [[notification userInfo] objectForKey:WCErrorKey]; 426 if([[self window] isMiniaturized]) 427 [self showWindow:self]; 433 428 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]]; 445 432 } 446 433 … … 453 440 } 454 441 455 if([WCSettings boolForKey:WCAutoReconnect] && _ userID > 0 && !_kicked && !_disconnecting) {442 if([WCSettings boolForKey:WCAutoReconnect] && _shouldAutoReconnect) { 456 443 time = (100.0 + (random() % 200)) / 10.0; 457 444 // time = [WCSettings floatForKey:WCAutoReconnectTime]; … … 460 447 [self name], time]]; 461 448 462 [self performSelector:@selector( _autoReconnect) afterDelay:time];449 [self performSelector:@selector(autoReconnect) afterDelay:time]; 463 450 } 451 452 _manuallyReconnecting = NO; 453 _autoReconnecting = NO; 464 454 } 465 455 … … 489 479 [_link disconnect]; 490 480 } 491 }492 493 494 495 - (void)serverConnectionWillReconnect:(NSNotification *)notification {496 _reconnecting = YES;497 481 } 498 482 … … 528 512 [[self window] setTitle:[self name] withSubtitle:NSLS(@"Connect", @"Connect window title")]; 529 513 530 if(_reconnecting) { 531 514 if([self isReconnecting]) { 532 515 [[self chat] printEvent:[NSSWF:NSLS(@"Reconnected to %@", @"Reconnected chat message"), 533 516 [self name]]]; … … 547 530 [_link sendCommand:WCPrivilegesCommand]; 548 531 549 _dismissingWindow = YES;532 _dismissingWindow = YES; 550 533 [[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; 555 539 556 540 [self triggerEvent:WCEventsServerConnected]; … … 610 594 611 595 - (void)chatSelfWasKicked:(NSNotification *)notification { 612 _ kicked = YES;596 _shouldAutoReconnect = NO; 613 597 } 614 598 … … 940 924 [_progressIndicator startAnimation:self]; 941 925 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; 948 931 949 932 [self _connect]; … … 953 936 954 937 - (void)disconnect { 955 _disconnecting = YES; 938 _disconnecting = YES; 939 _shouldAutoReconnect = NO; 956 940 957 941 [_link disconnect]; … … 967 951 968 952 - (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 } 978 977 } 979 978 … … 1059 1058 1060 1059 - (BOOL)isReconnecting { 1061 return _reconnecting; 1060 return (_manuallyReconnecting || _autoReconnecting); 1061 } 1062 1063 1064 1065 - (BOOL)isManuallyReconnecting { 1066 return _manuallyReconnecting; 1062 1067 } 1063 1068
