voiceui/voiceuivoicerecognition/src/vuickeygrabber.cpp
branchRCL_3
changeset 18 cad71a31b7fc
parent 17 8ce15fced3a6
child 19 e36f3802f733
equal deleted inserted replaced
17:8ce15fced3a6 18:cad71a31b7fc
     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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <eikon.hrh>
       
    22 #include <apgwgnam.h>
       
    23 
       
    24 #include "vuickeygrabber.h"
       
    25 
       
    26 #include "vuimkeycallback.h"
       
    27 
       
    28 #include "rubydebug.h"
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CKeyGrabber::NewL
       
    32 // Two-phased constructor.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CKeyGrabber* CKeyGrabber::NewL( MKeyCallback* aKeyObserver )
       
    36     {
       
    37     CKeyGrabber* self = new (ELeave) CKeyGrabber( aKeyObserver );
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }   
       
    43     
       
    44 // ---------------------------------------------------------
       
    45 // CKeyGrabber::~CKeyGrabber
       
    46 // ---------------------------------------------------------
       
    47 //       
       
    48 CKeyGrabber::~CKeyGrabber()
       
    49     {
       
    50     Cancel();
       
    51 
       
    52     iWindowGroup.Close();
       
    53     
       
    54     iWsSession.Close();
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // CKeyGrabber::DoCancel
       
    59 // ---------------------------------------------------------
       
    60 // 
       
    61 void CKeyGrabber::DoCancel()
       
    62     {
       
    63     RUBY_DEBUG0( "CKeyGrabber::DoCancel START" );
       
    64     
       
    65     iWsSession.EventReadyCancel();
       
    66     
       
    67     iWindowGroup.CancelCaptureKey( iCameraHandle );
       
    68     iWindowGroup.CancelCaptureKey( iPocHandle );
       
    69     iWindowGroup.CancelCaptureKey( iPowerHandle );
       
    70     iWindowGroup.CancelCaptureKey( iApplicationHandle );
       
    71     
       
    72     RUBY_DEBUG0( "CKeyGrabber::DoCancel EXIT" );
       
    73     }
       
    74 
       
    75 // ---------------------------------------------------------
       
    76 // CKeyGrabber::RunL
       
    77 // ---------------------------------------------------------
       
    78 //     
       
    79 void CKeyGrabber::RunL()
       
    80     {
       
    81     RUBY_DEBUG_BLOCK( "CKeyGrabber::RunL" );
       
    82     
       
    83     if ( iStatus.Int() == KErrNone )
       
    84         {
       
    85         TWsEvent event;
       
    86         iWsSession.GetEvent( event );
       
    87         
       
    88         iWsSession.EventReady( &iStatus );
       
    89         SetActive();
       
    90         
       
    91         //fix for ESLI-7YSA3 we terminate Vcommand when received EKeyNull.
       
    92         if ( event.Key()->iCode == EKeyNull )
       
    93         	iKeyObserver->HandleKeypressL( event.Key()->iCode );
       
    94         if ( event.Key()->iCode == EKeyCamera ||
       
    95              event.Key()->iCode == EKeyPoC ||
       
    96              event.Key()->iCode == EKeyPowerOff ||
       
    97              event.Key()->iCode == EKeyApplication )
       
    98             {
       
    99             iWsSession.SendEventToOneWindowGroupsPerClient( event );
       
   100 
       
   101             iKeyObserver->HandleKeypressL( event.Key()->iCode );
       
   102             }
       
   103         }
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------
       
   107 // CKeyGrabber::CKeyGrabber
       
   108 // ---------------------------------------------------------
       
   109 //              
       
   110 CKeyGrabber::CKeyGrabber( MKeyCallback* aKeyObserver )
       
   111  : CActive( EPriorityStandard ), iKeyObserver( aKeyObserver )
       
   112     {
       
   113     }
       
   114     
       
   115 // ---------------------------------------------------------
       
   116 // CKeyGrabber::ConstructL
       
   117 // ---------------------------------------------------------
       
   118 //           
       
   119 void CKeyGrabber::ConstructL()
       
   120     {
       
   121     RUBY_DEBUG_BLOCK( "CKeyGrabber::ConstructL" );
       
   122 
       
   123     User::LeaveIfError( iWsSession.Connect() );
       
   124 
       
   125     iWindowGroup = RWindowGroup ( iWsSession );
       
   126     iWindowGroup.Construct( (TUint32) &iWindowGroup, EFalse );
       
   127     
       
   128     User::LeaveIfError( iCameraHandle = iWindowGroup.CaptureKey( EKeyCamera, 0, 0 ) );
       
   129     User::LeaveIfError( iPocHandle = iWindowGroup.CaptureKey( EKeyPoC, 0, 0 ) );
       
   130     User::LeaveIfError( iPowerHandle = iWindowGroup.CaptureKey( EKeyPowerOff, 0, 0 ) );
       
   131     User::LeaveIfError( iApplicationHandle = iWindowGroup.CaptureKey( EKeyApplication, 0, 0 ) );
       
   132     
       
   133     iWindowGroup.SetOrdinalPosition( -1 );
       
   134     iWindowGroup.EnableReceiptOfFocus( EFalse );
       
   135     
       
   136     CApaWindowGroupName* name = CApaWindowGroupName::NewLC( iWsSession );
       
   137     name->SetHidden( ETrue );
       
   138     name->SetWindowGroupName( iWindowGroup );
       
   139     CleanupStack::PopAndDestroy( name );
       
   140 
       
   141     iWsSession.EventReady( &iStatus );
       
   142     
       
   143     CActiveScheduler::Add( this );
       
   144     SetActive();
       
   145     }
       
   146 
       
   147     
       
   148 // End of File
       
   149