uiservicetabsettings/src/cvimpstsettingscenrep.cpp
branchRCL_3
changeset 29 9a48e301e94b
parent 0 5e5d6b214f4f
equal deleted inserted replaced
28:3104fc151679 29:9a48e301e94b
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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:  vimpstsettings store implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include 	<e32std.h>
       
    22 #include    <centralrepository.h>
       
    23 
       
    24 #include    "cvimpstsettingscenrep.h"
       
    25 #include	"cvimpstsettings.h"
       
    26 #include	"cvimpstsettingskeyvaluepair.h"
       
    27 #include    "cvimpstsettingskeyvaluepairs.h"
       
    28 #include	"vimpstsettingsstorecenrepuids.h"
       
    29 #include    "vimpstsettingsstoredefinitions.h"
       
    30 #include    "rvimpstsettingsreleasearray.h"
       
    31 
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CVIMPSTSettingsCenRep::CVIMPSTUiSAPCenRep
       
    37 // C++ default constructor can NOT contain any code, that
       
    38 // might leave.
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 CVIMPSTSettingsCenRep::CVIMPSTSettingsCenRep()
       
    42     {
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CVIMPSTSettingsCenRep::ConstructL
       
    47 // Symbian 2nd phase constructor can leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 void CVIMPSTSettingsCenRep::ConstructL( )
       
    51     {
       
    52     iRepository = CRepository::NewL( KCRUidIMStore ); 
       
    53     }
       
    54 
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CVIMPSTSettingsCenRep::NewL
       
    58 // Two-phased constructor.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 CVIMPSTSettingsCenRep* CVIMPSTSettingsCenRep::NewL( )
       
    62     {
       
    63     CVIMPSTSettingsCenRep* self = CVIMPSTSettingsCenRep::NewLC( );
       
    64     CleanupStack::Pop();
       
    65     return self;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CVIMPSTSettingsCenRep::NewLC
       
    70 // Two-phased constructor.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 CVIMPSTSettingsCenRep* CVIMPSTSettingsCenRep::NewLC( )
       
    74     {
       
    75     CVIMPSTSettingsCenRep* self = new( ELeave ) CVIMPSTSettingsCenRep();
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     return self;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CVIMPSTSettingsCenRep::~CVIMPSTSettingsCenRep
       
    83 // Destructor
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CVIMPSTSettingsCenRep::~CVIMPSTSettingsCenRep()
       
    87     {   
       
    88     delete iRepository;
       
    89     }
       
    90 
       
    91 
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CVIMPSTSettingsCenRep::StoreNewSAPL()
       
    95 // Stores new SAP in central repository
       
    96 // (other items were commented in a header).
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CVIMPSTSettingsCenRep::UpdateOldSettingsL( TUint32& aServiceId, CVIMPSTSettings* aSettings )
       
   100     {  
       
   101 
       
   102     // no documentation for StartTransaction() return values, leave if any error
       
   103     User::LeaveIfError( iRepository->StartTransaction( CRepository::EReadWriteTransaction ) );
       
   104 
       
   105     iRepository->CleanupCancelTransactionPushL();	
       
   106 
       
   107     const RPointerArray< CVIMPSTSettingsKeyValuePair >& pairs( aSettings->KeyValuePairs().Pairs() );
       
   108 
       
   109 
       
   110     //First delete old key-value pairs 	
       
   111     RArray<TUint32> foundPairs;
       
   112     CleanupClosePushL( foundPairs );
       
   113     iRepository->FindL( EKeyValuePairBase + aServiceId, KSAPPairsMask, foundPairs );
       
   114     TInt oldCount( foundPairs.Count() );
       
   115     for( TInt i( 0 ); i < oldCount; ++i )
       
   116         {
       
   117         User::LeaveIfError( iRepository->Delete( foundPairs[i] ) );
       
   118         }
       
   119 
       
   120     TInt count( pairs.Count() );
       
   121     RVIMPSTSettingsReleaseArray tempArray;
       
   122     CleanupClosePushL( tempArray );
       
   123     for( TInt i( 0 );i < count; ++i )
       
   124         {
       
   125         //HBufC ownership transfers here
       
   126         HBufC* valuePairFlat = pairs[i]->KeyValuePairFlatLC();
       
   127         User::LeaveIfError( iRepository->Create( EKeyValuePairBase + i + aServiceId,
       
   128                 *valuePairFlat ) );
       
   129         // CRepository->Create() is not copying the pointed data during transaction
       
   130         // so these must be stored until the transaction has completed
       
   131         tempArray.AppendL( valuePairFlat );
       
   132         CleanupStack::Pop( valuePairFlat );
       
   133         }
       
   134 
       
   135     TUint32 err( KErrNone );
       
   136     //passed err will be silently consumed because the value is of no use to client
       
   137     User::LeaveIfError( iRepository->CommitTransaction( err ) );	
       
   138     CleanupStack::PopAndDestroy( 3 ); //temparray, foundpairs, transaction
       
   139 	
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CVIMPSTSettingsCenRep::GetSAPL()
       
   144 // Gets SAP from central repository
       
   145 // (other items were commented in a header).
       
   146 // -----------------------------------------------------------------------------
       
   147 
       
   148 void CVIMPSTSettingsCenRep::GetSettingsL( TUint32& aServiceId, CVIMPSTSettings* aSettings )
       
   149 	{
       
   150 	TRAPD( err, DoGetSettingsL( aServiceId, aSettings ) );
       
   151 	if( err )
       
   152 		{
       
   153 		User::Leave( err );
       
   154 		}
       
   155 	}
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CVIMPSTSettingsCenRep::DoGetSAPL()
       
   159 // Does the actual get operation
       
   160 // (other items were commented in a header).
       
   161 // -----------------------------------------------------------------------------
       
   162 
       
   163 void CVIMPSTSettingsCenRep::DoGetSettingsL( TUint32& aServiceId, CVIMPSTSettings* aSettings )
       
   164 	{
       
   165 	TBool transaction( StartOwnTransaction( CRepository::EReadTransaction ) );
       
   166 	if( transaction )
       
   167 	    {
       
   168 	    iRepository->CleanupCancelTransactionPushL();
       
   169 	    }
       
   170 
       
   171 	HBufC* tmpBuffer = HBufC::NewLC( NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   172 	TPtr tmpPtr( tmpBuffer->Des() );
       
   173 
       
   174 	RPointerArray< CVIMPSTSettingsKeyValuePair >& pairs( aSettings->KeyValuePairs().Pairs() );
       
   175 	pairs.ResetAndDestroy();
       
   176 
       
   177 	RArray<TUint32> foundPairs;
       
   178 	CleanupClosePushL( foundPairs );
       
   179 	iRepository->FindL( EKeyValuePairBase + aServiceId, KSAPPairsMask, foundPairs );
       
   180 	TInt count( foundPairs.Count() );
       
   181 
       
   182 	for( TInt i( 0 );i < count; ++i )
       
   183 	    {
       
   184 	    TPtr valuePairFlatPtr( tmpBuffer->Des() );
       
   185 
       
   186 	    User::LeaveIfError(
       
   187 	            iRepository->Get( foundPairs[ i ],
       
   188 	                    valuePairFlatPtr ) );
       
   189 
       
   190 	    // parse the key-value pair descriptor
       
   191 
       
   192 	    CVIMPSTSettingsKeyValuePair* pair = CVIMPSTSettingsKeyValuePair::NewLC( valuePairFlatPtr );
       
   193 
       
   194 	    pairs.AppendL( pair );
       
   195 
       
   196 	    CleanupStack::Pop( pair );
       
   197 	    }
       
   198 
       
   199 	if( transaction )
       
   200 	    {
       
   201 	    TUint32 err( KErrNone );
       
   202 	    User::LeaveIfError( iRepository->CommitTransaction( err ) );
       
   203 	    CleanupStack::PopAndDestroy(); // transaction
       
   204 	    }
       
   205 	CleanupStack::PopAndDestroy( 2 ); // foundPairs, tmpBuffer	
       
   206 	}
       
   207 
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CVIMPSTSettingsCenRep::StartOwnTransaction()
       
   211 // Starts new transaction if there is no ongoing transaction
       
   212 // (other items were commented in a header).
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 TBool CVIMPSTSettingsCenRep::StartOwnTransaction( TInt aMode )
       
   216     {
       
   217      /*currently the API TransactionState() has been removed from 9.2
       
   218      * the API TransactionState was added for the synchronization purpose
       
   219      * from meco point of view, as of now we are no where, same key value is not updated across processes or exe's
       
   220      * this can be considered as a temporary fix and more analysis has to done on this
       
   221      * to provide a complete fix.
       
   222      */
       
   223     //TInt transaction( iRepository->TransactionState() );
       
   224 
       
   225     // if( !transaction )
       
   226     //  {
       
   227     iRepository->StartTransaction( static_cast<CRepository::TTransactionMode>( aMode ) );
       
   228     return ETrue;
       
   229     //  }
       
   230     //return EFalse;
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CVIMPSTSettingsCenRep::Repository()
       
   235 // Starts new transaction if there is no ongoing transaction
       
   236 // (other items were commented in a header).
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 CRepository* CVIMPSTSettingsCenRep::Repository( )const
       
   240     {
       
   241     return iRepository;
       
   242     }
       
   243 
       
   244 //  End of File