From 8287fc2305b38fdb3ecfa8ad5eef09cd745b80c9 Mon Sep 17 00:00:00 2001 From: mltownsend Date: Thu, 29 Oct 2009 23:40:09 +0000 Subject: Got rid of a crash when using the User Manager and closing last Table Document. May be leaking now, not sure. Still needs some work. --- Interfaces/English.lproj/DBView.xib | 167 +++++++++++++++++++++++---- Interfaces/English.lproj/UserManagerView.xib | 29 +++-- Source/SPUserManager.h | 10 +- Source/SPUserManager.m | 87 +++++++------- Source/TableDocument.h | 5 +- Source/TableDocument.m | 13 +-- 6 files changed, 213 insertions(+), 98 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 13bca4da..6dd4ef73 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -18,7 +18,7 @@ YES 732 732 - 1.2.1 + 1.2.2 @@ -4863,7 +4863,7 @@ {292, 112} {292, 112} - + 256 YES @@ -4872,7 +4872,6 @@ 256 {{36, 75}, {91, 14}} - YES 68288064 @@ -4889,7 +4888,6 @@ 256 {{17, 50}, {110, 14}} - YES 68288064 @@ -4906,7 +4904,6 @@ 258 {{135, 74}, {137, 18}} - YES -1804468671 @@ -4924,7 +4921,6 @@ 259 {{207, 13}, {70, 28}} - 1 YES @@ -4952,7 +4948,6 @@ 259 {{139, 13}, {70, 28}} - YES 67239424 @@ -4974,7 +4969,6 @@ 258 {{132, 45}, {143, 22}} - YES -2076049856 @@ -5295,8 +5289,6 @@ {292, 112} - - {{0, 0}, {1440, 878}} {292, 134} @@ -11159,6 +11151,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 SPHistoryController + + SPUserManager + @@ -15220,6 +15215,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 6637 + + + userManagerInstance + + + + 6639 + @@ -21464,6 +21467,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + + 6638 + + + @@ -22766,6 +22774,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 662.ImportedFromIB2 663.IBPluginDependency 663.ImportedFromIB2 + 6638.IBPluginDependency 669.IBPluginDependency 669.ImportedFromIB2 67.ImportedFromIB2 @@ -24624,6 +24633,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -24807,7 +24817,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 6637 + 6639 @@ -25047,6 +25057,13 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 Source/ImageAndTextCell.h + + NSDictionary + + IBProjectSource + Source/NSDictionary_DeepMutableCopy.h + + NSImageView NSControl @@ -25501,6 +25518,56 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 Source/SPTableView.h + + SPUserManager + NSWindowController + + YES + + YES + addHost: + addUser: + checkAllPrivileges: + doApply: + doCancel: + removeHost: + removeUser: + uncheckAllPrivileges: + + + YES + id + id + id + id + id + id + id + id + + + + YES + + YES + outlineView + privsSupportedByServer + tabView + treeController + + + YES + NSOutlineView + NSMutableDictionary + NSTabView + NSTreeController + + + + IBProjectSource + Source/SPUserManager.h + + TableContent NSObject @@ -25751,6 +25818,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 titleAccessoryView titleImageView titleStringView + userManagerInstance variablesCountTextField variablesSearchField variablesSheet @@ -25812,6 +25880,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id + SPUserManager NSTextField NSSearchField id @@ -26346,6 +26415,28 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 AppKit.framework/Headers/NSController.h + + NSDictionary + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSDictionary.h + + + + NSDictionary + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSDictionary + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + NSDocument NSObject @@ -26430,6 +26521,15 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 AppKit.framework/Headers/NSMenuItemCell.h + + NSMutableDictionary + NSDictionary + + + + NSMutableDictionary + + NSNumberFormatter NSFormatter @@ -26509,7 +26609,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 NSObject - + IBFrameworkSource AppKit.framework/Headers/NSOutlineView.h @@ -26572,17 +26672,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSFileManager.h - + NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyValueCoding.h - + NSObject @@ -26773,6 +26867,19 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 WebKit.framework/Headers/WebUIDelegate.h + + NSObjectController + NSController + + IBFrameworkSource + AppKit.framework/Headers/NSObjectController.h + + + + NSOutlineView + NSTableView + + NSPanel NSWindow @@ -26974,6 +27081,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 AppKit.framework/Headers/NSTextView.h + + NSTreeController + NSObjectController + + IBFrameworkSource + AppKit.framework/Headers/NSTreeController.h + + NSUserDefaultsController NSController @@ -27027,6 +27142,18 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 AppKit.framework/Headers/NSWindowScripting.h + + NSWindowController + NSResponder + + showWindow: + id + + + IBFrameworkSource + AppKit.framework/Headers/NSWindowController.h + + WebView NSView diff --git a/Interfaces/English.lproj/UserManagerView.xib b/Interfaces/English.lproj/UserManagerView.xib index 5e0b1e0a..0325f6d2 100644 --- a/Interfaces/English.lproj/UserManagerView.xib +++ b/Interfaces/English.lproj/UserManagerView.xib @@ -3,7 +3,7 @@ 1050 10B504 - 740 + 732 1038.2 437.00 @@ -15,18 +15,17 @@ YES - 740 - 1.2.1 + 732 + 1.2.2 YES - YES - com.brandonwalkin.BWToolkit com.apple.InterfaceBuilder.CocoaPlugin + com.brandonwalkin.BWToolkit YES @@ -52,14 +51,14 @@ 1 2 {{459, 282}, {752, 506}} - 1677722624 + 1140851712 User Managment NSWindow - {3.40282e+38, 3.40282e+38} + {1.79769e+308, 1.79769e+308} {752, 506} - + 256 YES @@ -148,7 +147,7 @@ controlBackgroundColor 3 - MC42NjY2NjY2ODY1AA + MC42NjY2NjY2NjY3AA @@ -377,7 +376,6 @@ - 2 YES 1 YES @@ -1605,8 +1603,8 @@ - 1 - + -1 + -1 @@ -1708,11 +1706,10 @@ {752, 506} - {{0, 0}, {1680, 1028}} {752, 528} - {3.40282e+38, 3.40282e+38} + {1.79769e+308, 1.79769e+308} @@ -4298,11 +4295,11 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{396, 275}, {752, 506}} + {{37, 275}, {752, 506}} com.apple.InterfaceBuilder.CocoaPlugin - {{396, 275}, {752, 506}} + {{37, 275}, {752, 506}} {752, 506} diff --git a/Source/SPUserManager.h b/Source/SPUserManager.h index 4af00c6c..4983ac49 100644 --- a/Source/SPUserManager.h +++ b/Source/SPUserManager.h @@ -44,13 +44,9 @@ } @property (nonatomic, retain) MCPConnection *mySqlConnection; - -- (NSPersistentStoreCoordinator *)persistentStoreCoordinator; -- (NSManagedObjectModel *)managedObjectModel; -- (NSManagedObjectContext *)managedObjectContext; - -- (id)initWithConnection:(MCPConnection *)connection; -- (void)initializeChild:(NSManagedObject *)child withItem:(NSDictionary *)item; +@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator; +@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel; +@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext; // Add/Remove Users - (IBAction)addUser:(id)sender; diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m index 40300dda..3978bec8 100644 --- a/Source/SPUserManager.m +++ b/Source/SPUserManager.m @@ -42,6 +42,7 @@ - (NSManagedObject *)_createNewSPUser; - (BOOL)checkAndDisplayMySqlError; - (void)_clearData; +- (void)initializeChild:(NSManagedObject *)child withItem:(NSDictionary *)item; @end @@ -49,31 +50,31 @@ @synthesize mySqlConnection; -/** - * Initialise the user manager with the supplied connection. - */ -- (id)initWithConnection:(MCPConnection*) connection +-(id)init { - if ((self = [super initWithWindowNibName:@"UserManagerView"])) { - - self.mySqlConnection = connection; - + if ((self = [super initWithWindowNibName:@"UserManagerView"])) + { // When reading privileges from the database, they are converted automatically to a // lowercase key used in the user privileges stores, from which a GRANT syntax // is derived automatically. While most keys can be automatically converted without // any difficulty, some keys differ slightly in mysql column storage to GRANT syntax; // this dictionary provides mappings for those values to ensure consistency. privColumnToGrantMap = [[NSDictionary alloc] initWithObjectsAndKeys: - @"Grant_option_priv", @"Grant_priv", - @"Show_databases_priv", @"Show_db_priv", - @"Create_temporary_tables_priv", @"Create_tmp_table_priv", - @"Replication_slave_priv", @"Repl_slave_priv", - @"Replication_client_priv", @"Repl_client_priv", - nil]; - - privsSupportedByServer = [[NSMutableDictionary alloc] init]; + @"Grant_option_priv", @"Grant_priv", + @"Show_databases_priv", @"Show_db_priv", + @"Create_temporary_tables_priv", @"Create_tmp_table_priv", + @"Replication_slave_priv", @"Repl_slave_priv", + @"Replication_client_priv", @"Repl_client_priv", + nil]; + + //privsSupportedByServer = [[NSMutableDictionary alloc] init]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(contextDidSave:) + name:NSManagedObjectContextDidSaveNotification + object:nil]; + } - return self; } @@ -82,28 +83,22 @@ */ - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [managedObjectContext release], managedObjectContext = nil; - [persistentStoreCoordinator release], persistentStoreCoordinator = nil; - [managedObjectModel release], managedObjectModel = nil; - [privColumnToGrantMap release], privColumnToGrantMap = nil; - [privsSupportedByServer release], privsSupportedByServer = nil; - - [mySqlConnection release], mySqlConnection = nil; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:NSManagedObjectContextDidSaveNotification + object:nil]; + //[treeController release]; +// [managedObjectContext release]; +// [persistentStoreCoordinator release]; +// [managedObjectModel release]; + [privColumnToGrantMap release]; + [mySqlConnection release]; + //[privsSupportedByServer release]; [super dealloc]; } -/** - * Initialise various interface controls. - */ -- (void)awakeFromNib -{ - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(contextDidSave:) - name:NSManagedObjectContextDidSaveNotification - object:nil]; +-(void)windowDidLoad +{ [tabView selectTabViewItemAtIndex:0]; NSTableColumn *tableColumn = [outlineView tableColumnWithIdentifier:COLUMNIDNAME]; @@ -111,12 +106,17 @@ [imageAndTextCell setEditable:NO]; [tableColumn setDataCell:imageAndTextCell]; - + [self _initializeUsers]; + [super windowDidLoad]; } - (void)_initializeUsers { + /** + * This method reads in the users from the mysql.user table of the current + * connection. Then uses this information to initialize the NSOutlineView. + */ isInitializing = TRUE; NSMutableString *privKey; NSArray *privRow; @@ -125,6 +125,7 @@ NSMutableArray *resultAsArray = [NSMutableArray array]; NSMutableArray *usersResultArray = [NSMutableArray array]; + // Select users from the mysql.user table MCPResult *result = [[self.mySqlConnection queryString:@"SELECT * FROM `mysql`.`user` ORDER BY `user`"] retain]; int rows = [result numOfRows]; if (rows > 0) @@ -177,13 +178,13 @@ for(int i = 0; i < [items count]; i++) { NSString *username = [[items objectAtIndex:i] objectForKey:@"User"]; - NSArray *array = [[self _fetchUserWithUserName:username] retain]; + NSArray *parentResults = [[self _fetchUserWithUserName:username] retain]; NSDictionary *item = [items objectAtIndex:i]; - if (array != nil && [array count] > 0) + if (parentResults != nil && [parentResults count] > 0) { // Add Children - NSManagedObject *parent = [array objectAtIndex:0]; + NSManagedObject *parent = [parentResults objectAtIndex:0]; NSManagedObject *child = [self _createNewSPUser]; [child setParent:parent]; [parent addChildrenObject:child]; @@ -209,7 +210,7 @@ { [[NSApplication sharedApplication] presentError:error]; } - [array release]; + [parentResults release]; } [outlineView reloadData]; } @@ -574,7 +575,7 @@ } droppedUsers = [[droppedUsers substringToIndex:[droppedUsers length]-2] mutableCopy]; [self.mySqlConnection queryString:[NSString stringWithFormat:@"DROP USER %@", droppedUsers]]; - + [droppedUsers release]; return TRUE; } @@ -681,8 +682,8 @@ - (NSManagedObject *)_createNewSPUser { - NSManagedObject *user = [[NSEntityDescription insertNewObjectForEntityForName:@"SPUser" - inManagedObjectContext:[self managedObjectContext]] autorelease]; + NSManagedObject *user = [NSEntityDescription insertNewObjectForEntityForName:@"SPUser" + inManagedObjectContext:[self managedObjectContext]]; return user; } diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 30d44084..414b7d4e 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -54,7 +54,9 @@ enum sp_current_query_mode IBOutlet id extendedTableInfoInstance; IBOutlet id databaseDataInstance; IBOutlet id spHistoryControllerInstance; - IBOutlet id exportControllerInstance; + IBOutlet id exportControllerInstance; + IBOutlet SPUserManager *userManagerInstance; + IBOutlet NSSearchField *listFilterField; @@ -119,7 +121,6 @@ enum sp_current_query_mode int passwordSheetReturnCode; SPConnectionController *connectionController; - SPUserManager *userManagerInstance; MCPConnection *mySQLConnection; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 9b00d82b..6cbccd60 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -260,7 +260,7 @@ NSData *pData = [NSData dataWithContentsOfFile:path options:NSUncachedRead error:&readError]; spf = [[NSPropertyListSerialization propertyListFromData:pData - mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain]; + mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] autorelease]; if(!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")] @@ -484,7 +484,6 @@ [spfDocData setObject:[NSNumber numberWithBool:YES] forKey:@"auto_connect"]; [connectionController initiateConnection:self]; } - } /** @@ -640,11 +639,6 @@ [tableDataInstance setConnection:mySQLConnection]; [extendedTableInfoInstance setConnection:mySQLConnection]; [databaseDataInstance setConnection:mySQLConnection]; - - if (!userManagerInstance) { - userManagerInstance = [[SPUserManager alloc] initWithConnection:mySQLConnection]; - } - userManagerInstance.mySqlConnection = mySQLConnection; // Set the cutom query editor's MySQL version @@ -739,8 +733,7 @@ NSPrintPanel *printPanel = [op printPanel]; [printPanel setOptions:[printPanel options] + NSPrintPanelShowsOrientation + NSPrintPanelShowsScaling + NSPrintPanelShowsPaperSize]; - SPPrintAccessory *printAccessory = [[SPPrintAccessory alloc] init]; - [printAccessory initWithNibName:@"PrintAccessory" bundle:nil]; + SPPrintAccessory *printAccessory = [[SPPrintAccessory alloc] initWithNibName:@"PrintAccessory" bundle:nil]; [printAccessory setPrintView:printWebView]; [printPanel addAccessoryController:printAccessory]; @@ -2415,6 +2408,7 @@ format:NSPropertyListXMLFormat_v1_0 errorDescription:&err]; + [spf release]; if(err != nil) { NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting connection data", @"error while converting connection data")] defaultButton:NSLocalizedString(@"OK", @"OK button") @@ -3551,7 +3545,6 @@ if (taskDrawTimer) [taskDrawTimer release]; if(queryEditorInitString) [queryEditorInitString release]; if(spfSession) [spfSession release]; - if(userManagerInstance) [userManagerInstance release]; if(spfDocData) [spfDocData release]; if(keyChainID) [keyChainID release]; [super dealloc]; -- cgit v1.2.3