diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMMCPConnection.h | 1 | ||||
-rw-r--r-- | Source/CMMCPConnection.m | 24 | ||||
-rw-r--r-- | Source/TableDocument.h | 6 | ||||
-rw-r--r-- | Source/TableDocument.m | 38 |
4 files changed, 66 insertions, 3 deletions
diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h index 7c892ead..814738bf 100644 --- a/Source/CMMCPConnection.h +++ b/Source/CMMCPConnection.h @@ -33,6 +33,7 @@ - (void)willQueryString:(NSString *)query; - (void)queryGaveError:(NSString *)error; +- (void)setStatusIconToImageWithName:(NSString *)imagePath; - (BOOL)connectionEncodingViaLatin1; @end diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index db45a3d8..6654948b 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -239,7 +239,10 @@ static void forcePingTimeout(int signalNumber); theRet = mysql_real_connect(mConnection, theHost, theLogin, thePass, NULL, connectionPort, theSocket, mConnectionFlags); thePass = NULL; if (theRet != mConnection) { - if (connectionTunnel) [connectionTunnel disconnect]; + if (connectionTunnel) { + [connectionTunnel disconnect]; + [delegate setStatusIconToImageWithName:@"ssh-disconnected"]; + } return mConnected = NO; } @@ -260,7 +263,10 @@ static void forcePingTimeout(int signalNumber); { [super disconnect]; - if (connectionTunnel) [connectionTunnel disconnect]; + if (connectionTunnel) { + [connectionTunnel disconnect]; + [delegate setStatusIconToImageWithName:@"ssh-disconnected"]; + } if( serverVersionString != nil ) { [serverVersionString release]; @@ -358,16 +364,19 @@ static void forcePingTimeout(int signalNumber); [connectionTunnel setConnectionStateChangeSelector:nil delegate:nil]; if ([connectionTunnel state] != SPSSH_STATE_IDLE) [connectionTunnel disconnect]; [connectionTunnel connect]; + [delegate setStatusIconToImageWithName:@"ssh-connecting"]; NSDate *tunnelStartDate = [NSDate date], *interfaceInteractionTimer; // Allow the tunnel to attempt to connect in a loop while (1) { if ([connectionTunnel state] == SPSSH_STATE_CONNECTED) { + [delegate setStatusIconToImageWithName:@"ssh-connected"]; connectionPort = [connectionTunnel localPort]; break; } if ([[NSDate date] timeIntervalSinceDate:tunnelStartDate] > (connectionTimeout + 1)) { [connectionTunnel disconnect]; + [delegate setStatusIconToImageWithName:@"ssh-disconnected"]; break; } @@ -449,6 +458,12 @@ static void forcePingTimeout(int signalNumber); { int newState = [theTunnel state]; + if (delegate && [delegate respondsToSelector:@selector(setStatusIconToImageWithName:)]) { + if (newState == SPSSH_STATE_IDLE) [delegate setStatusIconToImageWithName:@"ssh-disconnected"]; + else if (newState == SPSSH_STATE_CONNECTED) [delegate setStatusIconToImageWithName:@"ssh-connected"]; + else [delegate setStatusIconToImageWithName:@"ssh-connecting"]; + } + // Restart the tunnel if it dies if (mConnected && newState == SPSSH_STATE_IDLE && currentSSHTunnelState == SPSSH_STATE_CONNECTED) { currentSSHTunnelState = newState; @@ -614,7 +629,10 @@ static void forcePingTimeout(int signalNumber); [self startKeepAliveTimerResettingState:YES]; return YES; } - if (connectionTunnel) [connectionTunnel disconnect]; + if (connectionTunnel) { + [connectionTunnel disconnect]; + [delegate setStatusIconToImageWithName:@"ssh-disconnected"]; + } return NO; } diff --git a/Source/TableDocument.h b/Source/TableDocument.h index a7ba9d01..946b2492 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -51,6 +51,8 @@ IBOutlet id spExportControllerInstance; IBOutlet id tableWindow; + IBOutlet id titleAccessoryView; + IBOutlet id titleImageView; IBOutlet id connectSheet; IBOutlet id databaseSheet; IBOutlet id variablesSheet; @@ -215,6 +217,10 @@ - (IBAction)viewRelations:(id)sender; - (IBAction)addConnectionToFavorites:(id)sender; +// titlebar methods +- (void)setStatusIconToImageWithName:(NSString *)imagePath; +- (void)clearStatusIcon; + //toolbar methods - (void)setupToolbar; - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index c797b530..e9ad5322 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -113,6 +113,17 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum // Hide the tabs in the tab view (we only show them to allow switching tabs in interface builder) [tableTabView setTabViewType:NSNoTabsNoBorder]; [tableListSplitter setDividerStyle:NSSplitViewDividerStyleThin]; + + // Add the icon accessory view to the title bar + NSView *windowFrame = [[tableWindow contentView] superview]; + NSRect av = [titleAccessoryView frame]; + NSRect initialAccessoryViewFrame = NSMakeRect( + [windowFrame frame].size.width - av.size.width - 20, + [windowFrame frame].size.height - av.size.height, + av.size.width, + av.size.height); + [titleAccessoryView setFrame:initialAccessoryViewFrame]; + [windowFrame addSubview:titleAccessoryView]; } - (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context @@ -383,9 +394,13 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum int newState = [theTunnel state]; if (newState == SPSSH_STATE_IDLE) { + [self setStatusIconToImageWithName:@"ssh-disconnected"]; [self failConnectionWithErrorMessage:[theTunnel lastError]]; } else if (newState == SPSSH_STATE_CONNECTED) { + [self setStatusIconToImageWithName:@"ssh-connected"]; [self initiateMySQLConnection]; + } else { + [self setStatusIconToImageWithName:@"ssh-connecting"]; } } @@ -1991,6 +2006,29 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum } #pragma mark - +#pragma mark Titlebar Methods + +/** + * Set the connection status icon in the titlebar + */ +- (void)setStatusIconToImageWithName:(NSString *)imageName +{ + NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"]; + if (!imagePath) return; + + NSImage *image = [[NSImage alloc] initByReferencingFile:imagePath]; + [titleImageView setImage:image]; +} + +/** + * Clear the connection status icon in the titlebar + */ +- (void)clearStatusIcon +{ + [titleImageView setImage:nil]; +} + +#pragma mark - #pragma mark Toolbar Methods /** |