diff options
-rw-r--r-- | Source/SPConnectionDelegate.h | 30 | ||||
-rw-r--r-- | Source/SPConnectionDelegate.m | 128 | ||||
-rw-r--r-- | Source/TableDocument.m | 96 | ||||
-rw-r--r-- | sequel-pro.xcodeproj/project.pbxproj | 36 |
4 files changed, 186 insertions, 104 deletions
diff --git a/Source/SPConnectionDelegate.h b/Source/SPConnectionDelegate.h new file mode 100644 index 00000000..f3b3968d --- /dev/null +++ b/Source/SPConnectionDelegate.h @@ -0,0 +1,30 @@ +// +// $Id$ +// +// SPConnectionDelegate.h +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on November 13, 2009 +// Copyright (c) 2009 Stuart Connolly. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import "TableDocument.h" + +@interface TableDocument (SPConnectionDelegate) + +@end diff --git a/Source/SPConnectionDelegate.m b/Source/SPConnectionDelegate.m new file mode 100644 index 00000000..e306c497 --- /dev/null +++ b/Source/SPConnectionDelegate.m @@ -0,0 +1,128 @@ +// +// $Id$ +// +// SPConnectionDelegate.m +// sequel-pro +// +// Created by Stuart Connolly (stuconnolly.com) on November 13, 2009 +// Copyright (c) 2009 Stuart Connolly. All rights reserved. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// More info at <http://code.google.com/p/sequel-pro/> + +#import "SPConnectionDelegate.h" +#import "SPConnectionController.h" +#import "SPQueryController.h" +#import "SPKeychain.h" +#import "SPConstants.h" + +@implementation TableDocument (SPConnectionDelegate) + +#pragma mark - +#pragma mark MCPKit connection delegate methods + +/** + * Invoked when the framework is about to perform a query. + */ +- (void)willQueryString:(NSString *)query connection:(id)connection +{ + if ([prefs boolForKey:SPConsoleEnableLogging]) { + if ((_queryMode == SPInterfaceQueryMode && [prefs boolForKey:SPConsoleEnableInterfaceLogging]) + || (_queryMode == SPCustomQueryQueryMode && [prefs boolForKey:SPConsoleEnableCustomQueryLogging]) + || (_queryMode == SPImportExportQueryMode && [prefs boolForKey:SPConsoleEnableImportExportLogging])) + { + [[SPQueryController sharedQueryController] showMessageInConsole:query]; + } + } +} + +/** + * Invoked when the query just executed by the framework resulted in an error. + */ +- (void)queryGaveError:(NSString *)error connection:(id)connection +{ + if ([prefs boolForKey:SPConsoleEnableLogging] && [prefs boolForKey:SPConsoleEnableErrorLogging]) { + [[SPQueryController sharedQueryController] showErrorInConsole:error]; + } +} + +/** + * Invoked when the framework is in the process of reconnecting to the server and needs to know + * which database to select. + */ +- (NSString *)onReconnectShouldSelectDatabase:(id)connection +{ + return selectedDatabase; +} + +/** + * Invoked when the framework is in the process of reconnecting to the server and needs to know + * what encoding to use for the connection. + */ +- (NSString *)onReconnectShouldUseEncoding:(id)connection +{ + return _encoding; +} + +/** + * Invoked when the current connection needs a password from the Keychain. + */ +- (NSString *)keychainPasswordForConnection:(MCPConnection *)connection +{ + + // If no keychain item is available, return an empty password + if (![connectionController connectionKeychainItemName]) return @""; + + // Otherwise, pull the password from the keychain using the details from this connection + SPKeychain *keychain = [[SPKeychain alloc] init]; + + NSString *password = [keychain getPasswordForName:[connectionController connectionKeychainItemName] account:[connectionController connectionKeychainItemAccount]]; + + [keychain release]; + + return password; +} + +/** + * Invoked when an attempt was made to execute a query on the current connection, but the connection is not + * actually active. + */ +- (void)noConnectionAvailable:(id)connection +{ + NSBeginAlertSheet(NSLocalizedString(@"No connection available", @"no connection available message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, NSLocalizedString(@"An error has occured and there doesn't seem to be a connection available.", @"no connection available informatie message")); +} + +/** + * Invoked when the connection fails and the framework needs to know how to proceed. + */ +- (MCPConnectionCheck)connectionLost:(id)connection +{ + [NSApp beginSheet:connectionErrorDialog modalForWindow:tableWindow modalDelegate:self didEndSelector:nil contextInfo:nil]; + int connectionErrorCode = [NSApp runModalForWindow:connectionErrorDialog]; + + [NSApp endSheet:connectionErrorDialog]; + [connectionErrorDialog orderOut:nil]; + + // If 'disconnect' was selected, trigger a window close. + if (connectionErrorCode == MCPConnectionCheckDisconnect) { + [self windowWillClose:nil]; + [tableWindow performSelector:@selector(close) withObject:nil afterDelay:0.0]; + } + + return connectionErrorCode; +} + +@end diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 65c8afd6..8d1bca5f 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -755,6 +755,9 @@ return _shouldOpenConnectionAutomatically; } +/** + * Sets this connection's Keychain ID. + */ - (void)setKeychainID:(NSString *)theID { keyChainID = [[NSString stringWithString:theID] retain]; @@ -3425,99 +3428,6 @@ return [[[[self fileURL] absoluteString] lastPathComponent] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; } - -#pragma mark - -#pragma mark MCPKit connection delegate methods - -/** - * Invoked when the framework is about to perform a query. - */ -- (void)willQueryString:(NSString *)query connection:(id)connection -{ - if ([prefs boolForKey:SPConsoleEnableLogging]) { - if ((_queryMode == SPInterfaceQueryMode && [prefs boolForKey:SPConsoleEnableInterfaceLogging]) - || (_queryMode == SPCustomQueryQueryMode && [prefs boolForKey:SPConsoleEnableCustomQueryLogging]) - || (_queryMode == SPImportExportQueryMode && [prefs boolForKey:SPConsoleEnableImportExportLogging])) - { - [[SPQueryController sharedQueryController] showMessageInConsole:query]; - } - } -} - -/** - * Invoked when the query just executed by the framework resulted in an error. - */ -- (void)queryGaveError:(NSString *)error connection:(id)connection -{ - if ([prefs boolForKey:SPConsoleEnableLogging] && [prefs boolForKey:SPConsoleEnableErrorLogging]) { - [[SPQueryController sharedQueryController] showErrorInConsole:error]; - } -} - -/** - * Invoked when the framework is in the process of reconnecting to the server and needs to know - * which database to select. - */ -- (NSString *)onReconnectShouldSelectDatabase:(id)connection -{ - return selectedDatabase; -} - -/** - * Invoked when the framework is in the process of reconnecting to the server and needs to know - * what encoding to use for the connection. - */ -- (NSString *)onReconnectShouldUseEncoding:(id)connection -{ - return _encoding; -} - -/** - * Invoked when the current connection needs a password from the Keychain. - */ -- (NSString *)keychainPasswordForConnection:(MCPConnection *)connection -{ - - // If no keychain item is available, return an empty password - if (![connectionController connectionKeychainItemName]) return @""; - - // Otherwise, pull the password from the keychain using the details from this connection - SPKeychain *keychain = [[SPKeychain alloc] init]; - NSString *password = [keychain getPasswordForName:[connectionController connectionKeychainItemName] account:[connectionController connectionKeychainItemAccount]]; - [keychain release]; - - return password; -} - -/** - * Invoked when an attempt was made to execute a query on the current connection, but the connection is not - * actually active. - */ -- (void)noConnectionAvailable:(id)connection -{ - NSBeginAlertSheet(NSLocalizedString(@"No connection available", @"no connection available message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, NSLocalizedString(@"An error has occured and there doesn't seem to be a connection available.", @"no connection available informatie message")); -} - -/** - * Invoked when the connection fails and the framework needs to know how to proceed. - */ -- (MCPConnectionCheck)connectionLost:(id)connection -{ - [NSApp beginSheet:connectionErrorDialog modalForWindow:tableWindow modalDelegate:self didEndSelector:nil contextInfo:nil]; - int connectionErrorCode = [NSApp runModalForWindow:connectionErrorDialog]; - - [NSApp endSheet:connectionErrorDialog]; - [connectionErrorDialog orderOut:nil]; - - // If 'disconnect' was selected, trigger a window close. - if (connectionErrorCode == MCPConnectionCheckDisconnect) { - [self windowWillClose:nil]; - [tableWindow performSelector:@selector(close) withObject:nil afterDelay:0.0]; - } - - return connectionErrorCode; -} - #pragma mark - #pragma mark Connection controller delegate methods diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 04ac2980..5a40dc65 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ 1789343C0F30C1DD0097539A /* SPStringAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 1789343B0F30C1DD0097539A /* SPStringAdditions.m */; }; 1792C13210AD752100ABE758 /* DatabaseServerVariables.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1792C13010AD752100ABE758 /* DatabaseServerVariables.xib */; }; 1792C13710AD75C800ABE758 /* SPServerVariablesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 1792C13610AD75C800ABE758 /* SPServerVariablesController.m */; }; + 1792C26110AE1A2D00ABE758 /* SPConnectionDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1792C26010AE1A2D00ABE758 /* SPConnectionDelegate.m */; }; 179F15060F7C433C00579954 /* SPEditorTokens.l in Sources */ = {isa = PBXBuildFile; fileRef = 179F15050F7C433C00579954 /* SPEditorTokens.l */; }; 17B7B578101601C300F057DE /* libmysqlclient.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 17B7B576101601C300F057DE /* libmysqlclient.a */; }; 17B7B5901016028F00F057DE /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 17B7B58F1016028F00F057DE /* libcrypto.dylib */; }; @@ -375,6 +376,8 @@ 1792C13110AD752100ABE758 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Interfaces/English.lproj/DatabaseServerVariables.xib; sourceTree = "<group>"; }; 1792C13510AD75C800ABE758 /* SPServerVariablesController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPServerVariablesController.h; sourceTree = "<group>"; }; 1792C13610AD75C800ABE758 /* SPServerVariablesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPServerVariablesController.m; sourceTree = "<group>"; }; + 1792C25F10AE1A2D00ABE758 /* SPConnectionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPConnectionDelegate.h; sourceTree = "<group>"; }; + 1792C26010AE1A2D00ABE758 /* SPConnectionDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPConnectionDelegate.m; sourceTree = "<group>"; }; 179F15040F7C433C00579954 /* SPEditorTokens.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPEditorTokens.h; sourceTree = "<group>"; }; 179F15050F7C433C00579954 /* SPEditorTokens.l */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.lex; path = SPEditorTokens.l; sourceTree = "<group>"; }; 17B7B5621016012700F057DE /* MCPKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = MCPKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -834,6 +837,7 @@ 17E641530EF01EF6001BC333 /* TableDump.m */, 17E641540EF01EF6001BC333 /* TableSource.h */, 17E641550EF01EF6001BC333 /* TableSource.m */, + 1792C28910AE1C7200ABE758 /* Controller Categories */, ); name = "Main View Controllers"; sourceTree = "<group>"; @@ -931,6 +935,15 @@ path = Scripts; sourceTree = "<group>"; }; + 1792C28910AE1C7200ABE758 /* Controller Categories */ = { + isa = PBXGroup; + children = ( + 1792C25F10AE1A2D00ABE758 /* SPConnectionDelegate.h */, + 1792C26010AE1A2D00ABE758 /* SPConnectionDelegate.m */, + ); + name = "Controller Categories"; + sourceTree = "<group>"; + }; 17B7B5551016002900F057DE /* MCPKit */ = { isa = PBXGroup; children = ( @@ -1130,8 +1143,6 @@ 17E641710EF01F5C001BC333 /* GUI */ = { isa = PBXGroup; children = ( - BC05F1C3101241DF008A97F8 /* YRKSpinningProgressIndicator.h */, - BC05F1C4101241DF008A97F8 /* YRKSpinningProgressIndicator.m */, 17E6417C0EF01FA8001BC333 /* CMCopyTable.h */, 17E6417D0EF01FA8001BC333 /* CMCopyTable.m */, 17E6417E0EF01FA8001BC333 /* CMImageView.h */, @@ -1140,10 +1151,12 @@ 17E641810EF01FA8001BC333 /* CMTextView.m */, 58C56EF30F438E120035701E /* SPDataCellFormatter.h */, 58C56EF40F438E120035701E /* SPDataCellFormatter.m */, - 5841423D0F97E11000A34B47 /* NoodleLineNumberView.h */, - 5841423E0F97E11000A34B47 /* NoodleLineNumberView.m */, BC1847E80FE6EC8400094BFB /* SPEditSheetTextView.h */, BC1847E90FE6EC8400094BFB /* SPEditSheetTextView.m */, + 5841423D0F97E11000A34B47 /* NoodleLineNumberView.h */, + 5841423E0F97E11000A34B47 /* NoodleLineNumberView.m */, + BC05F1C3101241DF008A97F8 /* YRKSpinningProgressIndicator.h */, + BC05F1C4101241DF008A97F8 /* YRKSpinningProgressIndicator.m */, ); name = GUI; sourceTree = "<group>"; @@ -1293,21 +1306,21 @@ children = ( 296DC8A50F909194002A3258 /* MGTemplateMarker.h */, 296DC8A60F909194002A3258 /* MGTemplateFilter.h */, - 296DC8A70F909194002A3258 /* MGTemplateEngine.m */, 296DC8A80F909194002A3258 /* MGTemplateEngine.h */, + 296DC8A70F909194002A3258 /* MGTemplateEngine.m */, 296DC8A90F909194002A3258 /* ICUTemplateMatcher.h */, + 296DC8AC0F909194002A3258 /* ICUTemplateMatcher.m */, 296DC8AA0F909194002A3258 /* DeepMutableCopy.h */, + 296DC8B00F909194002A3258 /* RegexKitLite.h */, 296DC8AB0F909194002A3258 /* RegexKitLite.m */, - 296DC8AC0F909194002A3258 /* ICUTemplateMatcher.m */, - 296DC8AD0F909194002A3258 /* MGTemplateStandardMarkers.m */, - 296DC8AE0F909194002A3258 /* NSArray_DeepMutableCopy.m */, 296DC8AF0F909194002A3258 /* NSArray_DeepMutableCopy.h */, - 296DC8B00F909194002A3258 /* RegexKitLite.h */, - 296DC8B10F909194002A3258 /* NSDictionary_DeepMutableCopy.m */, + 296DC8AE0F909194002A3258 /* NSArray_DeepMutableCopy.m */, 296DC8B20F909194002A3258 /* NSDictionary_DeepMutableCopy.h */, + 296DC8B10F909194002A3258 /* NSDictionary_DeepMutableCopy.m */, 296DC8B30F909194002A3258 /* MGTemplateStandardMarkers.h */, - 296DC8B40F909194002A3258 /* MGTemplateStandardFilters.m */, + 296DC8AD0F909194002A3258 /* MGTemplateStandardMarkers.m */, 296DC8B50F909194002A3258 /* MGTemplateStandardFilters.h */, + 296DC8B40F909194002A3258 /* MGTemplateStandardFilters.m */, ); name = MGTemplateEngine; sourceTree = "<group>"; @@ -1827,6 +1840,7 @@ 171312CE109D23C700FB465F /* SPTableTextFieldCell.m in Sources */, 174CE14210AB9281008F892B /* SPProcessListController.m in Sources */, 1792C13710AD75C800ABE758 /* SPServerVariablesController.m in Sources */, + 1792C26110AE1A2D00ABE758 /* SPConnectionDelegate.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; |