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.
//
-// PithosNode.h
+// PithosAccountNode.h
// pithos-macos
//
// Copyright 2011 GRNET S.A. All rights reserved.
//
-// PithosNode.m
+// PithosAccountNode.m
// pithos-macos
//
// Copyright 2011 GRNET S.A. All rights reserved.
#pragma mark -
#pragma mark ASIHTTPRequestDelegate
-- (void)requestFinished:(ASIHTTPRequest *)request {
+- (void)accountRequestFinished:(ASIPithosAccountRequest *)request {
NSLog(@"URL: %@", [accountRequest url]);
NSLog(@"cached: %d", [accountRequest didUseCachedResponse]);
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) {
}
}
-- (void)requestFailed:(ASIHTTPRequest *)request {
+- (void)accountRequestFailed:(ASIPithosAccountRequest *)request {
// XXX do something on error, cleanup
NSLog(@"error:%@", [accountRequest error]);
[newChildren release];
shared:NO
until:nil] retain];
accountRequest.delegate = self;
+ accountRequest.didFinishSelector = @selector(accountRequestFinished:);
+ accountRequest.didFailSelector = @selector(accountRequestFailed:);
accountRequest.downloadCache = [ASIDownloadCache sharedCache];
[accountRequest startAsynchronous];
break;
@class PithosNode;
@class PithosAccountNode;
-@interface PithosBrowserController : NSWindowController <NSBrowserDelegate, NSSplitViewDelegate, NSOutlineViewDelegate> {
+@interface PithosBrowserController : NSWindowController <NSBrowserDelegate, NSSplitViewDelegate, NSOutlineViewDelegate, NSMenuDelegate> {
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;
@interface PithosBrowserController (Private) {}
- (void)resetContainers;
+- (void)getInfo:(NSMenuItem *)sender;
@end
@implementation PithosBrowserController
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
+ [browserMenu release];
[sharedPreviewController release];
[outlineViewDataSourceArray release];
[accountNode release];
[rootNode release];
- [browser release];
- [splitView release];
- [outlineView release];
[super dealloc];
}
[browser setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
[browser setCellClass:[PithosBrowserCell class]];
+
+ browserMenu = [[NSMenu alloc] init];
+ [browserMenu setDelegate:self];
+ [browser setMenu:browserMenu];
}
- (void)resetContainers {
}
}
+#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
//
-// PithosNode.h
+// PithosContainerNode.h
// pithos-macos
//
// Copyright 2011 GRNET S.A. All rights reserved.
- (id)initWithContainerName:(NSString *)aContainerName icon:(NSImage *)anIcon;
@property(nonatomic, retain) ASIPithosContainer *pithosContainer;
+@property(nonatomic, retain) NSString *prefix;
- (void)setIcon:(NSImage *)anIcon;
//
-// PithosNode.m
+// PithosContainerNode.m
// pithos-macos
//
// Copyright 2011 GRNET S.A. All rights reserved.
static NSImage *sharedIcon = nil;
@implementation PithosContainerNode
-@synthesize pithosContainer;
+@synthesize pithosContainer, prefix;
+ (void)initialize {
if (self == [PithosContainerNode class])
- (id)initWithPithosContainer:(ASIPithosContainer *)aPithosContainer icon:(NSImage *)anIcon {
if ((self = [super init])) {
- pithosContainer = [aPithosContainer retain];
+ self.pithosContainer = aPithosContainer;
prefix = nil;
icon = [anIcon retain];
childrenUpdatedNotificationName = @"PithosContainerNodeChildrenUpdated";
#pragma mark -
#pragma mark ASIHTTPRequestDelegate
-- (void)requestFinished:(ASIHTTPRequest *)request {
+- (void)containerRequestFinished:(ASIPithosContainerRequest *)request {
NSLog(@"URL: %@", [containerRequest url]);
NSLog(@"cached: %d", [containerRequest didUseCachedResponse]);
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) {
}
}
[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) {
}
}
-- (void)requestFailed:(ASIHTTPRequest *)request {
+- (void)containerRequestFailed:(ASIPithosContainerRequest *)request {
// XXX do something on error, cleanup
NSLog(@"error:%@", [containerRequest error]);
[newChildren release];
shared:NO
until:nil] retain];
containerRequest.delegate = self;
+ containerRequest.didFinishSelector = @selector(containerRequestFinished:);
+ containerRequest.didFailSelector = @selector(containerRequestFailed:);
containerRequest.downloadCache = [ASIDownloadCache sharedCache];
[containerRequest startAsynchronous];
break;
//
-// PithosEmpty.h
+// PithosEmptyNode.h
// pithos-macos
//
// Copyright 2011 GRNET S.A. All rights reserved.
//
-// PithosEmpty.m
+// PithosEmptyNode.m
// pithos-macos
//
// Copyright 2011 GRNET S.A. All rights reserved.
NSString *url;
+ PithosNode *parent;
NSMutableArray *children;
NSMutableArray *newChildren;
PithosNodeInfoController *pithosNodeInfoController;
}
+@property(nonatomic, assign) PithosNode *parent;
@property(readonly) NSString *url;
@property(readonly) NSArray *children;
@property(readonly) NSString *displayName;
#import "PithosNodeInfoController.h"
@implementation PithosNode
+@synthesize parent;
@dynamic url, children, displayName, icon;
@dynamic pithosContainer, pithosObject;
@synthesize isLeafItem;
<object class="NSComboTableView" key="NSTableView" id="296811353">
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
- <string key="NSFrameSize">{13, 18}</string>
+ <string key="NSFrameSize">{13, 36}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<bool key="NSEnabled">YES</bool>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
- <string key="label">value: node.pithosObject.bytes</string>
- <reference key="source" ref="335436590"/>
- <reference key="destination" ref="1001"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="335436590"/>
- <reference key="NSDestination" ref="1001"/>
- <string key="NSLabel">value: node.pithosObject.bytes</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">node.pithosObject.bytes</string>
- <object class="NSDictionary" key="NSOptions">
- <string key="NS.key.0">NSValueTransformerName</string>
- <string key="NS.object.0">BytesSizeTransformer</string>
- </object>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">171</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
<string key="label">value: node.pithosContainer.name</string>
<reference key="source" ref="969715508"/>
<reference key="destination" ref="1001"/>
<int key="connectionID">173</int>
</object>
<object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">value: node.pithosObject.contentType</string>
- <reference key="source" ref="860907333"/>
- <reference key="destination" ref="1001"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="860907333"/>
- <reference key="NSDestination" ref="1001"/>
- <string key="NSLabel">value: node.pithosObject.contentType</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">node.pithosObject.contentType</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">174</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">value: node.pithosObject.lastModified</string>
- <reference key="source" ref="886319680"/>
- <reference key="destination" ref="1001"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="886319680"/>
- <reference key="NSDestination" ref="1001"/>
- <string key="NSLabel">value: node.pithosObject.lastModified</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">node.pithosObject.lastModified</string>
- <object class="NSDictionary" key="NSOptions">
- <string key="NS.key.0">NSValueTransformerName</string>
- <string key="NS.object.0">LastModifiedDateTransformer</string>
- </object>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">176</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">value: node.pithosObject.modifiedBy</string>
- <reference key="source" ref="130231867"/>
- <reference key="destination" ref="1001"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="130231867"/>
- <reference key="NSDestination" ref="1001"/>
- <string key="NSLabel">value: node.pithosObject.modifiedBy</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">node.pithosObject.modifiedBy</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">177</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">value: node.pithosObject.version</string>
- <reference key="source" ref="754158675"/>
- <reference key="destination" ref="1001"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="754158675"/>
- <reference key="NSDestination" ref="1001"/>
- <string key="NSLabel">value: node.pithosObject.version</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">node.pithosObject.version</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">178</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
- <string key="label">value: node.pithosObject.bytes</string>
- <reference key="source" ref="626534516"/>
- <reference key="destination" ref="1001"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="626534516"/>
- <reference key="NSDestination" ref="1001"/>
- <string key="NSLabel">value: node.pithosObject.bytes</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">node.pithosObject.bytes</string>
- <object class="NSDictionary" key="NSOptions">
- <string key="NS.key.0">NSValueTransformerName</string>
- <string key="NS.object.0">BytesExtendedSizeTransformer</string>
- </object>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">184</int>
- </object>
- <object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">add:</string>
<reference key="source" ref="1051118663"/>
</object>
<object class="IBConnectionRecord">
<object class="IBBindingConnection" key="connection">
- <string key="label">value: node.isPublic</string>
- <reference key="source" ref="459717130"/>
- <reference key="destination" ref="1001"/>
- <object class="NSNibBindingConnector" key="connector">
- <reference key="NSSource" ref="459717130"/>
- <reference key="NSDestination" ref="1001"/>
- <string key="NSLabel">value: node.isPublic</string>
- <string key="NSBinding">value</string>
- <string key="NSKeyPath">node.isPublic</string>
- <int key="NSNibBindingConnectorVersion">2</int>
- </object>
- </object>
- <int key="connectionID">293</int>
- </object>
- <object class="IBConnectionRecord">
- <object class="IBBindingConnection" key="connection">
<string key="label">value: node.pithosObject.publicURI</string>
<reference key="source" ref="645911602"/>
<reference key="destination" ref="1001"/>
</object>
<int key="connectionID">322</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: node.pithosObject.bytes</string>
+ <reference key="source" ref="335436590"/>
+ <reference key="destination" ref="1001"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="335436590"/>
+ <reference key="NSDestination" ref="1001"/>
+ <string key="NSLabel">value: node.pithosObject.bytes</string>
+ <string key="NSBinding">value</string>
+ <string key="NSKeyPath">node.pithosObject.bytes</string>
+ <object class="NSDictionary" key="NSOptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSNullPlaceholder</string>
+ <string>NSValueTransformerName</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>-</string>
+ <string>BytesSizeTransformer</string>
+ </object>
+ </object>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">323</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: node.pithosObject.contentType</string>
+ <reference key="source" ref="860907333"/>
+ <reference key="destination" ref="1001"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="860907333"/>
+ <reference key="NSDestination" ref="1001"/>
+ <string key="NSLabel">value: node.pithosObject.contentType</string>
+ <string key="NSBinding">value</string>
+ <string key="NSKeyPath">node.pithosObject.contentType</string>
+ <object class="NSDictionary" key="NSOptions">
+ <string key="NS.key.0">NSNullPlaceholder</string>
+ <string key="NS.object.0">-</string>
+ </object>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">324</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: node.pithosObject.bytes</string>
+ <reference key="source" ref="626534516"/>
+ <reference key="destination" ref="1001"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="626534516"/>
+ <reference key="NSDestination" ref="1001"/>
+ <string key="NSLabel">value: node.pithosObject.bytes</string>
+ <string key="NSBinding">value</string>
+ <string key="NSKeyPath">node.pithosObject.bytes</string>
+ <object class="NSDictionary" key="NSOptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSNullPlaceholder</string>
+ <string>NSValueTransformerName</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>-</string>
+ <string>BytesExtendedSizeTransformer</string>
+ </object>
+ </object>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">325</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: node.pithosObject.lastModified</string>
+ <reference key="source" ref="886319680"/>
+ <reference key="destination" ref="1001"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="886319680"/>
+ <reference key="NSDestination" ref="1001"/>
+ <string key="NSLabel">value: node.pithosObject.lastModified</string>
+ <string key="NSBinding">value</string>
+ <string key="NSKeyPath">node.pithosObject.lastModified</string>
+ <object class="NSDictionary" key="NSOptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSNullPlaceholder</string>
+ <string>NSValueTransformerName</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>-</string>
+ <string>LastModifiedDateTransformer</string>
+ </object>
+ </object>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">326</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: node.pithosObject.modifiedBy</string>
+ <reference key="source" ref="130231867"/>
+ <reference key="destination" ref="1001"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="130231867"/>
+ <reference key="NSDestination" ref="1001"/>
+ <string key="NSLabel">value: node.pithosObject.modifiedBy</string>
+ <string key="NSBinding">value</string>
+ <string key="NSKeyPath">node.pithosObject.modifiedBy</string>
+ <object class="NSDictionary" key="NSOptions">
+ <string key="NS.key.0">NSNullPlaceholder</string>
+ <string key="NS.object.0">-</string>
+ </object>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">327</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: node.pithosObject.version</string>
+ <reference key="source" ref="754158675"/>
+ <reference key="destination" ref="1001"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="754158675"/>
+ <reference key="NSDestination" ref="1001"/>
+ <string key="NSLabel">value: node.pithosObject.version</string>
+ <string key="NSBinding">value</string>
+ <string key="NSKeyPath">node.pithosObject.version</string>
+ <object class="NSDictionary" key="NSOptions">
+ <string key="NS.key.0">NSNullPlaceholder</string>
+ <string key="NS.object.0">-</string>
+ </object>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">328</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBBindingConnection" key="connection">
+ <string key="label">value: node.isPublic</string>
+ <reference key="source" ref="459717130"/>
+ <reference key="destination" ref="1001"/>
+ <object class="NSNibBindingConnector" key="connector">
+ <reference key="NSSource" ref="459717130"/>
+ <reference key="NSDestination" ref="1001"/>
+ <string key="NSLabel">value: node.isPublic</string>
+ <string key="NSBinding">value</string>
+ <string key="NSKeyPath">node.isPublic</string>
+ <int key="NSNibBindingConnectorVersion">2</int>
+ </object>
+ </object>
+ <int key="connectionID">330</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
- <int key="maxID">322</int>
+ <int key="maxID">330</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes"/>
<int key="IBDocument.localizationMode">0</int>
//
-// PithosNode.h
+// PithosObjectNode.h
// pithos-macos
//
// Copyright 2011 GRNET S.A. All rights reserved.
//
-// PithosNode.m
+// PithosObjectNode.m
// pithos-macos
//
// Copyright 2011 GRNET S.A. All rights reserved.
#import "ASIPithosContainer.h"
#import "ASIPithosObject.h"
#import "ASIDownloadCache.h"
-#import "PithosNodeInfoController.h"
@implementation PithosObjectNode
@synthesize pithosContainer, pithosObject;
metadata:pithosObject.metadata
update:NO] retain];
applyMetadataObjectRequest.delegate = self;
+ applyMetadataObjectRequest.didFinishSelector = @selector(objectRequestFinished:);
+ applyMetadataObjectRequest.didFailSelector = @selector(objectRequestFailed:);
[applyMetadataObjectRequest startAsynchronous];
}
}
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];
}
#pragma mark -
#pragma mark ASIHTTPRequestDelegate
-- (void)requestFinished:(ASIHTTPRequest *)request {
+- (void)objectRequestFinished:(ASIPithosObjectRequest *)request {
NSLog(@"URL: %@", [request url]);
NSLog(@"cached: %d", [request didUseCachedResponse]);
}
}
-- (void)requestFailed:(ASIHTTPRequest *)request {
+- (void)objectRequestFailed:(ASIPithosObjectRequest *)request {
if ([request isEqualTo:applyMetadataObjectRequest]) {
// XXX do something on error, cleanup
NSLog(@"error:%@", [applyMetadataObjectRequest error]);
//
-// PithosNode.h
+// PithosSubdirNode.h
// pithos-macos
//
// Copyright 2011 GRNET S.A. All rights reserved.
#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
//
-// PithosNode.m
+// PithosSubdirNode.m
// pithos-macos
//
// Copyright 2011 GRNET S.A. All rights reserved.
#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])
- (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];
}
- (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;
}
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