pkiutilities/CTSecurityDialogs/NotifSrc/CTpinquerydialog.cpp
changeset 0 164170e6151a
child 26 aad866c37519
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2003-2004 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:   Crypto Token Security Dialogs PIN Query Dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CTPinQueryDialog.h"
       
    22 #include "CTSecurityDialogsLogger.h"
       
    23 #include <CTSecDlgs.rsg>
       
    24 #include <eikenv.h>
       
    25 #include <barsread.h>
       
    26 #include <uikon/eiksrvui.h>
       
    27 
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CCTPinQueryDialog::CCTPinQueryDialog
       
    33 // C++ default constructor can NOT contain any code, that
       
    34 // might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CCTPinQueryDialog::CCTPinQueryDialog(
       
    38     TRequestStatus& aClientStatus,
       
    39     const TDesC& aDlgText, TDes& aPinValue, 
       
    40     const TInt aMinTextLength, const TInt aMaxTextLength, TBool& aRetVal, TBool& aIsDeleted ): 
       
    41     CAknTextQueryDialog(aPinValue),
       
    42 	iDlgText(aDlgText),
       
    43 	iPinValue(aPinValue),
       
    44 	iClientStatus(&aClientStatus),
       
    45 	iRetVal(aRetVal),
       
    46 	iIsDeleted(aIsDeleted)
       
    47     {
       
    48 	iMaxTextLength = Min(aPinValue.MaxLength(), aMaxTextLength);
       
    49 	iMinTextLength = Max(0, aMinTextLength);
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CCTPinQueryDialog::~CCTPinQueryDialog()
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CCTPinQueryDialog::~CCTPinQueryDialog()
       
    57     {
       
    58     // Allow application switching again
       
    59    CEikonEnv* eikonEnv = CEikonEnv::Static();
       
    60     if( eikonEnv )
       
    61         {
       
    62         CEikServAppUi* eikServAppUi = static_cast<CEikServAppUi*>( eikonEnv->EikAppUi() );
       
    63         if( eikServAppUi )
       
    64             {
       
    65             eikServAppUi->SuppressAppSwitching( EFalse );
       
    66             }
       
    67         }
       
    68 
       
    69     // Complete the client request
       
    70     if( iClientStatus && *iClientStatus == KRequestPending )
       
    71         {
       
    72         iRetVal = EFalse;
       
    73         User::RequestComplete( iClientStatus, KErrNone );
       
    74         }
       
    75     
       
    76     // Notify that the dialog has been deleted
       
    77     iIsDeleted = ETrue;
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CCTPinQueryDialog::RunDlgLD()
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CCTPinQueryDialog::RunDlgLD(
       
    85     TRequestStatus& aClientStatus, 
       
    86     const TDesC& aDlgText, 
       
    87     TDes& aPinValue, 
       
    88     const TInt aMinTextLength, 
       
    89     const TInt aMaxTextLength, 
       
    90     TBool& aRetVal, 
       
    91     TInt aResourceId, CCTPinQueryDialog*& aDialog, TBool& aIsDeleted )
       
    92     {
       
    93 	CCTPinQueryDialog* self = new (ELeave) CCTPinQueryDialog(aClientStatus, aDlgText, aPinValue, aMinTextLength, aMaxTextLength, aRetVal, aIsDeleted );
       
    94 	aDialog = self;
       
    95 	// OkToExitL function handles dialog response
       
    96 	self->ExecuteLD(aResourceId);
       
    97     }
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 // CCTPinQueryDialog::PreLayoutDynInitL()
       
   101 // -----------------------------------------------------------------------------
       
   102 //
       
   103 void CCTPinQueryDialog::PreLayoutDynInitL()
       
   104     {
       
   105 	SetMaxLength(iMaxTextLength);
       
   106 	SetPromptL(iDlgText);
       
   107 	CAknTextQueryDialog::PreLayoutDynInitL();
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CCTPinQueryDialog::CheckIfEntryTextOk()
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 TBool CCTPinQueryDialog::CheckIfEntryTextOk() const
       
   115     {
       
   116     CAknQueryControl* control = QueryControl();
       
   117     if (control)
       
   118         {
       
   119         control->GetText(iDataText);
       
   120         }
       
   121     const TInt textLength = Text().Length();
       
   122     return (textLength <= iMaxTextLength && textLength >= iMinTextLength);
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CCTPinQueryDialog::UpdateLeftSoftKeyL()
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void CCTPinQueryDialog::UpdateLeftSoftKeyL()
       
   130     {
       
   131     CAknTextQueryDialog::UpdateLeftSoftKeyL();
       
   132     MakeLeftSoftkeyVisible(CheckIfEntryTextOk());
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CCTPinQueryDialog::PostLayoutDynInitL()
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CCTPinQueryDialog::PostLayoutDynInitL()
       
   140     {
       
   141 	((CEikServAppUi*)(CEikonEnv::Static())->EikAppUi())->SuppressAppSwitching(ETrue);
       
   142     }
       
   143 // -----------------------------------------------------------------------------
       
   144 // CCTPinQueryDialog::OkToExitL()
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 TBool CCTPinQueryDialog::OkToExitL( TInt aButtonId )
       
   148     {
       
   149 
       
   150     if ( aButtonId == EEikBidCancel || aButtonId == EAknSoftkeyNo )
       
   151         {
       
   152         iRetVal = EFalse;
       
   153         User::RequestComplete(iClientStatus, KErrNone);   
       
   154         }
       
   155 
       
   156     else if ( aButtonId ==EAknSoftkeyYes || aButtonId == EAknSoftkeyOk)
       
   157         {
       
   158         CAknQueryControl* control = QueryControl();
       
   159         if (control)
       
   160             {
       
   161             control->GetText(iPinValue);
       
   162             }
       
   163         iRetVal = ETrue;
       
   164         User::RequestComplete(iClientStatus, KErrNone); 
       
   165         }
       
   166 
       
   167     return ETrue; 
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CCTPinQueryDialog::OfferKeyEventL()
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 TKeyResponse CCTPinQueryDialog::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
       
   175     {
       
   176 	// '#' key is inactive in Pin query dialog
       
   177 	if( (aKeyEvent.iScanCode == EStdKeyHash)  && (aType == EEventKeyDown || aType == EEventKeyUp) )
       
   178 	    { 
       
   179 		return EKeyWasConsumed;
       
   180 	    }
       
   181 	// '*' key is inactive in Pin query dialog
       
   182 	if (aKeyEvent.iCode == '*')
       
   183 	    {
       
   184 		return EKeyWasConsumed;
       
   185 	    }
       
   186 	return CAknTextQueryDialog::OfferKeyEventL(aKeyEvent, aType);
       
   187     }
       
   188 // End of File