videofeeds/vcnsuiengine/src/vcxnsservicesettings.cpp
branchRCL_3
changeset 23 befca0ec475f
parent 0 96612d01cf9f
equal deleted inserted replaced
22:839377eedc2b 23:befca0ec475f
       
     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 #include "CIptvIapList.h"
       
    25 
       
    26 #include "CIptvServiceManagementClient.h"
       
    27 #include "vcxnsservicesettings.h"
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CVcxNsServiceSettings::CVcxNsServiceSettings()
       
    33 // 
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CVcxNsServiceSettings::CVcxNsServiceSettings( )
       
    37     {
       
    38     }
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CVcxNsServiceSettings::CVcxNsServiceSettings()
       
    42 // 
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CVcxNsServiceSettings::~CVcxNsServiceSettings( )
       
    46     {
       
    47     delete iIptvServiceManagementClient;
       
    48     }
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CVcxNsServiceSettings::NewL()
       
    52 // 
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 EXPORT_C CVcxNsServiceSettings* CVcxNsServiceSettings::NewL( )
       
    56     {
       
    57     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsServiceSettings::NewL()");
       
    58     
       
    59     return new (ELeave) CVcxNsServiceSettings();
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CVcxNsServiceSettings::GetAllServicesL()
       
    64 // Note: Returns NULL if an error occurs.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 EXPORT_C CDesC8ArraySeg* CVcxNsServiceSettings::GetAllServicesL()
       
    68     {
       
    69     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsServiceSettings::GetAllServicesL()");
       
    70 
       
    71     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
    72     CDesC8ArraySeg* services = NULL;
       
    73 
       
    74     TInt error = GetServiceManagementClientL()->GetServicesL( 0, 
       
    75                                                               CIptvServiceManagementClient::EDisplayOrderDescending,
       
    76                                                               services,
       
    77                                                               respStatus );
       
    78     if ( error == KErrNone )
       
    79         {
       
    80         return services;
       
    81         }
       
    82     else
       
    83         {
       
    84         return NULL;
       
    85         }
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CVcxNsServiceSettings::GetAllSelectedServicesL()
       
    90 // Note: Returns NULL if an error occurs.
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C CDesC8ArraySeg* CVcxNsServiceSettings::GetAllSelectedServicesL( TInt& aError )
       
    94     {
       
    95     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsServiceSettings::GetAllSelectedServicesL()");
       
    96     
       
    97     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
    98     CDesC8ArraySeg* services = NULL;
       
    99     
       
   100     aError = GetServiceManagementClientL()->GetServicesL( CIptvServiceManagementClient::ESelectedServices, 
       
   101                                                           CIptvServiceManagementClient::EDisplayOrderDescending,
       
   102                                                           services,
       
   103                                                           respStatus );
       
   104     if ( aError == KErrNone )
       
   105         {
       
   106         return services;
       
   107         }
       
   108     else
       
   109         {
       
   110         return NULL;
       
   111         }
       
   112     }
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CVcxNsServiceSettings::GetServicesByTypeL()
       
   116 // Note: Returns NULL if an error occurs.
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 EXPORT_C CDesC8ArraySeg* CVcxNsServiceSettings::GetServicesByTypeL( CIptvService::TServiceType aServiceType )
       
   120     {
       
   121     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsServiceSettings::GetServicesByTypeL()");
       
   122 
       
   123     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
   124     CDesC8ArraySeg* services = NULL;
       
   125 
       
   126     CIptvServiceManagementClient::TSearchLimitFlag flag = (CIptvServiceManagementClient::TSearchLimitFlag) 0;
       
   127 
       
   128     switch ( aServiceType )
       
   129         {
       
   130         case CIptvService::EVod:
       
   131             // using flag EVodServices to also include service groups and vodcasts.
       
   132             flag = CIptvServiceManagementClient::EVodServices;
       
   133             break;
       
   134         case CIptvService::ELiveTv:
       
   135             flag = CIptvServiceManagementClient::ELiveTv;
       
   136             break;
       
   137         case CIptvService::EVodCast:
       
   138             flag = CIptvServiceManagementClient::EVodCast;
       
   139             break;
       
   140         case CIptvService::EBrowser:
       
   141             flag = CIptvServiceManagementClient::EBrowser;
       
   142             break;
       
   143         case CIptvService::EVideoRemote:     
       
   144             flag = CIptvServiceManagementClient::EVideoRemote;
       
   145             break;               
       
   146         case CIptvService::EApplication:
       
   147             flag = CIptvServiceManagementClient::EApplication;
       
   148             break;        
       
   149         case CIptvService::EMobileTv:
       
   150             flag = CIptvServiceManagementClient::EMobileTv;
       
   151             break;
       
   152         case CIptvService::EOther:
       
   153             flag = CIptvServiceManagementClient::EOther;
       
   154             break;        
       
   155         default:     
       
   156             flag = (CIptvServiceManagementClient::TSearchLimitFlag) 0;
       
   157             break;
       
   158         }
       
   159 
       
   160     TInt error = GetServiceManagementClientL()->GetServicesL( flag, 
       
   161                                                               CIptvServiceManagementClient::EDisplayOrderDescending,
       
   162                                                               services,
       
   163                                                               respStatus );                                                             
       
   164     if ( error == KErrNone )
       
   165         {
       
   166         return services;
       
   167         }
       
   168     else
       
   169         {
       
   170         return NULL;
       
   171         }
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CVcxNsServiceSettings::GetIapListForNewServiceL()
       
   176 // Gathers list of IAPs from other user defined services.
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 EXPORT_C TInt CVcxNsServiceSettings::GetIapListForNewServiceL( CIptvIapList& aIapList )
       
   180     {
       
   181     CDesC8ArraySeg* services = GetAllServicesL();
       
   182     
       
   183     if ( services )
       
   184         {
       
   185         CleanupStack::PushL( services );
       
   186 
       
   187         CIptvService* service = CIptvService::NewL();
       
   188         CleanupStack::PushL( service );
       
   189 
       
   190         // Go through all services.
       
   191         for (TInt i = 0; i < services->Count(); i++)
       
   192             {
       
   193             service->SetL( services->MdcaPoint(i) );
       
   194 
       
   195             TUint32 flags = service->GetFlags();
       
   196 
       
   197             // Only copy IAPs from user modifiable services (not provisioned).
       
   198             if ( ! (flags & CIptvService::EReadOnlyIaps) )
       
   199                 {
       
   200                 // Go through all IAPs for this service.
       
   201                 for ( TUint8 j = 0; j < service->iIapList->Count(); j++ )
       
   202                     {
       
   203                     TIptvIap& existingIap = service->iIapList->IapL( j ); 
       
   204 
       
   205                     // Check that this IAP is not already on user's list.
       
   206                     TBool bFound = EFalse;
       
   207                     for ( TUint8 k = 0; k < aIapList.Count(); k++ )
       
   208                         {
       
   209                         TIptvIap& userIap = aIapList.IapL( k );
       
   210                         
       
   211                         if ( userIap.iId == existingIap.iId )
       
   212                             {
       
   213                             bFound = ETrue;
       
   214                             break;
       
   215                             }
       
   216                         }
       
   217                       
       
   218                     // Add IAP to user's list.  
       
   219                     if ( ! bFound )
       
   220                         {
       
   221                         aIapList.AddIap( existingIap );
       
   222                         }
       
   223                     }
       
   224                 }
       
   225             }
       
   226 
       
   227         CleanupStack::PopAndDestroy( service );
       
   228         services->Reset();
       
   229         CleanupStack::PopAndDestroy( services );
       
   230 
       
   231         if (aIapList.Count() > 0)
       
   232             {
       
   233             return KErrNone;            
       
   234             }
       
   235         }
       
   236 
       
   237     return KErrNotFound;
       
   238     }
       
   239 // -----------------------------------------------------------------------------
       
   240 // CVcxNsServiceSettings::AddServiceL()
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 EXPORT_C TInt CVcxNsServiceSettings::AddServiceL( const TDesC& aServiceName,
       
   244                                              const TDesC& aAddress,
       
   245                                              const TDesC& aDescription,
       
   246                                              CIptvIapList& aIapList,
       
   247                                              CIptvService::TServiceType aServiceType,
       
   248                                              const TUid& aEpgPluginUid,
       
   249                                              const TUid& aIptvPluginUid,
       
   250                                              const TUid& aVodPluginUid )
       
   251     {
       
   252     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsServiceSettings::AddServiceL()");
       
   253 
       
   254     if ( aServiceName.Length() == 0 || aAddress.Length() == 0 )
       
   255         {
       
   256         return KErrArgument;
       
   257         }
       
   258 
       
   259     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
   260     CIptvService*                                     iptvService = CIptvService::NewL();
       
   261     CleanupStack::PushL( iptvService );
       
   262 
       
   263     iptvService->SetId( 0 );
       
   264     iptvService->SetName( aServiceName );
       
   265     iptvService->SetAddress( aAddress );
       
   266     iptvService->SetIconPath( KNullDesC );
       
   267     iptvService->SetType( aServiceType );
       
   268     iptvService->SetDesc( aDescription );
       
   269     iptvService->SetFlags( CIptvService::ESelected );
       
   270     iptvService->SetApplicationUid( 0 );
       
   271     iptvService->SetDisplayOrder( 0 );
       
   272     iptvService->iIapList->SetL( aIapList );
       
   273     
       
   274     iptvService->SetEpgPluginUid(aEpgPluginUid);
       
   275     iptvService->SetIptvPluginUid(aIptvPluginUid);
       
   276     iptvService->SetVodPluginUid(aVodPluginUid);
       
   277 
       
   278     TInt error = GetServiceManagementClientL()->AddServiceL( *iptvService, respStatus );
       
   279 
       
   280 
       
   281 
       
   282     CleanupStack::PopAndDestroy( iptvService );
       
   283     return error;
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CVcxNsServiceSettings::UpdateServiceL()
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 EXPORT_C void CVcxNsServiceSettings::UpdateServiceL( CIptvService& aIptvService )
       
   291     {
       
   292     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsServiceSettings::UpdateServiceL()");
       
   293     
       
   294     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
   295     
       
   296     GetServiceManagementClientL()->UpdateServiceL( aIptvService, respStatus );
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // CVcxNsServiceSettings::DeleteServiceL()
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 EXPORT_C void CVcxNsServiceSettings::DeleteServiceL( TUint32 aItemId )
       
   304     {
       
   305     IPTVLOGSTRING_HIGH_LEVEL("UI Engine ## CVcxNsServiceSettings::DeleteServiceL()");
       
   306 
       
   307     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
   308 
       
   309     GetServiceManagementClientL()->DeleteServiceL( aItemId, respStatus );
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CVcxNsServiceSettings::GetServiceL()
       
   314 // Note: Method is not efficient, so use only if absolutely necessary.
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 EXPORT_C TInt CVcxNsServiceSettings::GetServiceL( TUint32 aServiceId, CIptvService& aIptvService )
       
   318     {
       
   319     /*CDesC8ArraySeg* services = NULL;
       
   320     MIptvServiceManagementClientObserver::TRespStatus respStatus;
       
   321 
       
   322     if ( ! iIptvServiceManagementClient )
       
   323         {
       
   324         iIptvServiceManagementClient = CIptvServiceManagementClient::NewL( *this );
       
   325         }
       
   326 
       
   327     TInt error = iIptvServiceManagementClient->GetServicesL( aServiceId, aServiceId, services, respStatus );
       
   328 
       
   329     if ( error == KErrNone && services->MdcaCount() > 0)
       
   330         {
       
   331         CleanupStack::PushL( services );
       
   332         aIptvService.SetL( services->MdcaPoint(0) );
       
   333         CleanupStack::PopAndDestroy( services );
       
   334         return KErrNone;
       
   335         }
       
   336 
       
   337     return KErrNotFound;
       
   338     */
       
   339 
       
   340     //Get only this specified service   
       
   341     CDesC8ArraySeg* services = GetAllServicesL();
       
   342     TInt            error    = KErrNotFound;
       
   343 
       
   344     if ( services )
       
   345         {
       
   346         CleanupStack::PushL( services );
       
   347 
       
   348         CIptvService* service = CIptvService::NewL();
       
   349         CleanupStack::PushL( service );
       
   350 
       
   351         // Go through all services.
       
   352         for ( TInt i = 0; i < services->Count(); i++ )
       
   353             {
       
   354             service->SetL( services->MdcaPoint(i) );
       
   355             
       
   356             if ( service->GetId() == aServiceId )
       
   357                 {
       
   358                 aIptvService.SetL( services->MdcaPoint(i) );
       
   359                 error = KErrNone;
       
   360                 }
       
   361             }
       
   362 
       
   363         CleanupStack::PopAndDestroy( service );
       
   364         CleanupStack::PopAndDestroy( services );
       
   365         }
       
   366     
       
   367     return error;    
       
   368     
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CVcxNsServiceProvider::GetServiceManagementClientL()
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 CIptvServiceManagementClient* CVcxNsServiceSettings::GetServiceManagementClientL()
       
   376     {
       
   377     if ( ! iIptvServiceManagementClient )
       
   378         {
       
   379         iIptvServiceManagementClient = CIptvServiceManagementClient::NewL( *this );
       
   380         }
       
   381     
       
   382     return iIptvServiceManagementClient;    
       
   383     }
       
   384 
       
   385 
       
   386 // -----------------------------------------------------------------------------
       
   387 // CVcxNsServiceSettings::GetScheduledDownloadSettingsL
       
   388 // -----------------------------------------------------------------------------
       
   389 //
       
   390 EXPORT_C TInt CVcxNsServiceSettings::GetScheduledDownloadSettingsL(
       
   391     TIptvServiceId aServiceId,
       
   392     TIptvVodScheduleDownloadtimeCombination& aDownloadTime,
       
   393     TIptvVodScheduleConnectionCondition& aCondition,
       
   394     TIptvVodScheduleDownloadTypeCombination& aType )
       
   395     {
       
   396     CIptvService* service = CIptvService::NewL();
       
   397     CleanupStack::PushL( service );
       
   398     
       
   399     TInt err = GetServiceL( aServiceId, *service );
       
   400     
       
   401     if ( err == KErrNone )
       
   402         {
       
   403         aDownloadTime = service->ScheduleDlTime();
       
   404         aCondition = static_cast<TIptvVodScheduleConnectionCondition>(
       
   405                         service->ScheduleDlNetwork() );
       
   406         aType = service->ScheduleDlType();
       
   407         }
       
   408     
       
   409     CleanupStack::PopAndDestroy( service );
       
   410     
       
   411     return err;
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // CVcxNsServiceSettings::SetScheduledDownloadSettingsL
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 EXPORT_C TInt CVcxNsServiceSettings::SetScheduledDownloadSettingsL(
       
   419     TIptvServiceId aServiceId,
       
   420     TIptvVodScheduleDownloadtimeCombination aDownloadTime,
       
   421     TIptvVodScheduleConnectionCondition aCondition,
       
   422     TIptvVodScheduleDownloadTypeCombination aType )
       
   423     {
       
   424     CIptvService* service = CIptvService::NewL();
       
   425     CleanupStack::PushL( service );
       
   426     
       
   427     TInt err = GetServiceL( aServiceId, *service );
       
   428 
       
   429     if ( err == KErrNone )
       
   430         {
       
   431         service->SetScheduleDlTime( aDownloadTime );
       
   432         service->SetScheduleDlNetwork( aCondition );
       
   433         service->SetScheduleDlType( aType );
       
   434 
       
   435         //  If this is the first time scheduling for this service.
       
   436         if ( service->GetScheduledLastDownloadTime().Int64() == 0 &&
       
   437              aCondition != EManual &&
       
   438              aDownloadTime != ENoSchedule )
       
   439             {
       
   440             TTime current;
       
   441             current.UniversalTime();
       
   442             service->SetScheduledLastDownloadTime( current );
       
   443             }
       
   444         // If we move back to manual download state, let's reset the 'last
       
   445         // scheduled download time' so that old scheduling for service does
       
   446         // not confuse user when he later on sets scheduling on again.
       
   447         else if ( aCondition == EManual )
       
   448             {
       
   449             TTime zero( 0 );
       
   450             
       
   451             service->SetScheduledLastDownloadTime( zero );
       
   452             }
       
   453 
       
   454         UpdateServiceL( *service );
       
   455         }
       
   456 
       
   457     CleanupStack::PopAndDestroy( service );
       
   458 
       
   459     return err;
       
   460     }