videofeeds/vcnsuiengine/src/vcxnsmpxcollectionclienthandler.cpp
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:    Class for handling mpx collection interactions*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #include <bldvariant.hrh>
       
    21 #include "IptvDebug.h"
       
    22 #include "CIptvUtil.h"
       
    23 #include <mpxcollectionutility.h>
       
    24 #include <mpxmediacontainerdefs.h>
       
    25 #include <mpxmediageneraldefs.h>
       
    26 #include <mpxmessagegeneraldefs.h>
       
    27 #include <mpxcollectionmessagedefs.h>
       
    28 #include <mpxcollectionpath.h>
       
    29 #include <mpxmessage2.h>
       
    30 #include <mpxcollectionmessage.h>
       
    31 #include <mpxlog.h>
       
    32 #include <mpxitemid.h>
       
    33 #include <mpxmessagecontainerdefs.h>
       
    34 #include <vcxmyvideosdefs.h>
       
    35 #include <vcxmyvideosuids.h>
       
    36 #include <mpxcommandgeneraldefs.h>
       
    37 #include <mpxcollectioncommanddefs.h>
       
    38 #include <HttpDownloadMgrCommon.h>
       
    39 
       
    40 #include "CIptvMyVideosGlobalFileId.h"
       
    41 #include "vcxnsmpxcollectionclienthandler.h"
       
    42 #include "vcxnscontentclienthandler.h"
       
    43 #include "vcxnsuiengine.h"
       
    44 #include "vcxnseventrouter.h"
       
    45 #include "vcxnscontentprovider.h"
       
    46 
       
    47 #include "vcxnsservice.h"
       
    48 #include "vcxnscontent.h"
       
    49 #include "vcxnscontentaccess.h"
       
    50 #include "vcxnsdownloadupdater.h"
       
    51 
       
    52 const TInt KMpxMediaId2 = 0;
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CVcxNsMpxCollectionClientHandler::CVcxNsMpxCollectionClientHandler( CVcxNsUiEngine& aUiEngine )
       
    59   : iUiEngine( aUiEngine ),
       
    60     iMarkAsWatchedId( KErrNotFound )
       
    61     {
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CVcxNsMpxCollectionClientHandler* CVcxNsMpxCollectionClientHandler::NewL( 
       
    69                                                            CVcxNsUiEngine& aUiEngine )
       
    70     {
       
    71     CVcxNsMpxCollectionClientHandler* self =
       
    72         new (ELeave) CVcxNsMpxCollectionClientHandler( aUiEngine );
       
    73     
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL();
       
    76     CleanupStack::Pop( self );
       
    77 
       
    78     return self;    
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 void CVcxNsMpxCollectionClientHandler::ConstructL()
       
    86     {
       
    87     iCollectionUtility = MMPXCollectionUtility::NewL( this, KMcModeDefault );
       
    88 
       
    89     CMPXCollectionPath* path = CMPXCollectionPath::NewL();
       
    90     CleanupStack::PushL( path );
       
    91     path->AppendL( KVcxUidMyVideosMpxCollection );
       
    92     iCollectionUtility->Collection().OpenL( *path );
       
    93     CleanupStack::PopAndDestroy( path );
       
    94     
       
    95     iDownloadUpdater = CVcxNsDownloadUpdater::NewL( this );
       
    96 
       
    97     iGetMediaDetailWait = new ( ELeave ) CActiveSchedulerWait;
       
    98     }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 CVcxNsMpxCollectionClientHandler::~CVcxNsMpxCollectionClientHandler()
       
   105     {
       
   106     iLastFetchedMedias.ResetAndDestroy();
       
   107 
       
   108     iResumeArray.Close();
       
   109     delete iDownloadUpdater;
       
   110     
       
   111     if( iCollectionUtility )
       
   112         {
       
   113         iCollectionUtility->Close();
       
   114         }
       
   115 
       
   116     iDownloadedContents.Reset();
       
   117 
       
   118     delete iGetMediaDetailWait;
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 // -----------------------------------------------------------------------------
       
   124 //  
       
   125 TInt CVcxNsMpxCollectionClientHandler::DownloadL( CVcxNsService& aService, 
       
   126                                                   CVcxNsContent& aContent )
       
   127     {
       
   128     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::DownloadL(s,c) IN");
       
   129     
       
   130     aContent.SetDlFailNotified( EFalse );
       
   131     aContent.SetUsernameL( aService.GetUserName() );
       
   132     aContent.SetPasswordL( aService.GetPassword() );
       
   133     
       
   134     if( aContent.PendingCommand() == CVcxNsContent::EVcxNsMpxContentCommandStartDownload ||
       
   135         aContent.PendingCommand() == CVcxNsContent::EVcxNsMpxContentCommandResumeDownload ||
       
   136         aContent.PendingCommand() == CVcxNsContent::EVcxNsMpxContentCommandWaitingForMpxItem )
       
   137         {
       
   138         // Download request is already made, but 
       
   139         // Collection hasn't processed it yet.
       
   140         return KErrAlreadyExists;
       
   141         }
       
   142 
       
   143     if( aContent.PendingCommand() == CVcxNsContent::EVcxNsMpxContentCommandCancelDownload )
       
   144         {
       
   145         // Download request is already made, and user has cancelled
       
   146         // it already, but Collection hasn't process the requests yet.
       
   147         // So reset just the pending cmd data.
       
   148         aContent.SetPendingCommand( CVcxNsContent::EVcxNsMpxContentCommandNone  );
       
   149 
       
   150         return KErrNone;
       
   151         }
       
   152 
       
   153     TInt ret( KErrGeneral );
       
   154 
       
   155     if( aContent.GetUrl( CVcxNsContent::EVcxContentTypeVideo ).Length() == 0 )
       
   156         {
       
   157         ret = KErrArgument;
       
   158         }
       
   159     else 
       
   160         {
       
   161         TUint32 transactionId( 0 );
       
   162 
       
   163         ret = DownloadL( aContent.GetUrl( CVcxNsContent::EVcxContentTypeVideo ),
       
   164                          aContent.GetName(),
       
   165                          aService.GetIap(),                          
       
   166                          aService.GetIsReadOnlyIap(),
       
   167                          aService.GetUserName(),
       
   168                          aService.GetPassword(),
       
   169                          transactionId );
       
   170         
       
   171         if ( ret == KErrNone )
       
   172             {
       
   173             // To the download list. Content from Mpx events
       
   174             // is resolved from the list.
       
   175             AppendToDownloadList( &aContent );
       
   176 
       
   177             aContent.SetPendingCommand( CVcxNsContent::EVcxNsMpxContentCommandStartDownload );
       
   178             aContent.SetCmdTransactionId( transactionId );
       
   179             
       
   180             iUiEngine.ContentProvider()->UpdateContent( &aContent );
       
   181             }
       
   182         else
       
   183             {
       
   184             aContent.SetPendingCommand( CVcxNsContent::EVcxNsMpxContentCommandNone );
       
   185             }
       
   186         }
       
   187     
       
   188     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::DownloadL(s,c) OUT");
       
   189 
       
   190     return ret;
       
   191     }
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 // -----------------------------------------------------------------------------
       
   196 //  
       
   197 TInt CVcxNsMpxCollectionClientHandler::DownloadL( const TDesC& aAddress,
       
   198                                                   const TDesC& aName,
       
   199                                                   TUint32 aIapId,
       
   200                                                   TBool aIsReadOnlyIap,
       
   201                                                   const TDesC& aUserName,
       
   202                                                   const TDesC& aPassword,
       
   203                                                   TUint32& aTransactionId )
       
   204     {
       
   205     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::DownloadL() start");
       
   206            
       
   207     CMPXCommand* cmd = CMPXCommand::NewL();
       
   208     CleanupStack::PushL( cmd ); // 1->
       
   209     
       
   210     cmd->SetTObjectValueL( KMPXCommandGeneralId, KVcxCommandIdMyVideos );
       
   211     cmd->SetTObjectValueL( KVcxMediaMyVideosCommandId, KVcxCommandMyVideosStartDownload );
       
   212     cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, EFalse /* = async */ );
       
   213     cmd->SetTObjectValueL( KVcxMediaMyVideosTransactionId, ++iLatestTransactionId );
       
   214     aTransactionId = iLatestTransactionId;
       
   215 
       
   216     TUid colId = TUid::Uid( KVcxUidMyVideosMpxCollection );
       
   217     cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, colId.iUid );
       
   218     
       
   219     CMPXMedia* startDownloadReq = CMPXMedia::NewL();
       
   220     CleanupStack::PushL( startDownloadReq ); // 2->
       
   221     
       
   222     TUint flags = ( aIsReadOnlyIap ? EVcxMyVideosServiceHasReadOnlyIap : 0 ) | 
       
   223                         EVcxMyVideosSilent;
       
   224     
       
   225     startDownloadReq->SetTObjectValueL( KMPXMediaGeneralFlags, flags );
       
   226     
       
   227     if( aIsReadOnlyIap )
       
   228         {
       
   229         startDownloadReq->SetTObjectValueL( KVcxMediaMyVideosIapId, aIapId );
       
   230         }
       
   231     else
       
   232         {
       
   233         // not a read only iap, set iap 0 so download utility 
       
   234         // can select iap via connectionutility
       
   235         startDownloadReq->SetTObjectValueL( KVcxMediaMyVideosIapId, 0 );
       
   236         }
       
   237 
       
   238     startDownloadReq->SetTextValueL( KVcxMediaMyVideosRemoteUrl, aAddress );
       
   239     startDownloadReq->SetTextValueL( KVcxMediaMyVideosUsername, aUserName );
       
   240     startDownloadReq->SetTextValueL( KVcxMediaMyVideosPassword, aPassword );
       
   241     startDownloadReq->SetTextValueL( KMPXMediaGeneralTitle, aName );
       
   242 
       
   243     cmd->SetCObjectValueL<CMPXMedia>( KMPXCommandColAddMedia, startDownloadReq );
       
   244     
       
   245     iCollectionUtility->Collection().CommandL( *cmd );
       
   246     
       
   247     CleanupStack::PopAndDestroy( startDownloadReq ); // <-2
       
   248     CleanupStack::PopAndDestroy( cmd );              // <-1
       
   249 
       
   250     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::DownloadL() exit");
       
   251     
       
   252     return KErrNone;
       
   253     }
       
   254 
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 // -----------------------------------------------------------------------------
       
   259 //  
       
   260 TInt CVcxNsMpxCollectionClientHandler::PauseDownloadL( CVcxNsContent& aContent )
       
   261     {
       
   262     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::PauseDownloadL IN");
       
   263     
       
   264     TInt ret( KErrNone );
       
   265     
       
   266     if( !aContent.GetMpxMedia() ||
       
   267              !aContent.GetMpxMedia()->ValueTObjectL<TUint32>( KVcxMediaMyVideosDownloadId ) )
       
   268         {
       
   269         IPTVLOGSTRING_LOW_LEVEL(
       
   270              "CVcxNsMpxCollectionClientHandler::PauseDownloadL OUT, bad argument");
       
   271         
       
   272         ret = KErrArgument;
       
   273         }
       
   274     else
       
   275         {
       
   276         CMPXMedia* media = CMPXMedia::NewL( *(aContent.GetMpxMedia()) );
       
   277         CleanupStack::PushL( media );
       
   278         
       
   279         CMPXCommand* cmd = CMPXCommand::NewL();
       
   280         CleanupStack::PushL( cmd );
       
   281         
       
   282         cmd->SetTObjectValueL( KMPXCommandGeneralId, KVcxCommandIdMyVideos );
       
   283         cmd->SetTObjectValueL( KVcxMediaMyVideosCommandId, KVcxCommandMyVideosPauseDownload );
       
   284         cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, EFalse );
       
   285         
       
   286         TUid colId = TUid::Uid( KVcxUidMyVideosMpxCollection );
       
   287         cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, colId.iUid );
       
   288 
       
   289         TUint32 downloadId = media->ValueTObjectL<TUint32>( KVcxMediaMyVideosDownloadId );            
       
   290         cmd->SetTObjectValueL( KVcxMediaMyVideosDownloadId, downloadId );        
       
   291         iCollectionUtility->Collection().CommandL( *cmd );
       
   292 
       
   293         CleanupStack::PopAndDestroy( cmd );
       
   294         CleanupStack::PopAndDestroy( media );
       
   295         }
       
   296     
       
   297     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::PauseDownloadL OUT");
       
   298 
       
   299     return ret;
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 // -----------------------------------------------------------------------------
       
   305 //  
       
   306 TInt CVcxNsMpxCollectionClientHandler::ResumeDownloadL( CVcxNsContent& aContent )
       
   307     {
       
   308     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::ResumeDownloadL IN");
       
   309     
       
   310     aContent.SetDlFailNotified( EFalse );
       
   311     
       
   312     TInt ret( KErrNone );
       
   313      
       
   314     if( !aContent.GetMpxMedia() || 
       
   315              !aContent.GetMpxMedia()->ValueTObjectL<TUint32>( KVcxMediaMyVideosDownloadId ) )
       
   316         {
       
   317         ret = KErrArgument;
       
   318         IPTVLOGSTRING_LOW_LEVEL(
       
   319             "CVcxNsMpxCollectionClientHandler::ResumeDownloadL OUT, bad argument");
       
   320         }
       
   321     else
       
   322         {
       
   323         CMPXMedia* media = CMPXMedia::NewL( *(aContent.GetMpxMedia()) );
       
   324         CleanupStack::PushL( media );
       
   325         
       
   326         CMPXCommand* cmd = CMPXCommand::NewL();
       
   327         CleanupStack::PushL( cmd );
       
   328         
       
   329         cmd->SetTObjectValueL( KMPXCommandGeneralId, KVcxCommandIdMyVideos );
       
   330         cmd->SetTObjectValueL( KVcxMediaMyVideosCommandId, KVcxCommandMyVideosStartDownload );
       
   331         cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, EFalse );
       
   332         
       
   333         TUid colId = TUid::Uid( KVcxUidMyVideosMpxCollection );
       
   334         cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, colId.iUid );
       
   335         cmd->SetTObjectValueL( KVcxMediaMyVideosTransactionId, ++iLatestTransactionId );
       
   336 
       
   337         IPTVLOGSTRING2_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:: TR ID = %d", iLatestTransactionId);
       
   338 
       
   339         TUint32 transactionId = iLatestTransactionId;
       
   340 
       
   341         media->SetTObjectValueL( KVcxMediaMyVideosIapId, 0 );
       
   342         media->SetTextValueL( KVcxMediaMyVideosUsername, aContent.GetUsername() );
       
   343         media->SetTextValueL( KVcxMediaMyVideosPassword, aContent.GetPassword() );
       
   344         
       
   345         cmd->SetCObjectValueL<CMPXMedia>( KMPXCommandColAddMedia, media );
       
   346         iCollectionUtility->Collection().CommandL( *cmd );
       
   347 
       
   348         CleanupStack::PopAndDestroy( cmd );
       
   349         CleanupStack::PopAndDestroy( media );
       
   350         
       
   351         aContent.SetPendingCommand( CVcxNsContent::EVcxNsMpxContentCommandResumeDownload );
       
   352         aContent.SetCmdTransactionId( transactionId );
       
   353         
       
   354         AppendToDownloadList( &aContent );
       
   355         iUiEngine.ContentProvider()->UpdateContent( &aContent );
       
   356         
       
   357         TUint32 mpxId = aContent.GetMpxId();
       
   358 		if ( iResumeArray.Find( mpxId ) == KErrNotFound )
       
   359 		    { 
       
   360             iResumeArray.AppendL( mpxId );
       
   361 			}
       
   362         
       
   363         IPTVLOGSTRING_LOW_LEVEL(
       
   364             "CVcxNsMpxCollectionClientHandler::ResumeDownloadL OUT, cmd OK.");
       
   365         }
       
   366     
       
   367     return ret;
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 // -----------------------------------------------------------------------------
       
   373 //  
       
   374 TInt CVcxNsMpxCollectionClientHandler::CancelDownloadL( CVcxNsContent& aContent )
       
   375     {
       
   376     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::CancelDownloadL IN");
       
   377 
       
   378     aContent.SetDlFailNotified( EFalse );
       
   379     
       
   380     TInt ret( KErrNone );
       
   381     
       
   382     if( !aContent.GetMpxMedia(CVcxNsContent::EVcxContentTypeVideo) )
       
   383         {
       
   384         // Even though cancel cannot be called now, it must be called later
       
   385         // So mark the content to be pending the cancel.
       
   386         aContent.SetPendingCommand ( CVcxNsContent::EVcxNsMpxContentCommandCancelDownload );
       
   387         
       
   388         // Incremet cmd id, so the cmd is not reset when this 
       
   389         // content's previous cmd's complete msg arrives.
       
   390         aContent.SetCmdTransactionId ( ++iLatestTransactionId );
       
   391         
       
   392         // Redraw the fake state to user.
       
   393         iUiEngine.ContentProvider()->UpdateContent( &aContent );
       
   394         }
       
   395     else
       
   396         {
       
   397         CMPXCommand* cmd = CMPXCommand::NewL();
       
   398         CleanupStack::PushL( cmd );
       
   399         
       
   400         cmd->SetTObjectValueL( KMPXCommandGeneralId, KVcxCommandIdMyVideos );
       
   401         
       
   402         cmd->SetTObjectValueL( KVcxMediaMyVideosCommandId, 
       
   403                                KVcxCommandMyVideosCancelDownload );
       
   404         
       
   405         cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, EFalse /* = async */ );
       
   406         TUid colId = TUid::Uid( KVcxUidMyVideosMpxCollection );
       
   407         cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, colId.iUid );
       
   408         
       
   409         CMPXMedia* media = aContent.GetMpxMedia( CVcxNsContent::EVcxContentTypeVideo );
       
   410         
       
   411         if ( media )
       
   412             {
       
   413             cmd->SetCObjectValueL<CMPXMedia>( KMPXCommandColAddMedia, media );
       
   414             cmd->SetTObjectValueL( KVcxMediaMyVideosTransactionId, ++iLatestTransactionId );
       
   415             
       
   416             iCollectionUtility->Collection().CommandL( *cmd );
       
   417             }
       
   418         
       
   419         CleanupStack::PopAndDestroy( cmd );
       
   420         
       
   421         aContent.SetPendingCommand ( CVcxNsContent::EVcxNsMpxContentCommandCancelDownload );
       
   422         aContent.SetCmdTransactionId ( iLatestTransactionId );
       
   423         }
       
   424 
       
   425     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::CancelDownloadL OUT");
       
   426     
       
   427     return ret;
       
   428     }
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 // -----------------------------------------------------------------------------
       
   433 //  
       
   434 void CVcxNsMpxCollectionClientHandler::LoadMpxMediaObjectsL()
       
   435     {
       
   436     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::LoadMpxMediaObjectsL IN");
       
   437 
       
   438     RArray<TUint32> ids;
       
   439     CleanupClosePushL( ids );
       
   440 
       
   441     for( TInt i = 0; i < iDownloadedContents.Count(); i++ )
       
   442         {
       
   443         if( (iDownloadedContents[i])->GetMpxId() )
       
   444             {
       
   445             ids.Append( (iDownloadedContents[i])->GetMpxId() );
       
   446             }
       
   447         }
       
   448 
       
   449     GetMediaByMpxIdReqL( ids );
       
   450     CleanupStack::PopAndDestroy( &ids );
       
   451     
       
   452     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::LoadMpxMediaObjectsL OUT");
       
   453     }
       
   454 
       
   455 
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 // -----------------------------------------------------------------------------
       
   459 //  
       
   460 void CVcxNsMpxCollectionClientHandler::LoadMpxMediaObjectL( TUint32 aMpxId )
       
   461     {
       
   462     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::LoadMpxMediaObjectL IN");
       
   463 
       
   464     RArray<TUint32> id;
       
   465     CleanupClosePushL( id );
       
   466     id.Append( aMpxId );
       
   467     GetMediaByMpxIdReqL( id );
       
   468     CleanupStack::PopAndDestroy( &id );
       
   469     
       
   470     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::LoadMpxMediaObjectL OUT");
       
   471     }
       
   472 
       
   473 // -----------------------------------------------------------------------------
       
   474 //
       
   475 // -----------------------------------------------------------------------------
       
   476 //  
       
   477 void CVcxNsMpxCollectionClientHandler::HandleCollectionMediaL( const CMPXMedia& aMedia, 
       
   478                              TInt aError )
       
   479     {
       
   480     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::HandleCollectionMediaL");
       
   481     
       
   482     if ( aError == KErrNone )
       
   483         {
       
   484         SearchAndAddMpxMediaL( & const_cast<CMPXMedia&>( aMedia ) );
       
   485 
       
   486         if ( aMedia.IsSupported( KMPXMediaGeneralId ) )
       
   487             {
       
   488             iLastFetchedMedias.ResetAndDestroy();
       
   489             iLastFetchedMedias.Append( CMPXMedia::NewL( aMedia ) );
       
   490             }
       
   491         }
       
   492     
       
   493     if ( iGetMediaDetailWait->IsStarted() )
       
   494         {
       
   495         iGetMediaDetailWait->AsyncStop();
       
   496         }
       
   497     }
       
   498 
       
   499 // -----------------------------------------------------------------------------
       
   500 // CVcxNsMpxCollectionClientHandler::HandleCollectionMessage
       
   501 // -----------------------------------------------------------------------------
       
   502 //
       
   503 void CVcxNsMpxCollectionClientHandler::HandleCollectionMessage(CMPXMessage* aMessage, 
       
   504                                                                TInt aError )
       
   505     {
       
   506     TRAPD( err, ExplodeCollectionMessagesL( aMessage, aError ) );
       
   507     
       
   508     if ( err != KErrNone )
       
   509         {
       
   510         IPTVLOGSTRING2_LOW_LEVEL(
       
   511 "CVcxNsMpxCollectionClientHandler::ExplodeCollectionMessagesL() leaved with error code %d", err);
       
   512         }
       
   513     }
       
   514     
       
   515 // -----------------------------------------------------------------------------
       
   516 // CVcxNsMpxCollectionClientHandler::ExplodeCollectionMessagesL
       
   517 // -----------------------------------------------------------------------------
       
   518 //
       
   519 void CVcxNsMpxCollectionClientHandler::ExplodeCollectionMessagesL(CMPXMessage* aMessage, 
       
   520                                                                   TInt aError )
       
   521     {
       
   522     if ( !aMessage )
       
   523         {
       
   524         return;
       
   525         }
       
   526     
       
   527     TInt cmdId = aMessage->ValueTObjectL<TMPXMessageId>( KMPXMessageGeneralId );
       
   528     TInt myVideosCmd = -1; 
       
   529 
       
   530     if ( cmdId == KVcxCommandIdMyVideos )
       
   531         {
       
   532         myVideosCmd = aMessage->ValueTObjectL<TInt>( KVcxMediaMyVideosCommandId );
       
   533         }
       
   534     
       
   535     if ( myVideosCmd != KVcxMessageMyVideosMessageArray )
       
   536         {
       
   537         HandleSingleCollectionMessageL( aMessage, aError );
       
   538         }
       
   539     else
       
   540         {
       
   541         if ( aMessage->IsSupported( KMPXMessageArrayContents ) )
       
   542             {
       
   543             const CMPXMessageArray* messageArray =
       
   544                 aMessage->Value<CMPXMessageArray>(KMPXMessageArrayContents);
       
   545 
       
   546             if ( messageArray->Count() > 0 )
       
   547                 {
       
   548                 IPTVLOGSTRING_LOW_LEVEL(
       
   549                    "CVcxNsMpxCollectionClientHandler:: ----------------------.");
       
   550                 IPTVLOGSTRING_LOW_LEVEL(
       
   551                    "CVcxNsMpxCollectionClientHandler:: MESSAGE ARRAY ARRIVED |");
       
   552                 IPTVLOGSTRING_LOW_LEVEL(
       
   553                    "CVcxNsMpxCollectionClientHandler:: ----------------------'");
       
   554                 }
       
   555                 
       
   556             for( TInt i = 0; i < messageArray->Count(); i++ )
       
   557                 {
       
   558                 HandleSingleCollectionMessageL( messageArray->AtL( i ), aError );
       
   559                 }    
       
   560             }
       
   561         }
       
   562     }
       
   563 
       
   564 // -----------------------------------------------------------------------------
       
   565 //
       
   566 // -----------------------------------------------------------------------------
       
   567 //  
       
   568 void CVcxNsMpxCollectionClientHandler::HandleSingleCollectionMessageL( CMPXMessage* aMsg, 
       
   569                                                                        TInt aErr )
       
   570     {
       
   571     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::HandleSingleCollectionMessageL IN");
       
   572 
       
   573 #ifdef _DEBUG
       
   574     
       
   575     TMPXMessageId msgId = 0;    
       
   576     if ( aMsg->IsSupported( KMPXMessageGeneralId ) )
       
   577         {
       
   578         msgId = aMsg->ValueTObjectL<TMPXMessageId>(KMPXMessageGeneralId);
       
   579         }
       
   580     
       
   581     TUid colId;
       
   582     colId.iUid = 0;
       
   583     if ( aMsg->IsSupported( KMPXMessageCollectionId ) )
       
   584         {
       
   585         colId = aMsg->ValueTObjectL<TUid>(KMPXMessageCollectionId);
       
   586         }
       
   587             
       
   588     TMPXChangeEventType type = static_cast<TMPXChangeEventType>( -1 );
       
   589     if ( aMsg->IsSupported( KMPXMessageChangeEventType ) )
       
   590         { 
       
   591         type = aMsg->ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType);
       
   592         }
       
   593         
       
   594     TMPXItemId itemId(0,0);
       
   595     if ( aMsg->IsSupported( KMPXMessageMediaGeneralId ) )
       
   596         {
       
   597         itemId = aMsg->ValueTObjectL<TMPXItemId>( KMPXMessageMediaGeneralId );
       
   598         }
       
   599     else
       
   600         {
       
   601         IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## HandleSingleCollectionMessageL() : KMPXMessageMediaGeneralId not supported!");
       
   602         }
       
   603         
       
   604     TInt cmdId = -1;
       
   605     if ( aMsg->IsSupported( KVcxMediaMyVideosCommandId ) )
       
   606         {
       
   607         cmdId = aMsg->ValueTObjectL<TInt>( KVcxMediaMyVideosCommandId );
       
   608         }
       
   609                 
       
   610     IPTVLOGSTRING2_HIGH_LEVEL( 
       
   611           "UI Engine ## HandleSingleCollectionMessageL() : msgId = %d", msgId );
       
   612     IPTVLOGSTRING2_HIGH_LEVEL( 
       
   613           "UI Engine ## HandleSingleCollectionMessageL() : colId = %x", colId );
       
   614     
       
   615     switch ( type )
       
   616         {
       
   617         case EMPXItemDeleted:
       
   618             IPTVLOGSTRING_HIGH_LEVEL(
       
   619                   "UI Engine ## HandleSingleCollectionMessageL() : type = EMPXItemDeleted" );
       
   620             break;
       
   621         case EMPXItemInserted:
       
   622             IPTVLOGSTRING_HIGH_LEVEL(
       
   623                 "UI Engine ## HandleSingleCollectionMessageL() : type = EMPXItemInserted" );
       
   624             break;
       
   625         case EMPXItemModified:
       
   626             IPTVLOGSTRING_HIGH_LEVEL(
       
   627                 "UI Engine ## HandleSingleCollectionMessageL() : type = EMPXItemModified" );
       
   628             break;
       
   629         }
       
   630         
       
   631     IPTVLOGSTRING3_HIGH_LEVEL( 
       
   632           "UI Engine ## HandleSingleCollectionMessageL() : KMPXMessageMediaGeneralId = %d,%d", itemId.iId1, itemId.iId2 );
       
   633     IPTVLOGSTRING2_HIGH_LEVEL( 
       
   634           "UI Engine ## HandleSingleCollectionMessageL() : aErr = %d", aErr );
       
   635 
       
   636     switch ( cmdId )
       
   637         {
       
   638         case KVcxMessageMyVideosGetMediasByMpxIdResp:
       
   639             IPTVLOGSTRING_HIGH_LEVEL(
       
   640                   "UI Engine ## HandleSingleCollectionMessageL() : cmd Id = KVcxMessageMyVideosGetMediasByMpxIdResp" );
       
   641             
       
   642             if ( aMsg->IsSupported( KMPXMediaArrayContents ) )
       
   643                 {
       
   644                 const CMPXMessageArray* videoArray =
       
   645                     aMsg->Value<CMPXMessageArray>(KMPXMediaArrayContents);
       
   646                 
       
   647                 TInt count = videoArray->Count();
       
   648                 CMPXMedia* video;
       
   649                 TMPXItemId mpxId;
       
   650                 for ( TInt i = 0; i < count; i++ )
       
   651                     {
       
   652                     video = videoArray->AtL( i );
       
   653                     mpxId = video->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
   654                     IPTVLOGSTRING3_HIGH_LEVEL("UI Engine ## HandleSingleCollectionMessageL() :     contains video MPXID: %d,%d", mpxId.iId1, mpxId.iId2 );
       
   655                     }
       
   656                 }
       
   657             else
       
   658                 {
       
   659                 IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## HandleSingleCollectionMessageL() : EMPTY KVcxMessageMyVideosGetMediasByMpxIdResp, SHOULD NOT HAPPEN");
       
   660                 }
       
   661             
       
   662             break;
       
   663 
       
   664         case KVcxMessageMyVideosItemsAppended:
       
   665             IPTVLOGSTRING_HIGH_LEVEL(
       
   666                   "UI Engine ## HandleSingleCollectionMessageL() : cmd Id = KVcxMessageMyVideosItemsAppended" );
       
   667             break;
       
   668 
       
   669         case KVcxMessageMyVideosListComplete:
       
   670             IPTVLOGSTRING_HIGH_LEVEL(
       
   671                   "UI Engine ## HandleSingleCollectionMessageL() : cmd Id = KVcxMessageMyVideosListComplete" );
       
   672             break;
       
   673 
       
   674         case KVcxMessageMyVideosMoveOrCopyStarted:
       
   675             IPTVLOGSTRING_HIGH_LEVEL(
       
   676                   "UI Engine ## HandleSingleCollectionMessageL() : cmd Id = KVcxMessageMyVideosMoveOrCopyStarted" );
       
   677             break;
       
   678 
       
   679         case KVcxMessageMyVideosDeleteStarted:
       
   680             IPTVLOGSTRING_HIGH_LEVEL(
       
   681                   "UI Engine ## HandleSingleCollectionMessageL() : cmd Id = KVcxMessageMyVideosDeleteStarted" );
       
   682             break;
       
   683 
       
   684         case KVcxMessageMyVideosMoveResp:
       
   685             IPTVLOGSTRING_HIGH_LEVEL(
       
   686                   "UI Engine ## HandleSingleCollectionMessageL() : cmd Id = KVcxMessageMyVideosMoveResp" );
       
   687             break;
       
   688 
       
   689         case KVcxMessageMyVideosCopyResp:
       
   690             IPTVLOGSTRING_HIGH_LEVEL(
       
   691                   "UI Engine ## HandleSingleCollectionMessageL() : cmd Id = KVcxMessageMyVideosCopyResp" );
       
   692             break;
       
   693 
       
   694         case KVcxMessageMyVideosDeleteResp:
       
   695             IPTVLOGSTRING_HIGH_LEVEL(
       
   696                   "UI Engine ## HandleSingleCollectionMessageL() : cmd Id = KVcxMessageMyVideosDeleteResp" );
       
   697             break;
       
   698 
       
   699         }
       
   700         
       
   701 
       
   702 #endif // _DEBUG
       
   703     
       
   704     DoHandleSingleCollectionMessageL( aMsg, aErr );
       
   705     
       
   706     IPTVLOGSTRING_LOW_LEVEL(
       
   707           "CVcxNsMpxCollectionClientHandler::HandleSingleCollectionMessage OUT");
       
   708     }
       
   709 
       
   710 // -----------------------------------------------------------------------------
       
   711 //
       
   712 // -----------------------------------------------------------------------------
       
   713 //  
       
   714 void CVcxNsMpxCollectionClientHandler::HandleOpenL( const CMPXCollectionPlaylist&
       
   715                                                     /*aPlaylist*/, TInt /*aError*/ )
       
   716     {
       
   717     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::HandleOpenL( playlist )");
       
   718     }
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 // -----------------------------------------------------------------------------
       
   723 //  
       
   724 void CVcxNsMpxCollectionClientHandler::HandleOpenL( const CMPXMedia& /*aEntries*/,
       
   725                   TInt /*aIndex*/, TBool /*aComplete*/, TInt /*aError*/ )
       
   726     {
       
   727     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::HandleOpenL( aEntries )");
       
   728     }
       
   729 
       
   730 // -----------------------------------------------------------------------------
       
   731 //
       
   732 // -----------------------------------------------------------------------------
       
   733 //  
       
   734 void CVcxNsMpxCollectionClientHandler::HandleCommandComplete( CMPXCommand* aCommandResult,
       
   735                                                               TInt /*aError*/ )
       
   736     {
       
   737     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::HandleCommandComplete IN");
       
   738 
       
   739     TInt32 error( KErrNone );
       
   740                             
       
   741     if ( aCommandResult->IsSupported( KVcxMediaMyVideosInt32Value ) )
       
   742         {
       
   743         error = aCommandResult->ValueTObjectL<TInt32>( KVcxMediaMyVideosInt32Value );
       
   744         }
       
   745 
       
   746     TInt tid = -1;
       
   747     
       
   748     if( aCommandResult->IsSupported( KVcxMediaMyVideosTransactionId ) )
       
   749         {
       
   750         tid = aCommandResult->ValueTObjectL<TInt>( KVcxMediaMyVideosTransactionId );
       
   751         }
       
   752 
       
   753     TMPXItemId mpxId( 0, 0 );
       
   754         
       
   755     if ( aCommandResult->IsSupported( KMPXMediaGeneralId ) )
       
   756         {
       
   757         mpxId = aCommandResult->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
   758         }
       
   759         
       
   760     if( error != KErrNone )
       
   761         {    
       
   762         for( TInt i = iDownloadedContents.Count() - 1; i >= 0; i-- )
       
   763             {
       
   764             if( (iDownloadedContents[i])->CmdTransactionId() == tid )
       
   765                 {
       
   766                 IPTVLOGSTRING2_HIGH_LEVEL( "UI Engine ## clearing failed (TR ID = %d) command", tid); 
       
   767                 (iDownloadedContents[i])->SetPendingCommand( 
       
   768                         CVcxNsContent::EVcxNsMpxContentCommandNone );
       
   769                 iUiEngine.ContentProvider()->UpdateContent( iDownloadedContents[i] );
       
   770                 break;
       
   771                 }
       
   772             }        
       
   773         IPTVLOGSTRING2_HIGH_LEVEL( "UI Engine ## HandleCommandComplete() OUT, error = %d ",
       
   774                                    error);
       
   775         return;
       
   776         }
       
   777     
       
   778     if( !aCommandResult )
       
   779         {
       
   780         IPTVLOGSTRING_LOW_LEVEL(
       
   781             "CVcxNsMpxCollectionClientHandler::HandleCommandComplete OUT, aResult == NULL");
       
   782         return;
       
   783         }
       
   784     
       
   785     if( aCommandResult->IsSupported( KVcxMediaMyVideosTransactionId ) )
       
   786         {
       
   787         IPTVLOGSTRING2_LOW_LEVEL(
       
   788                  "CVcxNsMpxCollectionClientHandler::HandleCommandComplete , trid == %d", tid );
       
   789 
       
   790         // See which content's request is processed.
       
   791         for( TInt i = iDownloadedContents.Count() - 1; i >= 0 ; i-- )
       
   792             {
       
   793             if( (iDownloadedContents[i])->CmdTransactionId() == tid )
       
   794                 {
       
   795                 switch ( (iDownloadedContents[i])->PendingCommand() )
       
   796                     {
       
   797                     case CVcxNsContent::EVcxNsMpxContentCommandCancelDownload:
       
   798                         {
       
   799                         IPTVLOGSTRING_LOW_LEVEL("UI Engine ## command complete EVcxNsMpxContentCommandCancelDownload OK");
       
   800                         (iDownloadedContents[i])->SetPendingCommand( CVcxNsContent::EVcxNsMpxContentCommandNone );
       
   801                         TMPXItemId mpxId = aCommandResult->Value<CMPXMedia>( KMPXCommandColAddMedia )
       
   802                             ->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
   803                         DeleteDownload( mpxId );
       
   804                         }
       
   805                         break;
       
   806                         
       
   807                     case CVcxNsContent::EVcxNsMpxContentCommandStartDownload:
       
   808                         (iDownloadedContents[i])->SetPendingCommand( CVcxNsContent::EVcxNsMpxContentCommandWaitingForMpxItem );
       
   809                         break;                    
       
   810                 
       
   811                     default:
       
   812                         (iDownloadedContents[i])->SetPendingCommand( CVcxNsContent::EVcxNsMpxContentCommandNone );
       
   813                         iUiEngine.ContentProvider()->UpdateContent( iDownloadedContents[i] );
       
   814                         break;
       
   815                     }
       
   816                 break;
       
   817                 }
       
   818             }
       
   819         }
       
   820     
       
   821     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::HandleCommandComplete OUT");
       
   822     }
       
   823 
       
   824 // -----------------------------------------------------------------------------
       
   825 // CVcxNsMpxCollectionClientHandler::GetMediaByMpxIdReqL
       
   826 // -----------------------------------------------------------------------------
       
   827 //
       
   828 void CVcxNsMpxCollectionClientHandler::GetMediaByMpxIdReqL( RArray<TUint32>& aMpxIds )
       
   829     {
       
   830     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::GetMediaByMpxIdReqL IN");
       
   831     
       
   832     CMPXCommand* cmd = CMPXCommand::NewL();
       
   833     CleanupStack::PushL( cmd );
       
   834     
       
   835     cmd->SetTObjectValueL( KMPXCommandGeneralId, KVcxCommandIdMyVideos );
       
   836     cmd->SetTObjectValueL( KVcxMediaMyVideosCommandId, KVcxCommandMyVideosGetMediasByMpxId ); 
       
   837     TUid colId = TUid::Uid( KVcxUidMyVideosMpxCollection );
       
   838     cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, colId.iUid );
       
   839     
       
   840     CMPXMediaArray* idMediaArray = CMPXMediaArray::NewL();
       
   841     CleanupStack::PushL( idMediaArray );
       
   842 
       
   843     CMPXMedia* media;
       
   844     TMPXItemId mpxId;
       
   845     for ( TInt i = 0; i < aMpxIds.Count(); i++ )
       
   846         {
       
   847         media = CMPXMedia::NewL();
       
   848         CleanupStack::PushL( media );
       
   849         
       
   850         mpxId.iId1 = aMpxIds[i];
       
   851         mpxId.iId2 = KMpxMediaId2;
       
   852         
       
   853         media->SetTObjectValueL( KMPXMessageMediaGeneralId, mpxId );
       
   854         idMediaArray->AppendL( *media );
       
   855         CleanupStack::PopAndDestroy( media );
       
   856         }
       
   857                             
       
   858     cmd->SetCObjectValueL<CMPXMediaArray>( KMPXMediaArrayContents, idMediaArray );
       
   859     
       
   860     cmd->SetTObjectValueL( KMPXMediaArrayCount, idMediaArray->Count() );
       
   861 
       
   862     iCollectionUtility->Collection().CommandL( *cmd );
       
   863 
       
   864     CleanupStack::PopAndDestroy( idMediaArray );
       
   865     CleanupStack::PopAndDestroy( cmd ); 
       
   866     
       
   867     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::GetMediaByMpxIdReqL OUT");
       
   868     }
       
   869 
       
   870 // -----------------------------------------------------------------------------
       
   871 // CVcxNsMpxCollectionClientHandler::LinkMediaObjectsL
       
   872 // -----------------------------------------------------------------------------
       
   873 //
       
   874 void CVcxNsMpxCollectionClientHandler::LinkMediaObjectsL( CMPXMediaArray* aArray  )
       
   875     {
       
   876     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::LinkMediaObjectsL IN");
       
   877     
       
   878     if ( aArray )
       
   879         {
       
   880         for ( TInt i = aArray->Count()-1; i >= 0; i-- )
       
   881             {
       
   882             SearchAndAddMpxMediaL( (*aArray)[i] );
       
   883             }
       
   884         }
       
   885 
       
   886     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::LinkMediaObjectsL OUT");
       
   887     }
       
   888 
       
   889 // -----------------------------------------------------------------------------
       
   890 // CVcxNsMpxCollectionClientHandler::SearchAndAddMpxMediaL
       
   891 // -----------------------------------------------------------------------------
       
   892 //
       
   893 void CVcxNsMpxCollectionClientHandler::SearchAndAddMpxMediaL( CMPXMedia* aMedia )
       
   894     {
       
   895     //NOTE: It takes a while before this is called after download has been started.
       
   896     //      If application is closed before the media item has arrived, metadata is lost
       
   897     
       
   898     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::SearchAndAddMpxMediaL IN");
       
   899     CVcxNsContent* content = NULL;
       
   900     TUint32 mpxId = aMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ).iId1;
       
   901     TPtrC uri = aMedia->ValueText( KVcxMediaMyVideosRemoteUrl );
       
   902     
       
   903     // search from dl first by mpx id
       
   904     IPTVLOGSTRING_LOW_LEVEL(
       
   905          "CVcxNsMpxCollectionClientHandler::SearchAndAddMpxMediaL: SearchFromDownloadList( mpxId )");
       
   906     content = SearchFromDownloadList( mpxId );
       
   907     
       
   908     if( !content )
       
   909         {
       
   910         IPTVLOGSTRING_LOW_LEVEL(
       
   911             "CVcxNsMpxCollectionClientHandler::SearchAndAddMpxMediaL: SearchFromDownloadList( uri ) ");
       
   912         // Not found from dl list, this
       
   913         // is new media. search by uri.        
       
   914         content = SearchFromDownloadList( uri );
       
   915         }
       
   916     
       
   917     // Cancel can be called before the media object
       
   918     // has arrived. If so, cancel it now.
       
   919     if( content && 
       
   920         content->PendingCommand()==CVcxNsContent::EVcxNsMpxContentCommandCancelDownload )
       
   921         {
       
   922         content->SetMpxMediaL( aMedia );
       
   923         CancelDownloadL( *content );
       
   924         // Dont link, object will be removed.
       
   925         return;
       
   926         }
       
   927 
       
   928     if( !content )
       
   929         {
       
   930         IPTVLOGSTRING_LOW_LEVEL(
       
   931              "CVcxNsMpxCollectionClientHandler::SearchAndAddMpxMediaL: SearchContentByUri( uri ) ");
       
   932 
       
   933         // Still not found from dl list, dl is not currently visible
       
   934         //   -> search from all contents.
       
   935 
       
   936         if( iUiEngine.GetContentProviderL() )
       
   937             {
       
   938 	        content = iUiEngine.ContentProvider()->SearchContentByUri( uri );
       
   939             }
       
   940 
       
   941         // Content was found, but the download was not started directly
       
   942 		// from Vod. Add to download list.
       
   943         if ( content && content->GetServiceId() == iUiEngine.ActiveService() )
       
   944             {
       
   945             AppendToDownloadList( content );
       
   946             }
       
   947         }
       
   948 
       
   949     if ( content )
       
   950         {
       
   951         CVcxNsContentAccess* contentAccess = 
       
   952             content->GetContentAccess( CVcxNsContent::EVcxContentTypeVideo );
       
   953         if ( contentAccess )
       
   954             {
       
   955             content->SetMpxMediaL( aMedia );
       
   956             
       
   957             if( !content->GetMpxId() || content->GetMpxId() != mpxId )
       
   958                 {
       
   959                 content->SetMpxId( mpxId );
       
   960                 iUiEngine.GetContentClientHandlerL()->
       
   961                       StoreMpxIdToEcgDbL( content->GetServiceId(),
       
   962                                           content->GetContentId(),
       
   963                                           contentAccess->iIndex,
       
   964                                           mpxId );
       
   965     
       
   966                 CopyEcgDataToMpxColL( content, mpxId );
       
   967                 }
       
   968     
       
   969             if ( !content->GetMpxMedia()->IsSupported( KMPXMediaGeneralIcon ) &&
       
   970                   content->GetIconPath().Length() > 0 )
       
   971                 {
       
   972                 TIconInfo icon;
       
   973                 icon.bmpfile = content->GetIconPath();
       
   974                 content->GetMpxMedia()->SetTObjectValueL( KMPXMediaGeneralIcon, icon );
       
   975                 }
       
   976             
       
   977             iUiEngine.ContentProvider()->UpdateContent( content );
       
   978             
       
   979             CVcxNsContent::TVcxContentDlStatus status = content->GetDlStatus();
       
   980             
       
   981             if( status == CVcxNsContent::EVcxContentDlStateDownloading )
       
   982                 {
       
   983                 iDownloadUpdater->AddDownload( content );
       
   984                 }
       
   985             }
       
   986         }
       
   987     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::SearchAndAddMpxMediaL OUT");
       
   988     }
       
   989 
       
   990 // -----------------------------------------------------------------------------
       
   991 // CVcxNsMpxCollectionClientHandler::AppendToDownloadList
       
   992 // -----------------------------------------------------------------------------
       
   993 //
       
   994 void CVcxNsMpxCollectionClientHandler::AppendToDownloadList( CVcxNsContent* aContent )
       
   995     {
       
   996     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::AppendToDownloadList");
       
   997     
       
   998     if( iDownloadedContents.Find( aContent ) == KErrNotFound )
       
   999         {
       
  1000         iDownloadedContents.Append( aContent );
       
  1001         }
       
  1002     
       
  1003     if( aContent->GetMpxMedia() )
       
  1004         {
       
  1005         CVcxNsContent::TVcxContentDlStatus status = aContent->GetDlStatus();
       
  1006         
       
  1007         if( status == CVcxNsContent::EVcxContentDlStateDownloading )
       
  1008             {
       
  1009 	        iDownloadUpdater->AddDownload( aContent );
       
  1010 	        }
       
  1011         }
       
  1012     }
       
  1013 
       
  1014 // -----------------------------------------------------------------------------
       
  1015 // CVcxNsMpxCollectionClientHandler::RemoveFromDownloadList
       
  1016 // -----------------------------------------------------------------------------
       
  1017 //
       
  1018 void CVcxNsMpxCollectionClientHandler::RemoveFromDownloadList( CVcxNsContent* aContent )
       
  1019     {
       
  1020     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::RemoveFromDownloadList");
       
  1021     
       
  1022     TInt index = iDownloadedContents.Find( aContent );
       
  1023     
       
  1024     if( index >= 0 )
       
  1025         {
       
  1026         iDownloadedContents.Remove( index );
       
  1027         
       
  1028         if( aContent->GetMpxMedia() )
       
  1029             {
       
  1030             iDownloadUpdater->RemoveDownload( aContent );
       
  1031             }
       
  1032         }
       
  1033 
       
  1034     index = iResumeArray.Find( aContent->GetMpxId() );
       
  1035     if ( index >= 0 )
       
  1036         {
       
  1037         iResumeArray.Remove( index );
       
  1038         }
       
  1039     }
       
  1040 
       
  1041 // -----------------------------------------------------------------------------
       
  1042 // CVcxNsMpxCollectionClientHandler::ResetDownloadList
       
  1043 // -----------------------------------------------------------------------------
       
  1044 //
       
  1045 void CVcxNsMpxCollectionClientHandler::ResetDownloadList( TBool aResetCmdsFromContentItems )
       
  1046     {
       
  1047     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::ResetDownloadList");
       
  1048 
       
  1049     if ( aResetCmdsFromContentItems )
       
  1050         {    
       
  1051         for( TInt i = iDownloadedContents.Count()-1; i >= 0 ; i-- )
       
  1052             {
       
  1053             // Reset the pending cmds before removing from the list.
       
  1054             (iDownloadedContents[i])->SetPendingCommand( CVcxNsContent::EVcxNsMpxContentCommandNone );
       
  1055             }
       
  1056         }
       
  1057 
       
  1058 
       
  1059     iDownloadedContents.Reset();
       
  1060     iDownloadUpdater->RemoveAllDownloads();
       
  1061     
       
  1062     iResumeArray.Reset();
       
  1063     }
       
  1064 
       
  1065 // -----------------------------------------------------------------------------
       
  1066 // CVcxNsMpxCollectionClientHandler::SearchFromDownloadList
       
  1067 // -----------------------------------------------------------------------------
       
  1068 //
       
  1069 CVcxNsContent* CVcxNsMpxCollectionClientHandler::SearchFromDownloadList( const TDesC& aUri )
       
  1070     {
       
  1071     IPTVLOGSTRING_LOW_LEVEL(
       
  1072          "CVcxNsMpxCollectionClientHandler::SearchFromDownloadList (aUri) IN");
       
  1073     
       
  1074     for( TInt i = iDownloadedContents.Count()-1; i >= 0 ; i-- )
       
  1075         {
       
  1076         TPtrC contentUri = TPtrC( (iDownloadedContents[i])->GetUrl( CVcxNsContent::EVcxContentTypeVideo ) );
       
  1077 
       
  1078         if ( contentUri.CompareF( aUri ) == 0 )
       
  1079             {
       
  1080             IPTVLOGSTRING_LOW_LEVEL(
       
  1081                  "CVcxNsMpxCollectionClientHandler::SearchFromDownloadList (aUri) OUT, content found");
       
  1082             return iDownloadedContents[i];
       
  1083             }
       
  1084         }
       
  1085 
       
  1086     IPTVLOGSTRING_LOW_LEVEL(
       
  1087         "CVcxNsMpxCollectionClientHandler::SearchFromDownloadList (aUri) OUT, not found");
       
  1088     
       
  1089     return NULL;
       
  1090     }
       
  1091 
       
  1092 // -----------------------------------------------------------------------------
       
  1093 // CVcxNsMpxCollectionClientHandler::SearchFromDownloadList
       
  1094 // -----------------------------------------------------------------------------
       
  1095 //
       
  1096 CVcxNsContent* CVcxNsMpxCollectionClientHandler::SearchFromDownloadList( const TUint32 aMpxId )
       
  1097     {
       
  1098     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::SearchFromDownloadList (aId) IN");
       
  1099     
       
  1100     for( TInt i = iDownloadedContents.Count()-1; i >= 0 ; i-- )
       
  1101         {
       
  1102         TUint32 mpxId = (iDownloadedContents[i])->GetMpxId();
       
  1103 
       
  1104         if ( mpxId == aMpxId )
       
  1105             {
       
  1106             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::SearchFromDownloadList (aId) OUT, found");
       
  1107             return iDownloadedContents[i];
       
  1108             }
       
  1109         }
       
  1110 
       
  1111     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::SearchFromDownloadList (aId) OUT, not found");
       
  1112     return NULL;
       
  1113     }
       
  1114 
       
  1115 // -----------------------------------------------------------------------------
       
  1116 // CVcxNsMpxCollectionClientHandler::DoHandleSingleCollectionMessageL
       
  1117 // -----------------------------------------------------------------------------
       
  1118 //
       
  1119 void CVcxNsMpxCollectionClientHandler::DoHandleSingleCollectionMessageL( CMPXMessage* aMsg, TInt aErr )
       
  1120     {
       
  1121     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::DoHandleSingleCollectionMessageL IN");
       
  1122     
       
  1123     if ( aMsg && aErr == KErrNone )
       
  1124         {
       
  1125         TMPXMessageId mpxMsgId = *( aMsg->Value<TMPXMessageId>( KMPXMessageGeneralId ) );
       
  1126         
       
  1127         TInt mpxCmdId( -1 );
       
  1128         if ( aMsg->IsSupported( KVcxMediaMyVideosCommandId ) )
       
  1129             {
       
  1130             mpxCmdId = aMsg->ValueTObjectL<TInt>( KVcxMediaMyVideosCommandId );
       
  1131             }
       
  1132             
       
  1133         if ( mpxMsgId == KMPXMessageGeneral )
       
  1134             {
       
  1135             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::DoHandleSingleCollectionMessageL KMPXMessageGeneral");
       
  1136             }
       
  1137         else if ( mpxMsgId == KMPXMessageIdItemChanged )
       
  1138             {
       
  1139             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::DoHandleSingleCollectionMessageL: KMPXMessageIdItemChanged");
       
  1140             
       
  1141             TMPXItemId id( 0, 0 );                            
       
  1142             if ( aMsg->IsSupported( KMPXMessageMediaGeneralId ) )
       
  1143                 {
       
  1144                 id = aMsg->ValueTObjectL<TMPXItemId>( KMPXMessageMediaGeneralId );
       
  1145                 }
       
  1146 
       
  1147             if ( id.iId1 == KVcxUidMyVideosMpxCollection )
       
  1148                 {
       
  1149                 // the whole collection changed
       
  1150                 IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::DoHandleSingleCollectionMessageL: The whole collection changed, fetching all items.");
       
  1151                 LoadMpxMediaObjectsL();
       
  1152                 }
       
  1153             else
       
  1154                 {
       
  1155                 iUiEngine.GetEventRouter()->HandleCollectionMessageL( aMsg, aErr );  
       
  1156                 HandleMpxItemChangedL( aMsg, aErr );
       
  1157                 }
       
  1158             }
       
  1159 
       
  1160         else if ( mpxCmdId == KVcxMessageMyVideosGetMediasByMpxIdResp )
       
  1161             {
       
  1162             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::DoHandleSingleCollectionMessageL KVcxMessageMyVideosGetMediasByMpxIdResp");
       
  1163             CMPXMedia* entries = CMPXMedia::NewL( *aMsg );
       
  1164             CleanupStack::PushL( entries );
       
  1165 
       
  1166             CMPXMediaArray* array = entries->Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  1167             
       
  1168             if ( array && 0 < array->Count() )
       
  1169                 {
       
  1170                 iLastFetchedMedias.ResetAndDestroy();
       
  1171                 
       
  1172                 for ( TInt i = 0; i < array->Count(); i++ )
       
  1173                     {
       
  1174                     iLastFetchedMedias.Append( CMPXMedia::NewL( *(*array)[i]) );
       
  1175                     }
       
  1176                 }
       
  1177             
       
  1178             SearchAndMarkItemAsWatchedL( array );
       
  1179 
       
  1180             LinkMediaObjectsL( array );
       
  1181             
       
  1182             CleanupStack::PopAndDestroy( entries );
       
  1183             }
       
  1184         else if ( mpxCmdId ==  KVcxMessageMyVideosListComplete )
       
  1185             {
       
  1186             LoadMpxMediaObjectsL();
       
  1187             }
       
  1188         }
       
  1189     
       
  1190     IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::DoHandleSingleCollectionMessageL OUT");
       
  1191     }
       
  1192 
       
  1193 
       
  1194 // -----------------------------------------------------------------------------
       
  1195 // 
       
  1196 // -----------------------------------------------------------------------------
       
  1197 //
       
  1198 void CVcxNsMpxCollectionClientHandler::HandleMpxItemChangedL( CMPXMessage* aMsg, TInt /*aErr*/ )
       
  1199     {
       
  1200     if( !iUiEngine.ContentProvider() )
       
  1201         {
       
  1202         return;
       
  1203         }
       
  1204     
       
  1205     TUid colId = aMsg->ValueTObjectL<TUid>(KMPXMessageCollectionId);
       
  1206     TMPXChangeEventType type = aMsg->ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType);
       
  1207     
       
  1208     if( colId.iUid == KVcxUidMyVideosMpxCollection )
       
  1209         {
       
  1210         TMPXItemId itemId = aMsg->ValueTObjectL<TMPXItemId>( KMPXMessageMediaGeneralId );
       
  1211     
       
  1212         if ( type == EMPXItemModified )
       
  1213             {
       
  1214             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::HandleCollectionMessageL EMPXItemModified");
       
  1215             CVcxNsContent* content = SearchFromDownloadList( itemId );
       
  1216             if( content )
       
  1217                 {
       
  1218                 if ( content->GetMpxMedia() && !content->GetMpxMedia()->IsSupported( KVcxMediaMyVideosDownloadState ) )
       
  1219                     {
       
  1220                     // Media can be invalid, refetch
       
  1221                     LoadMpxMediaObjectL( aMsg->Value<TMPXItemId>( KMPXMessageMediaGeneralId )->iId1 );
       
  1222                     }
       
  1223                 
       
  1224                 if( iUiEngine.VcAppState() == EStateContentView )
       
  1225                     {
       
  1226 			        CVcxNsContent::TVcxContentDlStatus status = content->GetDlStatus();
       
  1227 			        
       
  1228 			        if( status == CVcxNsContent::EVcxContentDlStateDownloading )
       
  1229                         {
       
  1230                         iDownloadUpdater->AddDownload( content );
       
  1231                         }
       
  1232                     else
       
  1233                         {
       
  1234                         iDownloadUpdater->RemoveDownload( content );
       
  1235                         }
       
  1236 			        
       
  1237 			        if( status == CVcxNsContent::EVcxContentDlStateFailed && 
       
  1238 			            ! content->DlFailNotified() )
       
  1239 			            {
       
  1240 			            NotifyDownloadErrorL( content->GetMpxMedia(), *content );
       
  1241 			            }
       
  1242                     }
       
  1243                 }
       
  1244             }
       
  1245         else if ( type == EMPXItemInserted )
       
  1246             {
       
  1247             LoadMpxMediaObjectL( aMsg->Value<TMPXItemId>( KMPXMessageMediaGeneralId )->iId1 );
       
  1248             }
       
  1249         else if( type == EMPXItemDeleted )
       
  1250             {
       
  1251             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler::HandleCollectionMessageL EMPXItemDeleted");
       
  1252             DeleteDownload( itemId );
       
  1253             }
       
  1254         }
       
  1255     }
       
  1256 
       
  1257 // -----------------------------------------------------------------------------
       
  1258 // 
       
  1259 // -----------------------------------------------------------------------------
       
  1260 //
       
  1261 void CVcxNsMpxCollectionClientHandler::DeleteDownload( TMPXItemId itemId )
       
  1262     {            
       
  1263     CVcxNsContent* content = iUiEngine.ContentProvider()->SearchContentByMpxId( itemId );
       
  1264     if ( content )
       
  1265         {
       
  1266         iDownloadUpdater->RemoveDownload( content );
       
  1267         content->SetMpxId( 0, CVcxNsContent::EVcxContentTypeVideo );
       
  1268         TRAP_IGNORE( 
       
  1269             content->SetMpxMediaL( NULL, CVcxNsContent::EVcxContentTypeVideo );
       
  1270             RemoveFromDownloadList( content );
       
  1271        
       
  1272             CVcxNsContentAccess* contentAccess =
       
  1273                 content->GetContentAccess( CVcxNsContent::EVcxContentTypeVideo );
       
  1274 
       
  1275             if ( contentAccess )
       
  1276                 {
       
  1277                 iUiEngine.GetContentClientHandlerL()->StoreMpxIdToEcgDbL(
       
  1278                             content->GetServiceId(),
       
  1279                             content->GetContentId(),
       
  1280                             contentAccess->iIndex,
       
  1281                             0 /*mpx id*/ );
       
  1282                 }
       
  1283             )
       
  1284         iUiEngine.ContentProvider()->UpdateContent( content );
       
  1285         }
       
  1286     }
       
  1287 
       
  1288 // -----------------------------------------------------------------------------
       
  1289 // 
       
  1290 // -----------------------------------------------------------------------------
       
  1291 //
       
  1292 void CVcxNsMpxCollectionClientHandler::UpdateVideoObject( TUint32 aMpxId )
       
  1293     {
       
  1294     if( iUiEngine.ContentProvider() )
       
  1295         {    
       
  1296         CVcxNsContent* content = SearchFromDownloadList( aMpxId );
       
  1297 
       
  1298         if( content )
       
  1299             {
       
  1300             iUiEngine.ContentProvider()->UpdateContent( content );
       
  1301             }
       
  1302         }
       
  1303     }
       
  1304 
       
  1305 // -----------------------------------------------------------------------------
       
  1306 // 
       
  1307 // -----------------------------------------------------------------------------
       
  1308 //
       
  1309 void CVcxNsMpxCollectionClientHandler::ResumeStartedFromBeginningL( TUint32 aMpxId )
       
  1310     {
       
  1311     TInt index = iResumeArray.Find( aMpxId );
       
  1312     if ( index >= 0 )
       
  1313         {
       
  1314         iResumeArray.Remove( index );
       
  1315 
       
  1316         CVcxNsContent* content = SearchFromDownloadList( aMpxId );
       
  1317         if ( content )
       
  1318             {
       
  1319             iUiEngine.GetEventRouter()->HandleDlErrorL( EIptvResumingFromBeginning, *content );
       
  1320             }
       
  1321         }
       
  1322     }
       
  1323 
       
  1324 // -----------------------------------------------------------------------------
       
  1325 // 
       
  1326 // -----------------------------------------------------------------------------
       
  1327 //
       
  1328 void CVcxNsMpxCollectionClientHandler::CopyEcgDataToMpxColL( CVcxNsContent *aContent, 
       
  1329                                                              TUint32 aMpxId )
       
  1330     {
       
  1331     if ( !aContent->GetDescription().Length() &&
       
  1332          !aContent->GetAuthor().Length() &&
       
  1333          !aContent->GetCopyright().Length()  )
       
  1334         {
       
  1335         iUiEngine.ContentProvider()->FetchFullDetailsL( aContent );
       
  1336         }
       
  1337     
       
  1338     CMPXMedia* msg = CMPXMedia::NewL();
       
  1339     CleanupStack::PushL( msg );
       
  1340     
       
  1341     msg->SetTObjectValueL( KMPXMediaGeneralId, TMPXItemId( aMpxId, KMpxMediaId2 ) );
       
  1342     
       
  1343     //Language
       
  1344     if ( aContent->GetLanguage().Length() > 0 )
       
  1345         {
       
  1346         msg->SetTextValueL( KVcxMediaMyVideosAudioLanguage, aContent->GetLanguage() ) ;
       
  1347         }
       
  1348 
       
  1349     //Length
       
  1350     if ( aContent->GetLength() )
       
  1351         {
       
  1352         msg->SetTObjectValueL<TReal32>( KVcxMediaMyVideosDuration, aContent->GetLength() );
       
  1353         }
       
  1354     
       
  1355     //Description
       
  1356     if ( aContent->GetDescription().Length() > 0 )
       
  1357         {
       
  1358         msg->SetTextValueL( KMPXMediaGeneralComment, aContent->GetDescription() );
       
  1359         }
       
  1360 
       
  1361     //Author
       
  1362     if ( aContent->GetAuthor().Length() > 0 )
       
  1363         {
       
  1364         msg->SetTextValueL( KVcxMediaMyVideosAuthor, aContent->GetAuthor() );
       
  1365         }
       
  1366     
       
  1367     //Copyright
       
  1368     if ( aContent->GetCopyright().Length() > 0 )
       
  1369         {
       
  1370         msg->SetTextValueL( KMPXMediaGeneralCopyright, aContent->GetCopyright() );
       
  1371         }
       
  1372 
       
  1373     // Age profile
       
  1374     if ( aContent->GetAgeProfile() > 0 )
       
  1375         {
       
  1376         msg->SetTObjectValueL<TInt32>( KVcxMediaMyVideosAgeProfile, aContent->GetAgeProfile() );
       
  1377         }
       
  1378     
       
  1379     WriteMsgToColL( msg );
       
  1380 
       
  1381     CleanupStack::PopAndDestroy( msg );
       
  1382     }
       
  1383 
       
  1384 // -----------------------------------------------------------------------------
       
  1385 // 
       
  1386 // -----------------------------------------------------------------------------
       
  1387 //
       
  1388 void CVcxNsMpxCollectionClientHandler::NotifyDownloadErrorL( 
       
  1389     CMPXMedia* aMedia,
       
  1390     CVcxNsContent& aContent )
       
  1391     {
       
  1392     if( !aMedia )
       
  1393         {
       
  1394         return;
       
  1395         }
       
  1396     
       
  1397     TIptvDlError error = GetDownloadErrorL( aMedia );
       
  1398     
       
  1399     aContent.SetDlFailNotified( ETrue );
       
  1400     
       
  1401     iUiEngine.GetEventRouter()->HandleDlErrorL( error, aContent );
       
  1402     }
       
  1403 
       
  1404 // -----------------------------------------------------------------------------
       
  1405 // 
       
  1406 // -----------------------------------------------------------------------------
       
  1407 //
       
  1408 TIptvDlError CVcxNsMpxCollectionClientHandler::GetDownloadErrorL( CMPXMedia* aMedia )
       
  1409     {
       
  1410     TInt32 errorId = aMedia->ValueTObjectL<TInt32>( KVcxMediaMyVideosDownloadError );
       
  1411     TInt32 globalErrorId = aMedia->ValueTObjectL<TInt32>( KVcxMediaMyVideosDownloadGlobalError );
       
  1412     TIptvDlError vcxError;
       
  1413 
       
  1414     IPTVLOGSTRING2_LOW_LEVEL(
       
  1415         "CVcxNsMpxCollectionClientHandler: DL error ID: %d", errorId );
       
  1416     IPTVLOGSTRING2_LOW_LEVEL(
       
  1417         "CVcxNsMpxCollectionClientHandler: DL global error ID: %d", globalErrorId );
       
  1418 
       
  1419     switch ( errorId )
       
  1420         {
       
  1421         case EConnectionFailed:
       
  1422             vcxError = EIptvDlConnectionFailed;
       
  1423             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:  EIptvDlConnectionFailed");
       
  1424             if ( globalErrorId == KErrServerBusy )
       
  1425                 {
       
  1426                 IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler: EIptvDlGeneral");
       
  1427                 vcxError = EIptvDlGeneral;
       
  1428                 }
       
  1429             break;
       
  1430         case EHttpAuthenticationFailed:
       
  1431             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:  EIptvDlAuthFailed");
       
  1432             vcxError = EIptvDlAuthFailed;
       
  1433             // Add download authentication error handling
       
  1434             break; 
       
  1435         case EProxyAuthenticationFailed:
       
  1436             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:  EIptvDlProxyAuthFailed");
       
  1437             vcxError = EIptvDlProxyAuthFailed;
       
  1438             break;
       
  1439         case EDestFileInUse:
       
  1440             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:  EIptvDlDestFileInUse");
       
  1441             vcxError = EIptvDlDestFileInUse;
       
  1442             break;
       
  1443         case EBadUrl:
       
  1444             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:  EIptvDlBadUrl");
       
  1445             vcxError = EIptvDlBadUrl;
       
  1446             break;
       
  1447         case EMMCRemoved:
       
  1448             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:  EIptvDlMmcRemoved");
       
  1449             vcxError = EIptvDlMmcRemoved;
       
  1450             break;
       
  1451         case EDiskFull:
       
  1452             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:  EIptvDlDiskFull");
       
  1453             vcxError = EIptvDlDiskFull;
       
  1454             break;
       
  1455         case EObjectNotFound:
       
  1456             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:  EIptvDlContentNotFound");
       
  1457             vcxError = EIptvDlContentNotFound;
       
  1458             break;
       
  1459         case ETransactionFailed:
       
  1460             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:  EIptvDlInvalidIap");
       
  1461             vcxError = EIptvDlInvalidIap;
       
  1462             break;
       
  1463         default:
       
  1464             IPTVLOGSTRING_LOW_LEVEL("CVcxNsMpxCollectionClientHandler:  EIptvDlGeneral");
       
  1465             vcxError = EIptvDlGeneral;
       
  1466             break;
       
  1467         }
       
  1468     
       
  1469     return vcxError;
       
  1470     }
       
  1471 
       
  1472 // -----------------------------------------------------------------------------
       
  1473 // 
       
  1474 // -----------------------------------------------------------------------------
       
  1475 //
       
  1476 void CVcxNsMpxCollectionClientHandler::MarkVideoAsWatchedL( const TUint32 aMpxId )
       
  1477     {
       
  1478     TBool found( EFalse );
       
  1479     
       
  1480     for ( TInt i = 0; i < iLastFetchedMedias.Count(); i++ )
       
  1481         {
       
  1482         if ( iLastFetchedMedias[i]->IsSupported( KMPXMediaGeneralId ) &&
       
  1483              iLastFetchedMedias[i]->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ).iId1 == aMpxId )
       
  1484             {
       
  1485             MarkItemAsWatchedL( iLastFetchedMedias[i] );
       
  1486             found = ETrue;
       
  1487             break;
       
  1488             }
       
  1489         }
       
  1490     
       
  1491     if ( !found )
       
  1492         {
       
  1493 	    RArray<TUint32> mpxIds;
       
  1494 	    CleanupClosePushL( mpxIds );
       
  1495 	    mpxIds.Append( aMpxId );
       
  1496 	    iMarkAsWatchedId = aMpxId;
       
  1497 	    GetMediaByMpxIdReqL( mpxIds );
       
  1498 	    CleanupStack::PopAndDestroy( &mpxIds );
       
  1499         }
       
  1500     }
       
  1501 
       
  1502 // -----------------------------------------------------------------------------
       
  1503 // 
       
  1504 // -----------------------------------------------------------------------------
       
  1505 //
       
  1506 void CVcxNsMpxCollectionClientHandler::SetlastPlayPosL( const TUint32 aMpxId, TInt32 aPos )
       
  1507     {
       
  1508     if ( CIptvUtil::LastPlaybackPositionFeatureSupported() )
       
  1509         {
       
  1510         WriteAttrToColL( KMPXMediaGeneralLastPlaybackPosition,
       
  1511                          aPos,
       
  1512                          aMpxId );
       
  1513         }
       
  1514     }
       
  1515 
       
  1516 // -----------------------------------------------------------------------------
       
  1517 // 
       
  1518 // -----------------------------------------------------------------------------
       
  1519 //
       
  1520 void CVcxNsMpxCollectionClientHandler::SearchAndMarkItemAsWatchedL( CMPXMediaArray* aArray )
       
  1521     {
       
  1522     if( !aArray || iMarkAsWatchedId == KErrNotFound )
       
  1523         {
       
  1524         return;
       
  1525         }
       
  1526 
       
  1527     CMPXMedia* pMedia;
       
  1528             
       
  1529     for( TInt i = 0; i < aArray->Count(); i++ )
       
  1530         {
       
  1531         pMedia = ( *aArray )[i];
       
  1532                        
       
  1533         TUint32 mpxid = pMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
  1534         
       
  1535         if ( iMarkAsWatchedId == mpxid )
       
  1536             {
       
  1537             iMarkAsWatchedId = KErrNotFound;
       
  1538             MarkItemAsWatchedL( pMedia );
       
  1539             break;
       
  1540             }
       
  1541         }
       
  1542     }
       
  1543 
       
  1544 // -----------------------------------------------------------------------------
       
  1545 // 
       
  1546 // -----------------------------------------------------------------------------
       
  1547 //
       
  1548 void CVcxNsMpxCollectionClientHandler::MarkItemAsWatchedL( CMPXMedia* aMedia )
       
  1549     {
       
  1550     if( !aMedia || !aMedia->IsSupported( KMPXMediaGeneralFlags ) )
       
  1551         {
       
  1552         return;
       
  1553         }
       
  1554 
       
  1555     TUint32 flags = aMedia->ValueTObjectL<TUint32>( KMPXMediaGeneralFlags );
       
  1556     
       
  1557     if ( flags & EVcxMyVideosVideoNew )
       
  1558         {
       
  1559         flags &= ~EVcxMyVideosVideoNew;
       
  1560 
       
  1561         TUint32 mpxid = aMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
  1562         
       
  1563         TInt32 val( flags );
       
  1564 
       
  1565         WriteAttrToColL( KMPXMediaGeneralFlags, val, mpxid );
       
  1566         }
       
  1567     }
       
  1568 
       
  1569 // -----------------------------------------------------------------------------
       
  1570 // 
       
  1571 // -----------------------------------------------------------------------------
       
  1572 //
       
  1573 void CVcxNsMpxCollectionClientHandler::WriteAttrToColL( TMPXAttributeData aAttribute, 
       
  1574                                                         TInt32 aValue, 
       
  1575                                                         TUint32 aMpxId )
       
  1576     {
       
  1577     CMPXMedia* msg = CMPXMedia::NewL();
       
  1578     CleanupStack::PushL( msg );
       
  1579 
       
  1580     msg->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, TMPXItemId( aMpxId, KMpxMediaId2 ) );
       
  1581     msg->SetTObjectValueL<TInt32>( aAttribute, aValue );
       
  1582 
       
  1583     WriteMsgToColL( msg );
       
  1584 
       
  1585     CleanupStack::PopAndDestroy( msg );
       
  1586     }
       
  1587 
       
  1588 
       
  1589 // -----------------------------------------------------------------------------
       
  1590 // 
       
  1591 // -----------------------------------------------------------------------------
       
  1592 //
       
  1593 void CVcxNsMpxCollectionClientHandler::WriteAttrToColL( TMPXAttributeData aAttribute, 
       
  1594                                                         TReal32 aValue, 
       
  1595                                                         TUint32 aMpxId )
       
  1596     {
       
  1597     CMPXMedia* msg = CMPXMedia::NewL();
       
  1598     CleanupStack::PushL( msg );
       
  1599 
       
  1600     msg->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, TMPXItemId( aMpxId, KMpxMediaId2 ) );
       
  1601     msg->SetTObjectValueL<TReal32>( aAttribute, aValue );
       
  1602 
       
  1603     WriteMsgToColL( msg );
       
  1604 
       
  1605     CleanupStack::PopAndDestroy( msg );
       
  1606     }
       
  1607 
       
  1608 // -----------------------------------------------------------------------------
       
  1609 // 
       
  1610 // -----------------------------------------------------------------------------
       
  1611 //
       
  1612 void CVcxNsMpxCollectionClientHandler::WriteMsgToColL( CMPXMedia* aMsg )
       
  1613     {
       
  1614     CMPXCommand* cmd = CMPXCommand::NewL();
       
  1615     CleanupStack::PushL( cmd );
       
  1616 
       
  1617     cmd->SetTObjectValueL( KMPXCommandGeneralId, KMPXCommandIdCollectionSet );
       
  1618     cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, ETrue );
       
  1619     cmd->SetCObjectValueL( KMPXCommandColSetMedia, aMsg );
       
  1620     cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, KVcxUidMyVideosMpxCollection );
       
  1621 
       
  1622     iCollectionUtility->Collection().CommandL( *cmd );
       
  1623 
       
  1624     CleanupStack::PopAndDestroy( cmd );
       
  1625     }
       
  1626 
       
  1627 // -----------------------------------------------------------------------------
       
  1628 // 
       
  1629 // -----------------------------------------------------------------------------
       
  1630 //
       
  1631 void CVcxNsMpxCollectionClientHandler::GetMediaDetailsL( TUint32 aMpxId )
       
  1632     {
       
  1633     if ( iGetMediaDetailWait->IsStarted() )
       
  1634         {
       
  1635         User::Leave( KErrNotReady );
       
  1636         }
       
  1637     
       
  1638     RArray<TMPXAttribute> attrs;
       
  1639     CleanupClosePushL( attrs );
       
  1640     
       
  1641     attrs.Append( KMPXMediaGeneralId );
       
  1642     attrs.Append( KMPXMediaGeneralFlags );
       
  1643     attrs.Append( KMPXMediaGeneralLastPlaybackPosition );
       
  1644 
       
  1645     CMPXCollectionPath* path = CMPXCollectionPath::NewL();
       
  1646     CleanupStack::PushL( path );
       
  1647 
       
  1648     path->AppendL( KVcxUidMyVideosMpxCollection );
       
  1649     path->AppendL( KVcxMvcCategoryIdAll );
       
  1650     path->AppendL( TMPXItemId( aMpxId, KMpxMediaId2 ) );
       
  1651     path->SelectL( TMPXItemId( aMpxId, KMpxMediaId2 ) );
       
  1652 
       
  1653     iCollectionUtility->Collection().MediaL( *path, attrs.Array() );
       
  1654     
       
  1655     CleanupStack::PopAndDestroy( path );
       
  1656     
       
  1657     CleanupStack::PopAndDestroy( &attrs );
       
  1658     }
       
  1659 
       
  1660 // -----------------------------------------------------------------------------
       
  1661 // 
       
  1662 // -----------------------------------------------------------------------------
       
  1663 //
       
  1664 void CVcxNsMpxCollectionClientHandler::GetMediaDetailsSyncL( TUint32 aMpxId )
       
  1665     {
       
  1666     if ( !iGetMediaDetailWait->IsStarted() )
       
  1667         {
       
  1668         GetMediaDetailsL( aMpxId );
       
  1669         iGetMediaDetailWait->Start();
       
  1670         }
       
  1671     else
       
  1672         {
       
  1673         User::Leave( KErrNotReady );
       
  1674         }
       
  1675     }
       
  1676 
       
  1677 // -----------------------------------------------------------------------------
       
  1678 // 
       
  1679 // -----------------------------------------------------------------------------
       
  1680 //
       
  1681 void CVcxNsMpxCollectionClientHandler::PlayVideoL( TUint32 aMpxId )
       
  1682     {
       
  1683     CMPXCollectionPath* path = CMPXCollectionPath::NewL();
       
  1684     CleanupStack::PushL(path);
       
  1685     
       
  1686     path->AppendL( KVcxUidMyVideosMpxCollection );
       
  1687     path->AppendL( KVcxMvcCategoryIdAll );
       
  1688     path->AppendL( TMPXItemId( aMpxId, KMpxMediaId2 ) );
       
  1689     path->SelectL( TMPXItemId( aMpxId, KMpxMediaId2 ) );
       
  1690     
       
  1691     iCollectionUtility->Collection().OpenL( *path );
       
  1692     CleanupStack::PopAndDestroy(path);
       
  1693     }