videofeeds/vcnsuiengine/src/vcxnscategorytprovider.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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <bldvariant.hrh>
       
    23 #include "CIptvUtil.h"
       
    24 #include "CIptvVodContentCategoryBriefDetails.h"
       
    25 #include "CIptvVodContentClient.h"
       
    26 #include "MIptvVodContentClientObserver.h"
       
    27 #include "TIptvRssSearchQuery.h"
       
    28 #include "vcxnscategoryproviderobserver.h"
       
    29 #include "vcxnscontentclienthandler.h"
       
    30 #include "vcxnscontentsearchhandler.h"
       
    31 #include "vcxnscategoryprovider.h"
       
    32 #include "vcxnsserviceprovider.h"
       
    33 #include "vcxnsuiengine.h"
       
    34 #include "vcxnscategory.h"
       
    35 #include "vcxnsdatalist.h"
       
    36 
       
    37 // CONSTS
       
    38 const TInt KMaxCategoryHistory = 50; 
       
    39 
       
    40 // ============================ MEMBER FUNCTIONS ===============================
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // Default constructor
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CVcxNsCategoryProvider::CVcxNsCategoryProvider( CVcxNsUiEngine& aUiEngine ) : 
       
    47     iUiEngine( aUiEngine )
       
    48     {
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // Constructor
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 CVcxNsCategoryProvider* CVcxNsCategoryProvider::NewL( CVcxNsUiEngine& aUiEngine )
       
    56     {
       
    57     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsCategoryProvider::NewL()");
       
    58     return new (ELeave) CVcxNsCategoryProvider( aUiEngine );
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // Destructor
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CVcxNsCategoryProvider::~CVcxNsCategoryProvider()
       
    66     {
       
    67     iCategoryObservers.Reset();
       
    68     iCategoryListList.ResetAndDestroy();
       
    69     }
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 // Get categories from active service
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 RPointerArray<CVcxNsCategory>& CVcxNsCategoryProvider::GetCategoriesL( TInt& aHighlight )
       
    76     {
       
    77     if ( iUiEngine.ServiceProvider() )
       
    78         {
       
    79         aHighlight = iUiEngine.ServiceProvider()->GetCurrentHighlight();
       
    80         }
       
    81     else
       
    82         {
       
    83         aHighlight = 0;
       
    84         }
       
    85 
       
    86     return GetCategorysL(); 
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // Get categories from active service
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 RPointerArray<CVcxNsCategory>& CVcxNsCategoryProvider::GetCategorysL()
       
    94     {
       
    95     IPTVLOGSTRING_LOW_LEVEL("CVcxNsCategoryProvider::GetCategorysL");
       
    96 
       
    97     for( TInt k = 0; k < iCategoryListList.Count(); k++ )
       
    98         {
       
    99         if( (iCategoryListList[k])->iServiceId == iUiEngine.ActiveService() )
       
   100             {
       
   101             // Sort the data by use order
       
   102             CVcxNsCategoryList* list = iCategoryListList[k];
       
   103             if( k != iCategoryListList.Count()-1 )
       
   104                 {
       
   105                 iCategoryListList.Remove( k );
       
   106                 iCategoryListList.Compress();
       
   107                 iCategoryListList.Append( list );
       
   108                 }
       
   109             return list->iArray;
       
   110             }
       
   111         }
       
   112     
       
   113     // Get the category data from DB
       
   114     RPointerArray<CIptvVodContentCategoryBriefDetails> catList;
       
   115     
       
   116     TInt error = iUiEngine.GetContentClientHandlerL()->
       
   117                      GetVodContentClientL( iUiEngine.ActiveService() )->
       
   118                          GetEcgCategoryListL( KIptvVodContentCategoryRootId, catList );
       
   119     
       
   120     
       
   121     // If cache is already full, remove the oldest data.
       
   122     if( iCategoryListList.Count() >= KMaxCategoryHistory )
       
   123         {
       
   124         delete iCategoryListList[0];
       
   125         iCategoryListList.Remove(0);
       
   126         iCategoryListList.Compress();
       
   127         }
       
   128     
       
   129     // Append the new data to cache
       
   130     CVcxNsCategoryList* entry = new (ELeave) CVcxNsCategoryList;
       
   131     entry->iServiceId = iUiEngine.ActiveService();
       
   132     iCategoryListList.AppendL( entry );
       
   133     RPointerArray<CVcxNsCategory>& categoryList = entry->iArray;
       
   134     
       
   135    // Translate data classes     
       
   136     if ( error == KErrNone )
       
   137         {
       
   138         CVcxNsCategory* category = NULL;
       
   139         
       
   140         for( TInt i = 0; i < catList.Count(); i++ )
       
   141             {
       
   142             category = CVcxNsCategory::NewL();
       
   143             CleanupStack::PushL( category );
       
   144 
       
   145             category->SetNameL( (catList[i])->iName );
       
   146             category->SetCategoryId( (catList[i])->iCategoryId );
       
   147             category->SetVideoCount( (catList[i])->iContentCount );
       
   148             
       
   149             if( category->GetCategoryId() == KIptvRssSearchCategoryId )
       
   150                 {
       
   151                 // Search is always first.
       
   152                 categoryList.Insert( category, 0 ); 
       
   153                 CleanupStack::Pop( category );                
       
   154                 }
       
   155             else
       
   156                 {
       
   157                 categoryList.AppendL( category );
       
   158                 CleanupStack::Pop( category );                
       
   159                 }
       
   160             }
       
   161         }
       
   162     catList.ResetAndDestroy();
       
   163 
       
   164     return categoryList;
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // Open category
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 void CVcxNsCategoryProvider::OpenCategoryL( TInt aIndex )
       
   172     {
       
   173     IPTVLOGSTRING_LOW_LEVEL("CVcxNsCategoryProvider::OpenCategoryL");
       
   174 
       
   175     RPointerArray<CVcxNsCategory>* categoryList = &GetCategorysL();
       
   176     
       
   177     if( aIndex >= 0 && aIndex < (*categoryList).Count() )
       
   178         {
       
   179         CVcxNsCategory* categoryData = (*categoryList)[aIndex];
       
   180 
       
   181         if ( ( categoryData->GetCategoryId() == KIptvRssSearchCategoryId )
       
   182               && ( categoryData->GetVideoCount() <= 0 ) )
       
   183             {
       
   184             //Start new search
       
   185             iUiEngine.GetContentSearchHandlerL()->StartNewSearchL();
       
   186             }
       
   187         else
       
   188             {
       
   189             iUiEngine.SetActiveCategory ( categoryData->GetCategoryId() ); 
       
   190             iUiEngine.SetVcAppState( EStateContentView );
       
   191             }
       
   192         }
       
   193     }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // Get active category data
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 CVcxNsCategory* CVcxNsCategoryProvider::GetActiveCategoryDataL( )
       
   200     {
       
   201     TUint32 activeCategory = iUiEngine.ActiveCategory();
       
   202     
       
   203     //Get list of categories from active service
       
   204     RPointerArray<CVcxNsCategory>* categoryList = &GetCategorysL();
       
   205     
       
   206     for ( TInt i = 0; i < (*categoryList).Count(); i++ )
       
   207         {
       
   208         if ( (*categoryList)[i]->GetCategoryId() == activeCategory )
       
   209             {
       
   210             return (*categoryList)[i];
       
   211             }
       
   212         }
       
   213 
       
   214     return NULL;
       
   215     }
       
   216 
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // Get category data
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 CVcxNsCategory* CVcxNsCategoryProvider::GetCategoryDataL( 
       
   223     TUint32 aServiceId, 
       
   224     TUint32 aCategoryId )
       
   225     {
       
   226     if ( aServiceId == iUiEngine.ActiveService() )
       
   227         {
       
   228         //Get list of categories from active service
       
   229         RPointerArray<CVcxNsCategory>* categoryList = &GetCategorysL();
       
   230         
       
   231         for ( TInt i = 0; i < (*categoryList).Count(); i++ )
       
   232             {
       
   233             if ( (*categoryList)[i]->GetCategoryId() == aCategoryId )
       
   234                 {
       
   235                 return (*categoryList)[i];
       
   236                 }
       
   237             }
       
   238 
       
   239         return NULL;
       
   240         }
       
   241     else
       
   242         {
       
   243         // Check, if category data exists
       
   244         for( TInt k = 0; k < iCategoryListList.Count(); k++ )
       
   245             {
       
   246             if( ( iCategoryListList[k])->iServiceId == aServiceId )
       
   247                 {
       
   248                 // Sort the data by use order
       
   249                 CVcxNsCategoryList* list = iCategoryListList[k];
       
   250                 if ( list )
       
   251                     {
       
   252                     for ( TInt ind = 0; ind < list->iArray.Count(); ind++ )
       
   253                         {
       
   254                         if ( (list->iArray[ind])->GetCategoryId() == aCategoryId )
       
   255                             {
       
   256                             return list->iArray[ind];
       
   257                             }
       
   258                         }
       
   259                     }
       
   260                 }
       
   261             }
       
   262 
       
   263         // GetCategorysL() includes same kind of implementation that follows,
       
   264         // Check and modify to one method
       
   265         
       
   266         // Get the category data from DB
       
   267         RPointerArray<CIptvVodContentCategoryBriefDetails> catList;
       
   268         
       
   269         TInt error = iUiEngine.GetContentClientHandlerL()->
       
   270                          GetVodContentClientL( aServiceId )->
       
   271                              GetEcgCategoryListL( KIptvVodContentCategoryRootId, catList );
       
   272         
       
   273         // If cache is already full, remove the oldest data.
       
   274         if( iCategoryListList.Count() >= KMaxCategoryHistory )
       
   275             {
       
   276             delete iCategoryListList[0];
       
   277             iCategoryListList.Remove(0);
       
   278             iCategoryListList.Compress();
       
   279             }
       
   280         
       
   281         // Append the new data to cache
       
   282         CVcxNsCategoryList* entry = new (ELeave) CVcxNsCategoryList;
       
   283         entry->iServiceId = aServiceId;
       
   284         iCategoryListList.AppendL( entry );
       
   285         RPointerArray<CVcxNsCategory>& categoryList = entry->iArray;
       
   286         
       
   287         CVcxNsCategory* toReturn = NULL;
       
   288        // Translate data classes     
       
   289         if ( error == KErrNone )
       
   290             {
       
   291             CVcxNsCategory* category = NULL;
       
   292             
       
   293             for( TInt i = 0; i < catList.Count(); i++ )
       
   294                 {
       
   295                 category = CVcxNsCategory::NewL();
       
   296                 CleanupStack::PushL( category );
       
   297 
       
   298                 category->SetNameL( (catList[i])->iName );
       
   299                 category->SetCategoryId( (catList[i])->iCategoryId );
       
   300                 category->SetVideoCount( (catList[i])->iContentCount );
       
   301                 
       
   302                 if( category->GetCategoryId() == KIptvRssSearchCategoryId )
       
   303                     {
       
   304                     // Search is always first.
       
   305                     categoryList.Insert( category, 0 ); 
       
   306                     CleanupStack::Pop( category );                
       
   307                     }
       
   308                 else
       
   309                     {
       
   310                     categoryList.AppendL( category );
       
   311                     CleanupStack::Pop( category );                
       
   312                     }
       
   313                 
       
   314                 if ( category->GetCategoryId() == aCategoryId )
       
   315                     {
       
   316                     toReturn = category;
       
   317                     }
       
   318                 }
       
   319             }
       
   320         catList.ResetAndDestroy();
       
   321         return toReturn;
       
   322         }
       
   323 
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CVcxNsCategoryProvider::GetCurrentHighlight
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 TInt CVcxNsCategoryProvider::GetCurrentHighlightL()
       
   331     {
       
   332     CVcxNsCategory* category = GetActiveCategoryDataL();
       
   333     if ( category )
       
   334         {
       
   335         return category->HighlightContentIndex();
       
   336         }
       
   337 
       
   338     return 0;
       
   339     }
       
   340 
       
   341 // -----------------------------------------------------------------------------
       
   342 // CVcxNsCategoryProvider::SetCurrentHighlight
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 void CVcxNsCategoryProvider::SetCurrentHighlightL( TInt aIndex )
       
   346     {
       
   347     CVcxNsCategory* category = GetActiveCategoryDataL();
       
   348     if ( category )
       
   349         {
       
   350         return category->SetHighlightContentIndex( aIndex );
       
   351         }
       
   352     }
       
   353 
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // Update active category data
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 void CVcxNsCategoryProvider::UpdateActiveCategoryDataL( 
       
   360    CVcxNsCategory& aCategory )
       
   361     {
       
   362     IPTVLOGSTRING_LOW_LEVEL("CVcxNsCategoryProvider::UpdateActiveCategoryDataL");
       
   363 
       
   364     TUint32 activeCategory = iUiEngine.ActiveCategory();
       
   365     
       
   366     if ( activeCategory == aCategory.GetCategoryId() )
       
   367         {
       
   368         //Get list of categories from active service
       
   369         RPointerArray<CVcxNsCategory>* categoryList = &GetCategorysL();
       
   370     
       
   371         for ( TInt i = 0; i < (*categoryList).Count(); i++ )
       
   372             {
       
   373             if ( (*categoryList)[i]->GetCategoryId() == activeCategory )
       
   374                 {
       
   375                 (*categoryList)[i]->SetVideoCount( aCategory.GetVideoCount() );
       
   376                 }
       
   377             }
       
   378         }
       
   379     }
       
   380 // -----------------------------------------------------------------------------
       
   381 // Remove category data from specified service
       
   382 // -----------------------------------------------------------------------------
       
   383 //
       
   384 void CVcxNsCategoryProvider::RemoveServiceData( TUint32 aServiceId )
       
   385     {
       
   386     IPTVLOGSTRING_LOW_LEVEL("CVcxNsCategoryProvider::RemoveServiceData");
       
   387     for( TInt k = 0; k < iCategoryListList.Count(); k++ )
       
   388         {
       
   389         if( (iCategoryListList[k])->iServiceId == aServiceId )
       
   390             {
       
   391             delete (iCategoryListList[k]);
       
   392             iCategoryListList.Remove( k );
       
   393             iCategoryListList.Compress();
       
   394             }
       
   395         }
       
   396     }
       
   397 
       
   398 // -----------------------------------------------------------------------------
       
   399 // Update active service
       
   400 // -----------------------------------------------------------------------------
       
   401 //
       
   402 TInt CVcxNsCategoryProvider::RefreshCategorysL()
       
   403     {
       
   404     return iUiEngine.GetContentClientHandlerL()->UpdateEcgL( iUiEngine.ActiveService() );
       
   405     }
       
   406 
       
   407 // -----------------------------------------------------------------------------
       
   408 // Register observer
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 void CVcxNsCategoryProvider::RegisterObserver( 
       
   412     MVcxNsCategoryProviderObserver* aObserver )
       
   413     {
       
   414     for ( TInt i = 0; i < iCategoryObservers.Count(); i++ )
       
   415         {
       
   416         if( iCategoryObservers[i] == aObserver )
       
   417             {
       
   418             return;
       
   419             }
       
   420         }
       
   421     
       
   422     iCategoryObservers.Append(aObserver);
       
   423     }
       
   424 
       
   425 // -----------------------------------------------------------------------------
       
   426 // Unregister observer
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 void CVcxNsCategoryProvider::DeRegisterObserver( 
       
   430     MVcxNsCategoryProviderObserver* aObserver )
       
   431     {
       
   432     for ( TInt i = 0; i < iCategoryObservers.Count(); i++ )
       
   433         {
       
   434         if( iCategoryObservers[i] == aObserver )
       
   435             {
       
   436             iCategoryObservers.Remove( i );
       
   437             iCategoryObservers.Compress();
       
   438             }
       
   439         }
       
   440     }
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CVcxNsCategoryProvider::CategoryUpdated()
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 void CVcxNsCategoryProvider::CategoryUpdated( TInt aIndex )
       
   447     {
       
   448     IPTVLOGSTRING_LOW_LEVEL("CVcxNsCategoryProvider::CategoryUpdated");
       
   449     for ( TInt i = 0; i < iCategoryObservers.Count(); i++ )
       
   450         {
       
   451         if( iCategoryObservers[i] )
       
   452             {
       
   453             iCategoryObservers[i]->CategoryUpdated( aIndex );
       
   454             }
       
   455         }
       
   456     }
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // CVcxNsCategoryProvider::RefreshView()
       
   460 // -----------------------------------------------------------------------------
       
   461 //
       
   462 void CVcxNsCategoryProvider::RefreshView()
       
   463     {
       
   464     IPTVLOGSTRING_LOW_LEVEL("CVcxNsCategoryProvider::RefreshView");
       
   465     for ( TInt i = 0; i < iCategoryObservers.Count(); i++ )
       
   466         {
       
   467         if( iCategoryObservers[i] )
       
   468             {
       
   469             iCategoryObservers[i]->RefreshView();
       
   470             }
       
   471         }   
       
   472     }
       
   473 
       
   474 // -----------------------------------------------------------------------------
       
   475 // CVcxNsCategoryProvider::HandleAppStateChangedL()
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 void CVcxNsCategoryProvider::HandleAppStateChangedL()
       
   479     {
       
   480     IPTVLOGSTRING_LOW_LEVEL("CVcxNsCategoryProvider::HandleAppStateChangedL");
       
   481     for ( TInt i = 0; i < iCategoryObservers.Count(); i++ )
       
   482         {
       
   483         if( iCategoryObservers[i] )
       
   484             {
       
   485             iCategoryObservers[i]->HandleAppStateChangedL();
       
   486             }
       
   487         }
       
   488     }
       
   489 
       
   490 // -----------------------------------------------------------------------------
       
   491 // CVcxNsCategoryProvider::ShowUpdatingNoteL()
       
   492 // -----------------------------------------------------------------------------
       
   493 //
       
   494 void CVcxNsCategoryProvider::ShowUpdatingNoteL( TBool aShow, TInt aDownloadedTbns, TInt aTotalTbns )
       
   495     {
       
   496     IPTVLOGSTRING_LOW_LEVEL("CVcxNsCategoryProvider::ShowUpdatingNote");
       
   497     for ( TInt i = 0; i < iCategoryObservers.Count(); i++ )
       
   498         {
       
   499         if( iCategoryObservers[i] )
       
   500             {
       
   501             iCategoryObservers[i]->ShowUpdatingNoteL( aShow, aDownloadedTbns, aTotalTbns );
       
   502             }
       
   503         }       
       
   504     }
       
   505 
       
   506 // -----------------------------------------------------------------------------
       
   507 // CVcxNsCategoryProvider::HandleErrorL()
       
   508 // -----------------------------------------------------------------------------
       
   509 //
       
   510 void CVcxNsCategoryProvider::HandleErrorL( 
       
   511     TInt aError,
       
   512     TUint32 aServiceId )
       
   513     {
       
   514     for ( TInt i = 0; i < iCategoryObservers.Count(); i++ )
       
   515         {
       
   516         if( iCategoryObservers[i] && 
       
   517               aServiceId == iUiEngine.ActiveService() )
       
   518             {
       
   519             iCategoryObservers[i]->HandleUpdateErrorL( aError );
       
   520             }
       
   521         }
       
   522     }
       
   523 
       
   524 // -----------------------------------------------------------------------------
       
   525 // Set highlighted category index for active service
       
   526 // -----------------------------------------------------------------------------
       
   527 //
       
   528 void CVcxNsCategoryProvider::SetCategoryHighlight( TInt aHighlight )
       
   529     {
       
   530     if ( iUiEngine.ServiceProvider() )
       
   531         {
       
   532         if ( aHighlight >= 0 )
       
   533             {
       
   534             iUiEngine.ServiceProvider()->SetCurrentHighlight( aHighlight );
       
   535             }
       
   536         else
       
   537             {
       
   538             iUiEngine.ServiceProvider()->SetCurrentHighlight( 0 );
       
   539             }
       
   540         }
       
   541     }