diff --git a/Ubuntu One Client/AsynchronousAdapter.h b/Ubuntu One Client/AsynchronousAdapter.h index 8a84007..f9622d8 100644 --- a/Ubuntu One Client/AsynchronousAdapter.h +++ b/Ubuntu One Client/AsynchronousAdapter.h @@ -22,6 +22,7 @@ #import "AbstractAdapter.h" @protocol AsynchronousAdapterDelegate +- (void)willStartLoading; - (void)didReceiveData:(NSData*)data; - (void)didFailWithError:(NSError*)error; - (void)didFinishLoading; diff --git a/Ubuntu One Client/AsynchronousAdapter.m b/Ubuntu One Client/AsynchronousAdapter.m index 706cbe4..646e084 100644 --- a/Ubuntu One Client/AsynchronousAdapter.m +++ b/Ubuntu One Client/AsynchronousAdapter.m @@ -49,6 +49,10 @@ - (void)request { NSLog(@"requesting %@", request.URL.absoluteString); #endif + [_delegates enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + [obj willStartLoading]; + }]; + [NSURLConnection connectionWithRequest:request delegate:self]; } diff --git a/Ubuntu One Client/AsynchronousAdapterOperation.h b/Ubuntu One Client/AsynchronousAdapterOperation.h index 71de30d..7e8f5e2 100644 --- a/Ubuntu One Client/AsynchronousAdapterOperation.h +++ b/Ubuntu One Client/AsynchronousAdapterOperation.h @@ -1,6 +1,6 @@ #import #import "AsynchronousAdapter.h" -@interface AsynchronousAdapterOperation : NSOperation +@interface AsynchronousAdapterOperation : NSOperation + (AsynchronousAdapterOperation*)adapterOperationWithAsynchronousAdapter:(AsynchronousAdapter*)adapter; @end diff --git a/Ubuntu One Client/AsynchronousAdapterOperation.m b/Ubuntu One Client/AsynchronousAdapterOperation.m index c9b772b..3e125d1 100644 --- a/Ubuntu One Client/AsynchronousAdapterOperation.m +++ b/Ubuntu One Client/AsynchronousAdapterOperation.m @@ -1,8 +1,5 @@ #import "AsynchronousAdapterOperation.h" -@interface AsynchronousAdapterOperation (Private) -@end - @implementation AsynchronousAdapterOperation { @private AsynchronousAdapter *_adapter; @@ -36,6 +33,11 @@ - (void)main { #pragma mark - #pragma mark AsynchronAdapterDelegate + +- (void)willStartLoading { + // ... +} + - (void)didReceiveData:(NSData*)data { // ... } diff --git a/Ubuntu One Client/FileAttributesUpdatingAsynchronAdapterDelegate.m b/Ubuntu One Client/FileAttributesUpdatingAsynchronAdapterDelegate.m index df3fa9d..2d278cc 100644 --- a/Ubuntu One Client/FileAttributesUpdatingAsynchronAdapterDelegate.m +++ b/Ubuntu One Client/FileAttributesUpdatingAsynchronAdapterDelegate.m @@ -38,6 +38,10 @@ - (id)initWithAbsolutePath:(NSString*)absolutePath { return self; } +- (void)willStartLoading { + // ... +} + - (void)didReceiveData:(NSData*)data { if (!_data) { _data = [NSMutableData dataWithData:data]; diff --git a/Ubuntu One Client/FileWritingAsynchronousAdapterDelegate.m b/Ubuntu One Client/FileWritingAsynchronousAdapterDelegate.m index 23f7072..fecc396 100644 --- a/Ubuntu One Client/FileWritingAsynchronousAdapterDelegate.m +++ b/Ubuntu One Client/FileWritingAsynchronousAdapterDelegate.m @@ -32,16 +32,18 @@ @implementation FileWritingAsynchronousAdapterDelegate{ - (id)initWithAbsolutePath:(NSString*)path andNodeDetails:(NodeDetails*)nodeDetails { self = [super init]; if (self) { - _absolutePath = path; + _absolutePath = [path stringByExpandingTildeInPath]; _nodeDetails = nodeDetails; - - [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil]; - _fileHandle = [NSFileHandle fileHandleForWritingAtPath:[path stringByExpandingTildeInPath]]; } return self; } +- (void)willStartLoading { + [[NSFileManager defaultManager] createFileAtPath:_absolutePath contents:nil attributes:nil]; + _fileHandle = [NSFileHandle fileHandleForWritingAtPath:_absolutePath]; +} + - (void)didReceiveData:(NSData *)data { [_fileHandle writeData:data]; } diff --git a/Ubuntu One Client/StatusItemController.h b/Ubuntu One Client/StatusItemController.h index 6d4e1bf..5ab9a2d 100644 --- a/Ubuntu One Client/StatusItemController.h +++ b/Ubuntu One Client/StatusItemController.h @@ -24,7 +24,8 @@ #import "OptionsWindowController.h" @interface StatusItemController : NSObject -@property (weak) IBOutlet NSMenu *menu; +@property(weak) IBOutlet NSMenu *menu; + - (IBAction)clickedSyncNowMenuItem:(NSMenuItem *)sender; - (IBAction)clickedOptionsMenuItem:(NSMenuItem *)sender; @end diff --git a/Ubuntu One Client/StatusItemController.m b/Ubuntu One Client/StatusItemController.m index b9ef3a5..e913337 100644 --- a/Ubuntu One Client/StatusItemController.m +++ b/Ubuntu One Client/StatusItemController.m @@ -24,7 +24,6 @@ #import "SyncWorker.h" #import "Constants.h" - @implementation StatusItemController { @private NSStatusItem *_statusItem; @@ -50,7 +49,6 @@ - (void)awakeFromNib { - (IBAction)clickedSyncNowMenuItem:(NSMenuItem *)sender { AuthorizationDetails *authorizationDetails = [AuthorizationDetails current]; - NSString *path = [[NSUserDefaults standardUserDefaults] stringForKey:kLocalFolder]; [SyncWorker syncWithAbsoluteRootPath:path andAuthorizationDetails:authorizationDetails]; } diff --git a/Ubuntu One Client/SyncWorker.m b/Ubuntu One Client/SyncWorker.m index e4324e6..db4594a 100644 --- a/Ubuntu One Client/SyncWorker.m +++ b/Ubuntu One Client/SyncWorker.m @@ -25,6 +25,7 @@ #import "ContentAdapter.h" #import "AsynchronousAdapterOperation.h" #import "ContentUploadAdapter.h" + #import "FileWritingAsynchronousAdapterDelegate.h" #import "FileAttributesUpdatingAsynchronAdapterDelegate.h" @@ -184,15 +185,17 @@ - (void)createRemoteDirectory:(NSString*)resourcePath { #pragma mark - #pragma mark FileHandler -- (void)download:(NodeDetails*)nodeDetails to:(NSString*)absolutePath { - NSAssert(absolutePath, @"absolutePath must not be null."); +- (void)download:(NodeDetails*)nodeDetails to:(NSString*)path { + NSAssert(path, @"absolutePath must not be null."); NSAssert(nodeDetails, @"nodeDetails must not be null."); - NSLog(@"downloading \"%@\" to \"%@\"", nodeDetails.resourcePath, absolutePath); + NSLog(@"downloading \"%@\" to \"%@\"", nodeDetails.resourcePath, path); - FileWritingAsynchronousAdapterDelegate *fileWritingDelegate = [[FileWritingAsynchronousAdapterDelegate alloc] initWithAbsolutePath:absolutePath andNodeDetails:nodeDetails]; - NSArray *delegates = [NSArray arrayWithObject:fileWritingDelegate]; + FileWritingAsynchronousAdapterDelegate *fileWritingDelegate = [[FileWritingAsynchronousAdapterDelegate alloc] initWithAbsolutePath:path andNodeDetails:nodeDetails]; + + NSArray *delegates = [NSArray arrayWithObjects:fileWritingDelegate, nil]; AsynchronousAdapter *adapter = [ContentAdapter adapterWithContentPath:nodeDetails.contentPath authorizationDetails:_authorizationDetails andDelegates:delegates]; + NSOperation *operation = [AsynchronousAdapterOperation adapterOperationWithAsynchronousAdapter:adapter]; [_operationQueue addOperation:operation]; }