From e26e22d9d6a6641cfc0a35e8ae31c12aee8bea5b Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sat, 17 Mar 2012 17:56:04 +0000 Subject: - Remove the GPL-licensed Colloquy-sourced NSNotificationAdditions category from the project, and replace with an MIT-licensed TCMPortMapper sources NSNotificationCenterThreadingAdditions category. This should fix method clashes in the SP_REFACTOR project, so remove behavioural/namespacing switches. --- Source/NSNotificationAdditions.h | 35 --------- Source/NSNotificationAdditions.m | 97 ------------------------- Source/NSNotificationCenterThreadingAdditions.h | 18 +++++ Source/NSNotificationCenterThreadingAdditions.m | 52 +++++++++++++ Source/SPCategoryAdditions.h | 2 +- Source/SPDatabaseDocument.m | 21 +----- Source/SPDatabaseViewController.m | 11 +-- Source/SPTableContent.m | 25 +------ Source/SPTableStructure.m | 8 -- Source/SPTablesList.m | 8 -- 10 files changed, 76 insertions(+), 201 deletions(-) delete mode 100644 Source/NSNotificationAdditions.h delete mode 100644 Source/NSNotificationAdditions.m create mode 100644 Source/NSNotificationCenterThreadingAdditions.h create mode 100644 Source/NSNotificationCenterThreadingAdditions.m (limited to 'Source') diff --git a/Source/NSNotificationAdditions.h b/Source/NSNotificationAdditions.h deleted file mode 100644 index 54b8bfdf..00000000 --- a/Source/NSNotificationAdditions.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// $Id$ -// -// NSNotificationAdditions.h -// sequel-pro -// -// Copied from the Colloquy project; original code available from Trac at -// http://colloquy.info/project/browser/trunk/Additions/NSNotificationAdditions.h -// -// 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 - -@interface NSNotificationCenter (NSNotificationCenterAdditions) - -- (void)postNotificationOnMainThread:(NSNotification *)aNotification; -- (void)postNotificationOnMainThread:(NSNotification *)aNotification waitUntilDone:(BOOL)shouldWaitUntilDone; - -- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject; -- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo; -- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo waitUntilDone:(BOOL)shouldWaitUntilDone; - -@end diff --git a/Source/NSNotificationAdditions.m b/Source/NSNotificationAdditions.m deleted file mode 100644 index 1b8c37eb..00000000 --- a/Source/NSNotificationAdditions.m +++ /dev/null @@ -1,97 +0,0 @@ -// -// $Id$ -// -// NSNotificationAdditions.m -// sequel-pro -// -// Copied from the Colloquy project; original code available from Trac at -// http://colloquy.info/project/browser/trunk/Additions/NSNotificationAdditions.m -// -// 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 - -#import "NSNotificationAdditions.h" -#import "pthread.h" - -@interface NSNotificationCenter (NSNotificationCenterAdditions_PrivateAPI) -+ (void)_postNotification:(NSNotification *)aNotification; -+ (void)_postNotificationWithDetails:(NSDictionary *)anInfoDictionary; -@end - -@implementation NSNotificationCenter (NSNotificationCenterAdditions) - -- (void)postNotificationOnMainThread:(NSNotification *)aNotification -{ - if (pthread_main_np()) return [self postNotification:aNotification]; - - [self performSelectorOnMainThread:@selector(_postNotification:) withObject:aNotification waitUntilDone:NO]; -} - -- (void)postNotificationOnMainThread:(NSNotification *)aNotification waitUntilDone:(BOOL)shouldWaitUntilDone -{ - if (pthread_main_np()) return [self postNotification:aNotification]; - - [self performSelectorOnMainThread:@selector(_postNotification:) withObject:aNotification waitUntilDone:shouldWaitUntilDone]; -} - -- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject -{ - if (pthread_main_np()) return [self postNotificationName:aName object:anObject userInfo:nil]; - - [self postNotificationOnMainThreadWithName:aName object:anObject userInfo:nil waitUntilDone:NO]; -} - -- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo -{ - if(pthread_main_np()) return [self postNotificationName:aName object:anObject userInfo:aUserInfo]; - - [self postNotificationOnMainThreadWithName:aName object:anObject userInfo:aUserInfo waitUntilDone:NO]; -} - -- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject userInfo:(NSDictionary *)aUserInfo waitUntilDone:(BOOL)shouldWaitUntilDone -{ - if (pthread_main_np()) return [self postNotificationName:aName object:anObject userInfo:aUserInfo]; - - NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] initWithCapacity:3]; - - if (aName) [info setObject:aName forKey:@"name"]; - if (anObject) [info setObject:anObject forKey:@"object"]; - if (aUserInfo) [info setObject:aUserInfo forKey:@"userInfo"]; - - [[self class] performSelectorOnMainThread:@selector(_postNotificationWithDetails:) withObject:info waitUntilDone:shouldWaitUntilDone]; -} - -@end - -@implementation NSNotificationCenter (NSNotificationCenterAdditions_PrivateAPI) - -+ (void)_postNotification:(NSNotification *)aNotification -{ - [[self defaultCenter] postNotification:aNotification]; -} - -+ (void)_postNotificationWithDetails:(NSDictionary *)anInfoDictionary -{ - NSString *name = [anInfoDictionary objectForKey:@"name"]; - id object = [anInfoDictionary objectForKey:@"object"]; - NSDictionary *userInfo = [anInfoDictionary objectForKey:@"userInfo"]; - - [[self defaultCenter] postNotificationName:name object:object userInfo:userInfo]; - - [anInfoDictionary release]; -} - -@end diff --git a/Source/NSNotificationCenterThreadingAdditions.h b/Source/NSNotificationCenterThreadingAdditions.h new file mode 100644 index 00000000..b71ad17f --- /dev/null +++ b/Source/NSNotificationCenterThreadingAdditions.h @@ -0,0 +1,18 @@ +// +// $Id$ +// +// NSNotificationCenterThreadingAdditions.h +// Enable NSNotification being sent from threads +// +// Copied from the TCMPortMapper project; original code available on +// Google Code at +// +// Copyright (c) 2007-2008 TheCodingMonkeys: +// Martin Pittenauer, Dominik Wagner, +// Some rights reserved: +// + +@interface NSNotificationCenter (NSNotificationCenterThreadingAdditions) +- (void)postNotificationOnMainThread:(NSNotification *)aNotification; +- (void)postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject; +@end diff --git a/Source/NSNotificationCenterThreadingAdditions.m b/Source/NSNotificationCenterThreadingAdditions.m new file mode 100644 index 00000000..395275e4 --- /dev/null +++ b/Source/NSNotificationCenterThreadingAdditions.m @@ -0,0 +1,52 @@ +// +// $Id$ +// +// NSNotificationCenterThreadingAdditions.m +// Enable NSNotification being sent from threads +// +// Copied from the TCMPortMapper project; original code available on +// Google Code at +// +// Copyright (c) 2007-2008 TheCodingMonkeys: +// Martin Pittenauer, Dominik Wagner, +// Some rights reserved: +// + +#import "NSNotificationCenterThreadingAdditions.h" +#import + +@implementation NSNotificationCenter (NSNotificationCenterThreadingAdditions) + ++ (void)_postNotification:(NSNotification *)aNotification { + [[self defaultCenter] postNotification:aNotification]; +} + ++ (void)_postNotificationViaDictionary:(NSDictionary *)anInfoDictionary { + NSString *name = [anInfoDictionary objectForKey:@"name"]; + id object = [anInfoDictionary objectForKey:@"object"]; + [[self defaultCenter] postNotificationName:name + object:object + userInfo:nil]; + [anInfoDictionary release]; +} + + +- (void)postNotificationOnMainThread:(NSNotification *)aNotification { + if( pthread_main_np() ) return [self postNotification:aNotification]; + [[self class] performSelectorOnMainThread:@selector( _postNotification: ) withObject:aNotification waitUntilDone:NO]; +} + +- (void) postNotificationOnMainThreadWithName:(NSString *)aName object:(id)anObject { + if( pthread_main_np() ) return [self postNotificationName:aName object:anObject userInfo:nil]; + NSMutableDictionary *info = [[NSMutableDictionary allocWithZone:nil] initWithCapacity:2]; + if (aName) { + [info setObject:aName forKey:@"name"]; + } + if (anObject) { + [info setObject:anObject forKey:@"object"]; + } + [[self class] performSelectorOnMainThread:@selector(_postNotificationViaDictionary:) + withObject:info + waitUntilDone:NO]; +} +@end diff --git a/Source/SPCategoryAdditions.h b/Source/SPCategoryAdditions.h index 2243d4f5..b7581c44 100644 --- a/Source/SPCategoryAdditions.h +++ b/Source/SPCategoryAdditions.h @@ -41,5 +41,5 @@ #import "SPColorAdditions.h" #import "SPFileManagerAdditions.h" -#import "NSNotificationAdditions.h" +#import "NSNotificationCenterThreadingAdditions.h" #import "NSMutableArray-MultipleSort.h" diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index 4e2d5954..da2dbaf7 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -969,11 +969,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; NSString *dbName = nil; // Notify listeners that a query has started -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:self]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:self]; -#endif SPMySQLResult *theResult = [mySQLConnection queryString:@"SELECT DATABASE()"]; [theResult setDefaultRowReturnType:SPMySQLResultRowAsArray]; @@ -1000,11 +996,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; } //query finished -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:self]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:self]; -#endif } #ifndef SP_REFACTOR /* navigatorSchemaPathExistsForDatabase: */ @@ -5325,11 +5317,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; - (void)registerActivity:(NSDictionary*)commandDict { [runningActivitiesArray addObject:commandDict]; -#ifndef SP_REFACTOR - [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self]; -#endif + [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self]; if([runningActivitiesArray count] || [[[NSApp delegate] runningActivities] count]) [self performSelector:@selector(setActivityPaneHidden:) withObject:[NSNumber numberWithInteger:0] afterDelay:1.0]; @@ -5361,12 +5349,7 @@ static NSString *SPCreateSyntx = @"SPCreateSyntax"; [self setActivityPaneHidden:[NSNumber numberWithInteger:1]]; } -#ifndef SP_REFACTOR - [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:nil]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self]; -#endif - + [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPActivitiesUpdateNotification object:self]; } - (void)setActivityPaneHidden:(NSNumber*)hide diff --git a/Source/SPDatabaseViewController.m b/Source/SPDatabaseViewController.m index 41e95a38..7fb6b794 100644 --- a/Source/SPDatabaseViewController.m +++ b/Source/SPDatabaseViewController.m @@ -320,11 +320,7 @@ #endif // Notify listeners of the table change -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableChangedNotification object:self]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPTableChangedNotification object:self]; -#endif return; } @@ -467,11 +463,8 @@ if (changeEncoding) [mySQLConnection restoreStoredEncoding]; // Notify listeners of the table change now that the state is fully set up. -#ifndef SP_REFACTOR - [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableChangedNotification object:self]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:SPTableChangedNotification object:self]; -#endif + [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:SPTableChangedNotification object:self]; + #ifndef SP_REFACTOR /* [spHistoryControllerInstance restoreViewStates] */ // Restore view states as appropriate diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 7549a1f1..11e19588 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -278,11 +278,7 @@ } // Post a notification that a query will be performed -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; -#endif // Set up the table details for the new table, and trigger an interface update NSDictionary *tableDetails = [NSDictionary dictionaryWithObjectsAndKeys: @@ -322,11 +318,7 @@ [[tableContentView onMainThread] setNeedsDisplay:YES]; // Post the notification that the query is finished -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#endif // Clear any details to restore now that they have been restored [self clearDetailsToRestore]; @@ -755,11 +747,7 @@ #endif // Notify any listeners that a query has started -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; -#endif // Start construction of the query string queryString = [NSMutableString stringWithFormat:@"SELECT %@%@ FROM %@", @@ -875,11 +863,7 @@ // Notify listenters that the query has finished -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#endif if ([mySQLConnection queryErrored] && ![mySQLConnection lastQueryWasCancelled]) { #ifndef SP_REFACTOR @@ -2724,11 +2708,8 @@ [rowValuesToSave addObject:fieldValue]; } -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; -#endif + NSMutableString *queryString; // Use INSERT syntax when creating new rows @@ -2754,11 +2735,7 @@ // Run the query [mySQLConnection queryString:queryString]; -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#endif // If no rows have been changed, show error if appropriate. if ( ![mySQLConnection rowsAffectedByLastQuery] && ![mySQLConnection queryErrored] ) { diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m index bdf3a9fd..2fbd6b5b 100644 --- a/Source/SPTableStructure.m +++ b/Source/SPTableStructure.m @@ -255,11 +255,7 @@ // If an error occurred, reset the interface and abort if ([mySQLConnection queryErrored]) { -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#endif [[self onMainThread] setTableDetails:nil]; if ([mySQLConnection isConnected]) { @@ -384,11 +380,7 @@ autoIncrementIndex = nil; // Send the query finished/work complete notification -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#endif [theTableFields release]; } diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m index f4a21800..0283eb98 100644 --- a/Source/SPTablesList.m +++ b/Source/SPTablesList.m @@ -134,11 +134,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; if ([tableDocumentInstance database]) { // Notify listeners that a query has started -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; -#endif // Use UTF8 for identifier-based queries if (changeEncoding) { @@ -274,11 +270,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable"; if (changeEncoding) [mySQLConnection restoreStoredEncoding]; // Notify listeners that the query has finished -#ifndef SP_REFACTOR [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#else - [[NSNotificationCenter defaultCenter] sequelProPostNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; -#endif } // Add the table headers even if no tables were found -- cgit v1.2.3