videocollection/mpxmyvideoscollection/inc/vcxmyvideosalbums.h
branchRCL_3
changeset 26 67eb01668b0e
child 45 baf439b22ddd
equal deleted inserted replaced
23:8f0df5c82986 26:67eb01668b0e
       
     1 /*
       
     2 * Copyright (c) 2007 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:   Albums related collection functionality.
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 #ifndef VCXMYVIDEOSALBUMS_H
       
    20 #define VCXMYVIDEOSALBUMS_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <mdequery.h>
       
    24 #include "vcxmyvideosmdsdb.h"
       
    25 #include "vcxmyvideosalbum.h"
       
    26 
       
    27 // FORWARD DECLARATIONS
       
    28 class CVcxMyVideosMdsDb;
       
    29 class CMPXMedia;
       
    30 class CVcxMyVideosCollectionPlugin;
       
    31 class CVcxMyVideosAlbum;
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 // CLASS DECLARATION
       
    36 
       
    37 /**
       
    38 * Albums related collection functionality.
       
    39 *
       
    40 * @lib mpxmyvideoscollectionplugin.lib
       
    41 */
       
    42 NONSHARABLE_CLASS(CVcxMyVideosAlbums) : public CBase, public MVcxMyVideosMdsAlbumsObserver
       
    43     {    
       
    44     public: // Constructors and destructor
       
    45         
       
    46         /**
       
    47         * Two-phased constructor
       
    48         * @return object constructed
       
    49         */
       
    50         static CVcxMyVideosAlbums* NewL( CVcxMyVideosCollectionPlugin& aCollectionPlugin );
       
    51 
       
    52         /**
       
    53         * Destructor
       
    54         */
       
    55         virtual ~CVcxMyVideosAlbums();
       
    56 
       
    57     public: // new methods
       
    58 
       
    59         /**
       
    60          * Returns album from iAlbums array by MDS ID. Ownership does not move.
       
    61          * 
       
    62          * @param aMdsId  MDS ID of the album to get.
       
    63          * @param aPos    If given, then the position index in iAlbums is written here.
       
    64          *                Ownership does not move.
       
    65          * @return        Pointer to album or NULL if not found.
       
    66          */
       
    67         CVcxMyVideosAlbum* Album( TUint32 aMdsId, TInt* aPos = NULL );
       
    68         
       
    69         /**
       
    70         * Creates iAlbumList if it doesn't exist yet. The list is populated
       
    71         * from async callback, HandleGetAlbumsResp().
       
    72         */
       
    73         void CreateAlbumListL();
       
    74                 
       
    75         /**
       
    76          * Fetches MDS IDs from MDS for all videos belonging to albums.
       
    77          * Ie fills iAlbums[*]->iVideoList[*].iMdsId (and iAlbums[*]->iVideoList[*].iRelationMdsId) fields.
       
    78          * Causes several async calls to MDS. 
       
    79          */
       
    80         void GetAlbumContentIdsL();
       
    81 
       
    82         /**
       
    83          * Adds videos to album.
       
    84          * 
       
    85          * @param aCmd  See attribute usage from vcxmyvideosdefs.h.
       
    86          */
       
    87         void AddVideosToAlbumL( CMPXMedia* aCmd );
       
    88 
       
    89         /**
       
    90          * Removes videos from album.
       
    91          * 
       
    92          * @param aCmd  See attribute usage from vcxmyvideosdefs.h.
       
    93          */
       
    94         void RemoveVideosFromAlbumL( CMPXMedia* aCmd );
       
    95 
       
    96         /**
       
    97          * Adds album to MDS and to this class. KMPXMediaGeneralTitle
       
    98          * should be set in aCmd. Upon completion, the KMPXMediaGeneralId
       
    99          * attribute contains the new MPX item ID. Leaves if could
       
   100          * not add to MDS.
       
   101          * 
       
   102          * @param aCmd  Command object received from collection client.
       
   103          */
       
   104         void AddAlbumL( CMPXMedia& aCmd );
       
   105         
       
   106         /**
       
   107          * Removes albums from MDS. MDS delete events will clean up albums
       
   108          * from this class.
       
   109          * 
       
   110          * @param aCmd  MPX command received from the client. Contains media array,
       
   111          *              which contains medias with album IDs set to KMPXMediaGeneralId.
       
   112          *              Ownership does not move. 
       
   113          */
       
   114         void RemoveAlbumsFromMdsOnlyL( CMPXMedia* aCmd );
       
   115         
       
   116         /**
       
   117          * Removes albums from this object (iAlbumList and iAlbums).
       
   118          * Called from MDS delete event. Album IDs which were removed are
       
   119          * also removed from aAlbumIds array. After the call aAlbumIds
       
   120          * will contain items which were not found and not deleted.
       
   121          * Sends appropriate events to collection client.
       
   122          * 
       
   123          * @param aAlbumIds  Album IDs to be removed.
       
   124          */
       
   125         void RemoveAlbumsL( RArray<TUint32>& aAlbumIds );
       
   126 
       
   127         /**
       
   128          * Removes album from this class (iAlbumList and iAlbums).
       
   129          * Adds event to message list but does not send it.
       
   130          * 
       
   131          * @param aMdsIds    Album MDS ID to be removed.
       
   132          * @param aCompress  If ETrue, then iAlbums is compressed,
       
   133          *                   otherwise not.
       
   134          * @return           ETrue if album was found and removed.
       
   135          */
       
   136         TBool RemoveAlbumL( TUint32 aMdsId, TBool aCompress );
       
   137         
       
   138         /**
       
   139          * Fetches albums from MDS. This is called from MDS insert event.
       
   140          * 
       
   141          * @param aAlbumIds  Album IDs to fetch.
       
   142          */
       
   143         void AddAlbumsFromMdsL( RArray<TUint32>& aAlbumIds );
       
   144 
       
   145         /**
       
   146          * Updates albums from MDS. This is called from MDS modify event.
       
   147          * 
       
   148          * @param aAlbumIds  Album IDs to update.
       
   149          */
       
   150         void UpdateAlbumsFromMdsL( RArray<TUint32>& aAlbumIds );
       
   151 
       
   152         /**
       
   153          * Updates album attributes, does not write to MDS. Adds
       
   154          * modify event to iCollection.iMessageList if necessarry.
       
   155          * 
       
   156          * @param aAlbum  New values are read from this.
       
   157          * @return        ETrue if album was modified, EFalse otherwise.
       
   158          */
       
   159         TBool UpdateAlbumL( const CMPXMedia& aAlbum );
       
   160 
       
   161         /**
       
   162          * Calculates and updates album media attributes.
       
   163          */
       
   164         void CalculateAttributesL();
       
   165         
       
   166         /**
       
   167          * Called when video's New Video flag changes. Calculates
       
   168          * album attributes for the affected albums. Adds events
       
   169          * to iCollection.iMessageList but does not send them.
       
   170          * 
       
   171          * @param aMdsId  MDS ID of the changed video.
       
   172          */
       
   173         void NewVideoFlagChangedL( TUint32 aMdsId );
       
   174 
       
   175         /**
       
   176          * Called when video's title changes. Calculates
       
   177          * album attributes for the affected albums. Adds events
       
   178          * to iCollection.iMessageList but does not send them.
       
   179          * 
       
   180          * @param aMdsId  MDS ID of the changed video.
       
   181          */
       
   182         void VideoTitleChangedL( TUint32 aMdsId );
       
   183         
       
   184         /**
       
   185          * Called when video is added or removed from cache. Adds changed
       
   186          * album indexes to iChangedAlbums.
       
   187          */
       
   188         void VideoAddedOrRemovedFromCacheL( CMPXMedia& video );
       
   189 
       
   190         /**
       
   191          * Goes through iChangedAlbums and updates album attributes and adds
       
   192          * changed events.
       
   193          */
       
   194         void UpdateChangedAlbumsL();
       
   195 
       
   196 protected:
       
   197         
       
   198         /**
       
   199          * From MVcxMyVideosMdsAlbumsObserver.
       
   200          * Process albums arriving from MDS. Response to VcxMyVideosMdsAlbums::GetAlbumsL.
       
   201          */
       
   202         void HandleGetAlbumsRespL( CMPXMedia* aAlbumList );
       
   203 
       
   204         /**
       
   205          * From MVcxMyVideosMdsAlbumsObserver.
       
   206          * Process content ids arriving from MDS. Response to VcxMyVideosMdsAlbums::GetAlbumContentIdsL.
       
   207          * 
       
   208          * @param aAlbumId      ID of the album.
       
   209          * @param aAlbumContent Array containing MDS object IDs. This array is the same which
       
   210          *                      was given in GetAlbumContentIdsL call.
       
   211          */
       
   212         void HandleGetAlbumContentIdsRespL( TUint32 aAlbumId,
       
   213                 RArray<TVcxMyVideosAlbumVideo>& aAlbumContentIds );
       
   214         
       
   215         /**
       
   216         * From MVcxMyVideosMdsAlbumsObserver.
       
   217         * Response to VcxMyVideosMdsAlbums::GetAlbumsL.
       
   218         * Sends insert events to collection clients.
       
   219         * 
       
   220         * @param aAlbumList  Pointer to same array which was given in GetAlbums call.
       
   221         */
       
   222         void HandleGetAlbumsResp( CMPXMedia* aAlbumList );
       
   223  
       
   224         /**
       
   225          * From MVcxMyVideosMdsAlbumsObserver.
       
   226          * Process content ids arriving from MDS. Response to CVcxMyVideosMdsAlbums::GetAlbumContentIdsL.
       
   227          * 
       
   228          * @param aAlbumId      ID of the album.
       
   229          * @param aAlbumContent Array containing MDS object IDs. This array is the same which
       
   230          *                      was given in GetAlbumContentL call.
       
   231          */
       
   232         void HandleGetAlbumContentIdsResp( TUint32 aAlbumId,
       
   233                 RArray<TVcxMyVideosAlbumVideo>& aAlbumContentIds );
       
   234 
       
   235         /**
       
   236          * From MVcxMyVideosMdsAlbumsObserver.
       
   237          * Process content videos arriving from MDS. Response to CVcxMyVideosMdsAlbums::GetAlbumContentVideosL.
       
   238          * 
       
   239          * @param aAlbumId    Album ID.
       
   240          * @param aVideoList  Media containing media array, array items are videos.
       
   241          * @param aError      Error code in case of failure.
       
   242          * @param aFirstNewItemIndex The index of the first new item.
       
   243          * @param aNewItemCount      How many new items since the last results.
       
   244          * @param aComplete          ETrue is query is complete, EFalse if there is new to come.
       
   245          */
       
   246         void HandleGetAlbumContentVideosResp( TUint32 /*aAlbumId*/, CMPXMedia& /*aVideoList*/,
       
   247                 TInt /*aError*/, TInt /*aFirstNewItemIndex*/, TInt /*aNewItemCount*/, TBool /*aComplete*/ ) {}
       
   248         
       
   249         /**
       
   250          * From MVcxMyVideosMdsAlbumsObserver.
       
   251          * Response to CVcxMyVideosMdsAlbums::AddVideosToAlbumL.
       
   252          * 
       
   253          * @param aCmd  Pointer to object which was given in AddVideosToAlbumL
       
   254          *              function call. Ownership does not move.
       
   255          * @param aItemArray  Item array which was tried to add to MDS.
       
   256          */        
       
   257         void HandleAddVideosToAlbumResp( CMPXMedia* aCmd,
       
   258                 RPointerArray<CMdEInstanceItem>& aItemArray );
       
   259 
       
   260         /**
       
   261          * From MVcxMyVideosMdsAlbumsObserver.
       
   262          * Response to CVcxMyVideosMdsAlbums::RemoveRelationsL.
       
   263          */
       
   264         void HandleRemoveRelationsResp( RArray<TUint32>& aRelationIds,
       
   265                 RArray<TUint32>& aResults );
       
   266 
       
   267         /**
       
   268          * From MVcxMyVideosMdsAlbumsObserver.
       
   269          * Response to CVcxMyVideosMdsAlbums::RemoveAlbumsL.
       
   270          */
       
   271         void HandleRemoveAlbumsResp( CMPXMedia* aCmd,
       
   272                 RArray<TUint32>& aResultIds );
       
   273 
       
   274         /**
       
   275          * From MVcxMyVideosMdsAlbumsObserver.
       
   276          * Relation events from MDS. This object is set as an observer at
       
   277          * iCollection.ConstructL, CVcxMyVideosMdsDb::NewL(..,aAlbumsObserver,..).
       
   278          */
       
   279         void HandleRelationEvent( TObserverNotificationType aType,
       
   280                 const RArray<TMdERelation>& aRelationArray );
       
   281         
       
   282     private:
       
   283 
       
   284         /**
       
   285          * Fills in iAlbums array. This is called when iAlbumList is ready.
       
   286          * Pointers to CVcxMyVideosVideoCache::iVideoList are not filled
       
   287          * in yet.
       
   288          */
       
   289         void CreateAlbumsL();
       
   290 
       
   291         /**
       
   292         * Constructor
       
   293         */
       
   294         CVcxMyVideosAlbums( CVcxMyVideosCollectionPlugin& aCollectionPlugin );
       
   295 
       
   296         /**
       
   297         * Symbian 2nd phase constructor.
       
   298         */
       
   299         void ConstructL();
       
   300 
       
   301         /**
       
   302          * Leaving version of HandleAddVideosToAlbumResp.
       
   303          */
       
   304         void DoHandleAddVideosToAlbumRespL( CMPXMedia* aCmd,
       
   305                 RPointerArray<CMdEInstanceItem>& aItemArray );
       
   306 
       
   307     public:
       
   308 
       
   309         /**
       
   310         * Album list. This is given to client when categorylevel items are requested. Own.
       
   311         * If this is destroyed/edited, then pointers have to be updated in iAlbums.
       
   312         */
       
   313         CMPXMedia* iAlbumList;
       
   314         
       
   315         /**
       
   316          * Array containing MDS IDs and pointers to album and video media items.
       
   317          * Album media items are in iAlbumList and video media items are in
       
   318          * CVcxMyVideosVideoCache::iVideoList.
       
   319          */
       
   320         RArray<CVcxMyVideosAlbum*> iAlbums;
       
   321     
       
   322         /**
       
   323          * ETrue when iAlbumList is ready and iAlbums contains video IDs.
       
   324          */
       
   325         TBool iAlbumListIsComplete;
       
   326         
       
   327     private:
       
   328         
       
   329         /**
       
   330          * Owner of this object.
       
   331          */
       
   332         CVcxMyVideosCollectionPlugin& iCollection;
       
   333         
       
   334         /**
       
   335          * Used in MDS operations to store MDS video (or relation) IDs.
       
   336          */
       
   337         RArray<TUint32> iMdsOpTargetIds;
       
   338         
       
   339         /**
       
   340          * Stores album video data during relation deletion. This is to
       
   341          * avoid second search when resp arrives.
       
   342          */
       
   343         RArray<TVcxMyVideosAlbumVideo> iRemoveFromAlbumVideos;
       
   344         
       
   345         /**
       
   346          * Used in MDS operations to store operation results. Is in sync with iMdsOpTargetIds. 
       
   347          */
       
   348         RArray<TInt> iMdsOpResults;
       
   349 
       
   350         /**
       
   351          * Used in MDS operations to store operation results. Is in sync with iMdsOpTargetIds. 
       
   352          */
       
   353         RArray<TUint32> iMdsOpResultsUint32;
       
   354         
       
   355         /**
       
   356          * When videos are removed or added from cache, the indexes of the
       
   357          * changed albums are stored here. Reason is to calculate new attributes
       
   358          * only once per changed album.
       
   359          */
       
   360         RArray<TInt> iChangedAlbums;
       
   361         
       
   362     };
       
   363 
       
   364 #endif   // VCXMYVIDEOSALBUMS_H
       
   365 
       
   366