Revision fb27f368 pithos-macos/PithosContainerNode.m
b/pithos-macos/PithosContainerNode.m | ||
---|---|---|
2 | 2 |
// PithosContainerNode.m |
3 | 3 |
// pithos-macos |
4 | 4 |
// |
5 |
// Copyright 2011-2012 GRNET S.A. All rights reserved.
|
|
5 |
// Copyright 2011-2013 GRNET S.A. All rights reserved.
|
|
6 | 6 |
// |
7 | 7 |
// Redistribution and use in source and binary forms, with or |
8 | 8 |
// without modification, are permitted provided that the following |
... | ... | |
44 | 44 |
#import "ASIPithosObject.h" |
45 | 45 |
#import "ASIDownloadCache.h" |
46 | 46 |
#import "PithosUtilities.h" |
47 |
#import "PithosAccount.h" |
|
47 | 48 |
#import "PithosContainerNodeInfoController.h" |
48 | 49 |
#import "PithosActivityFacility.h" |
49 | 50 |
|
50 | 51 |
static NSImage *sharedIcon = nil; |
51 | 52 |
|
52 | 53 |
@implementation PithosContainerNode |
53 |
@synthesize pithos, pithosContainer, containerRequest, prefix, applyMetadataContainerRequest, refreshMetadataContainerRequest;
|
|
54 |
@synthesize pithosContainer, containerRequest, prefix, applyMetadataContainerRequest, refreshMetadataContainerRequest; |
|
54 | 55 |
@synthesize policyVersioning, policyQuota; |
55 | 56 |
|
56 | 57 |
+ (void)initialize { |
... | ... | |
61 | 62 |
#pragma mark - |
62 | 63 |
#pragma mark Object Lifecycle |
63 | 64 |
|
64 |
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager |
|
65 |
andPithos:(ASIPithos *)aPithos pithosContainer:(ASIPithosContainer *)aPithosContainer icon:(NSImage *)anIcon { |
|
65 |
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager pithosContainer:(ASIPithosContainer *)aPithosContainer icon:(NSImage *)anIcon { |
|
66 | 66 |
if ((self = [super initWithPithosAccountManager:aPithosAccountManager])) { |
67 |
pithos = aPithos; |
|
68 | 67 |
self.pithosContainer = aPithosContainer; |
69 | 68 |
self.icon = anIcon; |
70 | 69 |
} |
71 | 70 |
return self; |
72 | 71 |
} |
73 | 72 |
|
74 |
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager |
|
75 |
andPithos:(ASIPithos *)aPithos pithosContainer:(ASIPithosContainer *)aPithosContainer { |
|
76 |
return [self initWithPithosAccountManager:aPithosAccountManager andPithos:aPithos pithosContainer:aPithosContainer icon:nil]; |
|
73 |
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager pithosContainer:(ASIPithosContainer *)aPithosContainer { |
|
74 |
return [self initWithPithosAccountManager:aPithosAccountManager pithosContainer:aPithosContainer icon:nil]; |
|
77 | 75 |
} |
78 | 76 |
|
79 |
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager |
|
80 |
andPithos:(ASIPithos *)aPithos containerName:(NSString *)aContainerName icon:(NSImage *)anIcon { |
|
77 |
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager containerName:(NSString *)aContainerName icon:(NSImage *)anIcon { |
|
81 | 78 |
ASIPithosContainer *container = [ASIPithosContainer container]; |
82 | 79 |
container.name = aContainerName; |
83 |
return [self initWithPithosAccountManager:aPithosAccountManager andPithos:aPithos pithosContainer:container icon:anIcon];
|
|
80 |
return [self initWithPithosAccountManager:aPithosAccountManager pithosContainer:container icon:anIcon]; |
|
84 | 81 |
} |
85 | 82 |
|
86 |
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager |
|
87 |
andPithos:(ASIPithos *)aPithos containerName:(NSString *)aContainerName { |
|
88 |
return [self initWithPithosAccountManager:aPithosAccountManager andPithos:aPithos containerName:aContainerName icon:nil]; |
|
83 |
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager containerName:(NSString *)aContainerName { |
|
84 |
return [self initWithPithosAccountManager:aPithosAccountManager containerName:aContainerName icon:nil]; |
|
89 | 85 |
} |
90 | 86 |
|
91 | 87 |
- (void)dealloc { |
... | ... | |
97 | 93 |
#pragma mark - |
98 | 94 |
#pragma mark Properties |
99 | 95 |
|
100 |
- (void)setPithos:(ASIPithos *)aPithos { |
|
101 |
if (aPithos && ![aPithos isEqualTo:pithos]) { |
|
102 |
pithos = aPithos; |
|
103 |
url = nil; |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 | 96 |
- (NSString *)url { |
108 |
if (url == nil) |
|
109 |
url = [[NSString alloc] initWithFormat:@"%@/%@%@", |
|
110 |
(sharingAccount ? [pithos storageURLWithAuthUser:sharingAccount] : pithos.storageURL), |
|
111 |
pithosContainer.name, |
|
112 |
(shared ? @"?shared" : @"")]; |
|
113 |
return url; |
|
97 |
return [NSString stringWithFormat:@"@container@%@/%@%@", |
|
98 |
(sharingAccount ? sharingAccount : pithosAccountManager.pithos.authUser), |
|
99 |
pithosContainer.name, |
|
100 |
(shared ? @"?shared" : @"")]; |
|
114 | 101 |
} |
115 | 102 |
|
116 | 103 |
- (NSArray *)children { |
... | ... | |
120 | 107 |
break; |
121 | 108 |
case PithosNodeStateRefreshNeeded: |
122 | 109 |
freshness = PithosNodeStateRefreshing; |
123 |
self.containerRequest = [ASIPithosContainerRequest listObjectsRequestWithPithos:pithos |
|
110 |
self.containerRequest = [ASIPithosContainerRequest listObjectsRequestWithPithos:pithosAccountManager.pithos
|
|
124 | 111 |
containerName:pithosContainer.name |
125 | 112 |
limit:0 |
126 | 113 |
marker:nil |
... | ... | |
131 | 118 |
shared:shared |
132 | 119 |
until:nil]; |
133 | 120 |
if (sharingAccount) |
134 |
[containerRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithos]; |
|
121 |
[containerRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithosAccountManager.pithos];
|
|
135 | 122 |
else if (!forcedRefresh) |
136 | 123 |
containerRequest.downloadCache = [ASIDownloadCache sharedCache]; |
137 | 124 |
containerRequest.delegate = self; |
... | ... | |
273 | 260 |
if ((sameNameObjectIndex == NSNotFound) || |
274 | 261 |
![PithosUtilities isContentTypeDirectory:[[objects objectAtIndex:sameNameObjectIndex] contentType]]) { |
275 | 262 |
PithosSubdirNode *node = [[PithosSubdirNode alloc] initWithPithosAccountManager:pithosAccountManager |
276 |
andPithos:pithos |
|
277 | 263 |
pithosContainer:pithosContainer |
278 | 264 |
pithosObject:object]; |
279 | 265 |
node.parent = self; |
... | ... | |
297 | 283 |
} |
298 | 284 |
} else if ([PithosUtilities isContentTypeDirectory:object.contentType]) { |
299 | 285 |
PithosSubdirNode *node = [[PithosSubdirNode alloc] initWithPithosAccountManager:pithosAccountManager |
300 |
andPithos:pithos |
|
301 | 286 |
pithosContainer:pithosContainer |
302 | 287 |
pithosObject:object]; |
303 | 288 |
node.parent = self; |
... | ... | |
318 | 303 |
[newChildren addObject:node]; |
319 | 304 |
} else { |
320 | 305 |
PithosObjectNode *node = [[PithosObjectNode alloc] initWithPithosAccountManager:pithosAccountManager |
321 |
andPithos:pithos |
|
322 | 306 |
pithosContainer:pithosContainer |
323 | 307 |
pithosObject:object]; |
324 | 308 |
node.parent = self; |
... | ... | |
356 | 340 |
[self postChildrenUpdatedNotificationName]; |
357 | 341 |
} else { |
358 | 342 |
// Do an additional request to fetch more objects |
359 |
self.containerRequest = [ASIPithosContainerRequest listObjectsRequestWithPithos:pithos |
|
343 |
self.containerRequest = [ASIPithosContainerRequest listObjectsRequestWithPithos:pithosAccountManager.pithos
|
|
360 | 344 |
containerName:pithosContainer.name |
361 | 345 |
limit:0 |
362 | 346 |
marker:[[someObjects lastObject] name] |
... | ... | |
367 | 351 |
shared:shared |
368 | 352 |
until:nil]; |
369 | 353 |
if (sharingAccount) |
370 |
[containerRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithos]; |
|
354 |
[containerRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithosAccountManager.pithos];
|
|
371 | 355 |
else if (!forcedRefresh) |
372 | 356 |
containerRequest.downloadCache = [ASIDownloadCache sharedCache]; |
373 | 357 |
containerRequest.delegate = self; |
... | ... | |
455 | 439 |
@synchronized(self) { |
456 | 440 |
if (applyMetadataContainerRequest == nil) { |
457 | 441 |
[[pithosNodeInfoController window] makeFirstResponder:nil]; |
458 |
self.applyMetadataContainerRequest = [ASIPithosContainerRequest updateContainerMetadataRequestWithPithos:pithos |
|
442 |
self.applyMetadataContainerRequest = [ASIPithosContainerRequest updateContainerMetadataRequestWithPithos:pithosAccountManager.pithos
|
|
459 | 443 |
containerName:pithosContainer.name |
460 | 444 |
policy:[NSDictionary dictionaryWithObjectsAndKeys: |
461 | 445 |
policyVersioning, @"versioning", |
... | ... | |
480 | 464 |
- (void)refreshInfo { |
481 | 465 |
@synchronized(self) { |
482 | 466 |
if (refreshMetadataContainerRequest == nil) { |
483 |
self.refreshMetadataContainerRequest = [ASIPithosContainerRequest containerMetadataRequestWithPithos:pithos |
|
467 |
self.refreshMetadataContainerRequest = [ASIPithosContainerRequest containerMetadataRequestWithPithos:pithosAccountManager.pithos
|
|
484 | 468 |
containerName:pithosContainer.name]; |
485 | 469 |
refreshMetadataContainerRequest.delegate = self; |
486 | 470 |
refreshMetadataContainerRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:); |
Also available in: Unified diff