securitydialogs/lockapp/src/lockappbasecontrol.cpp
branchRCL_3
changeset 21 09b1ac925e3f
parent 20 63339781d179
child 22 03674e5abf46
equal deleted inserted replaced
20:63339781d179 21:09b1ac925e3f
     1 /*
       
     2 * Copyright (c) 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:  Base control for logical UI components
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "lockappbasecontrol.h"
       
    20 #include "lockappkeycapturecontroller.h"
       
    21 #include "lockapputils.h"
       
    22 
       
    23 #include <eikenv.h>
       
    24 #include <eikbtgpc.h>
       
    25 #include <aknnotedialog.h>
       
    26 #include <AknSmallIndicator.h> // CAknSmallIndicator
       
    27 #include <AknUtils.h>
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Constructor.
       
    31 // ---------------------------------------------------------------------------
       
    32 CLockAppBaseControl::CLockAppBaseControl( MLockAppStateControl& aStateControl ) :
       
    33     iStateControl(aStateControl), iWindowGroup( iEikonEnv->RootWin())
       
    34     {
       
    35 	INFO_4( "%s %s (%u) 1=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // Second phase constructor.
       
    40 // ---------------------------------------------------------------------------
       
    41 void CLockAppBaseControl::ConstructL( )
       
    42     {
       
    43 	INFO_4( "%s %s (%u) 1=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, 1 );
       
    44     iKeyPattern = CLockAppKeyPattern::NewL( );
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // Destructor.
       
    49 // ---------------------------------------------------------------------------
       
    50 CLockAppBaseControl::~CLockAppBaseControl( )
       
    51     {
       
    52     CancelNote( );
       
    53     if ( iActive )
       
    54         {
       
    55         TRAP_IGNORE(HandleDeActivateEventL( NULL ));
       
    56         }
       
    57     delete iCba;
       
    58     delete iKeyPattern;
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Setup key pattern matcher.
       
    63 // ---------------------------------------------------------------------------
       
    64 TBool CLockAppBaseControl::SetupKeyPatternsWithPolicyL( TLockPolicyType aType )
       
    65     {
       
    66     INFO_1( "CLockAppBaseControl::SetupKeyPatternsL( type=%d )", aType );
       
    67     TBool ret(EFalse);
       
    68     __ASSERT_DEBUG( iKeyPattern, DoPanic(ELockIllegalState));
       
    69     if ( iKeyPattern )
       
    70         {
       
    71         CKeyLockPolicyApi* keylockPolicy = CKeyLockPolicyApi::NewL( aType );
       
    72                 
       
    73         // if the keylockpolicy has keycombinations
       
    74         if ( keylockPolicy->HasConfiguration( ) )
       
    75             {
       
    76             // TESTING1!
       
    77             INFO( "CLockAppBaseControl::SetupKeyPatternsWithPolicyL - HasConfiguration!" );
       
    78             
       
    79             TUint32 index(0), k1(0), k2(0);
       
    80             while ( keylockPolicy->GetKeyCombination( index, k1, k2 )== KErrNone )
       
    81                 {
       
    82                 // TESTING2!
       
    83                 INFO( "CLockAppBaseControl::SetupKeyPatternsWithPolicyL - key combination found!" );
       
    84                 
       
    85                 // add each combination to our pattern matcher
       
    86                 iKeyPattern->AddPattern( k1, k2 );
       
    87                 index++;
       
    88                 }
       
    89                         
       
    90             ret = ETrue;
       
    91             INFO_1( "CLockAppBaseControl::SetupKeyPatternsL: added %d patterns", index );
       
    92             }
       
    93         delete keylockPolicy;
       
    94         }
       
    95     return ret;
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Show note
       
   100 // ---------------------------------------------------------------------------
       
   101 void CLockAppBaseControl::ShowNote( CLockAppLockedNote* aNote, const TInt aTimeout,
       
   102         const CAknNoteDialog::TTone aTone )
       
   103     {
       
   104     if ( aNote )
       
   105         {
       
   106         // cancel the current note if any
       
   107         if ( iCurrentNote != aNote )
       
   108             {
       
   109             CancelNote( );
       
   110             iCurrentNote = aNote;
       
   111             }
       
   112         iCurrentNote->ShowNote( aTimeout, aTone );
       
   113         }
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // Cancel currently shown note
       
   118 // ---------------------------------------------------------------------------
       
   119 void CLockAppBaseControl::CancelNote( )
       
   120     {
       
   121     if ( iCurrentNote )
       
   122         {
       
   123         if ( iCurrentNote->IsVisible( ) )
       
   124             {
       
   125             iCurrentNote->CancelNote( );
       
   126             }
       
   127         iCurrentNote = NULL;
       
   128         }
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // Internal lock state has been changed.
       
   133 // ---------------------------------------------------------------------------
       
   134 void CLockAppBaseControl::HandleLockStatusChangedL( TLockStatus aStatus )
       
   135     {
       
   136     switch ( aStatus )
       
   137         {
       
   138         case ELockNotActive:
       
   139             break;
       
   140         case EKeyguardActive:
       
   141             break;
       
   142         case EDevicelockActive:
       
   143             break;
       
   144         default:
       
   145             DoPanic( ELockPanicGeneral );
       
   146             break;
       
   147         }
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // Handle activate event
       
   152 // ---------------------------------------------------------------------------
       
   153 void CLockAppBaseControl::HandleActivateEventL( TUint /*aEnvMask*/ )
       
   154     {
       
   155     __ASSERT_DEBUG( !iActive, DoPanic(ELockIllegalState));
       
   156     if ( !iActive )
       
   157         {
       
   158         iActive = ETrue;
       
   159         }
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // Handle de-activate event
       
   164 // ---------------------------------------------------------------------------
       
   165 void CLockAppBaseControl::HandleDeActivateEventL( TUint /*aEnvMask*/ )
       
   166     {
       
   167     __ASSERT_DEBUG( iActive, DoPanic(ELockIllegalState));
       
   168     if ( iActive )
       
   169         {
       
   170         iActive = EFalse;
       
   171         }
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // Capture/uncapture primary keys
       
   176 // ---------------------------------------------------------------------------
       
   177 void CLockAppBaseControl::CapturePrimaryKeys( const TBool aCapture )
       
   178     {   
       
   179     	INFO_4( "%s %s (%u) aCapture=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, aCapture );
       
   180     	INFO_4( "%s %s (%u) iKeyPattern=%x", __FILE__, __PRETTY_FUNCTION__, __LINE__, iKeyPattern );
       
   181     if ( iKeyPattern )
       
   182         {
       
   183         if ( aCapture )
       
   184             {
       
   185             // capture primary keys
       
   186             TUint32 index( 0), primaryKey( 0), secondaryKey( 0);
       
   187             while (iKeyPattern->GetPattern( index, primaryKey, secondaryKey )== KErrNone )
       
   188                 {
       
   189                 CLockAppKeyCaptureController::CaptureKey( primaryKey, 0, EKeyCaptureUpAndDownEvents );
       
   190                 index++;
       
   191                 }
       
   192             }
       
   193         else
       
   194             {
       
   195             // uncapture primary keys
       
   196             TUint32 index( 0), primaryKey( 0), secondaryKey( 0);
       
   197             while (iKeyPattern->GetPattern( index, primaryKey, secondaryKey )== KErrNone )
       
   198                 {
       
   199                 CLockAppKeyCaptureController::ReleaseKey( primaryKey );
       
   200                 index++;
       
   201                 }
       
   202             }
       
   203         }
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // Bring keyguard cba forwards/backwards.
       
   208 // ---------------------------------------------------------------------------
       
   209 void CLockAppBaseControl::ShowCba( const TBool aShow )
       
   210     {
       
   211     if ( iCba )
       
   212         {
       
   213         RDrawableWindow* cbaWindow = iCba->ButtonGroup()->AsControl()->DrawableWindow( );
       
   214         if ( aShow )
       
   215             {
       
   216             cbaWindow->SetNonFading( ETrue );
       
   217             cbaWindow->SetOrdinalPosition( 0 );
       
   218             iCba->MakeVisible( ETrue );
       
   219             }
       
   220         else
       
   221             {
       
   222             // hide the window
       
   223             iCba->MakeVisible( EFalse );
       
   224             }
       
   225         }
       
   226     }
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // Method used for capturing/releasing pointer events when key lock is enabled.
       
   230 // Capturing is done using button/cba group window.
       
   231 // ---------------------------------------------------------------------------
       
   232 void CLockAppBaseControl::SetPointerEventCapture(const TBool aEnable )
       
   233     {
       
   234 #ifdef RD_SCALABLE_UI_V2
       
   235     if ( AknLayoutUtils::PenEnabled( )&& iCba )
       
   236         {
       
   237         // cba captures all pointer events
       
   238         RDrawableWindow* cbaWindow = iCba->ButtonGroup()->AsControl()->DrawableWindow( );
       
   239         if ( aEnable )
       
   240             {
       
   241             cbaWindow->SetPointerCapture( RWindowBase::TCaptureDragDrop );
       
   242             }
       
   243         else
       
   244             {
       
   245             cbaWindow->SetPointerCapture( RWindowBase::TCaptureDisabled );
       
   246             }
       
   247         cbaWindow->ClaimPointerGrab( aEnable );
       
   248         }
       
   249 #endif // RD_SCALABLE_UI_V2
       
   250     }
       
   251 
       
   252 // ---------------------------------------------------------------------------
       
   253 // Set Keyguard indicator on Idle.
       
   254 // ---------------------------------------------------------------------------
       
   255 void CLockAppBaseControl::SetKeyguardIndicatorStateL( const TBool aEnable )
       
   256     {
       
   257     CAknSmallIndicator* theIndicator = CAknSmallIndicator::NewLC( TUid::Uid( EAknIndicatorKeyguard ) );
       
   258     if ( aEnable )
       
   259         {
       
   260         theIndicator->SetIndicatorStateL( EAknIndicatorStateOn );
       
   261         }
       
   262     else
       
   263         {
       
   264         theIndicator->SetIndicatorStateL( EAknIndicatorStateOff );
       
   265         }
       
   266     CleanupStack::PopAndDestroy( theIndicator );
       
   267     }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // Handle environment changes (Screensaver, Telephony, etc.)
       
   271 // ---------------------------------------------------------------------------
       
   272 void CLockAppBaseControl::HandleEnvironmentChange( TUint /*aEnvMask*/, TUint /*aEventMask*/ )
       
   273     {
       
   274     // no implementation needed - virtual function
       
   275     }
       
   276 
       
   277 // END OF FILE