Simplify default and support custom notifications for nodes.
[pithos-macos] / pithos-macos / PithosSharingAccountsNode.m
index 4fda9f6..f96b598 100644 (file)
@@ -2,7 +2,7 @@
 //  PithosAccountNode.m
 //  pithos-macos
 //
-// Copyright 2011 GRNET S.A. All rights reserved.
+// Copyright 2011-2012 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 "PithosSharingAccountsNode.h"
 #import "PithosAccountNode.h"
 #import "ASIPithosRequest.h"
+#import "ASIPithos.h"
 #import "ASIPithosAccount.h"
 #import "ASIDownloadCache.h"
 #import "PithosUtilities.h"
 #import "PithosActivityFacility.h"
 
 @implementation PithosSharingAccountsNode
+@synthesize pithos;
 
 #pragma mark -
 #pragma mark Object Lifecycle
 
-- (id)init {
+- (id)initWithPithos:(ASIPithos *)aPithos {
     if ((self = [super init])) {
+        self.pithos = aPithos;
         self.sharingAccount = @"";
     }
     return self;
     [sharingAccountsRequest clearDelegatesAndCancel];
     [sharingAccountsRequest release];
     [sharingAccounts release];
+    [pithos release];
     [super dealloc];
 }
 
 #pragma mark -
 #pragma mark Properties
 
+- (void)setPithos:(ASIPithos *)aPithos {
+    if (aPithos && ![aPithos isEqualTo:pithos]) {
+        [pithos release];
+        pithos = [aPithos retain];
+        [url release];
+        url = nil;
+    }
+}
+
 - (NSString *)url {
     if (url == nil) 
-        url = [[ASIPithosRequest storageURLPrefix] copy];
+        url = [pithos.storageURLPrefix copy];
     return url;
 }
 
@@ -78,8 +91,7 @@
                 break;
             case PithosNodeStateRefreshNeeded:
                 freshness = PithosNodeStateRefreshing;
-                sharingAccountsRequest = [[ASIPithosRequest listSharingAccountsRequestWithLimit:0 
-                                                                                         marker:nil] retain];
+                sharingAccountsRequest = [[ASIPithosRequest listSharingAccountsRequestWithPithos:pithos limit:0 marker:nil] retain];
                 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:[ASIPithosRequest authUser]]) {
-                        PithosAccountNode *node = [[[PithosAccountNode alloc] init] autorelease];
+                    if (![account.name isEqualToString:pithos.authUser]) {
+                        PithosAccountNode *node = [[[PithosAccountNode alloc] initWithPithos:pithos] autorelease];
                         node.parent = self;
                         node.shared = shared;
                         node.sharingAccount = account.name;
+                        node.inheritChildrenUpdatedNotificationName = inheritChildrenUpdatedNotificationName;
                         if (children) {
                             NSUInteger oldIndex = [children indexOfObject:node];
                             if (oldIndex != NSNotFound) {
             @synchronized(self) {
                 freshness = PithosNodeStateRefreshFinished;
             }
-            // Notify observers that children are updated
-            [[NSNotificationCenter defaultCenter] postNotificationName:@"PithosSharingAccountsNodeChildrenUpdated" object:self];
+            [self postChildrenUpdatedNotificationName];
         } else {
             [sharingAccountsRequest release];
             // Do an additional request to fetch more objects
-            sharingAccountsRequest = [[ASIPithosRequest listSharingAccountsRequestWithLimit:0 
-                                                                                     marker:[[someSharingAccounts lastObject] name]] retain];
+            sharingAccountsRequest = [[ASIPithosRequest listSharingAccountsRequestWithPithos:pithos 
+                                                                                       limit:0 
+                                                                                      marker:[[someSharingAccounts lastObject] name]] retain];
             sharingAccountsRequest.delegate = self;
             sharingAccountsRequest.didFinishSelector = @selector(performRequestFinishedDelegateInBackground:);
             sharingAccountsRequest.didFailSelector = @selector(performRequestFailedDelegateInBackground:);