videocollection/hgmyvideos/src/vcxhgmyvideosmodel.cpp
branchRCL_3
changeset 10 ce5ada96ab30
parent 0 96612d01cf9f
child 23 8f0df5c82986
equal deleted inserted replaced
6:7d91903f795f 10:ce5ada96ab30
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include <bldvariant.hrh>
    21 #include <bldvariant.hrh>
    22 #include <AknUtils.h>
    22 #include <AknUtils.h>
    23 #include <centralrepository.h>
    23 #include <centralrepository.h>
    24 #include "IptvDebug.h"
    24 #include "IptvDebug.h"
    25 #include <MediatorEventProvider.h>
       
    26 #include "iptvlastwatcheddata.h"
       
    27 #include "iptvlastwatchedapi.h"
       
    28 #include "vcxhgmyvideosmodel.h"
    25 #include "vcxhgmyvideosmodel.h"
    29 #include "vcxhgmyvideoscollectionclient.h"
    26 #include "vcxhgmyvideoscollectionclient.h"
    30 #include "vcxhgmyvideosdownloadclient.h"
    27 #include "vcxhgmyvideosdownloadclient.h"
    31 #include "vcxnsmediatorids.h"
       
    32 #include "thumbnaildata.h"
    28 #include "thumbnaildata.h"
    33 
    29 #include "vcxhgmyvideoscenrepkeys.h"
    34 _LIT( KTemporaryThumbPath, "C:\\Data\\videocenter\\ecg\\lastwatched.bmp" ); 
    30 #include "vcxhgmyvideosthumbnailmanager.h"
    35 
    31 
    36 // ============================ MEMBER FUNCTIONS ===============================
    32 // ============================ MEMBER FUNCTIONS ===============================
    37 
    33 
    38 // -----------------------------------------------------------------------------
    34 // -----------------------------------------------------------------------------
    39 //
    35 //
    40 // -----------------------------------------------------------------------------
    36 // -----------------------------------------------------------------------------
    41 //
    37 //
    42 CVcxHgMyVideosModel::CVcxHgMyVideosModel()
    38 CVcxHgMyVideosModel::CVcxHgMyVideosModel()
    43   : iAppState( EVcxMyVideosAppStateUnknown ),
    39   : iAppState( EVcxMyVideosAppStateUnknown ),
    44     iPreviousAppState( EVcxMyVideosAppStateUnknown ),
    40     iPreviousAppState( EVcxMyVideosAppStateUnknown ),
    45     iTnRequestId( KErrNotFound ),
       
    46     iSortOrder( EVcxMyVideosSortingNone )
    41     iSortOrder( EVcxMyVideosSortingNone )
    47     {
    42     {
    48     }
    43     }
    49 
    44 
    50 // -----------------------------------------------------------------------------
    45 // -----------------------------------------------------------------------------
    78 //
    73 //
    79 void CVcxHgMyVideosModel::ConstructL()
    74 void CVcxHgMyVideosModel::ConstructL()
    80     {
    75     {
    81     iCollection = CVcxHgMyVideosCollectionClient::NewL();
    76     iCollection = CVcxHgMyVideosCollectionClient::NewL();
    82     iTouchSupport = AknLayoutUtils::PenEnabled();
    77     iTouchSupport = AknLayoutUtils::PenEnabled();
    83     iMediatorEventProvider = CMediatorEventProvider::NewL();
    78     iTnManager = CVcxHgMyVideosThumbnailManager::NewL();
       
    79     InitMyVideosCenRepL();
    84     }
    80     }
    85 
    81 
    86 // -----------------------------------------------------------------------------
    82 // -----------------------------------------------------------------------------
    87 // CVcxHgMyVideosModel::~CVcxHgMyVideosModel()
    83 // CVcxHgMyVideosModel::~CVcxHgMyVideosModel()
    88 // -----------------------------------------------------------------------------
    84 // -----------------------------------------------------------------------------
    94         iFsSession.Close();
    90         iFsSession.Close();
    95         }
    91         }
    96     delete iDriveMonitor;
    92     delete iDriveMonitor;
    97     delete iCollection;
    93     delete iCollection;
    98     delete iCollectionCenRep;
    94     delete iCollectionCenRep;
    99     delete iLastWatchedApi;
    95     delete iMyVideosCenRep;
   100     delete iLastWatchedData;
       
   101     delete iVideoPlayerCustomMessage;
       
   102 
       
   103     if ( iTnManager && iTnRequestId != KErrNotFound )
       
   104         {
       
   105         iTnManager->CancelRequest( iTnRequestId );
       
   106         }
       
   107     delete iTnManager;
    96     delete iTnManager;
   108     delete iMediatorEventProvider;
       
   109     }
    97     }
   110 
    98 
   111 // -----------------------------------------------------------------------------
    99 // -----------------------------------------------------------------------------
   112 // CVcxHgMyVideosModel::TouchSupport()
   100 // CVcxHgMyVideosModel::TouchSupport()
   113 // -----------------------------------------------------------------------------
   101 // -----------------------------------------------------------------------------
   141 //
   129 //
   142 RFs& CVcxHgMyVideosModel::FileServerSessionL()
   130 RFs& CVcxHgMyVideosModel::FileServerSessionL()
   143     {
   131     {
   144     if ( ! iFsSession.Handle() )
   132     if ( ! iFsSession.Handle() )
   145         {
   133         {
   146         User::LeaveIfError( iFsSession.Connect() );
   134         TInt err = iFsSession.Connect();
       
   135         if ( err == KErrNone )
       
   136             {
       
   137             // For sending handles to thumbnailmanager
       
   138             err = iFsSession.ShareProtected();
       
   139             }
       
   140         if ( err != KErrNone )
       
   141             {
       
   142             iFsSession.Close();
       
   143             User::Leave( err );
       
   144             }
   147         }
   145         }
   148 
   146 
   149     return iFsSession;
   147     return iFsSession;
   150     }
   148     }
   151 
   149 
   206 
   204 
   207     iCollectionCenRep->Set( KVcxMyVideosCollectionCenrepKeySortingOrder, 
   205     iCollectionCenRep->Set( KVcxMyVideosCollectionCenrepKeySortingOrder, 
   208                             static_cast<TInt>( aSortOrder ) );
   206                             static_cast<TInt>( aSortOrder ) );
   209     
   207     
   210     iSortOrder = aSortOrder;
   208     iSortOrder = aSortOrder;
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CVcxHgMyVideosModel::GetLastWatchedIdL()
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 TInt CVcxHgMyVideosModel::GetLastWatchedIdL( TInt& aId )
       
   216     {
       
   217     if ( ! iCollectionCenRep )
       
   218         {
       
   219         iCollectionCenRep = CRepository::NewL( TUid::Uid( KVcxMyVideosCollectionCenrepUid ) );
       
   220         }
       
   221 
       
   222     return iCollectionCenRep->Get( KVcxMyVideosCollectionCenrepKeyLastWatchedMpxId, aId );
   211     }
   223     }
   212 
   224 
   213 // -----------------------------------------------------------------------------
   225 // -----------------------------------------------------------------------------
   214 // CVcxHgMyVideosModel::VideolistSortOrderL()
   226 // CVcxHgMyVideosModel::VideolistSortOrderL()
   215 // -----------------------------------------------------------------------------
   227 // -----------------------------------------------------------------------------
   273 
   285 
   274     return resolution;
   286     return resolution;
   275     }
   287     }
   276 
   288 
   277 // -----------------------------------------------------------------------------
   289 // -----------------------------------------------------------------------------
   278 // CVcxHgMyVideosModel::SetVideoAsLastWatchedL()
   290 // CVcxHgMyVideosModel::ThumbnailManager()
   279 // -----------------------------------------------------------------------------
   291 // -----------------------------------------------------------------------------
   280 //
   292 //
   281 void CVcxHgMyVideosModel::SetVideoAsLastWatchedL( TVideoPlayerCustomMessage& aVideoInfo, 
   293 CVcxHgMyVideosThumbnailManager& CVcxHgMyVideosModel::ThumbnailManager() const
   282                                                   TInt aMpxId1,
   294     {
   283                                                   TUint32 aAgeProfile )
   295     return *iTnManager;
   284     {
       
   285     if ( iTnRequestId != KErrNotFound )
       
   286         {
       
   287         ThumbnailManagerL()->CancelRequest( iTnRequestId );
       
   288         iTnRequestId = KErrNotFound;
       
   289         }
       
   290 
       
   291     CopyVideoPlayerCustomMessageL( aVideoInfo, *VideoPlayerCustomMessageL() );
       
   292     
       
   293     // Store data from Video Player Custom message to 'Last Watched' item on 
       
   294     // disk. Un-used (legacy) data fields are resetted to dummy values.
       
   295     
       
   296     LastWatchedDataL()->SetIconPathL( VideoPlayerCustomMessageL()->iIcon );
       
   297     /*
       
   298     LastWatchedDataL()->SetLastVideoPlayPoint( ViaPlayerCustomMessageL()->iStartPosition ); 
       
   299     LastWatchedDataL()->SetMimeTypeL( ViaPlayerCustomMessageL()->iMimeType ); 
       
   300     */
       
   301     
       
   302     LastWatchedDataL()->SetNameL( VideoPlayerCustomMessageL()->iName );
       
   303     LastWatchedDataL()->SetUriL( VideoPlayerCustomMessageL()->iContent ); 
       
   304     
       
   305 	// LastWatchedDataL()->SetContentType( ViaPlayerCustomMessageL()->iContentType );
       
   306         
       
   307     LastWatchedDataL()->SetMpxId( aMpxId1 );
       
   308     LastWatchedDataL()->SetServiceId( KIdUndefined );
       
   309     LastWatchedDataL()->SetContentId( KIdUndefined );
       
   310     LastWatchedDataL()->SetContentIndex( -1 );    
       
   311     LastWatchedDataL()->SetParentalControl( aAgeProfile );
       
   312     LastWatchedDataL()->SetParametersL( KNullDesC8 );
       
   313     LastWatchedDataL()->SetAppUid( TUid::Uid( 0 ) );
       
   314     LastWatchedDataL()->SetViewUid( TUid::Uid( 0 ) );
       
   315     LastWatchedDataL()->SetParameterId( TUid::Uid( 0 ) );
       
   316     LastWatchedDataL()->SetLaunchType( CIptvLastWatchedData::EUndefined );
       
   317     
       
   318     // Start fetching or generating thumbnail for last watched video.
       
   319     // The 'Last Watched' data is published only when thumb is available.
       
   320     CThumbnailObjectSource* source = CThumbnailObjectSource::NewLC( 
       
   321         VideoPlayerCustomMessageL()->iContent, 
       
   322         KNullDesC ); 
       
   323     iTnRequestId = ThumbnailManagerL()->GetThumbnailL( *source );
       
   324     CleanupStack::PopAndDestroy( source );    
       
   325     }
       
   326 
       
   327 // -----------------------------------------------------------------------------
       
   328 // CVcxHgMyVideosModel::UpdateLastWatchedPlayPositionL()
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 void CVcxHgMyVideosModel::UpdateLastWatchedPlayPositionL( TUint32 aLastVideoPlayPoint )
       
   332     {
       
   333     if ( iTnRequestId != KErrNotFound )
       
   334         {
       
   335         LastWatchedDataL()->SetLastVideoPlayPoint( aLastVideoPlayPoint );
       
   336         }
       
   337     else
       
   338         {
       
   339         LastWatchedApiL()->UpdateLastVideoPlayPointL( aLastVideoPlayPoint );
       
   340         }
       
   341     }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CVcxHgMyVideosModel::GetLastWatchedDataL()
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void CVcxHgMyVideosModel::GetLastWatchedDataL( TVideoPlayerCustomMessage& aVideoInfo,
       
   348                                                TUint32& /*aMpxId1 */,
       
   349                                                TUint32& aAgeProfile )
       
   350     {
       
   351     LastWatchedApiL()->GetLastWatchedDataL( *LastWatchedDataL() );
       
   352 
       
   353     aVideoInfo.iContent = LastWatchedDataL()->Uri();
       
   354     aVideoInfo.iName = LastWatchedDataL()->Name();
       
   355     aVideoInfo.iIcon = LastWatchedDataL()->IconPath();
       
   356     
       
   357     aAgeProfile = LastWatchedDataL()->ParentalControl();
       
   358     }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CVcxHgMyVideosModel::ThumbnailPreviewReady()
       
   362 // From MThumbnailManagerObserver, not used in Video Center.
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 void CVcxHgMyVideosModel::ThumbnailPreviewReady( MThumbnailData& /*aThumbnail*/, 
       
   366                                                  TThumbnailRequestId /*aId*/ )
       
   367     {
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 // CVcxHgMyVideosModel::ThumbnailReady()
       
   372 // From MThumbnailManagerObserver
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 void CVcxHgMyVideosModel::ThumbnailReady( TInt aError,
       
   376                                           MThumbnailData& aThumbnail,
       
   377                                           TThumbnailRequestId aId )
       
   378     {
       
   379     TRAP_IGNORE( HandleThumbnailReadyL( aError, aThumbnail, aId ) );
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CVcxHgMyVideosModel::HandleThumbnailReadyL()
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 void CVcxHgMyVideosModel::HandleThumbnailReadyL( TInt aError,
       
   387                                                  MThumbnailData& aThumbnail,
       
   388                                                  TThumbnailRequestId aId )
       
   389     {
       
   390     IPTVLOGSTRING3_LOW_LEVEL(
       
   391         "MPX My Videos UI # HandleThumbnailReadyL(error=%d, ID=%d)", aError, aId );
       
   392 
       
   393     if ( aError == KErrNone && aId == iTnRequestId )
       
   394         {
       
   395         iTnRequestId = KErrNotFound;
       
   396 
       
   397         // Save a copy of the bitmap to local file that Matrix Menu can access.
       
   398         CFbsBitmap* bitmap = aThumbnail.Bitmap();
       
   399         bitmap->Save( KTemporaryThumbPath );
       
   400         LastWatchedDataL()->SetIconPathL( KTemporaryThumbPath );
       
   401         VideoPlayerCustomMessageL()->iIcon = KTemporaryThumbPath;
       
   402         }
       
   403     else
       
   404         {
       
   405         iTnRequestId = KErrNotFound;
       
   406         }
       
   407 
       
   408     LastWatchedApiL()->SetLastWatchedDataL( *LastWatchedDataL() );
       
   409     TPckg<TVideoPlayerCustomMessage> videoInfoPckg( *VideoPlayerCustomMessageL() );
       
   410     iMediatorEventProvider->RaiseEvent( KVcxNsVideoCenterMediatorDomain,
       
   411                                         KVcxNsPlayerGeneralCategory,
       
   412                                         KVcxNsMediatorEventPlayerLastWatch,
       
   413                                         TVersion( KVcxNsMediatorPlayerVersion, 0, 0 ),
       
   414                                         videoInfoPckg );
       
   415     }
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // CVcxHgMyVideosModel::ResetDownloadNotification()
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 void CVcxHgMyVideosModel::ResetDownloadNotification()
       
   422     {
       
   423     iMediatorEventProvider->RaiseEvent( TUid::Uid( KVcxNsMpxMediatorDomain ),
       
   424                                         TUid::Uid( KVcxNsMpxMediatorCategory ), 
       
   425                                         KVcxNsMpxEventResetDownloadNotification,
       
   426                                         TVersion( KVcxNsMpxEventVersion, 0, 0 ),
       
   427                                         KNullDesC8() ); 
       
   428     }
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // CVcxHgMyVideosModel::ThumbnailManagerL()
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 CThumbnailManager* CVcxHgMyVideosModel::ThumbnailManagerL()
       
   435     {
       
   436     if ( ! iTnManager )
       
   437         {
       
   438         iTnManager = CThumbnailManager::NewL( *this );
       
   439         iTnManager->SetThumbnailSizeL( EVideoListThumbnailSize );
       
   440         iTnManager->SetDisplayModeL( EColor16M );
       
   441         }
       
   442     return iTnManager;
       
   443     }
       
   444 
       
   445 // -----------------------------------------------------------------------------
       
   446 // CVcxHgMyVideosModel::CopyVideoPlayerCustomMessageL()
       
   447 // -----------------------------------------------------------------------------
       
   448 //
       
   449 void CVcxHgMyVideosModel::CopyVideoPlayerCustomMessageL( TVideoPlayerCustomMessage& aSource,
       
   450                                                          TVideoPlayerCustomMessage& aTarget )
       
   451     {
       
   452     aTarget.iContent = aSource.iContent;
       
   453     aTarget.iName = aSource.iName;
       
   454     aTarget.iIcon = aSource.iIcon;
       
   455     }
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // CVcxHgMyVideosModel::VideoPlayerCustomMessageL()
       
   459 // -----------------------------------------------------------------------------
       
   460 //
       
   461 TVideoPlayerCustomMessage* CVcxHgMyVideosModel::VideoPlayerCustomMessageL()
       
   462     {
       
   463     if ( ! iVideoPlayerCustomMessage ) 
       
   464         {
       
   465         iVideoPlayerCustomMessage = new (ELeave) TVideoPlayerCustomMessage;
       
   466         }
       
   467     return iVideoPlayerCustomMessage;
       
   468     }
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // CVcxHgMyVideosModel::LastWatchedApiL()
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 CIptvLastWatchedApi* CVcxHgMyVideosModel::LastWatchedApiL()
       
   475     {
       
   476     if ( ! iLastWatchedApi )
       
   477         {
       
   478         iLastWatchedApi = CIptvLastWatchedApi::NewL();
       
   479         }
       
   480     return iLastWatchedApi;
       
   481     }
       
   482 
       
   483 // -----------------------------------------------------------------------------
       
   484 // CVcxHgMyVideosModel::LastWatchedDataL()
       
   485 // -----------------------------------------------------------------------------
       
   486 //
       
   487 CIptvLastWatchedData* CVcxHgMyVideosModel::LastWatchedDataL()
       
   488     {
       
   489     if ( ! iLastWatchedData )
       
   490         {
       
   491         iLastWatchedData = CIptvLastWatchedData::NewL();
       
   492         }
       
   493     return iLastWatchedData;
       
   494     }
   296     }
   495 
   297 
   496 // -----------------------------------------------------------------------------
   298 // -----------------------------------------------------------------------------
   497 // CVcxHgMyVideosModel::HandleDriveMonitorEvent()
   299 // CVcxHgMyVideosModel::HandleDriveMonitorEvent()
   498 // -----------------------------------------------------------------------------
   300 // -----------------------------------------------------------------------------
   500 void CVcxHgMyVideosModel::HandleDriveMonitorEvent( TIptvDriveMonitorEvent& /*aEvent*/ )
   302 void CVcxHgMyVideosModel::HandleDriveMonitorEvent( TIptvDriveMonitorEvent& /*aEvent*/ )
   501     {
   303     {
   502     // We are not interested about the event, we are observing just to keep
   304     // We are not interested about the event, we are observing just to keep
   503     // iDriveMonitor.iAvailableDrives up to date. 
   305     // iDriveMonitor.iAvailableDrives up to date. 
   504     }
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CVcxHgMyVideosModel::GetMyVideosCustomizationIntL()
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 TInt CVcxHgMyVideosModel::GetMyVideosCustomizationInt( const TInt& aKey, 
       
   313                                                        TInt& aValue )
       
   314     {
       
   315     if ( iMyVideosCenRep )
       
   316         {
       
   317         return iMyVideosCenRep->Get( aKey, aValue );
       
   318         }
       
   319     return KErrNotFound;
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // CVcxHgMyVideosModel::GetMyVideosCustomizationString()
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 TInt CVcxHgMyVideosModel::GetMyVideosCustomizationString( const TInt& aKey, 
       
   327                                                           TDes& aValue )
       
   328     {
       
   329     if ( iMyVideosCenRep )
       
   330         {
       
   331         return iMyVideosCenRep->Get( aKey, aValue );
       
   332         }
       
   333     return KErrNotFound;
       
   334     }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // CVcxHgMyVideosModel::InitMyVideosCenRepL()
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 TInt CVcxHgMyVideosModel::InitMyVideosCenRepL()
       
   341     {
       
   342     TInt retVal = KErrNone;
       
   343     if ( !iMyVideosCenRep )
       
   344         {
       
   345         TRAPD( error, iMyVideosCenRep = CRepository::NewL( KMyVideosMainViewCenRepUid ) );
       
   346         retVal = error;
       
   347         }
       
   348     return retVal;
       
   349     }