profilesservices/ProfileEngine/EngSrc/CProfileEngineImpl.cpp
changeset 0 8c5d936e5675
child 8 f62c3a3d66b8
child 18 e3554c9069b6
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Implementation of the CProfileEngineImpl.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CProfileEngineImpl.h"
       
    22 #include <bautils.h> // BaflUtils
       
    23 #include <barsc.h> // RResoureFile
       
    24 #include <featmgr.h>
       
    25 #include <bldvariant.hrh>
       
    26 #include <DRMCommon.h>
       
    27 #include <sysutil.h>
       
    28 
       
    29 #include <ProfileEng.rsg>
       
    30 #include <TProfileToneSettings.h>
       
    31 #include <MProfileTones.h>
       
    32 #include "CProfilesNamesArrayImpl.h"
       
    33 #include "CProfileImpl.h"
       
    34 #include "CProfileNameImpl.h"
       
    35 #include "ProfileEngUtils.h"
       
    36 #include "MProfileSetName.h"
       
    37 #include "ProfileEng.hrh"
       
    38 #include "ProfileEngineConstants.h"
       
    39 #include "ProfileEngPanic.h"
       
    40 #include "MProfileSetTones.h"
       
    41 #include "MProfileSetExtraTones.h"
       
    42 #include "MProfileExtraSettings.h"
       
    43 #include "MProfileFeedbackSettings.h"
       
    44 #include "MProfilesLocalFeatures.h"
       
    45 #include "MProfileUtilitySingleton.h"
       
    46 #include "ProfilesVariant.hrh" // KProEngFeatureIdVTRingingTone
       
    47 #include "CProfileTiming.h"
       
    48 #include <centralrepository.h>
       
    49 #include "ProfileEnginePrivateCRKeys.h"
       
    50 #include "ProfileEnginePrivatePSKeys.h"
       
    51 #include <hwrmvibrasdkcrkeys.h>
       
    52 #include <data_caging_path_literals.hrh>
       
    53 #include "ProfilesDebug.h"
       
    54 
       
    55 #include <psmsettings.h>
       
    56 #include <psmsrvdomaincrkeys.h>
       
    57 
       
    58 
       
    59 // ============================ MEMBER FUNCTIONS ===============================
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CProfileEngineImpl::NewL
       
    63 // Two-phased constructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CProfileEngineImpl* CProfileEngineImpl::NewL()
       
    67     {
       
    68     CProfileEngineImpl* self = CProfileEngineImpl::NewLC();
       
    69     CleanupStack::Pop();
       
    70     return self;
       
    71     }
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CProfileEngineImpl::NewLC
       
    76 // Two-phased constructor.
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 CProfileEngineImpl* CProfileEngineImpl::NewLC()
       
    80     {
       
    81     CProfileEngineImpl* self = new ( ELeave ) CProfileEngineImpl;
       
    82 
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL();
       
    85 
       
    86     return self;
       
    87     }
       
    88 
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CProfileEngineImpl::NewL
       
    92 // Two-phased constructor.
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 CProfileEngineImpl* CProfileEngineImpl::NewL( RFs* aFs )
       
    96     {
       
    97     CProfileEngineImpl* self = CProfileEngineImpl::NewLC( aFs );
       
    98     CleanupStack::Pop();
       
    99     return self;
       
   100     }
       
   101 
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CProfileEngineImpl::NewLC
       
   105 // Two-phased constructor.
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CProfileEngineImpl* CProfileEngineImpl::NewLC( RFs* aFs )
       
   109     {
       
   110     CProfileEngineImpl* self = new ( ELeave ) CProfileEngineImpl;
       
   111 
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL( aFs );
       
   114 
       
   115     return self;
       
   116     }
       
   117 
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CProfileEngineImpl::ConstructL
       
   121 // Symbian 2nd phase constructor can leave.
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CProfileEngineImpl::ConstructL()
       
   125     {
       
   126     iFs = new ( ELeave ) RFs;
       
   127     iFsOwned = ETrue;
       
   128     User::LeaveIfError( iFs->Connect() );
       
   129     CommonConstructL();
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CProfileEngineImpl::ConstructL
       
   134 // Symbian 2nd phase constructor can leave.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CProfileEngineImpl::ConstructL( RFs* aFs )
       
   138     {
       
   139     iFs = aFs;
       
   140     CommonConstructL();
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CProfileEngineImpl::CommonConstructL
       
   145 // Symbian 2nd phase constructor can leave.
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 void CProfileEngineImpl::CommonConstructL()
       
   149     {
       
   150     PRODEBUG( "Profiles Engine CommonConstructL" );
       
   151 
       
   152     FeatureManager::InitializeLibL();
       
   153     iSideVolumeKeys = FeatureManager::FeatureSupported( KFeatureIdSideVolumeKeys );
       
   154     
       
   155 
       
   156     iCenRep = CRepository::NewL( KCRUidProfileEngine );
       
   157     iVibraCenRep = CRepository::NewL( KCRUidVibraCtrl );
       
   158 
       
   159     // Profile Utility must be released in destructor:
       
   160     iFeatures = &( ProfileUtilityInstanceL().ProfilesLocalFeatures() );
       
   161     iProfileLocalisedNames = CProfilesNamesArrayImpl::NewL();
       
   162     ReadProfilesNamesFromResourceL();
       
   163 
       
   164     iProfileTiming = CProfileTiming::NewL( *iCenRep, *iFeatures );
       
   165 
       
   166     // Open/Create mutex
       
   167     TInt error( KErrNotFound );
       
   168     while( error == KErrNotFound )
       
   169         {
       
   170         error = iMutex.CreateGlobal( KProfileMutexName );
       
   171         if( error != KErrAlreadyExists )
       
   172             {
       
   173             break;
       
   174             }
       
   175         error = iMutex.OpenGlobal( KProfileMutexName );
       
   176         }
       
   177     User::LeaveIfError( error );
       
   178     PRODEBUG( "Profiles Engine CommonConstructL end" );
       
   179     }
       
   180 
       
   181 // Destructor
       
   182 CProfileEngineImpl::~CProfileEngineImpl()
       
   183     {
       
   184     iMutex.Close();
       
   185     iProperty.Close();
       
   186     delete iProfileTiming;
       
   187     delete iProfileLocalisedNames;
       
   188     
       
   189     if ( iFeatures )
       
   190         {
       
   191         ReleaseProfileUtility();    
       
   192         }
       
   193         
       
   194     delete iCenRep;
       
   195     delete iVibraCenRep;
       
   196     if( iFsOwned )
       
   197         {
       
   198         iFs->Close();
       
   199         delete iFs;
       
   200         }
       
   201     
       
   202     FeatureManager::UnInitializeLib();
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CProfileEngineImpl::ActiveProfileLC
       
   207 //
       
   208 // (other items were commented in a header).
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 MProfile* CProfileEngineImpl::ActiveProfileLC()
       
   212     {
       
   213     TInt id( User::LeaveIfError( ActiveProfileId() ) );
       
   214     MProfileExtended* profile = ProfileLC( id );
       
   215     return profile;
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CProfileEngineImpl::ActiveProfileL
       
   220 //
       
   221 // (other items were commented in a header).
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 MProfile* CProfileEngineImpl::ActiveProfileL()
       
   225     {
       
   226     MProfile* profile = ActiveProfileLC();
       
   227     CleanupStack::Pop();    // profile
       
   228     return profile;
       
   229     }
       
   230 
       
   231 // -----------------------------------------------------------------------------
       
   232 // CProfileEngineImpl::ProfileLC
       
   233 //
       
   234 // (other items were commented in a header).
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 MProfileExtended* CProfileEngineImpl::ProfileLC(
       
   238     TInt aId )
       
   239     {
       
   240     CProfileImpl* profile = NULL;
       
   241 
       
   242     iMutex.Wait();
       
   243     TInt err( CheckProfileIdL( aId ) );
       
   244 
       
   245     if( !err )
       
   246         {
       
   247         TRAP( err, profile = GetProfileL( aId ) );
       
   248         }
       
   249     iMutex.Signal();
       
   250 
       
   251     User::LeaveIfError( err );
       
   252 
       
   253     CleanupStack::PushL( profile );
       
   254 
       
   255     if( iSideVolumeKeys )
       
   256         {
       
   257         // Because SetTemp*VolumeL() functions update only Shared Data those
       
   258         // values must be read from SD and set to the MProfile instance
       
   259         // returned to the caller:
       
   260         TInt activeId( User::LeaveIfError( ActiveProfileId() ) );
       
   261         if( activeId == aId )
       
   262             {
       
   263             TProfileToneSettings& settings =
       
   264                     profile->ProfileSetTones().SetToneSettings();
       
   265             settings.iRingingVolume = TempRingingVolumeL();
       
   266             settings.iMediaVolume = TempMediaVolumeL();
       
   267             }
       
   268         }
       
   269 
       
   270     if( !profile->IsProfileNameChanged() )
       
   271         {
       
   272         if( IsDefaultProfile( aId ) )
       
   273             {
       
   274             profile->SetLocalizedProfileNameL( *iProfileLocalisedNames );
       
   275             }
       
   276         else
       
   277             {
       
   278             SetLocalizedNameForDynamicProfileL( *profile );
       
   279             }
       
   280         }
       
   281 
       
   282     return profile;
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // CProfileEngineImpl::ProfileL
       
   287 //
       
   288 // (other items were commented in a header).
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 MProfileExtended* CProfileEngineImpl::ProfileL(
       
   292     TInt aId )
       
   293     {
       
   294     MProfileExtended* profile = ProfileLC( aId );
       
   295     CleanupStack::Pop();    // profile
       
   296     return profile;
       
   297     }
       
   298 
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CProfileEngineImpl::SetActiveProfileL
       
   302 //
       
   303 // (other items were commented in a header).
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 void CProfileEngineImpl::SetActiveProfileL( TInt aId )
       
   307     {
       
   308     PRODEBUG1( "SetActiveProfileL( %d )", aId );
       
   309     CreatePubSubKeysIfNeededL(); 
       
   310 
       
   311     iMutex.Wait();
       
   312     TInt err( CheckProfileIdL( aId ) );
       
   313 
       
   314     if( !err )
       
   315         {
       
   316         TRAP( err, DoSetActiveProfileL( aId ) );
       
   317         }
       
   318     else
       
   319         {
       
   320         // Timed profile was deleted while time expired
       
   321         // So pass event to ActiveIdle2 to deal with time icon.
       
   322         iProfileTiming->CancelTimedProfileL();
       
   323         PublishChangeL( KProEngActiveProfileModified );    
       
   324         }
       
   325     iMutex.Signal();
       
   326 
       
   327     PRODEBUG1( "SetActiveProfileL err=%d", err );
       
   328     User::LeaveIfError( err );
       
   329     PRODEBUG1( "SetActiveProfileL( %d ) end", aId );
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CProfileEngineImpl::IsActiveProfileTimedL
       
   334 //
       
   335 // (other items were commented in a header).
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 TBool CProfileEngineImpl::IsActiveProfileTimedL()
       
   339     {
       
   340     return iProfileTiming->IsTimingActiveL();
       
   341     }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // CProfileEngineImpl::SetActiveProfileTimedL
       
   345 //
       
   346 // (other items were commented in a header).
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 void CProfileEngineImpl::SetActiveProfileTimedL( TInt aId, TTime aTime )
       
   350     {
       
   351     if( !iFeatures->IsFeatureSupported( KProEngFeatureIdTimedProfiles ) )
       
   352         {
       
   353         User::Leave( KErrNotSupported );
       
   354         }
       
   355 
       
   356     CreatePubSubKeysIfNeededL(); 
       
   357 
       
   358     iMutex.Wait();
       
   359     TInt err( CheckProfileIdL( aId ) );
       
   360 
       
   361     if( !err )
       
   362         {
       
   363         TRAP( err, DoSetActiveProfileL( aId, &aTime ) );
       
   364         }
       
   365     iMutex.Signal();
       
   366 
       
   367     User::LeaveIfError( err );
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 // CProfileEngineImpl::ReadResourceInBufferLC
       
   372 //
       
   373 // (other items were commented in a header).
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CProfileEngineImpl::ReadResourceInBufferLC( TInt aResourceId,
       
   377         TResourceReader& aReader )
       
   378     {
       
   379     TParse* fp = new ( ELeave ) TParse();
       
   380     fp->Set( KProfileEngineResourceDriveAndDir, &KDC_RESOURCE_FILES_DIR, NULL );
       
   381     iFileName.Copy( fp->FullName() );
       
   382     delete fp;
       
   383 
       
   384     BaflUtils::NearestLanguageFile( *iFs, iFileName );
       
   385 
       
   386     RResourceFile resourceFile;
       
   387     resourceFile.OpenL( *iFs, iFileName );
       
   388     CleanupClosePushL( resourceFile );
       
   389 
       
   390     resourceFile.ConfirmSignatureL( PROFILES_ENGINE_RESOURCE_SIGNATURE );
       
   391 
       
   392     HBufC8* dataBuffer = resourceFile.AllocReadLC( aResourceId );
       
   393 
       
   394     CleanupStack::Pop(); // dataBuffer
       
   395     CleanupStack::PopAndDestroy(); // resourceFile.Close()
       
   396     CleanupStack::PushL( dataBuffer );
       
   397 
       
   398     aReader.SetBuffer( dataBuffer );
       
   399     }
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // CProfileEngineImpl::ReadProfilesNamesFromResourceL
       
   403 //
       
   404 // (other items were commented in a header).
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 void CProfileEngineImpl::ReadProfilesNamesFromResourceL()
       
   408     {
       
   409     TResourceReader rsReader;
       
   410     ReadResourceInBufferLC( R_DEFAULT_PROFILES, rsReader );
       
   411 
       
   412     TInt numOfElements( rsReader.ReadInt16() );
       
   413 
       
   414     for( TInt i( 0 ) ; i < numOfElements ; ++i )
       
   415         {
       
   416         TInt profileId( rsReader.ReadInt32() );
       
   417         TPtrC profileName( rsReader.ReadTPtrC() );
       
   418         TPtrC shortName( rsReader.ReadTPtrC() );
       
   419         TPtrC naviName( rsReader.ReadTPtrC() );
       
   420         TPtrC titleName( rsReader.ReadTPtrC() );
       
   421         CProfileNameImpl* pn =
       
   422             CProfileNameImpl::NewLC( profileId, profileName, shortName,
       
   423                                      naviName, titleName );
       
   424         User::LeaveIfError( iProfileLocalisedNames->Append( pn ) );
       
   425         CleanupStack::Pop(); // pn
       
   426         }
       
   427 
       
   428     CleanupStack::PopAndDestroy(); // ReadResourceInBufferLC()
       
   429     }
       
   430 
       
   431 // -----------------------------------------------------------------------------
       
   432 // CProfileEngineImpl::Release
       
   433 //
       
   434 // (other items were commented in a header).
       
   435 // -----------------------------------------------------------------------------
       
   436 //
       
   437 void CProfileEngineImpl::Release()
       
   438     {
       
   439     delete this;
       
   440     }
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CProfileEngineImpl::SendPresenceSettingsL
       
   444 //
       
   445 // (other items were commented in a header).
       
   446 // -----------------------------------------------------------------------------
       
   447 //
       
   448 void CProfileEngineImpl::SendPresenceSettingsL(
       
   449     const MProfilePresence& /* aPresence */ )
       
   450     {
       
   451     }
       
   452 
       
   453 // -----------------------------------------------------------------------------
       
   454 // CProfileEngineImpl::IsDefaultProfile
       
   455 //
       
   456 // (other items were commented in a header).
       
   457 // -----------------------------------------------------------------------------
       
   458 //
       
   459 TBool CProfileEngineImpl::IsDefaultProfile( TInt aId )
       
   460     {
       
   461     return ( iProfileLocalisedNames->FindById( aId ) != KErrNotFound );
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CProfileEngineImpl::LocalFeaturesL
       
   466 //
       
   467 // (other items were commented in a header).
       
   468 // -----------------------------------------------------------------------------
       
   469 //
       
   470 MProfilesLocalFeatures& CProfileEngineImpl::LocalFeatures()
       
   471     {
       
   472     return *iFeatures;
       
   473     }
       
   474 
       
   475 // -----------------------------------------------------------------------------
       
   476 // CProfileEngineImpl::IsFeatureSupported
       
   477 //
       
   478 // (other items were commented in a header).
       
   479 // -----------------------------------------------------------------------------
       
   480 //
       
   481 TBool CProfileEngineImpl::IsFeatureSupported(
       
   482         TProfileFeatureId aFeatureId ) const
       
   483     {
       
   484     switch( aFeatureId )
       
   485         {
       
   486         case EProfileFeatureVTRingingTone:
       
   487             {
       
   488             return iFeatures->IsFeatureSupported(
       
   489                     KProEngFeatureIdVTRingingTone );
       
   490             // no break after return
       
   491             }
       
   492         default:
       
   493             {
       
   494             return EFalse;
       
   495             // no break after return
       
   496             }
       
   497         }
       
   498     }
       
   499 
       
   500 // -----------------------------------------------------------------------------
       
   501 // CProfileEngineImpl::ProfileUtilityObject
       
   502 //
       
   503 // (other items were commented in a header).
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 void CProfileEngineImpl::GetProfileUtilityObject(
       
   507         TProfileUtilityObjectType /* aType */, TAny*& /* aImpl */ )
       
   508     {
       
   509     }
       
   510 
       
   511 // -----------------------------------------------------------------------------
       
   512 // CProfileEngineImpl::LeaveIfReadOnlyL
       
   513 //
       
   514 // (other items were commented in a header).
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 void CProfileEngineImpl::LeaveIfReadOnlyL( TProfileFlags aFlag )
       
   518     {
       
   519     MProfileExtended* profile = ProfileLC( ActiveProfileId() );
       
   520     TUint32 flags = profile->ModifiableFlags();
       
   521     CleanupStack::PopAndDestroy(); // profile
       
   522     if( !( flags & aFlag ) )
       
   523         {
       
   524         User::Leave( KErrAccessDenied );
       
   525         }
       
   526     }
       
   527 
       
   528 // -----------------------------------------------------------------------------
       
   529 // CProfileEngineImpl::ActiveProfileId
       
   530 //
       
   531 // (other items were commented in a header).
       
   532 // -----------------------------------------------------------------------------
       
   533 //
       
   534 TInt CProfileEngineImpl::ActiveProfileId()
       
   535     {
       
   536     TInt profileId( 0 );
       
   537     TInt error( iCenRep->Get( KProEngActiveProfile, profileId ) );
       
   538     if( error )
       
   539         {
       
   540         return error;
       
   541         }
       
   542     return profileId;
       
   543     }
       
   544 
       
   545 // -----------------------------------------------------------------------------
       
   546 // CProfileEngineImpl::CommitChangeL
       
   547 //
       
   548 // (other items were commented in a header).
       
   549 // -----------------------------------------------------------------------------
       
   550 //
       
   551 void CProfileEngineImpl::CommitChangeL(
       
   552     MProfileExtended& aProfile )
       
   553     {
       
   554     CreatePubSubKeysIfNeededL(); 
       
   555     if( SysUtil::FFSSpaceBelowCriticalLevelL( iFs ) )
       
   556         {
       
   557         User::Leave( KErrDiskFull );
       
   558         }
       
   559 
       
   560     TInt profileId( aProfile.ProfileName().Id() );
       
   561     // write profile settings
       
   562     iMutex.Wait();
       
   563     TUint32 ignore( 0 );
       
   564     TRAPD( error,
       
   565            TInt activeId( User::LeaveIfError( ActiveProfileId() ) );
       
   566            User::LeaveIfError( iCenRep->StartTransaction(
       
   567                    CRepository::EReadWriteTransaction ) );
       
   568            iCenRep->CleanupCancelTransactionPushL();
       
   569            aProfile.ExternalizeL( *iCenRep );
       
   570 
       
   571            if( profileId == activeId )
       
   572                {
       
   573                UpdateActiveProfileSettingsL( aProfile );
       
   574                }
       
   575 
       
   576            // write settings to Cenrep:
       
   577            User::LeaveIfError( iCenRep->CommitTransaction( ignore ) );
       
   578            CleanupStack::PopAndDestroy(); // CleanupCancelTransactionPushL()
       
   579 
       
   580            if( profileId == activeId )
       
   581                {
       
   582                //Send event through P&S
       
   583                PublishChangeL( KProEngActiveProfileModified );
       
   584                }
       
   585          );
       
   586     iMutex.Signal();
       
   587     User::LeaveIfError( error );
       
   588     }
       
   589 
       
   590 // -----------------------------------------------------------------------------
       
   591 // CProfileEngineImpl::ProfilesNamesArrayLC
       
   592 //
       
   593 // (other items were commented in a header).
       
   594 // -----------------------------------------------------------------------------
       
   595 //
       
   596 MProfilesNamesArray* CProfileEngineImpl::ProfilesNamesArrayLC()
       
   597     {
       
   598     CProfilesNamesArrayImpl* nameArray = CProfilesNamesArrayImpl::NewLC();
       
   599 
       
   600     iMutex.Wait();
       
   601     TRAPD( error, ReadProfilesNamesL( nameArray ) );
       
   602     iMutex.Signal();
       
   603     User::LeaveIfError( error );
       
   604 
       
   605     return nameArray;
       
   606     }
       
   607 
       
   608 // -----------------------------------------------------------------------------
       
   609 // CProfileEngineImpl::PublishChangeL
       
   610 //
       
   611 // (other items were commented in a header).
       
   612 // -----------------------------------------------------------------------------
       
   613 //
       
   614 void CProfileEngineImpl::PublishChangeL( TUint32 aPSKey )
       
   615     {
       
   616     TInt flag( 0 );
       
   617     User::LeaveIfError( iProperty.Get( KPSUidProfileEngine,
       
   618                                        aPSKey, flag ) );
       
   619     User::LeaveIfError( iProperty.Set( KPSUidProfileEngine,
       
   620                                        aPSKey, ~flag ) );
       
   621     }
       
   622 
       
   623 // -----------------------------------------------------------------------------
       
   624 // CProfileEngineImpl::UpdateActiveProfileSettingsL
       
   625 //
       
   626 // (other items were commented in a header).
       
   627 // -----------------------------------------------------------------------------
       
   628 //
       
   629 void CProfileEngineImpl::UpdateActiveProfileSettingsL( MProfile& aProfile,
       
   630         TBool aSetId )
       
   631     {
       
   632     const MProfileTones& profileTones = aProfile.ProfileTones();
       
   633     const MProfileName& profileName = aProfile.ProfileName();
       
   634     const TProfileToneSettings& settings = profileTones.ToneSettings();
       
   635 
       
   636     // These cannot fail because this method is called only in between
       
   637     // StartTransaction() and CommitTransaction() calls (except vibra)
       
   638     iCenRep->Set( KProEngActiveRingingType, settings.iRingingType );
       
   639     iCenRep->Set( KProEngActiveRingingVolume, settings.iRingingVolume );
       
   640     iCenRep->Set( KProEngActiveMessageAlert, !( aProfile.IsSilent() ) );
       
   641     if ( !PowerSaveMode() )
       
   642         {
       
   643     User::LeaveIfError( iVibraCenRep->Set(
       
   644             KVibraCtrlProfileVibraEnabled, settings.iVibratingAlert ) );
       
   645 
       
   646 #ifdef RD_TACTILE_FEEDBACK
       
   647 	const MProfileExtraSettings& extraSettings = aProfile.ProfileExtraSettings();
       
   648 	const MProfileFeedbackSettings& feedbackSettings = 
       
   649 			extraSettings.ProfileFeedbackSettings();
       
   650     User::LeaveIfError( iVibraCenRep->Set( KVibraCtrlProfileFeedbackEnabled, 
       
   651     		( feedbackSettings.TactileFeedback() ? 1 : 0 ) ) );
       
   652     iCenRep->Set( KProEngActiveTactileFeedback, feedbackSettings.TactileFeedback() );
       
   653     iCenRep->Set( KProEngActiveAudioFeedback, feedbackSettings.AudioFeedback() );
       
   654 #endif
       
   655 
       
   656     iCenRep->Set( KProEngActiveKeypadVolume, settings.iKeypadVolume );
       
   657         }
       
   658 
       
   659     iCenRep->Set( KProEngActiveWarningTones, settings.iWarningAndGameTones );
       
   660     if( aSetId )
       
   661         {
       
   662         iCenRep->Set( KProEngActiveProfile, profileName.Id() );
       
   663         }
       
   664     }
       
   665 
       
   666 // -----------------------------------------------------------------------------
       
   667 // CProfileEngineImpl::UpdateContactGroupsValueL
       
   668 //
       
   669 // (other items were commented in a header).
       
   670 // -----------------------------------------------------------------------------
       
   671 //
       
   672 void CProfileEngineImpl::UpdateContactGroupsValueL(
       
   673     MProfile& /* aProfile */ )
       
   674     {
       
   675     }
       
   676 
       
   677 // -----------------------------------------------------------------------------
       
   678 // CProfileEngineImpl::GetProfileL
       
   679 //
       
   680 // (other items were commented in a header).
       
   681 // -----------------------------------------------------------------------------
       
   682 //
       
   683 CProfileImpl* CProfileEngineImpl::GetProfileL(
       
   684     TInt aId )
       
   685     {
       
   686     CProfileImpl* profile = CProfileImpl::NewLC( *iFs );
       
   687     profile->InternalizeL( *iCenRep, aId );
       
   688     CleanupStack::Pop(); // profile
       
   689     return profile;
       
   690     }
       
   691 
       
   692 // -----------------------------------------------------------------------------
       
   693 // CProfileEngineImpl::ReadProfilesNamesL
       
   694 //
       
   695 // (other items were commented in a header).
       
   696 // -----------------------------------------------------------------------------
       
   697 //
       
   698 void CProfileEngineImpl::ReadProfilesNamesL(
       
   699         CProfilesNamesArrayImpl* aProfilesNames )
       
   700     {
       
   701     __ASSERT_DEBUG( aProfilesNames,
       
   702         ProfileEngPanic::Panic( EProfileEngPanicNullPointer ) );
       
   703 
       
   704     TInt len( iProfileLocalisedNames->MdcaCount() );
       
   705     CProfileNameImpl* profileName = CProfileNameImpl::NewL();
       
   706     CleanupStack::PushL( profileName );
       
   707 
       
   708     for( TInt i( 0 ); i < len; ++i )
       
   709         {
       
   710         TInt id( iProfileLocalisedNames->ProfileName( i )->Id() );
       
   711         profileName->InternalizeL( *iCenRep, id );
       
   712         if( !profileName->IsProfileNameChanged() )
       
   713             {
       
   714             profileName->SetLocalizedProfileNameL( *iProfileLocalisedNames );
       
   715             }
       
   716         CProfileNameImpl* nameImpl =
       
   717             CProfileNameImpl::NewLC( *profileName );
       
   718 
       
   719         User::LeaveIfError( aProfilesNames->InsertInOrder( nameImpl ) );
       
   720         CleanupStack::Pop();    // nameImpl
       
   721         }
       
   722 
       
   723     ReadDynamicProfilesNamesL( aProfilesNames, *profileName );
       
   724     CleanupStack::PopAndDestroy();  // profileName
       
   725     }
       
   726 
       
   727 // -----------------------------------------------------------------------------
       
   728 // CProfileEngineImpl::DoSetActiveProfileL
       
   729 //
       
   730 // (other items were commented in a header).
       
   731 // -----------------------------------------------------------------------------
       
   732 //
       
   733 void CProfileEngineImpl::DoSetActiveProfileL(
       
   734     TInt aId, TTime* aTime )
       
   735     {
       
   736     MProfileExtended* profile = ProfileLC( aId );
       
   737 
       
   738     User::LeaveIfError( iCenRep->StartTransaction(
       
   739             CRepository::EReadWriteTransaction ) );
       
   740     iCenRep->CleanupCancelTransactionPushL();
       
   741     // Cancel first any pending timings (the logic is the same both in new
       
   742     // timing and in plain activation):
       
   743     TInt previousId( iProfileTiming->CancelTimedProfileL() );
       
   744     if( aTime )
       
   745         {
       
   746         TInt activeId( ( previousId != KErrNotFound )
       
   747                        ? previousId
       
   748                        : User::LeaveIfError( ActiveProfileId() ) );
       
   749         iProfileTiming->SetTimedProfileL( activeId, *aTime );
       
   750         }
       
   751 
       
   752     TRAPD( error, UpdateActiveProfileSettingsL( *profile, ETrue ) );
       
   753     TUint32 ignore( 0 );
       
   754     if( !error )
       
   755         {
       
   756         error = iCenRep->CommitTransaction( ignore );
       
   757         }
       
   758 
       
   759     if( error )
       
   760         {
       
   761         if( aTime )
       
   762             {
       
   763             iProfileTiming->RollbackTimedProfile();
       
   764             }
       
   765         User::Leave( error );
       
   766         }
       
   767 
       
   768     PublishChangeL( KProEngActiveProfileChanged );// send P&S event
       
   769 
       
   770     CleanupStack::PopAndDestroy( 2 ); // profile, CleanupCancelTransactionPushL
       
   771     }
       
   772 
       
   773 // -----------------------------------------------------------------------------
       
   774 // CProfileEngineImpl::SetTempRingingVolumeL
       
   775 //
       
   776 // (other items were commented in a header).
       
   777 // -----------------------------------------------------------------------------
       
   778 //
       
   779 void CProfileEngineImpl::SetTempRingingVolumeL(
       
   780         TProfileRingingVolume aVolume )
       
   781     {
       
   782     LeaveIfReadOnlyL( EProfileFlagRingingVolume );
       
   783     CreatePubSubKeysIfNeededL(); 
       
   784     iMutex.Wait();
       
   785     TRAPD( error,
       
   786            User::LeaveIfError( iCenRep->StartTransaction(
       
   787                    CRepository::EReadWriteTransaction ) );
       
   788            iCenRep->CleanupCancelTransactionPushL();
       
   789            SetTempVolumeL( *iCenRep, KProEngActiveRingingVolume, aVolume );
       
   790            TUint32 ignore( 0 );
       
   791            User::LeaveIfError( iCenRep->CommitTransaction( ignore ) );
       
   792            CleanupStack::PopAndDestroy(); // CleanupCancelTransactionPushL()
       
   793            PublishChangeL( KProEngActiveProfileModified );
       
   794         );
       
   795     iMutex.Signal();
       
   796     User::LeaveIfError( error );
       
   797     }
       
   798 
       
   799 // -----------------------------------------------------------------------------
       
   800 // CProfileEngineImpl::TempRingingVolumeL
       
   801 //
       
   802 // (other items were commented in a header).
       
   803 // -----------------------------------------------------------------------------
       
   804 //
       
   805 TProfileRingingVolume CProfileEngineImpl::TempRingingVolumeL() const
       
   806     {
       
   807     return TempVolumeL( *iCenRep, KProEngActiveRingingVolume );
       
   808     }
       
   809 
       
   810 // -----------------------------------------------------------------------------
       
   811 // CProfileEngineImpl::SetTempMediaVolumeL
       
   812 //
       
   813 // (other items were commented in a header).
       
   814 // -----------------------------------------------------------------------------
       
   815 //
       
   816 void CProfileEngineImpl::SetTempMediaVolumeL(
       
   817         TProfileRingingVolume /* aVolume */ )
       
   818     {
       
   819     // Media volume is not used anymore
       
   820     }
       
   821 
       
   822 // -----------------------------------------------------------------------------
       
   823 // CProfileEngineImpl::TempMediaVolumeL
       
   824 //
       
   825 // (other items were commented in a header).
       
   826 // -----------------------------------------------------------------------------
       
   827 //
       
   828 TProfileRingingVolume CProfileEngineImpl::TempMediaVolumeL() const
       
   829     {
       
   830     return TempRingingVolumeL();
       
   831     // Media volume is not used anymore
       
   832     }
       
   833 
       
   834 // -----------------------------------------------------------------------------
       
   835 // CProfileEngineImpl::SetTempVolumeL
       
   836 //
       
   837 // (other items were commented in a header).
       
   838 // -----------------------------------------------------------------------------
       
   839 //
       
   840 void CProfileEngineImpl::SetTempVolumeL(
       
   841         CRepository& aCenRep, TUint32 aCenRepKey,
       
   842         TProfileRingingVolume aVolume )
       
   843     {
       
   844     // level 0 is only for CDMA version:
       
   845     User::LeaveIfError( aCenRep.Set( aCenRepKey, aVolume ) );
       
   846     }
       
   847 
       
   848 
       
   849 // -----------------------------------------------------------------------------
       
   850 // CProfileEngineImpl::TempVolumeL
       
   851 //
       
   852 // (other items were commented in a header).
       
   853 // -----------------------------------------------------------------------------
       
   854 //
       
   855 TProfileRingingVolume CProfileEngineImpl::TempVolumeL(
       
   856         CRepository& aCenRep, TUint32 aCenRepKey ) const
       
   857     {
       
   858     TInt volume( 0 );
       
   859     User::LeaveIfError( aCenRep.Get( aCenRepKey, volume ) );
       
   860     TProfileRingingVolume vol = TProfileRingingVolume( volume );
       
   861     return vol;
       
   862     }
       
   863 
       
   864 // -----------------------------------------------------------------------------
       
   865 // CProfileEngineImpl::CheckProfileIdL
       
   866 //
       
   867 // (other items were commented in a header).
       
   868 // -----------------------------------------------------------------------------
       
   869 //
       
   870 TInt CProfileEngineImpl::CheckProfileIdL( TInt aId )
       
   871     {
       
   872     if( !IsDefaultProfile( aId ) && ProfileEngUtils::FindValueFromBinaryKeyL(
       
   873             *iCenRep, KProEngUsedIds, aId ) == KErrNotFound )
       
   874         {
       
   875         return KErrNotFound;
       
   876         }
       
   877     return KErrNone;
       
   878     }
       
   879 
       
   880 // -----------------------------------------------------------------------------
       
   881 // CProfileEngineImpl::CreatePubSubKeysIfNeededL
       
   882 //
       
   883 // (other items were commented in a header).
       
   884 // -----------------------------------------------------------------------------
       
   885 //
       
   886 void CProfileEngineImpl::CreatePubSubKeysIfNeededL()
       
   887     {
       
   888     if( iPubSubKeysCreated ) return;
       
   889 
       
   890     _LIT_SECURITY_POLICY_PASS( KProfileEngReadPolicy );
       
   891     const TSecurityPolicy KProfileEngWritePolicy( ECapabilityWriteDeviceData );
       
   892 
       
   893     TInt error( RProperty::Define( KPSUidProfileEngine,
       
   894                                    KProEngActiveProfileModified,
       
   895                                    RProperty::EInt,
       
   896                                    KProfileEngReadPolicy,
       
   897                                    KProfileEngWritePolicy ) );
       
   898     if( error && error != KErrAlreadyExists )
       
   899         {
       
   900         User::Leave( error );
       
   901         }
       
   902 
       
   903     error = RProperty::Define( KPSUidProfileEngine,
       
   904                                KProEngActiveProfileChanged,
       
   905                                RProperty::EInt,
       
   906                                KProfileEngReadPolicy,
       
   907                                KProfileEngWritePolicy );
       
   908     if( error && error != KErrAlreadyExists )
       
   909         {
       
   910         User::Leave( error );
       
   911         }
       
   912 
       
   913     iPubSubKeysCreated = ETrue;
       
   914     }
       
   915 
       
   916 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
   917 
       
   918 // -----------------------------------------------------------------------------
       
   919 // CreateProfileEngineL create profiles engine and return public interface
       
   920 // of the profiles engine.
       
   921 // Returns: Profiles Engine public interface
       
   922 // -----------------------------------------------------------------------------
       
   923 //
       
   924 EXPORT_C MProfileEngine* CreateProfileEngineL()
       
   925     {
       
   926     return CProfileEngineImpl::NewL();
       
   927     }
       
   928 
       
   929 // -----------------------------------------------------------------------------
       
   930 // CreateProfileEngineExtendedL create profiles engine and
       
   931 // return internal interface of the profiles engine
       
   932 // Returns: Profiles Engine internal interface
       
   933 // -----------------------------------------------------------------------------
       
   934 //
       
   935 EXPORT_C MProfileEngineExtended* CreateProfileEngineExtendedL()
       
   936     {
       
   937     return CProfileEngineImpl::NewL();
       
   938     }
       
   939 
       
   940 // -----------------------------------------------------------------------------
       
   941 // CreateProfileEngineL create profiles engine and return public interface
       
   942 // of the profiles engine.
       
   943 // Returns: Profiles Engine public interface
       
   944 // -----------------------------------------------------------------------------
       
   945 //
       
   946 EXPORT_C MProfileEngine* CreateProfileEngineL( RFs* aFs )
       
   947     {
       
   948     return CProfileEngineImpl::NewL( aFs );
       
   949     }
       
   950 
       
   951 // -----------------------------------------------------------------------------
       
   952 // CreateProfileEngineExtendedL create profiles engine and
       
   953 // return internal interface of the profiles engine
       
   954 // Returns: Profiles Engine internal interface
       
   955 // -----------------------------------------------------------------------------
       
   956 //
       
   957 EXPORT_C MProfileEngineExtended* CreateProfileEngineExtendedL( RFs* aFs )
       
   958     {
       
   959     return CProfileEngineImpl::NewL( aFs );
       
   960     }
       
   961 
       
   962 
       
   963 // -----------------------------------------------------------------------------
       
   964 // CProfileEngineImpl::PowerSaveMode
       
   965 //
       
   966 // -----------------------------------------------------------------------------
       
   967 //
       
   968 TBool CProfileEngineImpl::PowerSaveMode()
       
   969     {
       
   970     TBool psm = EFalse;
       
   971     
       
   972     TRAPD( err, psm = PowerSaveModeL() );
       
   973     
       
   974     if ( err != KErrNone )
       
   975         {
       
   976         return EFalse;
       
   977         }
       
   978         
       
   979     return psm;
       
   980     }
       
   981 
       
   982     
       
   983 // -----------------------------------------------------------------------------
       
   984 // CProfileEngineImpl::PowerSaveModeL
       
   985 //
       
   986 // -----------------------------------------------------------------------------
       
   987 //
       
   988 TBool CProfileEngineImpl::PowerSaveModeL()
       
   989     {
       
   990     if( !FeatureManager::FeatureSupported( KFeatureIdPowerSave ) )
       
   991         {
       
   992         return EFalse;
       
   993         }
       
   994 
       
   995     TInt psm = EPsmsrvModeNormal;
       
   996     
       
   997     // KProEngPsmChanged PubSub key is set by GSProfilesPlugin when power save
       
   998     // mode changes. If the key cannot be read (doesn't exist), PSM hasn't
       
   999     // changed since the last boot and the mode is read from PSM CenRep.
       
  1000     if( RProperty::Get( KPSUidProfileEngine, KProEngPsmChanged, psm ) != KErrNone )
       
  1001         {
       
  1002         CRepository* cenrep = CRepository::NewLC( KCRUidPowerSaveMode );
       
  1003         User::LeaveIfError( cenrep->Get( KPsmCurrentMode, psm ) );
       
  1004         CleanupStack::PopAndDestroy( cenrep );
       
  1005         }
       
  1006 
       
  1007     if ( psm == EPsmsrvModePowerSave )
       
  1008         {
       
  1009         return ETrue;
       
  1010         }
       
  1011         
       
  1012     return EFalse;
       
  1013     }
       
  1014 
       
  1015 
       
  1016 //  End of File