diff options
author | stuconnolly <stuart02@gmail.com> | 2012-04-29 11:13:35 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2012-04-29 11:13:35 +0000 |
commit | 37b58a7b37cabc7409be30f57671d7af05961436 (patch) | |
tree | 884580160074d369ee309795454c138d9a6c1bfb /Source | |
parent | 6732cbb54f7fea129742dbe27e8681a993e6b2f5 (diff) | |
download | sequelpro-37b58a7b37cabc7409be30f57671d7af05961436.tar.gz sequelpro-37b58a7b37cabc7409be30f57671d7af05961436.tar.bz2 sequelpro-37b58a7b37cabc7409be30f57671d7af05961436.zip |
Pass the array of imported favorites instead of the whole dictionary to the delegate and improve error handling.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPConnectionControllerDelegate.m | 3 | ||||
-rw-r--r-- | Source/SPFavoritesImportProtocol.h | 2 | ||||
-rw-r--r-- | Source/SPFavoritesImporter.m | 47 |
3 files changed, 36 insertions, 16 deletions
diff --git a/Source/SPConnectionControllerDelegate.m b/Source/SPConnectionControllerDelegate.m index c0bdf5d8..dc429faf 100644 --- a/Source/SPConnectionControllerDelegate.m +++ b/Source/SPConnectionControllerDelegate.m @@ -524,9 +524,8 @@ static NSString *SPDatabaseImage = @"database-small"; /** * Called by the favorites importer when the imported data is available. */ -- (void)favoritesImportData:(NSDictionary *)data +- (void)favoritesImportData:(NSArray *)data { - // TODO: do something with the data } /** diff --git a/Source/SPFavoritesImportProtocol.h b/Source/SPFavoritesImportProtocol.h index f025ab8e..bee4d7e8 100644 --- a/Source/SPFavoritesImportProtocol.h +++ b/Source/SPFavoritesImportProtocol.h @@ -37,7 +37,7 @@ * * @param data The imported data as a dictionary. */ -- (void)favoritesImportData:(NSDictionary *)data; +- (void)favoritesImportData:(NSArray *)data; /** * Invoked when the favorites import proccess completes. diff --git a/Source/SPFavoritesImporter.m b/Source/SPFavoritesImporter.m index 60b483d5..5ec0c433 100644 --- a/Source/SPFavoritesImporter.m +++ b/Source/SPFavoritesImporter.m @@ -29,7 +29,8 @@ - (void)_importFavoritesInBackground; - (void)_informDelegateOfImportCompletion:(NSError *)error; -- (void)_informDelegateOfImportDataAvailable:(NSDictionary *)data; +- (void)_informDelegateOfImportDataAvailable:(NSArray *)data; +- (void)_informDelegateOfErrorCode:(NSUInteger)code description:(NSString *)description; @end @@ -50,6 +51,9 @@ [NSThread detachNewThreadSelector:@selector(_importFavoritesInBackground) toTarget:self withObject:nil]; } +#pragma mark - +#pragma mark Private API + /** * Starts the import process on a separate thread. */ @@ -57,25 +61,27 @@ { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSError *error = nil; + NSDictionary *importData; NSFileManager *fileManager = [NSFileManager defaultManager]; - NSDictionary *importData = nil; - if ([fileManager fileExistsAtPath:[self importPath]]) { importData = [[NSDictionary alloc] initWithContentsOfFile:[self importPath]]; - [self _informDelegateOfImportDataAvailable:importData]; + NSArray *favorites = [importData valueForKey:SPFavoritesDataRootKey]; + + if (favorites) { + [self _informDelegateOfImportDataAvailable:favorites]; + } + else { + [self _informDelegateOfErrorCode:NSFileReadUnknownError + description:NSLocalizedString(@"Error reading import file.", @"error reading import file")]; + } } else { - error = [NSError errorWithDomain:NSCocoaErrorDomain - code:NSFileNoSuchFileError - userInfo:[NSDictionary dictionaryWithObject:NSLocalizedString(@"Import file does not exist.", @"import file does not exist message") - forKey:NSLocalizedDescriptionKey]]; + [self _informDelegateOfErrorCode:NSFileReadNoSuchFileError + description:NSLocalizedString(@"Import file does not exist.", @"import file does not exist message")]; } - - [self _informDelegateOfImportCompletion:error]; - + [pool release]; } @@ -92,11 +98,26 @@ /** * Informs the delegate that the imported data is available. */ -- (void)_informDelegateOfImportDataAvailable:(NSDictionary *)data +- (void)_informDelegateOfImportDataAvailable:(NSArray *)data { if ([self delegate] && [[self delegate] respondsToSelector:@selector(favoritesImportData:)]) { [[self delegate] performSelectorOnMainThread:@selector(favoritesImportData:) withObject:data waitUntilDone:NO]; } } +/** + * Informs the delegate that an error occurred during the import. + * + * @param code The error code + * @param description A short description of the error + */ +- (void)_informDelegateOfErrorCode:(NSUInteger)code description:(NSString *)description +{ + NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain + code:code + userInfo:[NSDictionary dictionaryWithObject:description forKey:NSLocalizedDescriptionKey]]; + + [self _informDelegateOfImportCompletion:error]; +} + @end |