videofeeds/vcnsuiengine/src/vcxnscontentprovider.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 "IptvDebug.h"
       
    24 
       
    25 #include "CIptvMediaContent.h"
       
    26 #include "IptvLiveDataStructures.h"
       
    27 
       
    28 #include <mpxmediageneraldefs.h>
       
    29 #include <mpxitemid.h>
       
    30 #include <mpxmedia.h>
       
    31 #include "CIptvUtil.h" 
       
    32 
       
    33 #include "CIptvMyVideosGlobalFileId.h"
       
    34 #include "MIptvVodContentClientObserver.h"
       
    35 #include "CIptvVodContentContentBriefDetails.h"
       
    36 #include "CIptvVodContentContentFullDetails.h"
       
    37 #include "CIptvVodContentClient.h"
       
    38 #include "vcxnsserviceprovider.h"
       
    39 #include "vcxnscontentproviderobserver.h"
       
    40 #include "vcxnscontentclienthandler.h"
       
    41 #include "vcxnsmpxcollectionclienthandler.h"
       
    42 #include "vcxnscontentprovider.h"
       
    43 #include "vcxnscategoryprovider.h"
       
    44 #include "vcxnsuiengine.h"
       
    45 #include "vcxnscontent.h"
       
    46 #include "vcxnscontentaccess.h"
       
    47 #include "vcxnsdatalist.h"
       
    48 
       
    49 // CONSTS
       
    50 const TInt KMaxContentHistory = 50; 
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CVcxNsContentProvider::CVcxNsContentProvider()
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CVcxNsContentProvider::CVcxNsContentProvider( CVcxNsUiEngine& aUiEngine ) :
       
    59     iUiEngine( aUiEngine )
       
    60     {
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CVcxNsContentProvider::NewL()
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 CVcxNsContentProvider* CVcxNsContentProvider::NewL( CVcxNsUiEngine& aUiEngine )
       
    68     {
       
    69     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsContentProvider::NewL()");
       
    70     
       
    71     return new (ELeave) CVcxNsContentProvider( aUiEngine );
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CVcxNsContentProvider::~CVcxNsContentProvider()
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CVcxNsContentProvider::~CVcxNsContentProvider()
       
    79     {
       
    80     iContentObservers.Reset();
       
    81     
       
    82     iContentListList.ResetAndDestroy();
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // Get contents for active service and active category
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 RPointerArray<CVcxNsContent>& CVcxNsContentProvider::GetContentsL( TInt& aHighlight )
       
    90     {
       
    91     //Check if current state is content state and last state was category state:
       
    92     
       
    93     if ( iUiEngine.CategoryProvider() )
       
    94         {
       
    95         aHighlight = iUiEngine.CategoryProvider()->GetCurrentHighlightL();
       
    96         }
       
    97     else
       
    98         {
       
    99         aHighlight = 0;
       
   100         }
       
   101     
       
   102     return GetContentsL();
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 // CVcxNsContentProvider::GetContentsL()
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 RPointerArray<CVcxNsContent>& CVcxNsContentProvider::GetContentsL()
       
   110     {
       
   111     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::GetContentsL");
       
   112     
       
   113     //  Dl list does not need to be updated, if fetching same old list again. 
       
   114     if( iPreviousList &&
       
   115         iPreviousList->iServiceId == iUiEngine.ActiveService() &&
       
   116         iPreviousList->iCategoryId == iUiEngine.ActiveCategory() )
       
   117         {
       
   118         return iPreviousList->iArray;
       
   119         }
       
   120     
       
   121     CVcxNsContentList* list = NULL;    
       
   122     
       
   123     list = GetListFromCache();
       
   124     
       
   125     if( !list )
       
   126         {
       
   127         // Reset old download list, items might not be visible anymore.
       
   128         iUiEngine.GetMpxCollectionClientHandlerL()->ResetDownloadList(
       
   129                 EFalse /* don't reset commands from content items */);
       
   130         list = LoadEpgDataL();
       
   131         BuildDownloadListL( list->iArray );
       
   132         iUiEngine.GetMpxCollectionClientHandlerL()->LoadMpxMediaObjectsL();
       
   133         }
       
   134     else
       
   135         {
       
   136         // Reset old download list, items might not be visible anymore.
       
   137         iUiEngine.GetMpxCollectionClientHandlerL()->ResetDownloadList(
       
   138                 ETrue /* reset commands from content items */);
       
   139         BuildDownloadListL( list->iArray );
       
   140         }
       
   141 
       
   142     iPreviousList = list;
       
   143 
       
   144     return list->iArray;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CVcxNsContentProvider::RefreshContentsL()
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 TInt CVcxNsContentProvider::RefreshContentsL()
       
   152     {
       
   153     return iUiEngine.GetContentClientHandlerL()->UpdateEcgL( iUiEngine.ActiveService() );
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CVcxNsContentProvider::StartDownloadL()
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 TInt CVcxNsContentProvider::StartDownloadL( TInt aIndex )
       
   161     {
       
   162     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::StartDownloadL");
       
   163     CVcxNsService* service = ( iUiEngine.GetServiceProviderL()->GetActiveServiceData() );
       
   164     CVcxNsContent* content = NULL;
       
   165     
       
   166     RPointerArray<CVcxNsContent>& contents = GetContentsL();
       
   167     
       
   168     if( service && aIndex >= 0 && aIndex < contents.Count() )
       
   169 	    {
       
   170 	    content = contents[aIndex];
       
   171 	    }
       
   172     else
       
   173         {
       
   174         return KErrArgument;
       
   175         }
       
   176 
       
   177     TInt retVal( KErrNotFound );
       
   178     
       
   179     if( service && content )
       
   180         {
       
   181         retVal = iUiEngine.GetMpxCollectionClientHandlerL()->DownloadL( *service, *content );
       
   182         }
       
   183     
       
   184     return retVal;
       
   185     }
       
   186 
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CVcxNsContentProvider::PauseDownloadL()
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 TInt CVcxNsContentProvider::PauseDownloadL( TInt aIndex )
       
   193     {
       
   194     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::PauseDownloadL");
       
   195     CVcxNsContent* content = NULL;
       
   196     RPointerArray<CVcxNsContent>& contents = GetContentsL();
       
   197     
       
   198     if( aIndex >= 0 && aIndex < contents.Count() )
       
   199         {
       
   200         content = contents[aIndex];
       
   201         }
       
   202     else
       
   203         {
       
   204         return KErrArgument;
       
   205         }
       
   206 
       
   207     TInt retVal( KErrNotFound );
       
   208     
       
   209     if( content )
       
   210         {
       
   211         retVal = iUiEngine.GetMpxCollectionClientHandlerL()->PauseDownloadL( *content );
       
   212         }
       
   213     
       
   214     return retVal;
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CVcxNsContentProvider::ResumeDownloadL()
       
   219 // -----------------------------------------------------------------------------
       
   220 //
       
   221 TInt CVcxNsContentProvider::ResumeDownloadL( TInt aIndex )
       
   222     {
       
   223     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::ResumeDownloadL");
       
   224     CVcxNsContent* content = NULL;
       
   225     RPointerArray<CVcxNsContent>& contents = GetContentsL();
       
   226 
       
   227     
       
   228     if( aIndex >= 0 && aIndex < contents.Count() )
       
   229         {
       
   230         content = contents[aIndex];
       
   231         }
       
   232     else
       
   233         {
       
   234         return KErrArgument;
       
   235         }
       
   236 
       
   237     TInt retVal( KErrNotFound );
       
   238     
       
   239     if( content )
       
   240         {
       
   241         retVal = iUiEngine.GetMpxCollectionClientHandlerL()->ResumeDownloadL( *content );
       
   242         }
       
   243     
       
   244     return retVal;
       
   245     }
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CVcxNsContentProvider::ResumeDownloadL()
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 TInt CVcxNsContentProvider::ResumeDownloadL( CVcxNsContent& aContent )
       
   252     {
       
   253     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::ResumeDownloadL()");
       
   254     
       
   255     if ( iUiEngine.ServiceProvider() )
       
   256         {
       
   257         return iUiEngine.GetMpxCollectionClientHandlerL()->ResumeDownloadL( aContent );
       
   258         }
       
   259     
       
   260     return KErrGeneral;
       
   261     }
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CVcxNsContentProvider::CancelDownloadL()
       
   265 // -----------------------------------------------------------------------------
       
   266 //
       
   267 TInt CVcxNsContentProvider::CancelDownloadL( TInt aIndex )
       
   268     {
       
   269     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::CancelDownloadL");
       
   270     CVcxNsContent* content = NULL;
       
   271     RPointerArray<CVcxNsContent>& contents = GetContentsL();
       
   272 
       
   273     if( aIndex >= 0 && aIndex < contents.Count() )
       
   274         {
       
   275         content = contents[aIndex];
       
   276         }
       
   277     else
       
   278         {
       
   279         return KErrArgument;
       
   280         }
       
   281 
       
   282     TInt retVal( KErrNotFound );
       
   283 
       
   284     if( content )
       
   285         {
       
   286         retVal = iUiEngine.GetMpxCollectionClientHandlerL()->CancelDownloadL( *content );
       
   287         }
       
   288 
       
   289     return retVal;
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CVcxNsContentProvider::RemoveServiceData
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 void CVcxNsContentProvider::RemoveServiceData( TUint32 aServiceId )
       
   297     {
       
   298     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::RemoveServiceData");
       
   299     
       
   300     if( iPreviousList && iPreviousList->iServiceId == aServiceId )
       
   301         {
       
   302         iPreviousList = NULL;
       
   303         }
       
   304     
       
   305     for( TInt k = 0; k < iContentListList.Count(); k++ )
       
   306         {
       
   307         if( (iContentListList[k])->iServiceId == aServiceId )
       
   308             {
       
   309             delete (iContentListList[k]);
       
   310             iContentListList.Remove( k );
       
   311             iContentListList.Compress();
       
   312             }
       
   313         }
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CVcxNsContentProvider::RemoveCategoryData
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 void CVcxNsContentProvider::RemoveCategoryData( 
       
   321     TUint32 aServiceId, 
       
   322     TUint32 aCategoryId )
       
   323     {
       
   324     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::RemoveCategoryData");
       
   325 
       
   326     if( iPreviousList && iPreviousList->iServiceId == aServiceId )
       
   327         {
       
   328         iPreviousList = NULL;
       
   329         }
       
   330 
       
   331     for( TInt k = 0; k < iContentListList.Count(); k++ )
       
   332         {
       
   333         if( (iContentListList[k])->iServiceId == aServiceId
       
   334                 && (iContentListList[k])->iCategoryId == aCategoryId )
       
   335             {
       
   336             delete (iContentListList[k]);
       
   337             iContentListList.Remove( k );
       
   338             iContentListList.Compress();
       
   339             }
       
   340         }
       
   341     }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CVcxNsContentProvider::RegisterObserver()
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void CVcxNsContentProvider::RegisterObserver( MVcxNsContentProviderObserver* aObserver )
       
   348     {
       
   349     for ( TInt i = 0; i < iContentObservers.Count(); i++ )
       
   350         {
       
   351         if( iContentObservers[i] == aObserver )
       
   352             {
       
   353             return;
       
   354             }
       
   355         }
       
   356     
       
   357     iContentObservers.Append( aObserver );
       
   358     }
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CVcxNsContentProvider::DeRegisterObserver()
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 void CVcxNsContentProvider::DeRegisterObserver( MVcxNsContentProviderObserver* aObserver )
       
   365     {
       
   366     for ( TInt i = 0; i < iContentObservers.Count(); i++ )
       
   367         {
       
   368         if( iContentObservers[i] == aObserver )
       
   369             {
       
   370             iContentObservers.Remove( i );
       
   371             
       
   372             iContentObservers.Compress();
       
   373             }
       
   374         }
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CVcxNsContentProvider::ContentUpdated()
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 void CVcxNsContentProvider::ContentUpdated( TInt aIndex )
       
   382     {
       
   383     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::ContentUpdated");
       
   384     
       
   385     for ( TInt i = 0; i < iContentObservers.Count(); i++ )
       
   386         {
       
   387         if( iContentObservers[i] )
       
   388             {
       
   389             iContentObservers[i]->ContentUpdated( aIndex );
       
   390             }
       
   391         }
       
   392     }
       
   393 
       
   394 // -----------------------------------------------------------------------------
       
   395 // CVcxNsContentProvider::RefreshView()
       
   396 // -----------------------------------------------------------------------------
       
   397 //
       
   398 void CVcxNsContentProvider::RefreshView()
       
   399     {
       
   400     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::RefreshView");
       
   401     for ( TInt i = 0; i < iContentObservers.Count(); i++ )
       
   402         {
       
   403         if( iContentObservers[i] )
       
   404             {
       
   405             iContentObservers[i]->RefreshView();
       
   406             }
       
   407         }
       
   408     }
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // CVcxNsContentProvider::UpdateIconsPathL()
       
   412 // -----------------------------------------------------------------------------
       
   413 //
       
   414 void CVcxNsContentProvider::UpdateIconsPathL()
       
   415     {
       
   416     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::UpdateIconsPathL");
       
   417     
       
   418     CVcxNsContentList* list = NULL; 
       
   419     list = LoadEpgDataL();
       
   420     
       
   421     if ( list && iPreviousList )
       
   422         {
       
   423         for ( TInt i = 0; i < list->iArray.Count(); i++ )
       
   424             {
       
   425             for ( TInt j = 0; j < iPreviousList->iArray.Count(); j++ )
       
   426                 {
       
   427                 if ( ( iPreviousList->iArray[j]->GetContentId() == list->iArray[i]->GetContentId() ) && 
       
   428                      ( iPreviousList->iArray[j]->GetServiceId() == list->iArray[i]->GetServiceId() ) )
       
   429                     {
       
   430                     iPreviousList->iArray[j]->SetIconPathL( list->iArray[i]->GetIconPath() );        
       
   431                     break;
       
   432                     }
       
   433                 }       
       
   434             }
       
   435         }
       
   436     }
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // CVcxNsContentProvider::HandleAppStateChanged()
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 void CVcxNsContentProvider::HandleAppStateChangedL()
       
   443     {
       
   444     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::HandleAppStateChangedL");
       
   445     for ( TInt i = 0; i < iContentObservers.Count(); i++ )
       
   446         {
       
   447         if( iContentObservers[i] )
       
   448             {
       
   449             iContentObservers[i]->HandleAppStateChangedL();
       
   450             }
       
   451         }
       
   452     }
       
   453 
       
   454 // -----------------------------------------------------------------------------
       
   455 // CVcxNsContentProvider::SearchContentByUri()
       
   456 // -----------------------------------------------------------------------------
       
   457 //
       
   458 CVcxNsContent* CVcxNsContentProvider::SearchContentByUri( const TDesC& aUri )
       
   459     {
       
   460     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::SearchContentByUri IN");
       
   461     for( TInt i = iContentListList.Count()-1; i >= 0 ; i-- )
       
   462         {
       
   463         // improve nested loops
       
   464         for( TInt j = (iContentListList[i])->iArray.Count()-1; j >= 0 ; j-- )
       
   465             {
       
   466             TPtrC contentUri = TPtrC( ((iContentListList[i])->iArray[j])->GetUrl( CVcxNsContent::EVcxContentTypeVideo ) );
       
   467             
       
   468             if ( contentUri.CompareF( aUri ) == 0 )
       
   469                 {
       
   470                 IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::SearchContentByUri OUT");
       
   471                 return (iContentListList[i])->iArray[j];
       
   472                 }
       
   473             }
       
   474         }
       
   475     
       
   476     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::SearchContentByUri OUT");
       
   477     return NULL;
       
   478     }
       
   479 
       
   480 // -----------------------------------------------------------------------------
       
   481 // CVcxNsContentProvider::SearchContentByMpxId()
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 CVcxNsContent* CVcxNsContentProvider::SearchContentByMpxId( TMPXItemId aItemId )
       
   485     {
       
   486     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::SearchContentByMpxId IN");
       
   487     CVcxNsContent* content = NULL;
       
   488     
       
   489     for( TInt i = iContentListList.Count()-1; i >= 0 ; i-- )
       
   490         {
       
   491         for( TInt j = (iContentListList[i])->iArray.Count()-1; j >= 0 ; j-- )
       
   492             {
       
   493             CMPXMedia* media = ((iContentListList[i])->iArray[j])->GetMpxMedia( CVcxNsContent::EVcxContentTypeVideo );
       
   494             TUint32 mediaId = aItemId.iId1;
       
   495             
       
   496             if( media )
       
   497                 {
       
   498                 TUint32 contentsId = media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ).iId1;
       
   499                 
       
   500                 if ( mediaId == contentsId )
       
   501                     {
       
   502                     content = (iContentListList[i])->iArray[j];
       
   503                     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::SearchContentByMpxId OUT, id found from mpx data");
       
   504 				    return content;
       
   505                     }
       
   506                 }
       
   507             else if ( ((iContentListList[i])->iArray[j])->GetMpxId( CVcxNsContent::EVcxContentTypeVideo ) && 
       
   508                       ((iContentListList[i])->iArray[j])->GetMpxId( CVcxNsContent::EVcxContentTypeVideo ) == mediaId )
       
   509                 {
       
   510                 content = (iContentListList[i])->iArray[j];
       
   511                 IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::SearchContentByMpxId OUT, found by stored mpx id ");
       
   512                 return content;
       
   513                 }
       
   514             }
       
   515         }
       
   516 
       
   517     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::SearchContentByMpxId OUT");
       
   518     return NULL;
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CVcxNsContentProvider::SearchContentById()
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 CVcxNsContent* CVcxNsContentProvider::SearchContentById( TUint32 aServiceId, 
       
   526                                                          TUint32 aContentId )
       
   527     {
       
   528     // improve nested loops
       
   529     for( TInt i = iContentListList.Count()-1; i >= 0 ; i-- )
       
   530         {
       
   531         if( (iContentListList[i])->iServiceId == aServiceId )
       
   532             {
       
   533             for( TInt j = (iContentListList[i])->iArray.Count()-1; j >= 0 ; j-- )
       
   534                 {
       
   535                 if (((iContentListList[i])->iArray[j])->GetContentId() == aContentId )
       
   536                     {
       
   537                     return (iContentListList[i])->iArray[j];
       
   538                     }
       
   539                 }            
       
   540             }
       
   541         }
       
   542     return NULL;
       
   543     }
       
   544 
       
   545 // -----------------------------------------------------------------------------
       
   546 // CVcxNsContentProvider::ContentIndex()
       
   547 // -----------------------------------------------------------------------------
       
   548 //
       
   549 TInt CVcxNsContentProvider::ContentIndex( CVcxNsContent* aContent )
       
   550     {
       
   551     if( !aContent )
       
   552         {
       
   553         return KErrArgument;
       
   554         }
       
   555 
       
   556     for( TInt i = iContentListList.Count()-1; i >= 0 ; i-- )
       
   557         {
       
   558         if( iUiEngine.ActiveService() == (iContentListList[i])->iServiceId && 
       
   559             iUiEngine.ActiveCategory() == (iContentListList[i])->iCategoryId )
       
   560             {
       
   561             for( TInt j = (iContentListList[i])->iArray.Count()-1; j >= 0 ; j-- )
       
   562                 {
       
   563                 if ( ((iContentListList[i])->iArray[j])->GetContentId() == aContent->GetContentId() )
       
   564                     {
       
   565                     return j;
       
   566                     }
       
   567                 }
       
   568             break;
       
   569             }
       
   570         }
       
   571     return KErrNotFound;
       
   572     }
       
   573 
       
   574 // -----------------------------------------------------------------------------
       
   575 // CVcxNsContentProvider::UpdateContent()
       
   576 // -----------------------------------------------------------------------------
       
   577 //
       
   578 void CVcxNsContentProvider::UpdateContent( CVcxNsContent* aContentdata )
       
   579     {
       
   580     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::UpdateContent");
       
   581     if( aContentdata )
       
   582         {
       
   583         TInt index = ContentIndex( aContentdata );
       
   584     
       
   585         if( index >= 0 )
       
   586             {
       
   587             ContentUpdated( index );
       
   588             }        
       
   589         }
       
   590     }
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // CVcxNsContentProvider::ShowUpdatingNoteL()
       
   594 // -----------------------------------------------------------------------------
       
   595 //
       
   596 void CVcxNsContentProvider::ShowUpdatingNoteL( 
       
   597     TBool aShow,
       
   598     TInt aDownloadedTbns, 
       
   599     TInt aTotalTbns )
       
   600     {
       
   601     IPTVLOGSTRING_LOW_LEVEL("CVcxNsContentProvider::ShowUpdatingNote");
       
   602     for ( TInt i = 0; i < iContentObservers.Count(); i++ )
       
   603         {
       
   604         if( iContentObservers[i] )
       
   605             {
       
   606             iContentObservers[i]->ShowUpdatingNoteL( aShow, aDownloadedTbns, aTotalTbns );
       
   607             }
       
   608         }
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CVcxNsContentProvider::StoreLastPlayPosL()
       
   613 // -----------------------------------------------------------------------------
       
   614 //
       
   615 void CVcxNsContentProvider::StoreLastPlayPosL( CVcxNsContent* aContent, 
       
   616                                                CVcxNsContent::TVcxNsContentAccessType aType,
       
   617                                                TReal32 aPos )
       
   618     {
       
   619     
       
   620     if( aType == CVcxNsContent::EVcxContentTypeStream )
       
   621         {
       
   622         CVcxNsContentAccess* access = aContent->GetContentAccess( aType );
       
   623         
       
   624         if ( access )
       
   625             {
       
   626             iUiEngine.GetContentClientHandlerL()->
       
   627                                     StoreLastPlayPosL( aContent->GetServiceId(), 
       
   628                                                        aContent->GetContentId(), 
       
   629                                                        access->iIndex,
       
   630                                                        aPos );            
       
   631             // Stream's pos is stored to epg, but it's fetched only when
       
   632             // loading content list, so it needs to be set to content item.
       
   633             CVcxNsContent* contentInCache = SearchContentById( aContent->GetServiceId(), aContent->GetContentId() );
       
   634 			
       
   635             if( contentInCache )
       
   636 			    {
       
   637 				contentInCache->SetLastPlaybackPosition( aPos, aType );
       
   638 				}
       
   639             }
       
   640         }
       
   641     }
       
   642 
       
   643 // -----------------------------------------------------------------------------
       
   644 // CVcxNsContentProvider::HandleErrorL()
       
   645 // -----------------------------------------------------------------------------
       
   646 //
       
   647 void CVcxNsContentProvider::HandleErrorL( 
       
   648     TInt aError,
       
   649     TBool aUpdate,
       
   650     TUint32 aServiceId )
       
   651     {
       
   652     for ( TInt i = 0; i < iContentObservers.Count(); i++ )
       
   653         {
       
   654         if ( iContentObservers[i] &&
       
   655               aUpdate &&
       
   656               aServiceId == iUiEngine.ActiveService() )
       
   657             {
       
   658             iContentObservers[i]->HandleUpdateErrorL( aError );
       
   659             }
       
   660         }
       
   661     }
       
   662 
       
   663 // -----------------------------------------------------------------------------
       
   664 // CVcxNsContentProvider::HandleDlErrorL()
       
   665 // -----------------------------------------------------------------------------
       
   666 //
       
   667 void CVcxNsContentProvider::HandleDlErrorL( 
       
   668     TIptvDlError aError,
       
   669     CVcxNsContent& aContent )
       
   670     {
       
   671     for ( TInt i = 0; i < iContentObservers.Count(); i++ )
       
   672         {
       
   673         if ( iContentObservers[i] )
       
   674             {
       
   675             iContentObservers[i]->HandleDownloadErrorL( aError, aContent );
       
   676             }
       
   677         }
       
   678     }
       
   679 
       
   680 // -----------------------------------------------------------------------------
       
   681 // CVcxNsContentProvider::GetListFromCache()
       
   682 // -----------------------------------------------------------------------------
       
   683 //
       
   684 CVcxNsContentList* CVcxNsContentProvider::GetListFromCache()
       
   685     {
       
   686     for( TInt k = 0; k < iContentListList.Count(); k++ )
       
   687         {
       
   688         if( (iContentListList[k])->iServiceId == iUiEngine.ActiveService() &&
       
   689             (iContentListList[k])->iCategoryId == iUiEngine.ActiveCategory() )
       
   690             {
       
   691             // Sort the data by use order
       
   692             CVcxNsContentList* list = iContentListList[k];
       
   693             if( k != iContentListList.Count()-1 )
       
   694                 {
       
   695                 iContentListList.Remove( k );
       
   696                 iContentListList.Compress();
       
   697                 iContentListList.Append( list );
       
   698                 }
       
   699             return list;
       
   700             }
       
   701         } 
       
   702     
       
   703     return NULL;
       
   704     }
       
   705 
       
   706 // -----------------------------------------------------------------------------
       
   707 // CVcxNsContentProvider::GetListFromCache()
       
   708 // -----------------------------------------------------------------------------
       
   709 //
       
   710 void CVcxNsContentProvider::BuildDownloadListL( RPointerArray<CVcxNsContent>& aContentList )
       
   711     {
       
   712     for( TInt k = 0; k < aContentList.Count(); k++ )
       
   713         {
       
   714         if( (aContentList[k])->GetMpxId( CVcxNsContent::EVcxContentTypeVideo ) )
       
   715             {
       
   716             iUiEngine.GetMpxCollectionClientHandlerL()->AppendToDownloadList( (aContentList[k]) );            
       
   717             }
       
   718         }
       
   719     }
       
   720 
       
   721 // -----------------------------------------------------------------------------
       
   722 // CVcxNsContentProvider::GetListFromCache()
       
   723 // -----------------------------------------------------------------------------
       
   724 //
       
   725 CVcxNsContentList* CVcxNsContentProvider::LoadEpgDataL()
       
   726     {
       
   727     RPointerArray<CIptvVodContentContentBriefDetails> ecgList;
       
   728     TUint32 total;
       
   729     TBuf<1>KEmptyDes( KNullDesC ); 
       
   730     
       
   731     TInt error = iUiEngine.GetContentClientHandlerL()->GetVodContentClientL( 
       
   732                         iUiEngine.ActiveService() )->GetEcgListL( 
       
   733                         iUiEngine.ActiveCategory(),
       
   734                         KEmptyDes, 
       
   735                         0, 
       
   736                         0, 
       
   737                         total,
       
   738                         ecgList );
       
   739 
       
   740     // If cache is already full, remove the oldest data.
       
   741     if( iContentListList.Count() >= KMaxContentHistory )
       
   742         {
       
   743         delete iContentListList[0];
       
   744         iContentListList.Remove(0);
       
   745         iContentListList.Compress();
       
   746         }
       
   747     
       
   748     // Append the new data to cache
       
   749     CVcxNsContentList* entry = new (ELeave) CVcxNsContentList;
       
   750     entry->iCategoryId = iUiEngine.ActiveCategory();
       
   751     entry->iServiceId = iUiEngine.ActiveService();
       
   752     iContentListList.AppendL( entry );
       
   753     RPointerArray<CVcxNsContent>& contentList = entry->iArray;
       
   754     
       
   755     // Translate data classes
       
   756     if ( error == KErrNone )
       
   757         {
       
   758         CVcxNsContent* content = NULL;
       
   759 
       
   760         for( TInt i = 0; i < ecgList.Count(); i++ )
       
   761             {
       
   762             content = ConstructContentItemL( ecgList[ i ], iUiEngine.ActiveService() );
       
   763             
       
   764             if( content )
       
   765                 {
       
   766                 contentList.AppendL( content );
       
   767                 }
       
   768             }
       
   769         }
       
   770 
       
   771     ecgList.ResetAndDestroy();
       
   772     
       
   773     return entry;
       
   774     }
       
   775 
       
   776 // -----------------------------------------------------------------------------
       
   777 // CVcxNsContentProvider::HasVideoDetailsL()
       
   778 // -----------------------------------------------------------------------------
       
   779 //
       
   780 TBool CVcxNsContentProvider::HasVideoDetailsL( TInt aSelected )
       
   781     {
       
   782     TBool hasDetails ( EFalse );
       
   783     CVcxNsContent* content = NULL;
       
   784     RPointerArray<CVcxNsContent>& contents = GetContentsL();
       
   785     
       
   786     if( aSelected >= 0 && aSelected < contents.Count() )
       
   787         {
       
   788         content = contents[aSelected];
       
   789         }
       
   790     
       
   791     if ( content )
       
   792         {
       
   793         hasDetails = ( content->GetLanguage() != KNullDesC ) ||
       
   794                      ( content->GetLength() > 0 ) ||
       
   795                      ( content->GetSize() > 0 ) ||
       
   796                      ( content->GetDescription() != KNullDesC ) ||
       
   797                      ( content->GetAuthor() != KNullDesC ) ||
       
   798                      ( content->GetCopyright() != KNullDesC );
       
   799         }
       
   800 
       
   801     if ( !hasDetails && content )
       
   802         {
       
   803         FetchFullDetailsL( content );
       
   804         
       
   805         hasDetails = ( content->GetDescription() != KNullDesC ) ||
       
   806                      ( content->GetAuthor() != KNullDesC ) ||
       
   807                      ( content->GetCopyright() != KNullDesC );
       
   808         }
       
   809 
       
   810     return hasDetails;
       
   811     }
       
   812 
       
   813 
       
   814 // -----------------------------------------------------------------------------
       
   815 // CVcxNsContentProvider::FullDetailsL()
       
   816 // -----------------------------------------------------------------------------
       
   817 //
       
   818 CVcxNsContent* CVcxNsContentProvider::GetFullDetailsL( TInt aSelected )
       
   819     {
       
   820     CVcxNsContent* content = NULL;
       
   821     RPointerArray<CVcxNsContent>& contents = GetContentsL();
       
   822         
       
   823     if( aSelected >= 0 && aSelected < contents.Count() )
       
   824         {
       
   825         content = contents[aSelected];
       
   826         }
       
   827     
       
   828     if ( content )
       
   829         {
       
   830         //if full details have already been fetched for this item, no need to fetch again
       
   831         if ( content->GetDescription().Length() > 0 ||
       
   832              content->GetAuthor().Length() > 0 ||
       
   833              content->GetCopyright().Length() > 0 )
       
   834             {
       
   835             return content;
       
   836             }
       
   837         else
       
   838             {
       
   839             FetchFullDetailsL( content );
       
   840             }
       
   841         }
       
   842     return content;
       
   843     }
       
   844 
       
   845 // -----------------------------------------------------------------------------
       
   846 // CVcxNsContentProvider::AddContentAccessesL()
       
   847 // -----------------------------------------------------------------------------
       
   848 //
       
   849 void CVcxNsContentProvider::AddContentAccessesL( CVcxNsContent& aContent, 
       
   850                                                  RPointerArray<CIptvMediaContent>& aContentAccessList )
       
   851     {
       
   852     for ( TInt i=0; i < aContentAccessList.Count(); i++ )
       
   853         {
       
   854         TUint32 type = (aContentAccessList[i])->iDownloadType;
       
   855         TUint32 expr = (aContentAccessList[i])->iExpression;
       
   856         
       
   857         if( expr == CIptvMediaContent::EFull && type == EIptvDownloadTypeStream )
       
   858             {
       
   859             CVcxNsContentAccess* contentAccess = CVcxNsContentAccess::NewL();
       
   860             CleanupStack::PushL( contentAccess );
       
   861 
       
   862             contentAccess->SetUrlL( (aContentAccessList[i])->GetMediaContentUrl() );
       
   863             contentAccess->iType = CVcxNsContent::EVcxContentTypeStream;
       
   864             contentAccess->iIndex = i;
       
   865             contentAccess->iLastPosition = (aContentAccessList[i])->iLastPosition;
       
   866             
       
   867             aContent.AddContentAccess( contentAccess );
       
   868             CleanupStack::Pop( contentAccess );
       
   869             }
       
   870         else if( expr == CIptvMediaContent::EFull && type == EIptvDownloadTypeImmediate )
       
   871             {
       
   872             CVcxNsContentAccess* contentAccess = CVcxNsContentAccess::NewL();
       
   873             CleanupStack::PushL( contentAccess );
       
   874 
       
   875             contentAccess->SetUrlL( (aContentAccessList[i])->GetMediaContentUrl() );
       
   876             contentAccess->iType = CVcxNsContent::EVcxContentTypeVideo;
       
   877             contentAccess->iIndex = i;
       
   878             contentAccess->iMpxId = (aContentAccessList[i])->iFileId;
       
   879             
       
   880             aContent.AddContentAccess( contentAccess );
       
   881             CleanupStack::Pop( contentAccess );
       
   882             }
       
   883         }
       
   884     }
       
   885 
       
   886 // -----------------------------------------------------------------------------
       
   887 // CVcxNsContentProvider::GetContentL()
       
   888 // -----------------------------------------------------------------------------
       
   889 //
       
   890 CVcxNsContent* CVcxNsContentProvider::GetContentL( TUint32 aServiceId, TUint32 aContentId )
       
   891     {
       
   892     CVcxNsContent* cnt = SearchContentById(  aServiceId, aContentId );
       
   893     
       
   894     if( !cnt )
       
   895         {
       
   896         // Get all contents of the service to cache
       
   897         RPointerArray<CIptvVodContentContentBriefDetails> ecgList;
       
   898         TUint32 total;
       
   899         TBuf<1>KEmptyDes( KNullDesC ); 
       
   900         
       
   901         TInt error = iUiEngine.GetContentClientHandlerL()->GetVodContentClientL( aServiceId )->
       
   902                             GetEcgAllListL( KEmptyDes, 0, 0, total, ecgList );
       
   903 
       
   904         User::LeaveIfError( error );
       
   905 
       
   906         CVcxNsContentList* entry = new (ELeave) CVcxNsContentList;
       
   907         entry->iServiceId  = aServiceId;
       
   908         entry->iCategoryId = KIptvVodContentCategoryRootId;
       
   909         iContentListList.AppendL( entry );
       
   910         RPointerArray<CVcxNsContent>& contentList = entry->iArray;
       
   911         
       
   912         // Translate data classes
       
   913         CVcxNsContent* content = NULL;
       
   914 
       
   915         for( TInt i = 0; i < ecgList.Count(); i++ )
       
   916             {
       
   917             content = ConstructContentItemL( ecgList[ i ], aServiceId );
       
   918             
       
   919             if( content )
       
   920                 {
       
   921                 contentList.AppendL( content );
       
   922                 }
       
   923             }
       
   924 
       
   925         ecgList.ResetAndDestroy();
       
   926         
       
   927         // Search the content from new list
       
   928         for( TInt i = 0; i < contentList.Count() ; i++ )
       
   929             {
       
   930             if ( contentList[i]->GetContentId() == aContentId )
       
   931                 {
       
   932                 cnt = contentList[i];
       
   933                 break;
       
   934                 }
       
   935             }
       
   936         }
       
   937     
       
   938     return cnt;
       
   939     }
       
   940 
       
   941 // -----------------------------------------------------------------------------
       
   942 // CVcxNsContentProvider::ConstructContentItemL()
       
   943 // -----------------------------------------------------------------------------
       
   944 //
       
   945 CVcxNsContent* CVcxNsContentProvider::ConstructContentItemL( CIptvVodContentContentBriefDetails* aData,
       
   946                                                              TUint32 aServiceId )
       
   947     {
       
   948     CVcxNsContent* content = CVcxNsContent::NewL();
       
   949     
       
   950     CleanupStack::PushL( content );
       
   951 
       
   952     content->SetNameL( aData->iName );
       
   953     content->SetIconPathL( aData->iThumbnailPath );
       
   954     content->SetServiceId( aServiceId );
       
   955     content->SetContentId( aData->iContentId );
       
   956     content->SetSize( aData->iSize );
       
   957     content->SetLength( aData->iPlaytime );
       
   958     content->SetLanguageL( aData->iLanguage );
       
   959     content->SetBrowserUrlL( aData->GetBrowserUrlL() );
       
   960     content->SetAgeProfile( aData->iRatingAge );
       
   961 
       
   962     RPointerArray<CIptvMediaContent> caList;
       
   963     CleanupResetAndDestroyPushL( caList );
       
   964     TInt ret = iUiEngine.GetContentClientHandlerL()->GetVodContentClientL( content->GetServiceId() )->GetContentAccessListL( content->GetContentId(), caList );
       
   965 
       
   966     if( KErrNone == ret && caList.Count() > 0 )
       
   967         {
       
   968         AddContentAccessesL( *content, caList );
       
   969         
       
   970         CleanupStack::PopAndDestroy( &caList );
       
   971         CleanupStack::Pop( content );
       
   972         
       
   973         return  content;
       
   974         }
       
   975     else
       
   976         {
       
   977         // Trash 'em
       
   978         CleanupStack::PopAndDestroy( &caList );
       
   979         CleanupStack::PopAndDestroy( content );
       
   980         
       
   981         return NULL;
       
   982         }
       
   983     }
       
   984 
       
   985 // -----------------------------------------------------------------------------
       
   986 // CVcxNsContentProvider::FetchFullDetailsL()
       
   987 // -----------------------------------------------------------------------------
       
   988 //
       
   989 void CVcxNsContentProvider::FetchFullDetailsL( CVcxNsContent* aContent )
       
   990     {
       
   991     if ( aContent->FullDetailsFetched() )
       
   992         {
       
   993         // Do this only once
       
   994         return;
       
   995         }
       
   996 
       
   997     CIptvVodContentContentFullDetails* fullDetails = CIptvVodContentContentFullDetails::NewL();
       
   998     CleanupStack::PushL( fullDetails );
       
   999     
       
  1000     TInt err = iUiEngine.GetContentClientHandlerL()->GetVodContentClientL(
       
  1001                         iUiEngine.ActiveService() )->GetContentDetailsL(
       
  1002                         aContent->GetContentId(), *fullDetails );
       
  1003     
       
  1004     if ( err == KErrNone )
       
  1005         {
       
  1006         aContent->SetFullDetailsFetched( ETrue );
       
  1007         
       
  1008         if ( fullDetails->iDescription != KNullDesC )
       
  1009             {
       
  1010             aContent->SetDescriptionL( fullDetails->iDescription );
       
  1011             }
       
  1012         if ( fullDetails->iAuthor != KNullDesC )
       
  1013             {
       
  1014             aContent->SetAuthorL( fullDetails->iAuthor );
       
  1015             }
       
  1016         if ( fullDetails->iCopyright != KNullDesC )
       
  1017             {
       
  1018             aContent->SetCopyrightL( fullDetails->iCopyright );
       
  1019             }
       
  1020         }
       
  1021     
       
  1022     CleanupStack::PopAndDestroy( fullDetails );
       
  1023     }
       
  1024 
       
  1025 // -----------------------------------------------------------------------------
       
  1026 // Set highlighted content index for active category
       
  1027 // -----------------------------------------------------------------------------
       
  1028 //
       
  1029 void CVcxNsContentProvider::SetContentHighlight( TInt aHighlight )
       
  1030     {
       
  1031     if ( iUiEngine.CategoryProvider() )
       
  1032         {
       
  1033         if ( aHighlight < 0 )
       
  1034             {
       
  1035             aHighlight = 0;
       
  1036             }
       
  1037         
       
  1038         TRAP_IGNORE( 
       
  1039             iUiEngine.CategoryProvider()->SetCurrentHighlightL( aHighlight ) );
       
  1040         }
       
  1041     }