5 // Copyright 2011 GRNET S.A. All rights reserved.
7 // Redistribution and use in source and binary forms, with or
8 // without modification, are permitted provided that the following
11 // 1. Redistributions of source code must retain the above
12 // copyright notice, this list of conditions and the following
15 // 2. Redistributions in binary form must reproduce the above
16 // copyright notice, this list of conditions and the following
17 // disclaimer in the documentation and/or other materials
18 // provided with the distribution.
20 // THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
21 // OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
24 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
33 // The views and conclusions contained in the software and
34 // documentation are those of the authors and should not be
35 // interpreted as representing official policies, either expressed
36 // or implied, of GRNET S.A.
38 #import "PithosNode.h"
39 #import "PithosNodeInfoController.h"
40 #import "ASIPithosRequest.h"
42 @implementation PithosNode
43 @synthesize forcedRefresh, parent, shared, sharingAccount, childrenUpdatedNotificationName,
44 inheritChildrenUpdatedNotificationName, displayName, isLeafItem, icon;
45 @dynamic url, children, pithos, pithosAccount, pithosContainer, pithosObject;
48 #pragma mark Object Lifecycle
51 if ((self = [super init])) {
52 freshness = PithosNodeStateRefreshNeeded;
56 self.childrenUpdatedNotificationName = @"PithosNodeChildrenUpdated";
57 inheritChildrenUpdatedNotificationName = NO;
63 - (BOOL)isEqual:(id)anObject {
64 return ([anObject isKindOfClass:[self class]] && [((PithosNode *)anObject).url isEqual:self.url]);
72 #pragma mark Properties
74 - (void)setShared:(BOOL)aShared {
75 if (shared != aShared) {
81 - (void)setSharingAccount:(NSString *)aSharingAccount {
82 if (![sharingAccount isEqualToString:aSharingAccount]) {
83 sharingAccount = aSharingAccount;
91 - (void)invalidateChildren {
92 if (freshness == PithosNodeStateFresh)
93 freshness = PithosNodeStateRefreshNeeded;
96 - (void)invalidateChildrenRecursive {
97 if (freshness == PithosNodeStateFresh) {
98 for (PithosNode *child in children) {
99 [child invalidateChildrenRecursive];
101 freshness = PithosNodeStateRefreshNeeded;
106 [self invalidateChildren];
110 - (void)forceRefresh {
115 - (void)postChildrenUpdatedNotificationName {
116 // Notify observers that children are updated
117 if (inheritChildrenUpdatedNotificationName) {
118 PithosNode *ancestor = self;
119 while (ancestor && ancestor.parent) {
120 ancestor = ancestor.parent;
122 if (ancestor && ancestor.childrenUpdatedNotificationName) {
123 [[NSNotificationCenter defaultCenter] postNotificationName:ancestor.childrenUpdatedNotificationName object:self];
125 } else if (childrenUpdatedNotificationName) {
126 [[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self];
130 - (void)showPithosNodeInfo:(id)sender {
134 - (void)pithosNodeInfoWillClose:(id)sender {
135 if (pithosNodeInfoController) {
136 pithosNodeInfoController = nil;
140 - (void)pithosNodeWillBeRemoved {
141 if (pithosNodeInfoController) {
142 pithosNodeInfoController.node = nil;
143 [[pithosNodeInfoController window] close];
145 for (PithosNode *child in children) {
146 [child pithosNodeWillBeRemoved];
151 #pragma mark ASIHTTPRequestDelegate
153 - (void)performRequestFinishedDelegateInBackground:(ASIPithosRequest *)request {
154 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
155 [self performSelector:NSSelectorFromString([request.userInfo objectForKey:@"didFinishSelector"]) withObject:request];
159 - (void)performRequestFailedDelegateInBackground:(ASIPithosRequest *)request {
160 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
161 [self performSelector:NSSelectorFromString([request.userInfo objectForKey:@"didFailSelector"]) withObject:request];