videofeeds/hgvodui/src/vcxhgvodcontentlistmodelhandler.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of 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:    HG VOD*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #include <aknnotewrappers.h>
       
    21 #include <StringLoader.h>
       
    22 #include <vcxhgvodui.rsg>
       
    23 #include <ganes/HgScroller.h>
       
    24 #include <ganes/HgItem.h>
       
    25 #include <ganes/HgDoubleGraphicList.h>
       
    26 
       
    27 #include "CIptvUtil.h"
       
    28 #include "vcxhgvodcontentlistimpl.h"
       
    29 #include "vcxhgvodcontentlistmodelhandler.h"
       
    30 #include "vcxhgvodmainviewcontainer.h"
       
    31 #include "vcxnsuiengine.h"
       
    32 #include "vcxnsserviceproviderif.h"
       
    33 #include "vcxnscategoryproviderif.h"
       
    34 #include "vcxnscontentproviderif.h"
       
    35 #include "vcxnsservice.h"
       
    36 #include "vcxnscategory.h"
       
    37 #include "vcxnscontent.h"
       
    38 #include "vcxhgvodutils.h"
       
    39 #include "vcxhgvodui.hrh"
       
    40 #include "vcxhgvodmainview.h"
       
    41 #include "vcxhgvodmainviewcontainer.h"
       
    42 #include "vcxhgvodvideodetailsdialog.h"
       
    43 #include "vcxhgvodthumbnailmanager.h"
       
    44 
       
    45 const TInt KFullPercents = 100;
       
    46 const TInt KFullPercentsToList = 99;
       
    47 
       
    48 TInt FindContentIndex( TUint32 aId, RPointerArray<CVcxNsContent>* aArray )
       
    49     {
       
    50     TInt index( KErrNotFound );
       
    51     if ( aArray )
       
    52         {
       
    53         for ( TInt i = 0; i < aArray->Count(); i++ )
       
    54             {
       
    55             if ( (*aArray)[i]->GetContentId() == aId )
       
    56                 {
       
    57                 index = i;
       
    58                 break;
       
    59                 }
       
    60             }
       
    61         }
       
    62     
       
    63     return index;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CVcxHgVodServiceListModelHandler::~CVcxHgVodServiceListModelHandler()
       
    68 // Destructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CVcxHgVodContentListModelHandler::~CVcxHgVodContentListModelHandler()
       
    72     {
       
    73     if ( iContentProvider )
       
    74         {
       
    75         iContentProvider->DeRegisterObserver( this );
       
    76         }
       
    77     
       
    78     delete iTnManager;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CVcxHgVodServiceListImpl::NewL()
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CVcxHgVodContentListModelHandler* CVcxHgVodContentListModelHandler::NewL( 
       
    86     CVcxNsUiEngine& aDataProviderIf,
       
    87     CVcxHgVodMainView& aView, 
       
    88     CHgScroller& aScroller,
       
    89     CVcxHgVodContentListImpl& aContentListImpl )
       
    90     {
       
    91     CVcxHgVodContentListModelHandler* self = 
       
    92         CVcxHgVodContentListModelHandler::NewLC( 
       
    93                     aDataProviderIf, 
       
    94                     aView,
       
    95                     aScroller, 
       
    96                     aContentListImpl );
       
    97     CleanupStack::Pop( self );
       
    98     return self;
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CVcxHgVodContentListModelHandler::NewLC()
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 CVcxHgVodContentListModelHandler* CVcxHgVodContentListModelHandler::NewLC(
       
   106     CVcxNsUiEngine& aDataProviderIf,
       
   107     CVcxHgVodMainView& aView, 
       
   108     CHgScroller& aScroller,
       
   109     CVcxHgVodContentListImpl& aContentListImpl )
       
   110     {
       
   111     CVcxHgVodContentListModelHandler* self = 
       
   112         new (ELeave) CVcxHgVodContentListModelHandler( 
       
   113                 aDataProviderIf, aView, aScroller, aContentListImpl );
       
   114     CleanupStack::PushL( self );
       
   115     self->ConstructL();
       
   116     return self;
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CVcxHgVodContentListModelHandler::CVcxHgVodContentListModelHandler()
       
   121 // Constructor
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CVcxHgVodContentListModelHandler::CVcxHgVodContentListModelHandler(
       
   125     CVcxNsUiEngine& aDataProviderIf,
       
   126     CVcxHgVodMainView& aView, 
       
   127     CHgScroller& aScroller,
       
   128     CVcxHgVodContentListImpl& aContentListImpl )
       
   129     : iDataProviderIf ( aDataProviderIf ),
       
   130       iView ( aView ),
       
   131       iScroller ( aScroller ), 
       
   132       iListImpl ( aContentListImpl )
       
   133     {
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CVcxHgVodContentListModelHandler::ConstructL()
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CVcxHgVodContentListModelHandler::ConstructL()
       
   141     {
       
   142     iContentProvider = iDataProviderIf.GetContentProviderL();
       
   143     iTnManager = CVcxHgVodThumbnailManager::NewL( iView.EikonEnv().FsSession() );
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // Activate model
       
   148 // -----------------------------------------------------------------------------
       
   149 // 
       
   150 void CVcxHgVodContentListModelHandler::DoActivateModelL()
       
   151     {
       
   152     iContentProvider->RegisterObserver( this );
       
   153     iScroller.EnableScrollBufferL( *this, KScrollerBufferSize, KScrollerBufferTreshold ); 
       
   154     iScroller.Reset();
       
   155     iScroller.ControlEnv()->WsSession().ClearAllRedrawStores();
       
   156     iScroller.MakeVisible( ETrue );
       
   157     iScroller.DrawNow();
       
   158     iScroller.ControlEnv()->WsSession().Flush();
       
   159     
       
   160     TRAP_IGNORE( SetListContentL() );
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // Deactivate model
       
   165 // -----------------------------------------------------------------------------
       
   166 // 
       
   167 void CVcxHgVodContentListModelHandler::DoDeActivateModel( )
       
   168     {
       
   169     if ( iContentProvider )
       
   170         {
       
   171         iContentProvider->SetContentHighlight( iScroller.SelectedIndex() );
       
   172         iContentProvider->DeRegisterObserver( this );
       
   173         }
       
   174     
       
   175     iTnManager->Reset();
       
   176     iScroller.DisableScrollBuffer();
       
   177     iScroller.MakeVisible( EFalse );
       
   178     }
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // Set content for model
       
   182 // -----------------------------------------------------------------------------
       
   183 // 
       
   184 void CVcxHgVodContentListModelHandler::SetListContentL()
       
   185     {
       
   186     TInt highlight = 0;
       
   187     iContents = NULL;
       
   188     iContents = &(iContentProvider->GetContentsL( highlight ));
       
   189     if ( iContents )
       
   190         {
       
   191         RefreshViewL();
       
   192         
       
   193         if ( iContents->Count() > 0 )
       
   194             {
       
   195             iScroller.SetSelectedIndex( highlight );
       
   196             }
       
   197         }
       
   198 
       
   199     UpdateViewDetailsL();
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 //  Get category provider interface
       
   204 // -----------------------------------------------------------------------------
       
   205 // 
       
   206 MVcxNsContentProviderIf* CVcxHgVodContentListModelHandler::ContentProvider()
       
   207     {
       
   208     return iContentProvider;
       
   209     }
       
   210  
       
   211 // -----------------------------------------------------------------------------
       
   212 // 
       
   213 // -----------------------------------------------------------------------------
       
   214 // 
       
   215 void CVcxHgVodContentListModelHandler::ContentUpdated( TInt aIndex )
       
   216     {
       
   217     TRAP_IGNORE( UpdateListItemL( aIndex ) );
       
   218     TRAP_IGNORE( HandleCommandUpdatesL() );
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // Handle command updates
       
   223 // -----------------------------------------------------------------------------
       
   224 // 
       
   225 void CVcxHgVodContentListModelHandler::HandleCommandUpdatesL()
       
   226     {
       
   227     iListImpl.CheckMskL();
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // Refresh view, all contents updated
       
   232 // -----------------------------------------------------------------------------
       
   233 // 
       
   234 void CVcxHgVodContentListModelHandler::RefreshView()
       
   235     {
       
   236     if ( iDataProviderIf.VcAppState() == EStateContentView )
       
   237         {
       
   238         iContents = NULL;
       
   239         TRAP_IGNORE( iContents = &(iContentProvider->GetContentsL()) );
       
   240         if ( iContents )
       
   241             {
       
   242             TInt highlight = iScroller.SelectedIndex();
       
   243             
       
   244             TRAP_IGNORE( RefreshViewL() );
       
   245             
       
   246             if ( iScroller.ItemCount() > 0 )
       
   247                 {
       
   248                 if ( highlight < 0 )
       
   249                     {
       
   250                     highlight = 0;
       
   251                     }
       
   252                 else if ( highlight >= iScroller.ItemCount() )
       
   253                     {
       
   254                     highlight = iScroller.ItemCount() - 1;
       
   255                     }
       
   256 
       
   257                 iScroller.SetSelectedIndex( highlight );
       
   258                 }
       
   259             }
       
   260         
       
   261         TRAP_IGNORE( UpdateViewDetailsL() );
       
   262         }
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // Update view details
       
   267 // -----------------------------------------------------------------------------
       
   268 // 
       
   269 void CVcxHgVodContentListModelHandler::UpdateViewDetailsL()
       
   270     {
       
   271     iListImpl.UpdateTitlePaneL();
       
   272     iListImpl.CheckMskL();
       
   273     
       
   274     if ( iContents && iContents->Count() <= 0 
       
   275             && iDataProviderIf.ActiveCategory() == KVcxNsSearchCategoryId )
       
   276         {
       
   277         //When activating search list view and there's no content, 
       
   278         //search result is 0 and show no videos found.
       
   279         iListImpl.SetEmptyListTextL( R_VCXHG_NO_VIDEOS_FOUND );
       
   280         }
       
   281     else if ( iContents && iContents->Count() <= 0 )
       
   282         {
       
   283         iListImpl.SetEmptyListTextL( R_VCXHG_VOD_NO_DATA );
       
   284         }
       
   285     }
       
   286 
       
   287 // -----------------------------------------------------------------------------
       
   288 // Application state change initialized by data provider.
       
   289 // -----------------------------------------------------------------------------
       
   290 // 
       
   291 void CVcxHgVodContentListModelHandler::HandleAppStateChangedL()
       
   292     {
       
   293     iView.ChangeListViewL();
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CVcxHgVodContentListModelHandler::ShowUpdatingNoteL()
       
   298 // -----------------------------------------------------------------------------
       
   299 //
       
   300 void CVcxHgVodContentListModelHandler::ShowUpdatingNoteL( 
       
   301     TBool aShow,
       
   302     TInt aDownloadedTbns, 
       
   303     TInt aTotalTbns )
       
   304     {
       
   305     iListImpl.ShowInformationPopupL( aShow, aDownloadedTbns, aTotalTbns );
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CVcxHgVodContentListModelHandler::HandleUpdateErrorL()
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 void CVcxHgVodContentListModelHandler::HandleUpdateErrorL( TInt aError )
       
   313     {
       
   314     iListImpl.ShowUpdateErrorNoteL( aError );
       
   315     
       
   316     if ( aError == EIptvDlAuthFailed )
       
   317         {
       
   318         TRAPD( err, iListImpl.HandleAuthenticationL( ETrue ) );
       
   319         
       
   320         if ( err == KErrNone && iContentProvider )
       
   321             {
       
   322             //if no error in authentication, refresh contents.
       
   323             iContentProvider->RefreshContentsL();
       
   324             return;
       
   325             }
       
   326         }
       
   327 
       
   328     if ( iScroller.ItemCount() <= 0 )
       
   329         {
       
   330         iListImpl.SetEmptyListTextL( R_VCXHG_VOD_NO_DATA );
       
   331         }
       
   332     
       
   333     iScroller.DrawDeferred();
       
   334     }
       
   335 
       
   336 // -----------------------------------------------------------------------------
       
   337 // CVcxHgVodContentListModelHandler::HandleDownloadErrorL()
       
   338 // -----------------------------------------------------------------------------
       
   339 //
       
   340 void CVcxHgVodContentListModelHandler::HandleDownloadErrorL( 
       
   341     TIptvDlError aError,
       
   342     CVcxNsContent& aContent )
       
   343     {
       
   344     // 
       
   345     // EIptvDlConnectionFailed - Is this handling needed for UI side anymore as connection is 
       
   346     //                           handled in collection side? Is Resume done in collection side also?    
       
   347     
       
   348     HBufC* textFromResource = NULL;
       
   349 
       
   350     switch ( aError )
       
   351         {
       
   352         case EIptvDlContentNotFound:
       
   353             textFromResource = StringLoader::LoadLC( R_VCXHGVOD_ERR_VIDEO_MISSING_FROM_SERVER );
       
   354             break;
       
   355             
       
   356         case EIptvDlAuthFailed:
       
   357             iListImpl.HandleAuthenticationL( EFalse, &aContent );
       
   358             iContentProvider->ResumeDownloadL( aContent );
       
   359             break;
       
   360         case EIptvDlDiskFull:
       
   361             {
       
   362             textFromResource = StringLoader::LoadLC( R_VCXHGVOD_ERR_MEMORY_FULL );
       
   363             CAknQueryDialog* dlg = CAknQueryDialog::NewL( );
       
   364             dlg->ExecuteLD( R_VCXHG_CONFIRMATION_QUERY, *textFromResource );
       
   365             CleanupStack::PopAndDestroy( textFromResource );
       
   366             textFromResource = NULL;
       
   367             }
       
   368             break;
       
   369 
       
   370         case EIptvDlBadUrl:
       
   371             textFromResource = StringLoader::LoadLC( R_VCXHGVOD_ERR_INVALID_ADDRESS );
       
   372             break;
       
   373 
       
   374         case EIptvResumingFromBeginning:
       
   375             {
       
   376             textFromResource = StringLoader::LoadLC( R_VCXHGVOD_RESUME_NOT_POSSIBLE );
       
   377             CAknInformationNote* note = new( ELeave ) CAknInformationNote( ETrue );
       
   378             note->ExecuteLD( *textFromResource );
       
   379             CleanupStack::PopAndDestroy( textFromResource );     
       
   380             textFromResource = NULL;
       
   381             }
       
   382             break;
       
   383             
       
   384         case EIptvDlGeneral:
       
   385         default:
       
   386             {
       
   387             textFromResource = StringLoader::LoadLC( 
       
   388                     R_VCXHGVOD_ERR_DOWNLOAD_FAILED, aContent.GetName() );
       
   389             }
       
   390             break;
       
   391         }
       
   392 
       
   393     if ( textFromResource )
       
   394         {
       
   395         iListImpl.ShowErrorNoteL( *textFromResource );
       
   396         CleanupStack::PopAndDestroy( textFromResource );
       
   397         }
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // 
       
   402 // -----------------------------------------------------------------------------
       
   403 // 
       
   404 void CVcxHgVodContentListModelHandler::MvtoThumbnailReady( 
       
   405     CGulIcon* aIcon,
       
   406     TInt64 aClientId )
       
   407     {
       
   408     // error ignored, as there is no error handling that can be done if this leaves
       
   409     TRAP_IGNORE( DoThumbnailReadyL( aIcon, aClientId ) );
       
   410     }
       
   411 
       
   412 // -----------------------------------------------------------------------------
       
   413 // Generate text for second line
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 HBufC* CVcxHgVodContentListModelHandler::GenerateContextInfoTextLC( 
       
   417     CVcxNsContent& aContent )
       
   418     {
       
   419     // FormatLengthAndSizeL could return new HBufC*, no need for preallocated.
       
   420     HBufC* formattedString = HBufC::NewLC( 100 ); 
       
   421     TPtr formattedStringPtr = formattedString->Des();
       
   422     CVcxNsContent::TVcxContentDlStatus dlStatus = aContent.GetDlStatus();
       
   423 
       
   424     // If not in download list, size and length to list if available
       
   425     if ( ( dlStatus == CVcxNsContent::EVcxContentDlStateNotFound )
       
   426          || ( dlStatus == CVcxNsContent::EVcxContentDlStateNotDownloadable ) )
       
   427         {
       
   428         CVcxHgVodUtils::FormatLengthAndSizeL( 
       
   429             aContent.GetLength(), aContent.GetSize(), formattedStringPtr );
       
   430         }
       
   431     else
       
   432         {
       
   433         // Content is being downloaded, show the status.
       
   434         TInt progress = aContent.GetDlProgress();
       
   435         if ( progress >= KFullPercents )
       
   436             {
       
   437             // always show 99% as highest progress before changing to "downloaded"
       
   438             progress = KFullPercentsToList;
       
   439             }
       
   440         CVcxHgVodUtils::FormatDownloadStateL( dlStatus, progress, 
       
   441                                               formattedStringPtr );
       
   442         }
       
   443     
       
   444     return formattedString;
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // Get content information of currently selected video and pass it to video details dialog
       
   449 // -----------------------------------------------------------------------------
       
   450 // 
       
   451 void CVcxHgVodContentListModelHandler::ShowVideoDetailsL( TInt aSelected )
       
   452     {
       
   453     if ( iContents && aSelected >= 0 && aSelected < iContents->Count() )
       
   454         {
       
   455         CVcxNsContent* content = iContentProvider->GetFullDetailsL( aSelected );
       
   456         iVideoDetails->ShowVideoDetailsDialogL( *content );
       
   457         }  
       
   458     }
       
   459 
       
   460 // -----------------------------------------------------------------------------
       
   461 // Check if model is empty
       
   462 // -----------------------------------------------------------------------------
       
   463 // 
       
   464 TBool CVcxHgVodContentListModelHandler::IsEmptyModel()
       
   465     {
       
   466     return iScroller.ItemCount() <= 0;
       
   467     }
       
   468 
       
   469 // -----------------------------------------------------------------------------
       
   470 // Update list 
       
   471 // -----------------------------------------------------------------------------
       
   472 // 
       
   473 void CVcxHgVodContentListModelHandler::RefreshViewL()
       
   474     {
       
   475     iScroller.Reset();
       
   476     
       
   477     if ( iContents && iContents->Count() > 0 )
       
   478         {
       
   479         iScroller.ResizeL( iContents->Count() );
       
   480         }
       
   481     iScroller.DrawDeferred();
       
   482     }
       
   483 
       
   484 // -----------------------------------------------------------------------------
       
   485 //  
       
   486 // -----------------------------------------------------------------------------
       
   487 //
       
   488 void CVcxHgVodContentListModelHandler::Request( TInt aBufferStart, 
       
   489     TInt aBufferEnd, THgScrollDirection /*aDirection*/ )
       
   490     {
       
   491     for ( TInt i = aBufferStart; i <= aBufferEnd; i++ )
       
   492         {
       
   493         TRAP_IGNORE( UpdateListItemL( i ) );
       
   494         }
       
   495     }
       
   496 
       
   497 // -----------------------------------------------------------------------------
       
   498 //  
       
   499 // -----------------------------------------------------------------------------
       
   500 //
       
   501 void CVcxHgVodContentListModelHandler::Release( TInt /*aBufferStart*/, 
       
   502     TInt /*aBufferEnd*/ )
       
   503     {
       
   504     // No implementation required.
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // Update single content
       
   509 // -----------------------------------------------------------------------------
       
   510 // 
       
   511 void CVcxHgVodContentListModelHandler::UpdateListItemL( TInt aIndex )
       
   512     {
       
   513     if ( iDataProviderIf.VcAppState() == EStateContentView &&
       
   514          aIndex >= 0 && iContents && iContents->Count() > aIndex &&
       
   515          iScroller.ItemCount() > aIndex )
       
   516         {
       
   517         CHgItem& item = iScroller.ItemL( aIndex );
       
   518         CVcxNsContent& content = *(*iContents)[aIndex];
       
   519     
       
   520         item.SetTitleL( content.GetName() );
       
   521     
       
   522         HBufC* info = GenerateContextInfoTextLC( content );    
       
   523 
       
   524         if ( info )
       
   525             {
       
   526             item.SetTextL( *info );
       
   527             }
       
   528     
       
   529         CleanupStack::PopAndDestroy( info );
       
   530     
       
   531         CVcxNsContent::TVcxContentDlStatus dlStatus = content.GetDlStatus();
       
   532     
       
   533         if ( !( item.Icon() ) ||
       
   534              ( dlStatus != CVcxNsContent::EVcxContentDlStateDownloading ) )
       
   535             {
       
   536             item.SetIcon( NULL );
       
   537             const TDesC& iconPath = content.GetIconPath();
       
   538 
       
   539             if ( iconPath.Length() > 0 )
       
   540                 {
       
   541                 iTnManager->AddThumbnailRequestL( *this, 
       
   542                                                   content.GetIconPath(), 
       
   543                                                   CHgDoubleGraphicList::PreferredImageSize(), 
       
   544                                                   content.GetContentId() );
       
   545                 }
       
   546             }
       
   547         iScroller.RefreshScreen( aIndex );
       
   548         }
       
   549     }
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // 
       
   553 // -----------------------------------------------------------------------------
       
   554 // 
       
   555 void CVcxHgVodContentListModelHandler::DoThumbnailReadyL( 
       
   556     CGulIcon* aIcon, 
       
   557     TInt64 aClientId )
       
   558     {
       
   559     CleanupStack::PushL( aIcon );
       
   560     TInt index = FindContentIndex( (TUint32)aClientId, iContents );
       
   561     
       
   562     if ( index >= 0 && iScroller.ItemCount() > index )
       
   563         {
       
   564         iScroller.ItemL( index ).SetIcon( aIcon );
       
   565         iScroller.RefreshScreen( index );
       
   566         CleanupStack::Pop( aIcon );
       
   567         }
       
   568     else
       
   569         {
       
   570         // For some reason the scroller list was update after image conversion
       
   571         // started, and the icon is no longer needed.
       
   572         CleanupStack::PopAndDestroy( aIcon );
       
   573         }
       
   574     }