videofeeds/vcnsuiengine/src/vcxnsserviceprovider.cpp
changeset 0 96612d01cf9f
child 2 dec420019252
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 // Version : %version: Rel6_49 %
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <bldvariant.hrh>
       
    23 #include <bautils.h>
       
    24 
       
    25 #include "IptvDebug.h"
       
    26 #include "CIptvIapList.h"
       
    27 #include "CIptvVodContentClient.h"
       
    28 #include "CIptvServiceManagementClient.h"
       
    29 #include "vcxnsserviceproviderobserver.h"
       
    30 #include "vcxnsserviceclienthandler.h"
       
    31 #include "vcxnscontentclienthandler.h"
       
    32 #include "vcxnsserviceprovider.h"
       
    33 #include "vcxnscontentprovider.h"
       
    34 #include "vcxnscategoryprovider.h"
       
    35 #include "vcxnscategory.h"
       
    36 #include "vcxnsuiengine.h"
       
    37 #include "vcxnsupdateprogresshandler.h"
       
    38 #include "vcxnscontentsearchhandler.h"
       
    39 
       
    40 _LIT( KVcxNsRtspProtocol, "rtsp://" );
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CVcxNsServiceProvider::CVcxNsServiceProvider()
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CVcxNsServiceProvider::CVcxNsServiceProvider( CVcxNsUiEngine& aUiEngine ) : iUiEngine( aUiEngine )
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CVcxNsServiceProvider::NewL()
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CVcxNsServiceProvider* CVcxNsServiceProvider::NewL( CVcxNsUiEngine& aUiEngine )
       
    57     {
       
    58     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsServiceProvider::NewL()");
       
    59 
       
    60     CVcxNsServiceProvider* self =  new (ELeave) CVcxNsServiceProvider( aUiEngine );
       
    61 
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64     CleanupStack::Pop( self );
       
    65 
       
    66     return self;
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CVcxNsServiceProvider::ConstructL()
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CVcxNsServiceProvider::ConstructL()
       
    74     {
       
    75     User::LeaveIfError( iFs.Connect() );
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CVcxNsServiceProvider::~CVcxNsServiceProvider()
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CVcxNsServiceProvider::~CVcxNsServiceProvider()
       
    83     {
       
    84     iUpdateQueue.Reset();
       
    85     iServiceObservers.Reset();
       
    86     iServiceList.ResetAndDestroy();
       
    87     iFs.Close();
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CVcxNsServiceProvider::GetSubscribedServicesL()
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 RPointerArray<CVcxNsService>& CVcxNsServiceProvider::GetSubscribedServicesL()
       
    95     {
       
    96     IPTVLOGSTRING_HIGH_LEVEL(
       
    97         "UI Engine ## CVcxNsServiceProvider::GetSubscribedServicesL()");
       
    98 
       
    99     if( iServiceList.Count() > 0 )
       
   100         {
       
   101         return iServiceList;
       
   102         }
       
   103      
       
   104     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
   105     CDesC8ArraySeg* services = NULL;
       
   106     TUint32 flags = 0;
       
   107 
       
   108     TInt error = iUiEngine.GetServiceClientHandlerL()->GetServiceManagementClientL()->GetServicesL( 
       
   109                          CIptvServiceManagementClient::ESelectedServices 
       
   110                          || CIptvServiceManagementClient::EBrowser,
       
   111                          CIptvServiceManagementClient::EDisplayOrderDescending,
       
   112                          services,
       
   113                          respStatus );
       
   114     
       
   115     
       
   116     if ( error == KErrNone )
       
   117         {
       
   118         CleanupStack::PushL( services );
       
   119         
       
   120         CIptvService* service = CIptvService::NewL();
       
   121         CleanupStack::PushL( service );
       
   122         
       
   123         for ( TInt i = 0; i < services->Count(); i++ )
       
   124             {
       
   125             service->SetL( services->MdcaPoint(i) );
       
   126             flags = service->GetFlags();
       
   127             
       
   128             if ( ( flags & CIptvService::ESelected ) && 
       
   129                 ( ( service->GetType() == CIptvService::EVod )
       
   130                     || ( service->GetType() == CIptvService::EVodCast )
       
   131                     || ( service->GetType() == CIptvService::EServiceGroup ) ) )
       
   132                 {
       
   133   		    	CVcxNsService* newService = CVcxNsService::NewL();
       
   134                 CleanupStack::PushL( newService );
       
   135   		    	newService->SetServiceId( service->GetId() );
       
   136   		    	newService->SetNameL( service->GetName() );
       
   137   		    	newService->SetGroupId( service->GetGroupId() );
       
   138   		    	
       
   139   		    	if ( service->GetType() == CIptvService::EServiceGroup )
       
   140   		    	    {
       
   141                     newService->SetType( CVcxNsService::EVcxNsMainGroup );
       
   142                     }
       
   143   		    	else if ( flags & CIptvService::EReadOnly )
       
   144   		    	    {
       
   145   		    	    newService->SetType( CVcxNsService::EVcxNsReadOnly );
       
   146   		    	    }
       
   147   		    	else
       
   148   		    	    {
       
   149   		    	    newService->SetType( CVcxNsService::EVcxNsEditable ); 
       
   150   		    	    }
       
   151                 
       
   152   		    	if ( EnsureFileExists( service->GetIconPath() ))
       
   153   		    	    {
       
   154   		    	    newService->SetIconPathL( service->GetIconPath() );
       
   155   		    	    }
       
   156 
       
   157                 newService->SetUpdateTime( service->GetEpgUpdateTimeL() );
       
   158                 newService->SetUpdateStatus( CVcxNsService::ENotUpdating );
       
   159                 newService->SetUserNameL( service->GetUserName() );
       
   160                 newService->SetPasswordL( service->GetPassword() );
       
   161                 newService->SetDescL( service->GetDesc() );
       
   162                 newService->SetIsReadOnlyIap( flags & CIptvService::EReadOnlyIaps ? ETrue : EFalse );
       
   163                 newService->SetAccountMgmtUriL( service->GetAccountManagementUrl() );
       
   164                 
       
   165                 if( flags & CIptvService::EReadOnlyIaps && service->GetIapList().Count() > 0 )
       
   166                     {
       
   167                     // if readonly, more than one?
       
   168                     newService->SetIap( service->GetIapList().IapL(0).iId );
       
   169                     }
       
   170                 
       
   171                 iServiceList.AppendL( newService );
       
   172                 CleanupStack::Pop( newService );
       
   173                 }
       
   174             }
       
   175 
       
   176         for ( TInt i = 0; i < services->Count(); i++ )
       
   177             {
       
   178             service->SetL( services->MdcaPoint(i) );
       
   179             flags = service->GetFlags();
       
   180 
       
   181             if ( ( service->GetType() == CIptvService::EBrowser )
       
   182                     &&  service->GetName().CompareF( KVcxNsVideoDirectory ) == 0 )
       
   183                 {
       
   184                 CVcxNsService* videoDirectory = CVcxNsService::NewL();
       
   185                 CleanupStack::PushL( videoDirectory );
       
   186 
       
   187                 //Name is localisation string, needs to be handled in UI side.
       
   188                 videoDirectory->SetServiceId( service->GetId() );
       
   189                 videoDirectory->SetNameL( service->GetName() );
       
   190                 videoDirectory->SetCustomUriL( service->GetAddress() );
       
   191                 videoDirectory->SetIconPathL( service->GetIconPath() );
       
   192                 videoDirectory->SetType( CVcxNsService::EVcxNsVideoDirectory );
       
   193 
       
   194                 //Add Video directory item always at the end of the list
       
   195                 iServiceList.AppendL( videoDirectory );
       
   196                 CleanupStack::Pop( videoDirectory );
       
   197 
       
   198 				break; // Allow just one Video Directory
       
   199                 }
       
   200             }
       
   201 
       
   202         CleanupStack::PopAndDestroy( service );
       
   203         CleanupStack::PopAndDestroy( services );
       
   204         }
       
   205  
       
   206     return iServiceList;
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CVcxNsServiceProvider::GetActiveGroupListL()
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 RPointerArray<CVcxNsService>& CVcxNsServiceProvider::GetActiveGroupListL()
       
   214     {
       
   215     IPTVLOGSTRING_HIGH_LEVEL(
       
   216         "UI Engine ## CVcxNsServiceProvider::GetActiveGroupListL()");
       
   217 
       
   218     CVcxNsService* service = GetActiveServiceData();
       
   219 
       
   220     if( !service )
       
   221         {
       
   222         User::Leave( KErrNotFound );
       
   223         }
       
   224     
       
   225     if ( service->Type() == CVcxNsService::EVcxNsMainGroup )
       
   226         {
       
   227         if ( service->ServiceGroup().Count() <= 0 )
       
   228             {
       
   229             GetGroupedServicesL( service->GroupId() );
       
   230             }
       
   231         }
       
   232 
       
   233     return service->ServiceGroup();
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CVcxNsServiceProvider::OpenServiceL( TInt aIndex )
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 void CVcxNsServiceProvider::OpenServiceL( TInt aIndex )
       
   241     {
       
   242     IPTVLOGSTRING2_LOW_LEVEL("CVcxNsServiceProvider::OpenServiceL (%d)", aIndex );
       
   243     
       
   244      if ( iUiEngine.VcAppState() == EStateCustomView ) 
       
   245         {
       
   246         OpenServiceFromGroupL( aIndex );
       
   247         return;
       
   248         }
       
   249     
       
   250     if( !( aIndex >= 0 && aIndex < iServiceList.Count() ) )
       
   251         {
       
   252         return;
       
   253         }
       
   254     
       
   255     if ( iServiceList[aIndex]->Type() == CVcxNsService::EVcxNsVideoDirectory ) 
       
   256         {
       
   257         OpenToBrowserL( iServiceList[aIndex]->CustomUri() );
       
   258         }
       
   259     else
       
   260         {
       
   261         TUint32 serviceToOpen = iServiceList[aIndex]->GetServiceId();
       
   262         
       
   263         OpenVideoServiceL( serviceToOpen, aIndex );
       
   264         }
       
   265     }
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CVcxNsServiceProvider::OpenVideoService( TInt aIndex )
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 void CVcxNsServiceProvider::OpenVideoServiceL( TUint32 aServiceId, TInt aIndex )
       
   272     {
       
   273     if( aIndex < 0 && aIndex >= iServiceList.Count() )
       
   274         {
       
   275         return;
       
   276         }
       
   277     
       
   278     TBool shouldBeUpdated( EFalse );
       
   279     
       
   280     if ( iServiceList[aIndex]->GetUpdateStatus() != CVcxNsService::EUpdateOngoing )
       
   281         {
       
   282 	    if ( iUpdateQueue.Count() > 0 )
       
   283 	        {
       
   284 	        IPTVLOGSTRING_LOW_LEVEL("-- Refresh feeds ongoing --");
       
   285 	        if ( iUpdateQueue.Find( aServiceId ) > KErrNotFound )
       
   286 	            {
       
   287 	            shouldBeUpdated = ETrue;
       
   288 	            }
       
   289 	        }
       
   290 	    else if ( iServiceList[aIndex]->Type() == CVcxNsService::EVcxNsMainGroup )
       
   291 	        {
       
   292 	        TTime updated( iServiceList[aIndex]->GetUpdateTime() );
       
   293 	        // See if more than an hour from last update
       
   294 	        TTime now;
       
   295 	        now.UniversalTime();
       
   296 	        TTimeIntervalHours hourInterval( 0 );
       
   297 	        TInt error( updated.HoursFrom( now, hourInterval ) );
       
   298 	        if ( error != KErrNone || Abs( hourInterval.Int() ) > 0 )
       
   299 	            {
       
   300 	            shouldBeUpdated = ETrue;
       
   301 	            }
       
   302 	        }
       
   303         }
       
   304     
       
   305     CVcxNsContentClientHandler* contentClientHandler = 
       
   306         iUiEngine.GetContentClientHandlerL();
       
   307     
       
   308     User::LeaveIfNull( contentClientHandler );
       
   309 
       
   310     TBool updateAvailable ( EFalse );
       
   311     
       
   312     //Check if service update for this available
       
   313     CIptvVodContentClient* contentClient = 
       
   314         contentClientHandler->GetVodContentClientL( aServiceId );
       
   315 
       
   316     User::LeaveIfNull( contentClient );
       
   317     
       
   318     CVcxNsService::TServiceUpdateStatus statusOpening =
       
   319         iServiceList[aIndex]->GetUpdateStatus();
       
   320     
       
   321     if ( !shouldBeUpdated &&  
       
   322          !( ( statusOpening == CVcxNsService::EStartingPending || 
       
   323             statusOpening == CVcxNsService::EUpdateOngoing ) ) )
       
   324         {
       
   325         IPTVLOGSTRING_LOW_LEVEL("-- Check update availability --");
       
   326         contentClient->UpdateAvailableL( updateAvailable );
       
   327         }
       
   328     
       
   329     if ( updateAvailable || shouldBeUpdated )
       
   330         {
       
   331         //Update will start for selected service. 
       
   332         // Cancel any update ongoing before opening service:
       
   333         for ( TInt i = 0; i < iServiceList.Count(); i++ )
       
   334             {
       
   335             CVcxNsService::TServiceUpdateStatus status = 
       
   336                 iServiceList[i]->GetUpdateStatus();
       
   337             TUint32 currentlyUpdatedServiceId = iServiceList[i]->GetServiceId();
       
   338 
       
   339             if ( status == CVcxNsService::EStartingPending  ||
       
   340                  status == CVcxNsService::EUpdateOngoing &&
       
   341                  currentlyUpdatedServiceId != aServiceId )
       
   342                 {
       
   343                 contentClientHandler->GetVodContentClientL( 
       
   344                             currentlyUpdatedServiceId )->CancelUpdate();
       
   345 
       
   346                 // Update was ongoing, start it whenever possible.
       
   347                 SetBackToUpdateQueue( currentlyUpdatedServiceId );
       
   348                 
       
   349                 CVcxNsUpdateProgressHandler* progressHandler = iUiEngine.GetProgressHandler();
       
   350                 progressHandler->Cancel();
       
   351                 
       
   352                 iServiceList[i]->SetUpdateStatus( CVcxNsService::ENotUpdating );
       
   353                 ServiceUpdated( i );
       
   354                 break;
       
   355                 }
       
   356              }
       
   357         
       
   358         if ( iServiceList[aIndex]->Type() == CVcxNsService::EVcxNsMainGroup
       
   359                 || iServiceList[aIndex]->Type() == CVcxNsService::EVcxNsEditable
       
   360                 || iServiceList[aIndex]->Type() == CVcxNsService::EVcxNsReadOnly )
       
   361             {
       
   362             StartManualUpdateL( aServiceId );
       
   363             }
       
   364         }
       
   365         
       
   366     
       
   367     iUiEngine.SetActiveService( aServiceId );
       
   368     
       
   369     if ( iServiceList[aIndex]->Type() == CVcxNsService::EVcxNsMainGroup )
       
   370         {
       
   371         iUiEngine.SetVcAppState( EStateCustomView );
       
   372         }
       
   373     else
       
   374         {
       
   375         RPointerArray<CVcxNsCategory> categorys = iUiEngine.GetCategoryProviderL()->GetCategorysL();
       
   376         
       
   377         if( categorys.Count() == 0 )
       
   378             {
       
   379             iUiEngine.SetActiveCategory( KIptvVodContentCategoryRootId );
       
   380             iUiEngine.SetVcAppState( EStateContentView );            
       
   381             }
       
   382         else if( categorys.Count() == 1 &&
       
   383                  categorys[0]->GetCategoryId() == KIptvRssSearchCategoryId )
       
   384             {
       
   385             iUiEngine.SetActiveCategory( (categorys[0])->GetCategoryId() );
       
   386             iUiEngine.SetVcAppState( EStateCategoryView );
       
   387             }
       
   388         else if( categorys.Count() == 1 )
       
   389             {
       
   390             iUiEngine.SetActiveCategory( (categorys[0])->GetCategoryId() );
       
   391             iUiEngine.SetVcAppState( EStateContentView );
       
   392             }
       
   393         else
       
   394             {
       
   395             iUiEngine.SetVcAppState( EStateCategoryView );
       
   396             }
       
   397         }
       
   398     }
       
   399 
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // CVcxNsServiceProvider::OpenServiceL
       
   403 // -----------------------------------------------------------------------------
       
   404 //
       
   405 void CVcxNsServiceProvider::OpenServiceL( TUint32 aServiceId )
       
   406     {
       
   407     TBool found( EFalse );
       
   408     for ( TInt i = 0; i < iServiceList.Count(); i++ )
       
   409         {
       
   410         if ( iServiceList[i]->GetServiceId() == aServiceId )
       
   411             {
       
   412             OpenServiceL( i );
       
   413             found = ETrue;
       
   414             break;
       
   415             }
       
   416         }
       
   417     
       
   418     if ( !found )
       
   419         {
       
   420         //First, remove old services
       
   421         RemoveServiceData();
       
   422         //Get new list 
       
   423         GetSubscribedServicesL();
       
   424     
       
   425         for ( TInt i = 0; i < iServiceList.Count(); i++ )
       
   426             {
       
   427             if ( iServiceList[i]->GetServiceId() == aServiceId )
       
   428                 {
       
   429                 OpenServiceL( i );
       
   430                 break;
       
   431                 }
       
   432             }
       
   433         }
       
   434     }
       
   435     
       
   436 // -----------------------------------------------------------------------------
       
   437 // CVcxNsServiceProvider::GetCurrentHighlight
       
   438 // -----------------------------------------------------------------------------
       
   439 //
       
   440 TInt CVcxNsServiceProvider::GetCurrentHighlight()
       
   441     {
       
   442     CVcxNsService* service = GetActiveServiceData();
       
   443     if ( service )
       
   444         {
       
   445         return service->HighlightCategoryIndex();
       
   446         }
       
   447 
       
   448     return 0;
       
   449     }
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // CVcxNsServiceProvider::SetCurrentHighlight
       
   453 // -----------------------------------------------------------------------------
       
   454 //
       
   455 void CVcxNsServiceProvider::SetCurrentHighlight( TInt aIndex )
       
   456     {
       
   457     CVcxNsService* service = GetActiveServiceData();
       
   458     if ( service )
       
   459         {
       
   460         return service->SetHighlightCategoryIndex( aIndex );
       
   461         }
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CVcxNsServiceProvider::RemoveServiceL
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 void CVcxNsServiceProvider::RemoveServiceL( TInt aIndex )
       
   469     {
       
   470     CVcxNsService* service = GetServiceData( aIndex );
       
   471     if ( service )
       
   472         {
       
   473         iUiEngine.GetServiceClientHandlerL()->DeleteFeedL( 
       
   474                 service->GetServiceId() );
       
   475         
       
   476         for ( TInt i = 0; i < iServiceList.Count(); i++ )
       
   477             {
       
   478             if ( iServiceList[i]->GetServiceId() 
       
   479                     == service->GetServiceId() )
       
   480                 {
       
   481                 CVcxNsService* temp = iServiceList[i];
       
   482                 delete temp;
       
   483                 iServiceList.Remove( i );
       
   484                 iServiceList.Compress();
       
   485                 }
       
   486             }
       
   487 
       
   488         for ( TInt i = 0; i < iServiceObservers.Count(); i++ )
       
   489             {
       
   490             if ( iServiceObservers[i] )
       
   491                 {
       
   492                 iServiceObservers[i]->ServiceRemoved( aIndex, iServiceList );
       
   493                 }
       
   494             }
       
   495         }
       
   496     }
       
   497 
       
   498 // -----------------------------------------------------------------------------
       
   499 // Get active service data
       
   500 // -----------------------------------------------------------------------------
       
   501 //
       
   502 CVcxNsService* CVcxNsServiceProvider::GetServiceData( TInt aIndex )
       
   503     {
       
   504     if ( aIndex >= 0 && 
       
   505          iServiceList.Count() > aIndex )
       
   506         {
       
   507         return iServiceList[ aIndex ];
       
   508         }
       
   509     
       
   510     return NULL;
       
   511     }
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CVcxNsServiceProvider::GetServiceDataById()
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 CVcxNsService* CVcxNsServiceProvider::GetServiceDataById( TUint32 aServiceId )
       
   518     {
       
   519     TRAPD( leave, GetSubscribedServicesL() );
       
   520 
       
   521     if ( leave != KErrNone )
       
   522         {
       
   523         return NULL;
       
   524         }
       
   525     
       
   526     for( TInt i = 0; i < iServiceList.Count(); i++ )
       
   527         {
       
   528         if ( ( iServiceList[i])->GetServiceId() == aServiceId )
       
   529             {
       
   530             return iServiceList[i];
       
   531             }
       
   532         else if ( iServiceList[i]->Type() == CVcxNsService::EVcxNsMainGroup )
       
   533             {
       
   534             RPointerArray<CVcxNsService>& group = iServiceList[i]->ServiceGroup();
       
   535             for( TInt index = 0; index < group.Count(); index++ )
       
   536                 {
       
   537                 if ( group[index]->GetServiceId() == aServiceId )
       
   538                     {
       
   539                     return group[index];
       
   540                     }
       
   541                 }            
       
   542             }
       
   543         }
       
   544 
       
   545     return NULL;
       
   546     }
       
   547 
       
   548 // -----------------------------------------------------------------------------
       
   549 // Get active service data
       
   550 // -----------------------------------------------------------------------------
       
   551 //
       
   552 CVcxNsService* CVcxNsServiceProvider::GetActiveServiceData()
       
   553     {
       
   554     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::GetActiveServiceData");
       
   555     return GetServiceDataById( iUiEngine.ActiveService() );    
       
   556     }
       
   557 
       
   558 // -----------------------------------------------------------------------------
       
   559 // CVcxNsServiceProvider::RemoveServiceData
       
   560 // -----------------------------------------------------------------------------
       
   561 //
       
   562 void CVcxNsServiceProvider::RemoveServiceData()
       
   563     {
       
   564     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::RemoveServiceData");
       
   565     iServiceList.ResetAndDestroy();
       
   566     }
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CVcxNsServiceProvider::HandleBack()
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 TBool CVcxNsServiceProvider::HandleBack()
       
   573     {
       
   574     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::HandleBack");
       
   575     return iUiEngine.HandleBack();
       
   576     }
       
   577 
       
   578 // -----------------------------------------------------------------------------
       
   579 // CVcxNsServiceProvider::RefreshAllServicesL()
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 void CVcxNsServiceProvider::RefreshAllServicesL()
       
   583     {
       
   584     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::RefreshAllServicesL");
       
   585     RPointerArray<CVcxNsService>& servicelist = GetSubscribedServicesL();
       
   586     
       
   587     if ( servicelist.Count() > 0 && iUpdateQueue.Count() <= 0 )
       
   588         {
       
   589         if ( !( servicelist[0]->Type() == CVcxNsService::EVcxNsVideoDirectory ) )
       
   590             {
       
   591             // Start updating first immediately
       
   592             TUint32 serviceId = (servicelist[0])->GetServiceId();
       
   593             iUiEngine.GetContentClientHandlerL()->UpdateEcgL( serviceId );
       
   594             }
       
   595 
       
   596         // Mark rest of the services to be pending to be updated later
       
   597         for ( TInt i = 1; i < servicelist.Count(); i++ )
       
   598             {
       
   599             if ( !( servicelist[i]->Type() == CVcxNsService::EVcxNsVideoDirectory ) )
       
   600                 {
       
   601                 iUpdateQueue.Append( (servicelist[i])->GetServiceId() );
       
   602                 }
       
   603             }
       
   604         }
       
   605     }
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // CVcxNsServiceProvider::CancelUpdateQueue()
       
   609 // -----------------------------------------------------------------------------
       
   610 //
       
   611 void CVcxNsServiceProvider::CancelUpdateQueue()
       
   612     {
       
   613     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::UpdatesInQueue");
       
   614     if ( iUpdateQueue.Count() > 0 )
       
   615         {
       
   616         iUpdateQueue.Reset();
       
   617         }
       
   618     }
       
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // CVcxNsServiceProvider::StartManualUpdateL()
       
   622 // -----------------------------------------------------------------------------
       
   623 //
       
   624 void CVcxNsServiceProvider::StartManualUpdateL( TUint32 aServiceId )
       
   625     {
       
   626     IPTVLOGSTRING2_LOW_LEVEL(
       
   627         "CVcxNsServiceProvider::StartManualUpdateL (%d)", (TInt)aServiceId );
       
   628     TInt foundIndex = iUpdateQueue.Find( aServiceId );
       
   629     
       
   630     if ( foundIndex >= 0 && foundIndex < iUpdateQueue.Count() )
       
   631         {
       
   632         for ( TInt i = 0; i < iServiceList.Count(); i++ )
       
   633             {
       
   634             if ( (iServiceList[i])->GetServiceId() 
       
   635                     == iUpdateQueue[foundIndex] ) 
       
   636                 {
       
   637                 UpdateServiceL( (*iServiceList[i] ) );
       
   638                 iUpdateQueue.Remove( foundIndex );
       
   639                 return;
       
   640                 }
       
   641             }
       
   642         }
       
   643     else
       
   644         {
       
   645         for ( TInt i = 0; i < iServiceList.Count(); i++ )
       
   646             {
       
   647             if ( ( iServiceList[i])->GetServiceId() 
       
   648                     == aServiceId ) 
       
   649                 {
       
   650                 UpdateServiceL( (*iServiceList[i]) );
       
   651                 return;
       
   652                 }
       
   653             }
       
   654         }
       
   655     }
       
   656 
       
   657 // -----------------------------------------------------------------------------
       
   658 // CVcxNsServiceProvider::UpdateServiceL()
       
   659 // -----------------------------------------------------------------------------
       
   660 //
       
   661 void CVcxNsServiceProvider::UpdateServiceL( CVcxNsService& aService )
       
   662     {
       
   663     aService.SetUpdateStatus( CVcxNsService::EStartingPending );
       
   664     iUiEngine.GetContentClientHandlerL()->UpdateEcgL( aService.GetServiceId() );
       
   665     }
       
   666 
       
   667 // -----------------------------------------------------------------------------
       
   668 // CVcxNsServiceProvider::SetBackToUpdateQueue()
       
   669 // -----------------------------------------------------------------------------
       
   670 //
       
   671 void CVcxNsServiceProvider::SetBackToUpdateQueue( TUint32 aServiceId )
       
   672     {
       
   673     IPTVLOGSTRING2_LOW_LEVEL(
       
   674         "CVcxNsServiceProvider::SetBackToUpdateQueue (%d)", (TInt)aServiceId );
       
   675 
       
   676     TInt foundIndex = iUpdateQueue.Find( aServiceId );
       
   677     if ( foundIndex >= 0 )
       
   678         {
       
   679         return;
       
   680         }
       
   681     
       
   682     iUpdateQueue.Insert( aServiceId, 0 );
       
   683     }
       
   684 
       
   685 // -----------------------------------------------------------------------------
       
   686 // CVcxNsServiceProvider::OpenVideoDirectoryL()
       
   687 // -----------------------------------------------------------------------------
       
   688 //
       
   689 void CVcxNsServiceProvider::OpenVideoDirectoryL()
       
   690     {
       
   691     for ( TInt index = 0; index < iServiceList.Count(); index++ )
       
   692         {
       
   693         if ( iServiceList[index]->Type() == CVcxNsService::EVcxNsVideoDirectory ) 
       
   694             {
       
   695             OpenToBrowserL( iServiceList[index]->CustomUri() );
       
   696             return;
       
   697             }
       
   698         }
       
   699     }
       
   700 
       
   701 // -----------------------------------------------------------------------------
       
   702 // CVcxNsServiceProvider::ManageAccountL()
       
   703 // -----------------------------------------------------------------------------
       
   704 //
       
   705 void CVcxNsServiceProvider::ManageAccountL( TInt aSelected )
       
   706     {
       
   707     if ( aSelected >= 0 && aSelected < iServiceList.Count() )
       
   708         {
       
   709         CVcxNsService* service = NULL;
       
   710         service = GetServiceData( aSelected );
       
   711         if ( service )
       
   712             {
       
   713             for ( TInt i = 0; i < iServiceObservers.Count(); i++ )
       
   714                 {
       
   715                 if( iServiceObservers[i] )
       
   716                     {
       
   717                     iServiceObservers[i]->OpenBrowserLinkL( 
       
   718                         service->AccountMgmtUri() );
       
   719                     }
       
   720                 }
       
   721             iUiEngine.SetVcAppState( EStateBrowser );
       
   722             }
       
   723         }
       
   724     }
       
   725 
       
   726 // -----------------------------------------------------------------------------
       
   727 // CVcxNsServiceProvider::SetAuthenticationDataL
       
   728 // -----------------------------------------------------------------------------
       
   729 //
       
   730 void CVcxNsServiceProvider::SetAuthenticationDataL( 
       
   731     const TDesC& aUserName,
       
   732     const TDesC& aPasswd )
       
   733     {
       
   734     CVcxNsService* activeService = GetActiveServiceData();
       
   735     if ( activeService  )
       
   736         {
       
   737         activeService->SetUserNameL( aUserName );
       
   738         activeService->SetPasswordL( aPasswd );
       
   739         
       
   740         MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
   741         CDesC8ArraySeg* services = NULL;
       
   742         TUint32 serviceId = activeService->GetServiceId();
       
   743 
       
   744         TInt error = 
       
   745             iUiEngine.GetServiceClientHandlerL()->GetServiceManagementClientL()->GetServicesL( 
       
   746                     serviceId, serviceId, services, respStatus );
       
   747 
       
   748         CIptvService* service = CIptvService::NewL();
       
   749         CleanupStack::PushL( service );
       
   750         
       
   751         if ( error == KErrNone && services->MdcaCount() > 0 )
       
   752             {
       
   753             CleanupStack::PushL( services );
       
   754             service->SetL( services->MdcaPoint(0) );
       
   755             service->SetUserName( aUserName );
       
   756             service->SetPassword( aPasswd );
       
   757             CleanupStack::PopAndDestroy( services );
       
   758             }
       
   759 
       
   760         iUiEngine.GetServiceClientHandlerL()->UpdateFeedL( *service );
       
   761         CleanupStack::PopAndDestroy( service );
       
   762         }
       
   763     }
       
   764 
       
   765 // -----------------------------------------------------------------------------
       
   766 // CVcxNsServiceProvider::RegisterObserver()
       
   767 // -----------------------------------------------------------------------------
       
   768 //
       
   769 void CVcxNsServiceProvider::RegisterObserver( MVcxNsServiceProviderObserver* aObserver )
       
   770     {
       
   771     for ( TInt i = 0; i < iServiceObservers.Count(); i++ )
       
   772         {
       
   773         if( iServiceObservers[i] == aObserver )
       
   774             {
       
   775             return;
       
   776             }
       
   777         }   
       
   778     iServiceObservers.Append( aObserver );
       
   779     }
       
   780 
       
   781 // -----------------------------------------------------------------------------
       
   782 // CVcxNsServiceProvider::DeRegisterObserver()
       
   783 // -----------------------------------------------------------------------------
       
   784 //
       
   785 void CVcxNsServiceProvider::DeRegisterObserver( MVcxNsServiceProviderObserver* aObserver )
       
   786     {
       
   787     for ( TInt i = 0; i < iServiceObservers.Count(); i++ )
       
   788         {
       
   789         if( iServiceObservers[i] == aObserver )
       
   790             {
       
   791             iServiceObservers.Remove( i );
       
   792             iServiceObservers.Compress();
       
   793             }
       
   794         }
       
   795    }
       
   796 
       
   797 // -----------------------------------------------------------------------------
       
   798 // CVcxNsServiceProvider::ServiceAdded()
       
   799 // -----------------------------------------------------------------------------
       
   800 //
       
   801 void CVcxNsServiceProvider::ServiceAdded( TInt aIndex )
       
   802     {
       
   803     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::ServiceAdded");
       
   804     for ( TInt i = 0; i < iServiceObservers.Count(); i++ )
       
   805         {
       
   806         if( iServiceObservers[i] )
       
   807             {
       
   808             iServiceObservers[i]->ServiceAdded( aIndex );
       
   809             }
       
   810         }
       
   811     }
       
   812 
       
   813 // -----------------------------------------------------------------------------
       
   814 // CVcxNsServiceProvider::ServiceUpdated()
       
   815 // -----------------------------------------------------------------------------
       
   816 //
       
   817 void CVcxNsServiceProvider::ServiceUpdated( TInt aIndex )
       
   818     {
       
   819     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::ServiceUpdated");
       
   820     for ( TInt i = 0; i < iServiceObservers.Count(); i++ )
       
   821         {
       
   822         if( iServiceObservers[i] )
       
   823             {
       
   824             iServiceObservers[i]->ServiceUpdated( aIndex );
       
   825             }
       
   826         }
       
   827     }
       
   828 
       
   829 // -----------------------------------------------------------------------------
       
   830 // CVcxNsServiceProvider::HandleAppStateChangedL()
       
   831 // -----------------------------------------------------------------------------
       
   832 //
       
   833 void CVcxNsServiceProvider::HandleAppStateChangedL()
       
   834     {
       
   835     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::HandleAppStateChangedL");
       
   836     for ( TInt i = 0; i < iServiceObservers.Count(); i++ )
       
   837         {
       
   838         if( iServiceObservers[i] )
       
   839             {
       
   840             iServiceObservers[i]->HandleAppStateChangedL();
       
   841             }
       
   842         }
       
   843     }
       
   844 
       
   845 // -----------------------------------------------------------------------------
       
   846 // CVcxNsServiceProvider::RefreshView()
       
   847 // -----------------------------------------------------------------------------
       
   848 //
       
   849 void CVcxNsServiceProvider::RefreshView()
       
   850     {
       
   851     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::RefreshView");
       
   852     for ( TInt i = 0; i < iServiceObservers.Count(); i++ )
       
   853         {
       
   854         if( iServiceObservers[i] )
       
   855             {
       
   856             iServiceObservers[i]->RefreshView();
       
   857             }
       
   858         }
       
   859     }
       
   860 
       
   861 // -----------------------------------------------------------------------------
       
   862 // CVcxNsServiceProvider::UpdateServiceUpdateStatus()
       
   863 // -----------------------------------------------------------------------------
       
   864 //
       
   865 void CVcxNsServiceProvider::UpdateServiceUpdateStatusL( 
       
   866     TUint32 aServiceId,
       
   867     CVcxNsService::TServiceUpdateStatus aStatus )
       
   868     {
       
   869     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::UpdateServiceUpdateStatus");
       
   870     CVcxNsService* service = GetServiceDataById( aServiceId );
       
   871 
       
   872     if ( service )
       
   873         {
       
   874         service->SetUpdateStatus( aStatus );
       
   875         if( aStatus == CVcxNsService::ENotUpdating )
       
   876             {
       
   877             TTime newUpdateTime;
       
   878             TInt error ( KErrNone );
       
   879             // This wrapped trap generates false codescanner warning.
       
   880             error = iUiEngine.GetContentClientHandlerL()->GetVodContentClientL( 
       
   881                       aServiceId )->GetUpdateTimeL( newUpdateTime );
       
   882 
       
   883             if( error == KErrNone && newUpdateTime != 0 )
       
   884                 {
       
   885                 service->SetUpdateTime( newUpdateTime );
       
   886                 }
       
   887             }
       
   888         
       
   889         }
       
   890     }
       
   891 
       
   892 // -----------------------------------------------------------------------------
       
   893 // CVcxNsServiceProvider::RefreshNextPendingService()
       
   894 // -----------------------------------------------------------------------------
       
   895 //
       
   896 void CVcxNsServiceProvider::RefreshNextPendingService()
       
   897     {
       
   898     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::RefreshNextPendingService");
       
   899     
       
   900     TBool updating( EFalse );
       
   901 
       
   902     if ( iUpdateQueue.Count() > 0 )
       
   903         {
       
   904         TUint32 serviceId = iUpdateQueue[0]; 
       
   905         CVcxNsService* service = NULL; 
       
   906         for ( TInt i = 0; i < iServiceList.Count(); i++ )
       
   907             {
       
   908             if ( (iServiceList[i])->GetServiceId() 
       
   909                     == serviceId )
       
   910                 {
       
   911                 service = iServiceList[i];
       
   912                 }
       
   913             if( iServiceList[i]->GetUpdateStatus() == CVcxNsService::EUpdateOngoing )
       
   914                 {
       
   915                 updating = ETrue;
       
   916                 break;
       
   917                 }
       
   918             }
       
   919 
       
   920         if ( service && !updating )
       
   921             {
       
   922             service->SetUpdateStatus( CVcxNsService::EStartingPending );
       
   923             TRAP_IGNORE( iUiEngine.GetContentClientHandlerL()->UpdateEcgL( serviceId ) );
       
   924             iUpdateQueue.Remove( 0 );
       
   925             }
       
   926         }
       
   927     }
       
   928 
       
   929 // -----------------------------------------------------------------------------
       
   930 // CVcxNsServiceProvider::UpdateService()
       
   931 // -----------------------------------------------------------------------------
       
   932 //
       
   933 void CVcxNsServiceProvider::UpdateService( TUint aServiceId )
       
   934     {
       
   935     TInt idx = ServiceIndex( aServiceId );
       
   936     
       
   937     if( idx != KErrNotFound  )
       
   938         {
       
   939         ServiceUpdated( idx );
       
   940         }
       
   941     }
       
   942 
       
   943 // -----------------------------------------------------------------------------
       
   944 // CVcxNsServiceProvider::ReloadThumbnailPathL()
       
   945 // -----------------------------------------------------------------------------
       
   946 //
       
   947 void CVcxNsServiceProvider::ReloadThumbnailPathL( TUint aServiceId )
       
   948     {
       
   949     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::ReloadThumbnailPathL");
       
   950     
       
   951     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
   952     CDesC8ArraySeg* services = NULL;
       
   953     TInt error = iUiEngine.GetServiceClientHandlerL()->GetServiceManagementClientL()->
       
   954                     GetServicesL( aServiceId, aServiceId, services, respStatus );
       
   955     
       
   956     if( error == KErrNone && 
       
   957         respStatus == MIptvServiceManagementClientObserver::ESucceeded &&
       
   958         services )
       
   959         {
       
   960         CleanupStack::PushL( services );
       
   961 
       
   962         if ( services->Count() > 0 )
       
   963             {
       
   964             CIptvService* service = CIptvService::NewL();
       
   965             CleanupStack::PushL( service );
       
   966     
       
   967             service->SetL( services->MdcaPoint( 0 ) );
       
   968     
       
   969             if( EnsureFileExists( service->GetIconPath() ) )
       
   970                 {
       
   971                 CVcxNsService* updated = GetServiceDataById( aServiceId );
       
   972                 if ( updated )
       
   973                     {
       
   974                     updated->SetIconPathL( service->GetIconPath() );
       
   975                     }
       
   976                 }    
       
   977             CleanupStack::PopAndDestroy( service );
       
   978             }
       
   979 
       
   980         CleanupStack::PopAndDestroy( services );
       
   981         }
       
   982     }
       
   983 
       
   984 // -----------------------------------------------------------------------------
       
   985 // CVcxNsServiceProvider::ServiceIndex()
       
   986 // -----------------------------------------------------------------------------
       
   987 //
       
   988 TInt CVcxNsServiceProvider::ServiceIndex( TUint32 aServiceId )
       
   989     {
       
   990     for( TInt i = 0; i < iServiceList.Count(); i++ )
       
   991         {
       
   992         if ( (iServiceList[i])->GetServiceId() == aServiceId )
       
   993             {
       
   994             return i;
       
   995             }
       
   996         }
       
   997     
       
   998     return KErrNotFound;
       
   999     }
       
  1000 
       
  1001 // -----------------------------------------------------------------------------
       
  1002 // CVcxNsServiceProvider::EnsureFileExists()
       
  1003 // -----------------------------------------------------------------------------
       
  1004 //
       
  1005 TBool CVcxNsServiceProvider::EnsureFileExists( const TDesC& aPath )
       
  1006     {
       
  1007     TBool exists( EFalse );
       
  1008     
       
  1009     if ( aPath.Length() > 0 )
       
  1010         {
       
  1011         exists = BaflUtils::FileExists( iFs, aPath );
       
  1012         }
       
  1013 
       
  1014     return exists;
       
  1015     }
       
  1016 
       
  1017 // -----------------------------------------------------------------------------
       
  1018 // CVcxNsServiceProvider::HasFeedDetails()
       
  1019 // -----------------------------------------------------------------------------
       
  1020 //
       
  1021 TBool CVcxNsServiceProvider::HasFeedDetails( TInt aSelected )
       
  1022     {
       
  1023     TBool hasDetails (EFalse);
       
  1024     
       
  1025     if ( aSelected >= 0 && aSelected < iServiceList.Count() )
       
  1026         {
       
  1027         CVcxNsService* service = NULL;
       
  1028         service = GetServiceData( aSelected );
       
  1029                 
       
  1030         if ( service->GetDesc() != KNullDesC )
       
  1031             {
       
  1032             hasDetails = ETrue;
       
  1033             }
       
  1034         }
       
  1035     return hasDetails;
       
  1036     }
       
  1037 
       
  1038 // -----------------------------------------------------------------------------
       
  1039 // CVcxNsServiceProvider::MoveServiceL()
       
  1040 // -----------------------------------------------------------------------------
       
  1041 //
       
  1042 TInt CVcxNsServiceProvider::MoveServiceL( TInt aSourceIndex, TInt aTargetIndex )
       
  1043     {
       
  1044     if ( aSourceIndex == aTargetIndex ||
       
  1045          aSourceIndex < 0 || 
       
  1046          aTargetIndex < 0 ||
       
  1047          aSourceIndex >= iServiceList.Count() ||
       
  1048          aTargetIndex >= iServiceList.Count() )
       
  1049         {
       
  1050         return KErrArgument;
       
  1051         }
       
  1052     
       
  1053     TUint32 movedId = iServiceList[ aSourceIndex ]->GetServiceId();
       
  1054     TUint32 dismountedId = iServiceList[ aTargetIndex ]->GetServiceId();
       
  1055     
       
  1056     CDesC8ArraySeg* services = NULL;
       
  1057     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
  1058     
       
  1059     CIptvServiceManagementClient* smClient = 
       
  1060         iUiEngine.GetServiceClientHandlerL()->GetServiceManagementClientL();
       
  1061 
       
  1062     TInt error = smClient->GetServicesL( dismountedId, dismountedId, services, respStatus  );
       
  1063     
       
  1064     if ( error != KErrNone || 
       
  1065          respStatus != MIptvServiceManagementClientObserver::ESucceeded ||
       
  1066          !services || 
       
  1067          services->Count() <= 0 )
       
  1068         {
       
  1069         return KErrNotFound;
       
  1070         }
       
  1071          
       
  1072     CleanupStack::PushL( services );
       
  1073     
       
  1074     CIptvService* service = NULL;
       
  1075     service = CIptvService::NewL();
       
  1076     CleanupStack::PushL( service );
       
  1077     
       
  1078     service->SetL( services->MdcaPoint( 0 ) );
       
  1079     TUint32 newDispOrder = service->GetDisplayOrder();
       
  1080      
       
  1081     CleanupStack::PopAndDestroy( service );
       
  1082     CleanupStack::PopAndDestroy( services );
       
  1083           
       
  1084     error = smClient->GetServicesL( movedId, movedId, services, respStatus  );
       
  1085     
       
  1086     if ( error != KErrNone || 
       
  1087          respStatus != MIptvServiceManagementClientObserver::ESucceeded ||
       
  1088          !services || 
       
  1089          services->Count() <= 0 )
       
  1090         {
       
  1091         return KErrNotFound;
       
  1092         }     
       
  1093     
       
  1094     service = CIptvService::NewL();
       
  1095     CleanupStack::PushL( service );
       
  1096     CleanupStack::PushL( services );
       
  1097       
       
  1098     service->SetL( services->MdcaPoint( 0 ) );
       
  1099     service->SetDisplayOrder( newDispOrder );
       
  1100     
       
  1101     TInt updateResult = smClient->UpdateServiceL( *service, respStatus );
       
  1102     
       
  1103     if( updateResult == KErrNone &&
       
  1104         respStatus == MIptvServiceManagementClientObserver::ESucceeded )
       
  1105         {
       
  1106         CVcxNsService* tmp = iServiceList[ aSourceIndex ];
       
  1107         iServiceList.Remove( aSourceIndex );
       
  1108         iServiceList.Insert( tmp, aTargetIndex );
       
  1109         }
       
  1110     
       
  1111     CleanupStack::PopAndDestroy( services );
       
  1112     CleanupStack::PopAndDestroy( service );
       
  1113     
       
  1114     return KErrNone;
       
  1115     }
       
  1116 
       
  1117 
       
  1118 // -----------------------------------------------------------------------------
       
  1119 // CVcxNsServiceProvider::HasAccountManagementUri()
       
  1120 // -----------------------------------------------------------------------------
       
  1121 //
       
  1122 TBool CVcxNsServiceProvider::HasAccountManagementUri( TInt aSelected )
       
  1123     {
       
  1124     TBool hasAccManagementUri( EFalse );
       
  1125     
       
  1126     if ( aSelected >= 0 && aSelected < iServiceList.Count() )
       
  1127         {
       
  1128         CVcxNsService* service = NULL;
       
  1129         service = GetServiceData( aSelected );
       
  1130                 
       
  1131         if ( service && service->AccountMgmtUri().Length() > 0 )
       
  1132             {
       
  1133             hasAccManagementUri = ETrue;
       
  1134             }
       
  1135         }
       
  1136     return hasAccManagementUri;
       
  1137     }
       
  1138 
       
  1139 // -----------------------------------------------------------------------------
       
  1140 // Update service in cache ( thumbnail info, update time )
       
  1141 // -----------------------------------------------------------------------------
       
  1142 //
       
  1143 void CVcxNsServiceProvider::UpdateServiceInCacheL( TUint32 aServiceId )
       
  1144     {
       
  1145     IPTVLOGSTRING_LOW_LEVEL("CVcxNsServiceProvider::UpdateServiceInCacheL()");
       
  1146     
       
  1147     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
  1148     CDesC8ArraySeg* services = NULL;
       
  1149     TInt error = iUiEngine.GetServiceClientHandlerL()->GetServiceManagementClientL()->
       
  1150                     GetServicesL( aServiceId, aServiceId, services, respStatus );
       
  1151     
       
  1152     if( error == KErrNone && 
       
  1153         respStatus == MIptvServiceManagementClientObserver::ESucceeded && 
       
  1154         services )
       
  1155         {
       
  1156         CleanupStack::PushL( services );
       
  1157         
       
  1158         if ( services->Count() > 0  )
       
  1159             {
       
  1160             CIptvService* service = CIptvService::NewL();
       
  1161             CleanupStack::PushL( service );
       
  1162     
       
  1163             service->SetL( services->MdcaPoint( 0 ) );
       
  1164     
       
  1165             CVcxNsService* updated = GetServiceDataById( aServiceId );
       
  1166             if ( updated )
       
  1167                 {
       
  1168                 updated->SetIconPathL( service->GetIconPath() );
       
  1169                 updated->SetUpdateTime( service->GetEpgUpdateTimeL() );
       
  1170                 }
       
  1171     
       
  1172             CleanupStack::PopAndDestroy( service );
       
  1173             }
       
  1174         
       
  1175         CleanupStack::PopAndDestroy( services );
       
  1176         }
       
  1177     }
       
  1178 
       
  1179 // -----------------------------------------------------------------------------
       
  1180 // CVcxNsServiceProvider::GetGroupedServicesL()
       
  1181 // -----------------------------------------------------------------------------
       
  1182 //
       
  1183 RPointerArray<CVcxNsService>& CVcxNsServiceProvider::GetGroupedServicesL( 
       
  1184     TUint32 aGroupId )
       
  1185     {
       
  1186     IPTVLOGSTRING_HIGH_LEVEL(
       
  1187         "UI Engine ## CVcxNsServiceProvider::GetGroupedServicesL( )");
       
  1188 
       
  1189     CVcxNsService* groupService = NULL;
       
  1190     
       
  1191     for ( TInt i = 0; i < iServiceList.Count(); i++ )
       
  1192         {
       
  1193         if ( iServiceList[i]->GroupId() == aGroupId )
       
  1194             {
       
  1195             groupService = iServiceList[i];
       
  1196             break;
       
  1197             }
       
  1198         }
       
  1199     
       
  1200     if ( !groupService )
       
  1201         {
       
  1202         User::Leave( KErrArgument );
       
  1203         }
       
  1204 
       
  1205     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
  1206     CDesC8ArraySeg* services = NULL;
       
  1207     TUint32 flags = 0;
       
  1208 
       
  1209     TInt error = iUiEngine.GetServiceClientHandlerL()->GetServiceManagementClientL()->GetServicesL( 
       
  1210                          CIptvServiceManagementClient::EGroupedServices, 
       
  1211                          CIptvServiceManagementClient::EDisplayOrderDescending,
       
  1212                          services,
       
  1213                          respStatus );
       
  1214     
       
  1215     if ( error == KErrNone )
       
  1216         {
       
  1217         CleanupStack::PushL( services );
       
  1218         
       
  1219         CIptvService* service = CIptvService::NewL();
       
  1220         CleanupStack::PushL( service );
       
  1221         
       
  1222         for ( TInt i = 0; i < services->Count(); i++ )
       
  1223             {
       
  1224             service->SetL( services->MdcaPoint(i) );
       
  1225             flags = service->GetFlags();
       
  1226             
       
  1227             if ( flags & CIptvService::EGroupedService 
       
  1228                     && service->GetGroupId() == aGroupId )
       
  1229                 {
       
  1230                 CVcxNsService* newService = CVcxNsService::NewL();
       
  1231                 CleanupStack::PushL( newService );
       
  1232                 newService->SetServiceId( service->GetId() );
       
  1233                 newService->SetNameL( service->GetName() );
       
  1234                 newService->SetGroupId( service->GetGroupId() );
       
  1235                 newService->SetCustomUriL( service->GetAddress() );
       
  1236                
       
  1237                 CIptvService::TServiceType type = service->GetType();
       
  1238                 
       
  1239                 if ( type == CIptvService::EVod || type == CIptvService::EVodCast )
       
  1240                     {
       
  1241                     newService->SetType( CVcxNsService::EVcxNsGroupedVod );
       
  1242                     }
       
  1243                 else if ( type == CIptvService::EBrowser )
       
  1244                     {
       
  1245                     newService->SetType( CVcxNsService::EVcxNsGroupedBrowser );
       
  1246                     }
       
  1247                 else if ( type == CIptvService::ESearch )
       
  1248                     {
       
  1249                     newService->SetType( CVcxNsService::EVcxNsGroupedSearch );
       
  1250                     }
       
  1251                 else if ( type == CIptvService::EUpload )
       
  1252                     {
       
  1253                     newService->SetType( CVcxNsService::EVcxNsGroupedUpload );
       
  1254                     }
       
  1255 
       
  1256                 if ( EnsureFileExists( service->GetIconPath() ))
       
  1257                     {
       
  1258                     newService->SetIconPathL( service->GetIconPath() );
       
  1259                     }
       
  1260 
       
  1261                 newService->SetUpdateTime( service->GetEpgUpdateTimeL() );
       
  1262                 newService->SetUpdateStatus( CVcxNsService::ENotUpdating );
       
  1263                 newService->SetUserNameL( service->GetUserName() );
       
  1264                 newService->SetPasswordL( service->GetPassword() );
       
  1265                 newService->SetDescL( service->GetDesc() );
       
  1266                 newService->SetIsReadOnlyIap( flags & CIptvService::EReadOnlyIaps ? ETrue : EFalse );
       
  1267                 newService->SetAccountMgmtUriL( service->GetAccountManagementUrl() );
       
  1268                 
       
  1269                 if( flags & CIptvService::EReadOnlyIaps )
       
  1270                     {
       
  1271                     // if readonly, more than one?
       
  1272                     newService->SetIap( service->GetIapList().IapL(0).iId );
       
  1273                     }
       
  1274                 
       
  1275                 groupService->AddSubServiceL( newService );
       
  1276                 CleanupStack::Pop( newService );
       
  1277                 }
       
  1278             }
       
  1279         
       
  1280         CleanupStack::PopAndDestroy( service );
       
  1281         CleanupStack::PopAndDestroy( services );
       
  1282         }
       
  1283     
       
  1284     return groupService->ServiceGroup();
       
  1285     }
       
  1286 
       
  1287 // -----------------------------------------------------------------------------
       
  1288 // CVcxNsServiceProvider::OpenServiceFromGroupL()
       
  1289 // -----------------------------------------------------------------------------
       
  1290 //
       
  1291 void CVcxNsServiceProvider::OpenServiceFromGroupL( TInt aIndex )
       
  1292     {
       
  1293     CVcxNsService* activeGroup = NULL;
       
  1294     activeGroup = GetActiveServiceData();
       
  1295     if ( activeGroup && 
       
  1296          activeGroup->Type() == CVcxNsService::EVcxNsMainGroup )
       
  1297         {
       
  1298         RPointerArray<CVcxNsService>& groupedServices = activeGroup->ServiceGroup();
       
  1299         if ( groupedServices.Count() > aIndex )
       
  1300             {
       
  1301             CVcxNsService* serviceToOpen = groupedServices[aIndex];
       
  1302             if ( serviceToOpen )
       
  1303                 {
       
  1304                 CVcxNsService::TVcxNsVodServiceType type = groupedServices[aIndex]->Type();
       
  1305                 if ( type == CVcxNsService::EVcxNsGroupedVod )
       
  1306                     {
       
  1307                     iUiEngine.SetActiveServiceGroup( activeGroup->GetServiceId() );
       
  1308                     iUiEngine.SetActiveService( serviceToOpen->GetServiceId() );
       
  1309                     RPointerArray<CVcxNsCategory>& categorys = iUiEngine.GetCategoryProviderL()->GetCategorysL();
       
  1310                     
       
  1311                     if( categorys.Count() == 0 )
       
  1312                         {
       
  1313                         iUiEngine.SetActiveCategory( KIptvVodContentCategoryRootId );
       
  1314                         iUiEngine.SetVcAppState( EStateContentView );            
       
  1315                         }
       
  1316                     else if( categorys.Count() == 1 &&
       
  1317                              categorys[0]->GetCategoryId() == KIptvRssSearchCategoryId )
       
  1318                         {
       
  1319                         iUiEngine.SetActiveCategory( (categorys[0])->GetCategoryId() );
       
  1320                         iUiEngine.SetVcAppState( EStateCategoryView );
       
  1321                         }
       
  1322                     else if( categorys.Count() == 1 )
       
  1323                         {
       
  1324                         iUiEngine.SetActiveCategory( (categorys[0])->GetCategoryId() );
       
  1325                         iUiEngine.SetVcAppState( EStateContentView );
       
  1326                         }
       
  1327                     else
       
  1328                         {
       
  1329                         iUiEngine.SetVcAppState( EStateCategoryView );
       
  1330                         }
       
  1331                     }
       
  1332                 else if ( type == CVcxNsService::EVcxNsGroupedBrowser )
       
  1333                     {
       
  1334                     if ( ( serviceToOpen->CustomUri().Length() > 0 ) && 
       
  1335                          ( serviceToOpen->CustomUri().FindF( KVcxNsRtspProtocol ) == 0 ) )
       
  1336                         {
       
  1337                         OpenToPlayerL( serviceToOpen->GetName(), 
       
  1338                                        serviceToOpen->CustomUri() );
       
  1339                         }
       
  1340                     else
       
  1341                         {
       
  1342                         OpenToBrowserL( serviceToOpen->CustomUri() );
       
  1343                         }
       
  1344 
       
  1345                     }
       
  1346                 else if ( type == CVcxNsService::EVcxNsGroupedSearch )
       
  1347                     {
       
  1348                     iUiEngine.SetActiveServiceGroup( activeGroup->GetServiceId() );
       
  1349                     iUiEngine.SetActiveService( serviceToOpen->GetServiceId() );
       
  1350                     iUiEngine.SetActiveCategory( KIptvRssSearchCategoryId );
       
  1351                     
       
  1352                     if ( iUiEngine.GetContentProviderL()->GetContentsL().Count() > 0 )
       
  1353                         {
       
  1354                         iUiEngine.SetVcAppState( EStateContentView );
       
  1355                         iUiEngine.ServiceProvider()->HandleAppStateChangedL();
       
  1356                         }
       
  1357                     else
       
  1358                         {
       
  1359                         iUiEngine.GetContentSearchHandlerL()->StartNewSearchL();
       
  1360                         }
       
  1361                     }
       
  1362                 }
       
  1363             }
       
  1364         }
       
  1365     }
       
  1366 
       
  1367 // -----------------------------------------------------------------------------
       
  1368 // Open link to browser
       
  1369 // -----------------------------------------------------------------------------
       
  1370 //
       
  1371 void CVcxNsServiceProvider::OpenToBrowserL( const TDesC& aUri )
       
  1372     {
       
  1373     if ( aUri.Length() > 0 )
       
  1374         {
       
  1375         for ( TInt i = 0; i < iServiceObservers.Count(); i++ )
       
  1376             {
       
  1377             if( iServiceObservers[i] )
       
  1378                 {
       
  1379                 iServiceObservers[i]->OpenBrowserLinkL( aUri );
       
  1380                 }
       
  1381             }
       
  1382         iUiEngine.SetVcAppState( EStateBrowser );
       
  1383         }
       
  1384     }
       
  1385 
       
  1386 // -----------------------------------------------------------------------------
       
  1387 // Open rtsp link to player
       
  1388 // -----------------------------------------------------------------------------
       
  1389 //
       
  1390 void CVcxNsServiceProvider::OpenToPlayerL( const TDesC& /*aName*/, const TDesC& aUri )
       
  1391     {
       
  1392     if ( !( aUri.FindF( KVcxNsRtspProtocol ) == 0 ) )
       
  1393         {
       
  1394         User::Leave( KErrArgument );
       
  1395         }
       
  1396     else
       
  1397         {
       
  1398         /***
       
  1399          * Send player custom message to UI and start playing:
       
  1400          * iIcon = Service icon
       
  1401          ***/
       
  1402         for ( TInt i = 0; i < iServiceObservers.Count(); i++ )
       
  1403             {
       
  1404             if( iServiceObservers[i] )
       
  1405                 {
       
  1406                 iServiceObservers[i]->OpenStreamingLinkL( aUri );
       
  1407                 }
       
  1408             }     
       
  1409         }
       
  1410     }
       
  1411 
       
  1412