|
1 /* |
|
2 * Copyright (c) 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 the License "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 cached MDS media items* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 #ifndef VCXMYVIDEOSVIDEOCACHE_H |
|
20 #define VCXMYVIDEOSVIDEOCACHE_H |
|
21 |
|
22 // INCLUDES |
|
23 #include "vcxmyvideosmdsdb.h" |
|
24 |
|
25 // FORWARD DECLARATIONS |
|
26 class CVcxMyVideosCollectionPlugin; |
|
27 class CMPXMedia; |
|
28 class CRepository; |
|
29 |
|
30 // CONSTANTS |
|
31 |
|
32 // CLASS DECLARATION |
|
33 |
|
34 /** |
|
35 * Contains information about video. |
|
36 * These are stored to CVcxMyVideosVideoListIndex::iVideoArray. |
|
37 */ |
|
38 NONSHARABLE_CLASS(TVcxMyVideosVideo) |
|
39 { |
|
40 public: |
|
41 |
|
42 /** |
|
43 * Constructor. |
|
44 */ |
|
45 TVcxMyVideosVideo(); |
|
46 |
|
47 /** |
|
48 * = operator. |
|
49 */ |
|
50 TVcxMyVideosVideo& operator=( const TVcxMyVideosVideo& aVideo ); |
|
51 public: |
|
52 |
|
53 /** |
|
54 * Set values. |
|
55 * |
|
56 * @param aMdsId MDS ID |
|
57 * @param aPos Position in CVcxMyVideosVideoCache::iVideoList |
|
58 * @param aVideo Pointer to CVcxMyVideosVideoCache::iVideoList item, |
|
59 * ownership does not move. |
|
60 */ |
|
61 void Set( TUint32 aMdsId, TInt aPos, CMPXMedia* aVideo ); |
|
62 |
|
63 public: |
|
64 TUint32 iMdsId; // Video object ID in MDS. |
|
65 CMPXMedia* iVideo; // Pointer to CVcxMyVideosVideoCache::iVideoList item |
|
66 TInt iPos; // Items position in CVcxMyVideosVideoCache::iVideoList |
|
67 }; |
|
68 |
|
69 /** |
|
70 * Used for keeping videos in MDS ID order for fast access. |
|
71 * (Indexes CVcxMyVideosVideoCache::iVideoList). |
|
72 * |
|
73 * @lib mpxmyvideoscollectionplugin.lib |
|
74 */ |
|
75 NONSHARABLE_CLASS(CVcxMyVideosVideoListIndex) : public CBase |
|
76 { |
|
77 public: // Constructors and destructor |
|
78 |
|
79 /** |
|
80 * Two-phased constructor |
|
81 * @return Object constructed |
|
82 */ |
|
83 static CVcxMyVideosVideoListIndex* NewL(); |
|
84 |
|
85 /** |
|
86 * Destructor |
|
87 */ |
|
88 virtual ~CVcxMyVideosVideoListIndex(); |
|
89 |
|
90 public: |
|
91 |
|
92 /** |
|
93 * Sets up iVideoArray from aVideoList. Sorting is also done. |
|
94 * |
|
95 * @param aVideoList Video list to use for constructing iVideoArray. |
|
96 */ |
|
97 void SetL( const CMPXMedia& aVideoList ); |
|
98 |
|
99 /** |
|
100 * Finds video by MDS ID from the index. Uses bisection method. |
|
101 * |
|
102 * @param aVideo The found video data is written here. |
|
103 * @return KErrNotFound if not found, index of the item in iVideoArray |
|
104 * otherwise. |
|
105 */ |
|
106 TInt Find( TUint32 aMdsId, TVcxMyVideosVideo& aVideo ); |
|
107 |
|
108 /** |
|
109 * Removes video from index. |
|
110 * |
|
111 * @param aMdsId ID if the item to be removed. |
|
112 * @param aCompress If ETrue, compresses the video array. |
|
113 * @return KErrNotFound if not found, index of the removed item otherwise. |
|
114 */ |
|
115 TInt Remove( TUint32 aMdsId, TBool aCompress = ETrue ); |
|
116 |
|
117 /** |
|
118 * Adds video to index. Keeps sorting order. |
|
119 * |
|
120 * @param aVideo Video to be added, ownership does not move. |
|
121 * @param aPos aVideo's position in CVcxMyVideosVideoCache::iVideoList. |
|
122 */ |
|
123 void AddL( CMPXMedia* aVideo, TInt aPos ); |
|
124 |
|
125 #ifdef _DEBUG |
|
126 /** |
|
127 * Returns reference to video array. |
|
128 */ |
|
129 const RArray<TVcxMyVideosVideo>& VideoArray(); |
|
130 #endif |
|
131 |
|
132 private: |
|
133 /** |
|
134 * Constructor |
|
135 */ |
|
136 CVcxMyVideosVideoListIndex(); |
|
137 |
|
138 /** |
|
139 * Symbian 2nd phase constructor. |
|
140 */ |
|
141 void ConstructL (); |
|
142 |
|
143 /** |
|
144 * Sorts iVideoArray by MDS ID. |
|
145 */ |
|
146 void Sort(); |
|
147 |
|
148 /** |
|
149 * Used for keeping RArray<TVcxMyVideosVideo> in integer order by |
|
150 * TVcxMyVideosVideo::iMdsId. |
|
151 * |
|
152 * @param aVideo1 Video to compare |
|
153 * @param aVideo2 Video to compare |
|
154 * @return -1 if aVideo1 is smaller than aVideo2, 1 if aVideo1 is larger than |
|
155 * aVideo2. |
|
156 */ |
|
157 static TInt CompareVideosByMdsId( const TVcxMyVideosVideo& aVideo1, |
|
158 const TVcxMyVideosVideo& aVideo2 ); |
|
159 |
|
160 private: |
|
161 |
|
162 /** |
|
163 * Video array which is kept in order by MDS ID. |
|
164 */ |
|
165 RArray<TVcxMyVideosVideo> iVideoArray; |
|
166 }; |
|
167 |
|
168 /** |
|
169 * Used for storing MDS items to RAM for fast access. |
|
170 * |
|
171 * @lib mpxmyvideoscollectionplugin.lib |
|
172 */ |
|
173 NONSHARABLE_CLASS(CVcxMyVideosVideoCache) : public CBase |
|
174 { |
|
175 public: // Constructors and destructor |
|
176 |
|
177 /** |
|
178 * Two-phased constructor |
|
179 * @param aMyVideosCollectionPlugin Owner of this object. |
|
180 * @return Object constructed |
|
181 */ |
|
182 static CVcxMyVideosVideoCache* NewL ( |
|
183 CVcxMyVideosCollectionPlugin& aMyVideosCollectionPlugin ); |
|
184 |
|
185 /** |
|
186 * Destructor |
|
187 */ |
|
188 virtual ~CVcxMyVideosVideoCache(); |
|
189 |
|
190 public: |
|
191 |
|
192 /** |
|
193 * @return ETrue if iVideoList is complete. (All items have |
|
194 * been fetched from MDS.) |
|
195 */ |
|
196 TBool IsComplete(); |
|
197 |
|
198 /** |
|
199 * Set to ETrue when all items have been fetched from MDS. |
|
200 */ |
|
201 void SetComplete( TBool aComplete ); |
|
202 |
|
203 private: |
|
204 /** |
|
205 * Constructor |
|
206 */ |
|
207 CVcxMyVideosVideoCache( CVcxMyVideosCollectionPlugin& aMyVideosCollectionPlugin ); |
|
208 |
|
209 /** |
|
210 * Symbian 2nd phase constructor. |
|
211 */ |
|
212 void ConstructL (); |
|
213 |
|
214 /** |
|
215 * Finds correct position in iVideoList for the new video. |
|
216 * |
|
217 * @param aMedia Video to be inserted to the list. |
|
218 * @param aSortingOrder Sorting order. |
|
219 * @return Position in the cache. |
|
220 */ |
|
221 TInt FindCorrectPositionL( CMPXMedia& aMedia, TVcxMyVideosSortingOrder aSortingOrder ); |
|
222 |
|
223 /** |
|
224 * Compares aNewVideo and aVideoInList in sizes, creation dates |
|
225 * or titles. |
|
226 * |
|
227 * @param aNewVideo Video to be added to the list. |
|
228 * @param aVideoInList Video in cache video list which is currently compared against |
|
229 * aNewVideo. |
|
230 * @param aSortingOrder Defines which attributes are compared. Size, Creation Date and Title |
|
231 * are possible. |
|
232 * @return -1 if aVideoInList has smaller value, 1 if greater and 0 if equal. |
|
233 */ |
|
234 TInt CompareL( CMPXMedia& aNewVideo, CMPXMedia& aVideoInList, |
|
235 TVcxMyVideosSortingOrder aSortingOrder ); |
|
236 |
|
237 /** |
|
238 * Adds video to iVideoList to the correct position, according to sorting order. |
|
239 * MDS ID is used to identify the video. |
|
240 * |
|
241 * @param aVideo Video to add. |
|
242 * @param aSortingOrder Sorting order used. |
|
243 * @param aUpdateCategories If ETrue, then categories are updated. |
|
244 * @return KErrNone if added, KErrAlreadyExists if already exists and |
|
245 * was not added. |
|
246 */ |
|
247 TInt AddToCorrectPlaceL( CMPXMedia& aVideo, TVcxMyVideosSortingOrder aSortingOrder, |
|
248 TBool aUpdateCategories = ETrue ); |
|
249 |
|
250 /** |
|
251 * Moves a video to correct place on iVideoList, according to sorting order. |
|
252 * aVideo should be a refrence to iVideoList item. After the call the referenced |
|
253 * item is gone and the reference shouldn't be used anymore. |
|
254 * |
|
255 * @param aVideo Video to move. |
|
256 * @param aSortingOrder Sorting order used. |
|
257 */ |
|
258 void MoveToCorrectPlaceL( CMPXMedia& aVideo, |
|
259 TVcxMyVideosSortingOrder aSortingOrder ); |
|
260 |
|
261 /** |
|
262 * Removes video from iVideoList or iPartialVideoList. |
|
263 * MDS ID is used to identify the video. |
|
264 * |
|
265 * @param aVideo Video to remove, MDS ID is read from here. |
|
266 * @param aUpdateCategories If ETrue, then categories are updated. |
|
267 * @return KErrNotFound if not found, KErrNone otherwise. |
|
268 */ |
|
269 TInt RemoveL( CMPXMedia& aVideo, TBool aUpdateCategories = ETrue ); |
|
270 |
|
271 /** |
|
272 * Fetches sorting order from Cenrep. |
|
273 * @return Sorting order. |
|
274 */ |
|
275 TVcxMyVideosSortingOrder SortingOrderL(); |
|
276 |
|
277 /** |
|
278 * Called when Title in video cache has been modified. |
|
279 * Updates sorting order and category attributes if necessarry. |
|
280 * NOTICE that aVideoInCache is not allowed to own the media object, since this |
|
281 * function may change the pointer value to point to a new object. |
|
282 * |
|
283 * @param aVideoInCache Video in cache which Title has been modified. aVideoInCache |
|
284 * is not allowed to own the data. |
|
285 */ |
|
286 void HandleVideoTitleModifiedL( CMPXMedia*& aVideoInCache ); |
|
287 |
|
288 /** |
|
289 * Deletes iPartialList. |
|
290 */ |
|
291 void DeletePartialList(); |
|
292 |
|
293 /** |
|
294 * Adds video to cache (iVideoList or iPartialVideoList). Ownership moves. |
|
295 * |
|
296 * @param aVideo Video to add. |
|
297 * @param aSortingOrder Sorting order. |
|
298 * @param aUpdateCategores If ETrue, then category and album attributes are updated. |
|
299 * @return KErrNone if added, KErrAlreadyExists if already exists and |
|
300 * was not added. |
|
301 */ |
|
302 TInt AddL( CMPXMedia* aVideo, TVcxMyVideosSortingOrder aSortingOrder, |
|
303 TBool aUpdateCategories = ETrue ); |
|
304 |
|
305 /** |
|
306 * Adds video to iPartialVideoList. Ownership moves. |
|
307 * |
|
308 * @param aVideo Video to add. |
|
309 * @return KErrNone if item was added, KErrAlreadyExists if video |
|
310 * was already on the list and was not added. |
|
311 */ |
|
312 TInt AddToPartialListL( CMPXMedia* aVideo ); |
|
313 |
|
314 /** |
|
315 * Finds the array position of aVideo in iPartialVideoList . |
|
316 * |
|
317 * @param aVideo Video which position is searched. |
|
318 * @return Position, KErrNotFound if item is not in iPartialVideoList. |
|
319 */ |
|
320 TInt PosOnPartialVideoListL( CMPXMedia& aVideo ); |
|
321 |
|
322 /** |
|
323 * Finds the array position of aVideo in iVideoList. |
|
324 * |
|
325 * @param aVideo Video which position is searched. |
|
326 * @return Position, KErrNotFound if item is not in iVideoList. |
|
327 */ |
|
328 TInt PosOnVideoListL( CMPXMedia& aVideo ); |
|
329 |
|
330 #ifdef _DEBUG |
|
331 /** |
|
332 * Checks that iVideoListIndex is correctly formed. |
|
333 */ |
|
334 void CheckVideoListIndexL(); |
|
335 #endif |
|
336 |
|
337 public: |
|
338 /** |
|
339 * Creates filtered video list from iVideoList. This is used for |
|
340 * showing video categories by origin. |
|
341 * |
|
342 * @param aOrigin Only videos with this origin are added to list, |
|
343 * see values from TVcxMyVideosOrigin (in vcxmyvideosdefs.h). |
|
344 * @return New video list, containing videos from aOrigin. |
|
345 */ |
|
346 CMPXMedia* CreateVideoListByOriginL( TUint8 aOrigin ); |
|
347 |
|
348 /** |
|
349 * Appends items from aFromList to aToList if items origin is equal with |
|
350 * aOrigin. This is used when fetching other than All category from MDS. |
|
351 * |
|
352 * @param aToList List to append |
|
353 * @param aFromList List to append from. |
|
354 * @param aOrigin Only items with this origin are copied. |
|
355 * @param aNewItemsStartIndex Start index in aFromList where from the copying is started. |
|
356 */ |
|
357 void AppendToListL( CMPXMedia& aToList, CMPXMedia& aFromList, |
|
358 TUint8 aOrigin, TInt aNewItemsStartIndex ); |
|
359 |
|
360 /** |
|
361 * Tries to find media with matching URI from the cached video list. |
|
362 * |
|
363 * @param aUri URI to compare |
|
364 * @return Contains pointer to media if match found, NULL otherwise. |
|
365 * Pointer ownership is not moved to the caller. |
|
366 */ |
|
367 CMPXMedia* FindVideoByUriL( const TDesC& aUri ); |
|
368 |
|
369 /** |
|
370 * Tries to find media with matching MdsId from iVideoList and iPartialVideoList. |
|
371 * |
|
372 * @param aMdsId ID to compare |
|
373 * @param aPos If found from iVideoList, the position index is written here, |
|
374 * KErrNotFound otherwise. If found from iPartialVideoList, then |
|
375 * the value is still set to KErrNotFound. |
|
376 * @return Contains pointer to media if match found, NULL otherwise. |
|
377 * Pointer ownership is not moved to the caller. |
|
378 */ |
|
379 CMPXMedia* FindVideoByMdsIdL( TUint32 aMdsId, TInt& aPos ); |
|
380 |
|
381 /** |
|
382 * Gets medias from iVideoList and iPartialVideoList. |
|
383 * |
|
384 * @param aMdsIds IDs of the items to fetch. |
|
385 * @return Pointer to fetched items, KMPXMediaArrayContents |
|
386 * attribute contains the media items. Ownership |
|
387 * moves to caller. |
|
388 */ |
|
389 CMPXMedia* GetVideosL( RArray<TUint32>& aMdsIds ); |
|
390 |
|
391 /** |
|
392 * Removes video from iVideoList (or from iPartialVideoList). |
|
393 * |
|
394 * @param aMdsId MDS ID of the video to be removed. |
|
395 * @param aUpdateCategories If ETrue, then categories are updated. |
|
396 * @return KErrNotFound if not found, KErrNone otherwise. |
|
397 */ |
|
398 TInt RemoveL( TUint32 aMdsId, TBool aUpdateCategories = ETrue ); |
|
399 |
|
400 /** |
|
401 * Removes videos from iVideoList. |
|
402 * |
|
403 * @param aUpdateCategories If ETrue, then categories are updated. |
|
404 * @param aMdsIds Array containing MDS IDs of the videos to be deleted. |
|
405 */ |
|
406 void RemoveL( RArray<TUint32>& aMdsIds, TBool aUpdateCategories = ETrue ); |
|
407 |
|
408 /** |
|
409 * Adds videos to cache (iVideoList or iPartialVideoList). After the function call aMdsIds |
|
410 * will contain only those items which were actually added to cache. |
|
411 * |
|
412 * @param aMdsIds Array containing MDS IDs of the videos to be added. |
|
413 * @param aListFetchingWasCanceled This is set to EFalse if video list fetching from mds |
|
414 * had to be cancelled. EFalse otherwise. |
|
415 * @param aNonVideoIds If argument given then Ids which were detected to not be |
|
416 * videos are written here. Caller owns the array, ownership |
|
417 * does not move. |
|
418 * @param aUpdateCategories If ETrue, then category/album attributes are updated. |
|
419 */ |
|
420 void AddVideosFromMdsL( RArray<TUint32>& aMdsIds, TBool& aListFetchingWasCanceled, |
|
421 RArray<TUint32>* aNonVideoIds = NULL, TBool aUpdateCategories = ETrue ); |
|
422 |
|
423 /** |
|
424 * Deletes old and creates new iVideoList. After the function call iVideoList exists, |
|
425 * but it might not contain any media items yet, only empty array. |
|
426 * Media items are added to the list asynchronoysly in |
|
427 * VcxMyVideosColletionPlugin::HandleCreateVideoListResp(), called by |
|
428 * VcxMyVideosMdsDb. Once iVideoList is complete, iVideoListIsPartial |
|
429 * is set to EFalse. During the video list fetching |
|
430 * VcxMyVideosMdsDb::iVideoListFetchingIsOngoing is ETrue. |
|
431 * If there is video list creation already ongoing |
|
432 * and the aSortingOrder is the same, nothing is done. |
|
433 * During the video list fetching iPartialVideoList items are moved to |
|
434 * iVideoList. When fetch is complete, iPartialVideoList is empty. |
|
435 * |
|
436 * @param aForce If ETrue, then the list is always created from scratch, possible |
|
437 * ongoing fetch is cancelled. |
|
438 */ |
|
439 void CreateVideoListL( TBool aForce = EFalse ); |
|
440 |
|
441 /** |
|
442 * Resets iVideoList (removes items, empty list is left) and cancels possible ongoing |
|
443 * asynchronous videolist fetching. iVideoListIsPartial is set to ETrue. |
|
444 * CVcxMyVideosCollection plugin variables are not touched. Caller is responsible to |
|
445 * either cancel the fetch from plugin, or restart fetch from mds in a way that |
|
446 * client gets its list. iVideoList media object remains pointing to same shared data. |
|
447 */ |
|
448 void ResetVideoListL(); |
|
449 |
|
450 /** |
|
451 * Updates video attributes in cache from aVideo. NOTE: iVideoList might be changed |
|
452 * if Size or Title values are modified and matching sorting order is currently on. |
|
453 * Pointers to iVideoList items should be refreshed after calling this with size and title |
|
454 * parameters. |
|
455 * |
|
456 * @param aVideo Attributes are read from here and updated to cache if difference exists. |
|
457 * @return ETrue if any parameter was changed. |
|
458 */ |
|
459 TBool UpdateVideoL( CMPXMedia& aVideo ); |
|
460 |
|
461 /** |
|
462 * iVideoList and its media array are deleted and recreated. New instances point to |
|
463 * different global heap position. Media objects stay the same and point to |
|
464 * same global heap. |
|
465 */ |
|
466 void ReCreateVideoListL(); |
|
467 |
|
468 /** |
|
469 * Replaces items in iVideoList with items from iPartialVideoList. |
|
470 * Called by iCollection when fetching videolist. |
|
471 */ |
|
472 void CheckForPartialVideoListItemsL( TInt aNewItemsStartIndex ); |
|
473 |
|
474 public: |
|
475 |
|
476 /** |
|
477 * Contains list of all videos in MDS. Used for caching MDS to RAM. |
|
478 */ |
|
479 CMPXMedia* iVideoList; |
|
480 |
|
481 /** |
|
482 * Items fetched by MDS ID which don't (yet) have instance in iVideoList |
|
483 * are added here. When iVideoList instance is received from MDS, it is |
|
484 * replaced by item from iPartialVideoList and instance from iPartialVideoList |
|
485 * is removed. |
|
486 */ |
|
487 RArray<CMPXMedia*> iPartialVideoList; |
|
488 |
|
489 /** |
|
490 * Sorting order which was used last time when list was queryed from MDS. |
|
491 */ |
|
492 TVcxMyVideosSortingOrder iLastSortingOrder; |
|
493 |
|
494 /** |
|
495 * Set to ETrue when doing videolist fetching. |
|
496 */ |
|
497 TBool iIsFetchingVideoList; |
|
498 |
|
499 private: |
|
500 |
|
501 /** |
|
502 * If ETrue then iVideoList contains all items from MDS. |
|
503 */ |
|
504 TBool iVideoListIsComplete; |
|
505 |
|
506 /** |
|
507 * My Videos collection plugin, owner of this object. |
|
508 */ |
|
509 CVcxMyVideosCollectionPlugin& iCollection; |
|
510 |
|
511 /** |
|
512 * Index which keeps TVcxMyVidesVideo items indexed in MDS ID |
|
513 * order for fast access. |
|
514 */ |
|
515 CVcxMyVideosVideoListIndex* iVideoListIndex; |
|
516 |
|
517 /** |
|
518 * Provides access to the sorting order key in cenrep. Own. |
|
519 */ |
|
520 CRepository* iCenRep; |
|
521 |
|
522 public: // Friend classes |
|
523 |
|
524 // used in testing |
|
525 TBool iLeaveOnReset; |
|
526 TBool iCancelListFetching; |
|
527 |
|
528 friend class CCollectionPluginTest; |
|
529 |
|
530 }; |
|
531 |
|
532 #endif // VCXMYVIDEOSVIDEOCACHE_H |
|
533 |
|
534 |