aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConnectionControllerDelegate.m3
-rw-r--r--Source/SPFavoritesImportProtocol.h2
-rw-r--r--Source/SPFavoritesImporter.m47
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