|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Contains CNcdBundleFolderProxy class implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdbundlefolderproxy.h" |
|
20 #include "ncdoperationmanagerproxy.h" |
|
21 #include "ncdloadnodeoperationproxy.h" |
|
22 #include "catalogsinterfaceidentifier.h" |
|
23 #include "catalogsdebug.h" |
|
24 #include "catalogsutils.h" |
|
25 #include "ncdchildentity.h" |
|
26 #include "ncdnodemanagerproxy.h" |
|
27 #include "ncdchildloadmode.h" |
|
28 #include "ncdcapabilities.h" |
|
29 |
|
30 CNcdBundleFolderProxy* CNcdBundleFolderProxy::NewL( |
|
31 MCatalogsClientServer& aSession, |
|
32 TInt aHandle, |
|
33 CNcdNodeManagerProxy& aNodeManager, |
|
34 CNcdOperationManagerProxy& aOperationManager, |
|
35 CNcdFavoriteManagerProxy& aFavoriteManager ) |
|
36 { |
|
37 DLTRACEIN(("")); |
|
38 CNcdBundleFolderProxy* self = NewLC( |
|
39 aSession, aHandle, aNodeManager, aOperationManager, aFavoriteManager ); |
|
40 CleanupStack::Pop( self ); |
|
41 return self; |
|
42 } |
|
43 |
|
44 CNcdBundleFolderProxy* CNcdBundleFolderProxy::NewLC( |
|
45 MCatalogsClientServer& aSession, |
|
46 TInt aHandle, |
|
47 CNcdNodeManagerProxy& aNodeManager, |
|
48 CNcdOperationManagerProxy& aOperationManager, |
|
49 CNcdFavoriteManagerProxy& aFavoriteManager ) |
|
50 { |
|
51 DLTRACEIN(("")); |
|
52 CNcdBundleFolderProxy* self = new ( ELeave ) CNcdBundleFolderProxy( |
|
53 aSession, aHandle, aNodeManager, aOperationManager, aFavoriteManager ); |
|
54 // Using PushL because the object does not have any references yet |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL(); |
|
57 return self; |
|
58 } |
|
59 |
|
60 CNcdBundleFolderProxy::CNcdBundleFolderProxy( |
|
61 MCatalogsClientServer& aSession, |
|
62 TInt aHandle, |
|
63 CNcdNodeManagerProxy& aNodeManager, |
|
64 CNcdOperationManagerProxy& aOperationManager, |
|
65 CNcdFavoriteManagerProxy& aFavoriteManager ) |
|
66 : CNcdParentOfTransparentNodeProxy( aSession, |
|
67 aHandle, |
|
68 aNodeManager, |
|
69 aOperationManager, |
|
70 aFavoriteManager ) |
|
71 { |
|
72 } |
|
73 |
|
74 CNcdBundleFolderProxy::~CNcdBundleFolderProxy() |
|
75 { |
|
76 delete iViewType; |
|
77 } |
|
78 |
|
79 MNcdNode::TState CNcdBundleFolderProxy::State() const |
|
80 { |
|
81 DLTRACEIN((_L("Node namespace=%S, id=%S"), &Namespace(), &Id() )); |
|
82 |
|
83 // Check if the link handle has been set, which means that also |
|
84 // link data has been internalized. Also, check if the metadata |
|
85 // exists, which means that metadata has also been internalized. |
|
86 if ( LinkHandleSet() |
|
87 && Metadata() != NULL ) |
|
88 { |
|
89 DLINFO(("State was initialized")); |
|
90 // If state was initialized we have to check if the state |
|
91 // has acutally expired already |
|
92 TTime now; |
|
93 now.HomeTime(); |
|
94 |
|
95 DLINFO(("now time: %Ld", now.Int64() )); |
|
96 DLINFO(("expired time: %Ld", ExpiredTime().Int64() )); |
|
97 |
|
98 |
|
99 // We can just compare the times here. Server side |
|
100 // inserts the maximum value for the expired time if the |
|
101 // protocol has set never expire value for the validity delta. |
|
102 TBool isExpired = ( now > ExpiredTime() ); |
|
103 TInt err = KErrNone; |
|
104 |
|
105 if ( !isExpired ) |
|
106 { |
|
107 TRAP( err, isExpired = IsTransparentChildExpiredL() ); |
|
108 } |
|
109 |
|
110 if ( isExpired || err != KErrNone ) |
|
111 { |
|
112 DLTRACEOUT(("Expired")); |
|
113 return MNcdNode::EStateExpired; |
|
114 } |
|
115 |
|
116 DLTRACEOUT(("Initialized")); |
|
117 return MNcdNode::EStateInitialized; |
|
118 } |
|
119 else |
|
120 { |
|
121 // Node has not been initialized. |
|
122 DLTRACEOUT(("Not initialized")); |
|
123 return MNcdNode::EStateNotInitialized; |
|
124 } |
|
125 } |
|
126 |
|
127 TInt CNcdBundleFolderProxy::ChildCount() const |
|
128 { |
|
129 return iChildren.Count(); |
|
130 } |
|
131 |
|
132 |
|
133 MNcdNode* CNcdBundleFolderProxy::ChildL( TInt aIndex ) |
|
134 { |
|
135 DLTRACEIN(( _L("This parent: %S, %S"), &Namespace(), &Id() )); |
|
136 |
|
137 |
|
138 if ( aIndex < 0 || aIndex >= iChildren.Count() ) |
|
139 { |
|
140 // Nothing to be done |
|
141 DLERROR(( "Index error. child count: %d Given index: %d", |
|
142 iChildren.Count(), aIndex )); |
|
143 DASSERT( EFalse ); |
|
144 User::Leave( KErrArgument ); |
|
145 } |
|
146 |
|
147 const CNcdNodeIdentifier* child = &iChildren[aIndex]->Identifier(); |
|
148 |
|
149 MNcdNode* node( NULL ); |
|
150 |
|
151 TRAPD( err, node = &NodeManager().NodeL( *child ) ); |
|
152 |
|
153 if ( err == KErrNotFound ) |
|
154 { |
|
155 return NULL; |
|
156 } |
|
157 |
|
158 User::LeaveIfError( err ); |
|
159 |
|
160 // Increase the reference counter by one |
|
161 node->AddRef(); |
|
162 |
|
163 DLTRACEOUT(("")); |
|
164 |
|
165 return node; |
|
166 } |
|
167 |
|
168 MNcdLoadNodeOperation* CNcdBundleFolderProxy::LoadChildrenL( |
|
169 TInt aIndex, |
|
170 TInt aSize, |
|
171 TNcdChildLoadMode aMode, |
|
172 MNcdLoadNodeOperationObserver& aObserver ) |
|
173 { |
|
174 DLTRACEIN(("")); |
|
175 |
|
176 if( aSize < 1 || aIndex < 0 || ( aMode == ELoadMetadata && aIndex + aSize > ChildCount() ) ) |
|
177 { |
|
178 // Nothing to be done |
|
179 DLERROR(( "Argument error. ChildCount: %d Given index: %d, size: %d", |
|
180 ChildCount(), aIndex, aSize )); |
|
181 DASSERT( EFalse ); |
|
182 User::Leave( KErrArgument ); |
|
183 } |
|
184 |
|
185 DLTRACE(( _L("Node: %S, %S"), &Namespace(), &Id() )); |
|
186 |
|
187 if( aMode == ELoadMetadata ) |
|
188 { |
|
189 // Child metadata can be loaded in a regular load op. |
|
190 // Notice, because this node can be parent of transparent nodes |
|
191 // we have to make sure that the indexing is correct. (Transparent folders |
|
192 // may have been replaced by their children, and then the indexing will not |
|
193 // match the server side.) |
|
194 // Note that start index is always 0 for bundles |
|
195 CNcdLoadNodeOperationProxy* operation = |
|
196 OperationManager().CreateLoadNodeOperationL( *this, ETrue, |
|
197 ServerChildCount(), |
|
198 0, |
|
199 1, |
|
200 aMode ); |
|
201 |
|
202 if( operation == NULL ) |
|
203 { |
|
204 DLTRACEOUT(("NULL")); |
|
205 return NULL; |
|
206 } |
|
207 |
|
208 operation->AddObserverL( this ); |
|
209 operation->AddObserverL( &aObserver ); |
|
210 |
|
211 DLTRACEOUT(("")); |
|
212 |
|
213 return operation; |
|
214 } |
|
215 else |
|
216 { |
|
217 // Everything else needs to be loaded via root load op |
|
218 return LoadL( aObserver ); |
|
219 } |
|
220 } |
|
221 |
|
222 |
|
223 MNcdLoadNodeOperation* CNcdBundleFolderProxy::LoadL( |
|
224 MNcdLoadNodeOperationObserver& aObserver ) |
|
225 { |
|
226 DLTRACEIN(("")); |
|
227 |
|
228 CNcdLoadNodeOperationProxy* operation( NULL ); |
|
229 |
|
230 // bundle's are loaded with load bundle op |
|
231 operation = |
|
232 OperationManager().CreateLoadBundleNodeOperationL( *this ); |
|
233 |
|
234 operation->AddObserverL( this ); |
|
235 operation->AddObserverL( &aObserver ); |
|
236 |
|
237 return operation; |
|
238 } |
|
239 |
|
240 void CNcdBundleFolderProxy::ConstructL() |
|
241 { |
|
242 DLTRACEIN((("this: %x"), this )); |
|
243 AssignDesL( iViewType, KNullDesC() ); |
|
244 CNcdParentOfTransparentNodeProxy::ConstructL(); |
|
245 |
|
246 // Add the interface information to the list |
|
247 MNcdBundle* bundle( this ); |
|
248 AddInterfaceL( |
|
249 CCatalogsInterfaceIdentifier::NewL( |
|
250 bundle, this, MNcdBundle::KInterfaceUid ) ); |
|
251 } |
|
252 |
|
253 const TDesC& CNcdBundleFolderProxy::ViewType() const |
|
254 { |
|
255 DLTRACEIN((_L("this: %x, viewtype: %S"), this, iViewType)); |
|
256 return *iViewType; |
|
257 } |
|
258 |
|
259 |
|
260 |
|
261 void CNcdBundleFolderProxy::InternalizeL() |
|
262 { |
|
263 DLTRACEIN((("this: %x"), this)); |
|
264 |
|
265 // First call the parent internalizator. So, all the parent stuff will |
|
266 // be initialized before folder specific data. |
|
267 CNcdParentOfTransparentNodeProxy::InternalizeL(); |
|
268 |
|
269 DLTRACEOUT(("")); |
|
270 } |
|
271 |
|
272 |
|
273 |
|
274 void CNcdBundleFolderProxy::InternalizeNodeDataL( RReadStream& aStream ) |
|
275 { |
|
276 DLTRACEIN(("")); |
|
277 |
|
278 // First internalize parent data |
|
279 CNcdParentOfTransparentNodeProxy::InternalizeNodeDataL( aStream ); |
|
280 |
|
281 InternalizeDesL( iViewType, aStream ); |
|
282 |
|
283 DLINFO((_L("this: %x, viewtype: %S"), this, iViewType)); |
|
284 |
|
285 DLTRACEOUT(("")); |
|
286 } |
|
287 |
|
288 void CNcdBundleFolderProxy::InternalizeNodeLinkDataL( RReadStream& aStream ) |
|
289 { |
|
290 DLTRACEIN(("")); |
|
291 |
|
292 // First internalize parent data |
|
293 CNcdParentOfTransparentNodeProxy::InternalizeNodeLinkDataL( aStream ); |
|
294 |
|
295 DLTRACEOUT(("")); |
|
296 } |
|
297 |
|
298 TBool CNcdBundleFolderProxy::IsSearchSupportedL() |
|
299 { |
|
300 DLTRACEIN(("")); |
|
301 // If one of the bundles children has search capability set, then this |
|
302 // bundle supports searching. |
|
303 // NOTE: Search will only be conducted for children with search capability set. |
|
304 for( TInt i = 0 ; i < iChildren.Count() ; i++ ) |
|
305 { |
|
306 if( NodeManager().IsCapabilitySupportedL( iChildren[i]->Identifier(), |
|
307 NcdCapabilities::KSearch ) ) |
|
308 { |
|
309 return ETrue; |
|
310 } |
|
311 } |
|
312 return EFalse; |
|
313 } |