|
1 /* |
|
2 * Copyright (c) 2007-2008 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_NCDNODESEENINFO_H |
|
20 #define C_NCDNODESEENINFO_H |
|
21 |
|
22 #include <e32base.h> |
|
23 #include "ncdstoragedataitem.h" |
|
24 #include "ncdnodefactory.h" |
|
25 |
|
26 // Defines the maximum amount of "new" idenfifiers. If |
|
27 // this value is exceeded then older identifiers will be |
|
28 // removed from the bottom of the "new" list. |
|
29 const TInt KNewListMaxSize(50); |
|
30 |
|
31 class CNcdNodeIdentifier; |
|
32 class MNcdStorageManager; |
|
33 class CNcdNodeManager; |
|
34 class CNcdNodeFolder; |
|
35 class CNcdChildEntity; |
|
36 class CNcdChildEntityMap; |
|
37 class CNcdGeneralManager; |
|
38 |
|
39 enum TNcdNewStatus |
|
40 { |
|
41 /** Node itself is new */ |
|
42 ENcdStatusNew = 0x00000001, |
|
43 /** Node itself is new */ |
|
44 ENcdStatusNewButSeen = 0x00000010, |
|
45 /** Folder contains new items */ |
|
46 ENcdStatusNewNodesInside = 0x00000100 |
|
47 }; |
|
48 |
|
49 /** |
|
50 * Stores information about new nodes. |
|
51 */ |
|
52 class CNcdNodeSeenInfo : public CBase |
|
53 { |
|
54 public: |
|
55 static CNcdNodeSeenInfo* NewL( CNcdGeneralManager& aGeneralManager ); |
|
56 |
|
57 static CNcdNodeSeenInfo* NewLC( CNcdGeneralManager& aGeneralManager ); |
|
58 |
|
59 ~CNcdNodeSeenInfo(); |
|
60 |
|
61 /** |
|
62 * Adds a structure identifier to the new list if it does not exist yet. |
|
63 * If it does exist, it will be moved to the top of the list. |
|
64 * |
|
65 * @param aStructureIdentifier The identifier. |
|
66 * @param aNewStatus New status of the node. |
|
67 */ |
|
68 void AddNewIdL( const CNcdNodeIdentifier& aStructureIdentifier, |
|
69 TNcdNewStatus aNewStatus, CNcdNodeFactory::TNcdNodeType aNodeType ); |
|
70 |
|
71 void AddNewIdL( const CNcdChildEntity& aChildEntity ); |
|
72 |
|
73 /** |
|
74 * Tells whether the given structure node is seen. |
|
75 * |
|
76 * @param aStructureIdentifier The structure node identifier. |
|
77 * @return ETrue if the node is seen, otherwise EFalse. |
|
78 */ |
|
79 TBool IsSeenL( const CNcdNodeIdentifier& aStructureIdentifier ); |
|
80 |
|
81 /** |
|
82 * Sets the given structure node as seen. Affects only after |
|
83 * CommitChangesL. |
|
84 * |
|
85 * @param aStructureIdentifier The structure node identifier. |
|
86 */ |
|
87 void SetSeenL( const CNcdNodeIdentifier& aStructureIdentifier ); |
|
88 |
|
89 |
|
90 /** |
|
91 * Checks the new statuses of a folder's children against the previous children. |
|
92 * The folder's and it's parent hierarchy's new statuses are set if needed. |
|
93 * The previous array is fetched from the folder. |
|
94 * |
|
95 * @param aParentFolder The parent folder to check. |
|
96 */ |
|
97 void CheckFolderNewStatusL( CNcdNodeFolder& aParentFolder ); |
|
98 |
|
99 /** |
|
100 * Checks the new statuses of a folder's children against the previous children. |
|
101 * The folder's and it's parent hierarchy's new statuses are set if needed. |
|
102 * The previous array is fetched from the folder. |
|
103 * |
|
104 * @param aParentFolder The parent folder to check. |
|
105 * @param aPreviousChildArray The previous children to check against. |
|
106 */ |
|
107 void CheckFolderNewStatusL( CNcdNodeFolder& aParentFolder, |
|
108 const RPointerArray<CNcdChildEntity>& aPreviousChildArray ); |
|
109 |
|
110 /** |
|
111 * Checks the new status of a child node against the parent folder's |
|
112 * previous children. The parent hierarchy's new statuses are set if needed. |
|
113 * |
|
114 * @param aParentFolder The parent folder of the node. |
|
115 * @param aChildIndex The index of the child node to check. |
|
116 */ |
|
117 void CheckChildNewStatusL( CNcdNodeFolder& aParentFolder, TInt aChildIndex ); |
|
118 |
|
119 |
|
120 /** |
|
121 * Clears the new list completely. |
|
122 * |
|
123 * @param aClient Uid of the client whose list will be cleared. |
|
124 */ |
|
125 void ClearInfoL( const TUid& aClientUid ); |
|
126 |
|
127 /** |
|
128 * Commits the changes made by SetSeenL (the seen nodes are be removed from the new list) |
|
129 * and saves seen info to the database storage. |
|
130 * |
|
131 * @param aClient Uid of the client whose changes are committed. |
|
132 */ |
|
133 void CommitChangesL( const TUid& aClientUid ); |
|
134 |
|
135 /** |
|
136 * Creates lists of previous children for the children of the given folder. |
|
137 * |
|
138 * @note Only folders with type CNcdNodeFactory::ENcdNodeFolder are handled |
|
139 * (e.g. bundles are not handled). |
|
140 * @param aParentFolder The folder. |
|
141 * @param aChildEntityMaps Will contain a child entity map for each child on return. |
|
142 */ |
|
143 void CreatePreviousListsForChildrenL( CNcdNodeFolder& aParentFolder, |
|
144 RPointerArray<CNcdChildEntityMap>& aChildEntityMaps ); |
|
145 |
|
146 /** |
|
147 * Stoeres previous child lists for the existing child folders of the given folder. |
|
148 * |
|
149 * @param aParentFolder The folder. |
|
150 * @param aChildEntityMaps Child entity maps containing the previous lists. |
|
151 */ |
|
152 void StorePreviousListsToExistingChildrenL( CNcdNodeFolder& aParentFolder, |
|
153 const RPointerArray<CNcdChildEntityMap>& aChildEntityMaps ); |
|
154 |
|
155 /** |
|
156 * Does a new status check for the transparent children of the given folder. |
|
157 * |
|
158 * @param aParentFolder The folder. |
|
159 */ |
|
160 void DoNewCheckForTransparentChildrenL( CNcdNodeFolder& aParentFolder ); |
|
161 |
|
162 /** |
|
163 * Immediately removes new id for the folder if no new children exist. |
|
164 */ |
|
165 void RefreshFolderSeenStatusL( const CNcdNodeIdentifier& aNodeIdentifier ); |
|
166 |
|
167 private: |
|
168 class CClientSeenInfo; |
|
169 class CNcdNodeNewStatus; |
|
170 |
|
171 CNcdNodeSeenInfo( CNcdGeneralManager& aGeneralManager ); |
|
172 void ConstructL(); |
|
173 |
|
174 /** |
|
175 * Returns the client's client info, if one exists. |
|
176 * |
|
177 * @param aClientUid The uid of the client. |
|
178 * @return The client info, or NULL. Ownership is not transferred. |
|
179 */ |
|
180 CClientSeenInfo* ClientInfo( const TUid& aClientUid ) const; |
|
181 |
|
182 /** |
|
183 * Checks that is the given identifier in the new status array. |
|
184 * |
|
185 * @param aNodeIdentifier The identifier to search for. |
|
186 * @return The index of the given identifier in the array if found, |
|
187 * otherwise KErrNotFound. |
|
188 */ |
|
189 TInt IndexInNewStatusArray( const CNcdNodeIdentifier& aNodeIdentifier ) const; |
|
190 |
|
191 /** |
|
192 * Getter for node new status. |
|
193 * |
|
194 * @param aNodeIdentifier The identifier to search for. |
|
195 * @return New status for the node, NULL if not found. |
|
196 */ |
|
197 CNcdNodeNewStatus* NodeNewStatus( const CNcdNodeIdentifier& aNodeIdentifier ); |
|
198 TInt IndexInSeenArray( const CNcdNodeIdentifier& aNodeIdentifier ) const; |
|
199 TBool IsAddedAsSeen( const CNcdNodeIdentifier& aNodeIdentifier ) const; |
|
200 |
|
201 void RemoveFromSeenListL( const CNcdNodeIdentifier& aNodeIdentifier ); |
|
202 void RemoveFromNewListL( const CNcdNodeIdentifier& aNodeIdentifier ); |
|
203 |
|
204 TBool IsClientInfoLoaded( const TUid& aClientUid ) const; |
|
205 void RemoveClientInfo( const TUid& aClientUid ); |
|
206 |
|
207 void DbLoadClientInfoL( const TUid& aClientUid ); |
|
208 void DbSaveClientInfoL( const TUid& aClientUid ); |
|
209 |
|
210 /** |
|
211 * Removes the given structure identifier from the new list. |
|
212 * |
|
213 * @param aStructureIdentifier The structure node identifier. |
|
214 */ |
|
215 void RemoveNewIdL( const CNcdNodeIdentifier& aStructureIdentifier ); |
|
216 |
|
217 /** |
|
218 * Checks that does the given child entity exist in the given array. |
|
219 * Comparison is done with identifier only. |
|
220 * |
|
221 * @param aChildEntity The child to search for. |
|
222 * @param aChildArray The array to search from. |
|
223 * @param aNodeWithSameIndexFound Set to ETrue if there is a |
|
224 * node in aChildArray with the same index as aChildEntity has. NOTE: |
|
225 * Since this is not needed if node is found the searching will stop and |
|
226 * this value may not have been set correctly! Only use if node not found! |
|
227 * @return ETrue if a child with the same identifier is found in the array. |
|
228 */ |
|
229 TBool ChildExistsInArrayL( const CNcdChildEntity& aChildEntity, |
|
230 const RPointerArray<CNcdChildEntity>& aChildArray, |
|
231 TBool& aNodeWithSameIndexFound ); |
|
232 |
|
233 /** |
|
234 * Checks whether a folder has new children that are have not been set seen. |
|
235 * Check is made against current new list only, no comparison against |
|
236 * previous child array is made. |
|
237 */ |
|
238 TBool FolderHasNewUnseenChildrenL( const CNcdNodeIdentifier& aNodeIdentifier ); |
|
239 |
|
240 /** |
|
241 * Checks whether a folder has new children. Being set seen has no effect here. |
|
242 * Check is made against current new list only, no comparison against |
|
243 * previous child array is made. |
|
244 */ |
|
245 TBool FolderHasNewChildrenL( const CNcdNodeIdentifier& aNodeIdentifier ); |
|
246 |
|
247 /** |
|
248 * Adds a seen id. |
|
249 */ |
|
250 void AddSeenIdL( const CNcdNodeIdentifier& aNodeIdentifier ); |
|
251 |
|
252 /** |
|
253 * Sets a folder seen if it no longer has new child items. |
|
254 */ |
|
255 void SetFolderSeenIfNeededL( const CNcdNodeIdentifier& aNodeIdentifier ); |
|
256 |
|
257 /** |
|
258 * Sets all children of the folder new. |
|
259 */ |
|
260 void SetChildrenNewL( CNcdNodeFolder& aParentFolder ); |
|
261 |
|
262 private: |
|
263 |
|
264 class CClientSeenInfo : public CBase, |
|
265 public MNcdStorageDataItem |
|
266 { |
|
267 public: |
|
268 CClientSeenInfo( const TUid& aClientUid ); |
|
269 ~CClientSeenInfo(); |
|
270 |
|
271 public: // from MNcdStorageDataItem |
|
272 |
|
273 /* |
|
274 * @see MNcdStorageDataItem::ExternalizeL |
|
275 */ |
|
276 virtual void ExternalizeL( RWriteStream& aStream ); |
|
277 |
|
278 /* |
|
279 * @see MNcdStorageDataItem::InternalizeL |
|
280 */ |
|
281 virtual void InternalizeL( RReadStream& aStream ); |
|
282 |
|
283 public: // member variables |
|
284 |
|
285 // List of node new statuses. |
|
286 RPointerArray<CNcdNodeNewStatus> iNodeNewStatusArray; |
|
287 // List of seen nodes. |
|
288 RPointerArray<CNcdNodeIdentifier> iSeenStructureIds; |
|
289 TUid iClientUid; |
|
290 }; |
|
291 |
|
292 /** |
|
293 * Node new status. |
|
294 */ |
|
295 class CNcdNodeNewStatus : public CBase |
|
296 { |
|
297 public: |
|
298 static CNcdNodeNewStatus* NewL( const CNcdNodeIdentifier& aNodeIdentifier, |
|
299 TNcdNewStatus aNewStatus, CNcdNodeFactory::TNcdNodeType aNodeType ); |
|
300 static CNcdNodeNewStatus* NewLC( const CNcdNodeIdentifier& aNodeIdentifier, |
|
301 TNcdNewStatus aNewStatus, CNcdNodeFactory::TNcdNodeType iNodeType ); |
|
302 static CNcdNodeNewStatus* NewL( RReadStream& aReadStream ); |
|
303 static CNcdNodeNewStatus* NewLC( RReadStream& aReadStream ); |
|
304 ~CNcdNodeNewStatus(); |
|
305 public: |
|
306 const CNcdNodeIdentifier& Identifier() const; |
|
307 TNcdNewStatus NewStatus() const; |
|
308 void SetNewStatus( TNcdNewStatus aNewStatus ); |
|
309 CNcdNodeFactory::TNcdNodeType NodeType() const; |
|
310 void ExternalizeL( RWriteStream& aStream ); |
|
311 void InternalizeL( RReadStream& aStream ); |
|
312 |
|
313 private: |
|
314 CNcdNodeNewStatus( TNcdNewStatus aNewStatus, |
|
315 CNcdNodeFactory::TNcdNodeType aNodeType ); |
|
316 CNcdNodeNewStatus(); |
|
317 void ConstructL( const CNcdNodeIdentifier& aNodeIdentifier ); |
|
318 |
|
319 private: //Data |
|
320 CNcdNodeIdentifier* iNodeIdentifier; |
|
321 TNcdNewStatus iNewStatus; |
|
322 CNcdNodeFactory::TNcdNodeType iNodeType; |
|
323 }; |
|
324 |
|
325 CNcdGeneralManager& iGeneralManager; |
|
326 |
|
327 RPointerArray<CClientSeenInfo> iClientSeenInfos; |
|
328 |
|
329 // Storage manager. |
|
330 MNcdStorageManager& iStorageManager; |
|
331 |
|
332 // Node manager. |
|
333 CNcdNodeManager& iNodeManager; |
|
334 |
|
335 }; |
|
336 |
|
337 #endif // C_NCDNODESEENINFO_H |
|
338 |