convergedcallengine/spsettings/tsrc/public/basic/spsettingsUT/stubs/T_spsettingsengineStub.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c)  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 "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:  Service Provider Settings API's engine.
       
    15 *
       
    16 */
       
    17 
       
    18 // The entire file is taken from 3.2.3 baseline
       
    19 
       
    20 #include <centralrepository.h>
       
    21 #include <e32property.h>
       
    22 #include <FeatMgr.h>
       
    23 #include <SettingsInternalCRKeys.h>
       
    24 #include <cenrepdatabaseutil.h>
       
    25 
       
    26 #include "spsettingsengine.h"
       
    27 #include "spentry.h"
       
    28 #include "spproperty.h"
       
    29 #include "spcrkeys.h"
       
    30 #include "spdefinitions.h"
       
    31 #include "spdefaultvalues.h"
       
    32 
       
    33 
       
    34 #include "spsapilogger.h" // For logging
       
    35 
       
    36 const TInt KSPPredefinedCount = 2;
       
    37 TInt counter( 0 );
       
    38 
       
    39 
       
    40 
       
    41 // ======== MEMBER FUNCTIONS ========
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // Constructor
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CSPSettingsEngine::CSPSettingsEngine()
       
    48     {
       
    49     }
       
    50 
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Constructor
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 void CSPSettingsEngine::ConstructL()
       
    57     {
       
    58     XSPSLOGSTRING( "CSPSettingsEngine::ConstructL() - IN" );
       
    59     
       
    60     iCenRepUtils = CCenRepDatabaseUtil::NewL( KCRUidSPSettings, 
       
    61                                             KSPStartKey,
       
    62                                             KSPColIncrement,         
       
    63                                             KSPColMask, 
       
    64                                             KServiceIdCounter,
       
    65                                             KSPColCount );
       
    66 
       
    67     XSPSLOGSTRING( "CSPSettingsEngine::ConstructL() - OUT" );
       
    68     }
       
    69 
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // Constructor
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 CSPSettingsEngine* CSPSettingsEngine::NewL()
       
    76     {
       
    77     CSPSettingsEngine* self = CSPSettingsEngine::NewLC();
       
    78     CleanupStack::Pop( self );
       
    79     return self;
       
    80     }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // Constructor
       
    85 // ---------------------------------------------------------------------------
       
    86 //
       
    87 CSPSettingsEngine* CSPSettingsEngine::NewLC()
       
    88     {
       
    89     CSPSettingsEngine* self = new( ELeave ) CSPSettingsEngine;
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL();
       
    92     return self;
       
    93     }
       
    94 
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // Destructor
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 CSPSettingsEngine::~CSPSettingsEngine()
       
   101     {
       
   102     XSPSLOGSTRING( "CSPSettingsEngine::~CSPSettingsEngine() - IN" );
       
   103     
       
   104     delete iCenRepUtils;
       
   105 
       
   106     XSPSLOGSTRING( "CSPSettingsEngine::~CSPSettingsEngine() - OUT" );
       
   107     }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // Begins transaction in repository.
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 TInt CSPSettingsEngine::BeginTransactionLC()
       
   115     {
       
   116     XSPSLOGSTRING( "CSPSettingsEngine::BeginTransaction() - IN" );
       
   117 
       
   118     iCenRepUtils->BeginTransactionL();
       
   119     
       
   120     XSPSLOGSTRING( "CSPSettingsEngine::BeginTransaction() - OUT" );
       
   121     
       
   122     return KErrNone;
       
   123     
       
   124     }
       
   125 
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Commits changes in repository.
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 TInt CSPSettingsEngine::CommitTransaction()
       
   132     {
       
   133     XSPSLOGSTRING( 
       
   134         "CSPSettingsEngine::CommitTransaction() - IN" );
       
   135 
       
   136     iCenRepUtils->CommitTransaction();
       
   137     
       
   138     XSPSLOGSTRING( "CSPSettingsEngine::CommitTransaction() - OUT" );
       
   139 
       
   140     return KErrNone;
       
   141     }
       
   142 
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // Rollback changes in repository.
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CSPSettingsEngine::RollbackTransaction()
       
   149     {
       
   150     XSPSLOGSTRING( 
       
   151         "CSPSettingsEngine::RollbackTransaction() - IN" );
       
   152 
       
   153     iCenRepUtils->RollbackTransaction();
       
   154     
       
   155     XSPSLOGSTRING( "CSPSettingsEngine::RollbackTransaction() - OUT" );
       
   156 
       
   157     }
       
   158 
       
   159 void CSPSettingsEngine::ConvertSpEntryToCenRepArrayL( const CSPEntry& aEntry, 
       
   160                                                      RIpAppPropArray& aArray )
       
   161     {
       
   162     CCenRepDatabaseProperty* property = CCenRepDatabaseProperty::NewLC();
       
   163     
       
   164     property->SetName( EServiceName );
       
   165     property->SetValue( aEntry.GetServiceName() );
       
   166     User::LeaveIfError( aArray.Append( property ) );
       
   167     CleanupStack::Pop( property );
       
   168     
       
   169     TInt count = aEntry.PropertyCount();
       
   170     const RPropertyArray& entryArray = aEntry.GetAllProperties();
       
   171     
       
   172     ConvertSpArrayToCenRepArrayL( entryArray, aArray );
       
   173     }
       
   174     
       
   175 void CSPSettingsEngine::ConvertSpArrayToCenRepArrayL( const RPropertyArray& aSpArray,
       
   176                                                       RIpAppPropArray& aCenRepArray )
       
   177     {
       
   178     TInt count = aSpArray.Count();
       
   179     for( TInt i = 0; i < count; i++ )
       
   180         {
       
   181         CSPProperty* spProperty = aSpArray[i];
       
   182         CCenRepDatabaseProperty* property = CCenRepDatabaseProperty::NewLC();
       
   183         property->SetName( spProperty->GetName() );
       
   184         
       
   185         RBuf value;
       
   186         value.CreateL( KSPMaxDesLength );
       
   187         CleanupClosePushL( value);
       
   188         User::LeaveIfError( spProperty->GetValue( value ) );
       
   189         User::LeaveIfError( property->SetValue( value ) );
       
   190         CleanupStack::PopAndDestroy( &value );
       
   191         
       
   192         User::LeaveIfError( aCenRepArray.Append( property ) );
       
   193         CleanupStack::Pop( property );
       
   194         }
       
   195     }
       
   196     
       
   197 void CSPSettingsEngine::CleanupPointerArray(  TAny* aPointer )
       
   198 	{
       
   199 	RIpAppPropArray* array = static_cast<RIpAppPropArray*>( aPointer );
       
   200 	array->ResetAndDestroy();
       
   201 	}
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // Stores new service provider settings entry
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CSPSettingsEngine::AddEntryL( CSPEntry& aEntry )
       
   208     {
       
   209     XSPSLOGSTRING( "CSPSettingsEngine::AddEntryL() - IN" );
       
   210     
       
   211     // check the service name is not empty
       
   212     if( aEntry.GetServiceName().Length() == 0 )
       
   213     	{
       
   214     	User::LeaveIfError( KErrArgument );
       
   215     	}
       
   216 
       
   217     // construct RIpAppPropArray
       
   218     RIpAppPropArray array;
       
   219 	TCleanupItem cleanup( CSPSettingsEngine::CleanupPointerArray, &array );
       
   220 	CleanupStack::PushL( cleanup );
       
   221     
       
   222     ConvertSpEntryToCenRepArrayL( aEntry, array );
       
   223 
       
   224     // Create new unique service ID
       
   225     TInt newId = 0;
       
   226     iCenRepUtils->AddEntryL( newId, array );
       
   227     aEntry.SetServiceId( newId );
       
   228     
       
   229     CleanupStack::PopAndDestroy( &array );
       
   230     
       
   231     XSPSLOGSTRING( "CSPSettingsEngine::AddEntryL() - OUT" );
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // Find service provider settings entry by service ID
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238  TInt CSPSettingsEngine::FindEntryL( TServiceId aServiceId, CSPEntry& aEntry )
       
   239     {
       
   240     XSPSLOGSTRING2( "CSPSettingsEngine::FindEntryL( %d ) - IN", aServiceId );
       
   241     
       
   242     RIpAppPropArray array;
       
   243 	TCleanupItem cleanup( CSPSettingsEngine::CleanupPointerArray, &array );
       
   244 	CleanupStack::PushL( cleanup );
       
   245 
       
   246     TInt err = iCenRepUtils->FindEntryL( aServiceId, array );
       
   247     
       
   248     if( err == KErrNone )
       
   249         {
       
   250         TInt count = array.Count();
       
   251 
       
   252         for( TInt i = 0; i < count; i++ )
       
   253             {
       
   254             CCenRepDatabaseProperty* property = array[i];
       
   255             
       
   256             if( property->GetName() == EServiceName )
       
   257                 {
       
   258                 User::LeaveIfError( aEntry.SetServiceName( property->GetDesValue() ) );
       
   259                 }
       
   260             else
       
   261                 {
       
   262                 CSPProperty* spProperty = CSPProperty::NewLC();
       
   263                 User::LeaveIfError( spProperty->SetName( (TServicePropertyName)( property->GetName() )));
       
   264                 User::LeaveIfError( spProperty->SetValue( property->GetDesValue() ));
       
   265                 
       
   266                 User::LeaveIfError( aEntry.AddPropertyL( *spProperty ));
       
   267                 CleanupStack::PopAndDestroy( spProperty );
       
   268                 }
       
   269             }
       
   270         }
       
   271     CleanupStack::PopAndDestroy( &array );
       
   272     
       
   273     aEntry.SetServiceId( aServiceId );
       
   274     
       
   275     XSPSLOGSTRING2( "CSPSettingsEngine::FindEntryL( %d ) - OUT", aServiceId );
       
   276     
       
   277     return err;
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // Update existing service provider settings entry
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 TInt CSPSettingsEngine::UpdateEntryL( const CSPEntry& aEntry )
       
   285     {
       
   286     XSPSLOGSTRING( "CSPSettingsEngine::UpdateEntry() - IN" );
       
   287 
       
   288     TServiceId serviceId( aEntry.GetServiceId() );
       
   289 
       
   290     // Leave if there is no service ID 
       
   291     if ( KSPNoId == serviceId || aEntry.GetServiceName().Length() == 0 )
       
   292         {
       
   293         User::Leave( KErrArgument );
       
   294         }
       
   295 
       
   296     // construct RIpAppPropArray
       
   297     RIpAppPropArray array;
       
   298 	TCleanupItem cleanup( CSPSettingsEngine::CleanupPointerArray, &array );
       
   299 	CleanupStack::PushL( cleanup );
       
   300     
       
   301     ConvertSpEntryToCenRepArrayL( aEntry, array );
       
   302 
       
   303     TInt err = iCenRepUtils->UpdateEntryL( (TInt) serviceId, array );
       
   304     
       
   305     CleanupStack::PopAndDestroy( &array );
       
   306 	
       
   307     XSPSLOGSTRING( "CSPSettingsEngine::UpdateEntry() - OUT" );
       
   308     
       
   309     return err;
       
   310     }
       
   311 
       
   312 	
       
   313 // ---------------------------------------------------------------------------
       
   314 // Deletes service provider settings entry by service ID
       
   315 // ---------------------------------------------------------------------------
       
   316 //
       
   317 TInt CSPSettingsEngine::DeleteEntryL( TServiceId aServiceId )
       
   318     {
       
   319     XSPSLOGSTRING2( "CSPSettingsEngine::DeleteEntryL(%d) - IN", aServiceId );
       
   320 
       
   321     TInt err = iCenRepUtils->DeleteEntryL( aServiceId );
       
   322     
       
   323     XSPSLOGSTRING2( "CSPSettingsEngine::DeleteEntryL(%d) - OUT", aServiceId );
       
   324     
       
   325     return err;
       
   326     }
       
   327 
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // Search property of service provider settings entry by property name
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 TInt CSPSettingsEngine::FindPropertyL( TServiceId aServiceId, 
       
   334     								   TServicePropertyName aPropertyName, 
       
   335     								   CSPProperty& aProperty )
       
   336     {
       
   337     XSPSLOGSTRING2( "CSPSettingsEngine::FindPropertyL(%d) - IN", aServiceId );
       
   338 
       
   339     CCenRepDatabaseProperty* cenrepProperty = CCenRepDatabaseProperty::NewLC();
       
   340     TInt err = iCenRepUtils->FindPropertyL( aServiceId, aPropertyName, *cenrepProperty );
       
   341     
       
   342     if( err == KErrNone )
       
   343         {
       
   344         User::LeaveIfError( aProperty.SetName( aPropertyName ) );
       
   345         User::LeaveIfError( aProperty.SetValue( cenrepProperty->GetDesValue()));
       
   346         }
       
   347         
       
   348     CleanupStack::PopAndDestroy( cenrepProperty );
       
   349     
       
   350     XSPSLOGSTRING2( "CSPSettingsEngine::FindPropertyL(%d) - OUT", aServiceId );
       
   351     
       
   352 /*    if ( !counter )
       
   353         {
       
   354         counter++;
       
   355         }
       
   356     else
       
   357         {
       
   358         err = KErrNone;
       
   359         }*/
       
   360 //    err = KErrNone;
       
   361     return err;
       
   362     }
       
   363 
       
   364 
       
   365 // ---------------------------------------------------------------------------
       
   366 // Add or update properties of service provider settings entry
       
   367 // ---------------------------------------------------------------------------
       
   368 //
       
   369 TInt CSPSettingsEngine::AddOrUpdatePropertiesL( TServiceId aServiceId,
       
   370 												const RPropertyArray& aPropertyArray )
       
   371     {
       
   372     XSPSLOGSTRING2( "CSPSettingsEngine::AddOrUpdatePropertiesL(%d) - IN", aServiceId );
       
   373 
       
   374     // construct RIpAppPropArray
       
   375     RIpAppPropArray array;
       
   376 	TCleanupItem cleanup( CSPSettingsEngine::CleanupPointerArray, &array );
       
   377 	CleanupStack::PushL( cleanup );
       
   378     
       
   379     ConvertSpArrayToCenRepArrayL( aPropertyArray, array );
       
   380     
       
   381     TInt err = iCenRepUtils->AddOrUpdatePropertiesL( aServiceId, array );    
       
   382 
       
   383     CleanupStack::PopAndDestroy( &array );
       
   384     
       
   385     XSPSLOGSTRING2( 
       
   386         "CSPSettingsEngine::AddOrUpdatePropertiesL(%d) - OUT", aServiceId );
       
   387         
       
   388     return err;
       
   389     }
       
   390 
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // Returns count of stored service provider settings entries
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 TInt CSPSettingsEngine::SettingsCountL()
       
   397     {
       
   398     XSPSLOGSTRING( "CSPSettingsEngine::SettingsCount() - IN" );
       
   399 
       
   400     TInt result( 0 );
       
   401 
       
   402     TInt err = iCenRepUtils->EntryCountL( result );
       
   403     
       
   404     if( err == KErrNone )
       
   405         {
       
   406       
       
   407         if( result >= KSPPredefinedCount )
       
   408             {
       
   409             result--;
       
   410             }
       
   411          
       
   412         err = result;
       
   413         }
       
   414     else
       
   415         {
       
   416         err = 0;
       
   417         }
       
   418     
       
   419     XSPSLOGSTRING2( "CSPSettingsEngine::SettingsCount(%d) - OUT", result );
       
   420 
       
   421     return err;
       
   422     }
       
   423 
       
   424 
       
   425 
       
   426 // ---------------------------------------------------------------------------
       
   427 // Search stored service IDs of service provider settings entries
       
   428 // ---------------------------------------------------------------------------
       
   429 //
       
   430 TInt CSPSettingsEngine::FindServiceIdsL( RIdArray& aServiceIds )
       
   431     {
       
   432     XSPSLOGSTRING( "CSPSettingsEngine::FindServiceIdsL() - IN" );
       
   433 
       
   434     RArray<TInt> cenrepArray;
       
   435     CleanupClosePushL( cenrepArray );
       
   436     
       
   437     TInt err = iCenRepUtils->FindEntryIdsL( cenrepArray );
       
   438     
       
   439     for( TInt i = 0; i < cenrepArray.Count(); i++ )
       
   440         {
       
   441         TServiceId id = (TServiceId)cenrepArray[i];
       
   442         if( id != KSPDefaultVoIPServiceId )
       
   443             {
       
   444             User::LeaveIfError( aServiceIds.Append( id ));
       
   445             
       
   446             if ( i > 2 )
       
   447                 {
       
   448                 aServiceIds.Append( 2 );
       
   449                 break;
       
   450                 }
       
   451             }
       
   452         }
       
   453 
       
   454     CleanupStack::PopAndDestroy( &cenrepArray );
       
   455     
       
   456     XSPSLOGSTRING( "CSPSettingsEngine::FindServiceIdsL() - OUT" );
       
   457     
       
   458     return err;
       
   459     }
       
   460 
       
   461 
       
   462 // ---------------------------------------------------------------------------
       
   463 // Search service names by given service IDs
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 void CSPSettingsEngine::FindServiceNamesL( RIdArray& aServiceIds,
       
   467     CDesCArray& aServiceNames )
       
   468     {
       
   469     XSPSLOGSTRING( "CSPSettingsEngine::FindServiceNamesL() - IN" );
       
   470     
       
   471     CCenRepDatabaseProperty* property = CCenRepDatabaseProperty::NewLC();
       
   472     TInt count = aServiceIds.Count();
       
   473     for( TInt i = 0; i < count; i++ )
       
   474         {
       
   475         TInt id = ( TInt )aServiceIds[i];
       
   476         
       
   477         TInt err = iCenRepUtils->FindPropertyL( id, EServiceName, *property );
       
   478         if( err == KErrNone )
       
   479             {
       
   480             aServiceNames.AppendL( property->GetDesValue() );
       
   481             }
       
   482         else
       
   483             {
       
   484             aServiceIds.Remove( i ); // Remove non-existent ID
       
   485             count--;
       
   486             i--; // Do not increment index
       
   487             }
       
   488         }
       
   489 
       
   490     CleanupStack::PopAndDestroy( property );
       
   491     
       
   492     XSPSLOGSTRING( "CSPSettingsEngine::FindServiceNamesL() - OUT" );
       
   493     }
       
   494 
       
   495 void CSPSettingsEngine::PropertyNameArrayFromItemTypeL( TSPItemType aPropertyType, 
       
   496                                                         RPropertyNameArray& aNameArray )
       
   497     {
       
   498     switch ( aPropertyType )
       
   499         {
       
   500         case EItemTypeVoIPSubProperty:
       
   501             {
       
   502             User::LeaveIfError( aNameArray.Append( ESubPropertyVoIPSettingsId ) );
       
   503             User::LeaveIfError( aNameArray.Append( ESubPropertyVoIPPreferredSNAPId ) );
       
   504             User::LeaveIfError( aNameArray.Append( ESubPropertyVoIPPreferredIAPId ) );
       
   505             User::LeaveIfError( aNameArray.Append( ESubPropertyVoIPTemporaryIAPId ) );
       
   506             User::LeaveIfError( aNameArray.Append( ESubPropertyVoIPRelNumber ) );
       
   507             User::LeaveIfError( aNameArray.Append( ESubPropertyVoIPBrandDataUri ) );
       
   508             User::LeaveIfError( aNameArray.Append( ESubPropertyVoIPBrandIconUri ) );
       
   509             User::LeaveIfError( aNameArray.Append( ESubPropertyVoIPAddrScheme ) );
       
   510             User::LeaveIfError( aNameArray.Append( ESubPropertyVoIPEnabled ) );
       
   511             break;
       
   512             }
       
   513         case EItemTypePresenceSubProperty:
       
   514             {
       
   515             User::LeaveIfError( aNameArray.Append( ESubPropertyPresenceSettingsId ) );
       
   516             User::LeaveIfError( aNameArray.Append( ESubPropertyPresencePreferredSNAPId ) );
       
   517             User::LeaveIfError( aNameArray.Append( ESubPropertyPresencePreferredIAPId ) );
       
   518             User::LeaveIfError( aNameArray.Append( ESubPropertyPresencePresentityIDFieldType ) );
       
   519             User::LeaveIfError( aNameArray.Append( ESubPropertyPresenceLaunchMethod ) );
       
   520             User::LeaveIfError( aNameArray.Append( ESubPropertyPresenceLaunchUid ) );
       
   521             User::LeaveIfError( aNameArray.Append( ESubPropertyPresenceAddrScheme ) );
       
   522             User::LeaveIfError( aNameArray.Append( ESubPropertyPresenceEnabled ) );
       
   523             User::LeaveIfError( aNameArray.Append( ESubPropertyPresenceRequestPreference ) );
       
   524             break;
       
   525             }
       
   526         case EItemTypeIMSubProperty:
       
   527             {
       
   528             User::LeaveIfError( aNameArray.Append( ESubPropertyIMSettingsId ) );
       
   529             User::LeaveIfError( aNameArray.Append( ESubPropertyIMPreferredSNAPId ) );
       
   530             User::LeaveIfError( aNameArray.Append( ESubPropertyIMPreferredIAPId ) );
       
   531             User::LeaveIfError( aNameArray.Append( ESubPropertyIMLaunchMethod ) );
       
   532             User::LeaveIfError( aNameArray.Append( ESubPropertyIMLaunchUid ) );
       
   533             User::LeaveIfError( aNameArray.Append( ESubPropertyIMAddrScheme ) );
       
   534             User::LeaveIfError( aNameArray.Append( ESubPropertyIMEnabled ) );
       
   535             break;
       
   536             }
       
   537         case EItemTypeVMBXSubProperty:
       
   538             {
       
   539             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXSettingsId ) );
       
   540             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXPreferredSNAPId ) );
       
   541             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXPreferredIAPId ) );
       
   542             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXMWISubscribeInterval ) );
       
   543             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXLaunchMethod ) );
       
   544             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXLaunchUid ) );
       
   545             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXListenAddress ) );
       
   546             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXMWIAddress ) );
       
   547             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXBrandIconUri ) );
       
   548             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXAddrScheme ) );
       
   549             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXListenRegister ) );
       
   550             User::LeaveIfError( aNameArray.Append( ESubPropertyVMBXEnabled ) );
       
   551             break;
       
   552             }
       
   553         default:
       
   554             {
       
   555             User::Leave( KErrArgument );
       
   556             break;
       
   557             }
       
   558         }
       
   559     }
       
   560     
       
   561 // ---------------------------------------------------------------------------
       
   562 // 
       
   563 // ---------------------------------------------------------------------------
       
   564 //
       
   565 TInt CSPSettingsEngine::FindSubServicePropertiesL( TServiceId aServiceId, 
       
   566 	TSPItemType aPropertyType,
       
   567     RPropertyArray& aPropertyArray )
       
   568     {
       
   569     XSPSLOGSTRING2( 
       
   570         "CSPSettingsEngine::FindSubServicePropertiesL( %d ) - IN", aServiceId );
       
   571 
       
   572     RPropertyNameArray nameArray;
       
   573     CleanupClosePushL( nameArray );
       
   574     
       
   575     PropertyNameArrayFromItemTypeL( aPropertyType, nameArray );
       
   576     TInt count = nameArray.Count();
       
   577     TInt id = (TInt) aServiceId;
       
   578     
       
   579     CCenRepDatabaseProperty* property = CCenRepDatabaseProperty::NewLC();
       
   580     
       
   581     for( TInt i = 0; i < count; i++ )
       
   582         {
       
   583         TUint32 name = nameArray[i];
       
   584         TInt err = iCenRepUtils->FindPropertyL( id, name, *property );
       
   585         if( err == KErrNone )
       
   586             {
       
   587             CSPProperty* spProperty = CSPProperty::NewLC();
       
   588             User::LeaveIfError( spProperty->SetName( (TServicePropertyName)(property->GetName())) );
       
   589             User::LeaveIfError( spProperty->SetValue( property->GetDesValue() ));
       
   590             
       
   591             User::LeaveIfError( aPropertyArray.Append( spProperty ));
       
   592             CleanupStack::Pop( spProperty );
       
   593             }
       
   594         }
       
   595         
       
   596     CleanupStack::PopAndDestroy( property );
       
   597     CleanupStack::PopAndDestroy( &nameArray );
       
   598     
       
   599     XSPSLOGSTRING( "CSPSettingsEngine::FindSubServicePropertiesL() - OUT" );
       
   600     
       
   601     return KErrNone;
       
   602     }
       
   603 
       
   604 // ---------------------------------------------------------------------------
       
   605 // Deletes service properties
       
   606 // ---------------------------------------------------------------------------
       
   607 //
       
   608 TInt CSPSettingsEngine::DeleteServicePropertiesL( TServiceId aServiceId,
       
   609     											  const RPropertyNameArray& aNameArray  )
       
   610     {
       
   611     XSPSLOGSTRING2( 
       
   612         "CSPSettingsEngine::FindSubServicePropertyL( %d ) - IN", aServiceId );
       
   613 
       
   614     RArray<TUint32> nameArray;
       
   615     CleanupClosePushL( nameArray );
       
   616     TInt count = aNameArray.Count();
       
   617     
       
   618     for( TInt i = 0; i < count; i++ )
       
   619         {
       
   620         TUint32 name = (TUint32)( aNameArray[i] );
       
   621         User::LeaveIfError( nameArray.Append( name ) );
       
   622         }
       
   623         
       
   624     TInt id = (TInt)aServiceId;
       
   625     TInt err = iCenRepUtils->DeletePropertiesL( id, nameArray );
       
   626     
       
   627     CleanupStack::PopAndDestroy( &nameArray );
       
   628     
       
   629     XSPSLOGSTRING( "CSPSettingsEngine::FindSubServicePropertyL() - OUT" );
       
   630     
       
   631     return err;
       
   632     }
       
   633 
       
   634 // ---------------------------------------------------------------------------
       
   635 // Find service IDs with same properties
       
   636 // ---------------------------------------------------------------------------
       
   637 //
       
   638 void CSPSettingsEngine::FindServiceIdsFromPropertiesL( const RPropertyArray& aPropertyArray, 
       
   639 													   RIdArray& aServiceIds )
       
   640 	{
       
   641 	XSPSLOGSTRING( "CSPSettingsEngine::FindServiceIdsFromPropertiesL() - IN" );
       
   642 	
       
   643     RArray<TInt> entryIds;
       
   644     CleanupClosePushL( entryIds );
       
   645     
       
   646     RIpAppPropArray array;
       
   647 	TCleanupItem cleanup( CSPSettingsEngine::CleanupPointerArray, &array );
       
   648 	CleanupStack::PushL( cleanup );
       
   649     
       
   650     // todo custom cleanup stack
       
   651     ConvertSpArrayToCenRepArrayL( aPropertyArray, array );  
       
   652     
       
   653     TInt err = iCenRepUtils->FindEntryIdsFromPropertiesL( array, entryIds );
       
   654     if( err == KErrNone )
       
   655         {
       
   656         TInt count = entryIds.Count();
       
   657         for( TInt i = 0; i < count; i++ )
       
   658             {
       
   659             TServiceId id = (TServiceId)entryIds[i];
       
   660             if( id != KSPDefaultVoIPServiceId )
       
   661                 {
       
   662                 User::LeaveIfError( aServiceIds.Append( id ) );
       
   663                 }
       
   664             }
       
   665         }
       
   666         
       
   667     CleanupStack::PopAndDestroy( &array );
       
   668     CleanupStack::PopAndDestroy( &entryIds );
       
   669     
       
   670 	XSPSLOGSTRING( "CSPSettingsEngine::FindServiceIdsFromPropertiesL() - OUT" );
       
   671 	}
       
   672 
       
   673 
       
   674 
       
   675 // ---------------------------------------------------------------------------
       
   676 // Check feature is supported or not
       
   677 // ---------------------------------------------------------------------------
       
   678 //
       
   679 TBool CSPSettingsEngine::IsFeatureSupportedL( TSPServiceFeature aFeature,
       
   680                                               TBool aWriteAllowed )
       
   681 	{
       
   682     XSPSLOGSTRING( "CSPSettingsEngine::IsFeatureSupportedL() - IN" );
       
   683 
       
   684     TBool ret = EFalse;
       
   685     
       
   686 	// First check P&S key, if P&S key is defined, use the value from P&S key.
       
   687 	// if not defined, then walk through all the sevices and check there is any service match
       
   688 	TInt mask = 0;
       
   689 	TInt value = 0;
       
   690 	TInt psFlag = 0;
       
   691 	TInt retProperty = 0;
       
   692 	
       
   693     switch( aFeature )
       
   694     	{
       
   695     	case ESupportInternetCallFeature:
       
   696     		{
       
   697     		retProperty = RProperty::Get( KUidSystemCategory, KSPSupportInternetCallKey, psFlag );
       
   698     		if( retProperty == KErrNone && psFlag != KSPInitFeatureValue )
       
   699     			{
       
   700     			ret = psFlag;
       
   701     			}
       
   702     		else
       
   703     			{
       
   704 				mask = ESupportsInternetCall | ESupportsAlphanumericAddressing | EIsVisibleInCallMenu;
       
   705 				value = mask;
       
   706 				ret = CheckFeatureL( mask, value );
       
   707 				if ( aWriteAllowed )
       
   708 				    {				    
       
   709 				    User::LeaveIfError( RProperty::Set( KUidSystemCategory, 
       
   710 				        KSPSupportInternetCallKey, ret ) );
       
   711 				    }
       
   712     			}
       
   713     		
       
   714     		break;
       
   715     		}
       
   716     	case ESupportCallOutFeature:
       
   717     		{
       
   718     		retProperty = RProperty::Get( KUidSystemCategory, KSPSupportCallOutKey, psFlag );
       
   719     		if( retProperty == KErrNone && psFlag != KSPInitFeatureValue )
       
   720     			{
       
   721     			ret = psFlag;
       
   722     			}
       
   723     		else
       
   724     			{
       
   725 				mask = ESupportsInternetCall | ESupportsMSISDNAddressing | EIsVisibleInCallMenu;
       
   726 				value = mask;
       
   727 				ret = CheckFeatureL( mask, value );
       
   728 				if ( aWriteAllowed )
       
   729 				    {				    
       
   730     				User::LeaveIfError( RProperty::Set( 
       
   731     				    KUidSystemCategory, 
       
   732     				    KSPSupportCallOutKey, ret ) );
       
   733 				    }
       
   734     			}
       
   735     		break;
       
   736     		}
       
   737     	
       
   738     	case ESupportVoIPSSFeature:
       
   739     		{
       
   740     		retProperty = RProperty::Get( KUidSystemCategory, KSPSupportVoIPSSKey, psFlag );
       
   741     		if( retProperty == KErrNone && psFlag != KSPInitFeatureValue )
       
   742     			{
       
   743     			ret = psFlag;
       
   744     			}
       
   745     		else
       
   746     			{
       
   747 				mask = ESupportVoIPSS;
       
   748 				value = mask;
       
   749 				ret = CheckFeatureL( mask, value );
       
   750 				if ( aWriteAllowed )
       
   751 				    {				    
       
   752     				User::LeaveIfError( RProperty::Set( 
       
   753     				    KUidSystemCategory, 
       
   754     				    KSPSupportVoIPSSKey, ret ) );
       
   755 				    }
       
   756     			}
       
   757     		break;
       
   758     		}
       
   759     	
       
   760     	case ESupportVoIPFeature:
       
   761     		{
       
   762     		TBool bFeatureMgr = EFalse;
       
   763     		TBool bDynVoIP = EFalse;
       
   764     		TBool bSubVoIP = EFalse;
       
   765     		
       
   766     		//check FeatureManager
       
   767     		FeatureManager::InitializeLibL();
       
   768     		bFeatureMgr = FeatureManager::FeatureSupported( KFeatureIdCommonVoip );
       
   769     		FeatureManager::UnInitializeLib();
       
   770     		
       
   771     		//check dynamic voip flag
       
   772 			CRepository* repository = CRepository::NewLC( KCRUidTelephonySettings );
       
   773 			TInt value = 0;
       
   774 			TInt err = repository->Get( KDynamicVoIP, value );
       
   775 			if( value != 0 )
       
   776 				{
       
   777 				bDynVoIP = ETrue;
       
   778 				}
       
   779 			
       
   780 			CleanupStack::PopAndDestroy( repository );
       
   781     		
       
   782     		//check subservice voip
       
   783 			RIdArray serviceIds;
       
   784 			CleanupClosePushL( serviceIds );
       
   785 			FindServiceIdsL( serviceIds );
       
   786 			CSPProperty* property = CSPProperty::NewLC();
       
   787 			
       
   788 			for( TInt i = 0; i < serviceIds.Count(); i++ )
       
   789 				{
       
   790 				TServiceId serviceId = serviceIds[i];
       
   791 				TInt retProperty = FindPropertyL( serviceId, EPropertyVoIPSubServicePluginId, *property );
       
   792 				if( retProperty == KErrNone )
       
   793 					{
       
   794 					bSubVoIP = ETrue;
       
   795 					break;
       
   796 					}
       
   797 				}
       
   798 			CleanupStack::PopAndDestroy( property );
       
   799 			CleanupStack::PopAndDestroy( &serviceIds );
       
   800 			
       
   801 			ret = bFeatureMgr && bDynVoIP && bSubVoIP;
       
   802 			
       
   803     		break;
       
   804     		}
       
   805 		default:
       
   806 			{
       
   807 			User::Leave( KErrNotSupported );    	
       
   808 			}
       
   809     	}
       
   810     
       
   811     XSPSLOGSTRING( "CSPSettingsEngine::IsFeatureSupportedL() - OUT" );
       
   812 
       
   813     return ret;
       
   814 	}
       
   815 
       
   816 // ---------------------------------------------------------------------------
       
   817 // When service table is changed, update the P&S key
       
   818 // ---------------------------------------------------------------------------
       
   819 //
       
   820 void CSPSettingsEngine::UpdateSupportFeaturePSKeyL()
       
   821 	{
       
   822 	TInt mask = 0;
       
   823 	TInt value = 0;
       
   824 	TBool ret = EFalse;
       
   825 	
       
   826 	//ESupportInternetCallFeature
       
   827 	//ESupportsInternetCall + ESupportsAlphanumericAddressing + EIsVisibleInCallMenu
       
   828 	mask = ESupportsInternetCall | ESupportsAlphanumericAddressing | EIsVisibleInCallMenu;
       
   829 	value = mask;
       
   830 	ret = CheckFeatureL( mask, value );
       
   831 	User::LeaveIfError( RProperty::Set( KUidSystemCategory, KSPSupportInternetCallKey, ret ) );
       
   832 	
       
   833 	//ESupportCallOutFeature
       
   834 	//ESupportsInternetCall + ESupportsMSISDNAddressing + EIsVisibleInCallMenu
       
   835 	mask = ESupportsInternetCall | ESupportsMSISDNAddressing | EIsVisibleInCallMenu;
       
   836 	value = mask;
       
   837 	ret = CheckFeatureL( mask, value );
       
   838 	User::LeaveIfError( RProperty::Set( KUidSystemCategory, KSPSupportCallOutKey, ret ) );
       
   839 	
       
   840 	//ESupportVoIPSSFeature
       
   841 	//ESupportVoIPSS
       
   842 	mask = ESupportVoIPSS;
       
   843 	value = mask;
       
   844 	ret = CheckFeatureL( mask, value );
       
   845 	User::LeaveIfError( RProperty::Set( KUidSystemCategory, KSPSupportVoIPSSKey, ret ) );
       
   846 	}
       
   847 
       
   848 // ---------------------------------------------------------------------------
       
   849 // Walk through all the sevices and check there is any service match 
       
   850 // ---------------------------------------------------------------------------
       
   851 //
       
   852 TBool CSPSettingsEngine::CheckFeatureL( TInt aMask, TInt aValue )
       
   853 	{
       
   854 	RArray<TInt> entryIds;
       
   855 	CleanupClosePushL( entryIds );
       
   856 	iCenRepUtils->FindEntryIdsL( entryIds );
       
   857 	CCenRepDatabaseProperty* property = CCenRepDatabaseProperty::NewLC();
       
   858 	TBool ret = EFalse;
       
   859 	
       
   860 	for( TInt i = 0; i < entryIds.Count(); i++ )
       
   861 		{
       
   862 		TInt entryId = entryIds[i];
       
   863 		if( entryId == KSPDefaultVoIPServiceId )
       
   864 		    {
       
   865 		    continue;
       
   866 		    }
       
   867 		    
       
   868 		TInt retProperty = iCenRepUtils->FindPropertyL( entryId, EPropertyServiceAttributeMask, *property );
       
   869 		if( retProperty == KErrNone )
       
   870 			{
       
   871 			TInt maskValue = 0;
       
   872 			TInt err = property->GetValue( maskValue );
       
   873 			if( err == KErrNone )
       
   874 				{
       
   875 				if( ( maskValue & aMask ) == (aValue & aMask) )
       
   876 					{
       
   877 					// Find matched servcie
       
   878 					ret = ETrue;
       
   879 					break;
       
   880 					}
       
   881 				}
       
   882 			}
       
   883 		}
       
   884 	
       
   885 	CleanupStack::PopAndDestroy( property );
       
   886 	CleanupStack::PopAndDestroy( &entryIds );
       
   887 	return ret;
       
   888 	}
       
   889 
       
   890 // ---------------------------------------------------------------------------
       
   891 // Check if it is VoIP Service ID
       
   892 // ---------------------------------------------------------------------------
       
   893 //
       
   894 TBool CSPSettingsEngine::IsVoIPServiceL( TServiceId aServiceId )
       
   895     {
       
   896     TBool bIsVoIP = EFalse;
       
   897     
       
   898     CSPProperty* property = CSPProperty::NewLC();
       
   899     TInt err = FindPropertyL( aServiceId, EPropertyVoIPSubServicePluginId, *property );
       
   900     if( err == KErrNone )
       
   901         {
       
   902         bIsVoIP = ETrue;
       
   903         }
       
   904     CleanupStack::PopAndDestroy( property );
       
   905     
       
   906     return bIsVoIP;
       
   907     }
       
   908 
       
   909 // ---------------------------------------------------------------------------
       
   910 // Check if an array has call related property name in it
       
   911 // ---------------------------------------------------------------------------
       
   912 //
       
   913 TBool CSPSettingsEngine::HasCallPropertyName( const RPropertyNameArray& aNameArray )
       
   914     {
       
   915     TBool bHasCall = EFalse;
       
   916     
       
   917     for( TInt i = 0; i < aNameArray.Count(); i++ )
       
   918         {
       
   919         TServicePropertyName name = aNameArray[i];
       
   920         if( name == EPropertyCTIPluginId ||
       
   921             name == EPropertyCLIPluginId ||
       
   922             name == EPropertyCallLoggingPluginId ||
       
   923             name == EPropertyCallStateIndicatorPluginId ||
       
   924             name == EPropertyCallMenuHandlerPluginId ||
       
   925             name == EPropertyCallProviderPluginId )
       
   926             {
       
   927             bHasCall = ETrue;
       
   928             break;
       
   929             }
       
   930         }
       
   931     
       
   932     return bHasCall;
       
   933     }
       
   934     
       
   935 // ---------------------------------------------------------------------------
       
   936 // Check if an array has VoIP or Vmbx related property name in it
       
   937 // ---------------------------------------------------------------------------
       
   938 //
       
   939 TBool CSPSettingsEngine::HasVoIPAndVmbxPropertyName(  const RPropertyNameArray& aNameArray )
       
   940     {
       
   941     TBool bHasVoIPAndVmbx = EFalse;
       
   942     
       
   943     for( TInt i = 0; i < aNameArray.Count(); i++ )
       
   944         {
       
   945         TServicePropertyName name = aNameArray[i];
       
   946         if( name == EPropertyVoIPSubServicePluginId ||
       
   947             name == EPropertyVMBXSubServicePluginId ||
       
   948             name == ESubPropertyVoIPSettingsId ||
       
   949             name == ESubPropertyVoIPPreferredSNAPId ||
       
   950             name == ESubPropertyVoIPPreferredIAPId ||
       
   951             name == ESubPropertyVoIPTemporaryIAPId ||
       
   952             name == ESubPropertyVMBXSettingsId ||
       
   953             name == ESubPropertyVMBXPreferredSNAPId ||
       
   954             name == ESubPropertyVMBXPreferredIAPId ||
       
   955             name == ESubPropertyVMBXMWISubscribeInterval ||
       
   956             name == ESubPropertyVMBXLaunchMethod ||
       
   957             name == ESubPropertyVMBXLaunchUid ||
       
   958             name == ESubPropertyVoIPRelNumber ||
       
   959             name == ESubPropertyVoIPBrandDataUri ||
       
   960             name == ESubPropertyVoIPBrandIconUri ||
       
   961             name == ESubPropertyVoIPAddrScheme ||
       
   962             name == ESubPropertyVMBXListenAddress ||
       
   963             name == ESubPropertyVMBXMWIAddress ||
       
   964             name == ESubPropertyVMBXBrandIconUri ||
       
   965             name == ESubPropertyVMBXAddrScheme ||
       
   966             name == ESubPropertyVoIPEnabled ||
       
   967             name == ESubPropertyVMBXListenRegister ||
       
   968             name == ESubPropertyVMBXEnabled )
       
   969             {
       
   970             bHasVoIPAndVmbx = ETrue;
       
   971             break;
       
   972             }
       
   973         }
       
   974     
       
   975     return bHasVoIPAndVmbx;
       
   976     }
       
   977 
       
   978 // ---------------------------------------------------------------------------
       
   979 // Get Name array from Property array 
       
   980 // ---------------------------------------------------------------------------
       
   981 //
       
   982 void CSPSettingsEngine::NameArrayFromPropertyArrayL( RPropertyNameArray& aNameArray, 
       
   983 												const RPropertyArray& aPropertyArray )
       
   984     {
       
   985     aNameArray.Reset();
       
   986     
       
   987     for( TInt i = 0; i < aPropertyArray.Count(); i++ )
       
   988         {
       
   989         CSPProperty* property = aPropertyArray[i];
       
   990         TServicePropertyName name = property->GetName();
       
   991         User::LeaveIfError( aNameArray.Append( name ) );
       
   992         }
       
   993     }
       
   994