profilesservices/ProfileEngine/EngSrc/CProfileEngineImpl.cpp
branchRCL_3
changeset 10 c8b9b0986973
parent 8 f62c3a3d66b8
child 11 23553eb4e470
equal deleted inserted replaced
8:f62c3a3d66b8 10:c8b9b0986973
   304 // -----------------------------------------------------------------------------
   304 // -----------------------------------------------------------------------------
   305 //
   305 //
   306 void CProfileEngineImpl::SetActiveProfileL( TInt aId )
   306 void CProfileEngineImpl::SetActiveProfileL( TInt aId )
   307     {
   307     {
   308     PRODEBUG1( "SetActiveProfileL( %d )", aId );
   308     PRODEBUG1( "SetActiveProfileL( %d )", aId );
   309     const TInt KProEngPreviousActiveNameLength( 128 );
       
   310     CreatePubSubKeysIfNeededL(); 
   309     CreatePubSubKeysIfNeededL(); 
   311 
   310 
   312     iMutex.Wait();
   311     iMutex.Wait();
   313     TInt err( CheckProfileIdL( aId ) );
   312     TInt err( CheckProfileIdL( aId ) );
   314     TInt nameCompare = 0;
       
   315     if( this->IsActiveProfileTimedL() )
       
   316         {
       
   317 		HBufC* tempProfileName = HBufC::NewL(KProEngPreviousActiveNameLength);
       
   318 		CleanupStack::PushL(tempProfileName);  
       
   319 		TPtr tempName = tempProfileName->Des();
       
   320 		TInt cenrepErr = iCenRep->Get( KProEngPreviousActiveName,tempName );
       
   321 		if( tempName.Length() )
       
   322 			{
       
   323 			TBuf<64> activeProfileName = this->ProfileLC(aId)->ProfileName().Name();
       
   324 			nameCompare = activeProfileName.Compare( tempName );
       
   325 			CleanupStack::PopAndDestroy();
       
   326 			}
       
   327 		CleanupStack::PopAndDestroy();
       
   328 		User::LeaveIfError( iCenRep->StartTransaction(
       
   329 											CRepository::EReadWriteTransaction ) );
       
   330 		iCenRep->CleanupCancelTransactionPushL();
       
   331 		iCenRep->Set(KProEngPreviousActiveName,_L(""));
       
   332 		TUint32 ignore( 0 );
       
   333     if( !err )
   313     if( !err )
   334 			{
       
   335 			err = iCenRep->CommitTransaction( ignore );
       
   336 			}
       
   337 		else
       
   338 			{
       
   339 			iCenRep->CancelTransaction();
       
   340 			}
       
   341 		CleanupStack::PopAndDestroy();
       
   342         }
       
   343     if( !err && !nameCompare )
       
   344         {
   314         {
   345         TRAP( err, DoSetActiveProfileL( aId ) );
   315         TRAP( err, DoSetActiveProfileL( aId ) );
   346         }
   316         }
   347     else
   317     else
   348         {
   318         {
   387     iMutex.Wait();
   357     iMutex.Wait();
   388     TInt err( CheckProfileIdL( aId ) );
   358     TInt err( CheckProfileIdL( aId ) );
   389 
   359 
   390     if( !err )
   360     if( !err )
   391         {
   361         {
   392         User::LeaveIfError( iCenRep->StartTransaction(
       
   393                         CRepository::EReadWriteTransaction ) );
       
   394         iCenRep->CleanupCancelTransactionPushL();
       
   395         iCenRep->Set(KProEngPreviousActiveName,this->ActiveProfileLC()->ProfileName().Name());
       
   396         TUint32 ignore( 0 );
       
   397         err = iCenRep->CommitTransaction( ignore );
       
   398         if( !err )
       
   399             {
       
   400         TRAP( err, DoSetActiveProfileL( aId, &aTime ) );
   362         TRAP( err, DoSetActiveProfileL( aId, &aTime ) );
   401             }
       
   402         else
       
   403         	{
       
   404         	iCenRep->CancelTransaction();
       
   405         	}
       
   406         CleanupStack::PopAndDestroy(2); 
       
   407         }
   363         }
   408     iMutex.Signal();
   364     iMutex.Signal();
   409 
   365 
   410     User::LeaveIfError( err );
   366     User::LeaveIfError( err );
   411     }
   367     }
   787     if( aTime )
   743     if( aTime )
   788         {
   744         {
   789         TInt activeId( ( previousId != KErrNotFound )
   745         TInt activeId( ( previousId != KErrNotFound )
   790                        ? previousId
   746                        ? previousId
   791                        : User::LeaveIfError( ActiveProfileId() ) );
   747                        : User::LeaveIfError( ActiveProfileId() ) );
   792         iProfileTiming->SetTimedProfileL( activeId, *aTime );
   748         iProfileTiming->SetTimedProfileL( activeId,
       
   749         		                          *aTime, 
       
   750         		                          ActiveProfileL()->ProfileName().Name() );
   793         }
   751         }
   794 
   752 
   795     TRAPD( error, UpdateActiveProfileSettingsL( *profile, ETrue ) );
   753     TRAPD( error, UpdateActiveProfileSettingsL( *profile, ETrue ) );
   796     TUint32 ignore( 0 );
   754     TUint32 ignore( 0 );
   797     if( !error )
   755     if( !error )