videofeeds/hgvodui/src/vcxhgvodservicegrouplistmodelhandler.cpp
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    HG VOD*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #include <aknmessagequerydialog.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 "vcxnsserviceproviderif.h"
       
    28 #include "vcxnscategoryproviderif.h"
       
    29 #include "vcxhgvodservicegrouplistimpl.h"
       
    30 #include "vcxhgvodservicegrouplistmodelhandler.h"
       
    31 #include "vcxhgvodmainview.h"
       
    32 #include "vcxhgvodmainviewcontainer.h"
       
    33 #include "vcxhgvodui.hrh"
       
    34 #include "vcxhgvodutils.h"
       
    35 #include "vcxnsuiengine.h"
       
    36 #include "vcxnsservice.h"
       
    37 #include "vcxnscategory.h"
       
    38 #include "vcxhgvodthumbnailmanager.h"
       
    39 
       
    40 TInt FindServiceGroupIndex( TUint32 aId, RPointerArray<CVcxNsService>* aArray )
       
    41     {
       
    42     TInt index( KErrNotFound );
       
    43     for ( TInt i = 0; i < aArray->Count(); i++ )
       
    44         {
       
    45         if ( (*aArray)[i]->GetServiceId() == aId )
       
    46             {
       
    47             index = i;
       
    48             break;
       
    49             }
       
    50         }
       
    51     
       
    52     return index;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CVcxHgVodServiceListModelHandler::~CVcxHgVodServiceListModelHandler()
       
    57 // Destructor
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CVcxHgVodServiceGroupListModelHandler::~CVcxHgVodServiceGroupListModelHandler()
       
    61     {
       
    62     if ( iServiceProvider )
       
    63         {
       
    64         iServiceProvider->DeRegisterObserver( this );
       
    65         }
       
    66     
       
    67     delete iTnManager;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CVcxHgVodServiceListImpl::NewL()
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CVcxHgVodServiceGroupListModelHandler* CVcxHgVodServiceGroupListModelHandler::NewL( 
       
    75     CVcxNsUiEngine& aDataProviderIf,
       
    76     CVcxHgVodMainView& aView, 
       
    77     CHgScroller& aScroller,
       
    78     CVcxHgVodServiceGroupListImpl& aServiceGroupListImpl )
       
    79     {
       
    80     CVcxHgVodServiceGroupListModelHandler* self = 
       
    81         CVcxHgVodServiceGroupListModelHandler::NewLC(  
       
    82                 aDataProviderIf, 
       
    83                 aView,
       
    84                 aScroller,
       
    85                 aServiceGroupListImpl );
       
    86     CleanupStack::Pop( self );
       
    87     return self;
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CVcxHgVodServiceGroupListModelHandler::NewLC()
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 CVcxHgVodServiceGroupListModelHandler* CVcxHgVodServiceGroupListModelHandler::NewLC(
       
    95     CVcxNsUiEngine& aDataProviderIf,
       
    96     CVcxHgVodMainView& aView, 
       
    97     CHgScroller& aScroller,
       
    98     CVcxHgVodServiceGroupListImpl& aServiceGroupListImpl )
       
    99     {
       
   100     CVcxHgVodServiceGroupListModelHandler* self = 
       
   101         new (ELeave) CVcxHgVodServiceGroupListModelHandler(  
       
   102                 aDataProviderIf,
       
   103                 aView,
       
   104                 aScroller, 
       
   105                 aServiceGroupListImpl );
       
   106     CleanupStack::PushL( self );
       
   107     self->ConstructL();
       
   108     return self;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CVcxHgVodServiceGroupListModelHandler::CVcxHgVodServiceGroupListModelHandler()
       
   113 // Constructor
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 CVcxHgVodServiceGroupListModelHandler::CVcxHgVodServiceGroupListModelHandler( 
       
   117     CVcxNsUiEngine& aDataProviderIf, 
       
   118     CVcxHgVodMainView& aView, 
       
   119     CHgScroller& aScroller,
       
   120     CVcxHgVodServiceGroupListImpl& aServiceGroupListImpl )
       
   121     : iDataProviderIf ( aDataProviderIf ),
       
   122       iScroller ( aScroller ),
       
   123       iView ( aView ),
       
   124       iListImpl ( aServiceGroupListImpl )
       
   125     {
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CVcxHgVodServiceGroupListModelHandler::ConstructL()
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CVcxHgVodServiceGroupListModelHandler::ConstructL()
       
   133     {
       
   134     iServiceProvider = iDataProviderIf.GetServiceProviderL();
       
   135     iTnManager = CVcxHgVodThumbnailManager::NewL( iView.EikonEnv().FsSession() );
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // 
       
   140 // -----------------------------------------------------------------------------
       
   141 // 
       
   142 void CVcxHgVodServiceGroupListModelHandler::ServiceAdded( TInt /*aIndex*/ )
       
   143     {
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // 
       
   148 // -----------------------------------------------------------------------------
       
   149 // 
       
   150 void CVcxHgVodServiceGroupListModelHandler::ServiceUpdated( TInt aIndex )
       
   151     {
       
   152     TRAP_IGNORE( UpdateListItemL( aIndex ) );
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // Refresh view, update all services.
       
   157 // -----------------------------------------------------------------------------
       
   158 // 
       
   159 void CVcxHgVodServiceGroupListModelHandler::RefreshView()
       
   160     {
       
   161     if ( iDataProviderIf.VcAppState() == EStateCustomView )
       
   162         {
       
   163         TRAPD( err, iGroupServices = &(iServiceProvider->GetActiveGroupListL()) );
       
   164         
       
   165         if ( err == KErrNone )
       
   166             {
       
   167             TInt highlight = iScroller.SelectedIndex();
       
   168             
       
   169             TRAP_IGNORE( RefreshViewL() );
       
   170             
       
   171             if ( iScroller.ItemCount() > 0 )
       
   172                 {
       
   173                 if ( highlight < 0 )
       
   174                     {
       
   175                     highlight = 0;
       
   176                     }
       
   177                 else if ( highlight >= iScroller.ItemCount() )
       
   178                     {
       
   179                     highlight = iScroller.ItemCount() - 1;
       
   180                     }
       
   181                 
       
   182                 iScroller.SetSelectedIndex( highlight );
       
   183                 }
       
   184             }
       
   185         }
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // Handle service removal (no implementation)
       
   190 // -----------------------------------------------------------------------------
       
   191 // 
       
   192 void CVcxHgVodServiceGroupListModelHandler::ServiceRemoved( 
       
   193     TInt /*aIndex*/, 
       
   194     RPointerArray<CVcxNsService>& /*aUpdatedServiceList*/ )
       
   195     {
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // Application state change initialized by data provider.
       
   200 // -----------------------------------------------------------------------------
       
   201 // 
       
   202 void CVcxHgVodServiceGroupListModelHandler::HandleAppStateChangedL()
       
   203     {
       
   204     iView.ChangeListViewL();
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // Open defined browser link
       
   209 // -----------------------------------------------------------------------------
       
   210 // 
       
   211 void CVcxHgVodServiceGroupListModelHandler::OpenBrowserLinkL( const TDesC& aUri )
       
   212     {
       
   213     iListImpl.OpenEmbeddedBrowserL( aUri );
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // open streaming link
       
   218 // -----------------------------------------------------------------------------
       
   219 // 
       
   220 void CVcxHgVodServiceGroupListModelHandler::OpenStreamingLinkL( const TDesC& aUri )
       
   221     {
       
   222     iView.PlayStreamL( aUri );
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // Activate model
       
   227 // -----------------------------------------------------------------------------
       
   228 // 
       
   229 void CVcxHgVodServiceGroupListModelHandler::DoActivateModelL( )
       
   230     {
       
   231     iServiceProvider->RegisterObserver( this );
       
   232     
       
   233     iGroupServices = &(iServiceProvider->GetActiveGroupListL());
       
   234     iScroller.EnableScrollBufferL( *this, KScrollerBufferSize, KScrollerBufferTreshold );
       
   235     iScroller.Reset();
       
   236     RefreshViewL();
       
   237     
       
   238     iScroller.SetSelectedIndex( iHighlight );
       
   239     iScroller.ControlEnv()->WsSession().ClearAllRedrawStores();
       
   240     iScroller.MakeVisible( ETrue );
       
   241     iScroller.DrawDeferred();
       
   242     }
       
   243 
       
   244 // -----------------------------------------------------------------------------
       
   245 // Deactivate model
       
   246 // -----------------------------------------------------------------------------
       
   247 // 
       
   248 void CVcxHgVodServiceGroupListModelHandler::DoDeActivateModel( )
       
   249     {
       
   250     if ( iServiceProvider )
       
   251         {
       
   252         iServiceProvider->DeRegisterObserver( this );
       
   253         }
       
   254     
       
   255     iTnManager->Reset();
       
   256     
       
   257     iHighlight = iScroller.SelectedIndex();
       
   258     iScroller.DisableScrollBuffer();
       
   259     iScroller.MakeVisible( EFalse );
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // Get highlight index
       
   264 // -----------------------------------------------------------------------------
       
   265 // 
       
   266 TInt CVcxHgVodServiceGroupListModelHandler::GetSelected() 
       
   267     {
       
   268     return iScroller.SelectedIndex();
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------
       
   272 // CVcxHgVodServiceGroupListModelHandler::IsEmptyModel
       
   273 // ---------------------------------------------------------
       
   274 //
       
   275 TBool CVcxHgVodServiceGroupListModelHandler::IsEmptyModel()
       
   276     {
       
   277     return iScroller.ItemCount() <= 0;
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------
       
   281 // CVcxHgVodServiceGroupListModelHandler::GenerateInfoTextLC
       
   282 // ---------------------------------------------------------
       
   283 //
       
   284 HBufC* CVcxHgVodServiceGroupListModelHandler::GenerateInfoTextLC( 
       
   285     CVcxNsService& aGroupService )
       
   286     {
       
   287     if ( aGroupService.Type() == CVcxNsService::EVcxNsGroupedSearch )
       
   288         {
       
   289         MVcxNsCategoryProviderIf* categoryProvider = 
       
   290             iDataProviderIf.GetCategoryProviderL();
       
   291         
       
   292         CVcxNsCategory* category = NULL;
       
   293         if ( categoryProvider )
       
   294             {
       
   295             category = categoryProvider->GetCategoryDataL( 
       
   296                            aGroupService.GetServiceId(), 
       
   297                            KIptvRssSearchCategoryId );
       
   298             }
       
   299         
       
   300         TInt count = 0;
       
   301         if ( category ) 
       
   302             {
       
   303             count = category->GetVideoCount();
       
   304             }
       
   305 
       
   306         if ( count == 1 )
       
   307             {
       
   308             return CVcxHgVodUtils::LoadStringFromResourceLC( 
       
   309                     R_VCXHG_SEARCH_VIDEOS_FOUND_ONE );
       
   310             }
       
   311         else if ( count > 1 ) 
       
   312             {
       
   313             return CVcxHgVodUtils::LoadStringFromResourceLC( 
       
   314                     R_VCXHG_SEARCH_VIDEOS_FOUND, count );            
       
   315             }
       
   316         }
       
   317     
       
   318     return aGroupService.GetDesc().AllocLC();
       
   319     }
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // 
       
   323 // -----------------------------------------------------------------------------
       
   324 // 
       
   325 TInt CVcxHgVodServiceGroupListModelHandler::ItemCount()
       
   326     {
       
   327     return iScroller.ItemCount();
       
   328     }
       
   329 
       
   330 // -----------------------------------------------------------------------------
       
   331 // 
       
   332 // -----------------------------------------------------------------------------
       
   333 // 
       
   334 void CVcxHgVodServiceGroupListModelHandler::MvtoThumbnailReady( 
       
   335     CGulIcon* aIcon,
       
   336     TInt64 aClientId )
       
   337     {
       
   338     // error ignored, as there is no error handling that can be done if this leaves
       
   339     TRAP_IGNORE( DoThumbnailReadyL( aIcon, aClientId ) );
       
   340     }
       
   341 
       
   342 // -----------------------------------------------------------------------------
       
   343 // 
       
   344 // -----------------------------------------------------------------------------
       
   345 // 
       
   346 void CVcxHgVodServiceGroupListModelHandler::RefreshViewL()
       
   347     {
       
   348     iScroller.Reset();
       
   349     
       
   350     if ( iGroupServices && iGroupServices->Count() > 0 )
       
   351         {
       
   352         iScroller.ResizeL( iGroupServices->Count() );
       
   353         }
       
   354     else
       
   355         {
       
   356         CVcxNsService* service = iServiceProvider->GetActiveServiceData();
       
   357         if ( service && 
       
   358              service->Type() == CVcxNsService::EVcxNsMainGroup && 
       
   359              service->GetUpdateStatus() == CVcxNsService::EUpdateFailed )
       
   360             {
       
   361             //Does this need empty list text? (not specified in ui spec)
       
   362             //There's no text available, so if update failed, return 
       
   363             //to video feeds view. 
       
   364             iView.HandleCommandL( EAknSoftkeyBack );
       
   365             }
       
   366 
       
   367         iListImpl.CheckSoftkeysL();
       
   368         }
       
   369     
       
   370     iScroller.DrawDeferred();
       
   371     }
       
   372 
       
   373 // -----------------------------------------------------------------------------
       
   374 // 
       
   375 // -----------------------------------------------------------------------------
       
   376 // 
       
   377 void CVcxHgVodServiceGroupListModelHandler::UpdateListItemL( TInt aIndex ) 
       
   378     
       
   379     {
       
   380     if ( iDataProviderIf.VcAppState() == EStateCustomView &&
       
   381          aIndex >= 0 && aIndex < iScroller.ItemCount() && 
       
   382          iGroupServices && iGroupServices->Count() > aIndex )    
       
   383         {
       
   384         CHgItem& item = iScroller.ItemL( aIndex ); 
       
   385         CVcxNsService& service = *(*iGroupServices)[aIndex];
       
   386     
       
   387         item.SetTitleL( service.GetName() );
       
   388     
       
   389         HBufC* info = GenerateInfoTextLC( service );
       
   390     
       
   391         item.SetTextL( *info );
       
   392         CleanupStack::PopAndDestroy( info );
       
   393     
       
   394         item.SetIcon( NULL );
       
   395     
       
   396         const TDesC& iconPath = service.GetIconPath();
       
   397         if ( iconPath.Length() > 0 )
       
   398             {
       
   399             iTnManager->AddThumbnailRequestL( *this,
       
   400                                               service.GetIconPath(), 
       
   401                                               CHgDoubleGraphicList::PreferredImageSize(), 
       
   402                                               service.GetServiceId() );
       
   403             }
       
   404         iScroller.RefreshScreen( aIndex );
       
   405         }
       
   406     
       
   407     iListImpl.SetMskL( R_VCXHG_VOD_MSK_BUTTON_OPEN );
       
   408     }
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // 
       
   412 // -----------------------------------------------------------------------------
       
   413 // 
       
   414 void CVcxHgVodServiceGroupListModelHandler::DoThumbnailReadyL( 
       
   415     CGulIcon* aIcon, 
       
   416     TInt64 aClientId )
       
   417     {
       
   418     CleanupStack::PushL( aIcon );
       
   419     TInt index = FindServiceGroupIndex( (TUint32)aClientId, iGroupServices );
       
   420     
       
   421     if ( index >= 0 && iScroller.ItemCount() > index )
       
   422         {
       
   423         iScroller.ItemL( index ).SetIcon( aIcon );
       
   424         iScroller.RefreshScreen( index );
       
   425         CleanupStack::Pop( aIcon );
       
   426         }
       
   427     else
       
   428         {
       
   429         // For some reason the scroller list was update after image conversion
       
   430         // started, and the icon is no longer needed.
       
   431         CleanupStack::PopAndDestroy( aIcon );
       
   432         }
       
   433     }
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 //  
       
   437 // -----------------------------------------------------------------------------
       
   438 //
       
   439 void CVcxHgVodServiceGroupListModelHandler::Request( TInt aBufferStart, 
       
   440     TInt aBufferEnd, THgScrollDirection /*aDirection*/ )
       
   441     {
       
   442     for ( TInt i = aBufferStart; i <= aBufferEnd; i++ )
       
   443         {
       
   444         TRAP_IGNORE( UpdateListItemL( i ) );
       
   445         }
       
   446     }
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 //  
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 void CVcxHgVodServiceGroupListModelHandler::Release( TInt /*aBufferStart*/, 
       
   453     TInt /*aBufferEnd*/ )
       
   454     {
       
   455     // No implementation required.
       
   456     }