uiservicetabsettings/src/cvimpstsettingsstore.cpp
branchRCL_3
changeset 23 9a48e301e94b
parent 0 5e5d6b214f4f
equal deleted inserted replaced
22:3104fc151679 23:9a48e301e94b
       
     1 /*
       
     2 * Copyright (c) 2005 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:  implimentation class for the settings store
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 //  INCLUDES
       
    20 #include <e32std.h>
       
    21 #include "cvimpstsettingsstore.h"
       
    22 #include "cvimpstsettingscenrep.h"
       
    23 #include "cvimpstsettings.h"
       
    24 #include <centralrepository.h>
       
    25 
       
    26 //dummy serviceId, assuming the service id not more than 256. for the first time
       
    27 //and it is assumed that this service id is for initializing the cenrep keys only.
       
    28 //not updated in the service table and hence will not get a TAB in phone book
       
    29 const TInt KServiceIDOffset = 16;
       
    30 
       
    31 //================= MEMBER FUNCTIONS =======================
       
    32 // ---------------------------------------------------------
       
    33 // CVIMPSTSettingsStore::NewLC
       
    34 // 
       
    35 // ---------------------------------------------------------
       
    36 EXPORT_C MVIMPSTSettingsStore* CVIMPSTSettingsStore::NewLC()
       
    37     {
       
    38     CVIMPSTSettingsStore* self = new (ELeave) CVIMPSTSettingsStore( );
       
    39     CleanupStack::PushL( self );
       
    40     self->ConstructL( );
       
    41     return self;
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------
       
    46 // CVIMPSTSettingsStore::NewL
       
    47 // 
       
    48 // ---------------------------------------------------------
       
    49 EXPORT_C MVIMPSTSettingsStore* CVIMPSTSettingsStore::NewL()
       
    50     {
       
    51     MVIMPSTSettingsStore* self = CVIMPSTSettingsStore::NewLC();
       
    52     CleanupStack::Pop( );//self
       
    53     return self;
       
    54     }
       
    55     
       
    56 // ---------------------------------------------------------
       
    57 // CVIMPSTSettingsStore::Destructor
       
    58 // 
       
    59 // ---------------------------------------------------------
       
    60 CVIMPSTSettingsStore::~CVIMPSTSettingsStore()
       
    61     {
       
    62     if(iCenrepStore)
       
    63         {
       
    64         delete iCenrepStore;
       
    65         iCenrepStore = NULL;
       
    66         }
       
    67     if(iSettings)
       
    68         {
       
    69         delete iSettings;
       
    70         iSettings = NULL;
       
    71         }
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------
       
    75 // CVIMPSTSettingsStore::ConstructL
       
    76 // 
       
    77 // ---------------------------------------------------------
       
    78 
       
    79  void CVIMPSTSettingsStore::ConstructL( )
       
    80     {
       
    81     iCenrepStore = CVIMPSTSettingsCenRep::NewL();
       
    82     // Get settings from vimpstsettings store to work with   
       
    83     iSettings = CVIMPSTSettings::NewL(); 
       
    84     }
       
    85  
       
    86 
       
    87 // ---------------------------------------------------------
       
    88 // CVIMPSTSettingsStore::Get
       
    89 // 
       
    90 // ---------------------------------------------------------
       
    91 TInt CVIMPSTSettingsStore::GetL(TUint32 aServiceId, TSettingItemName aSettingItemName, TInt& aValue ) const
       
    92     {
       
    93     TInt maskedId = aServiceId << KServiceIDOffset ;
       
    94     TInt retError = iCenrepStore->Repository()->Get( maskedId + aSettingItemName, aValue );
       
    95     if( retError == KErrNotFound)
       
    96         {
       
    97         //if key not found, create a new key with the defualt value 0
       
    98         aValue = 0;
       
    99         retError = iCenrepStore->Repository()->Create( maskedId + aSettingItemName, aValue ) ;
       
   100         }
       
   101     return retError; // return the value : error code  
       
   102     }
       
   103 
       
   104 // ---------------------------------------------------------
       
   105 // CVIMPSTSettingsStore::Set
       
   106 // 
       
   107 // ---------------------------------------------------------
       
   108 TInt CVIMPSTSettingsStore::SetL(TUint32 aServiceId, TSettingItemName aSettingItemName, const TInt aValue  )
       
   109     {
       
   110     TInt maskedId = aServiceId << KServiceIDOffset ;
       
   111     TInt retError = iCenrepStore->Repository()->Set( maskedId + aSettingItemName, aValue );    
       
   112     if( retError == KErrNotFound )
       
   113         {       
       
   114         retError = iCenrepStore->Repository()->Create( maskedId + aSettingItemName, aValue );
       
   115         }
       
   116     return retError; // return the value : error code  
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CVIMPSTSettingsStore::Get
       
   121 // 
       
   122 // ---------------------------------------------------------
       
   123 
       
   124 TInt CVIMPSTSettingsStore::GetL(TUint32 aServiceId, TSettingItemName aSettingItemName, RBuf& aBuffer  ) const
       
   125     {
       
   126     TInt maskedId = aServiceId << KServiceIDOffset ;
       
   127     TInt retError = iCenrepStore->Repository()->Get( maskedId + aSettingItemName, aBuffer );
       
   128     if( retError == KErrNotFound)
       
   129         {
       
   130         aBuffer = _L(" ");
       
   131         retError = iCenrepStore->Repository()->Create( maskedId + aSettingItemName, aBuffer ) ;
       
   132         }
       
   133     return retError;     // return the value : error code  
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------
       
   137 // CVIMPSTSettingsStore::Set
       
   138 // 
       
   139 // ---------------------------------------------------------
       
   140 
       
   141 TInt CVIMPSTSettingsStore::SetL(TUint32 aServiceId, TSettingItemName aSettingItemName, const TDesC& aBuffer  )
       
   142     {
       
   143     TInt maskedId = aServiceId << KServiceIDOffset ;
       
   144     TInt retError = iCenrepStore->Repository()->Set( maskedId + aSettingItemName, aBuffer );
       
   145     if( retError == KErrNotFound)
       
   146         {        
       
   147         retError = iCenrepStore->Repository()->Create( maskedId + aSettingItemName, aBuffer );
       
   148         }
       
   149     return retError;  // return the value : error code  
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------------------------------------
       
   153 // CVIMPSTSettingsStore::GetL
       
   154 // 
       
   155 // ------------------------------------------------------------------------------------------------------------
       
   156 
       
   157 TInt CVIMPSTSettingsStore::GetL(TUint32 aServiceId, TSettingItemName aSettingItemName, RBuf8& aBuffer  ) const
       
   158     {
       
   159     TInt maskedId = aServiceId << KServiceIDOffset ;
       
   160     TInt retError = iCenrepStore->Repository()->Get( maskedId + aSettingItemName, aBuffer );
       
   161     if( retError == KErrNotFound)
       
   162         { 
       
   163         // if not found set return value to null descriptor and create in the cenrep
       
   164         aBuffer = _L8("");
       
   165         retError = iCenrepStore->Repository()->Create( maskedId + aSettingItemName, aBuffer  ) ;  
       
   166         }
       
   167     return retError; // return the value : error code  
       
   168     }
       
   169 
       
   170 // --------------------------------------------------------------------------------------------------
       
   171 // CVIMPSTSettingsStore::SetL
       
   172 // 
       
   173 // ---------------------------------------------------------------------------------------------------
       
   174 
       
   175 TInt CVIMPSTSettingsStore::SetL(TUint32 aServiceId, TSettingItemName aSettingItemName, const TDesC8& aBuffer  )
       
   176     {
       
   177     TInt maskedId = aServiceId << KServiceIDOffset ;
       
   178     TInt retError = iCenrepStore->Repository()->Set( maskedId + aSettingItemName, aBuffer );
       
   179     if( retError == KErrNotFound)
       
   180         { // if not found create  
       
   181         retError = iCenrepStore->Repository()->Create( maskedId + aSettingItemName, aBuffer );
       
   182         }
       
   183     return retError; // return the value : Error code
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------------------------------
       
   187 // CVIMPSTSettingsStore::GetSAPL
       
   188 // 
       
   189 // ----------------------------------------------------------------------------------------------------
       
   190 void CVIMPSTSettingsStore::GetSAPL( TUint32 aServiceId, CVIMPSTSettings* aSettings )
       
   191     {
       
   192     iCenrepStore->GetSettingsL( aServiceId, aSettings );
       
   193     }
       
   194 
       
   195 //End of file