From: Miltiadis Vasilakis Date: Sat, 10 Sep 2011 12:06:15 +0000 (+0300) Subject: Initial implementation of browser context menu. X-Git-Tag: v0.1~73 X-Git-Url: https://code.grnet.gr/git/pithos-macos/commitdiff_plain/857217b05068c1b3bbd6ab25431536a049adab80 Initial implementation of browser context menu. Info window for subdirs. Support for application/directory objects. Conversion of subdir to application/directory object if metadata are applied. Other minor fixes and changes. --- diff --git a/pithos-macos/PithosAccountNode.h b/pithos-macos/PithosAccountNode.h index 7700332..e9abf01 100644 --- a/pithos-macos/PithosAccountNode.h +++ b/pithos-macos/PithosAccountNode.h @@ -1,5 +1,5 @@ // -// PithosNode.h +// PithosAccountNode.h // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. diff --git a/pithos-macos/PithosAccountNode.m b/pithos-macos/PithosAccountNode.m index e0a3e0f..3d2d457 100644 --- a/pithos-macos/PithosAccountNode.m +++ b/pithos-macos/PithosAccountNode.m @@ -1,5 +1,5 @@ // -// PithosNode.m +// PithosAccountNode.m // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. @@ -56,7 +56,7 @@ #pragma mark - #pragma mark ASIHTTPRequestDelegate -- (void)requestFinished:(ASIHTTPRequest *)request { +- (void)accountRequestFinished:(ASIPithosAccountRequest *)request { NSLog(@"URL: %@", [accountRequest url]); NSLog(@"cached: %d", [accountRequest didUseCachedResponse]); @@ -73,6 +73,7 @@ newChildren = [[NSMutableArray alloc] init]; for (ASIPithosContainer *container in containers) { PithosContainerNode *node = [[[PithosContainerNode alloc] initWithPithosContainer:container] autorelease]; + node.parent = self; if (children) { NSUInteger oldIndex = [children indexOfObject:node]; if (oldIndex != NSNotFound) { @@ -108,7 +109,7 @@ } } -- (void)requestFailed:(ASIHTTPRequest *)request { +- (void)accountRequestFailed:(ASIPithosAccountRequest *)request { // XXX do something on error, cleanup NSLog(@"error:%@", [accountRequest error]); [newChildren release]; @@ -143,6 +144,8 @@ shared:NO until:nil] retain]; accountRequest.delegate = self; + accountRequest.didFinishSelector = @selector(accountRequestFinished:); + accountRequest.didFailSelector = @selector(accountRequestFailed:); accountRequest.downloadCache = [ASIDownloadCache sharedCache]; [accountRequest startAsynchronous]; break; diff --git a/pithos-macos/PithosBrowserController.h b/pithos-macos/PithosBrowserController.h index fd4406b..a791ec1 100644 --- a/pithos-macos/PithosBrowserController.h +++ b/pithos-macos/PithosBrowserController.h @@ -39,20 +39,22 @@ @class PithosNode; @class PithosAccountNode; -@interface PithosBrowserController : NSWindowController { +@interface PithosBrowserController : NSWindowController { PithosNode *rootNode; PithosAccountNode *accountNode; NSMutableArray *outlineViewDataSourceArray; NSViewController *sharedPreviewController; + + NSMenu *browserMenu; } @property (nonatomic, retain) NSMutableArray *outlineViewDataSourceArray; -@property (nonatomic, retain) IBOutlet NSSplitView *splitView; -@property (nonatomic, retain) IBOutlet NSOutlineView *outlineView; -@property (nonatomic, retain) IBOutlet NSBrowser *browser; +@property (nonatomic, assign) IBOutlet NSSplitView *splitView; +@property (nonatomic, assign) IBOutlet NSOutlineView *outlineView; +@property (nonatomic, assign) IBOutlet NSBrowser *browser; - (IBAction)refresh:(id)sender; diff --git a/pithos-macos/PithosBrowserController.m b/pithos-macos/PithosBrowserController.m index 112cb4d..11e2bdc 100644 --- a/pithos-macos/PithosBrowserController.m +++ b/pithos-macos/PithosBrowserController.m @@ -99,6 +99,7 @@ @interface PithosBrowserController (Private) {} - (void)resetContainers; +- (void)getInfo:(NSMenuItem *)sender; @end @implementation PithosBrowserController @@ -113,13 +114,11 @@ - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; + [browserMenu release]; [sharedPreviewController release]; [outlineViewDataSourceArray release]; [accountNode release]; [rootNode release]; - [browser release]; - [splitView release]; - [outlineView release]; [super dealloc]; } @@ -130,6 +129,10 @@ [browser setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO]; [browser setCellClass:[PithosBrowserCell class]]; + + browserMenu = [[NSMenu alloc] init]; + [browserMenu setDelegate:self]; + [browser setMenu:browserMenu]; } - (void)resetContainers { @@ -452,4 +455,29 @@ forDraggedRowsWithIndexes:(NSIndexSet *)rowIndexes inColumn:(NSInteger)column { } } +#pragma mark - +#pragma mark NSMenuDelegate + +- (void)menuNeedsUpdate:(NSMenu *)menu { + NSInteger column = [browser clickedColumn]; + NSInteger row = [browser clickedRow]; + [menu removeAllItems]; + if ((column == -1) || (row == -1)) { + // General context menu has 0 + } else { + // PithosNode menu has 1 items + // Get Info + NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"Get Info" action:@selector(getInfo:) keyEquivalent:@""]; + [menuItem setRepresentedObject:[browser itemAtRow:row inColumn:column]]; + [menu addItem:menuItem]; + } +} + +#pragma mark - +#pragma mark Menu Actions + +- (void)getInfo:(NSMenuItem *)sender { + [(PithosNode *)[sender representedObject] showPithosNodeInfo:sender]; +} + @end \ No newline at end of file diff --git a/pithos-macos/PithosContainerNode.h b/pithos-macos/PithosContainerNode.h index 9239066..7b91d55 100644 --- a/pithos-macos/PithosContainerNode.h +++ b/pithos-macos/PithosContainerNode.h @@ -1,5 +1,5 @@ // -// PithosNode.h +// PithosContainerNode.h // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. @@ -54,6 +54,7 @@ - (id)initWithContainerName:(NSString *)aContainerName icon:(NSImage *)anIcon; @property(nonatomic, retain) ASIPithosContainer *pithosContainer; +@property(nonatomic, retain) NSString *prefix; - (void)setIcon:(NSImage *)anIcon; diff --git a/pithos-macos/PithosContainerNode.m b/pithos-macos/PithosContainerNode.m index aac59b7..0fdcac1 100644 --- a/pithos-macos/PithosContainerNode.m +++ b/pithos-macos/PithosContainerNode.m @@ -1,5 +1,5 @@ // -// PithosNode.m +// PithosContainerNode.m // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. @@ -46,7 +46,7 @@ static NSImage *sharedIcon = nil; @implementation PithosContainerNode -@synthesize pithosContainer; +@synthesize pithosContainer, prefix; + (void)initialize { if (self == [PithosContainerNode class]) @@ -58,7 +58,7 @@ static NSImage *sharedIcon = nil; - (id)initWithPithosContainer:(ASIPithosContainer *)aPithosContainer icon:(NSImage *)anIcon { if ((self = [super init])) { - pithosContainer = [aPithosContainer retain]; + self.pithosContainer = aPithosContainer; prefix = nil; icon = [anIcon retain]; childrenUpdatedNotificationName = @"PithosContainerNodeChildrenUpdated"; @@ -93,7 +93,7 @@ static NSImage *sharedIcon = nil; #pragma mark - #pragma mark ASIHTTPRequestDelegate -- (void)requestFinished:(ASIHTTPRequest *)request { +- (void)containerRequestFinished:(ASIPithosContainerRequest *)request { NSLog(@"URL: %@", [containerRequest url]); NSLog(@"cached: %d", [containerRequest didUseCachedResponse]); @@ -110,7 +110,27 @@ static NSImage *sharedIcon = nil; newChildren = [[NSMutableArray alloc] init]; for (ASIPithosObject *object in objects) { if (object.subdir) { + PithosNode *previousNode = (PithosNode *)[newChildren lastObject]; + if (!previousNode || + ([previousNode class] != [PithosSubdirNode class]) || + (![((PithosSubdirNode *)previousNode).pithosObject.contentType isEqualToString:@"application/directory"]) || + (![[((PithosSubdirNode *)previousNode).pithosObject.name stringByAppendingString:@"/"] isEqualToString:object.name])) { + PithosSubdirNode *node = [[[PithosSubdirNode alloc] initWithPithosContainer:pithosContainer pithosObject:object] autorelease]; + node.parent = self; + if (children) { + NSUInteger oldIndex = [children indexOfObject:node]; + if (oldIndex != NSNotFound) { + // Use the same pointer value, if possible + node = [children objectAtIndex:oldIndex]; + node.pithosContainer = pithosContainer; + node.pithosObject = object; + } + } + [newChildren addObject:node]; + } + } else if ([object.contentType isEqualToString:@"application/directory"]) { PithosSubdirNode *node = [[[PithosSubdirNode alloc] initWithPithosContainer:pithosContainer pithosObject:object] autorelease]; + node.parent = self; if (children) { NSUInteger oldIndex = [children indexOfObject:node]; if (oldIndex != NSNotFound) { @@ -121,10 +141,12 @@ static NSImage *sharedIcon = nil; } } [newChildren addObject:node]; - } else if (([self class] != [PithosSubdirNode class]) || (![((PithosSubdirNode *)self).pithosObject.name isEqualToString:object.name])) { + } else if (([self class] != [PithosSubdirNode class]) || + ![[((PithosSubdirNode *)self).prefix stringByAppendingString:@"/"] isEqualToString:object.name]) { // XXX the if above removes false objects due to trailing slash // XXX this will change in the server, but it is fixed in the client for now PithosObjectNode *node = [[[PithosObjectNode alloc] initWithPithosContainer:pithosContainer pithosObject:object] autorelease]; + node.parent = self; if (children) { NSUInteger oldIndex = [children indexOfObject:node]; if (oldIndex != NSNotFound) { @@ -167,7 +189,7 @@ static NSImage *sharedIcon = nil; } } -- (void)requestFailed:(ASIHTTPRequest *)request { +- (void)containerRequestFailed:(ASIPithosContainerRequest *)request { // XXX do something on error, cleanup NSLog(@"error:%@", [containerRequest error]); [newChildren release]; @@ -207,6 +229,8 @@ static NSImage *sharedIcon = nil; shared:NO until:nil] retain]; containerRequest.delegate = self; + containerRequest.didFinishSelector = @selector(containerRequestFinished:); + containerRequest.didFailSelector = @selector(containerRequestFailed:); containerRequest.downloadCache = [ASIDownloadCache sharedCache]; [containerRequest startAsynchronous]; break; diff --git a/pithos-macos/PithosEmptyNode.h b/pithos-macos/PithosEmptyNode.h index 90f62a2..238bf93 100644 --- a/pithos-macos/PithosEmptyNode.h +++ b/pithos-macos/PithosEmptyNode.h @@ -1,5 +1,5 @@ // -// PithosEmpty.h +// PithosEmptyNode.h // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. diff --git a/pithos-macos/PithosEmptyNode.m b/pithos-macos/PithosEmptyNode.m index 928562a..98f6a58 100644 --- a/pithos-macos/PithosEmptyNode.m +++ b/pithos-macos/PithosEmptyNode.m @@ -1,5 +1,5 @@ // -// PithosEmpty.m +// PithosEmptyNode.m // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. diff --git a/pithos-macos/PithosNode.h b/pithos-macos/PithosNode.h index eddc26d..82a1ba9 100644 --- a/pithos-macos/PithosNode.h +++ b/pithos-macos/PithosNode.h @@ -49,6 +49,7 @@ NSString *url; + PithosNode *parent; NSMutableArray *children; NSMutableArray *newChildren; @@ -60,6 +61,7 @@ PithosNodeInfoController *pithosNodeInfoController; } +@property(nonatomic, assign) PithosNode *parent; @property(readonly) NSString *url; @property(readonly) NSArray *children; @property(readonly) NSString *displayName; diff --git a/pithos-macos/PithosNode.m b/pithos-macos/PithosNode.m index b814c5b..5795b14 100644 --- a/pithos-macos/PithosNode.m +++ b/pithos-macos/PithosNode.m @@ -39,6 +39,7 @@ #import "PithosNodeInfoController.h" @implementation PithosNode +@synthesize parent; @dynamic url, children, displayName, icon; @dynamic pithosContainer, pithosObject; @synthesize isLeafItem; diff --git a/pithos-macos/PithosNodeInfoController.xib b/pithos-macos/PithosNodeInfoController.xib index 45fb87a..a851ede 100644 --- a/pithos-macos/PithosNodeInfoController.xib +++ b/pithos-macos/PithosNodeInfoController.xib @@ -865,7 +865,7 @@ 274 - {13, 18} + {13, 36} YES @@ -1282,26 +1282,6 @@ - value: node.pithosObject.bytes - - - - - - value: node.pithosObject.bytes - value - node.pithosObject.bytes - - NSValueTransformerName - BytesSizeTransformer - - 2 - - - 171 - - - value: node.pithosContainer.name @@ -1333,94 +1313,6 @@ 173 - - value: node.pithosObject.contentType - - - - - - value: node.pithosObject.contentType - value - node.pithosObject.contentType - 2 - - - 174 - - - - value: node.pithosObject.lastModified - - - - - - value: node.pithosObject.lastModified - value - node.pithosObject.lastModified - - NSValueTransformerName - LastModifiedDateTransformer - - 2 - - - 176 - - - - value: node.pithosObject.modifiedBy - - - - - - value: node.pithosObject.modifiedBy - value - node.pithosObject.modifiedBy - 2 - - - 177 - - - - value: node.pithosObject.version - - - - - - value: node.pithosObject.version - value - node.pithosObject.version - 2 - - - 178 - - - - value: node.pithosObject.bytes - - - - - - value: node.pithosObject.bytes - value - node.pithosObject.bytes - - NSValueTransformerName - BytesExtendedSizeTransformer - - 2 - - - 184 - - add: @@ -1601,22 +1493,6 @@ - value: node.isPublic - - - - - - value: node.isPublic - value - node.isPublic - 2 - - - 293 - - - value: node.pithosObject.publicURI @@ -1810,6 +1686,169 @@ 322 + + + value: node.pithosObject.bytes + + + + + + value: node.pithosObject.bytes + value + node.pithosObject.bytes + + YES + + YES + NSNullPlaceholder + NSValueTransformerName + + + YES + - + BytesSizeTransformer + + + 2 + + + 323 + + + + value: node.pithosObject.contentType + + + + + + value: node.pithosObject.contentType + value + node.pithosObject.contentType + + NSNullPlaceholder + - + + 2 + + + 324 + + + + value: node.pithosObject.bytes + + + + + + value: node.pithosObject.bytes + value + node.pithosObject.bytes + + YES + + YES + NSNullPlaceholder + NSValueTransformerName + + + YES + - + BytesExtendedSizeTransformer + + + 2 + + + 325 + + + + value: node.pithosObject.lastModified + + + + + + value: node.pithosObject.lastModified + value + node.pithosObject.lastModified + + YES + + YES + NSNullPlaceholder + NSValueTransformerName + + + YES + - + LastModifiedDateTransformer + + + 2 + + + 326 + + + + value: node.pithosObject.modifiedBy + + + + + + value: node.pithosObject.modifiedBy + value + node.pithosObject.modifiedBy + + NSNullPlaceholder + - + + 2 + + + 327 + + + + value: node.pithosObject.version + + + + + + value: node.pithosObject.version + value + node.pithosObject.version + + NSNullPlaceholder + - + + 2 + + + 328 + + + + value: node.isPublic + + + + + + value: node.isPublic + value + node.isPublic + 2 + + + 330 + @@ -2698,7 +2737,7 @@ - 322 + 330 0 diff --git a/pithos-macos/PithosObjectNode.h b/pithos-macos/PithosObjectNode.h index f90522f..6ffa522 100644 --- a/pithos-macos/PithosObjectNode.h +++ b/pithos-macos/PithosObjectNode.h @@ -1,5 +1,5 @@ // -// PithosNode.h +// PithosObjectNode.h // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. diff --git a/pithos-macos/PithosObjectNode.m b/pithos-macos/PithosObjectNode.m index dd1fcdb..e02d04a 100644 --- a/pithos-macos/PithosObjectNode.m +++ b/pithos-macos/PithosObjectNode.m @@ -1,5 +1,5 @@ // -// PithosNode.m +// PithosObjectNode.m // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. @@ -41,7 +41,6 @@ #import "ASIPithosContainer.h" #import "ASIPithosObject.h" #import "ASIDownloadCache.h" -#import "PithosNodeInfoController.h" @implementation PithosObjectNode @synthesize pithosContainer, pithosObject; @@ -123,6 +122,8 @@ metadata:pithosObject.metadata update:NO] retain]; applyMetadataObjectRequest.delegate = self; + applyMetadataObjectRequest.didFinishSelector = @selector(objectRequestFinished:); + applyMetadataObjectRequest.didFailSelector = @selector(objectRequestFailed:); [applyMetadataObjectRequest startAsynchronous]; } } @@ -134,6 +135,8 @@ refreshMetadataObjectRequest = [[ASIPithosObjectRequest objectMetadataRequestWithContainerName:pithosContainer.name objectName:pithosObject.name] retain]; refreshMetadataObjectRequest.delegate = self; + refreshMetadataObjectRequest.didFinishSelector = @selector(objectRequestFinished:); + refreshMetadataObjectRequest.didFailSelector = @selector(objectRequestFailed:); refreshMetadataObjectRequest.downloadCache = [ASIDownloadCache sharedCache]; [refreshMetadataObjectRequest startAsynchronous]; } @@ -143,7 +146,7 @@ #pragma mark - #pragma mark ASIHTTPRequestDelegate -- (void)requestFinished:(ASIHTTPRequest *)request { +- (void)objectRequestFinished:(ASIPithosObjectRequest *)request { NSLog(@"URL: %@", [request url]); NSLog(@"cached: %d", [request didUseCachedResponse]); @@ -162,7 +165,7 @@ } } -- (void)requestFailed:(ASIHTTPRequest *)request { +- (void)objectRequestFailed:(ASIPithosObjectRequest *)request { if ([request isEqualTo:applyMetadataObjectRequest]) { // XXX do something on error, cleanup NSLog(@"error:%@", [applyMetadataObjectRequest error]); diff --git a/pithos-macos/PithosSubdirNode.h b/pithos-macos/PithosSubdirNode.h index 0bbf0ce..d61e679 100644 --- a/pithos-macos/PithosSubdirNode.h +++ b/pithos-macos/PithosSubdirNode.h @@ -1,5 +1,5 @@ // -// PithosNode.h +// PithosSubdirNode.h // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. @@ -37,13 +37,25 @@ #import "PithosContainerNode.h" @class ASIPithosObject; +@class ASIPithosObjectRequest; @interface PithosSubdirNode : PithosContainerNode { ASIPithosObject *pithosObject; + + ASIPithosObjectRequest *applyMetadataObjectRequest; + ASIPithosObjectRequest *refreshMetadataObjectRequest; + + BOOL isPublic; + + BOOL refreshParent; } - (id)initWithPithosContainer:(ASIPithosContainer *)aPithosContainer pithosObject:(ASIPithosObject *)aPithosObject; @property (nonatomic, retain) ASIPithosObject *pithosObject; +@property (nonatomic, assign) BOOL isPublic; + +- (void)applyInfo; +- (void)refreshInfo; @end \ No newline at end of file diff --git a/pithos-macos/PithosSubdirNode.m b/pithos-macos/PithosSubdirNode.m index b96d7ff..0ca7a09 100644 --- a/pithos-macos/PithosSubdirNode.m +++ b/pithos-macos/PithosSubdirNode.m @@ -1,5 +1,5 @@ // -// PithosNode.m +// PithosSubdirNode.m // pithos-macos // // Copyright 2011 GRNET S.A. All rights reserved. @@ -37,13 +37,16 @@ #import "PithosSubdirNode.h" #import "ASIPithosRequest.h" +#import "ASIPithosObjectRequest.h" #import "ASIPithosContainer.h" #import "ASIPithosObject.h" +#import "ASIDownloadCache.h" static NSImage *sharedIcon = nil; @implementation PithosSubdirNode @synthesize pithosObject; +@synthesize isPublic; + (void)initialize { if (self == [PithosSubdirNode class]) @@ -55,15 +58,19 @@ static NSImage *sharedIcon = nil; - (id)initWithPithosContainer:(ASIPithosContainer *)aPithosContainer pithosObject:(ASIPithosObject *)aPithosObject { if ((self = [super init])) { - pithosContainer = [aPithosContainer retain]; - pithosObject = [aPithosObject retain]; - prefix = [[pithosObject.name substringToIndex:([pithosObject.name length] - 1)] retain]; + self.pithosContainer = aPithosContainer; + self.pithosObject = aPithosObject; childrenUpdatedNotificationName = @"PithosSubdirNodeChildrenUpdated"; + refreshParent = NO; } return self; } - (void)dealloc { + [refreshMetadataObjectRequest clearDelegatesAndCancel]; + [refreshMetadataObjectRequest release]; + [applyMetadataObjectRequest clearDelegatesAndCancel]; + [applyMetadataObjectRequest release]; [pithosObject release]; [super dealloc]; } @@ -73,7 +80,7 @@ static NSImage *sharedIcon = nil; - (NSString *)url { if (url == nil) - url = [[NSString alloc] initWithFormat:@"subdir %@/%@/%@", [ASIPithosRequest storageURL], pithosContainer.name, pithosObject.name]; + url = [[NSString alloc] initWithFormat:@"subdir %@/%@/%@", [ASIPithosRequest storageURL], pithosContainer.name, prefix]; return url; } @@ -88,4 +95,172 @@ static NSImage *sharedIcon = nil; return sharedIcon; } +- (void)setPithosObject:(ASIPithosObject *)aPithosObject { + if (![pithosObject isEqualTo:aPithosObject]) { + [pithosObject release]; + pithosObject = [aPithosObject retain]; + } + if (pithosObject.subdir) { + self.prefix = [pithosObject.name substringToIndex:([pithosObject.name length] - 1)]; + } else { + self.prefix = [NSString stringWithString:pithosObject.name]; + } + self.isPublic = (pithosObject.publicURI != nil); +} + +#pragma mark - +#pragma mark Info + +- (void)applyInfo { + @synchronized(self) { + if (applyMetadataObjectRequest == nil) { + if (pithosObject.subdir) { + BOOL createObject = NO; + NSAlert *alert = [[[NSAlert alloc] init] autorelease]; + ASIPithosObjectRequest *request = [ASIPithosObjectRequest objectMetadataRequestWithContainerName:pithosContainer.name + objectName:prefix]; + [request startSynchronous]; + if ([request error]) { + [alert setMessageText:@"HTTP Request Error"]; + [alert setInformativeText:[NSString stringWithFormat:@"An error occured: %@", [request error]]]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } else if (request.responseStatusCode == 200) { + [alert setMessageText:@"Apply changes"]; + [alert setInformativeText:[NSString stringWithFormat:@"In order to apply the changes in '%@', the object at the same path must be replaced. Continue?", self.displayName]]; + [alert addButtonWithTitle:@"OK"]; + [alert addButtonWithTitle:@"Cancel"]; + NSInteger choice = [alert runModal]; + if (choice == NSAlertFirstButtonReturn) { + request = [ASIPithosObjectRequest deleteContainerRequestWithContainerName:pithosContainer.name + objectName:prefix]; + [request startSynchronous]; + if ([request error]) { + [alert setMessageText:@"HTTP Request Error"]; + [alert setInformativeText:[NSString stringWithFormat:@"An error occured: %@", [request error]]]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } else if (request.responseStatusCode != 204) { + [alert setMessageText:@"Unexpected Response Status"]; + [alert setInformativeText:[NSString stringWithFormat:@"Unexpected response status %d - %@", request.responseStatusCode, request.responseStatusMessage]]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + refreshParent = YES; + createObject = YES; + } else { + return; + } + } else if (request.responseStatusCode == 404) { + createObject = YES; + } else { + [alert setMessageText:@"Unexpected Response Status"]; + [alert setInformativeText:[NSString stringWithFormat:@"Unexpected response status %d - %@", request.responseStatusCode, request.responseStatusMessage]]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + if (createObject) { + applyMetadataObjectRequest = [[ASIPithosObjectRequest writeObjectDataRequestWithContainerName:pithosContainer.name + objectName:prefix + eTag:nil + contentType:@"application/directory" + contentEncoding:nil + contentDisposition:nil + manifest:nil + sharing:pithosObject.sharing + isPublic:(isPublic ? ASIPithosObjectRequestPublicTrue : ASIPithosObjectRequestPublicFalse) + metadata:pithosObject.metadata + data:[NSData data]] retain]; + pithosObject.subdir = NO; + applyMetadataObjectRequest.delegate = self; + applyMetadataObjectRequest.didFinishSelector = @selector(objectRequestFinished:); + applyMetadataObjectRequest.didFailSelector = @selector(objectRequestFailed:); + [applyMetadataObjectRequest startAsynchronous]; + } + } else { + applyMetadataObjectRequest = [[ASIPithosObjectRequest updateObjectMetadataRequestWithContainerName:pithosContainer.name + objectName:pithosObject.name + contentEncoding:nil + contentDisposition:nil + manifest:nil + sharing:pithosObject.sharing + isPublic:(isPublic ? ASIPithosObjectRequestPublicTrue : ASIPithosObjectRequestPublicFalse) + metadata:pithosObject.metadata + update:NO] retain]; + applyMetadataObjectRequest.delegate = self; + applyMetadataObjectRequest.didFinishSelector = @selector(objectRequestFinished:); + applyMetadataObjectRequest.didFailSelector = @selector(objectRequestFailed:); + [applyMetadataObjectRequest startAsynchronous]; + } + } + } +} + +- (void)refreshInfo { + @synchronized(self) { + if (pithosObject.subdir) { + self.pithosObject = [ASIPithosObject subdirWithName:pithosObject.name]; + } else if (refreshMetadataObjectRequest == nil) { + refreshMetadataObjectRequest = [[ASIPithosObjectRequest objectMetadataRequestWithContainerName:pithosContainer.name + objectName:prefix] retain]; + refreshMetadataObjectRequest.delegate = self; + refreshMetadataObjectRequest.didFinishSelector = @selector(objectRequestFinished:); + refreshMetadataObjectRequest.didFailSelector = @selector(objectRequestFailed:); + refreshMetadataObjectRequest.downloadCache = [ASIDownloadCache sharedCache]; + [refreshMetadataObjectRequest startAsynchronous]; + } + } +} + +#pragma mark - +#pragma mark ASIHTTPRequestDelegate + +- (void)objectRequestFinished:(ASIPithosObjectRequest *)request { + NSLog(@"URL: %@", [request url]); + NSLog(@"cached: %d", [request didUseCachedResponse]); + + if ([request isEqualTo:applyMetadataObjectRequest]) { + @synchronized(self) { + [applyMetadataObjectRequest release]; + applyMetadataObjectRequest = nil; + } + [self refreshInfo]; + } else if ([request isEqualTo:refreshMetadataObjectRequest]) { + self.pithosObject = [refreshMetadataObjectRequest object]; + if (refreshParent) { + // Ask the parent for refresh for the case where an object was removed + // It is done here so that it doesn'e affect the info window refresh + [parent invalidateChildren]; + [parent children]; + refreshParent = NO; + } + @synchronized(self) { + [refreshMetadataObjectRequest release]; + refreshMetadataObjectRequest = nil; + } + } +} + +- (void)objectRequestFailed:(ASIPithosObjectRequest *)request { + if ([request isEqualTo:applyMetadataObjectRequest]) { + // XXX do something on error, cleanup + NSLog(@"error:%@", [applyMetadataObjectRequest error]); + @synchronized(self) { + [applyMetadataObjectRequest release]; + applyMetadataObjectRequest = nil; + } + } else if ([request isEqualTo:refreshMetadataObjectRequest]) { + // XXX do something on error, cleanup + NSLog(@"error:%@", [refreshMetadataObjectRequest error]); + @synchronized(self) { + [refreshMetadataObjectRequest release]; + refreshMetadataObjectRequest = nil; + } + } +} + @end