aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFavoritesImporter.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-04-29 11:13:35 +0000
committerstuconnolly <stuart02@gmail.com>2012-04-29 11:13:35 +0000
commit37b58a7b37cabc7409be30f57671d7af05961436 (patch)
tree884580160074d369ee309795454c138d9a6c1bfb /Source/SPFavoritesImporter.m
parent6732cbb54f7fea129742dbe27e8681a993e6b2f5 (diff)
downloadsequelpro-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/SPFavoritesImporter.m')
-rw-r--r--Source/SPFavoritesImporter.m47
1 files changed, 34 insertions, 13 deletions
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