videofeeds/vcnsuiengine/src/vcxnscontentsearchhandler.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:    Content search functionality*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <bldvariant.hrh>
       
    22 #include "IptvDebug.h"
       
    23 #include "TIptvRssSearchQuery.h"
       
    24 
       
    25 #include "CIptvVodContentClient.h"
       
    26 #include "vcxnscontentsearchobserver.h"
       
    27 #include "vcxnscontentclienthandler.h"
       
    28 #include "vcxnscontentsearchhandler.h"
       
    29 #include "vcxnsuiengine.h"
       
    30 #include "vcxnscategory.h"
       
    31 #include "vcxnscategoryprovider.h"
       
    32 #include "vcxnscontentprovider.h"
       
    33 #include "vcxnsserviceprovider.h"
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CVcxNsContentSearchHandler::CVcxNsContentSearchHandler()
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CVcxNsContentSearchHandler::CVcxNsContentSearchHandler( 
       
    42     CVcxNsUiEngine& aUiEngine ) 
       
    43 :   iUiEngine( aUiEngine )
       
    44     {
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CVcxNsContentSearchHandler::NewL()
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CVcxNsContentSearchHandler* CVcxNsContentSearchHandler::NewL( 
       
    52     CVcxNsUiEngine& aUiEngine )
       
    53     {
       
    54     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsContentSearchHandler::NewL()");
       
    55     
       
    56     return new (ELeave) CVcxNsContentSearchHandler( aUiEngine );
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CVcxNsContentSearchHandler::~CVcxNsContentSearchHandler()
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CVcxNsContentSearchHandler::~CVcxNsContentSearchHandler()
       
    64     {
       
    65     iSearchObservers.Reset();
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CVcxNsContentSearchHandler::StartNewSearchL()
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CVcxNsContentSearchHandler::StartNewSearchL()
       
    73     {
       
    74     for (TInt i = 0; i < iSearchObservers.Count(); i++ )
       
    75         {
       
    76         iSearchObservers[i]->StartSearchL( EFalse );
       
    77         }
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CVcxNsContentSearchHandler::SearchL()
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CVcxNsContentSearchHandler::SearchL( const TDesC& aSearchString )
       
    85     {
       
    86     CIptvVodContentClient* contentClient ( 
       
    87         iUiEngine.GetContentClientHandlerL()->GetVodContentClientL( 
       
    88                                              iUiEngine.ActiveService()));
       
    89     if ( contentClient )
       
    90         {
       
    91         TIptvRssSearchQuery query;
       
    92         // Set search string does not really change the given descriptor.
       
    93         query.SetSearchString( const_cast<TDesC&>( aSearchString ) );
       
    94         contentClient->Search( query );
       
    95         }
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CVcxNsContentSearchHandler::CancelSearchL()
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CVcxNsContentSearchHandler::CancelSearchL()
       
   103     {
       
   104     CIptvVodContentClient* contentClient ( 
       
   105         iUiEngine.GetContentClientHandlerL()->GetVodContentClientL( 
       
   106                                              iUiEngine.ActiveService()));
       
   107     if ( contentClient )
       
   108         {
       
   109         contentClient->CancelSearch( );
       
   110         }
       
   111     
       
   112     UpdateCategoryVideoCountL();
       
   113     SearchCancelled();
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CVcxNsContentSearchHandler::HandleSearchMsgL()
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 void CVcxNsContentSearchHandler::HandleSearchMsgL( TInt aStatus, TInt aInfo )
       
   121     {
       
   122     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsContentSearchHandler::HandleSearchMsgL()");
       
   123     
       
   124     TVcxNsAppState appState = iUiEngine.VcAppState();
       
   125     
       
   126     switch ( aStatus )
       
   127         {
       
   128         case KIptvErrorRssSearchNoIap: 
       
   129             {
       
   130             //KIptvErrorRssSearchNoIap was handled earlier, and if status comes
       
   131             //to this point, start search again.
       
   132             IPTVLOGSTRING_HIGH_LEVEL("UI Engine ##  IAP selected, start search again");
       
   133             for (TInt i = 0; i < iSearchObservers.Count(); i++ )
       
   134                 {
       
   135                 iSearchObservers[i]->StartSearchL( ETrue );
       
   136                 }
       
   137             }
       
   138             break;
       
   139         case KIptvErrorRssSearchStarted:
       
   140             {
       
   141             IPTVLOGSTRING_HIGH_LEVEL("UI Engine ##  Search Started ");
       
   142             ShowInfoPopupL( EFalse );
       
   143             
       
   144             for (TInt i = 0; i < iSearchObservers.Count(); i++ )
       
   145                 {
       
   146                 iSearchObservers[i]->SearchStartedL();
       
   147                 }
       
   148 
       
   149             //When new search has started, empty existing search result list.
       
   150             if ( iUiEngine.ContentProvider() )
       
   151                 {
       
   152                 iUiEngine.ContentProvider()->RemoveCategoryData( 
       
   153                         iUiEngine.ActiveService(), KIptvRssSearchCategoryId );
       
   154                 }
       
   155                 
       
   156             if ( appState == EStateContentView &&
       
   157                  iUiEngine.ContentProvider() &&                                           
       
   158                  iUiEngine.ActiveCategory() == KIptvRssSearchCategoryId )
       
   159                 {
       
   160                 iUiEngine.ContentProvider()->RefreshView();
       
   161                 }
       
   162             }
       
   163             break;
       
   164             
       
   165         case KIptvErrorRssSearchFailed:
       
   166             {
       
   167             IPTVLOGSTRING_HIGH_LEVEL("UI Engine ##  Search Failed ");
       
   168             ShowInfoPopupL( EFalse );
       
   169             
       
   170             for (TInt i = 0; i < iSearchObservers.Count(); i++ )
       
   171                 {
       
   172                 iSearchObservers[i]->HandleSearchResultL( EFalse );
       
   173                 }            
       
   174             }
       
   175             break;
       
   176             
       
   177         case KIptvErrorRssSearchSucceed:
       
   178             {
       
   179             IPTVLOGSTRING_HIGH_LEVEL("UI Engine ##  Search Succeeded ");
       
   180             ShowInfoPopupL( EFalse );
       
   181             
       
   182             if ( appState == EStateContentView &&
       
   183                  iUiEngine.ContentProvider() &&
       
   184                  iUiEngine.ActiveCategory() == KIptvRssSearchCategoryId )
       
   185                 {
       
   186                 iUiEngine.ContentProvider()->UpdateIconsPathL();
       
   187                 iUiEngine.ContentProvider()->RefreshView();
       
   188                 }
       
   189             }
       
   190             break;
       
   191 
       
   192         case KIptvRssSearchContentUpdateCompleted:
       
   193             {
       
   194             IPTVLOGSTRING_HIGH_LEVEL("UI Engine ##  Search content update completed ");
       
   195 
       
   196             //Remove category data again to make sure that we have valid cache for search results
       
   197             if ( iUiEngine.ContentProvider() )
       
   198                 {
       
   199                 iUiEngine.ContentProvider()->RemoveCategoryData( iUiEngine.ActiveService(),
       
   200                                                                  KIptvRssSearchCategoryId );
       
   201                 }
       
   202 
       
   203             //Category state: Switch to content state, set search category as active category
       
   204             //Content state: List contents (refresh view) with search results 
       
   205             
       
   206             for (TInt i = 0; i < iSearchObservers.Count(); i++ )
       
   207                 {
       
   208                 iSearchObservers[i]->HandleSearchResultL( ETrue );
       
   209                 }
       
   210             
       
   211             if ( appState == EStateCategoryView )
       
   212                 {
       
   213                 iUiEngine.SetActiveCategory ( KIptvRssSearchCategoryId );        
       
   214                 iUiEngine.SetVcAppState( EStateContentView );
       
   215                 iUiEngine.CategoryProvider()->HandleAppStateChangedL();
       
   216                 }
       
   217             else if ( appState == EStateCustomView  )                
       
   218                 {
       
   219                 iUiEngine.SetActiveCategory ( KIptvRssSearchCategoryId );        
       
   220                 iUiEngine.SetVcAppState( EStateContentView );
       
   221                 iUiEngine.ServiceProvider()->HandleAppStateChangedL();                
       
   222                 }
       
   223             else if ( appState == EStateContentView )
       
   224                 {
       
   225                 iUiEngine.ContentProvider()->RefreshView();
       
   226                 }
       
   227 
       
   228             UpdateCategoryVideoCountL();
       
   229             }
       
   230             break;
       
   231 
       
   232         case KIptvRssSearchThumbnailCount:
       
   233             {
       
   234             IPTVLOGSTRING2_HIGH_LEVEL("UI Engine ##  Search thumbnail count %d", aInfo);
       
   235             iThumbnailCount = aInfo;
       
   236             ShowInfoPopupL( ETrue );
       
   237             }
       
   238             break;
       
   239 
       
   240         case KIptvRssSearchContentThumbnailDownloaded:
       
   241             {
       
   242             iThumbnailsDownloaded++;
       
   243             IPTVLOGSTRING2_HIGH_LEVEL("UI Engine ##  Search thumbnail %d downloaded", iThumbnailsDownloaded);
       
   244             ShowInfoPopupL( ETrue );
       
   245             }
       
   246             break;
       
   247 
       
   248         default:
       
   249             break;
       
   250         }
       
   251 
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CVcxNsContentSearchHandler::RegisterObserver()
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CVcxNsContentSearchHandler::RegisterObserver( MVcxNsContentSearchObserver* aObserver )
       
   259     {
       
   260     // should use find instead of loop
       
   261     for ( TInt i = 0; i < iSearchObservers.Count(); i++ )
       
   262         {
       
   263         if( iSearchObservers[i] == aObserver )
       
   264             {
       
   265             return;
       
   266             }
       
   267         }
       
   268     
       
   269     iSearchObservers.Append( aObserver );
       
   270     }
       
   271 
       
   272 // -----------------------------------------------------------------------------
       
   273 // CVcxNsContentSearchHandler::DeRegisterObserver()
       
   274 // -----------------------------------------------------------------------------
       
   275 //
       
   276 void CVcxNsContentSearchHandler::DeRegisterObserver( MVcxNsContentSearchObserver* aObserver )
       
   277     {
       
   278     // should use find instead of loop
       
   279     for ( TInt i = 0; i < iSearchObservers.Count(); i++ )
       
   280         {
       
   281         if( iSearchObservers[i] == aObserver )
       
   282             {
       
   283             iSearchObservers.Remove( i );
       
   284             iSearchObservers.Compress();
       
   285             }
       
   286         }
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CVcxNsContentSearchHandler::UpdateCategoryVideoCountL()
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CVcxNsContentSearchHandler::UpdateCategoryVideoCountL( )
       
   294     {
       
   295     //Category's video count needs to be updated to keep search 
       
   296     //category's video count in UI up to date.
       
   297     //Other categories are updated during normal content update.
       
   298     CVcxNsCategory* activeCategory =  
       
   299         iUiEngine.GetCategoryProviderL()->GetActiveCategoryDataL();
       
   300     
       
   301     if ( activeCategory )
       
   302         {
       
   303         TInt videoCount = iUiEngine.GetContentProviderL()->GetContentsL().Count();
       
   304         activeCategory->SetVideoCount( videoCount );
       
   305         iUiEngine.CategoryProvider()->UpdateActiveCategoryDataL( *activeCategory );
       
   306         }
       
   307     }
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // Shows thumbnail loading pop-up
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 void CVcxNsContentSearchHandler::ShowInfoPopupL( TBool aVisible )
       
   314     {
       
   315     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentSearchHandler::ShowInfoPopupL");
       
   316     if ( !aVisible )
       
   317         {
       
   318         // Hiding pop-up, so reset the values
       
   319         iThumbnailCount = 0;
       
   320         iThumbnailsDownloaded = 0;
       
   321         }
       
   322 
       
   323     if ( iUiEngine.VcAppState() == EStateContentView && 
       
   324             iUiEngine.ActiveCategory() == KIptvRssSearchCategoryId )
       
   325         {
       
   326         if (  iUiEngine.ContentProvider() && 
       
   327              ( !iUiEngine.ServiceProvider() ||
       
   328                !iUiEngine.ServiceProvider()->GetActiveServiceData() ||
       
   329                 iUiEngine.ServiceProvider()->GetActiveServiceData()->GetUpdateStatus() 
       
   330                 != CVcxNsService::EUpdateOngoing ) )
       
   331             {
       
   332             iUiEngine.ContentProvider()->ShowUpdatingNoteL( 
       
   333                 aVisible, iThumbnailCount, iThumbnailsDownloaded );
       
   334             }
       
   335         }
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // Search cancelled by user
       
   340 // -----------------------------------------------------------------------------
       
   341 //
       
   342 void CVcxNsContentSearchHandler::SearchCancelled( )
       
   343     {
       
   344     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentSearchHandler::SearchCancelled()");
       
   345     if ( iUiEngine.VcAppState() == EStateCustomView && 
       
   346          iUiEngine.ActiveCategory() == KIptvRssSearchCategoryId )
       
   347         {
       
   348         iUiEngine.SetActiveService( iUiEngine.ActiveServiceGroup() );
       
   349         iUiEngine.SetActiveServiceGroup( KMaxTUint );        
       
   350         }
       
   351     }