Simplify default and support custom notifications for nodes.
authorMiltiadis Vasilakis <mvasilak@gmail.com>
Fri, 9 Mar 2012 16:47:05 +0000 (18:47 +0200)
committerMiltiadis Vasilakis <mvasilak@gmail.com>
Fri, 9 Mar 2012 16:47:05 +0000 (18:47 +0200)
pithos-macos/PithosAccount.m
pithos-macos/PithosAccountNode.m
pithos-macos/PithosBrowserController.m
pithos-macos/PithosContainerNode.m
pithos-macos/PithosNode.h
pithos-macos/PithosNode.m
pithos-macos/PithosSharingAccountsNode.m
pithos-macos/PithosSubdirNode.m

index 45af887..a4f9ab8 100644 (file)
     if (!accountNode) {
         accountNode = [[PithosAccountNode alloc] initWithPithos:self.pithos];
         accountNode.childrenUpdatedNotificationName = nil;
+        accountNode.inheritChildrenUpdatedNotificationName = YES;
     }
     return accountNode;
 }
index 48bce3b..eba9b49 100644 (file)
@@ -61,7 +61,6 @@ static NSImage *sharedIcon = nil;
 - (id)initWithPithos:(ASIPithos *)aPithos {
     if ((self = [super init])) {
         self.pithos = aPithos;
-        self.childrenUpdatedNotificationName = [NSString stringWithString:@"PithosAccountNodeChildrenUpdated"];
     }
     return self;
 }
@@ -215,6 +214,7 @@ static NSImage *sharedIcon = nil;
                     node.parent = self;
                     node.shared = shared;
                     node.sharingAccount = sharingAccount;
