Simplify default and support custom notifications for nodes.
[pithos-macos] / pithos-macos / PithosContainerNode.m
index 1752a0c..b061899 100644 (file)
@@ -67,7 +67,6 @@ static NSImage *sharedIcon = nil;
         self.pithosContainer = aPithosContainer;
         prefix = nil;
         self.icon = anIcon;
-        childrenUpdatedNotificationName = @"PithosContainerNodeChildrenUpdated";
     }
     return self;
 }
@@ -95,7 +94,6 @@ static NSImage *sharedIcon = nil;
     [applyMetadataContainerRequest release];
     [policyQuota release];
     [policyVersioning release];
-    [childrenUpdatedNotificationName release];
     [prefix release];
     [objects release];
     [pithosContainer release];
@@ -205,6 +203,20 @@ static NSImage *sharedIcon = nil;
     }
 }
 
+- (void)setLimitedPithosContainer:(ASIPithosContainer *)aPithosContainer {
+    if (![pithosContainer isEqualTo:aPithosContainer]) {
+        self.pithosContainer.name = aPithosContainer.name;
+        self.pithosContainer.count = aPithosContainer.count;
+        self.pithosContainer.bytes = aPithosContainer.bytes;
+        self.pithosContainer.lastModified = aPithosContainer.lastModified;
+        self.pithosContainer.untilTimestamp = aPithosContainer.untilTimestamp;
+        if (!pithosNodeInfoController) {
+            self.pithosContainer.policy = aPithosContainer.policy;
+            self.pithosContainer = pithosContainer;
+        }
+    }
+}
+
 #pragma mark -
 #pragma mark ASIHTTPRequestDelegate
 
@@ -281,13 +293,15 @@ 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) {
                                         // Use the same pointer value, if possible
                                         node = [children objectAtIndex:oldIndex];
                                         node.pithosContainer = pithosContainer;
-                                        node.pithosObject = object;
+//                                        node.pithosObject = object;
+                                        [node setLimitedPithosObject:object];
                                         [keptNodes addIndex:oldIndex];
                                     }
                                 }
@@ -302,13 +316,15 @@ 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) {
                                     // Use the same pointer value, if possible
                                     node = [children objectAtIndex:oldIndex];
                                     node.pithosContainer = pithosContainer;
-                                    node.pithosObject = object;
+//                                    node.pithosObject = object;
+                                    [node setLimitedPithosObject:object];
                                     [keptNodes addIndex:oldIndex];
                                 }
                             }
@@ -320,13 +336,15 @@ 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) {
                                     // Use the same pointer value, if possible
                                     node = [children objectAtIndex:oldIndex];
                                     node.pithosContainer = pithosContainer;
-                                    node.pithosObject = object;
+//                                    node.pithosObject = object;
+                                    [node setLimitedPithosObject:object];
                                     [keptNodes addIndex:oldIndex];
                                 }
                             }
@@ -350,8 +368,7 @@ static NSImage *sharedIcon = nil;
             @synchronized(self) {
                 freshness = PithosNodeStateRefreshFinished;
             }
-            // 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
@@ -390,8 +407,7 @@ static NSImage *sharedIcon = nil;
         @synchronized(self) {
             freshness = PithosNodeStateRefreshFinished;
         }
-        // Notify observers that children are updated
-        [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self];
+        [self postChildrenUpdatedNotificationName];
     } else {
         [self containerRequestFailed:containerRequest];
     }
@@ -424,7 +440,7 @@ static NSImage *sharedIcon = nil;
     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     NSUInteger retries = [[request.userInfo objectForKey:@"retries"] unsignedIntegerValue];
     if (retries > 0) {
-        ASIPithosContainerRequest *newRequest = (ASIPithosContainerRequest *)[PithosUtilities copyRequest:request];
+        ASIPithosContainerRequest *newRequest = (ASIPithosContainerRequest *)[[PithosUtilities copyRequest:request] autorelease];
         [(NSMutableDictionary *)(newRequest.userInfo)setObject:[NSNumber numberWithUnsignedInteger:(--retries)] forKey:@"retries"];
         if ([request isEqualTo:applyMetadataContainerRequest]) {
             @synchronized(self) {
@@ -513,8 +529,10 @@ static NSImage *sharedIcon = nil;
 #pragma mark Actions
 
 - (void)showPithosNodeInfo:(id)sender {
-    if (!pithosNodeInfoController)
+    if (!pithosNodeInfoController) {
         pithosNodeInfoController = [[PithosContainerNodeInfoController alloc] initWithPithosNode:self];
+        [self refreshInfo];
+    }
     [pithosNodeInfoController showWindow:sender];
     [[pithosNodeInfoController window] makeKeyAndOrderFront:sender];
     [NSApp activateIgnoringOtherApps:YES];