videocollection/hgmyvideos/src/vcxhgmyvideosvideodataupdater.cpp
branchRCL_3
changeset 10 ce5ada96ab30
parent 0 96612d01cf9f
child 11 5294c000a26d
equal deleted inserted replaced
6:7d91903f795f 10:ce5ada96ab30
    37 #include "vcxhgmyvideosmodel.h"
    37 #include "vcxhgmyvideosmodel.h"
    38 #include "vcxhgmyvideosmainview.h"
    38 #include "vcxhgmyvideosmainview.h"
    39 #include "vcxhgmyvideosvideolist.h"
    39 #include "vcxhgmyvideosvideolist.h"
    40 #include "vcxhgmyvideosvideodataupdater.h"
    40 #include "vcxhgmyvideosvideodataupdater.h"
    41 #include "vcxhgmyvideosindicatorhelper.h"
    41 #include "vcxhgmyvideosindicatorhelper.h"
       
    42 #include "vcxhgmyvideosthumbnailmanager.h"
    42 
    43 
    43 const TInt KRefreshTimerInterval( 1000000 ); // 1 second
    44 const TInt KRefreshTimerInterval( 1000000 ); // 1 second
       
    45 const TInt KMaxThumbnailReqs( 2 ); // Max count of peek and get reqs combined
       
    46 const TInt KMaxThumbnailGetReqs( 1 ); // Max count of get reqs
    44 
    47 
    45 // ============================ MEMBER FUNCTIONS ===============================
    48 // ============================ MEMBER FUNCTIONS ===============================
    46 
    49 
    47 // -----------------------------------------------------------------------------
    50 // -----------------------------------------------------------------------------
    48 // CVcxHgMyVideosVideoDataUpdater::NewL()
    51 // CVcxHgMyVideosVideoDataUpdater::NewL()
   101 // -----------------------------------------------------------------------------
   104 // -----------------------------------------------------------------------------
   102 //
   105 //
   103 void CVcxHgMyVideosVideoDataUpdater::ConstructL()
   106 void CVcxHgMyVideosVideoDataUpdater::ConstructL()
   104     {
   107     {
   105     iRefreshTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   108     iRefreshTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   109     iModel.ThumbnailManager().AddObserverL( *this );
   106     }
   110     }
   107 
   111 
   108 // -----------------------------------------------------------------------------
   112 // -----------------------------------------------------------------------------
   109 // CVcxHgMyVideosVideoDataUpdater::InfoArrayChanged()
   113 // CVcxHgMyVideosVideoDataUpdater::InfoArrayChanged()
   110 // -----------------------------------------------------------------------------
   114 // -----------------------------------------------------------------------------
   121 // CVcxHgMyVideosVideoDataUpdater::~CVcxHgMyVideosVideoDataUpdater()
   125 // CVcxHgMyVideosVideoDataUpdater::~CVcxHgMyVideosVideoDataUpdater()
   122 // -----------------------------------------------------------------------------
   126 // -----------------------------------------------------------------------------
   123 //
   127 //
   124 CVcxHgMyVideosVideoDataUpdater::~CVcxHgMyVideosVideoDataUpdater()
   128 CVcxHgMyVideosVideoDataUpdater::~CVcxHgMyVideosVideoDataUpdater()
   125     {
   129     {
   126     if ( iRefreshTimer )
   130     iModel.ThumbnailManager().RemoveObserver( *this );
   127 	    {
   131     Cancel();
   128 	    // Calling cancel without checking if the timer is active is safe.        
   132     delete iRefreshTimer; // Cancels active timer
   129         iRefreshTimer->Cancel();
   133     iFetchArray.ResetAndDestroy();
   130         delete iRefreshTimer;
       
   131 		}
       
   132     
       
   133     CancelAndDeleteFetchArray();
       
   134     delete iTnEngine;
       
   135     }
   134     }
   136 
   135 
   137 // -----------------------------------------------------------------------------
   136 // -----------------------------------------------------------------------------
   138 // CVcxHgMyVideosVideoDataUpdater::SetPausedL()
   137 // CVcxHgMyVideosVideoDataUpdater::SetPausedL()
   139 // -----------------------------------------------------------------------------
   138 // -----------------------------------------------------------------------------
   153 // -----------------------------------------------------------------------------
   152 // -----------------------------------------------------------------------------
   154 //
   153 //
   155 void CVcxHgMyVideosVideoDataUpdater::RequestDataL( TMPXItemId aMPXItemId )
   154 void CVcxHgMyVideosVideoDataUpdater::RequestDataL( TMPXItemId aMPXItemId )
   156     {
   155     {
   157     AddItemToFetchArrayL( aMPXItemId );
   156     AddItemToFetchArrayL( aMPXItemId );
       
   157     ContinueVideoDataFetchingL();
       
   158     }
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CVcxHgMyVideosVideoDataUpdater::AddToRequestBufferL()
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 void CVcxHgMyVideosVideoDataUpdater::AddToRequestBufferL( TMPXItemId aMPXItemId )
       
   165     {
       
   166     AddItemToFetchArrayL( aMPXItemId );
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CVcxHgMyVideosVideoDataUpdater::FlushRequestBufferL()
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CVcxHgMyVideosVideoDataUpdater::FlushRequestBufferL()
       
   174     {
   158     ContinueVideoDataFetchingL();
   175     ContinueVideoDataFetchingL();
   159     }
   176     }
   160 
   177 
   161 // -----------------------------------------------------------------------------
   178 // -----------------------------------------------------------------------------
   162 // CVcxHgMyVideosVideoDataUpdater::ReleaseData()
   179 // CVcxHgMyVideosVideoDataUpdater::ReleaseData()
   202 //
   219 //
   203 void CVcxHgMyVideosVideoDataUpdater::CancelActivities( TInt aIndex )
   220 void CVcxHgMyVideosVideoDataUpdater::CancelActivities( TInt aIndex )
   204     {    
   221     {    
   205     if ( aIndex >= 0 && aIndex < iFetchArray.Count() )
   222     if ( aIndex >= 0 && aIndex < iFetchArray.Count() )
   206         {
   223         {
   207         CVcxHgMyVideosVideoData::TVideoDataState state = iFetchArray[aIndex]->State();
   224 		CVcxHgMyVideosVideoData* item = iFetchArray[aIndex];
   208     
   225         CVcxHgMyVideosVideoData::TVideoDataState state = item->State();
   209         if ( state == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailStarted )
   226         if ( state == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailPeekStarted ||
   210             {
   227              state == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailStarted )
   211             // Cancel thumbnail generation. Safe to ignore leave, as the ThumbnailManagerL 
   228             {
   212 			// can only leave if iTnEngine is not created yet, so there cannot be 
   229             iModel.ThumbnailManager().Cancel( item->ThumbnailConversionId() );
   213 			// any outstanding requests either. 
       
   214             TRAP_IGNORE( ThumbnailManagerL()->CancelRequest( 
       
   215                     iFetchArray[aIndex]->ThumbnailConversionId() ) );
       
   216             }
       
   217         else if ( state == CVcxHgMyVideosVideoData::EVideoDataStateDrmStarted )
       
   218             {
       
   219             // Cancel DRM checking.
       
   220             Cancel();
       
   221             }
   230             }
   222         }
   231         }
   223     }
   232     }
   224 
   233 
   225 // -----------------------------------------------------------------------------
   234 // -----------------------------------------------------------------------------
   226 // CVcxHgMyVideosVideoDataUpdater::CancelAndDeleteFetchArray()
   235 // CVcxHgMyVideosVideoDataUpdater::CancelAndDeleteFetchArray()
   227 // -----------------------------------------------------------------------------
   236 // -----------------------------------------------------------------------------
   228 //
   237 //
   229 void CVcxHgMyVideosVideoDataUpdater::CancelAndDeleteFetchArray()
   238 void CVcxHgMyVideosVideoDataUpdater::CancelAndDeleteFetchArray()
   230     {    
   239     {    
   231     for ( TInt i = 0; i < iFetchArray.Count(); i++ )
   240     TInt count = iFetchArray.Count();
   232         {
   241     for ( TInt i = 0; i < count; i++ )
   233         RemoveItem( i );
   242         {
       
   243         CancelActivities( i );
   234         }
   244         }
   235     iFetchArray.ResetAndDestroy();
   245     iFetchArray.ResetAndDestroy();
   236     }
   246     }
   237 
   247 
   238 // -----------------------------------------------------------------------------
   248 // -----------------------------------------------------------------------------
   239 // CVcxHgMyVideosVideoDataUpdater::ContinueVideoDataFetchingL()
   249 // CVcxHgMyVideosVideoDataUpdater::ContinueVideoDataFetchingL()
   240 // -----------------------------------------------------------------------------
   250 // -----------------------------------------------------------------------------
   241 //
   251 //
   242 void CVcxHgMyVideosVideoDataUpdater::ContinueVideoDataFetchingL()
   252 void CVcxHgMyVideosVideoDataUpdater::ContinueVideoDataFetchingL()
   243     {
   253     {
   244     if ( iFetchArray.Count() >= 1 && ! iPaused && iVideoArray.VideoCount() > 0 )
   254     if ( !iPaused && iVideoArray.VideoCount() > 0 && iFetchArray.Count() > 0 )
   245         {
   255         {
   246         TBool go = EFalse;
   256         TBool startRefreshTimer = EFalse;
   247 
   257         TInt peekReqs = 0;
   248         // If first item is in idle state, we need to start new operation.
   258         TInt getReqs = 0;
   249         if ( iFetchArray[0]->State() == CVcxHgMyVideosVideoData::EVideoDataStateNone )
   259         GetActiveRequestCount( peekReqs, getReqs );
   250             {
   260         TInt reqs = peekReqs + getReqs;
   251             // It's safe to ignore leave here, because in that case we just use the first index
   261         if ( reqs < KMaxThumbnailReqs )
   252 			// of fetch array.
   262             {
   253 			TRAP_IGNORE( SelectNextIndexL() );
   263             CVcxHgMyVideosVideoData::TVideoDataState state =
   254             go = ETrue;
   264                         CVcxHgMyVideosVideoData::EVideoDataStateNone;
   255             }   
   265             CVcxHgMyVideosVideoData* prevItem = NULL;
   256         // If thumbnail generation has finished, start DRM checking.
   266             CVcxHgMyVideosVideoData* item = NULL;
   257         else if ( iFetchArray[0]->State() == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailFinished )
   267             do
   258             {
   268                 {
   259             go = ETrue;
   269                 TInt err = KErrNone;
   260             }
   270                 prevItem = item;
   261         // If first item has completed all operations, remove it and start with second one.
   271                 SelectNextIndexL( getReqs >= KMaxThumbnailGetReqs );
   262         else if ( iFetchArray[0]->State() == CVcxHgMyVideosVideoData::EVideoDataStateDrmFinished )
   272                 item = iFetchArray[0];
   263             {
   273                 state = item->State();
   264             UpdateVideoDataToUiL( *( iFetchArray[0] ) );
   274                 if ( state == CVcxHgMyVideosVideoData::EVideoDataStateNone )
   265             RemoveItem( 0 );            
   275                     {
   266 			
   276                     // Try first a quick peek with thumbnail creation denied
   267             if ( iFetchArray.Count() >= 1 )
   277                     TRAP( err, StartThumbnailL( *item, ETrue ) );
   268                 {
   278                     if( err == KErrNone )
   269                 TRAP_IGNORE( SelectNextIndexL() );
       
   270                 go = ETrue;
       
   271                 }
       
   272             }
       
   273 
       
   274         if ( go )
       
   275             {
       
   276             if ( iFetchArray[0]->State() == CVcxHgMyVideosVideoData::EVideoDataStateNone )
       
   277                 {
       
   278                 CMPXMedia* media = iVideoArray.MPXMediaByMPXItemId( iFetchArray[0]->MPXItemId() );
       
   279 
       
   280                 if ( media && media->IsSupported( KMPXMediaGeneralUri ) )
       
   281                     {
       
   282                     HBufC* mimeType = NULL;
       
   283                     if ( media->IsSupported( KMPXMediaGeneralMimeType ) )
       
   284                         {
   279                         {
   285                         mimeType = media->ValueText( KMPXMediaGeneralMimeType ).AllocLC();
   280                         ++reqs;
       
   281                         startRefreshTimer = ETrue;
   286                         }
   282                         }
   287                     else
   283                     }
       
   284                 else if ( state == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailPeekFinished ) 
       
   285                     {
       
   286                     if ( getReqs < KMaxThumbnailGetReqs )
   288                         {
   287                         {
   289                         mimeType = HBufC::NewLC( 1 );
   288                         // Try then get with thumbnail creation allowed
       
   289                         TRAP( err, StartThumbnailL( *item, EFalse ) );
       
   290                         if ( err == KErrNone )
       
   291                             {
       
   292                             ++reqs;
       
   293                             ++getReqs;
       
   294                             startRefreshTimer = ETrue;
       
   295                             }
   290                         }
   296                         }
   291 
   297                     }
   292                     CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC( 
   298                 else
   293                         media->ValueText( KMPXMediaGeneralUri ), 
   299                     {
   294                         *mimeType );
   300                     break; // Nothing to be started
   295                     iFetchArray[0]->SetThumbnailConversionId( 
   301                     }
   296                         ThumbnailManagerL()->GetThumbnailL( *source ) );
   302                 if ( err != KErrNone )
   297                     CleanupStack::PopAndDestroy( source );
   303                     {
   298                     CleanupStack::PopAndDestroy( mimeType );
   304                     RemoveItem( 0 );
   299 
   305                     }                
   300                     IPTVLOGSTRING3_LOW_LEVEL( 
   306                 }
   301                             "MPX My Videos UI # GetThumbnailL() called thumbID %d for %S.",
   307             while ( iFetchArray.Count() > 0 && reqs < KMaxThumbnailReqs && prevItem != item );
   302                             iFetchArray[0]->ThumbnailConversionId(),
   308             }
   303                             &media->ValueText( KMPXMediaGeneralUri ) );
   309         if ( startRefreshTimer )
   304 
   310             {
   305                     iRefreshTimer->Cancel();
   311             iRefreshTimer->Cancel();
   306                     iRefreshTimer->Start( KRefreshTimerInterval, 
   312             iRefreshTimer->Start( KRefreshTimerInterval, KRefreshTimerInterval,
   307                                           KRefreshTimerInterval, 
   313                 TCallBack( RefreshTimerCallBack, this ) );
   308                                           TCallBack( RefreshTimerCallBack, this ) );
       
   309                     
       
   310                     iFetchArray[0]->SetState(
       
   311                         CVcxHgMyVideosVideoData::EVideoDataStateThumbnailStarted );
       
   312                     }
       
   313                 }
       
   314             else if ( iFetchArray[0]->State() == 
       
   315                       CVcxHgMyVideosVideoData::EVideoDataStateThumbnailFinished )
       
   316                 {
       
   317                 if ( ! IsActive() )
       
   318                     {
       
   319                     SetActive();
       
   320                     iStatus = KRequestPending;
       
   321                     TRequestStatus* stat = &iStatus;
       
   322                     User::RequestComplete(stat, KErrNone);
       
   323 
       
   324                     iFetchArray[0]->SetState(
       
   325                         CVcxHgMyVideosVideoData::EVideoDataStateDrmStarted );
       
   326                     }
       
   327                 }
       
   328             }
   314             }
   329         }
   315         }
   330     }
   316     }
   331 
   317 
   332 // -----------------------------------------------------------------------------
   318 // -----------------------------------------------------------------------------
   333 // CVcxHgMyVideosVideoDataUpdater::UpdateVideoDataToUiL()
   319 // CVcxHgMyVideosVideoDataUpdater::UpdateVideoDataToUiL()
   334 // -----------------------------------------------------------------------------
   320 // -----------------------------------------------------------------------------
   335 //
   321 //
   336 void CVcxHgMyVideosVideoDataUpdater::UpdateVideoDataToUiL( CVcxHgMyVideosVideoData& videoData )
   322 void CVcxHgMyVideosVideoDataUpdater::UpdateVideoDataToUiL( CVcxHgMyVideosVideoData& aVideoData )
   337     {
   323     {
   338     TInt index = iVideoArray.IndexByMPXItemId( videoData.MPXItemId() );
   324     TInt index = iVideoArray.IndexByMPXItemId( aVideoData.MPXItemId() );
   339     
   325     
   340     if ( index >= 0 && index < iScroller.ItemCount() )
   326     if ( index >= 0 && index < iScroller.ItemCount() )
   341         {       
   327         {       
   342         TBool drmUpdate = videoData.DrmProtected();
   328         TBool drmUpdate = aVideoData.DrmProtected();
   343         CHgItem& listItem = iScroller.ItemL( index );
   329         CHgItem& listItem = iScroller.ItemL( index );
   344                 
   330                 
   345         if ( videoData.Thumbnail() )
   331         if ( aVideoData.Thumbnail() )
   346             {
   332             {
   347             CGulIcon* thumbnail = CGulIcon::NewL( videoData.Thumbnail( ETrue ) );
   333             CGulIcon* thumbnail = CGulIcon::NewL( aVideoData.Thumbnail( ETrue ) );
   348             listItem.SetIcon( thumbnail ); 
   334             listItem.SetIcon( thumbnail ); 
   349             }
   335             }
   350         
   336         
   351         if ( drmUpdate )
   337         if ( drmUpdate )
   352             {
   338             {
   357                 {
   343                 {
   358                 TVcxHgMyVideosIndicatorHelper indicatorHelper;
   344                 TVcxHgMyVideosIndicatorHelper indicatorHelper;
   359                 TInt indicator1( 0 );
   345                 TInt indicator1( 0 );
   360                 TInt indicator2( 0 );
   346                 TInt indicator2( 0 );
   361 
   347 
   362                 if ( videoData.ValidDrmRights() )
   348                 if ( aVideoData.ValidDrmRights() )
   363                     {
   349                     {
   364                     drmStatus = TVcxHgMyVideosIndicatorHelper::EIndicatorDrmStatusValid;
   350                     drmStatus = TVcxHgMyVideosIndicatorHelper::EIndicatorDrmStatusValid;
   365                     }
   351                     }
   366                 else
   352                 else
   367                     {
   353                     {
   409 // CVcxHgMyVideosVideoDataUpdater::IndexByMPXItemId()
   395 // CVcxHgMyVideosVideoDataUpdater::IndexByMPXItemId()
   410 // -----------------------------------------------------------------------------
   396 // -----------------------------------------------------------------------------
   411 //
   397 //
   412 TInt CVcxHgMyVideosVideoDataUpdater::IndexByMPXItemId( TMPXItemId aMPXItemId )
   398 TInt CVcxHgMyVideosVideoDataUpdater::IndexByMPXItemId( TMPXItemId aMPXItemId )
   413     {   
   399     {   
   414     for ( TInt i = 0; i < iFetchArray.Count(); i++ )
   400     TInt count = iFetchArray.Count();
       
   401     for ( TInt i = 0; i < count; i++ )
   415         {
   402         {
   416         if ( iFetchArray[i]->MPXItemId() == aMPXItemId )
   403         if ( iFetchArray[i]->MPXItemId() == aMPXItemId )
   417             {
   404             {
   418             return i;
   405             return i;
   419             }
   406             }
   423 
   410 
   424 // -----------------------------------------------------------------------------
   411 // -----------------------------------------------------------------------------
   425 // CVcxHgMyVideosVideoDataUpdater::SelectNextIndexL()
   412 // CVcxHgMyVideosVideoDataUpdater::SelectNextIndexL()
   426 // -----------------------------------------------------------------------------
   413 // -----------------------------------------------------------------------------
   427 // 
   414 // 
   428 void CVcxHgMyVideosVideoDataUpdater::SelectNextIndexL()
   415 void CVcxHgMyVideosVideoDataUpdater::SelectNextIndexL( TBool aSelectForPeekOnly )
   429     {   
   416     {   
   430     TInt firstIndexOnScreen = iScroller.FirstIndexOnScreen();
   417     TInt firstIndexOnScreen = iScroller.FirstIndexOnScreen();
   431     
   418     
   432     if ( firstIndexOnScreen < 0 ) 
   419     if ( firstIndexOnScreen < 0 ) 
   433         {
   420         {
   452         icon = iScroller.ItemL( i ).Icon();
   439         icon = iScroller.ItemL( i ).Icon();
   453         if ( !icon )
   440         if ( !icon )
   454             {
   441             {
   455             mpxItemId = iVideoArray.ArrayIndexToMpxItemIdL( i );
   442             mpxItemId = iVideoArray.ArrayIndexToMpxItemIdL( i );
   456             index = IndexByMPXItemId( mpxItemId );
   443             index = IndexByMPXItemId( mpxItemId );
   457         
   444 
   458             if ( index > 0 )
   445             if ( index >= 0 )
   459                 {
   446                 {
       
   447                 CVcxHgMyVideosVideoData* item = iFetchArray[index];
       
   448                 CVcxHgMyVideosVideoData::TVideoDataState state = item->State();
   460                 // Move selected index to first index of the fetch array. 
   449                 // Move selected index to first index of the fetch array. 
   461                 iFetchArray.Insert( iFetchArray[index], 0 );
   450                 if ( aSelectForPeekOnly )
   462                 iFetchArray.Remove( index + 1 );
   451                     {
   463                 break;
   452                     if ( state == CVcxHgMyVideosVideoData::EVideoDataStateNone )
       
   453                         {
       
   454                         iFetchArray.InsertL( item, 0 );
       
   455                         iFetchArray.Remove( index + 1 );
       
   456                         break;
       
   457                         }
       
   458                     }
       
   459                 else if ( state == CVcxHgMyVideosVideoData::EVideoDataStateNone ||
       
   460                           state == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailPeekFinished )
       
   461                     {
       
   462                     iFetchArray.InsertL( item, 0 );
       
   463                     iFetchArray.Remove( index + 1 );
       
   464                     break;
       
   465                     }
   464                 }
   466                 }
   465             }
   467             }
   466         }
   468         }
   467     }
   469     }
   468 
   470 
   537     
   539     
   538     return refreshNeeded;
   540     return refreshNeeded;
   539     }
   541     }
   540 
   542 
   541 // -----------------------------------------------------------------------------
   543 // -----------------------------------------------------------------------------
   542 // CVcxHgMyVideosVideoDataUpdater::ThumbnailManagerL()
       
   543 // -----------------------------------------------------------------------------
       
   544 //
       
   545 CThumbnailManager* CVcxHgMyVideosVideoDataUpdater::ThumbnailManagerL()
       
   546     {
       
   547     if ( !iTnEngine )
       
   548         {
       
   549         IPTVLOGSTRING_LOW_LEVEL( 
       
   550             "MPX My Videos UI # CVcxHgMyVideosVideoDataUpdater::ThumbnailManagerL: Creating thumbnail manager." );
       
   551         
       
   552         iTnEngine = CThumbnailManager::NewL( *this );
       
   553         iTnEngine->SetThumbnailSizeL( EVideoListThumbnailSize );
       
   554         iTnEngine->SetDisplayModeL( EColor16M );
       
   555         }
       
   556     
       
   557     return iTnEngine;
       
   558     }
       
   559 
       
   560 // -----------------------------------------------------------------------------
       
   561 // CVcxHgMyVideosVideoDataUpdater::ThumbnailPreviewReady()
   544 // CVcxHgMyVideosVideoDataUpdater::ThumbnailPreviewReady()
   562 // From MThumbnailManagerObserver, not used in Video Center.
   545 // From MThumbnailManagerObserver, not used in Video Center.
   563 // -----------------------------------------------------------------------------
   546 // -----------------------------------------------------------------------------
   564 //
   547 //
   565 void CVcxHgMyVideosVideoDataUpdater::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, 
   548 void CVcxHgMyVideosVideoDataUpdater::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, 
   577                                                      TThumbnailRequestId aId )
   560                                                      TThumbnailRequestId aId )
   578     {
   561     {
   579     IPTVLOGSTRING3_LOW_LEVEL( 
   562     IPTVLOGSTRING3_LOW_LEVEL( 
   580         "MPX My Videos UI # ThumbnailReady(error=%d, thumbID=%d)", aError, aId );
   563         "MPX My Videos UI # ThumbnailReady(error=%d, thumbID=%d)", aError, aId );
   581 
   564 
   582     if ( iFetchArray.Count() > 0 )
   565     TInt count = iFetchArray.Count();
   583         {
   566     for( TInt i = 0; i < count; ++i )
   584         if ( aError == KErrNone 
   567         {
   585              && aId == iFetchArray[0]->ThumbnailConversionId() )
   568         CVcxHgMyVideosVideoData* item = iFetchArray[i];
   586             {
   569         if ( aId == item->ThumbnailConversionId() )
   587             // Never delete this, ownership gone to Ganes list
   570             {
   588             iFetchArray[0]->SetThumbnail( aThumbnail.DetachBitmap() );
   571             if ( aError == KErrNone ||
   589             }
   572 			     aError == KErrCompletion || // Accept blacklisted
   590         else
   573                  item->State() == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailStarted )
   591             {
   574                 {
   592             iFetchArray[0]->SetThumbnail( NULL );
   575                 // Never delete this, ownership gone to Ganes list
   593             }
   576                 item->SetThumbnail( aError == KErrNone ? aThumbnail.DetachBitmap() : NULL );
   594 
   577                 item->SetState( CVcxHgMyVideosVideoData::EVideoDataStateThumbnailFinished );
   595         iFetchArray[0]->SetState( CVcxHgMyVideosVideoData::EVideoDataStateThumbnailFinished );
   578                 }
   596         }
   579             else if ( aError == KErrNotFound &&
   597 
   580             	item->State() == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailPeekStarted )
   598     TRAP_IGNORE( ContinueVideoDataFetchingL() );
   581                 {
       
   582                 // Try getting thumbnail with create allowed when peek failed with not found
       
   583                 item->SetState( CVcxHgMyVideosVideoData::EVideoDataStateThumbnailPeekFinished );
       
   584                 }
       
   585             else
       
   586                 {
       
   587                 // Stop thumbnail peek attemps
       
   588                 item->SetState( CVcxHgMyVideosVideoData::EVideoDataStateThumbnailFinished );
       
   589                 }
       
   590 
       
   591 			// Start DRM check if thumb finished
       
   592             if ( item->State() == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailFinished && 
       
   593 			     !IsActive() )
       
   594                 {
       
   595                 SetActive();
       
   596                 TRequestStatus* stat = &iStatus;
       
   597                 User::RequestComplete( stat, KErrNone );
       
   598                 }
       
   599 
       
   600             TRAPD( err, ContinueVideoDataFetchingL() );
       
   601             if ( err != KErrNone )
       
   602                 {
       
   603                 IPTVLOGSTRING2_LOW_LEVEL(
       
   604                 "MPX My Videos UI # CVcxHgMyVideosVideoDataUpdater::ThumbnailReady, err = %d",
       
   605                 err );
       
   606                 }
       
   607             break;
       
   608             }
       
   609         }
   599     }
   610     }
   600 
   611 
   601 // -----------------------------------------------------------------------------
   612 // -----------------------------------------------------------------------------
   602 // CVcxHgMyVideosVideoDataUpdater::RunL()
   613 // CVcxHgMyVideosVideoDataUpdater::RunL()
   603 // From CActive
   614 // From CActive
   604 // -----------------------------------------------------------------------------
   615 // -----------------------------------------------------------------------------
   605 //
   616 //
   606 void CVcxHgMyVideosVideoDataUpdater::RunL()
   617 void CVcxHgMyVideosVideoDataUpdater::RunL()
   607     {
   618     {
   608     if ( iFetchArray.Count() > 0 )
   619     if ( !iPaused )
   609         {
   620         {
   610         CMPXMedia* media = iVideoArray.MPXMediaByMPXItemId( iFetchArray[0]->MPXItemId() );
   621         TInt i = 0;
   611         
   622         while( i < iFetchArray.Count() )
   612         if ( media )
   623             {
   613             {
   624             CVcxHgMyVideosVideoData* item = iFetchArray[i];
   614             if ( media->IsSupported( KMPXMediaGeneralUri ) )
   625             if ( item->State() == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailFinished )
   615                 {
   626                 {
   616                 TUint32 flags = 0;
   627                 TRAP_IGNORE(
   617                 if ( media->IsSupported( KMPXMediaGeneralFlags ) )
   628                     {
   618                     {
   629                     CheckDrmL( *item );
   619                     flags = media->ValueTObjectL<TUint32>( KMPXMediaGeneralFlags );
   630                     UpdateVideoDataToUiL( *item );
   620                     }
   631                     } );
   621 
   632                 delete iFetchArray[i];
   622                 if ( flags & EVcxMyVideosVideoDrmProtected )
   633                 iFetchArray.Remove(i);
   623                     {
   634                 }
   624                     ContentAccess::CData* cData = NULL;
   635             else
   625 
   636                 {
   626                     iFetchArray[0]->SetDrmProtected( ETrue );
   637                 ++i;
   627                     iFetchArray[0]->SetValidDrmRights( EFalse );
   638                 }
   628 
   639             }
   629                     TRAPD( trapError,
   640         ContinueVideoDataFetchingL();
   630                            cData = CData::NewL( 
   641         }
   631                                        (TVirtualPathPtr) media->ValueText( KMPXMediaGeneralUri ),
       
   632                                        EPeek,
       
   633                                        EContentShareReadWrite ) );                    
       
   634 
       
   635                     if ( cData )
       
   636                         {
       
   637                         if ( trapError == KErrNone )
       
   638                             {
       
   639                             TInt intentResult = cData->EvaluateIntent( ContentAccess::EPlay );
       
   640 
       
   641                             // Not valid rights should return KErrCANoRights, KErrCANoPermission,
       
   642                             // or in rare cases KErrCAPendingRights. But we don't trust those and
       
   643                             // just compare against KErrNone.
       
   644                             if ( intentResult == KErrNone )
       
   645                                 {
       
   646                                 iFetchArray[0]->SetValidDrmRights( ETrue );
       
   647                                 }
       
   648                             }
       
   649                         delete cData;
       
   650                         }
       
   651                     }
       
   652                 }
       
   653             }
       
   654 
       
   655         iFetchArray[0]->SetState( CVcxHgMyVideosVideoData::EVideoDataStateDrmFinished );
       
   656         }
       
   657 
       
   658     ContinueVideoDataFetchingL();
       
   659     }
   642     }
   660 
   643 
   661 // -----------------------------------------------------------------------------
   644 // -----------------------------------------------------------------------------
   662 // CVcxHgMyVideosVideoDataUpdater::RunError()
   645 // CVcxHgMyVideosVideoDataUpdater::RunError()
   663 // From CActive
   646 // From CActive
   667     {
   650     {
   668     IPTVLOGSTRING2_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosVideoDataUpdater::RunError, aError = %d", aError );
   651     IPTVLOGSTRING2_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosVideoDataUpdater::RunError, aError = %d", aError );
   669     
   652     
   670     if ( aError != KErrNone )
   653     if ( aError != KErrNone )
   671         {
   654         {
   672         // Remove current item from fetch array
       
   673         RemoveItem( 0 );            
       
   674         }
   655         }
   675     return KErrNone;
   656     return KErrNone;
   676     }
   657     }
   677 
   658 
   678 // -----------------------------------------------------------------------------
   659 // -----------------------------------------------------------------------------
   681 // -----------------------------------------------------------------------------
   662 // -----------------------------------------------------------------------------
   682 //
   663 //
   683 void CVcxHgMyVideosVideoDataUpdater::DoCancel()
   664 void CVcxHgMyVideosVideoDataUpdater::DoCancel()
   684     {
   665     {
   685     }
   666     }
       
   667 
       
   668 // -----------------------------------------------------------------------------
       
   669 // CVcxHgMyVideosVideoDataUpdater::CheckDrmL()
       
   670 // -----------------------------------------------------------------------------
       
   671 //
       
   672 void CVcxHgMyVideosVideoDataUpdater::CheckDrmL( CVcxHgMyVideosVideoData& aVideoData )
       
   673     {
       
   674     CMPXMedia* media = iVideoArray.MPXMediaByMPXItemId( aVideoData.MPXItemId() );
       
   675     if ( media && media->IsSupported( KMPXMediaGeneralUri ) )
       
   676         {
       
   677         TUint32 flags = 0;
       
   678         if ( media->IsSupported( KMPXMediaGeneralFlags ) )
       
   679             {
       
   680             flags = media->ValueTObjectL<TUint32>( KMPXMediaGeneralFlags );
       
   681             }
       
   682         if ( flags & EVcxMyVideosVideoDrmProtected )
       
   683             {
       
   684             aVideoData.SetDrmProtected( ETrue );
       
   685             aVideoData.SetValidDrmRights( EFalse );
       
   686 
       
   687             ContentAccess::CData* cData = CData::NewLC( 
       
   688                                (TVirtualPathPtr) media->ValueText( KMPXMediaGeneralUri ),
       
   689                                EPeek,
       
   690                                EContentShareReadWrite );
       
   691             TInt intentResult = cData->EvaluateIntent( ContentAccess::EPlay );
       
   692 
       
   693             // Not valid rights should return KErrCANoRights, KErrCANoPermission,
       
   694             // or in rare cases KErrCAPendingRights. But we don't trust those and
       
   695             // just compare against KErrNone.
       
   696             if ( intentResult == KErrNone )
       
   697                 {
       
   698                 aVideoData.SetValidDrmRights( ETrue );
       
   699                 }
       
   700             CleanupStack::PopAndDestroy( cData );
       
   701             }
       
   702         }
       
   703     }
       
   704 
       
   705 // -----------------------------------------------------------------------------
       
   706 // CVcxHgMyVideosVideoDataUpdater::GetActiveRequestCount()
       
   707 // -----------------------------------------------------------------------------
       
   708 //
       
   709 void CVcxHgMyVideosVideoDataUpdater::GetActiveRequestCount(
       
   710         TInt& aPeekRequests, TInt& aGetRequests )
       
   711     {
       
   712     aPeekRequests = 0;
       
   713     aGetRequests = 0;
       
   714     TInt count = iFetchArray.Count();
       
   715     for( TInt i = 0; i < count; ++i )
       
   716         {
       
   717         CVcxHgMyVideosVideoData::TVideoDataState state = iFetchArray[i]->State();
       
   718         if ( state == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailPeekStarted )
       
   719             {
       
   720             ++aPeekRequests;
       
   721             }
       
   722         else if ( state == CVcxHgMyVideosVideoData::EVideoDataStateThumbnailStarted )
       
   723             {
       
   724             ++aGetRequests;
       
   725             }
       
   726         }
       
   727     }
       
   728 
       
   729 // -----------------------------------------------------------------------------
       
   730 // CVcxHgMyVideosVideoDataUpdater::StartThumbnailL()
       
   731 // -----------------------------------------------------------------------------
       
   732 //
       
   733 void CVcxHgMyVideosVideoDataUpdater::StartThumbnailL(
       
   734         CVcxHgMyVideosVideoData& aItem, TBool aPeek )
       
   735     {
       
   736     CMPXMedia* media = iVideoArray.MPXMediaByMPXItemId( aItem.MPXItemId() );
       
   737     if ( media && media->IsSupported( KMPXMediaGeneralUri ) )
       
   738         {
       
   739         TPtrC uri = media->ValueText( KMPXMediaGeneralUri ); 
       
   740         TPtrC mime = media->IsSupported( KMPXMediaGeneralMimeType ) ? 
       
   741                         media->ValueText( KMPXMediaGeneralMimeType ) : KNullDesC;
       
   742         TThumbnailRequestId id = 0;
       
   743         if ( aPeek )
       
   744             {
       
   745             CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(
       
   746                     uri, mime );
       
   747             id = iModel.ThumbnailManager().PeekL( *source );
       
   748             CleanupStack::PopAndDestroy( source );
       
   749             }
       
   750         else
       
   751             {
       
   752             // Use shared file handle to minimize thumbnailserver overhead 
       
   753             RFs& fs = iModel.FileServerSessionL();
       
   754             RFile64 file;
       
   755             User::LeaveIfError( file.Open( fs, uri, EFileShareReadersOrWriters ));
       
   756             CleanupClosePushL( file );
       
   757             CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC(
       
   758                     file, mime );
       
   759             id = iModel.ThumbnailManager().GetL( *source );
       
   760             CleanupStack::PopAndDestroy( source ); 
       
   761             CleanupStack::PopAndDestroy( &file );
       
   762             }
       
   763         aItem.SetThumbnailConversionId( id );
       
   764 
       
   765         IPTVLOGSTRING3_LOW_LEVEL( 
       
   766                 "MPX My Videos UI # GetThumbnailL() called thumbID %d for %S.",
       
   767                 aItem.ThumbnailConversionId(),
       
   768                 &media->ValueText( KMPXMediaGeneralUri ) );
       
   769 
       
   770         aItem.SetState( aPeek ?
       
   771                 CVcxHgMyVideosVideoData::EVideoDataStateThumbnailPeekStarted :
       
   772                 CVcxHgMyVideosVideoData::EVideoDataStateThumbnailStarted );
       
   773         }
       
   774     else
       
   775         {
       
   776         User::Leave( KErrNotFound );
       
   777         }
       
   778     }