idlefw/plugins/wsplugin/src/keypadsettings.cpp
branchRCL_3
changeset 9 d0529222e3f0
parent 4 1a2a00e78665
child 10 5ef93ea513cb
child 18 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 9:d0529222e3f0
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Keypad settings implmentation for Active Idle WS Plug-in.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "keypadsettings.h"
       
    20 
       
    21 #include <e32keys.h>
       
    22 #include <e32event.h>
       
    23 #include <centralrepository.h>
       
    24 
       
    25 #include <activeidle2domaincrkeys.h>
       
    26 
       
    27 #include "debug.h"
       
    28 
       
    29 namespace AiWsPlugin {
       
    30 
       
    31 
       
    32 /**
       
    33  * Maps selected numeric keypad scan codes to character.
       
    34  *
       
    35  * @param aScanCode scan code for which to find a character mapping.
       
    36  * @return character mapping for aScanCode or -1 if no mapping is found.
       
    37  */
       
    38 TInt16 TKeypadSettings::MapNkpScanCodeToChar( TInt aScanCode )
       
    39     {
       
    40     TInt16 result;
       
    41     switch( aScanCode )
       
    42         {
       
    43         case EStdKeyHash:        result = '#'; break;
       
    44         case EStdKeyMinus:       result = '-'; break;
       
    45         case EStdKeyNkpAsterisk: result = '*'; break;
       
    46         case EStdKeyNkpMinus:    result = '-'; break;
       
    47         case EStdKeyNkpPlus:     result = '+'; break;
       
    48         case EStdKeyNkp1:        result = '1'; break;
       
    49         case EStdKeyNkp2:        result = '2'; break;
       
    50         case EStdKeyNkp3:        result = '3'; break;
       
    51         case EStdKeyNkp4:        result = '4'; break;
       
    52         case EStdKeyNkp5:        result = '5'; break;
       
    53         case EStdKeyNkp6:        result = '6'; break;
       
    54         case EStdKeyNkp7:        result = '7'; break;
       
    55         case EStdKeyNkp8:        result = '8'; break;
       
    56         case EStdKeyNkp9:        result = '9'; break;
       
    57         case EStdKeyNkp0:        result = '0'; break;
       
    58         default:                 result =  -1; break;
       
    59         }
       
    60     return result;
       
    61     }
       
    62 
       
    63 void TKeypadSettings::ReadFromRepositoryL()
       
    64     {
       
    65     CRepository* repository = CRepository::NewLC( TUid::Uid( KCRUidActiveIdleLV ) );
       
    66     TInt value;
       
    67     
       
    68     // KAIFirstKeyLockKey
       
    69     User::LeaveIfError( repository->Get( KAIFirstKeyLockKey,  value ) );
       
    70     iFirstLockKeyScanCode = TInt16( value );
       
    71     iFirstLockKeyChar = MapNkpScanCodeToChar( value );
       
    72     __PRINT( 
       
    73         __DBG_FORMAT("AiWsPlugin: KAIFirstKeyLockKey = %d, ch=%d"), 
       
    74         TInt(iFirstLockKeyScanCode), TInt(iFirstLockKeyChar) );
       
    75     
       
    76     // KAISecondKeyLockKey
       
    77 	User::LeaveIfError( repository->Get( KAISecondKeyLockKey, value ) );
       
    78 	iSecondLockKeyScanCode = TInt16( value );
       
    79 	iSecondLockKeyChar = MapNkpScanCodeToChar( value );
       
    80     __PRINT( 
       
    81         __DBG_FORMAT("AiWsPlugin: KAISecondKeyLockKey = %d, ch=%d"), 
       
    82         TInt(iSecondLockKeyScanCode), TInt(iSecondLockKeyChar) );
       
    83     
       
    84     // KAISecondKeyLockKey2
       
    85 	User::LeaveIfError( repository->Get( KAISecondKeyLockKey2, value ) );
       
    86 	iSecondLockKeyScanCode2 = TInt16( value );
       
    87 	iSecondLockKeyChar2 = MapNkpScanCodeToChar( value );
       
    88     __PRINT( 
       
    89         __DBG_FORMAT("AiWsPlugin: KAISecondKeyLockKey2 = %d, ch=%d"), 
       
    90         TInt(iSecondLockKeyScanCode2), TInt(iSecondLockKeyChar2) );
       
    91 
       
    92     // KAIKeyLockTimeout    
       
    93 	User::LeaveIfError( repository->Get( KAIKeyLockTimeout, value ) );
       
    94     __PRINT( __DBG_FORMAT("AiWsPlugin: KAIKeyLockTimeout=%d ms"), value );
       
    95 	// Convert timeout from milliseconds to microseconds
       
    96     const TInt KUsInMs = 1000;
       
    97     iKeylockTimeout = KUsInMs * value;
       
    98     
       
    99     // KAISINDKey
       
   100 	User::LeaveIfError( repository->Get( KAIVoiceDialLaunchKey, value ) );
       
   101 	iSINDKeyScanCode = TInt16( value );
       
   102 	iSINDKeyScanChar = MapNkpScanCodeToChar( value );
       
   103     __PRINT( 
       
   104         __DBG_FORMAT("AiWsPlugin: iSINDKey = %d, ch=%d"), 
       
   105         TInt(iSINDKeyScanCode), TInt(iSINDKeyScanChar) );
       
   106 
       
   107     // KAISINDKeyTimeout    
       
   108 	User::LeaveIfError( repository->Get( KAIVoiceDialKeyTimeout, value ) );
       
   109     __PRINT( __DBG_FORMAT("AiWsPlugin: KAISINDKeyTimeout=%d ms"), value );
       
   110 	// Convert timeout from milliseconds to microseconds
       
   111     iKeySINDTimeout = KUsInMs * value;
       
   112 	
       
   113 	CleanupStack::PopAndDestroy( repository );
       
   114     }
       
   115 
       
   116 TBool TKeypadSettings::IsFirstLockKey( TInt aScanCode ) const
       
   117     {
       
   118     return ( aScanCode == iFirstLockKeyScanCode || aScanCode == iFirstLockKeyChar );
       
   119     }
       
   120     
       
   121 TBool TKeypadSettings::IsSecondLockKey( TInt aScanCode ) const
       
   122     {
       
   123     return (
       
   124         ( aScanCode == iSecondLockKeyScanCode || aScanCode == iSecondLockKeyChar ) ||
       
   125         ( aScanCode == iSecondLockKeyScanCode2 || aScanCode == iSecondLockKeyChar2 ) );
       
   126     }
       
   127 
       
   128 TTimeIntervalMicroSeconds32 TKeypadSettings::KeylockTimeout() const
       
   129     {
       
   130     return iKeylockTimeout;
       
   131     }
       
   132 
       
   133 } // namespace AiWsPlugin