terminalsecurity/SCP/SCPClient/src/SCPQueryDialog.cpp
changeset 73 ae69c2e8bc34
parent 71 d2517372cc44
child 77 9f85c58c0592
equal deleted inserted replaced
71:d2517372cc44 73:ae69c2e8bc34
     1 /*
       
     2 * Copyright (c) 2000 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: Implementation of terminalsecurity components
       
    15 *
       
    16 */
       
    17 
       
    18 #include <AknQueryDialog.h>
       
    19 #include "SCPQueryDialog.h"
       
    20 #include <eikseced.h>
       
    21 #include <aknsoundsystem.h>
       
    22 #include <StringLoader.h>
       
    23 #include <aknappui.h> 
       
    24 #include <avkon.rsg>
       
    25 #include <SecUi.rsg>
       
    26 // Include the SecUi definitions
       
    27 #include <secui.hrh>
       
    28 #include "SCPDebug.h"
       
    29 #include <scpnotifier.rsg>
       
    30 // For Central Repository
       
    31 #include <centralrepository.h>
       
    32 #include <AknIncallBubbleNotify.h>
       
    33 #include <e32property.h>
       
    34 #include <ctsydomainpskeys.h>
       
    35 #include "SCPCodePrivateCRKeys.h"
       
    36 /*#ifdef _DEBUG
       
    37 #define __SCP_DEBUG
       
    38 #endif // _DEBUG
       
    39 
       
    40 // Define this so the precompiler in CW 3.1 won't complain about token pasting,
       
    41 // the warnings are not valid
       
    42 #pragma warn_illtokenpasting off
       
    43 
       
    44 #ifdef __SCP_DEBUG
       
    45 #define Dprint(a) RDebug::Print##a
       
    46 #else
       
    47 #define Dprint(a)
       
    48 #endif // _DEBUG*/
       
    49 
       
    50 const TInt KSCPSpecialDeleteEvent( 63529 );
       
    51 
       
    52 // ================= MEMBER FUNCTIONS =======================
       
    53 //
       
    54 // ----------------------------------------------------------
       
    55 // CSCPQueryDialog::CSCPQueryDialog()
       
    56 // C++ constructor
       
    57 // ----------------------------------------------------------
       
    58 //
       
    59 CSCPQueryDialog::CSCPQueryDialog(   TDes& aDataText,
       
    60                                     RSCPClient::TSCPButtonConfig aButtonsShown, 
       
    61                                     TInt aMinLength,
       
    62                                     TInt aMaxLength,
       
    63                                     TBool aECSSupport
       
    64                                     )
       
    65             : CAknTextQueryDialog(aDataText, ENoTone),
       
    66 			  iMinLength(aMinLength),
       
    67 			  iMaxLength(aMaxLength),
       
    68 			  iValidTextLen( 0 ),
       
    69 			  iButtons( aButtonsShown ),
       
    70 			  iECSSupport( aECSSupport ),
       
    71 			  iEcsDetector( NULL ),
       
    72 			  iEMCallActivated( EFalse ),
       
    73 			  iShowingEMNumber( EFalse ),
       
    74 			  iPreviousCharacterWasInvalid( EFalse ),
       
    75 			  iPrioritySet( EFalse ),
       
    76 			  iPriorityDropped( EFalse ),
       
    77 			  iKeyUsed ( NULL )
       
    78 	{		 
       
    79         def_mode = 0;
       
    80         iAppKey = 0;
       
    81         iMode = KSCPModeNormal;
       
    82 	}
       
    83 	
       
    84 //
       
    85 // ----------------------------------------------------------
       
    86 // CSCPQueryDialog::~CSCPQueryDialog()
       
    87 // Destructor
       
    88 // ----------------------------------------------------------
       
    89 //
       
    90 CSCPQueryDialog::~CSCPQueryDialog()
       
    91 	{
       
    92 	Dprint( (_L("CSCPQueryDialog::~CSCPQueryDialog()")) );
       
    93 	
       
    94 	    if ( AknLayoutUtils::PenEnabled() )
       
    95         {
       
    96         TRAP_IGNORE ( SetIncallBubbleAllowedInUsualL( ETrue ) );
       
    97         }
       
    98 
       
    99 	
       
   100 	if (iFront)
       
   101 		{
       
   102 		// Uncapture keys, if they were captured
       
   103 		if ( iMode == KSCPModeRestricted )		
       
   104 			{
       
   105 			RWindowGroup& groupWin=iCoeEnv->RootWin();
       
   106 			groupWin.CancelCaptureKeyUpAndDowns(iAppKey);
       
   107 			groupWin.CancelCaptureKeyUpAndDowns(iVoiceKey2);
       
   108 			groupWin.CancelCaptureKey(iVoiceKey1);						
       
   109 			}
       
   110 
       
   111 		if ( iPrioritySet )
       
   112 		    {
       
   113     		// Return normal high-priority in case there are other notifiers active 
       
   114 	    	// and were are not going to lose foregroung right after following call	
       
   115 		    iEikonEnv->RootWin().SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront);
       
   116 		    }
       
   117 		 						
       
   118 		iEikonEnv->BringForwards(EFalse);	
       
   119 		iEikonEnv->EikAppUi()->RemoveFromStack(this);
       
   120 		
       
   121 
       
   122 		static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->ReleaseContext();
       
   123 		static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->PopContext();
       
   124 
       
   125 		
       
   126 		if ( iECSSupport )
       
   127             {
       
   128 		    delete iEcsDetector;
       
   129             }
       
   130 		
       
   131 		iFront = EFalse;
       
   132 		}
       
   133 	
       
   134 	if (iDeviceLockStatusObserver)
       
   135 		delete iDeviceLockStatusObserver;
       
   136 		if (iCallStatusObserver)
       
   137 		delete iCallStatusObserver;
       
   138 	}
       
   139 //
       
   140 // ----------------------------------------------------------
       
   141 // CSCPQueryDialog::PreLayoutDynInitL()
       
   142 // Called by framework before dialog is shown 
       
   143 // ----------------------------------------------------------
       
   144 //
       
   145 void CSCPQueryDialog::PreLayoutDynInitL()
       
   146     {
       
   147     Dprint( (_L("CSCPQueryDialog::PreLayoutDynInitL()") ));
       
   148     
       
   149     /* CEikSecretEditor* queryControl = 
       
   150                     static_cast<CEikSecretEditor*>(
       
   151                         QueryControl()->ControlByLayoutOrNull( QueryControl()->QueryType() ) 
       
   152                        ); 
       
   153     queryControl->EnableSCT(EFalse); */
       
   154     
       
   155     CAknTextQueryDialog::PreLayoutDynInitL();
       
   156     
       
   157     //disable in call bubble.
       
   158     if ( AknLayoutUtils::PenEnabled() )
       
   159         {
       
   160         SetIncallBubbleAllowedInUsualL( EFalse );
       
   161         }
       
   162 
       
   163     
       
   164     // Create the ECS detector object if required
       
   165     if ( iECSSupport )
       
   166         {
       
   167         Dprint( (_L(" Creating ECS detector") ));
       
   168         iEcsDetector = CAknEcsDetector::NewL();
       
   169         iEcsDetector->SetObserver( this );
       
   170         }    
       
   171     
       
   172     Dprint( (_L("CSCPQueryDialog::PreLayoutDynInitL(): Set input mode") ));
       
   173         
       
   174     /* The default input mode of the lock code query must be set on the basis of the
       
   175     very first character of the current lock code. If the first character of the current
       
   176     lock code is numeric, the default input mode will also be numeric. Otherwise, the 
       
   177     default input mode will be alphabetic */
       
   178     
       
   179     CRepository* repository;
       
   180     repository = CRepository::NewL( KCRUidSCPParameters );
       
   181     CleanupStack::PushL( repository );
       
   182     
       
   183     User::LeaveIfError(repository->Get( KSCPLockCodeDefaultInputMode , def_mode) );
       
   184     
       
   185     CleanupStack::PopAndDestroy( repository );
       
   186     repository = NULL;   
       
   187     
       
   188     if (def_mode == 0)
       
   189     	SetDefaultInputMode( EAknEditorNumericInputMode ); 
       
   190     else
       
   191     	SetDefaultInputMode( EAknEditorSecretAlphaInputMode );
       
   192     
       
   193     // Set the mode, we use this to determine the functionality for special keys
       
   194     if ( ( iButtons == RSCPClient::SCP_OK ) || ( iButtons == RSCPClient::SCP_OK_CANCEL ) )
       
   195         {
       
   196         // Normal mode
       
   197         iMode = KSCPModeNormal;
       
   198         }
       
   199     else
       
   200         {
       
   201         // Restricted mode, used for example for Etel-originated queries
       
   202         iMode = KSCPModeRestricted;
       
   203         }
       
   204     
       
   205     Dprint( (_L("CSCPQueryDialog::PreLayoutDynInitL(): Set button config") ));
       
   206     // Set the softkey-configuration
       
   207     switch ( iButtons )
       
   208         {
       
   209             case ( RSCPClient::SCP_OK ):
       
   210             // Flow through
       
   211             case ( RSCPClient::SCP_OK_ETEL ):
       
   212                 {
       
   213                 // Hide the Cancel-softkey
       
   214                 ButtonGroupContainer().MakeCommandVisible( EAknSoftkeyCancel, EFalse );
       
   215                 break;
       
   216                 }
       
   217             
       
   218             default:
       
   219                 // Show both softkeys
       
   220             break;
       
   221         }
       
   222         
       
   223 	QueryControl()->SetTextEntryLength( iMaxLength ); 
       
   224 	
       
   225 	// Add this higher than the environment filter, otherwise
       
   226 	// we cannot capture keys from the EikSrvUi KeyFilter. 
       
   227 	// Used because this query might be called from notifier		
       
   228 
       
   229 	if ( iMode == KSCPModeNormal )
       
   230 		{
       
   231 		iEikonEnv->EikAppUi()->AddToStackL(this,
       
   232 		                                   ECoeStackPriorityEnvironmentFilter+100,
       
   233 		                                   ECoeStackFlagRefusesAllKeys);
       
   234 		}
       
   235 	else
       
   236 		{
       
   237 		iEikonEnv->EikAppUi()->AddToStackL(this,
       
   238 		                                   ECoeStackPriorityEnvironmentFilter+100,
       
   239 		                                   ECoeStackFlagRefusesFocus);
       
   240 		}
       
   241 	
       
   242 	Dprint( (_L("CSCPQueryDialog::PreLayoutDynInitL(): Capture keys") ));
       
   243 	// Capture app, voice and end keys if necessary
       
   244 	if ( iMode == KSCPModeRestricted )		
       
   245 		{		
       
   246 		RWindowGroup& groupWin=iCoeEnv->RootWin();
       
   247 		// Capture app key
       
   248 		iAppKey = groupWin.CaptureKeyUpAndDowns(EStdKeyApplication0, 0, 0);
       
   249 		// capture voice key
       
   250 		iVoiceKey1 = groupWin.CaptureKey(EKeySide,0,0);
       
   251 		iVoiceKey2 = groupWin.CaptureKeyUpAndDowns(EStdKeyDevice6, 0, 0);
       
   252 		}
       
   253 
       
   254     RWsSession& wsSession = iEikonEnv->WsSession();
       
   255     TInt myWgId = iEikonEnv->RootWin().Identifier();
       
   256     
       
   257     TInt wgPrio = wsSession.GetWindowGroupOrdinalPriority(myWgId);
       
   258 	Dprint( (_L("CSCPQueryDialog::PreLayoutDynInitL(): wgPrio %d"),wgPrio ));
       
   259 	TInt var;
       
   260 	RProperty::Get(KPSUidCtsyCallInformation, KCTsyCallState,var);
       
   261 	Dprint( (_L("CSCPQueryDialog::PreLayoutDynInitL(): EPSCTsyCallStateNone %d"),var ));
       
   262     // we are already on forgeround, need to update priority differently
       
   263 	if (var != EPSCTsyCallStateNone)
       
   264 	{
       
   265 		// If the call is made during device startup have the priority as normal
       
   266 		if (iECSSupport && (iButtons == RSCPClient::SCP_OK))
       
   267 		{
       
   268 		iEikonEnv->RootWin().SetOrdinalPosition(1,ECoeWinPriorityNormal);
       
   269 		}
       
   270 	
       
   271 	}
       
   272     else if ((wgPrio == ECoeWinPriorityAlwaysAtFront)&&(iECSSupport))
       
   273         {
       
   274         Dprint( (_L("CSCPQueryDialog::PreLayoutDynInitL(): ECoeWinPriorityAlwaysAtFront+1") ));	
       
   275         iEikonEnv->RootWin().SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront+1);
       
   276         iPrioritySet = ETrue;
       
   277         }
       
   278         
       
   279    // this must be done always to keep the reference count in synch  
       
   280    // this does not have any effect if autoforwarding has not been set true (normal application.)
       
   281    iEikonEnv->BringForwards(ETrue, ECoeWinPriorityAlwaysAtFront+1);
       
   282 
       
   283 	/// -- Change Window Priority for dialog and CBA 
       
   284 	if (iECSSupport)
       
   285 		{
       
   286 		Dprint( (_L("CSCPQueryDialog::PreLayoutDynInitL(): Changing Window Priority") ));			
       
   287 		DrawableWindow()->SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront);
       
   288 		ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront); 	
       
   289 		}
       
   290 	else
       
   291 		{
       
   292 		DrawableWindow()->SetOrdinalPosition(0,ECoeWinPriorityNormal); //
       
   293 		ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(0,ECoeWinPriorityNormal); 	  	
       
   294 		}	
       
   295 
       
   296 	Dprint( (_L("CSCPQueryDialog::PreLayoutDynInitL(): Key sounds") ));
       
   297 	// Key sounds
       
   298 
       
   299 	static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->
       
   300 	    PushContextL(R_AVKON_DEFAULT_SKEY_LIST);
       
   301 	    	                                                             
       
   302 	static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->BringToForeground();
       
   303 	static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds()->LockContext();
       
   304 
       
   305 	iFront = ETrue;
       
   306 	
       
   307 	Dprint( (_L("CSCPQueryDialog::CSCPLockObserver") ));
       
   308 	iDeviceLockStatusObserver = CSCPLockObserver::NewL(this);
       
   309 	iCallStatusObserver = CSCPLockObserver::NewL(this,ESecUiCallStateObserver);
       
   310 
       
   311 	}
       
   312 //
       
   313 // ---------------------------------------------------------
       
   314 // CSCPQueryDialog::OfferKeyEventL
       
   315 // called by framework when any key is pressed
       
   316 // ---------------------------------------------------------
       
   317 //
       
   318 TKeyResponse CSCPQueryDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   319 	{
       
   320     Dprint( (_L("CSCPQueryDialog::OfferKeyEventL(%d, %d, %d)"), aKeyEvent.iScanCode, 
       
   321         aKeyEvent.iCode, aType ));
       
   322     
       
   323     //Handling for Key up events for special characters  
       
   324     if (aType == EEventKeyUp && iPriorityDropped && iKeyUsed
       
   325             == aKeyEvent.iScanCode)
       
   326         {
       
   327         DrawableWindow()->SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
       
   328         ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(
       
   329                 0, ECoeWinPriorityAlwaysAtFront);
       
   330         iPriorityDropped = EFalse;
       
   331         iKeyUsed = NULL;
       
   332         Dprint((_L("CSCPQueryDialog::OfferKeyEventL(): Priority dropped")));
       
   333         return EKeyWasConsumed;
       
   334         }
       
   335     else
       
   336         {
       
   337         if (iPriorityDropped && iKeyUsed != aKeyEvent.iScanCode
       
   338                 && (aKeyEvent.iScanCode == EStdKeyDevice0
       
   339                         || aKeyEvent.iScanCode == EStdKeyDevice1
       
   340                         || aKeyEvent.iScanCode == EStdKeyDevice2
       
   341                         || aKeyEvent.iScanCode == EStdKeyDevice3))
       
   342             {
       
   343             iPriorityDropped = EFalse;
       
   344             iKeyUsed = NULL;
       
   345             }
       
   346 
       
   347         }
       
   348     
       
   349     //Consume the characters which are typed before Key up events of special characters
       
   350     if (iPriorityDropped && iKeyUsed != NULL)
       
   351         {
       
   352         return EKeyWasConsumed;
       
   353         }
       
   354 
       
   355     	            		            
       
   356 	// Check if the priority should be dropped, so that special dialogs can be shown
       
   357 	if ( ( aType == EEventKeyDown ) && 
       
   358 	     ( ( aKeyEvent.iScanCode == EStdKeyLeftShift ) || // Pen-key
       
   359 	       ( aKeyEvent.iScanCode == EStdKeyRightShift ) || // Pen-key
       
   360 	       ( aKeyEvent.iScanCode == EStdKeyLeftFunc )  || //Chr-key
       
   361 	       ( aKeyEvent.iScanCode == EStdKeyNkpAsterisk ) || // * - key
       
   362 	       ( aKeyEvent.iScanCode == '*' )                  // * - key
       
   363 	     )
       
   364 	   )
       
   365 	    {
       
   366         iKeyUsed = aKeyEvent.iScanCode;
       
   367 	    DrawableWindow()->SetOrdinalPosition(0,0);
       
   368 	    ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(0,0);
       
   369 	    iPriorityDropped = ETrue;
       
   370 	    
       
   371 	    Dprint( (_L("CSCPQueryDialog::OfferKeyEventL(): Priority dropped") ));
       
   372 	    }
       
   373 	else
       
   374 	    {
       
   375 	    // Return priority, either no dialogs shown, or already exited.
       
   376 	    if ( iPriorityDropped )
       
   377 	        {
       
   378             DrawableWindow()->SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront);
       
   379 	        ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront);
       
   380 	        iPriorityDropped = EFalse;
       
   381 	        Dprint( (_L("CSCPQueryDialog::OfferKeyEventL(): Priority re-raised") ));
       
   382 	        }
       
   383 	    }
       
   384 		
       
   385     if ( aKeyEvent.iCode == EKeyOK || aKeyEvent.iCode == EKeyEnter)
       
   386         {
       
   387         // Try to exit with OK as well
       
   388         TryExitL(EAknSoftkeyOk);
       
   389         return EKeyWasConsumed;
       
   390         }
       
   391 
       
   392 	// app key
       
   393 	if (aKeyEvent.iScanCode == EStdKeyApplication0)
       
   394 		{
       
   395 		if ( iButtons == RSCPClient::SCP_OK_CANCEL )
       
   396 			{
       
   397 			TryExitL(EAknSoftkeyCancel);
       
   398 			return EKeyWasNotConsumed;	
       
   399 			}
       
   400 		return EKeyWasConsumed;
       
   401 		}
       
   402 		
       
   403 	// end key
       
   404 	if ( (aKeyEvent.iCode == EKeyPhoneEnd) || (aKeyEvent.iCode == EKeyEscape) )
       
   405         {
       
   406         if ( ( iButtons == RSCPClient::SCP_OK_CANCEL ) ||  
       
   407             ( iButtons == RSCPClient::SCP_OK_CANCEL_ETEL ) )
       
   408             {
       
   409             TryExitL(EAknSoftkeyCancel);          
       
   410             }
       
   411         return EKeyWasConsumed;
       
   412         }
       
   413 
       
   414 	if (aKeyEvent.iCode == EKeyPhoneSend)
       
   415 	    {
       
   416         //if (AknLayoutUtils::PenEnabled())
       
   417             {
       
   418             if (iECSSupport)
       
   419                 {
       
   420                 if (iEcsDetector->State()== CAknEcsDetector::ECompleteMatch)
       
   421                     {
       
   422                     iEcsDetector->AddChar( (TText)(EKeyPhoneSend) );
       
   423                     
       
   424                     }   
       
   425                 else
       
   426                     {
       
   427                     Dprint( (_L("CSCPQueryDialog::OfferKeyEventL(): ShowWarningNoteL") ));
       
   428                     ShowWarningNoteL();
       
   429                     return EKeyWasConsumed;
       
   430                     }
       
   431                 }
       
   432             else //consume the key to prevent dialler from opening
       
   433                 {
       
   434                 Dprint( (_L("CSCPQueryDialog::OfferKeyEventL(): EKeyPhoneSend :EKeyWasConsumed") ));
       
   435                 return EKeyWasConsumed;
       
   436                 }
       
   437             }
       
   438         }
       
   439 	    
       
   440     if ( ( aType == EEventKey ) && ( aKeyEvent.iCode == KSCPSpecialDeleteEvent ) )
       
   441         {
       
   442         // This special event is sent to remove the previous character while "cycling" with
       
   443         // the numeric keys. Discard, if the previous character was already removed.
       
   444         if ( iPreviousCharacterWasInvalid )
       
   445             {
       
   446             return EKeyWasConsumed;
       
   447             }
       
   448         }
       
   449 	               			
       
   450     if ( ( aType == EEventKey ) && ( iECSSupport ) )
       
   451         {        
       
   452         // Reset the field text
       
   453         QueryControl()->SetTextL( iTextBuffer );        
       
   454         }
       
   455             
       
   456 	TKeyResponse ret = QueryControl()->OfferKeyEventL( aKeyEvent, aType );
       
   457                 
       
   458     // Check that only alphanumeric letters are entered    
       
   459     if ( ( QueryControl() != NULL ) && ( QueryControl()->GetTextLength() > iValidTextLen ) )
       
   460         {                    
       
   461         // A new character was added to the editor
       
   462         iTmpBuffer.Zero();
       
   463         QueryControl()->GetText( iTmpBuffer );
       
   464         
       
   465         TChar newChar = iTmpBuffer[ iTmpBuffer.Length() - 1 ];
       
   466         TChar::TCategory newCat = newChar.GetCategory();
       
   467         if ( newChar.IsSpace() || newChar < 1 || newChar > 126 )
       
   468         /* if ( !newChar.IsAlphaDigit() && newCat != TChar::ENdCategory ) */
       
   469             {
       
   470             // Remove the last character, not allowed
       
   471             iTmpBuffer.SetLength( iTmpBuffer.Length() - 1 );
       
   472             QueryControl()->SetTextL( iTmpBuffer );
       
   473             
       
   474             iPreviousCharacterWasInvalid = ETrue;
       
   475             
       
   476             // Hide the OK key if the first character was invalid
       
   477             if ( iValidTextLen == 0 )
       
   478                 {
       
   479                 if (AknLayoutUtils::PenEnabled())
       
   480                     {
       
   481                     ButtonGroupContainer().DimCommand(EAknSoftkeyOk, ETrue);
       
   482                     }
       
   483                 else
       
   484                     {
       
   485                     ButtonGroupContainer().MakeCommandVisible(EAknSoftkeyOk, EFalse);
       
   486                     }
       
   487 
       
   488                 }
       
   489             }
       
   490         else
       
   491             {
       
   492             iValidTextLen++;
       
   493             iPreviousCharacterWasInvalid = EFalse;            	        	            
       
   494             }            
       
   495         }
       
   496     else if ( ( QueryControl() != NULL ) && ( QueryControl()->GetTextLength() < iValidTextLen ) )
       
   497         {
       
   498         // Character removed, make sure we're back on track,
       
   499         // though likely only backspace was pressed
       
   500         iValidTextLen = QueryControl()->GetTextLength();
       
   501         }   
       
   502         
       
   503 //Additional modifier set by query dialog, while simulating event
       
   504 // As raw key events are used to simulate, modifiers and scan codes cannot be set at a time
       
   505 // In the 1st event, modifiers are set and in subsequent event, scan codes will be set.
       
   506 if(aKeyEvent.iModifiers & EModifierNumLock &&
       
   507         aKeyEvent.iModifiers & EModifierKeypad && aKeyEvent.iModifiers & EModifierSpecial
       
   508 )
       
   509     {
       
   510    
       
   511     return EKeyWasConsumed;
       
   512     }
       
   513     if ( iECSSupport )
       
   514         {
       
   515         // Save the text
       
   516         if ( aType == EEventKey ) 
       
   517             {
       
   518             QueryControl()->GetText( iTextBuffer );
       
   519             }
       
   520         if ( aType == EEventKey ) 
       
   521             {
       
   522             iEcsDetector->SetBuffer(iTextBuffer.Left(KAknEcsMaxMatchingLength));
       
   523             }
       
   524         if ( aType == EEventKey )
       
   525             {
       
   526         if ( iEMCallActivated )
       
   527             {
       
   528             TryExitL( ESecUiEmergencyCall );
       
   529             return EKeyWasConsumed;
       
   530             }
       
   531         }
       
   532         // Retrieve the editor control ptr, we know it is a secret editor..
       
   533         CEikSecretEditor* queryControl = static_cast<CEikSecretEditor*>( 
       
   534             QueryControl()->ControlByLayoutOrNull( QueryControl()->QueryType() ) );                
       
   535         
       
   536          // Further check to ensure that the matched number is the entire buffer
       
   537          // Get the matched text and see if is the same length as the current query length
       
   538         if ( iShowingEMNumber && (QueryControl()->GetTextLength()== iEcsDetector->CurrentMatch().Length()))
       
   539             {
       
   540             // The previous keyDown-event resulted in a complete Em-number match.
       
   541                               
       
   542             // An emergency number is entered, show the text in the field
       
   543             QueryControl()->SetTextL( iEcsDetector->CurrentMatch() );            
       
   544             if ( queryControl != NULL )
       
   545                 {
       
   546                 queryControl->RevealSecretText( ETrue );
       
   547                 if (isCallSoftkeyAdded == EFalse)
       
   548                 {
       
   549                 	isCallSoftkeyAdded = ETrue;
       
   550                 HBufC* cbaLabel = NULL;
       
   551 				Dprint( (_L("CSCPQueryDialog::OfferKeyEventL(): R_AVKON_SOFTKEY_CALL_TEXT") ));
       
   552                 TRAPD ( err, cbaLabel =
       
   553                         StringLoader::LoadL( R_AVKON_SOFTKEY_CALL_TEXT) );
       
   554                 if ( err == KErrNone )
       
   555                 {
       
   556                 	ButtonGroupContainer().RemoveCommandFromStack(0,EAknSoftkeyOk);
       
   557                 TRAP ( err, ButtonGroupContainer().AddCommandToStackL( 0, EAknSoftkeyEmergencyCall,
       
   558                         *cbaLabel) );
       
   559 				ButtonGroupContainer().DrawDeferred();
       
   560                 delete cbaLabel;
       
   561                 }
       
   562               }
       
   563                 }            
       
   564             }
       
   565         else
       
   566             {
       
   567             // The input doesn't match a Em-number
       
   568             if ( queryControl != NULL )
       
   569                 {
       
   570                 queryControl->RevealSecretText( EFalse );
       
   571 			if(aType == EEventKey)
       
   572 			{
       
   573                 HBufC* cbaLabel = NULL;
       
   574                 TRAPD ( err , cbaLabel= StringLoader::LoadL(R_SCPDIALOG_OK_TEXT) );
       
   575                 if ( err == KErrNone )
       
   576                 {
       
   577 					if (isCallSoftkeyAdded)
       
   578 					{
       
   579 						isCallSoftkeyAdded = EFalse;
       
   580 						ButtonGroupContainer().RemoveCommandFromStack(0,EAknSoftkeyEmergencyCall);
       
   581 					}
       
   582 					else
       
   583 					{
       
   584 					ButtonGroupContainer().RemoveCommandFromStack(0,EAknSoftkeyOk);
       
   585 					}
       
   586                 TRAP ( err , ButtonGroupContainer().AddCommandToStackL(0,EAknSoftkeyOk,*cbaLabel) );
       
   587                 ButtonGroupContainer().DrawDeferred();
       
   588                 delete cbaLabel;
       
   589 				}
       
   590             	  }
       
   591                 }
       
   592             }
       
   593         }                  
       
   594      
       
   595     Dprint( (_L("CSCPQueryDialog::OfferKeyEventL() exiting") ));
       
   596               
       
   597     if ( ret == EKeyWasConsumed ) // The editor control used up this keyevent
       
   598         {
       
   599         return ret;
       
   600         }         
       
   601     else
       
   602         {
       
   603         return CAknTextQueryDialog::OfferKeyEventL(aKeyEvent,aType);
       
   604         }    
       
   605 	}
       
   606 //
       
   607 // ---------------------------------------------------------
       
   608 // CSCPQueryDialog::NeedToDismissQueryL()
       
   609 // Handles '#' key called by CAknTextQueryDialog::OfferKeyEventL()
       
   610 // ---------------------------------------------------------
       
   611 //
       
   612 TBool CSCPQueryDialog::NeedToDismissQueryL(const TKeyEvent& /*aKeyEvent*/)
       
   613 	{
       
   614 	return EFalse;
       
   615 	}
       
   616 //
       
   617 // ---------------------------------------------------------
       
   618 // CSCPQueryDialog::OkToExitL()
       
   619 // called by framework when the Softkey is pressed
       
   620 // ---------------------------------------------------------
       
   621 //
       
   622 TBool CSCPQueryDialog::OkToExitL(TInt aButtonId)
       
   623 	{
       
   624 	
       
   625 	     Dprint( (_L("CSCPQueryDialog::OkToExitL ( aButtonId :%d, "), aButtonId ));
       
   626 	TInt ret = EFalse;
       
   627 	
       
   628     if ( aButtonId == EAknSoftkeyOk )
       
   629 		{	        		
       
   630 		Dprint( (_L("CSCPQueryDialog::OkToExitL - EAknSoftkeyOk") ));		
       
   631 		TInt textLength = QueryControl()->GetTextLength();
       
   632 		if ( textLength < iMinLength )
       
   633 			{	
       
   634 			// The code was too short -> play error tone & clear editor
       
   635 			if ( textLength != 0 )
       
   636 				{
       
   637 				CAknKeySoundSystem* soundSystem;
       
   638 	            if ( iEikonEnv->AppUi() )
       
   639 		            {		            
       
   640 		            soundSystem = static_cast<CAknAppUi*>(iEikonEnv->EikAppUi())->KeySounds();
       
   641 		            soundSystem->PlaySound( EAvkonSIDErrorTone );
       
   642 		            } 
       
   643 				QueryControl()->SetTextL( KNullDesC );
       
   644 				iTextBuffer.Zero();
       
   645 				iValidTextLen = 0;
       
   646 
       
   647                 // Hide the OK key
       
   648                 //ButtonGroupContainer().MakeCommandVisible( EAknSoftkeyOk, EFalse );
       
   649                // ButtonGroupContainer().DimCommand(EAknSoftkeyOk, ETrue);
       
   650 
       
   651                 if (AknLayoutUtils::PenEnabled())
       
   652                     {
       
   653                     ButtonGroupContainer().DimCommand(EAknSoftkeyOk, ETrue);
       
   654                     }
       
   655                 else
       
   656                     {
       
   657                     ButtonGroupContainer().MakeCommandVisible(EAknSoftkeyOk, EFalse);
       
   658                     }
       
   659                 }
       
   660             ret = EFalse;
       
   661             }	
       
   662 		else
       
   663 			{		
       
   664 			ret = CAknTextQueryDialog::OkToExitL(aButtonId);
       
   665 			}			    
       
   666 		}
       
   667 				
       
   668 	// Cancel is allowed, if the key is active
       
   669 	if ( aButtonId == EAknSoftkeyCancel )
       
   670 		{
       
   671     	Dprint( (_L("CSCPQueryDialog::OkToExitL EAknSoftkeyCancel ")) );	
       
   672 	    ret = CAknTextQueryDialog::OkToExitL(aButtonId);
       
   673 		}
       
   674 		
       
   675     // Emergency call, exit
       
   676     if ( aButtonId == ESecUiEmergencyCall )
       
   677         {
       
   678 		Dprint( (_L("CSCPQueryDialog::OkToExitL(): ESecUiEmergencyCall") ));
       
   679         ret = ETrue;
       
   680         }
       
   681     if (aButtonId == EAknSoftkeyEmergencyCall)
       
   682         {
       
   683         //add EKeyPhonesend to ecs detector. 
       
   684         ret = ETrue;
       
   685         Dprint( (_L("CSCPQueryDialog::OkToExitL(): adding EKeyPhoneSend to detector") ));
       
   686          iEcsDetector->AddChar( (TText)(EKeyPhoneSend ) );
       
   687         CAknTextQueryDialog::OkToExitL(aButtonId);
       
   688         }
       
   689    
       
   690 	Dprint( (_L("CSCPQueryDialog::OkToExitL() done") ));   
       
   691 	return ret;
       
   692 	}
       
   693 
       
   694 
       
   695 // ---------------------------------------------------------
       
   696 // CSCPQueryDialog::HandleEcsEvent()
       
   697 // 
       
   698 // ---------------------------------------------------------
       
   699 //
       
   700 void CSCPQueryDialog::HandleEcsEvent(CAknEcsDetector* aDetector, 
       
   701                                      CAknEcsDetector::TState aUpdatedState)
       
   702     {   
       
   703     (void)aDetector; // Not used
       
   704     
       
   705     TInt err;
       
   706     if ( ( aUpdatedState == CAknEcsDetector::ECompleteMatchThenSendKey ) || 
       
   707          ( aUpdatedState == CAknEcsDetector::ECallAttempted ) )
       
   708         {
       
   709         // Call attempted, cancel the query
       
   710         iEMCallActivated = ETrue; // OfferKeyEventL will close the dialog         
       
   711         }        
       
   712     else if ( aUpdatedState == CAknEcsDetector::ECompleteMatch )    
       
   713         {                
       
   714         iShowingEMNumber = ETrue;
       
   715         }
       
   716     else if ( iShowingEMNumber )
       
   717         {
       
   718         // Cancel Em-number display
       
   719         iShowingEMNumber = EFalse;
       
   720         
       
   721         if ( aUpdatedState == CAknEcsDetector::EEmpty )
       
   722             {
       
   723             // Key timeout: OfferKeyEventL won't be called, so reset the display here
       
   724             TRAP( err, QueryControl()->SetTextL( iTextBuffer ) );
       
   725             (void)err;
       
   726             
       
   727             // Retrieve the editor control ptr, we know it is a secret editor..
       
   728             CEikSecretEditor* queryControl = 
       
   729                 static_cast<CEikSecretEditor*>(
       
   730                     QueryControl()->ControlByLayoutOrNull( QueryControl()->QueryType() ) 
       
   731                    );            
       
   732             if ( queryControl != NULL )
       
   733                 {
       
   734                 queryControl->RevealSecretText( EFalse );
       
   735                 }
       
   736            // }        
       
   737                 HBufC* cbaLabel = NULL;
       
   738 				Dprint( (_L("CSCPQueryDialog::HandleEcsEvent(): R_SCPDIALOG_OK_TEXT") ));
       
   739                 TRAP ( err, cbaLabel= StringLoader::LoadL(R_SCPDIALOG_OK_TEXT) );
       
   740                 if ( err == KErrNone )
       
   741                 {
       
   742                 	if (isCallSoftkeyAdded)
       
   743 						{
       
   744 							isCallSoftkeyAdded = EFalse;
       
   745 							ButtonGroupContainer().RemoveCommandFromStack(0,EAknSoftkeyEmergencyCall);
       
   746 						}
       
   747 						else
       
   748 						{
       
   749 							ButtonGroupContainer().RemoveCommandFromStack(0,EAknSoftkeyOk);
       
   750 						}
       
   751                 	TRAP ( err , ButtonGroupContainer().AddCommandToStackL(0, EAknSoftkeyOk, *cbaLabel) );
       
   752                 	ButtonGroupContainer().DrawDeferred();
       
   753                 	delete cbaLabel;
       
   754                 }
       
   755             }
       
   756         }    
       
   757     }
       
   758  
       
   759 void CSCPQueryDialog::ShowWarningNoteL()
       
   760     {
       
   761     
       
   762     CAknNoteDialog* noteDlg = new (ELeave) CAknNoteDialog();
       
   763     noteDlg->PrepareLC(R_SCPDIALOG_EMERGENCYCALLS_ONLY);
       
   764     noteDlg->SetTimeout(CAknNoteDialog::ELongTimeout);
       
   765     noteDlg->SetTone(CAknNoteDialog::EErrorTone);
       
   766     
       
   767     noteDlg->DrawableWindow()->SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront+1); //
       
   768     noteDlg->ButtonGroupContainer().ButtonGroup()->AsControl()->DrawableWindow()->SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront+1); 
       
   769     
       
   770     noteDlg->RunLD();
       
   771 
       
   772     }
       
   773     
       
   774 // -----------------------------------------------------------------------------
       
   775 // CSCPQueryDialog::SetIncallBubbleAllowedInUsualL()
       
   776 // -----------------------------------------------------------------------------
       
   777 //
       
   778 void CSCPQueryDialog::SetIncallBubbleAllowedInUsualL(TBool aAllowed)
       
   779     {
       
   780     CAknIncallBubble *incallBubble =  CAknIncallBubble::NewL();
       
   781     CleanupStack::PushL(incallBubble);
       
   782     incallBubble->SetIncallBubbleAllowedInUsualL( aAllowed );
       
   783     CleanupStack::PopAndDestroy();
       
   784     }
       
   785 	
       
   786 // Call from the SCPObserver
       
   787 	
       
   788 void CSCPQueryDialog::TryCancelQueryL(TInt aReason)
       
   789     {
       
   790     Dprint( (_L("CSCPQueryDialog::TryCancelQueryL()")) );
       
   791     
       
   792 	if (EPSCTsyCallStateDisconnecting == aReason)
       
   793 	{
       
   794 	Dprint( (_L("CSCPQueryDialog::TryCancelQueryL() -SetOrdinalPosition ->0")) );
       
   795 	iEikonEnv->RootWin().SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront+1);
       
   796 	iPrioritySet = ETrue;
       
   797 	}
       
   798 	else
       
   799 	{
       
   800 	Dprint( (_L("CSCPQueryDialog::TryExitL(EAknSoftkeyCancel)")) );
       
   801     TryExitL(EAknSoftkeyCancel);
       
   802 	}
       
   803     }
       
   804 
       
   805     
       
   806 // End of file
       
   807