videocollection/mpxmyvideoscollection/inc/vcxmyvideosvideocache.h
changeset 0 96612d01cf9f
child 1 6711b85517b7
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     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 
       
    20 #ifndef VCXMYVIDEOSVIDEOCACHE_H
       
    21 #define VCXMYVIDEOSVIDEOCACHE_H
       
    22 
       
    23 // INCLUDES
       
    24 #include "vcxmyvideosmdsdb.h"
       
    25 
       
    26 // FORWARD DECLARATIONS
       
    27 class CVcxMyVideosCollectionPlugin;
       
    28 class CMPXMedia;
       
    29 class CVcxMyVideosDownloadCache;
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // CLASS DECLARATION
       
    34 
       
    35 /**
       
    36 * Used for storing MDS items to RAM for fast access.
       
    37 *
       
    38 * @lib mpxmyvideoscollectionplugin.lib
       
    39 */
       
    40 NONSHARABLE_CLASS(CVcxMyVideosVideoCache) : public CBase
       
    41     {    
       
    42     public: // Constructors and destructor
       
    43 
       
    44         /**
       
    45         * Two-phased constructor
       
    46         * @param aMyVideosCollectionPlugin  Owner of this object.
       
    47         * @return                           Object constructed
       
    48         */
       
    49         static CVcxMyVideosVideoCache* NewL (
       
    50                 CVcxMyVideosCollectionPlugin& aMyVideosCollectionPlugin );
       
    51 
       
    52         /**
       
    53         * Destructor
       
    54         */
       
    55         virtual ~CVcxMyVideosVideoCache();
       
    56  
       
    57     private:
       
    58         /**
       
    59         * Constructor
       
    60         */
       
    61         CVcxMyVideosVideoCache( CVcxMyVideosCollectionPlugin& aMyVideosCollectionPlugin );
       
    62 
       
    63         /**
       
    64         * Symbian 2nd phase constructor.
       
    65         */
       
    66         void ConstructL ();
       
    67         
       
    68         /**
       
    69         * Finds correct position in iVideoList for the new video.
       
    70         *
       
    71         * @param aMedia        Video to be inserted to the list.
       
    72         * @param aSortingOrder Sorting order.
       
    73         * @return              Position in the cache.
       
    74         */
       
    75         TInt FindCorrectPositionL( CMPXMedia& aMedia, TVcxMyVideosSortingOrder aSortingOrder );
       
    76 
       
    77         /**
       
    78         * Compares aNewVideo and aVideoInList in sizes, creation dates
       
    79         * or titles.
       
    80         *
       
    81         * @param aNewVideo     Video to be added to the list.
       
    82         * @param aVideoInList  Video in cache video list which is currently compared against
       
    83         *                      aNewVideo.
       
    84         * @param aSortingOrder Defines which attributes are compared. Size, Creation Date and Title
       
    85         *                      are possible.
       
    86         * @return              -1 if aVideoInList has smaller value, 1 if greater and 0 if equal.
       
    87         */
       
    88         TInt CompareL( CMPXMedia& aNewVideo, CMPXMedia& aVideoInList,
       
    89                 TVcxMyVideosSortingOrder aSortingOrder );
       
    90 
       
    91         /**
       
    92         * Adds video to iVideoList to the correct position, according to sorting order.
       
    93         * MDS ID is used to identify the video.
       
    94         *
       
    95         * @param aVideo            Video to add.
       
    96         * @param aSortingOrder     Sorting order used.
       
    97         * @param aUpdateCategories If ETrue, then categories are updated.
       
    98         * @return                  KErrNone if added, KErrAlreadyExists if already exists and
       
    99         *                          was not added.
       
   100         */
       
   101         TInt AddToCorrectPlaceL( CMPXMedia& aVideo, TVcxMyVideosSortingOrder aSortingOrder,
       
   102                 TBool aUpdateCategories = ETrue );
       
   103 
       
   104         /**
       
   105         * Moves a video to correct place on iVideoList, according to sorting order.
       
   106         * aVideo should be a refrence to iVideoList item. After the call the referenced
       
   107         * item is gone and the reference shouldn't be used anymore.
       
   108         *
       
   109         * @param aVideo        Video to move.
       
   110         * @param aSortingOrder Sorting order used.
       
   111         */                
       
   112         void MoveToCorrectPlaceL( CMPXMedia& aVideo,
       
   113                 TVcxMyVideosSortingOrder aSortingOrder );
       
   114 
       
   115         /**
       
   116         * Removes video from iVideoList or iPartialVideoList.
       
   117         * MDS ID is used to identify the video.
       
   118         *
       
   119         * @param aVideo            Video to remove, MDS ID is read from here.
       
   120         * @param aUpdateCategories If ETrue, then categories are updated.
       
   121         * @return                  KErrNotFound if not found, KErrNone otherwise.
       
   122         */
       
   123         TInt RemoveL( CMPXMedia& aVideo, TBool aUpdateCategories = ETrue );
       
   124                 
       
   125         /**
       
   126         * Fetches sorting order from Cenrep.
       
   127         * @return Sorting order.
       
   128         */
       
   129         TVcxMyVideosSortingOrder SortingOrderL();
       
   130 
       
   131         /**
       
   132         * Called when Title in video cache has been modified. 
       
   133         * Updates sorting order and category attributes if necessarry.
       
   134         * NOTICE that aVideoInCache is not allowed to own the media object, since this
       
   135         * function may change the pointer value to point to a new object.
       
   136         *
       
   137         * @param aVideoInCache  Video in cache which Title has been modified. aVideoInCache
       
   138         *                       is not allowed to own the data.
       
   139         */
       
   140         void HandleVideoTitleModifiedL( CMPXMedia*& aVideoInCache );
       
   141        
       
   142         /**
       
   143         * Deletes iPartialList.
       
   144         */ 
       
   145         void DeletePartialList();
       
   146 
       
   147         /**
       
   148         * Adds video to cache (iVideoList or iPartialVideoList). Ownership moves.
       
   149         *
       
   150         * @param aVideo             Video to add.
       
   151         * @param aSortingOrder      Sorting order.
       
   152         * @return                   KErrNone if added, KErrAlreadyExists if already exists and
       
   153         *                           was not added.
       
   154         */
       
   155         TInt AddL( CMPXMedia* aVideo, TVcxMyVideosSortingOrder aSortingOrder );
       
   156         
       
   157         /**
       
   158         * Adds video to iPartialVideoList. Ownership moves.
       
   159         *
       
   160         * @param aVideo  Video to add.
       
   161         * @return        KErrNone if item was added, KErrAlreadyExists if video
       
   162         *                was already on the list and was not added.
       
   163         */       
       
   164         TInt AddToPartialListL( CMPXMedia* aVideo );
       
   165 
       
   166         /**
       
   167         * Finds the array position of aVideo in iPartialVideoList .
       
   168         *
       
   169         * @param aVideo  Video which position is searched.
       
   170         * @return        Position, KErrNotFound if item is not in iPartialVideoList.
       
   171         */
       
   172         TInt PosOnPartialVideoListL( CMPXMedia& aVideo );
       
   173 
       
   174         /**
       
   175         * Finds the array position of aVideo in iVideoList.
       
   176         *
       
   177         * @param aVideo  Video which position is searched.
       
   178         * @return        Position, KErrNotFound if item is not in iVideoList.
       
   179         */
       
   180         TInt PosOnVideoListL( CMPXMedia& aVideo );
       
   181                  
       
   182     public:            
       
   183         /**
       
   184         * Creates filtered video list from iVideoList. This is used for
       
   185         * showing video categories by origin.
       
   186         *
       
   187         * @param aOrigin Only videos with this origin are added to list,
       
   188         *                see values from TVcxMyVideosOrigin (in vcxmyvideosdefs.h).                
       
   189         * @return        New video list, containing videos from aOrigin.
       
   190         */
       
   191         CMPXMedia* CreateVideoListByOriginL( TUint8 aOrigin );
       
   192 
       
   193         /**
       
   194         * Appends items from aFromList to aToList if items origin is equal with
       
   195         * aOrigin. This is used when fetching other than All category from MDS.
       
   196         *
       
   197         * @param aToList    List to append
       
   198         * @param aFromList  List to append from.
       
   199         * @param aOrigin    Only items with this origin are copied.
       
   200         * @param aNewItemsStartIndex Start index in aFromList where from the copying is started.
       
   201         */
       
   202         void AppendToListL( CMPXMedia& aToList, CMPXMedia& aFromList,
       
   203                 TUint8 aOrigin, TInt aNewItemsStartIndex );
       
   204                 
       
   205         /**
       
   206         * Tries to find media with matching URI from the cached video list.
       
   207         *
       
   208         * @param aUri URI to compare
       
   209         * @return     Contains pointer to media if match found, NULL otherwise.
       
   210         *             Pointer ownership is not moved to the caller.
       
   211         */
       
   212         CMPXMedia* FindVideoByUriL( const TDesC& aUri );
       
   213 
       
   214         /**
       
   215         * Tries to find media with matching MdsId from iVideoList and iPartialVideoList.
       
   216         *
       
   217         * @param aMdsId ID to compare
       
   218         * @param aPos   If found from iVideoList, the position index is written here,
       
   219         *               KErrNotFound otherwise. If found from iPartialVideoList, then
       
   220         *               the value is still set to KErrNotFound.
       
   221         * @return       Contains pointer to media if match found, NULL otherwise.
       
   222         *               Pointer ownership is not moved to the caller.
       
   223         */
       
   224         CMPXMedia* FindVideoByMdsIdL( TUint32 aMdsId, TInt& aPos );
       
   225         
       
   226         /**
       
   227         * Tries to find media with matching download ID from iVideoList and iPartialVideoList.
       
   228         * If aDownloadId is 0, then NULL is returned.
       
   229         *
       
   230         * @param aDownloadId ID to compare
       
   231         * @return            Contains pointer to media if match found, NULL otherwise.
       
   232         *                    Pointer ownership is not moved to the caller.
       
   233         */
       
   234         CMPXMedia* FindVideoByDownloadIdL( TUint aDownloadId );
       
   235 
       
   236         /**
       
   237         * Gets medias from iVideoList and iPartialVideoList.
       
   238         *
       
   239         * @param aMdsIds  IDs of the items to fetch.
       
   240         * @return         Pointer to fetched items, KMPXMediaArrayContents
       
   241         *                 attribute contains the media items. Ownership
       
   242         *                 moves to caller.
       
   243         */
       
   244         CMPXMedia* GetVideosL( RArray<TUint32> aMdsIds );
       
   245 
       
   246         /**
       
   247         * Removes video from iVideoList (or from iPartialVideoList).
       
   248         *
       
   249         * @param aMdsId             MDS ID of the video to be removed.
       
   250         * @param aUpdateCategories  If ETrue, then categories are updated.
       
   251         * @return                   KErrNotFound if not found, KErrNone otherwise.
       
   252         */
       
   253         TInt RemoveL( TUint32 aMdsId, TBool aUpdateCategories = ETrue );
       
   254 
       
   255         /**
       
   256         * Removes videos from iVideoList.
       
   257         *
       
   258         * @param aUpdateCategories  If ETrue, then categories are updated.
       
   259         * @param aMdsIds            Array containing MDS IDs of the videos to be deleted.
       
   260         */
       
   261         void RemoveL( RArray<TUint32>& aMdsIds, TBool aUpdateCategories = ETrue );
       
   262 
       
   263         /**
       
   264         * Adds videos to cache (iVideoList or iPartialVideoList). After the function call aMdsIds
       
   265         * will contain only those items which were actually added to cache.
       
   266         *
       
   267         * @param aMdsIds                   Array containing MDS IDs of the videos to be added.
       
   268         * @param aListFetchingWasCanceled  This is set to EFalse if video list fetching from mds
       
   269         *                                  had to be cancelled. EFalse otherwise. 
       
   270         */
       
   271         void AddVideosFromMdsL( RArray<TUint32>& aMdsIds, TBool& aListFetchingWasCanceled );
       
   272 
       
   273         /**
       
   274         * Deletes old and creates new iVideoList. After the function call iVideoList exists,
       
   275         * but it might not contain any media items yet, only empty array.
       
   276         * Media items are added to the list asynchronoysly in
       
   277         * VcxMyVideosColletionPlugin::HandleCreateVideoListResp(), called by
       
   278         * VcxMyVideosMdsDb. When new items are added, they are synchronized with
       
   279         * Download Manager. Once iVideoList is complete, iVideoListIsPartial
       
   280         * is set to EFalse. During the video list fetching
       
   281         * VcxMyVideosMdsDb::iVideoListFetchingIsOngoing is ETrue.
       
   282         * If there is video list creation already ongoing
       
   283         * and the aSortingOrder is the same, nothing is done.
       
   284         * During the video list fetching iPartialVideoList items are moved to
       
   285         * iVideoList. When fetch is complete, iPartialVideoList is empty.
       
   286         *
       
   287         * @param aForce  If ETrue, then the list is always created from scratch, possible
       
   288         *                ongoing fetch is cancelled.
       
   289         */
       
   290         void CreateVideoListL( TBool aForce = EFalse );
       
   291     
       
   292         /**
       
   293         * Resets iVideoList (removes items, empty list is left) and cancels possible ongoing
       
   294         * asynchronous videolist fetching. iVideoListIsPartial is set to ETrue.
       
   295         * CVcxMyVideosCollection plugin variables are not touched. Caller is responsible to
       
   296         * either cancel the fetch from plugin, or restart fetch from mds in a way that
       
   297         * client gets its list. iVideoList media object remains pointing to same shared data.
       
   298         */
       
   299         void ResetVideoListL();
       
   300         
       
   301         /**
       
   302         * Updates video attributes in cache from aVideo. NOTE: iVideoList might be changed
       
   303         * if Size or Title values are modified and matching sorting order is currently on.
       
   304         * Pointers to iVideoList items should be refreshed after calling this with size and title
       
   305         * parameters.
       
   306         *
       
   307         * @param aVideo  Attributes are read from here and updated to cache if difference exists. 
       
   308         * @return        ETrue if any parameter was changed. 
       
   309         */
       
   310         TBool UpdateVideoL( CMPXMedia& aVideo );
       
   311 
       
   312         /**
       
   313         * iVideoList and its media array are deleted and recreated. New instances point to
       
   314         * different global heap position. Media objects stay the same and point to
       
   315         * same global heap.
       
   316         */
       
   317         void ReCreateVideoListL();
       
   318 
       
   319         /**
       
   320          * Replaces items in iVideoList with items from iPartialVideoList.
       
   321          * Called by iCollection when fetching videolist.
       
   322          */
       
   323         void CheckForPartialVideoListItemsL( TInt aNewItemsStartIndex );
       
   324         
       
   325     public:
       
   326     
       
   327         /**
       
   328         * Contains list of all videos in MDS. Used for caching MDS to RAM.
       
   329         */
       
   330         CMPXMedia* iVideoList;
       
   331 
       
   332         /**
       
   333         * Items fetched by MDS ID which don't (yet) have instance in iVideoList
       
   334         * are added here. When iVideoList instance is received from MDS, it is
       
   335         * replaced by item from iPartialVideoList and instance from iPartialVideoList
       
   336         * is removed.
       
   337         */
       
   338         RArray<CMPXMedia*> iPartialVideoList;
       
   339 
       
   340         /**
       
   341         * If ETrue then iVideoList does not contain all items from MDS.
       
   342         */
       
   343         TBool iVideoListIsPartial;
       
   344                                 
       
   345         /**
       
   346         * Sorting order which was used last time when list was queryed from MDS.
       
   347         */
       
   348         TVcxMyVideosSortingOrder iLastSortingOrder;
       
   349         
       
   350     private:
       
   351         
       
   352         /**
       
   353         * Circular buffer containing download id and media object pointer pairs.
       
   354         * Media object pointers are owned by iVideoList.
       
   355         * Used to speed up access to media objects which are used regularly during the
       
   356         * download.
       
   357         */
       
   358         CVcxMyVideosDownloadCache* iDownloadCache;
       
   359 
       
   360         /**
       
   361         * My Videos collection plugin, owner of this object.
       
   362         */
       
   363         CVcxMyVideosCollectionPlugin& iCollection;        
       
   364     };
       
   365 
       
   366 #endif   // VCXMYVIDEOSVIDEOCACHE_H
       
   367 
       
   368