videocollection/mpxmyvideoscollection/tsrc/ut_collectionplugintest/inc/vcxmyvideosmdsalbums.h
branchRCL_3
changeset 70 375929f879c2
equal deleted inserted replaced
64:3eb824b18d67 70:375929f879c2
       
     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:   Provides albums support from MDS*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 #ifndef VCXMYVIDEOSMDSALBUMS_H
       
    20 #define VCXMYVIDEOSMDSALBUMS_H
       
    21 
       
    22 // INCLUDES
       
    23 #include <mdequery.h>
       
    24 #include <mpxmedia.h>
       
    25 #include "vcxmyvideosalbum.h"
       
    26 #include "vcxmyvideosmdsdb.h"
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 class CMPXMedia;
       
    30 
       
    31 // CONSTANTS
       
    32 
       
    33 // CLASS DECLARATION
       
    34 
       
    35 /**
       
    36 * Provides albums support, uses MDS.
       
    37 *
       
    38 * @lib mpxmyvideoscollectionplugin.lib
       
    39 */
       
    40 NONSHARABLE_CLASS(CVcxMyVideosMdsAlbums) :
       
    41         public CActive,
       
    42         public MMdEQueryObserver,
       
    43         public MMdERelationItemObserver
       
    44 #if 0
       
    45         ,
       
    46         public MMdERelationObserver
       
    47 #endif
       
    48     {    
       
    49     public: // Constructors and destructor
       
    50         
       
    51         friend class CVcxMyVideosMdsCmdQueue;
       
    52         friend class CVcxMyVideosMdsDb;
       
    53         
       
    54         enum TVcxAsyncOperation
       
    55             {
       
    56             EVcxNone,
       
    57             EVcxAddVideosToAlbum,
       
    58             EVcxRemoveRelations,
       
    59             EVcxRemoveAlbums
       
    60             };
       
    61         
       
    62         /**
       
    63         * Constructor.
       
    64         * 
       
    65         * @param aMdsDb    Owner of this object.
       
    66         * @param aObserver Object which is listening album related events. If NULL, then
       
    67         *                  no observer is set.
       
    68         */
       
    69         static CVcxMyVideosMdsAlbums* NewL( CVcxMyVideosMdsDb& aMdsDb,
       
    70                 MVcxMyVideosMdsAlbumsObserver* aObserver );
       
    71 
       
    72         /**
       
    73         * Destructor
       
    74         */
       
    75         virtual ~CVcxMyVideosMdsAlbums();
       
    76 
       
    77     public: // new methods
       
    78 
       
    79         /**
       
    80          * From CActive.
       
    81          * Cancels possible ongoing asynchronous request.
       
    82          * 
       
    83          * @param aType Defines what kind of request is cancelled.
       
    84          */
       
    85         void DoCancel( CVcxMyVideosMdsDb::TRequestType aType = CVcxMyVideosMdsDb::EAll );
       
    86 
       
    87         /**
       
    88          * Cancels queries.
       
    89          *
       
    90          * @param aType Defines what kind of request is cancelled.
       
    91          */
       
    92         void CancelQueries( CVcxMyVideosMdsDb::TRequestType aType = CVcxMyVideosMdsDb::EAll );
       
    93         
       
    94         /**
       
    95         * Gets My Videos albums from MDS asynchronously.
       
    96         * HandleGetAlbumsResp() callback function is called when ready.
       
    97         * Utilizes CVcxMyVideosMdsCmdQueue.
       
    98         *
       
    99         * @param aAlbumList  Album list is written here. Caller owns this, ownership
       
   100         *                    does not move.
       
   101         * @param aClient     Response call is done to this object.
       
   102         */
       
   103         void GetAlbumsL( CMPXMedia* aAlbumList, MVcxMyVideosMdsAlbumsObserver& aClient );
       
   104 
       
   105         /**
       
   106          * Gets album from MDS synchronously.
       
   107          * 
       
   108          * @param aId  MDS ID of the album to be fetched.
       
   109          * @returm     MPX media containing album data. Ownership
       
   110          *             moves to caller. NULL if not found.
       
   111          */
       
   112         CMPXMedia* GetAlbumL( TUint32 aId );
       
   113 
       
   114         /**
       
   115          * Gets album content IDs asynchronously.
       
   116          * HandleGetAlbumContentIdsResp() callback function is called when ready.
       
   117          * Utilizes CVcxMyVideosMdsCmdQueue.
       
   118          *
       
   119          * @param aAlbumId      Album ID.
       
   120          * @param aContentArray Item IDs which belog to aAlbum are written here. Caller must
       
   121          *                      keep aContentArray available until HandleGetAlbumContentIdsResp
       
   122          *                      has been called.
       
   123         * @param aClient        Response call is done to this object.
       
   124          */
       
   125         void GetAlbumContentIdsL( TUint32 aAlbumId, RArray<TVcxMyVideosAlbumVideo>& aContentArray,
       
   126                 MVcxMyVideosMdsAlbumsObserver& aClient );
       
   127         
       
   128         /**
       
   129          * Gets album content videos asynchronously.
       
   130          * HandleGetAlbumContentVideosResp() callback function is called when ready.
       
   131          * Utilizes CVcxMyVideosMdsCmdQueue.
       
   132          * 
       
   133          * @param aAlbumId    Album ID.
       
   134          * @param aVideoList  Media containing media array. Video media objects are added to media array.
       
   135          *                    Caller must keep aVideoList available until callback has been called.
       
   136          * @param aClient     Response call is done to this object.
       
   137          */
       
   138         void GetAlbumContentVideosL( TUint32 aAlbumId, CMPXMedia& aVideoList,
       
   139                 MVcxMyVideosMdsAlbumsObserver& aClient );
       
   140         
       
   141         /**
       
   142          * Adds videos to album asynchronously. HandleAddVideosToAlbumResp() callback function
       
   143          * is called when operation finishes.
       
   144          * Utilizes CVcxMyVideosMdsCmdQueue.
       
   145          *
       
   146          * @param aMpxCmd    Media containing command parameters: album ID and video ID list.
       
   147          *                   Results are also written to this object. See media structure and
       
   148          *                   used attributes from vcxmyvideosdef.c file,
       
   149          *                   KVcxCommandMyVideosAddToAlbum command. Ownership does not move.
       
   150          *                   
       
   151          * @param aClient    Response call is done to this object.
       
   152          */
       
   153         void AddVideosToAlbumL( CMPXMedia* aMpxCmd, MVcxMyVideosMdsAlbumsObserver& aClient );
       
   154         
       
   155         /**
       
   156          * Removes relations asynchronously.
       
   157          * Utilizes CVcxMyVideosMdsCmdQueue.
       
   158          * 
       
   159          * @param aRelationIds  Relations which are removed.
       
   160          * @param aResults      In sync with aRelationIds. Result codes, KErrNone if successful,
       
   161          *                      KErrGeneral if failed.
       
   162          * @param aClient       Response call is done to this object.
       
   163          */
       
   164         void RemoveRelationsL( RArray<TUint32>& aRelationIds,
       
   165                 RArray<TUint32>& aResults, MVcxMyVideosMdsAlbumsObserver& aClient );
       
   166  
       
   167         /**
       
   168          * Adds album to MDS. aAlbum should have KMPXMediaGeneralTitle attribute
       
   169          * set. The MDS item ID of the created album is written to KMPXMediaGeneralId
       
   170          * attribute.
       
   171          * 
       
   172          * @param aAlbum  Album which is added to database. 
       
   173          */
       
   174         void AddAlbumL( CMPXMedia& aAlbum );
       
   175         
       
   176         /**
       
   177          * Removes albums asynchronously. HandleRemoveAlbumsResp() callback function
       
   178          * is called when operation finishes.
       
   179          * Utilizes CVcxMyVideosMdsCmdQueue.
       
   180          *
       
   181          * @param aMpxCmd    Media containing command parameters: media array containing album IDs.
       
   182          *                   Results are also written to this object. See media structure and
       
   183          *                   used attributes from vcxmyvideosdef.c file,
       
   184          *                   KVcxCommandMyVideosRemoveAlbums command. Ownership does not move.
       
   185          *                   
       
   186          * @param aClient    Response call is done to this object.
       
   187          */        
       
   188         void RemoveAlbumsL( CMPXMedia* aMpxCmd, MVcxMyVideosMdsAlbumsObserver& aClient );
       
   189         
       
   190         /**
       
   191          * Sets album attributes.
       
   192          * 
       
   193          * @param aVideo  Values from aVideo are written to MDS.
       
   194          */
       
   195         void SetAlbumL( CMPXMedia& aVideo );
       
   196         
       
   197     protected:
       
   198         
       
   199         /**
       
   200         * From CActive.
       
   201         * Called when operation completes.
       
   202         */
       
   203         void RunL();
       
   204 
       
   205         /**
       
   206         * From CActive.
       
   207         * Actual implementation for cancelling.
       
   208         */
       
   209         void DoCancel();
       
   210         
       
   211     private:
       
   212 
       
   213         /**
       
   214         * Constructor
       
   215         */
       
   216         CVcxMyVideosMdsAlbums( CVcxMyVideosMdsDb& aMdsDb,
       
   217                 MVcxMyVideosMdsAlbumsObserver* aObserver );
       
   218 
       
   219         /**
       
   220         * Symbian 2nd phase constructor.
       
   221         */
       
   222         void ConstructL();
       
   223 
       
   224         /**
       
   225         * Copies album data from aObject to aAlbum.
       
   226         *
       
   227         * @param aObject  MDS object to copy data from.
       
   228         * @param aAlbum   MPX media to copy data to.
       
   229         */
       
   230         void Object2MediaL( CMdEObject& aObject, CMPXMedia& aAlbum );
       
   231         
       
   232         /**
       
   233          * Copies album data from aAlbum to aObject.
       
   234          * 
       
   235          * @param aAlbum MPX media to copy data from.
       
   236          * @param aObject MDS object to copy data to.
       
   237          */
       
   238         void Media2ObjectL( CMPXMedia& aAlbum, CMdEObject& aObject);
       
   239 
       
   240         /**
       
   241         * Gets various defintions from MDS and stores them to member variables.
       
   242         */
       
   243         void GetSchemaDefinitionsL();
       
   244 
       
   245         /**
       
   246         * Gets My Videos albums from MDS asynchronously.
       
   247         * HandleGetAlbumsResp() callback function is called when ready.
       
   248         *
       
   249         * @param aAlbumList  Album list is written here. Caller owns this, ownership
       
   250         *                    does not move.
       
   251         * @param aClient     Callback is done to this object.
       
   252         */
       
   253         void DoGetAlbumsL( CMPXMedia* aAlbumList, MVcxMyVideosMdsAlbumsObserver& aClient );
       
   254 
       
   255         /**
       
   256          * Gets album content IDs from MDS asynchronously.
       
   257          * HandleGetAlbumContentIdsResp() callback function is called when ready.
       
   258          *
       
   259          * @param aAlbumId      Album ID.
       
   260          * @param aContentArray Array containing MDS IDs which belong to aAlbum.
       
   261          *                      Caller is responsible to keep array available
       
   262          *                      until HandleGetAlbumContentResp has been called. 
       
   263         * @param aClient        Callback is done to this object.
       
   264          */
       
   265         void DoGetAlbumContentIdsL( TUint32 aAlbumId,
       
   266                 RArray<TVcxMyVideosAlbumVideo>& aContentArray,
       
   267                 MVcxMyVideosMdsAlbumsObserver& aClient );
       
   268 
       
   269         /**
       
   270          * Gets album content videos from MDS asynchronously.
       
   271          * HandleGetAlbumContentVideosResp() callback function is called when ready.
       
   272          * 
       
   273          * @param aAlbumId   Album ID.
       
   274          * @param aVideoList Media containing empty media array. Videos are added to array. Caller
       
   275          *                   must keep aVideoList available until HandleGetAlbumContentVideosResp
       
   276          *                   is called.
       
   277          * @param aClient    Callback is done to this object.
       
   278          */
       
   279         void DoGetAlbumContentVideosL( TUint32 aAlbumId, CMPXMedia& aVideoList,
       
   280                 MVcxMyVideosMdsAlbumsObserver& aClient );
       
   281 
       
   282         /**
       
   283          * Adds videos to album asynchronously. HandleAddVideosToAlbumResp() callback function
       
   284          * is called when operation finishes.
       
   285          * 
       
   286          * @param aMpxCmd    Media containing command parameters: album ID and video ID list.
       
   287          *                   Results are also written to this object. See media structure and
       
   288          *                   used attributes from vcxmyvideosdef.c file,
       
   289          *                   KVcxCommandMyVideosAddToAlbum command. Ownership does not move.
       
   290          * @param aClient    Response call is done to this object.
       
   291          */
       
   292         void DoAddVideosToAlbumL( CMPXMedia* aMpxCmd, MVcxMyVideosMdsAlbumsObserver& aClient );
       
   293         
       
   294         /**
       
   295          * Removes relations asynchronously.
       
   296          * 
       
   297          * @param aRelationIds  Relations which are removed.
       
   298          * @param aResults      In sync with aRelationIds. Result codes, KErrNone if successful,
       
   299          *                      KErrGeneral if failed.
       
   300          * @param aClient       Response call is done to this object.
       
   301          */
       
   302         void DoRemoveRelationsL( RArray<TUint32>& aRelationIds,
       
   303                 RArray<TUint32>& aResults, MVcxMyVideosMdsAlbumsObserver& aClient );
       
   304         
       
   305         /**
       
   306          * Removes albums asynchronously.
       
   307          * 
       
   308          * @param aMpxCmd  Media containing command parameters: array with albums IDs.
       
   309          * @param aClient  Response call is done to this object.
       
   310          */
       
   311         void DoRemoveAlbumsL( CMPXMedia* aMpxCmd,
       
   312                 MVcxMyVideosMdsAlbumsObserver& aClient );
       
   313 
       
   314         /**
       
   315         * Handles album query responses.
       
   316         * 
       
   317         * @param aQuery  Query instance.
       
   318         * @param aError  <code>KErrNone</code>, if the query was completed
       
   319         *                successfully. Otherwise one of the system-wide error 
       
   320         *                codes.
       
   321         */
       
   322         void HandleAlbumQueryCompletedL(CMdEQuery& aQuery, TInt aError);
       
   323 
       
   324         /**
       
   325         * Handles video query responses.
       
   326         * 
       
   327         * @param aQuery  Query instance.
       
   328         * @param aError  <code>KErrNone</code>, if the query was completed
       
   329         *                successfully. Otherwise one of the system-wide error 
       
   330         *                codes.
       
   331         * @param aFirstNewItemIndex Index of the first new item in the query.
       
   332         * @param aNewItemCount      How many new items were added.
       
   333         * @param aComplete          ETrue if query is complete, EFalse if new to come.
       
   334         */
       
   335         void HandleVideoQueryResultsL( CMdEQuery& aQuery, TInt aError,
       
   336                 TInt aFirstNewItemIndex, TInt aNewItemCount, TBool aComplete );
       
   337 
       
   338         /**
       
   339          * Handles relation query responses.
       
   340          * 
       
   341          * @param aQuery Query instance.
       
   342          * @param aError  <code>KErrNone</code>, if the query was completed
       
   343          *                successfully. Otherwise one of the system-wide error 
       
   344          *                codes.
       
   345          */
       
   346         void HandleRelationQueryCompletedL( CMdEQuery& aQuery, TInt aError );
       
   347 
       
   348         /**
       
   349          * Called from RunL when video adding to album completes.
       
   350          */
       
   351         void HandleAddVideosToAlbumCompletedL();
       
   352 
       
   353         /**
       
   354          * Called from RunL when relations remove completes.
       
   355          */
       
   356         void HandleRemoveRelationsCompletedL();
       
   357 
       
   358         /**
       
   359          * Called from RunL when albums remove completes.
       
   360          */
       
   361         void HandleRemoveAlbumsCompletedL();
       
   362 
       
   363         /**
       
   364          * Registers observing to MDS session.
       
   365          */
       
   366         void SetObservingL();
       
   367         
       
   368     protected:
       
   369 
       
   370         /**
       
   371         * From MMdEQueryObserver.
       
   372         * Called to notify the observer that new results have been received 
       
   373         * in the query.
       
   374         *
       
   375         * @param aQuery              Query instance that received new results.
       
   376         * @param aFirstNewItemIndex  Index of the first new item that was added
       
   377         *                            to the result item array.
       
   378         * @param aNewItemCount       Number of items added to the result item 
       
   379         *                            array.
       
   380         */
       
   381         void HandleQueryNewResults(CMdEQuery& aQuery,
       
   382                 TInt aFirstNewItemIndex,
       
   383                 TInt aNewItemCount);
       
   384 
       
   385         /**
       
   386         * From MMdEQueryObserver.
       
   387         * Called to notify the observer that the query has been completed,
       
   388         * or that an error has occured.
       
   389         *
       
   390         * @param aQuery  Query instance.
       
   391         * @param aError  <code>KErrNone</code>, if the query was completed
       
   392         *                successfully. Otherwise one of the system-wide error 
       
   393         *                codes.
       
   394         */
       
   395         void HandleQueryCompleted(CMdEQuery& aQuery, TInt aError);
       
   396 
       
   397         /**
       
   398          * From MMdERelationItemObserver
       
   399          */
       
   400         void HandleRelationItemNotification(CMdESession& aSession, 
       
   401                     TObserverNotificationType aType,
       
   402                     const RArray<TMdERelation>& aRelationArray);
       
   403 
       
   404         /**
       
   405          * From MMdERelationObserver
       
   406          */
       
   407         void HandleRelationNotification(CMdESession& aSession, 
       
   408                 TObserverNotificationType aType,
       
   409                 const RArray<TItemId>& aRelationIdArray);
       
   410         
       
   411     private:
       
   412         
       
   413         /**
       
   414          * Main class for Mds operations. Owns session to MDS.
       
   415          */
       
   416         CVcxMyVideosMdsDb& iMdsDb;
       
   417         
       
   418         /**
       
   419          * Observer of albums related events. May be NULL.
       
   420          * not own.
       
   421          */
       
   422         MVcxMyVideosMdsAlbumsObserver* iObserver;
       
   423         
       
   424         /**
       
   425         * Asynchronous album object fetching query is stored here. Own.
       
   426         */
       
   427         CMdEObjectQuery* iAlbumQuery;
       
   428 
       
   429         /**
       
   430         * Asynchronous video object fetching query is stored here. Own.
       
   431         */
       
   432         CMdEObjectQuery* iVideoQuery;
       
   433 
       
   434         /**
       
   435         * Asynchronous relation fetching query is stored here. Own.
       
   436         */
       
   437         CMdERelationQuery* iRelationQuery;
       
   438                 
       
   439         /**
       
   440         * The default namespace definition, not own.
       
   441         */
       
   442         CMdENamespaceDef* iNamespaceDef;
       
   443         
       
   444         /**
       
   445         * Album object definition, not own.
       
   446         */
       
   447         CMdEObjectDef* iAlbumObjectDef;
       
   448         
       
   449         /**
       
   450         * Album type property definition, not own.
       
   451         */
       
   452         CMdEPropertyDef* iTypePropertyDef;
       
   453         
       
   454         /**
       
   455          * "Contains" relation definition, not own.
       
   456          */
       
   457         CMdERelationDef* iContainsRelationDef;
       
   458         
       
   459         /**
       
   460         * Pointer to album list which is being fetched from MDS. Not own.
       
   461         */
       
   462         CMPXMedia* iAlbumList;
       
   463 
       
   464         /**
       
   465         * Pointer to video list which is being fetched from MDS. Not own.
       
   466         */
       
   467         CMPXMedia* iVideoList;
       
   468 
       
   469         /**
       
   470          * When doing some async operation to MDS, the album ID is stored here.
       
   471          */
       
   472         TUint32 iAlbumId;
       
   473         
       
   474         /**
       
   475          * When fetching album content from MDS, the pointer to content array is stored here.
       
   476          * Only MDS ID is filled to TVideo.
       
   477          * Not own.
       
   478          */
       
   479         RArray<TVcxMyVideosAlbumVideo>* iAlbumContent;
       
   480 
       
   481         /**
       
   482          * The pending async operation ID is stored here.
       
   483          */
       
   484         TVcxAsyncOperation iAsyncOperation;
       
   485 
       
   486         /**
       
   487          * Used for storing items during async mds operations.
       
   488          */
       
   489         RPointerArray<CMdEInstanceItem> iItemArray;
       
   490         
       
   491         /**
       
   492          * Used for storing result buffer during async mds operations.
       
   493          */
       
   494         RMdEDataBuffer iResultBuffer;
       
   495 
       
   496         /**
       
   497          * Used in async operations to store
       
   498          * pointer to result array (which is owned by the user). 
       
   499          */
       
   500         RArray<TInt>* iResultArray;
       
   501 
       
   502         /**
       
   503          * Used in async operations to store
       
   504          * pointer to result array (which is owned by the user). 
       
   505          */
       
   506         RArray<TUint32>* iResultArrayUint32;
       
   507         
       
   508         /**
       
   509          * Used in async oprations (EVcxAddVideosToAlbum and EVcxRemoveVideosFromAlbum) to store
       
   510          * pointer to item ID array (which is owned by the user). 
       
   511          */
       
   512         RArray<TUint32>* iIdArray;
       
   513                 
       
   514         /**
       
   515          * Used to store command parameters during async MDS operations. Not owned.
       
   516          */
       
   517         CMPXMedia* iMpxCmd;
       
   518         
       
   519         /**
       
   520          * Used to store pointer to client who initiated the async operation.
       
   521          */
       
   522         MVcxMyVideosMdsAlbumsObserver* iClient;
       
   523 
       
   524     };
       
   525 
       
   526 #endif   // VCXMYVIDEOSMDSALBUMS_H
       
   527 
       
   528