aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPFavoritesImporter.m
diff options
context:
space:
mode:
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