#import "ASIDownloadCache.h"
#import "PithosFileUtilities.h"
+static NSImage *sharedIcon = nil;
+
@implementation PithosAccountNode
++ (void)initialize {
+ if (self == [PithosAccountNode class])
+ sharedIcon = [[[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kUserIcon)] retain];
+}
+
#pragma mark -
#pragma mark Object Lifecycle
#pragma mark Properties
- (NSString *)url {
- if (url == nil)
- url = [[ASIPithosRequest storageURL] copy];
+ if (url == nil)
+ url = [[NSString alloc] initWithFormat:@"%@%@",
+ (sharingAccount ? [ASIPithosRequest storageURLWithAuthUser:sharingAccount] : [ASIPithosRequest storageURL]),
+ (shared ? @"?shared" : @"")];
return url;
}
marker:nil
shared:shared
until:nil] retain];
+ if (sharingAccount)
+ [accountRequest setRequestUserFromDefaultTo:sharingAccount];
accountRequest.delegate = self;
accountRequest.didFinishSelector = @selector(accountRequestFinished:);
accountRequest.didFailSelector = @selector(accountRequestFailed:);
- accountRequest.downloadCache = [ASIDownloadCache sharedCache];
+ if (!forcedRefresh)
+ accountRequest.downloadCache = [ASIDownloadCache sharedCache];
[accountRequest startAsynchronous];
break;
case PithosNodeStateRefreshing:
}
- (NSString *)displayName {
- if (displayName == nil) {
- displayName = [[NSString alloc] initWithString:@"account"];
- }
- return displayName;
+ if (displayName == nil)
+ return [NSString stringWithString:(sharingAccount ? sharingAccount : @"account")];
+ return [[displayName copy] autorelease];
+}
+
+- (NSImage *)icon {
+ if (icon == nil)
+ icon = [sharedIcon retain];
+ return icon;
}
#pragma mark -
// Save new children
NSLog(@"using newChildren");
newChildren = [[NSMutableArray alloc] init];
+ NSMutableIndexSet *keptNodes = [NSMutableIndexSet indexSet];
for (ASIPithosContainer *container in containers) {
PithosContainerNode *node = [[[PithosContainerNode alloc] initWithPithosContainer:container] autorelease];
+ node.parent = self;
+ node.shared = shared;
+ node.sharingAccount = sharingAccount;
if (children) {
NSUInteger oldIndex = [children indexOfObject:node];
if (oldIndex != NSNotFound) {
// Use the same pointer value, if possible
node = [children objectAtIndex:oldIndex];
node.pithosContainer = container;
+ [keptNodes addIndex:oldIndex];
}
}
- node.parent = self;
- node.shared = shared;
[newChildren addObject:node];
}
+ [[children objectsAtIndexes:
+ [[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [children count])] indexesPassingTest:^(NSUInteger idx, BOOL *stop){
+ if ([keptNodes containsIndex:idx])
+ return NO;
+ return YES;
+ }]] makeObjectsPerformSelector:@selector(pithosNodeWillBeRemoved)];
}
// Else cache was used and all results were fetched during this request, so existing children can be reused
[accountRequest release];
accountRequest = nil;
[containers release];
containers = nil;
+ forcedRefresh = NO;
@synchronized(self) {
freshness = PithosNodeStateRefreshFinished;
}
marker:[[someContainers lastObject] name]
shared:shared
until:nil] retain];
+ if (sharingAccount)
+ [accountRequest setRequestUserFromDefaultTo:sharingAccount];
accountRequest.delegate = self;
- accountRequest.downloadCache = [ASIDownloadCache sharedCache];
+ if (!forcedRefresh)
+ accountRequest.downloadCache = [ASIDownloadCache sharedCache];
[accountRequest startAsynchronous];
}
}
accountRequest = nil;
[containers release];
containers = nil;
+ forcedRefresh = NO;
@synchronized(self) {
freshness = PithosNodeStateRefreshNeeded;
}