idlefw/plugins/wsplugin/src/numerickeyhandler.cpp
branchRCL_3
changeset 30 a5a39a295112
equal deleted inserted replaced
29:0efa10d348c0 30:a5a39a295112
       
     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:  Numeric key forwarding handler implementation for Active Idle 
       
    15 *                WS Plug-in.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include "numerickeyhandler.h"
       
    21 #include "uistate.h"
       
    22 
       
    23 #include <e32property.h>
       
    24 #include <centralrepository.h>
       
    25 #include <w32adll.h>
       
    26 
       
    27 #include <easydialingcrkeys.h>
       
    28 #include <spsettings.h>
       
    29 #include <featmgr.h>
       
    30 
       
    31 #include <PtiEngine.h>
       
    32 #include <activeidle2domainpskeys.h>
       
    33 #include <AvkonInternalCRKeys.h>
       
    34 #include <AknFepInternalCRKeys.h>
       
    35 
       
    36 #include <aiutility.h>
       
    37 #include <aipspropertyobserver.h>
       
    38 
       
    39 namespace AiWsPlugin {
       
    40 
       
    41 
       
    42 CNumericKeyHandler::CNumericKeyHandler
       
    43         ( TInt aTargetWgId, MAnimGeneralFunctionsWindowExtension* aWindowExt ) :
       
    44     iTargetWgId( aTargetWgId ), 
       
    45     iWindowExt( aWindowExt )
       
    46     {
       
    47     }
       
    48     
       
    49 void CNumericKeyHandler::ConstructL()
       
    50     {
       
    51     // Read capability: ReadUserData.
       
    52     _LIT_SECURITY_POLICY_C1( KReadUserPolicy, ECapabilityReadUserData ); 
       
    53     // Write capability: WriteDeviceData.
       
    54     _LIT_SECURITY_POLICY_C1( KWriteDevicePolicy, ECapabilityWriteDeviceData );
       
    55 
       
    56     RProperty::Define( 
       
    57          	KPSUidAiInformation,
       
    58          	KActiveIdleState,
       
    59          	RProperty::EInt,
       
    60             KReadUserPolicy,
       
    61             KWriteDevicePolicy );
       
    62                     
       
    63 	iQwertyObserver = AiUtility::CreatePSPropertyObserverL(
       
    64 			TCallBack( HandleQwertyModeChanged, this ),
       
    65         	KCRUidAvkon, KAknQwertyInputModeActive );
       
    66 	
       
    67 	iInputLanguageRepository = CRepository::NewL( KCRUidAknFep );
       
    68 	iInputLanguageObserver = CCenRepNotifyHandler::NewL(*this, *iInputLanguageRepository);
       
    69 	iInputLanguageObserver->StartListeningL(); 
       
    70 	
       
    71 	RProperty::Get(KCRUidAvkon, KAknQwertyInputModeActive, iQwertyMode);
       
    72 	iInputLanguageRepository->Get( KAknFepInputTxtLang, iInputLanguage );
       
    73           
       
    74     // Load numeric keys mapping for qwerty 
       
    75     if ( iQwertyMode )
       
    76         {
       
    77         LoadInputLanguageKeyBindings( iInputLanguage );            
       
    78         }
       
    79     }
       
    80 
       
    81 CNumericKeyHandler* CNumericKeyHandler::NewLC
       
    82         ( TInt aTargetWgId, MAnimGeneralFunctionsWindowExtension* aWindowExt )
       
    83     {
       
    84     CNumericKeyHandler* self = new(ELeave) CNumericKeyHandler
       
    85         ( aTargetWgId, aWindowExt );
       
    86     CleanupStack::PushL( self );
       
    87     self->ConstructL();
       
    88     return self;
       
    89     }
       
    90     
       
    91 CNumericKeyHandler::~CNumericKeyHandler()
       
    92     {
       
    93     if( iInputLanguageObserver )
       
    94         {
       
    95         iInputLanguageObserver->StopListening();
       
    96         }
       
    97     delete iInputLanguageObserver;
       
    98     delete iInputLanguageRepository;
       
    99     Release(iQwertyObserver);
       
   100     iNumericKeys.Close();
       
   101     }
       
   102 
       
   103 void CNumericKeyHandler::SetUiStateQuery( MUiState& aUiState )
       
   104     {
       
   105     iUiState = &aUiState;
       
   106     }
       
   107 
       
   108 void CNumericKeyHandler::FocusChanged( TBool /*aState*/ )
       
   109     {
       
   110     }
       
   111     
       
   112 TBool CNumericKeyHandler::OfferRawEvent(const TRawEvent& aRawEvent)
       
   113     {
       
   114     switch( aRawEvent.Type() )
       
   115         {
       
   116         case TRawEvent::EKeyDown:
       
   117             {
       
   118             if ( iUiState->HasFocus() && CheckPostToTarget( aRawEvent ) )
       
   119                 {
       
   120                 TInt forwardKeys = EPSAiForwardNumericKeysToPhone;       
       
   121                 
       
   122                 TInt err = RProperty::Get(
       
   123                         KPSUidAiInformation,
       
   124                         KActiveIdleForwardNumericKeysToPhone,
       
   125                         forwardKeys);
       
   126                 // Key event forwarding disabled => Ignore the keys
       
   127                 if ( err == KErrNone && 
       
   128                         forwardKeys == EPSAiDontForwardNumericKeysToPhone )
       
   129                     {
       
   130                     return EFalse;
       
   131                     }
       
   132     			// Phone app is listening this key and knows that next
       
   133                 // focus event from window server is becuase key events
       
   134                 // are coming to it.                        
       
   135                 RProperty::Set(
       
   136                  	KPSUidAiInformation, 
       
   137                     KActiveIdleState,
       
   138                 	EPSAiNumberEntry );
       
   139 
       
   140                 // Switch focus to Phone app
       
   141                 if( iWindowExt )
       
   142                     {
       
   143                     iWindowExt->SetOrdinalPosition( iTargetWgId, 0, 0 );
       
   144                     }
       
   145                 }
       
   146             break;
       
   147             }
       
   148         }
       
   149     
       
   150     // Never consume the key event as we want target application to process it
       
   151     return EFalse;
       
   152     }
       
   153 
       
   154 /**
       
   155  * Returns true if event should be forwarded to Phone app.
       
   156  */
       
   157 TBool CNumericKeyHandler::CheckPostToTarget(const TRawEvent& aRawEvent ) const
       
   158     {
       
   159     const TInt scanCode = aRawEvent.ScanCode();
       
   160     const TUint modifiers = iUiState->Modifiers();
       
   161 
       
   162     if ( iQwertyMode ) 
       
   163         {
       
   164         // Don't pass the check if shift is pressed.		
       
   165         if(( modifiers & EModifierShift ) == 0 )
       
   166             {
       
   167             TInt numericKeysCount = iNumericKeys.Count();
       
   168             while( numericKeysCount-- )
       
   169                 {
       
   170                 TPtiNumericKeyBinding numKeyBind = iNumericKeys[numericKeysCount];
       
   171                 if( numKeyBind.iKey == scanCode )
       
   172                     {
       
   173                     return ETrue;
       
   174                     }
       
   175                 }
       
   176             }
       
   177         }
       
   178     else
       
   179         {
       
   180         // Normal check ignore modifiers
       
   181         static const TInt KIdPlgScanCodes[] = 
       
   182             { '1','2','3','4','5','6','7','8','9','0',
       
   183               '*',EStdKeyNkpAsterisk,EStdKeyHash,EStdKeyNkpPlus };
       
   184         static const TInt KIdPlgScanCodeCount = 
       
   185             sizeof( KIdPlgScanCodes ) / sizeof( KIdPlgScanCodes[0] );
       
   186         TInt count = KIdPlgScanCodeCount;
       
   187         while( count-- )
       
   188             {
       
   189             const TInt refCode = KIdPlgScanCodes[ count ];
       
   190             // Is one of [0,1,2,3,4,5,6,7,8,9,*,#]?
       
   191             if( refCode == scanCode )
       
   192                 {
       
   193                 return ETrue;
       
   194                 }
       
   195             }
       
   196         }
       
   197     
       
   198     // Homescreen should open dialer also with alpha characters, if dialer is in 
       
   199     // mode that accepts alpha characters into number entry (ou1cimx1#299396)    
       
   200     
       
   201     const TInt  KPhoneKeyStart = 33;
       
   202     const TInt  KPhoneKeyEnd   = 127;
       
   203     
       
   204     return ( ( AllowAlphaNumericMode() ) && ( ( scanCode >= KPhoneKeyStart &&
       
   205              scanCode <= KPhoneKeyEnd ) || modifiers & EModifierSpecial ) );
       
   206     }
       
   207 
       
   208 
       
   209 /**
       
   210  * Load input locales.
       
   211  */
       
   212 void CNumericKeyHandler::LoadInputLanguageKeyBindings( TInt aLanguage )
       
   213     {
       
   214     iNumericKeys.Reset();
       
   215     
       
   216     TRAPD( err, 
       
   217         {
       
   218         CPtiEngine* ptiEngine = CPtiEngine::NewL();
       
   219         CleanupStack::PushL( ptiEngine );
       
   220         ptiEngine->GetNumericModeKeysForQwertyL( aLanguage, 
       
   221                                                  iNumericKeys );         
       
   222         CleanupStack::PopAndDestroy( ptiEngine );                                                 
       
   223         } ); // TRAP
       
   224         
       
   225     if ( err )        
       
   226         {
       
   227         iNumericKeys.Reset();
       
   228         iQwertyMode = 0; // To default mode
       
   229         }
       
   230     else
       
   231         {
       
   232         // remove numeric chars that not open number entry
       
   233         TInt numericKeysCount = iNumericKeys.Count();
       
   234         while ( numericKeysCount-- )
       
   235             {
       
   236             TPtiNumericKeyBinding numKeyBind = iNumericKeys[numericKeysCount];
       
   237             
       
   238             if ( numKeyBind.iChar == 'w' ||
       
   239                  numKeyBind.iChar == 'p' 
       
   240 #ifndef RD_INTELLIGENT_TEXT_INPUT
       
   241                  /*
       
   242                  * The following code is commented because
       
   243                  * For GQF requirement Space is mapped to "0"
       
   244                  */
       
   245                  || numKeyBind.iKey == EPtiKeyQwertySpace  
       
   246 #endif
       
   247                )
       
   248                  {
       
   249                  iNumericKeys.Remove( numericKeysCount );                    
       
   250                  }
       
   251             }    
       
   252         }
       
   253     }
       
   254     
       
   255 /**
       
   256  * Handles qwerty mode change.
       
   257  */
       
   258 TInt CNumericKeyHandler::HandleQwertyModeChanged( TAny *aPtr )
       
   259     {
       
   260     CNumericKeyHandler* self = static_cast<CNumericKeyHandler*>( aPtr );
       
   261     if( self )
       
   262         {
       
   263         TInt value = self->iQwertyMode;
       
   264         TInt err = self->iQwertyObserver->Get( value );
       
   265 
       
   266         if( err == KErrNone )
       
   267             {
       
   268             self->SetQwertyMode( value );
       
   269             }
       
   270         // Load key bindings if not already loaded
       
   271 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
   272         if ( self->iQwertyMode )
       
   273             {
       
   274             self->iNumericKeys.Reset();
       
   275 #else 
       
   276         if ( self->iQwertyMode && !self->iNumericKeys.Count() )
       
   277             {
       
   278 #endif
       
   279         	self->LoadInputLanguageKeyBindings( self->iInputLanguage );
       
   280             }
       
   281         }
       
   282     return KErrNone;
       
   283     }
       
   284 
       
   285 /**
       
   286  * Handles input language change.
       
   287  */
       
   288 TInt CNumericKeyHandler::HandleInputLanguageChanged( TInt aNewValue )
       
   289 	{    	
       
   290 	SetInputLanguage( aNewValue );
       
   291 	LoadInputLanguageKeyBindings( aNewValue );
       
   292     return KErrNone;
       
   293 	}
       
   294     
       
   295 /**
       
   296  * Set qwerty mode.
       
   297  */
       
   298 void CNumericKeyHandler::SetQwertyMode( TInt aValue )
       
   299 	{
       
   300 	iQwertyMode = aValue;
       
   301 	}
       
   302     
       
   303 /**
       
   304  * Set input language.
       
   305  */
       
   306 void CNumericKeyHandler::SetInputLanguage( TInt aValue )
       
   307     {
       
   308     iInputLanguage = aValue;
       
   309     }
       
   310 
       
   311 /**
       
   312  * Check alpha numeric mode.
       
   313  */
       
   314 TBool CNumericKeyHandler::AllowAlphaNumericMode() const
       
   315     {
       
   316     return ( EasyDialingEnabled() || VoIPSupported() );
       
   317     }
       
   318 
       
   319 /**
       
   320  * Check if voip supported.
       
   321  */
       
   322 TBool CNumericKeyHandler::VoIPSupported() const
       
   323     {
       
   324     TBool voipSupported( EFalse );
       
   325     CSPSettings* serviceProviderSettings( NULL );
       
   326 
       
   327     TRAP_IGNORE( serviceProviderSettings = CSPSettings::NewL() );   
       
   328 
       
   329     if ( serviceProviderSettings )
       
   330         {
       
   331         voipSupported = serviceProviderSettings->IsFeatureSupported( 
       
   332                 ESupportInternetCallFeature );
       
   333         
       
   334         delete serviceProviderSettings;
       
   335         }
       
   336 
       
   337     return voipSupported;
       
   338     }
       
   339 
       
   340 /**
       
   341  * Check if easy dialing enabled.
       
   342  */
       
   343 TBool CNumericKeyHandler::EasyDialingEnabled() const
       
   344     {
       
   345     TBool easyDialingEnabled( EFalse );
       
   346     if ( FeatureManager::FeatureSupported( 
       
   347             KFeatureIdProductIncludesHomeScreenEasyDialing ) )
       
   348         {
       
   349         CRepository* cenrep( NULL );
       
   350         TInt easyDialingSetting;
       
   351 
       
   352         TRAP_IGNORE( cenrep = CRepository::NewL( KCRUidEasyDialSettings ) );
       
   353 
       
   354         if ( cenrep )
       
   355             {
       
   356             TInt err = cenrep->Get( KEasyDialing, easyDialingSetting );
       
   357             if ( !err && easyDialingSetting )
       
   358                 {
       
   359                 easyDialingEnabled = ETrue;
       
   360                 }
       
   361 
       
   362             delete cenrep;        
       
   363             }
       
   364         }
       
   365 
       
   366     return easyDialingEnabled;
       
   367     }
       
   368 
       
   369 void CNumericKeyHandler::HandleNotifyGeneric(TUint32 aKey)
       
   370     {
       
   371     if( aKey == KAknFepInputTxtLang )
       
   372         {
       
   373         TInt newValue = iInputLanguage;
       
   374         iInputLanguageRepository->Get( KAknFepInputTxtLang, newValue );
       
   375         HandleInputLanguageChanged( newValue );
       
   376         }
       
   377     }
       
   378     
       
   379 void CNumericKeyHandler::HandleNotifyError
       
   380         (TUint32 /*aKey*/, TInt /*aError*/, CCenRepNotifyHandler* /*aHandler*/)
       
   381     {
       
   382     }
       
   383 
       
   384 } // namespace AiWsPlugin