phoneapp/phoneuiutils/src/cphonekeys.cpp
changeset 0 5f000ab63145
child 45 6b911d05207e
child 58 40a3f856b14d
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Phone Keys
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "cphonekeys.h"
       
    21 #include    <aknkeys.h>
       
    22 #include    <AknUtils.h>
       
    23 #include    "phonelogger.h"
       
    24 
       
    25 // CONSTANTS
       
    26 _LIT( KPhoneValidChars, "0123456789*#+pwPW" );
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // ---------------------------------------------------------
       
    31 // CPhoneKeys::IsNumberKey
       
    32 // ---------------------------------------------------------
       
    33 //
       
    34 EXPORT_C TBool CPhoneKeys::IsNumberKey(
       
    35     const TKeyEvent& aKeyEvent,
       
    36     TEventCode /*aType*/ )
       
    37     {
       
    38     // Convert key code to western.
       
    39     TBuf<1> buffer; // one character
       
    40     buffer.Append( aKeyEvent.iCode );
       
    41     AknTextUtils::ConvertDigitsTo( buffer, EDigitTypeWestern );
       
    42 
       
    43     TBool result = EFalse;
       
    44 
       
    45     switch ( buffer[ 0 ] ) // first char
       
    46         {
       
    47         // Digits, 0 .. 9
       
    48         case KPhoneDtmf0Character:
       
    49         case KPhoneDtmf1Character:
       
    50         case KPhoneDtmf2Character:
       
    51         case KPhoneDtmf3Character:
       
    52         case KPhoneDtmf4Character:
       
    53         case KPhoneDtmf5Character:
       
    54         case KPhoneDtmf6Character:
       
    55         case KPhoneDtmf7Character:
       
    56         case KPhoneDtmf8Character:
       
    57         case KPhoneDtmf9Character:
       
    58             result = ETrue;
       
    59             break;
       
    60         default:
       
    61             break;
       
    62         }
       
    63 __PHONELOG1( 
       
    64         EBasic, 
       
    65         EPhonePhoneapp, 
       
    66         "PhoneKeys::IsNumberKey: result: %d", 
       
    67         result );
       
    68         
       
    69     return result;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------
       
    73 // CPhoneKeys::IsNumericKey
       
    74 // ---------------------------------------------------------
       
    75 //
       
    76 EXPORT_C TBool CPhoneKeys::IsNumericKey( 
       
    77     const TKeyEvent& aKeyEvent,
       
    78     TEventCode aType )
       
    79     {
       
    80     TBool result = IsNumberKey( aKeyEvent, aType );
       
    81 
       
    82     if ( !result )
       
    83         {
       
    84         switch( aKeyEvent.iCode )
       
    85             {
       
    86             case KPhoneDtmfHashCharacter:      // Hash
       
    87             case KPhoneDtmfStarCharacter:      // Asterisk
       
    88                 // the following key can be got via taps of *
       
    89             case KPhoneDtmfSpeedDialCharacter: // Plus
       
    90             case KPhoneDtmfPauseCharacter:     // DTMF Soft-Pause character
       
    91             case KPhoneDtmfWaitCharacter:      // DTMF Wait character
       
    92                 result = ETrue;
       
    93                 break;
       
    94             default:
       
    95                 break;
       
    96             }
       
    97         }
       
    98 
       
    99 __PHONELOG2( 
       
   100         EBasic, 
       
   101         EPhonePhoneapp, 
       
   102         "PhoneKeys::IsNumericKey: result: %d, code %d", 
       
   103         result,
       
   104         aKeyEvent.iCode );
       
   105 
       
   106     return result;
       
   107     }       
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CPhoneKeys::IsEscapeKey
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 EXPORT_C TBool CPhoneKeys::IsEscapeKey(
       
   114     const TKeyEvent& aKeyEvent,
       
   115     TEventCode aType )
       
   116     {
       
   117     return 
       
   118         ( aType == EEventKey ) && 
       
   119         ( aKeyEvent.iCode == EKeyEscape );
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------
       
   123 // CPhoneKeys::IsDTMFTone
       
   124 // ---------------------------------------------------------
       
   125 //
       
   126 EXPORT_C TBool CPhoneKeys::IsDtmfTone( 
       
   127     const TKeyEvent& aKeyEvent,
       
   128     TEventCode aType )
       
   129     {
       
   130     TBool result = IsNumberKey( aKeyEvent, aType );
       
   131 
       
   132     if ( !result )
       
   133         {
       
   134         switch( aKeyEvent.iCode )
       
   135             {
       
   136             case KPhoneDtmfHashCharacter:  // Hash
       
   137             case KPhoneDtmfStarCharacter:  // Asterisk
       
   138                 result = ETrue;
       
   139                 break;
       
   140             default:
       
   141                 break;
       
   142             }
       
   143         }
       
   144 
       
   145 __PHONELOG2( 
       
   146         EBasic, 
       
   147         EPhonePhoneapp, 
       
   148         "PhoneKeys::IsDtmfTone: result: %d, code %d", 
       
   149         result,
       
   150         aKeyEvent.iCode );
       
   151         
       
   152     return result;
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------
       
   156 // CPhoneKeys::IsSecondHashKey
       
   157 // Checks if keyevent is Second "#" key, i.e, "##".
       
   158 // ---------------------------------------------------------
       
   159 //
       
   160 EXPORT_C TBool CPhoneKeys::IsSecondHashKey(
       
   161     const TDes& aText )
       
   162     {
       
   163     TInt length = aText.Length();
       
   164     TBool result = EFalse;
       
   165 
       
   166     // * or # character entered
       
   167     if ( ( length >= KSecondKeyEvent ) 
       
   168         && ( aText[0] == KPhoneDtmfHashCharacter ) 
       
   169         && ( aText[1] == KPhoneDtmfHashCharacter ) )
       
   170         {
       
   171         result = ETrue;
       
   172         }
       
   173     
       
   174     __PHONELOG1( 
       
   175         EBasic, 
       
   176         EPhonePhoneapp, 
       
   177         "PhoneKeys::IsSecondHashKey: result: %d", 
       
   178         result );
       
   179         
       
   180     return result;
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // PhoneKeys::IsExtraChar
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 EXPORT_C TBool CPhoneKeys::IsExtraChar(
       
   188         TInt aChar )
       
   189     {
       
   190     TBool result = EFalse;
       
   191     switch( aChar )
       
   192         {
       
   193         case '*': // Asterisk
       
   194             // the following key can be got via taps of *
       
   195         case '+': // Plus
       
   196         case 'p': // P character
       
   197         case 'w': // W character
       
   198             result = ETrue;
       
   199             break;
       
   200         default:
       
   201             break;
       
   202         }
       
   203 
       
   204     return result;
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------
       
   208 // CPhoneKeys::Validate
       
   209 //
       
   210 // Go through the whole string and validate each character.
       
   211 // If character is invalid, check if we have reached end of
       
   212 // string (in which case, input.Peek() returns 0).
       
   213 // ---------------------------------------------------------
       
   214 //
       
   215 EXPORT_C TBool CPhoneKeys::Validate( const TDesC& aString )
       
   216     {
       
   217     TLex input( aString );
       
   218     TPtrC valid( KPhoneValidChars );
       
   219 
       
   220     while ( valid.Locate( input.Peek() ) != KErrNotFound )
       
   221         {
       
   222         input.Inc();
       
   223         }
       
   224     
       
   225     return !input.Remainder().Length();
       
   226     }
       
   227 
       
   228 //  End of File