profilesservices/ProfileEngine/EngSrc/ProfileEngUtils.cpp
changeset 0 8c5d936e5675
child 8 f62c3a3d66b8
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:  Implemention of the ProfileEngUtils.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "ProfileEngUtils.h"
       
    22 #include "CProfileEngineImpl.h"
       
    23 #include "ProfileEngineConstants.h"
       
    24 #include <RSSSettings.h>
       
    25 #include <centralrepository.h>
       
    26 #include <bldvariant.hrh>
       
    27 
       
    28 #include <psmsrvdomaincrkeys.h>
       
    29 #include <psmsettings.h>
       
    30 #include <e32property.h>
       
    31 #include <ProfileEnginePrivatePSKeys.h>
       
    32 
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // ProfileEngUtils::GetAlternateService
       
    38 //
       
    39 // (other items were commented in a header).
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 void ProfileEngUtils::GetAlternateLineService( TInt& aValue )
       
    43     {
       
    44     aValue = ESSSettingsAlsNotSupported;
       
    45     RSSSettings settings;
       
    46 
       
    47     if( settings.Open() == KErrNone )
       
    48         {
       
    49         // Get Alternate Line Service setting. Ignore errors because
       
    50         // iAlternateLineService value ESSSettingsAlsNotSupported is also valid.
       
    51         settings.Get( ESSSettingsAls, aValue );
       
    52         settings.Close();
       
    53         }
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // ProfileEngUtils::IsAlternateLineSelected
       
    58 //
       
    59 // (other items were commented in a header).
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 TBool ProfileEngUtils::IsAlternateLineSelected()
       
    63     {
       
    64     TInt als( ESSSettingsAlsNotSupported );
       
    65     GetAlternateLineService( als );
       
    66     return ( als == ESSSettingsAlsAlternate );
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // ProfileEngUtils::ResolveKey
       
    71 //
       
    72 // (other items were commented in a header).
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 TUint32 ProfileEngUtils::ResolveKey( TUint aPartialKey, TInt aProfileId )
       
    76     {
       
    77     return ( ( aProfileId << KProfileIdShift ) | aPartialKey );
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // ProfileEngUtils::GetBinarySettingL
       
    82 //
       
    83 // (other items were commented in a header).
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void ProfileEngUtils::GetBinarySettingL( CRepository& aCenRep,
       
    87                                          TUint32 aId,
       
    88                                          TDes8& aDes )
       
    89     {
       
    90     aDes.Zero();
       
    91     User::LeaveIfError( aCenRep.Get( aId, aDes ) );
       
    92     const TInt KProEngEmptyBinSettingLength( 2 );
       
    93     const TInt KProEngZero( 0 );
       
    94 
       
    95     if( ( aDes.Length() == KProEngEmptyBinSettingLength ) &&
       
    96         ( aDes[0] == KProEngZero && aDes[1] == KProEngZero ) )
       
    97         {
       
    98             aDes.Zero();
       
    99         }
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // ProfileEngUtils::FindValueFromBinaryKey
       
   104 //
       
   105 // (other items were commented in a header).
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 TInt ProfileEngUtils::FindValueFromBinaryKeyL( CRepository& aCenRep,
       
   109         TUint32 aCenRepKey,
       
   110         TUint8 aValue )
       
   111     {
       
   112     HBufC8* buf = HBufC8::NewLC(
       
   113             NCentralRepositoryConstants::KMaxBinaryLength );
       
   114     TPtr8 ptr = buf->Des();
       
   115     ProfileEngUtils::GetBinarySettingL( aCenRep, aCenRepKey, ptr );
       
   116 
       
   117     TInt result( KErrNotFound );
       
   118     TInt len( buf->Length() );
       
   119     for( TInt i( 0 ); i<len; ++i )
       
   120         {
       
   121         if( ptr[ i ] == aValue )
       
   122             {
       
   123             result = i;
       
   124             }
       
   125         }
       
   126     CleanupStack::PopAndDestroy(); // buf
       
   127     return result;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // ProfileEngUtils::GetUint32Presentation
       
   132 //
       
   133 // (other items were commented in a header).
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void ProfileEngUtils::GetUint32Presentation( TUint32& aResult,
       
   137                                              const TDesC8& aBuf,
       
   138                                              TInt aOffset )
       
   139     {
       
   140     aResult = 0;
       
   141     const TInt KProEngByteLength( 8 );
       
   142     const TInt length( aBuf.Length() );
       
   143     const TInt maxBitShift( KProEngByteLength * ( length - 1 ) );
       
   144 
       
   145     for( TInt i( 0 ); i<length; ++i )
       
   146         {
       
   147         aResult |= ( aBuf[aOffset + i] <<
       
   148                    ( maxBitShift - ( KProEngByteLength * i ) ) );
       
   149         }
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // ProfileEngUtils::PowerSaveMode
       
   154 //
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 TBool ProfileEngUtils::PowerSaveMode()
       
   158     {
       
   159     TBool psm = EFalse;
       
   160     
       
   161     TRAPD( err, psm = PowerSaveModeL() );
       
   162     
       
   163     if ( err != KErrNone )
       
   164         {
       
   165         return EFalse;
       
   166         }
       
   167         
       
   168     return psm;
       
   169     }
       
   170 
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // ProfileEngUtils::PowerSaveModeL
       
   174 //
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 TBool ProfileEngUtils::PowerSaveModeL()
       
   178     {
       
   179 
       
   180 #ifdef FF_POWER_SAVE
       
   181     TInt psm = EPsmsrvModeNormal;
       
   182     
       
   183     // KProEngPsmChanged PubSub key is set by GSProfilesPlugin when power save
       
   184     // mode changes. If the key cannot be read (doesn't exist), PSM hasn't
       
   185     // changed since the last boot and the mode is read from PSM CenRep.
       
   186     if( RProperty::Get( KPSUidProfileEngine, KProEngPsmChanged, psm ) != KErrNone )
       
   187         {
       
   188         CRepository* cenrep = CRepository::NewLC( KCRUidPowerSaveMode );
       
   189         User::LeaveIfError( cenrep->Get( KPsmCurrentMode, psm ) );
       
   190         CleanupStack::PopAndDestroy( cenrep );
       
   191         }
       
   192 
       
   193     if ( psm == EPsmsrvModePowerSave )
       
   194         {
       
   195         return ETrue;
       
   196         }
       
   197 #endif
       
   198 
       
   199     return EFalse;
       
   200     }
       
   201 
       
   202 
       
   203 //  End of File