root / pithos-macos / PithosNode.m @ 97c9a632
History | View | Annotate | Download (5.3 kB)
1 |
// |
---|---|
2 |
// PithosNode.m |
3 |
// pithos-macos |
4 |
// |
5 |
// Copyright 2011 GRNET S.A. All rights reserved. |
6 |
// |
7 |
// Redistribution and use in source and binary forms, with or |
8 |
// without modification, are permitted provided that the following |
9 |
// conditions are met: |
10 |
// |
11 |
// 1. Redistributions of source code must retain the above |
12 |
// copyright notice, this list of conditions and the following |
13 |
// disclaimer. |
14 |
// |
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. |
19 |
// |
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. |
32 |
// |
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. |
37 |
|
38 |
#import "PithosNode.h" |
39 |
#import "PithosNodeInfoController.h" |
40 |
#import "ASIPithosRequest.h" |
41 |
|
42 |
@implementation PithosNode |
43 |
@synthesize forcedRefresh, pithosAccountManager, parent, shared, sharingAccount, childrenUpdatedNotificationName, |
44 |
inheritChildrenUpdatedNotificationName, displayName, isLeafItem, icon; |
45 |
@dynamic url, children, pithos, pithosAccount, pithosContainer, pithosObject; |
46 |
|
47 |
#pragma mark - |
48 |
#pragma mark Object Lifecycle |
49 |
|
50 |
- (id)initWithPithosAccountManager:(PithosAccount *)aPithosAccountManager { |
51 |
if ((self = [super init])) { |
52 |
self.pithosAccountManager = aPithosAccountManager; |
53 |
freshness = PithosNodeStateRefreshNeeded; |
54 |
forcedRefresh = NO; |
55 |
shared = NO; |
56 |
isLeafItem = NO; |
57 |
self.childrenUpdatedNotificationName = @"PithosNodeChildrenUpdated"; |
58 |
inheritChildrenUpdatedNotificationName = NO; |
59 |
} |
60 |
return self; |
61 |
} |
62 |
|
63 |
- (id)init { |
64 |
return [self initWithPithosAccountManager:nil]; |
65 |
} |
66 |
|
67 |
- (BOOL)isEqual:(id)anObject { |
68 |
return ([anObject isKindOfClass:[self class]] && [((PithosNode *)anObject).url isEqual:self.url]); |
69 |
} |
70 |
|
71 |
- (NSUInteger)hash { |
72 |
return self.url.hash; |
73 |
} |
74 |
|
75 |
#pragma mark - |
76 |
#pragma mark Properties |
77 |
|
78 |
- (void)setShared:(BOOL)aShared { |
79 |
if (shared != aShared) { |
80 |
shared = aShared; |
81 |
url = nil; |
82 |
} |
83 |
} |
84 |
|
85 |
- (void)setSharingAccount:(NSString *)aSharingAccount { |
86 |
if (![sharingAccount isEqualToString:aSharingAccount]) { |
87 |
sharingAccount = aSharingAccount; |
88 |
url = nil; |
89 |
} |
90 |
} |
91 |
|
92 |
#pragma mark - |
93 |
#pragma mark Actions |
94 |
|
95 |
- (void)invalidateChildren { |
96 |
if (freshness == PithosNodeStateFresh) |
97 |
freshness = PithosNodeStateRefreshNeeded; |
98 |
} |
99 |
|
100 |
- (void)invalidateChildrenRecursive { |
101 |
if (freshness == PithosNodeStateFresh) { |
102 |
for (PithosNode *child in children) { |
103 |
[child invalidateChildrenRecursive]; |
104 |
} |
105 |
freshness = PithosNodeStateRefreshNeeded; |
106 |
} |
107 |
} |
108 |
|
109 |
- (void)refresh { |
110 |
[self invalidateChildren]; |
111 |
[self children]; |
112 |
} |
113 |
|
114 |
- (void)forceRefresh { |
115 |
forcedRefresh = YES; |
116 |
[self refresh]; |
117 |
} |
118 |
|
119 |
- (void)postChildrenUpdatedNotificationName { |
120 |
// Notify observers that children are updated |
121 |
if (inheritChildrenUpdatedNotificationName) { |
122 |
PithosNode *ancestor = self; |
123 |
while (ancestor && ancestor.parent) { |
124 |
ancestor = ancestor.parent; |
125 |
} |
126 |
if (ancestor && ancestor.childrenUpdatedNotificationName) { |
127 |
[[NSNotificationCenter defaultCenter] postNotificationName:ancestor.childrenUpdatedNotificationName object:self]; |
128 |
} |
129 |
} else if (childrenUpdatedNotificationName) { |
130 |
[[NSNotificationCenter defaultCenter] postNotificationName:childrenUpdatedNotificationName object:self]; |
131 |
} |
132 |
} |
133 |
|
134 |
- (void)showPithosNodeInfo:(id)sender { |
135 |
// Abstract method |
136 |
} |
137 |
|
138 |
- (void)pithosNodeInfoWillClose:(id)sender { |
139 |
if (pithosNodeInfoController) { |
140 |
pithosNodeInfoController = nil; |
141 |
} |
142 |
} |
143 |
|
144 |
- (void)pithosNodeWillBeRemoved { |
145 |
if (pithosNodeInfoController) { |
146 |
pithosNodeInfoController.node = nil; |
147 |
[[pithosNodeInfoController window] close]; |
148 |
} |
149 |
[children makeObjectsPerformSelector:@selector(pithosNodeWillBeRemoved)]; |
150 |
} |
151 |
|
152 |
#pragma mark - |
153 |
#pragma mark ASIHTTPRequestDelegate |
154 |
|
155 |
- (void)performRequestFinishedDelegateInBackground:(ASIPithosRequest *)request { |
156 |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ |
157 |
[self performSelector:NSSelectorFromString([request.userInfo objectForKey:@"didFinishSelector"]) withObject:request]; |
158 |
}); |
159 |
} |
160 |
|
161 |
- (void)performRequestFailedDelegateInBackground:(ASIPithosRequest *)request { |
162 |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ |
163 |
[self performSelector:NSSelectorFromString([request.userInfo objectForKey:@"didFailSelector"]) withObject:request]; |
164 |
}); |
165 |
} |
166 |
|
167 |
@end |