5 // Copyright 2011 GRNET S.A. All rights reserved.
7 // Redistribution and use in source and binary forms, with or
8 // without modification, are permitted provided that the following
11 // 1. Redistributions of source code must retain the above
12 // copyright notice, this list of conditions and the following
15 // 2. Redistributions in binary form must reproduce the above
16 // copyright notice, this list of conditions and the following
17 // disclaimer in the documentation and/or other materials
18 // provided with the distribution.
20 // THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
21 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
24 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
33 // The views and conclusions contained in the software and
34 // documentation are those of the authors and should not be
35 // interpreted as representing official policies, either expressed
36 // or implied, of GRNET S.A.
38 #import "PithosObjectNode.h"
39 #import "ASIPithosRequest.h"
40 #import "ASIPithosObjectRequest.h"
41 #import "ASIPithosContainer.h"
42 #import "ASIPithosObject.h"
43 #import "ASIDownloadCache.h"
44 #import "PithosFileUtilities.h"
45 #import "PithosObjectNodeInfoController.h"
47 @implementation PithosObjectNode
48 @synthesize pithosContainer, pithosObject;
52 #pragma mark Object Lifecycle
54 - (id)initWithPithosContainer:(ASIPithosContainer *)aPithosContainer pithosObject:(ASIPithosObject *)aPithosObject {
55 if ((self = [super init])) {
56 self.pithosContainer = aPithosContainer;
57 self.pithosObject = aPithosObject;
64 [refreshMetadataObjectRequest clearDelegatesAndCancel];
65 [refreshMetadataObjectRequest release];
66 [applyMetadataObjectRequest clearDelegatesAndCancel];
67 [applyMetadataObjectRequest release];
68 [pithosObject release];
69 [pithosContainer release];
74 #pragma mark Properties
78 url = [[NSString alloc] initWithFormat:@"object %@/%@/%@", [ASIPithosRequest storageURL], pithosContainer.name, pithosObject.name];
82 - (NSArray *)children {
86 - (NSString *)displayName {
87 if (displayName == nil) {
88 // XXX check if there are problems with . or other special characters
89 displayName = [pithosObject.name lastPathComponent];
90 if([pithosObject.name hasSuffix:@"/"])
91 displayName = [displayName stringByAppendingString:@"/"];
94 return [[displayName copy] autorelease];
99 icon = [[[NSWorkspace sharedWorkspace] iconForFileType:[pithosObject.name pathExtension]] retain];
103 - (void)setPithosObject:(ASIPithosObject *)aPithosObject {
104 if (![pithosObject isEqualTo:aPithosObject]) {
105 [pithosObject release];
106 pithosObject = [aPithosObject retain];
108 self.isPublic = (pithosObject.publicURI != nil);
115 @synchronized(self) {
116 if (applyMetadataObjectRequest == nil) {
117 [[pithosNodeInfoController window] makeFirstResponder:nil];
118 applyMetadataObjectRequest = [[ASIPithosObjectRequest updateObjectMetadataRequestWithContainerName:pithosContainer.name
119 objectName:pithosObject.name
120 contentEncoding:pithosObject.contentEncoding
121 contentDisposition:pithosObject.contentDisposition
122 manifest:pithosObject.manifest
123 sharing:pithosObject.sharing
124 isPublic:(isPublic ? ASIPithosObjectRequestPublicTrue : ASIPithosObjectRequestPublicFalse)
125 metadata:pithosObject.metadata
127 applyMetadataObjectRequest.delegate = self;
128 applyMetadataObjectRequest.didFinishSelector = @selector(objectRequestFinished:);
129 applyMetadataObjectRequest.didFailSelector = @selector(objectRequestFailed:);
130 [applyMetadataObjectRequest startAsynchronous];
135 - (void)refreshInfo {
136 @synchronized(self) {
137 if (refreshMetadataObjectRequest == nil) {
138 refreshMetadataObjectRequest = [[ASIPithosObjectRequest objectMetadataRequestWithContainerName:pithosContainer.name
139 objectName:pithosObject.name] retain];
140 refreshMetadataObjectRequest.delegate = self;
141 refreshMetadataObjectRequest.didFinishSelector = @selector(objectRequestFinished:);
142 refreshMetadataObjectRequest.didFailSelector = @selector(objectRequestFailed:);
143 refreshMetadataObjectRequest.downloadCache = [ASIDownloadCache sharedCache];
144 [refreshMetadataObjectRequest startAsynchronous];
150 #pragma mark ASIHTTPRequestDelegate
152 - (void)objectRequestFinished:(ASIPithosObjectRequest *)request {
153 NSLog(@"URL: %@", [request url]);
154 NSLog(@"cached: %d", [request didUseCachedResponse]);
156 if ([request isEqualTo:applyMetadataObjectRequest]) {
157 @synchronized(self) {
158 [applyMetadataObjectRequest release];
159 applyMetadataObjectRequest = nil;
162 } else if ([request isEqualTo:refreshMetadataObjectRequest]) {
163 [[pithosNodeInfoController window] makeFirstResponder:nil];
165 self.pithosObject = [refreshMetadataObjectRequest object];
166 @synchronized(self) {
167 [refreshMetadataObjectRequest release];
168 refreshMetadataObjectRequest = nil;
173 - (void)objectRequestFailed:(ASIPithosObjectRequest *)request {
174 if ([request isEqualTo:applyMetadataObjectRequest]) {
175 [PithosFileUtilities httpRequestErrorAlertWithRequest:applyMetadataObjectRequest];
176 @synchronized(self) {
177 [applyMetadataObjectRequest release];
178 applyMetadataObjectRequest = nil;
180 } else if ([request isEqualTo:refreshMetadataObjectRequest]) {
181 [PithosFileUtilities httpRequestErrorAlertWithRequest:refreshMetadataObjectRequest];
182 @synchronized(self) {
183 [refreshMetadataObjectRequest release];
184 refreshMetadataObjectRequest = nil;
192 - (void)showPithosNodeInfo:(id)sender {
193 if (!pithosNodeInfoController)
194 pithosNodeInfoController = [[PithosObjectNodeInfoController alloc] initWithPithosNode:self];
195 [pithosNodeInfoController showWindow:sender];
196 [[pithosNodeInfoController window] makeKeyAndOrderFront:sender];
197 [NSApp activateIgnoringOtherApps:YES];