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