Refactor use of pithos objects to accommodate
[pithos-macos] / pithos-macos / PithosSharingAccountsNode.m
index c30091c..68a1f5f 100644 (file)
@@ -2,7 +2,7 @@
 //  PithosAccountNode.m
 //  pithos-macos
 //
-// Copyright 2011-2012 GRNET S.A. All rights reserved.
+// Copyright 2011-2013 GRNET S.A. All rights reserved.
 //
 // Redistribution and use in source and binary forms, with or
 // without modification, are permitted provided that the following
 #import "PithosActivityFacility.h"
 
 @implementation PithosSharingAccountsNode
-@synthesize pithos, sharingAccountsRequest;
+@synthesize sharingAccountsRequest;
 
 #pragma mark -
 #pragma mark Object Lifecycle
 
-- (id)initWithPithos:(ASIPithos *)aPithos {
-    if ((self = [super init])) {
-        pithos = aPithos;
+- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager {
+    if ((self = [super initWithPithosAccountManager:aPithosAccountManager])) {
         self.sharingAccount = @"";
     }
     return self;
 }
 
 #pragma mark -
-#pragma mark Properties
+#pragma mark Actions
 
-- (void)setPithos:(ASIPithos *)aPithos {
-    if (aPithos && ![aPithos isEqualTo:pithos]) {
-        pithos = aPithos;
-        url = nil;
-        [sharingAccountsRequest clearDelegatesAndCancel];
-        self.sharingAccountsRequest = nil;
-        reset = YES;
-    }
+- (void)reset {
+    [sharingAccountsRequest clearDelegatesAndCancel];
+    self.sharingAccountsRequest = nil;
+    children = nil;
+    newChildren = nil;
+    freshness = PithosNodeStateRefreshNeeded;
+    forcedRefresh = YES;
+    [self postChildrenUpdatedNotificationName];
+    [self children];
 }
 
+#pragma mark -
+#pragma mark Properties
+
 - (NSString *)url {
-    if (url == nil) 
-        url = [pithos.storageURLPrefix copy];
-    return url;
+    return @"@sharing accounts@";
 }
 
 - (NSArray *)children {
     @synchronized(self) {
-        if (reset) {
-            [sharingAccountsRequest clearDelegatesAndCancel];
-            self.sharingAccountsRequest = nil;
-            children = nil;
-            newChildren = nil;
-            freshness = PithosNodeStateRefreshNeeded;
-            forcedRefresh = YES;
-            reset = NO;
-            [self postChildrenUpdatedNotificationName];
-        }
         switch (freshness) {
             case PithosNodeStateFresh:
                 break;
             case PithosNodeStateRefreshNeeded:
                 freshness = PithosNodeStateRefreshing;
-                self.sharingAccountsRequest = [ASIPithosRequest listSharingAccountsRequestWithPithos:pithos limit:0 marker:nil];
+                self.sharingAccountsRequest = [ASIPithosRequest listSharingAccountsRequestWithPithos:pithosAccountManager.pithos limit:0 marker:nil];
                 sharingAccountsRequest.delegate = self;
                 sharingAccountsRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:);
                 sharingAccountsRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:);
                     newChildren = [[NSMutableArray alloc] init];
                     NSMutableIndexSet *keptNodes = [NSMutableIndexSet indexSet];
                     for (ASIPithosAccount *account in sharingAccounts) {
-                        if (![account.name isEqualToString:pithos.authUser]) {
-                            PithosAccountNode *node = [[PithosAccountNode alloc] initWithPithos:pithos];
+                        if (![account.name isEqualToString:pithosAccountManager.pithos.authUser]) {
+                            PithosAccountNode *node = [[PithosAccountNode alloc] initWithPithosAccountManager:pithosAccountManager];
                             node.parent = self;
                             node.shared = shared;
                             node.sharingAccount = account.name;
                             node.inheritChildrenUpdatedNotificationName = inheritChildrenUpdatedNotificationName;
-                            node.pithosAccountManager = pithosAccountManager;
                             if (children) {
                                 NSUInteger oldIndex = [children indexOfObject:node];
                                 if (oldIndex != NSNotFound) {
                 for (ASIPithosAccount *account in sharingAccounts) {
                     [sharingAccountsNames addObject:account.name];
                 }
-                [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:sharingAccountsNames];
+                [pithosAccountManager updateUserCatalogForDisplaynames:nil UUIDs:sharingAccountsNames];
                 self.sharingAccountsRequest = nil;
                 forcedRefresh = NO;
                 @synchronized(self) {
                 [self postChildrenUpdatedNotificationName];
             } else {
                 // Do an additional request to fetch more objects
-                self.sharingAccountsRequest = [ASIPithosRequest listSharingAccountsRequestWithPithos:pithos
+                self.sharingAccountsRequest = [ASIPithosRequest listSharingAccountsRequestWithPithos:pithosAccountManager.pithos
                                                                                                limit:0
                                                                                               marker:[[someSharingAccounts lastObject] name]];
                 sharingAccountsRequest.delegate = self;