idlefw/plugins/wsplugin/src/keylockhandler.cpp
branchRCL_3
changeset 8 d0529222e3f0
parent 4 1a2a00e78665
child 11 bd874ee5e5e2
equal deleted inserted replaced
4:1a2a00e78665 8: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:  Keylock handler implementation for Active Idle WS Plug-in
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "keylockhandler.h"
       
    20 #include "keyhandlertimer.h"
       
    21 #include "keylockstates.h"
       
    22 #include "aiwspluginanimdef.h"
       
    23 #include "uistate.h"
       
    24 
       
    25 #include <e32property.h>
       
    26 #include <activeidle2internalpskeys.h>
       
    27 #include <keylockpolicyapi.h>
       
    28 
       
    29 #include "debug.h"
       
    30 
       
    31 namespace AiWsPlugin {
       
    32 
       
    33 CKeyLockHandler::CKeyLockHandler() :
       
    34     // Initialize to start-up state
       
    35     iCurrentState( &TKeylockState::StartupState() ),
       
    36     iNextState( &iCurrentState->iDefaultNextState() )
       
    37     {
       
    38     }
       
    39     
       
    40 void CKeyLockHandler::ConstructL()
       
    41     {
       
    42     // Read capability: ReadDeviceData.
       
    43     _LIT_SECURITY_POLICY_C1( KReadDevicePolicy, ECapabilityReadDeviceData );
       
    44     // Write capability: WriteDeviceData.
       
    45     _LIT_SECURITY_POLICY_C1( KWriteDevicePolicy, ECapabilityWriteDeviceData );
       
    46 
       
    47     // Initialize Shortcut Plug-in command API
       
    48     RProperty::Define( 
       
    49     	KUidSystemCategory,
       
    50     	KPSUidShortcutCmd,  
       
    51       	RProperty::EText,
       
    52         KReadDevicePolicy,
       
    53         KWriteDevicePolicy 
       
    54         );
       
    55 
       
    56     iSettings.ReadFromRepositoryL();    
       
    57     iKeypadLockTimer = CPeriodic::NewL( CActive::EPriorityUserInput );
       
    58     iKeylockApi = CKeyLockPolicyApi::NewL( EPolicyActivateKeyguard );
       
    59     if ( !iKeylockApi->HasConfiguration() )
       
    60         {
       
    61         delete iKeylockApi;
       
    62         iKeylockApi = NULL;
       
    63         }
       
    64     }
       
    65 
       
    66 CKeyLockHandler* CKeyLockHandler::NewLC()
       
    67     {
       
    68     CKeyLockHandler* self = new( ELeave ) CKeyLockHandler;
       
    69     CleanupStack::PushL( self );
       
    70     self->ConstructL();
       
    71     return self;
       
    72     }
       
    73 
       
    74 CKeyLockHandler::~CKeyLockHandler()
       
    75     {
       
    76     delete iKeypadLockTimer;
       
    77     delete iKeylockApi;
       
    78     }
       
    79 
       
    80 void CKeyLockHandler::SetUiStateQuery( MUiState& aUiState )
       
    81     {
       
    82     iUiState = &aUiState;
       
    83     }
       
    84 
       
    85 TBool CKeyLockHandler::HasFocus()
       
    86     {
       
    87     return iUiState->HasFocus();
       
    88     }
       
    89     
       
    90 TBool CKeyLockHandler::TimeoutTimerActive()
       
    91     {
       
    92     return iKeypadLockTimer->IsActive();
       
    93     }
       
    94 
       
    95 void CKeyLockHandler::FocusChanged( TBool aState )
       
    96     {
       
    97     iCurrentState->FocusChanged( *this, aState );
       
    98     }
       
    99     
       
   100 TBool CKeyLockHandler::OfferRawEvent(const TRawEvent& aRawEvent)
       
   101     {
       
   102     return iCurrentState->OfferRawEvent( *this, aRawEvent );    
       
   103     }
       
   104 
       
   105 TBool CKeyLockHandler::IsFirstLockKey( TInt aScanCode )
       
   106     {  
       
   107     if ( iKeylockApi )
       
   108         {
       
   109         TKeyEvent event;
       
   110         event.iModifiers = 0;
       
   111         event.iCode = 0;
       
   112         event.iRepeats = 0;
       
   113         event.iScanCode = aScanCode;
       
   114         // Keylock API return ETrue on handlekeyeventL only if the whole key
       
   115         // sequence has been inputted (1st + 2nd key pressed)
       
   116         TRAP_IGNORE(iKeylockApi->HandleKeyEventL( event,EEventKeyDown ));
       
   117         return iKeylockApi->PrimaryKeyPressed();
       
   118         }
       
   119     else
       
   120         {
       
   121         return Settings().IsFirstLockKey( aScanCode );
       
   122         }
       
   123     }
       
   124 
       
   125 TBool CKeyLockHandler::IsSecondLockKey( TInt aScanCode )
       
   126     {   
       
   127     TBool returnValue = EFalse;
       
   128     if ( iKeylockApi )
       
   129         {
       
   130         TKeyEvent event;
       
   131         event.iModifiers = 0;
       
   132         event.iCode = 0;
       
   133         event.iRepeats = 0;
       
   134         event.iScanCode = aScanCode;
       
   135         TRAP_IGNORE(returnValue = iKeylockApi->HandleKeyEventL( event,EEventKeyDown ));
       
   136         return returnValue;
       
   137         }
       
   138     else
       
   139         {
       
   140         return Settings().IsSecondLockKey( aScanCode );
       
   141         }
       
   142     }
       
   143 
       
   144 const TKeypadSettings& CKeyLockHandler::Settings() const
       
   145     {
       
   146     return iSettings;
       
   147     }
       
   148 
       
   149 void CKeyLockHandler::StartTimeoutTimer( TInt aTimeout )
       
   150     {
       
   151     __PRINTS( "AiWsPlugin: CKeyLockHandler::StartTimeoutTimer()" );
       
   152     
       
   153     iKeypadLockTimer->Cancel();
       
   154     if( aTimeout < 0 )
       
   155         {
       
   156         iKeypadLockTimer->Start( 
       
   157             iSettings.KeylockTimeout(), iSettings.KeylockTimeout(),
       
   158             TCallBack( &CKeyLockHandler::TimerElapsed, this ) );
       
   159         }
       
   160     else
       
   161         {
       
   162         iKeypadLockTimer->Start( 
       
   163             aTimeout, aTimeout,
       
   164             TCallBack( &CKeyLockHandler::TimerElapsed, this ) );
       
   165         }
       
   166     }
       
   167     
       
   168 void CKeyLockHandler::StopTimeoutTimer()
       
   169     {
       
   170     __PRINTS( "AiWsPlugin: CKeyLockHandler::StopTimeoutTimer()" );
       
   171     iKeypadLockTimer->Cancel();
       
   172     }
       
   173 
       
   174 void CKeyLockHandler::ActivateKeypadLock()
       
   175 	{
       
   176     __PRINTS( "AiWsPlugin: CKeyLockHandler::ActivateKeypadLock()" );
       
   177 	StopTimeoutTimer();
       
   178 	// Use Shortcut Plug-in API to set the keylock
       
   179 	RProperty::Set(
       
   180 		KUidSystemCategory, 
       
   181 	    KPSUidShortcutCmd,
       
   182 	    KAiPSEnableKeyLock );
       
   183     }
       
   184 
       
   185 void CKeyLockHandler::CancelKeypadLock()
       
   186 	{
       
   187     __PRINTS( "AiWsPlugin: CKeyLockHandler::CancelKeypadLock()" );
       
   188 	StopTimeoutTimer();
       
   189 	RProperty::Set(
       
   190 		KUidSystemCategory, 
       
   191 	    KPSUidShortcutCmd,
       
   192 	    KAiPSSkipKeyLock );
       
   193 	} 
       
   194 
       
   195 void CKeyLockHandler::KeypadLockTimeout()
       
   196 	{
       
   197     __PRINTS( "AiWsPlugin: CKeyLockHandler::CancelKeypadLock()" );
       
   198 	StopTimeoutTimer();
       
   199 	RProperty::Set(
       
   200 		KUidSystemCategory, 
       
   201 	    KPSUidShortcutCmd,
       
   202 	    KAiPSKeyLockTimeout );
       
   203 	} 
       
   204 
       
   205 void CKeyLockHandler::SetNextState( const TKeylockState& aState )
       
   206     {
       
   207     iNextState = &aState;
       
   208     }
       
   209 
       
   210 void CKeyLockHandler::ActivateNextState()
       
   211     {
       
   212     iCurrentState = iNextState;
       
   213     iNextState = &(*iCurrentState->iDefaultNextState)();
       
   214     }
       
   215 
       
   216 void CKeyLockHandler::SetLastLockKeyScanCode( TInt aScanCode )
       
   217     {
       
   218     iLastLockKeyScanCode = aScanCode;
       
   219     }
       
   220     
       
   221 TInt CKeyLockHandler::LastLockKeyScanCode() const
       
   222     {
       
   223     return iLastLockKeyScanCode;
       
   224     }
       
   225     
       
   226 TInt CKeyLockHandler::TimerElapsed(TAny* aSelf)
       
   227     {
       
   228     CKeyLockHandler* self = static_cast<CKeyLockHandler*>(aSelf);
       
   229     if( self )
       
   230         {
       
   231         self->iCurrentState->TimerElapsed( *self );
       
   232         }
       
   233     return KErrNone;
       
   234     }
       
   235     
       
   236 void CKeyLockHandler::TimerDone()
       
   237     {
       
   238         
       
   239     }
       
   240 
       
   241 } // namespace AiWsPlugin