From 7da4ebcca5a3b0768cbd8f7c2baf32f90d32dadb Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Thu, 8 Mar 2012 19:46:48 +0200 Subject: [PATCH] Modify nodes to make notifications configurable and provide property access to all related ASIPithos objects. --- pithos-macos/PithosAccount.m | 1 + pithos-macos/PithosAccountNode.m | 13 +++++++++---- pithos-macos/PithosContainerNode.h | 1 - pithos-macos/PithosContainerNode.m | 15 +++++++++------ pithos-macos/PithosNode.h | 6 ++++++ pithos-macos/PithosNode.m | 5 +++-- pithos-macos/PithosSharingAccountsNode.m | 7 +++++-- pithos-macos/PithosSubdirNode.m | 2 +- 8 files changed, 34 insertions(+), 16 deletions(-) diff --git a/pithos-macos/PithosAccount.m b/pithos-macos/PithosAccount.m index 1d72e6b..45af887 100644 --- a/pithos-macos/PithosAccount.m +++ b/pithos-macos/PithosAccount.m @@ -369,6 +369,7 @@ - (PithosAccountNode *)accountNode { if (!accountNode) { accountNode = [[PithosAccountNode alloc] initWithPithos:self.pithos]; + accountNode.childrenUpdatedNotificationName = nil; } return accountNode; } diff --git a/pithos-macos/PithosAccountNode.m b/pithos-macos/PithosAccountNode.m index 3170e0e..48bce3b 100644 --- a/pithos-macos/PithosAccountNode.m +++ b/pithos-macos/PithosAccountNode.m @@ -61,6 +61,7 @@ static NSImage *sharedIcon = nil; - (id)initWithPithos:(ASIPithos *)aPithos { if ((self = [super init])) { self.pithos = aPithos; + self.childrenUpdatedNotificationName = [NSString stringWithString:@"PithosAccountNodeChildrenUpdated"]; } return self; } @@ -242,8 +243,10 @@ static NSImage *sharedIcon = nil; @synchronized(self) { freshness = PithosNodeStateRefreshFinished; } - // Notify observers that children are updated - [[NSNotificationCenter defaultCenter] postNotificationName:@"PithosAccountNodeChildrenUpdated" object:self]; + if (childrenUpdatedNotificationName) { + // Notify observers that children are updated + [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self]; + } } else { [accountRequest release]; // Do an additional request to fetch more objects @@ -277,8 +280,10 @@ static NSImage *sharedIcon = nil; @synchronized(self) { freshness = PithosNodeStateRefreshFinished; } - // Notify observers that children are updated - [[NSNotificationCenter defaultCenter] postNotificationName:@"PithosAccountNodeChildrenUpdated" object:self]; + if (childrenUpdatedNotificationName) { + // Notify observers that children are updated + [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self]; + } } else { [self accountRequestFailed:accountRequest]; } diff --git a/pithos-macos/PithosContainerNode.h b/pithos-macos/PithosContainerNode.h index e89a986..4f5fee9 100644 --- a/pithos-macos/PithosContainerNode.h +++ b/pithos-macos/PithosContainerNode.h @@ -47,7 +47,6 @@ NSMutableArray *objects; ASIPithosContainerRequest *containerRequest; NSString *prefix; - NSString *childrenUpdatedNotificationName; ASIPithosContainerRequest *applyMetadataContainerRequest; ASIPithosContainerRequest *refreshMetadataContainerRequest; diff --git a/pithos-macos/PithosContainerNode.m b/pithos-macos/PithosContainerNode.m index b12c98c..47d9a07 100644 --- a/pithos-macos/PithosContainerNode.m +++ b/pithos-macos/PithosContainerNode.m @@ -67,7 +67,7 @@ static NSImage *sharedIcon = nil; self.pithosContainer = aPithosContainer; prefix = nil; self.icon = anIcon; - childrenUpdatedNotificationName = @"PithosContainerNodeChildrenUpdated"; + self.childrenUpdatedNotificationName = [NSString stringWithString:@"PithosContainerNodeChildrenUpdated"]; } return self; } @@ -95,7 +95,6 @@ static NSImage *sharedIcon = nil; [applyMetadataContainerRequest release]; [policyQuota release]; [policyVersioning release]; - [childrenUpdatedNotificationName release]; [prefix release]; [objects release]; [pithosContainer release]; @@ -367,8 +366,10 @@ static NSImage *sharedIcon = nil; @synchronized(self) { freshness = PithosNodeStateRefreshFinished; } - // Notify observers that children are updated - [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self]; + if (childrenUpdatedNotificationName) { + // Notify observers that children are updated + [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self]; + } } else { [containerRequest release]; // Do an additional request to fetch more objects @@ -407,8 +408,10 @@ static NSImage *sharedIcon = nil; @synchronized(self) { freshness = PithosNodeStateRefreshFinished; } - // Notify observers that children are updated - [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self]; + if (childrenUpdatedNotificationName) { + // Notify observers that children are updated + [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self]; + } } else { [self containerRequestFailed:containerRequest]; } diff --git a/pithos-macos/PithosNode.h b/pithos-macos/PithosNode.h index b8fb28c..8089747 100644 --- a/pithos-macos/PithosNode.h +++ b/pithos-macos/PithosNode.h @@ -41,6 +41,8 @@ #define PithosNodeStateRefreshFinished 3 @class PithosNodeInfoController; +@class ASIPithos; +@class ASIPithosAccount; @class ASIPithosContainer; @class ASIPithosObject; @class ASIPithosRequest; @@ -56,6 +58,7 @@ NSString *sharingAccount; NSMutableArray *children; NSMutableArray *newChildren; + NSString *childrenUpdatedNotificationName; NSString *displayName; BOOL isLeafItem; @@ -73,12 +76,15 @@ @property(nonatomic, assign) BOOL shared; @property(nonatomic, retain) NSString *sharingAccount; @property(nonatomic, readonly) NSArray *children; +@property(nonatomic, retain) NSString *childrenUpdatedNotificationName; @property(nonatomic, retain) NSString *displayName; @property(nonatomic, readonly) BOOL isLeafItem; @property(nonatomic, retain) NSImage *icon; +@property(nonatomic, retain) ASIPithos *pithos; +@property(nonatomic, retain) ASIPithosAccount *pithosAccount; @property(nonatomic, retain) ASIPithosContainer *pithosContainer; @property(nonatomic, retain) ASIPithosObject *pithosObject; diff --git a/pithos-macos/PithosNode.m b/pithos-macos/PithosNode.m index 2439f70..bb97046 100644 --- a/pithos-macos/PithosNode.m +++ b/pithos-macos/PithosNode.m @@ -41,8 +41,8 @@ #import "ASIPithosRequest.h" @implementation PithosNode -@synthesize forcedRefresh, parent, shared, sharingAccount, displayName, isLeafItem, icon; -@dynamic url, children, pithosContainer, pithosObject; +@synthesize forcedRefresh, parent, shared, sharingAccount, childrenUpdatedNotificationName, displayName, isLeafItem, icon; +@dynamic url, children, pithos, pithosAccount, pithosContainer, pithosObject; #pragma mark - #pragma mark Object Lifecycle @@ -62,6 +62,7 @@ [sharingAccount release]; [icon release]; [displayName release]; + [childrenUpdatedNotificationName release]; [newChildren release]; [children release]; [url release]; diff --git a/pithos-macos/PithosSharingAccountsNode.m b/pithos-macos/PithosSharingAccountsNode.m index 39d902c..d8e4487 100644 --- a/pithos-macos/PithosSharingAccountsNode.m +++ b/pithos-macos/PithosSharingAccountsNode.m @@ -54,6 +54,7 @@ if ((self = [super init])) { self.pithos = aPithos; self.sharingAccount = @""; + self.childrenUpdatedNotificationName = [NSString stringWithString:@"PithosSharingAccountsNodeChildrenUpdated"]; } return self; } @@ -214,8 +215,10 @@ @synchronized(self) { freshness = PithosNodeStateRefreshFinished; } - // Notify observers that children are updated - [[NSNotificationCenter defaultCenter] postNotificationName:@"PithosSharingAccountsNodeChildrenUpdated" object:self]; + if (childrenUpdatedNotificationName) { + // Notify observers that children are updated + [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self]; + } } else { [sharingAccountsRequest release]; // Do an additional request to fetch more objects diff --git a/pithos-macos/PithosSubdirNode.m b/pithos-macos/PithosSubdirNode.m index 6623172..5569d69 100644 --- a/pithos-macos/PithosSubdirNode.m +++ b/pithos-macos/PithosSubdirNode.m @@ -67,7 +67,7 @@ static NSImage *sharedIcon = nil; self.pithos = aPithos; self.pithosContainer = aPithosContainer; self.pithosObject = aPithosObject; - childrenUpdatedNotificationName = @"PithosSubdirNodeChildrenUpdated"; + self.childrenUpdatedNotificationName = [NSString stringWithString:@"PithosSubdirNodeChildrenUpdated"]; refreshParent = NO; } return self; -- 1.7.10.4