videocollection/videocollectionwrapper/src/videocollectionclient.cpp
branchRCL_3
changeset 56 839377eedc2b
equal deleted inserted replaced
54:315810614048 56:839377eedc2b
       
     1 /*
       
     2 * Copyright (c) 2009 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:   VideoCollectionClient class implementation
       
    15 * 
       
    16 */
       
    17 
       
    18 // Version : %version: 41 %
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <qobject.h>
       
    22 #include <centralrepository.h>
       
    23 #include <mpxcollectionutility.h>
       
    24 #include <mpxcollectionpath.h>
       
    25 #include <mpxmediageneraldefs.h>
       
    26 #include <mpxmessagegeneraldefs.h>
       
    27 #include <mpxmessage2.h>
       
    28 #include <mpxcollectionmessagedefs.h>
       
    29 #include <mpxcollectionmessage.h>
       
    30 #include <mpxmessagecontainerdefs.h>
       
    31 #include <mpxmediacontainerdefs.h>
       
    32 #include <mpxcommandgeneraldefs.h>
       
    33 #include <mpxcollectioncommanddefs.h>
       
    34 #include <vcxmyvideosuids.h>
       
    35 
       
    36 #include "videodatasignalreceiver.h"
       
    37 #include "videocollectionclient.h"
       
    38 #include "videocollectionlistener.h"
       
    39 #include "videocollectiontrace.h"
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // VideoCollectionClient()
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 VideoCollectionClient::VideoCollectionClient() 
       
    46     : mCollectionUtility( 0 )
       
    47     , mCollectionOpenStatus( ECollectionNotOpen ) 
       
    48     , mCollectionListener( 0 )
       
    49     , mOpenCategoryAlbum( TMPXItemId::InvalidId() )
       
    50     , mCollectionPathLevel( VideoCollectionCommon::ELevelInvalid )
       
    51 {
       
    52 	FUNC_LOG;
       
    53 }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // initialize()
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 int VideoCollectionClient::initialize(VideoDataSignalReceiver *signalReceiver)
       
    60 {
       
    61 	FUNC_LOG;
       
    62     if(!signalReceiver)
       
    63     {
       
    64         return -1;
       
    65     }
       
    66     if(mCollectionUtility && mCollectionListener)
       
    67     {
       
    68         INFO("VideoCollectionClient::initialize() already initialized.");
       
    69         return 0;
       
    70     }
       
    71     if(!mCollectionListener)
       
    72     {
       
    73         mCollectionListener = new VideoCollectionListener(*this, *signalReceiver);
       
    74         if(!mCollectionListener)
       
    75         {
       
    76             return -1;
       
    77         }
       
    78     }
       
    79     if(!mCollectionUtility)
       
    80     {
       
    81         TRAPD( error, mCollectionUtility = MMPXCollectionUtility::NewL( mCollectionListener, KMcModeDefault ) );
       
    82         if(error)
       
    83         {
       
    84             ERROR(error, "VideoCollectionClient::initialize() construction of collection utility failed.");
       
    85             delete mCollectionListener;
       
    86             mCollectionListener = 0;
       
    87             return error;
       
    88         }
       
    89     }
       
    90     return 0;
       
    91 }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // ~VideoCollectionClient()
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 VideoCollectionClient::~VideoCollectionClient()
       
    98 {
       
    99 	FUNC_LOG;
       
   100     if (mCollectionUtility)
       
   101     {
       
   102         // closing deallocates collection utility pointer
       
   103         mCollectionUtility->Close();
       
   104     }
       
   105     delete mCollectionListener;
       
   106 }
       
   107 
       
   108 // ---------------------------------------------------------------------------
       
   109 // categoryIds
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 
       
   113 void VideoCollectionClient::getCategoryId(TMPXItemId &id)
       
   114 {
       
   115 	FUNC_LOG;
       
   116     id = mOpenCategoryAlbum;
       
   117 }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // getCollectionLevel
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 int VideoCollectionClient::getCollectionLevel()
       
   124 {
       
   125 	FUNC_LOG;
       
   126     return mCollectionPathLevel;
       
   127 }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // getOpenStatus
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 int VideoCollectionClient::getOpenStatus()
       
   134 {
       
   135 	FUNC_LOG;
       
   136 	return mCollectionOpenStatus;
       
   137 }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // setOpenStatus
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 void VideoCollectionClient::setOpenStatus(int status, bool startOpening)
       
   144 {
       
   145 	FUNC_LOG;
       
   146 	INFO_2("VideoCollectionClient::setOpenStatus() status: %d start opening %d", status, startOpening);
       
   147     mCollectionOpenStatus = status;
       
   148     if(mCollectionOpenStatus == ECollectionOpened && startOpening)
       
   149     {
       
   150         startOpenCurrentState();
       
   151     }
       
   152 }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // startOpenCollection
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 int VideoCollectionClient::startOpenCollection(int level)
       
   159 {
       
   160 	FUNC_LOG;
       
   161 	INFO_1("VideoCollectionClient::startOpenCollection() opening level: %d", level);
       
   162 	
       
   163     if(!mCollectionUtility)
       
   164     {
       
   165         return -1;
       
   166     }
       
   167     
       
   168 	if((mCollectionOpenStatus == ECollectionOpening) && (getCollectionLevel() == level))
       
   169     {
       
   170         // allready opening/opened
       
   171         return 0;
       
   172     }
       
   173     mCollectionOpenStatus = ECollectionNotOpen;
       
   174     TRAPD(error, startOpenCollectionL(level));
       
   175     return error;
       
   176 }
       
   177 
       
   178 // -----------------------------------------------------------------------------
       
   179 // startOpenCurrentState
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 int VideoCollectionClient::startOpenCurrentState()
       
   183 {
       
   184 	FUNC_LOG;
       
   185     int error = -1;
       
   186     if(mCollectionUtility && mCollectionOpenStatus == ECollectionOpened)
       
   187     {
       
   188         TRAP(error, mCollectionUtility->Collection().OpenL());
       
   189     }
       
   190     return error;
       
   191 }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // deleteFile
       
   195 // -----------------------------------------------------------------------------
       
   196 int VideoCollectionClient::deleteVideos(QList<TMPXItemId> *mediaIds)
       
   197 {  
       
   198 	FUNC_LOG;
       
   199     if(!mCollectionUtility || !mediaIds)
       
   200     {
       
   201         return -1;
       
   202     }    
       
   203     TRAPD(error, deleteVideosL(*mediaIds));
       
   204     return error;    
       
   205 }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // openItem
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 int VideoCollectionClient::openItem(const TMPXItemId &mediaId)
       
   212 {
       
   213 	FUNC_LOG;
       
   214     if(!mCollectionUtility)
       
   215     {
       
   216         return -1;
       
   217     } 
       
   218     
       
   219     TInt error;
       
   220     if (mediaId.iId2 == KVcxMvcMediaTypeVideo)
       
   221     {
       
   222     	TRAP(error, openVideoL(mediaId));
       
   223     }
       
   224     else
       
   225     {
       
   226     	TRAP(error, openCategoryL(mediaId));
       
   227     }
       
   228     return error;
       
   229 }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // back
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 int VideoCollectionClient::back()
       
   236 {
       
   237 	FUNC_LOG;
       
   238     if(!mCollectionUtility)
       
   239     {
       
   240         return -1;
       
   241     } 
       
   242     TRAPD(error, backL());
       
   243     return error;
       
   244 }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // fetchMpxMediaByMpxId
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 int VideoCollectionClient::fetchMpxMediaByMpxId(const TMPXItemId &mpxId)
       
   251 {
       
   252 	FUNC_LOG;
       
   253     if(!mCollectionUtility)
       
   254     {
       
   255         return -1;
       
   256     }
       
   257    
       
   258     TRAPD(error, fetchMpxMediaByMpxIdL(mpxId));
       
   259     return error;
       
   260 }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // getVideoDetails
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 int VideoCollectionClient::getVideoDetails(const TMPXItemId &mediaId)
       
   267 {
       
   268 	FUNC_LOG;
       
   269     if(!mCollectionUtility)
       
   270     {
       
   271         return -1;
       
   272     }
       
   273     
       
   274     TRAPD(error, getVideoDetailsL(mediaId));
       
   275    
       
   276     return error;
       
   277 }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // addNewAlbum
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 TMPXItemId VideoCollectionClient::addNewAlbum(const QString &title)
       
   284 {
       
   285 	FUNC_LOG;
       
   286 	
       
   287     TMPXItemId id = TMPXItemId::InvalidId();
       
   288     
       
   289     if (mCollectionUtility && title.length())
       
   290     {
       
   291         TRAPD(err, id = createAlbumL(title));
       
   292         if(err)
       
   293         {
       
   294             id = TMPXItemId::InvalidId();
       
   295         }
       
   296     }
       
   297 
       
   298     return id;
       
   299 }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // removeAlbums
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 int VideoCollectionClient::removeAlbums(const QList<TMPXItemId> &mediaIds)
       
   306 {
       
   307 	FUNC_LOG;
       
   308     int err(-1);
       
   309     
       
   310     if (mCollectionUtility && mediaIds.count())
       
   311     {
       
   312         TRAP(err, removeAlbumsL(mediaIds));
       
   313     }
       
   314 
       
   315     return err;
       
   316 }
       
   317 
       
   318 // -----------------------------------------------------------------------------
       
   319 // addItemsInAlbum
       
   320 // -----------------------------------------------------------------------------
       
   321 //
       
   322 int VideoCollectionClient::addItemsInAlbum(const TMPXItemId &albumId,
       
   323         const QList<TMPXItemId> &mediaIds)
       
   324 {
       
   325 	FUNC_LOG;
       
   326     int err(-1);
       
   327     
       
   328     if (mCollectionUtility && albumId != TMPXItemId::InvalidId() &&
       
   329         albumId.iId2 == KVcxMvcMediaTypeAlbum && mediaIds.count())
       
   330     {
       
   331         TRAP(err, addItemsInAlbumL(albumId, mediaIds));
       
   332     }
       
   333     
       
   334     return err;
       
   335 }
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // removeItemsFromAlbum
       
   339 // -----------------------------------------------------------------------------
       
   340 //
       
   341 int VideoCollectionClient::removeItemsFromAlbum(const TMPXItemId &albumId, 
       
   342         const QList<TMPXItemId> &mediaIds)
       
   343 {
       
   344 	FUNC_LOG;
       
   345     int err(-1);
       
   346         
       
   347     if (mCollectionUtility && albumId != TMPXItemId::InvalidId() &&
       
   348         albumId.iId2 == KVcxMvcMediaTypeAlbum && mediaIds.count())
       
   349     {
       
   350         TRAP(err, removeItemsFromAlbumL(albumId, mediaIds));
       
   351     }
       
   352     
       
   353     return err;
       
   354 }
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // renameItem
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 int VideoCollectionClient::renameItem(const TMPXItemId &itemId, 
       
   361         const QString &newTitle) 
       
   362 {
       
   363 	FUNC_LOG;
       
   364     int err(-1);
       
   365 
       
   366     if(mCollectionUtility && !newTitle.isEmpty() &&
       
   367        (itemId.iId2 == KVcxMvcMediaTypeAlbum ||
       
   368         itemId.iId2 == KVcxMvcMediaTypeVideo ) )
       
   369     {
       
   370         TRAP(err, renameL(itemId, newTitle));
       
   371     }
       
   372 
       
   373     return err;
       
   374 }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // startOpenCollectionL
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 void VideoCollectionClient::startOpenCollectionL(int level)
       
   381 {
       
   382 	FUNC_LOG;
       
   383 	INFO_1("VideoCollectionClient::startOpenCollectionL() level: %d", level);
       
   384 	
       
   385     if(!mCollectionUtility)
       
   386     {
       
   387         User::Leave(KErrGeneral);
       
   388     }
       
   389     CMPXCollectionPath* collectionPath = CMPXCollectionPath::NewL();
       
   390     CleanupStack::PushL( collectionPath );
       
   391   
       
   392     collectionPath->AppendL( KVcxUidMyVideosMpxCollection );
       
   393     if (level == VideoCollectionCommon::ELevelVideos)
       
   394     {
       
   395     	collectionPath->AppendL( KVcxMvcCategoryIdAll );
       
   396     	
       
   397     	mOpenCategoryAlbum = TMPXItemId(KVcxMvcCategoryIdAll, KVcxMvcMediaTypeCategory);
       
   398     	mCollectionPathLevel = VideoCollectionCommon::ELevelVideos;
       
   399     }
       
   400     else
       
   401     {
       
   402         mOpenCategoryAlbum = TMPXItemId::InvalidId();
       
   403     	mCollectionPathLevel = VideoCollectionCommon::ELevelCategory;
       
   404     }
       
   405     mCollectionUtility->Collection().OpenL( *collectionPath );
       
   406     CleanupStack::PopAndDestroy( collectionPath );  
       
   407 
       
   408     mCollectionOpenStatus = ECollectionOpening;
       
   409 }
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // deleteVideosL
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 void VideoCollectionClient::deleteVideosL(QList<TMPXItemId> &mediaIds)
       
   416 {
       
   417 	FUNC_LOG;
       
   418     if(!mCollectionUtility || mediaIds.count() == 0)
       
   419     {
       
   420         User::Leave(KErrGeneral);
       
   421     }
       
   422     CMPXMediaArray* mediasToDelete = CMPXMediaArray::NewL();
       
   423     CleanupStack::PushL( mediasToDelete );
       
   424     
       
   425     CMPXMedia* media = NULL;
       
   426 
       
   427     TMPXItemId currentId;
       
   428     foreach(currentId, mediaIds)
       
   429     {
       
   430         media = CMPXMedia::NewL();
       
   431         CleanupStack::PushL( media );
       
   432         media->SetTObjectValueL( KMPXMediaGeneralId, currentId );
       
   433         mediasToDelete->AppendL( *media );
       
   434         CleanupStack::PopAndDestroy( media );
       
   435     }
       
   436     
       
   437     CMPXCommand* cmd = CMPXMedia::NewL();
       
   438     CleanupStack::PushL( cmd );
       
   439 
       
   440     cmd->SetTObjectValueL( KMPXCommandGeneralId, KVcxCommandIdMyVideos );
       
   441     cmd->SetTObjectValueL( KVcxMediaMyVideosCommandId, KVcxCommandMyVideosDelete );    
       
   442     cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, EFalse );
       
   443     cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, 
       
   444                            TUid::Uid( KVcxUidMyVideosMpxCollection ) );
       
   445     cmd->SetCObjectValueL( KMPXMediaArrayContents, mediasToDelete );
       
   446 
       
   447     mCollectionUtility->Collection().CommandL( *cmd );
       
   448 
       
   449     CleanupStack::PopAndDestroy( cmd );  
       
   450     CleanupStack::PopAndDestroy( mediasToDelete ); 
       
   451 }
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // openVideoL
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 void VideoCollectionClient::openVideoL(const TMPXItemId &videoId)
       
   458 {
       
   459 	FUNC_LOG;
       
   460     if(!mCollectionUtility)
       
   461     {
       
   462         User::Leave(KErrGeneral);
       
   463     } 
       
   464     CMPXCollectionPath* path = CMPXCollectionPath::NewL();
       
   465     CleanupStack::PushL( path );
       
   466     path->AppendL( KVcxUidMyVideosMpxCollection );
       
   467     path->AppendL( KVcxMvcCategoryIdAll );
       
   468     path->AppendL( videoId );
       
   469     path->SelectL( videoId );
       
   470       
       
   471     mCollectionUtility->Collection().OpenL( *path );
       
   472     CleanupStack::PopAndDestroy( path );  
       
   473 }
       
   474 
       
   475 // -----------------------------------------------------------------------------
       
   476 // openCategoryL
       
   477 // -----------------------------------------------------------------------------
       
   478 //
       
   479 void VideoCollectionClient::openCategoryL(const TMPXItemId &id)
       
   480 {    
       
   481 	FUNC_LOG;
       
   482     if(!mCollectionUtility)
       
   483     {
       
   484         User::Leave(KErrGeneral);
       
   485     } 
       
   486     CMPXCollectionPath* collectionPath = CMPXCollectionPath::NewL();
       
   487     CleanupStack::PushL( collectionPath );
       
   488   
       
   489     collectionPath->AppendL( KVcxUidMyVideosMpxCollection );
       
   490     collectionPath->AppendL( id );
       
   491     mCollectionUtility->Collection().OpenL( *collectionPath );
       
   492     CleanupStack::PopAndDestroy( collectionPath );  
       
   493     
       
   494 	mOpenCategoryAlbum = id;
       
   495 	mCollectionPathLevel = VideoCollectionCommon::ELevelAlbum;
       
   496     mCollectionOpenStatus = ECollectionOpening;
       
   497 }
       
   498 
       
   499 // -----------------------------------------------------------------------------
       
   500 // backL
       
   501 // -----------------------------------------------------------------------------
       
   502 //
       
   503 void VideoCollectionClient::backL()
       
   504 {
       
   505 	FUNC_LOG;
       
   506     if(!mCollectionUtility)
       
   507     {
       
   508         User::Leave(KErrGeneral);
       
   509     }
       
   510     
       
   511     if (getCollectionLevel() > 2 )
       
   512     {
       
   513     	mCollectionUtility->Collection().BackL();
       
   514     	mCollectionOpenStatus = ECollectionOpening;
       
   515     	
       
   516     	mOpenCategoryAlbum = TMPXItemId::InvalidId();
       
   517 
       
   518     	mCollectionPathLevel = VideoCollectionCommon::ELevelCategory;
       
   519     }
       
   520 }
       
   521 
       
   522 // -----------------------------------------------------------------------------
       
   523 // getVideoDetailsL
       
   524 // -----------------------------------------------------------------------------
       
   525 //
       
   526 void VideoCollectionClient::getVideoDetailsL(const TMPXItemId &videoId)
       
   527 {
       
   528 	FUNC_LOG;
       
   529     if(!mCollectionUtility)
       
   530     {
       
   531         User::Leave(KErrGeneral);
       
   532     }
       
   533     CMPXCommand* cmd = CMPXCommand::NewL();
       
   534     CleanupStack::PushL( cmd );
       
   535     
       
   536     cmd->SetTObjectValueL( KMPXCommandGeneralId, KVcxCommandIdMyVideos );
       
   537     cmd->SetTObjectValueL( KVcxMediaMyVideosCommandId, KVcxCommandMyVideosGetMediaFullDetailsByMpxId );
       
   538     cmd->SetTObjectValueL( KMPXMediaGeneralId, videoId );
       
   539     mCollectionUtility->Collection().CommandL( *cmd );
       
   540     
       
   541     CleanupStack::PopAndDestroy( cmd );  
       
   542 }
       
   543 
       
   544 // -----------------------------------------------------------------------------
       
   545 // removeAlbumsL
       
   546 // -----------------------------------------------------------------------------
       
   547 //
       
   548 void VideoCollectionClient::removeAlbumsL(const QList<TMPXItemId> &mediaIds)
       
   549 {
       
   550 	FUNC_LOG;
       
   551     if(!mCollectionUtility)
       
   552     {
       
   553         User::Leave(KErrGeneral);
       
   554     }
       
   555 
       
   556     CMPXCommand* cmd = CMPXCommand::NewL();
       
   557     CleanupStack::PushL( cmd );
       
   558     cmd->SetTObjectValueL( KMPXCommandGeneralId, KVcxCommandIdMyVideos );
       
   559     cmd->SetTObjectValueL(KVcxMediaMyVideosCommandId, KVcxCommandMyVideosRemoveAlbums);
       
   560     cmd->SetTObjectValueL(KMPXCommandGeneralDoSync, EFalse);
       
   561     cmd->SetTObjectValueL(KMPXCommandGeneralCollectionId, TUid::Uid(KVcxUidMyVideosMpxCollection));
       
   562   
       
   563     CMPXMediaArray* array = CMPXMediaArray::NewL();
       
   564     CleanupStack::PushL( array );
       
   565     CMPXMedia* media = 0;
       
   566     int count = mediaIds.count();
       
   567     for (int i = 0; i < count; i++)
       
   568     {
       
   569         if(mediaIds.at(i).iId2 == KVcxMvcMediaTypeAlbum)
       
   570         {
       
   571             media = CMPXMedia::NewL();
       
   572             CleanupStack::PushL(media);
       
   573             media->SetTObjectValueL(KMPXMediaGeneralId, mediaIds.at(i));
       
   574             array->AppendL(*media);
       
   575             CleanupStack::PopAndDestroy(media);
       
   576         }
       
   577     }
       
   578     if(array->Count())
       
   579     {
       
   580         cmd->SetCObjectValueL(KMPXMediaArrayContents, array);
       
   581         mCollectionUtility->Collection().CommandL(*cmd);
       
   582     }
       
   583     else
       
   584     {
       
   585         // invalid data provided
       
   586         ERROR(KErrGeneral, "VideoCollectionClient::removeItemsFromAlbumL() no albums found");
       
   587         User::Leave(KErrGeneral);   
       
   588     }
       
   589 
       
   590     CleanupStack::PopAndDestroy( array );  
       
   591     CleanupStack::PopAndDestroy( cmd );  
       
   592 }
       
   593 
       
   594 // -----------------------------------------------------------------------------
       
   595 // createAlbumL
       
   596 // -----------------------------------------------------------------------------
       
   597 //
       
   598 TMPXItemId VideoCollectionClient::createAlbumL(const QString &title)
       
   599 {
       
   600 	FUNC_LOG;
       
   601     TMPXItemId albumId = TMPXItemId::InvalidId();
       
   602     
       
   603     CMPXCommand* cmd = CMPXCommand::NewL();
       
   604     CleanupStack::PushL( cmd );
       
   605 
       
   606     // 1. create album
       
   607     TPtrC titlePtrC(title.utf16());
       
   608     cmd->SetTObjectValueL(KMPXCommandGeneralId, KVcxCommandIdMyVideos);
       
   609     cmd->SetTObjectValueL(KVcxMediaMyVideosCommandId, KVcxCommandMyVideosAddAlbum);
       
   610     cmd->SetTextValueL(KMPXMediaGeneralTitle, titlePtrC);
       
   611     cmd->SetTObjectValueL(KMPXCommandGeneralDoSync, ETrue);
       
   612     cmd->SetTObjectValueL(KMPXCommandGeneralCollectionId, TUid::Uid(KVcxUidMyVideosMpxCollection));
       
   613     
       
   614     mCollectionUtility->Collection().CommandL(*cmd);
       
   615     
       
   616     // get album id
       
   617     if (cmd->IsSupported(KMPXMediaGeneralId))
       
   618     {
       
   619         albumId = cmd->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);        
       
   620     }
       
   621 
       
   622     // cleanup
       
   623     CleanupStack::PopAndDestroy(cmd);
       
   624 
       
   625     return albumId;
       
   626 }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // addItemsInAlbumL
       
   630 // -----------------------------------------------------------------------------
       
   631 //
       
   632 void VideoCollectionClient::addItemsInAlbumL(const TMPXItemId &albumId,
       
   633     const QList<TMPXItemId> &mediaIds)
       
   634 {
       
   635 	FUNC_LOG;
       
   636     CMPXCommand* cmd = CMPXCommand::NewL();
       
   637     CleanupStack::PushL(cmd);
       
   638     cmd->SetTObjectValueL(KMPXCommandGeneralId, KVcxCommandIdMyVideos);
       
   639     cmd->SetTObjectValueL(KVcxMediaMyVideosCommandId, KVcxCommandMyVideosAddToAlbum);
       
   640     cmd->SetTObjectValueL(KVcxMediaMyVideosUint32Value, albumId.iId1);
       
   641     cmd->SetTObjectValueL(KMPXCommandGeneralCollectionId, TUid::Uid(KVcxUidMyVideosMpxCollection));
       
   642 
       
   643     CMPXMediaArray* array = CMPXMediaArray::NewL();
       
   644     CleanupStack::PushL( array );
       
   645     CMPXMedia* video = 0;
       
   646     int count = mediaIds.count();
       
   647     for (int i = 0; i < count; i++)
       
   648     {
       
   649         if(mediaIds.at(i).iId2 == KVcxMvcMediaTypeVideo)
       
   650         {
       
   651             video = CMPXMedia::NewL();
       
   652             CleanupStack::PushL(video);
       
   653             video->SetTObjectValueL(KMPXMediaGeneralId, mediaIds.at(i));
       
   654             array->AppendL(*video);
       
   655             CleanupStack::PopAndDestroy(video);
       
   656         }
       
   657     }
       
   658     if(array->Count())
       
   659     {
       
   660         cmd->SetCObjectValueL(KMPXMediaArrayContents, array);
       
   661         mCollectionUtility->Collection().CommandL(*cmd);
       
   662     }
       
   663     else
       
   664     {
       
   665         // invalid data provided
       
   666         ERROR(KErrGeneral, "VideoCollectionClient::removeItemsFromAlbumL() no videos found");
       
   667         User::Leave(KErrGeneral);   
       
   668     }
       
   669 
       
   670     CleanupStack::PopAndDestroy(array);
       
   671     CleanupStack::PopAndDestroy(cmd);
       
   672 }
       
   673 
       
   674 // -----------------------------------------------------------------------------
       
   675 // removeItemsFromAlbumL
       
   676 // -----------------------------------------------------------------------------
       
   677 //
       
   678 void VideoCollectionClient::removeItemsFromAlbumL(const TMPXItemId &albumId, 
       
   679                                                 const QList<TMPXItemId> &mediaIds)
       
   680 {
       
   681 	FUNC_LOG;
       
   682     CMPXCommand* cmd = CMPXCommand::NewL();
       
   683     CleanupStack::PushL(cmd);
       
   684     cmd->SetTObjectValueL(KMPXCommandGeneralId, KVcxCommandIdMyVideos);
       
   685     cmd->SetTObjectValueL(KVcxMediaMyVideosCommandId, KVcxCommandMyVideosRemoveFromAlbum);
       
   686     cmd->SetTObjectValueL(KVcxMediaMyVideosUint32Value, albumId.iId1);
       
   687     cmd->SetTObjectValueL(KMPXCommandGeneralCollectionId, TUid::Uid(KVcxUidMyVideosMpxCollection));
       
   688 
       
   689     CMPXMediaArray* array = CMPXMediaArray::NewL();
       
   690     CleanupStack::PushL( array );
       
   691     CMPXMedia* video = 0;
       
   692     int count = mediaIds.count();
       
   693     for (int i = 0; i < count; i++)
       
   694     {
       
   695         if(mediaIds.at(i).iId2 == KVcxMvcMediaTypeVideo)
       
   696         {
       
   697             video = CMPXMedia::NewL();
       
   698             CleanupStack::PushL(video);
       
   699             video->SetTObjectValueL(KMPXMediaGeneralId, mediaIds.at(i));
       
   700             array->AppendL(*video);
       
   701             CleanupStack::PopAndDestroy(video);
       
   702         }
       
   703     }
       
   704     if(array->Count())
       
   705     {
       
   706         cmd->SetCObjectValueL(KMPXMediaArrayContents, array);
       
   707         mCollectionUtility->Collection().CommandL(*cmd);
       
   708     }
       
   709     else
       
   710     {
       
   711         // invalid data provided
       
   712         ERROR(KErrGeneral, "VideoCollectionClient::removeItemsFromAlbumL() no videos found");
       
   713         User::Leave(KErrGeneral);   
       
   714     }
       
   715     CleanupStack::PopAndDestroy(array);
       
   716     CleanupStack::PopAndDestroy(cmd);
       
   717 }
       
   718 
       
   719 // -----------------------------------------------------------------------------
       
   720 // renameL
       
   721 // -----------------------------------------------------------------------------
       
   722 //
       
   723 void VideoCollectionClient::renameL(const TMPXItemId &itemId, const QString newTitle)
       
   724 {
       
   725 	FUNC_LOG;
       
   726     CMPXMedia *media = CMPXMedia::NewL();
       
   727     CleanupStack::PushL(media);
       
   728     TPtrC titlePtrC(newTitle.utf16());
       
   729     media->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, itemId);
       
   730     media->SetTextValueL(KMPXMediaGeneralTitle, titlePtrC);
       
   731 
       
   732     CMPXCommand* cmd = CMPXMedia::NewL();
       
   733     CleanupStack::PushL( cmd );
       
   734     
       
   735     cmd->SetTObjectValueL(KMPXCommandGeneralId, KMPXCommandIdCollectionSet);
       
   736     cmd->SetCObjectValueL<CMPXMedia>(KMPXCommandColSetMedia, media);
       
   737     cmd->SetTObjectValueL(KMPXCommandGeneralDoSync, ETrue);
       
   738     cmd->SetTObjectValueL(KMPXCommandGeneralCollectionId,
       
   739                           TUid::Uid(KVcxUidMyVideosMpxCollection));
       
   740 
       
   741     mCollectionUtility->Collection().CommandL(*cmd);
       
   742 
       
   743     CleanupStack::PopAndDestroy(cmd);
       
   744     CleanupStack::PopAndDestroy(media);
       
   745 }
       
   746 
       
   747 // -----------------------------------------------------------------------------
       
   748 // fetchMpxMediaByMpxIdL
       
   749 // -----------------------------------------------------------------------------
       
   750 //
       
   751 void VideoCollectionClient::fetchMpxMediaByMpxIdL(const TMPXItemId &aMpxId)
       
   752 {
       
   753 	FUNC_LOG;
       
   754     if(!mCollectionUtility)
       
   755     {
       
   756         User::Leave(KErrGeneral);
       
   757     }
       
   758 
       
   759     CMPXCommand* cmd = CMPXCommand::NewL();
       
   760     CleanupStack::PushL( cmd );
       
   761     cmd->SetTObjectValueL( KMPXCommandGeneralId, KVcxCommandIdMyVideos );
       
   762     cmd->SetTObjectValueL( KVcxMediaMyVideosCommandId, KVcxCommandMyVideosGetMediasByMpxId );
       
   763     cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId,
       
   764                                    TUid::Uid( KVcxUidMyVideosMpxCollection ) );
       
   765    
       
   766     CMPXMediaArray* idMediaArray = CMPXMediaArray::NewL();
       
   767     CleanupStack::PushL( idMediaArray );
       
   768     CMPXMedia* media = CMPXMedia::NewL();
       
   769     CleanupStack::PushL( media );
       
   770     media->SetTObjectValueL( KMPXMessageMediaGeneralId, aMpxId );
       
   771     idMediaArray->AppendL( *media );
       
   772     cmd->SetCObjectValueL<CMPXMediaArray>( KMPXMediaArrayContents, idMediaArray );
       
   773     cmd->SetTObjectValueL( KMPXMediaArrayCount, idMediaArray->Count() );
       
   774     mCollectionUtility->Collection().CommandL( *cmd );
       
   775    
       
   776     CleanupStack::PopAndDestroy( media );  
       
   777     CleanupStack::PopAndDestroy( idMediaArray );  
       
   778     CleanupStack::PopAndDestroy( cmd );  
       
   779 }
       
   780 
       
   781 // End of file.