+                    node.inheritChildrenUpdatedNotificationName = inheritChildrenUpdatedNotificationName;
                     if (children) {
                         NSUInteger oldIndex = [children indexOfObject:node];
                         if (oldIndex != NSNotFound) {
@@ -243,10 +243,7 @@ static NSImage *sharedIcon = nil;
             @synchronized(self) {
                 freshness = PithosNodeStateRefreshFinished;
             }
-            if (childrenUpdatedNotificationName) {
-                // Notify observers that children are updated
-                [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self];
-            }
+            [self postChildrenUpdatedNotificationName];
         } else {
             [accountRequest release];
             // Do an additional request to fetch more objects
@@ -280,10 +277,7 @@ static NSImage *sharedIcon = nil;
         @synchronized(self) {
             freshness = PithosNodeStateRefreshFinished;
         }
-        if (childrenUpdatedNotificationName) {
-            // Notify observers that children are updated
-            [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self];
-        }
+        [self postChildrenUpdatedNotificationName];
     } else {
         [self accountRequestFailed:accountRequest];
     }
index b71d62a..9ee32ab 100644 (file)
     [[[outlineView tableColumns] objectAtIndex:0] setDataCell:[[[PithosOutlineViewCell alloc] init] autorelease]];
     
     // Register for updates
-    // PithosContainerNode updates browser nodes
-    [[NSNotificationCenter defaultCenter] addObserver:self 
-                                             selector:@selector(pithosNodeChildrenUpdated:) 
-                                                 name:@"PithosContainerNodeChildrenUpdated" 
-                                               object:nil];
-    // PithosSubdirNode updates browser nodes
-    [[NSNotificationCenter defaultCenter] addObserver:self 
-                                             selector:@selector(pithosNodeChildrenUpdated:) 
-                                                 name:@"PithosSubdirNodeChildrenUpdated" 
-                                               object:nil];
     // PithosAccountNode accountNode updates outlineView container nodes 
     [[NSNotificationCenter defaultCenter] addObserver:self 
                                              selector:@selector(pithosAccountNodeChildrenUpdated:) 
-                                                 name:@"PithosAccountNodeChildrenUpdated" 
+                                                 name:@"PithosNodeChildrenUpdated" 
                                                object:accountNode];
-    // PithosAccountNode other than accountNode updates nodes 
+    // PithosNode updates browser nodes
     [[NSNotificationCenter defaultCenter] addObserver:self 
                                              selector:@selector(pithosNodeChildrenUpdated:) 
-                                                 name:@"PithosAccountNodeChildrenUpdated" 
+                                                 name:@"PithosNodeChildrenUpdated" 
                                                object:nil];
-    // PithosSharingAccountsNode othersSharedNode updates browser nodes 
-    [[NSNotificationCenter defaultCenter] addObserver:self 
-                                             selector:@selector(pithosNodeChildrenUpdated:) 
-                                                 name:@"PithosSharingAccountsNodeChildrenUpdated" 
-                                               object:othersSharedNode];
     // Request for browser refresh 
     [[NSNotificationCenter defaultCenter] addObserver:self 
                                              selector:@selector(pithosBrowserRefreshNeeded:) 
 
 - (void)pithosNodeChildrenUpdated:(NSNotification *)notification {
     PithosNode *node = (PithosNode *)[notification object];
-    if (node == accountNode)
+    if ((node == accountNode) || ![node.pithos isEqualTo:pithos])
         return;
     NSLog(@"pithosNodeChildrenUpdated:%@", node.url);
     NSInteger lastColumn = [browser lastColumn];
index 47d9a07..b061899 100644 (file)
@@ -67,7 +67,6 @@ static NSImage *sharedIcon = nil;
         self.pithosContainer = aPithosContainer;
         prefix = nil;
         self.icon = anIcon;
-        self.childrenUpdatedNotificationName = [NSString stringWithString:@"PithosContainerNodeChildrenUpdated"];
     }
     return self;
 }
@@ -294,6 +293,7 @@ static NSImage *sharedIcon = nil;
                                 node.parent = self;
                                 node.shared = shared;
                                 node.sharingAccount = sharingAccount;
+                                node.inheritChildrenUpdatedNotificationName = inheritChildrenUpdatedNotificationName;
                                 if (children) {
                                     NSUInteger oldIndex = [children indexOfObject:node];
                                     if (oldIndex != NSNotFound) {
@@ -316,6 +316,7 @@ static NSImage *sharedIcon = nil;
                             node.parent = self;
                             node.shared = shared;
                             node.sharingAccount = sharingAccount;
+                            node.inheritChildrenUpdatedNotificationName = inheritChildrenUpdatedNotificationName;
                             if (children) {
                                 NSUInteger oldIndex = [children indexOfObject:node];
                                 if (oldIndex != NSNotFound) {
@@ -335,6 +336,7 @@ static NSImage *sharedIcon = nil;
                             node.parent = self;
                             node.shared = shared;
                             node.sharingAccount = sharingAccount;
+                            node.inheritChildrenUpdatedNotificationName = inheritChildrenUpdatedNotificationName;
                             if (children) {
                                 NSUInteger oldIndex = [children indexOfObject:node];
                                 if (oldIndex != NSNotFound) {
@@ -366,10 +368,7 @@ static NSImage *sharedIcon = nil;
             @synchronized(self) {
                 freshness = PithosNodeStateRefreshFinished;
             }
-            if (childrenUpdatedNotificationName) {
-                // Notify observers that children are updated
-                [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self];
-            }
+            [self postChildrenUpdatedNotificationName];
         } else {
             [containerRequest release];
             // Do an additional request to fetch more objects
@@ -408,10 +407,7 @@ static NSImage *sharedIcon = nil;
         @synchronized(self) {
             freshness = PithosNodeStateRefreshFinished;
         }
-        if (childrenUpdatedNotificationName) {
-            // Notify observers that children are updated
-            [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self];
-        }
+        [self postChildrenUpdatedNotificationName];
     } else {
         [self containerRequestFailed:containerRequest];
     }
index 8089747..22c97b0 100644 (file)
@@ -59,6 +59,7 @@
     NSMutableArray *children;
     NSMutableArray *newChildren;
     NSString *childrenUpdatedNotificationName;
+    BOOL inheritChildrenUpdatedNotificationName;
     
     NSString *displayName;
     BOOL isLeafItem;
@@ -77,6 +78,7 @@
 @property(nonatomic, retain) NSString *sharingAccount;
 @property(nonatomic, readonly) NSArray *children;
 @property(nonatomic, retain) NSString *childrenUpdatedNotificationName;
+@property(nonatomic, assign) BOOL inheritChildrenUpdatedNotificationName;
 
 @property(nonatomic, retain) NSString *displayName;
 @property(nonatomic, readonly) BOOL isLeafItem;
@@ -93,6 +95,8 @@
 - (void)refresh;
 - (void)forceRefresh;
 
+- (void) postChildrenUpdatedNotificationName;
+
 - (void)showPithosNodeInfo:(id)sender;
 - (void)pithosNodeInfoWillClose:(id)sender;
 
index bb97046..941b08e 100644 (file)
@@ -41,7 +41,8 @@
 #import "ASIPithosRequest.h"
 
 @implementation PithosNode
-@synthesize forcedRefresh, parent, shared, sharingAccount, childrenUpdatedNotificationName, displayName, isLeafItem, icon;
+@synthesize forcedRefresh, parent, shared, sharingAccount, childrenUpdatedNotificationName, 
+            inheritChildrenUpdatedNotificationName, displayName, isLeafItem, icon;
 @dynamic url, children, pithos, pithosAccount, pithosContainer, pithosObject;
 
 #pragma mark -
@@ -53,6 +54,8 @@
         forcedRefresh = NO;
         shared = NO;
         isLeafItem = NO;
+        self.childrenUpdatedNotificationName = @"PithosNodeChildrenUpdated";
+        inheritChildrenUpdatedNotificationName = NO;
     }
     return self;
 }
     [self refresh];
 }
 
+- (void)postChildrenUpdatedNotificationName {
+    // Notify observers that children are updated
+    if (inheritChildrenUpdatedNotificationName) {
+        PithosNode *ancestor = self;
+        while (ancestor && ancestor.parent) {
+            ancestor = ancestor.parent;
+        }
+        if (ancestor && ancestor.childrenUpdatedNotificationName) {
+            [[NSNotificationCenter defaultCenter] postNotificationName:ancestor.childrenUpdatedNotificationName object:self];
+        }
+    } else if (childrenUpdatedNotificationName) {
+        [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self];
+    }
+}
+
 - (void)showPithosNodeInfo:(id)sender {
     // Abstract method
 }
index a908f5c..f96b598 100644 (file)
@@ -54,7 +54,6 @@
     if ((self = [super init])) {
         self.pithos = aPithos;
         self.sharingAccount = @"";
-        self.childrenUpdatedNotificationName = [NSString stringWithString:@"PithosSharingAccountsNodeChildrenUpdated"];
     }
     return self;
 }
                         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;
             }
-            if (childrenUpdatedNotificationName) {
-                // Notify observers that children are updated
-                [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self];
-            }
+            [self postChildrenUpdatedNotificationName];
         } else {
             [sharingAccountsRequest release];
             // Do an additional request to fetch more objects
index 5569d69..940f601 100644 (file)
@@ -67,7 +67,6 @@ static NSImage *sharedIcon = nil;
         self.pithos = aPithos;
         self.pithosContainer = aPithosContainer;
         self.pithosObject = aPithosObject;
-        self.childrenUpdatedNotificationName = [NSString stringWithString:@"PithosSubdirNodeChildrenUpdated"];
         refreshParent = NO;
     }
     return self;