syncmlfw/ds/settings/src/nsmldsoperatorsettings.cpp
branchRCL_3
changeset 62 19bba8228ff0
parent 61 b183ec05bd8c
child 65 5cc2995847ea
equal deleted inserted replaced
61:b183ec05bd8c 62:19bba8228ff0
     1 /*
       
     2 * Copyright (c) 2010 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:  DS Operator Settings
       
    15 *
       
    16 */
       
    17 
       
    18 // INTERNAL INCLUDES
       
    19 #include "nsmldsoperatorsettings.h"
       
    20 
       
    21 // EXTERNAL INCLUDES
       
    22 #include <centralrepository.h>      //CRepository
       
    23 #include <nsmloperatordatacrkeys.h> // KCRUidOperatorDatasyncInternalKeys
       
    24 
       
    25 // CONSTANTS
       
    26 const TInt KMaxLength = 256;
       
    27 const TInt KBufferLength = 256;
       
    28 const TInt KValueLength = 50;
       
    29 _LIT( KSpace, " " );
       
    30 
       
    31 //-----------------------------------------------------------------------------
       
    32 //      CNSmlDSOperatorSettings::NewL
       
    33 //-----------------------------------------------------------------------------
       
    34 EXPORT_C CNSmlDSOperatorSettings* CNSmlDSOperatorSettings::NewL()
       
    35     {
       
    36     CNSmlDSOperatorSettings* self = CNSmlDSOperatorSettings::NewLC();
       
    37     CleanupStack::Pop();
       
    38     return self;
       
    39     }
       
    40 
       
    41 //-----------------------------------------------------------------------------
       
    42 //      CNSmlDSOperatorSettings::NewLC
       
    43 //-----------------------------------------------------------------------------
       
    44 EXPORT_C CNSmlDSOperatorSettings* CNSmlDSOperatorSettings::NewLC()
       
    45     {
       
    46     CNSmlDSOperatorSettings* self = new( ELeave ) CNSmlDSOperatorSettings;
       
    47     CleanupStack::PushL( self );
       
    48     self->ConstructL();
       
    49     return self;
       
    50     }
       
    51 
       
    52 //-----------------------------------------------------------------------------
       
    53 //      CNSmlDSOperatorSettings::ConstructL
       
    54 //-----------------------------------------------------------------------------
       
    55 void CNSmlDSOperatorSettings::ConstructL()
       
    56     {
       
    57     iRepository = CRepository::NewL( KCRUidOperatorDatasyncInternalKeys );
       
    58     }
       
    59 
       
    60 //-----------------------------------------------------------------------------
       
    61 //      CNSmlDSOperatorSettings::~CNSmlDSOperatorSettings
       
    62 //-----------------------------------------------------------------------------
       
    63 EXPORT_C CNSmlDSOperatorSettings::~CNSmlDSOperatorSettings()
       
    64     {
       
    65     delete iRepository;
       
    66     }
       
    67 
       
    68 //-----------------------------------------------------------------------------
       
    69 //      CNSmlDSOperatorSettings::CNSmlDSOperatorSettings
       
    70 //-----------------------------------------------------------------------------
       
    71 CNSmlDSOperatorSettings::CNSmlDSOperatorSettings()
       
    72     {
       
    73     }
       
    74 
       
    75 //-----------------------------------------------------------------------------
       
    76 // CNSmlDSOperatorSettings::IsOperatorProfileL
       
    77 // Is current profile Operator specific profile.
       
    78 //-----------------------------------------------------------------------------
       
    79 EXPORT_C TBool CNSmlDSOperatorSettings::IsOperatorProfileL( 
       
    80     const TDesC& aServerId )
       
    81     {
       
    82     if( aServerId.Length() != 0 )
       
    83         {
       
    84         TBuf8< KMaxLength > value;
       
    85         TBuf< KMaxLength > valueUtf16;
       
    86         
       
    87         iRepository->Get( KNsmlOpDsOperatorSyncServerId, value );
       
    88         valueUtf16.Copy( value );
       
    89         if ( aServerId.Compare( valueUtf16 ) == 0 )
       
    90             {
       
    91             return ETrue;
       
    92             }
       
    93         }
       
    94     return EFalse;
       
    95     }
       
    96 
       
    97 //-----------------------------------------------------------------------------
       
    98 // CNSmlDSOperatorSettings::CustomSwvValueLC
       
    99 // SW version of Operator specific profile.
       
   100 //-----------------------------------------------------------------------------
       
   101 EXPORT_C HBufC8* CNSmlDSOperatorSettings::CustomSwvValueLC()
       
   102     {
       
   103     return GetValueLC( KNsmlOpDsDevInfoSwVValue );
       
   104     }
       
   105 
       
   106 //-----------------------------------------------------------------------------
       
   107 // CNSmlDSOperatorSettings:::CustomModValueLC
       
   108 // Mod value of Operator specific profile.
       
   109 //-----------------------------------------------------------------------------
       
   110 EXPORT_C HBufC8* CNSmlDSOperatorSettings::CustomModValueLC()
       
   111     {
       
   112     return GetValueLC( KNsmlOpDsDevInfoModValue );
       
   113     }
       
   114 
       
   115 //-----------------------------------------------------------------------------
       
   116 // CNSmlDSOperatorSettings:::CustomManValueLC
       
   117 // Man value of Operator specific profile.
       
   118 //-----------------------------------------------------------------------------
       
   119 EXPORT_C HBufC8* CNSmlDSOperatorSettings::CustomManValueLC()
       
   120     {
       
   121     return GetValueLC( KNsmlOpDsDevInfoManValue );
       
   122     }
       
   123 
       
   124 //-----------------------------------------------------------------------------
       
   125 // CNSmlDSOperatorSettings:::PopulateStatusCodeListL
       
   126 // Populates server status code list
       
   127 //----------------------------------------------------------------------------
       
   128 EXPORT_C void CNSmlDSOperatorSettings::PopulateStatusCodeListL( 
       
   129     RArray< TInt >& aArray )
       
   130     {
       
   131     InitializeServerStatusCodeListL( aArray );
       
   132     }
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CNSmlDSOperatorSettings::InitializeServerStatusCodeListL
       
   136 // This function reads list of configured server status codes from cenrep
       
   137 // ----------------------------------------------------------------------------
       
   138 void CNSmlDSOperatorSettings::InitializeServerStatusCodeListL( 
       
   139     RArray< TInt >& aArray )
       
   140     {    
       
   141     TBuf< KBufferLength > tempStr;
       
   142     iRepository->Get( KNsmlOpDsSyncMLStatusCodeList, tempStr );
       
   143     TInt commaPos = KErrNotFound;
       
   144 
       
   145     while ( ( commaPos = tempStr.Locate( ',' ) ) > KErrNotFound )
       
   146         {
       
   147         tempStr.Replace( commaPos, 1, KSpace );
       
   148         }
       
   149 
       
   150     TLex lex( tempStr );
       
   151     while( !lex.Eos() )
       
   152         {
       
   153         TPtrC token = lex.NextToken();
       
   154         TLex temp( token );
       
   155         TInt val;
       
   156         temp.Val( val );      
       
   157         aArray.Append( val );
       
   158         }
       
   159     }
       
   160 
       
   161 //-----------------------------------------------------------------------------
       
   162 // CNSmlDSOperatorSettings:::SyncErrorReportingEnabled
       
   163 // Returns ETrue if SyncML Error Reporting is enabled
       
   164 //----------------------------------------------------------------------------
       
   165 EXPORT_C TBool CNSmlDSOperatorSettings::SyncErrorReportingEnabled() 
       
   166     {
       
   167     TBool errorReportingEnabled = EFalse;
       
   168     iRepository->Get( KNsmlOpDsSyncMLErrorReporting, errorReportingEnabled );
       
   169     return errorReportingEnabled;
       
   170     }
       
   171 
       
   172 //-----------------------------------------------------------------------------
       
   173 // CNSmlDSOperatorSettings:::HttpErrorReportingEnabled
       
   174 // Returns ETrue if HTTP Error Reporting is enabled
       
   175 //----------------------------------------------------------------------------
       
   176 EXPORT_C TBool CNSmlDSOperatorSettings::HttpErrorReportingEnabled() 
       
   177     {
       
   178     TBool errorReportingEnabled = EFalse;
       
   179     iRepository->Get( KNsmlOpDsHttpErrorReporting, errorReportingEnabled );
       
   180     return errorReportingEnabled;
       
   181     }
       
   182 
       
   183 // ----------------------------------------------------------------------------
       
   184 // CNSmlDSOperatorSettings::GetValueLC
       
   185 // This function Get Repository key value of Operator specific profile.
       
   186 // ----------------------------------------------------------------------------
       
   187 HBufC8* CNSmlDSOperatorSettings::GetValueLC( const TUint32 aKey )
       
   188     {
       
   189     HBufC8* buf = HBufC8::NewLC( KValueLength );
       
   190     TPtr8 ptr = buf->Des();
       
   191 
       
   192     TInt actualLength;
       
   193     TInt err = iRepository->Get( aKey, ptr, actualLength );
       
   194     if( err == KErrOverflow )
       
   195         {
       
   196         CleanupStack::Pop( buf );
       
   197         buf = buf->ReAllocL( actualLength );
       
   198         CleanupStack::PushL( buf );
       
   199         ptr.Set( buf->Des() );
       
   200         // ignore return error
       
   201         iRepository->Get( aKey, ptr );
       
   202         }
       
   203     return buf;
       
   204     }
       
   205 //  End of File