syncmlfw/syncmlnotifier/src/SyncMLTimedInputTextQuery.cpp
branchRCL_3
changeset 25 b183ec05bd8c
parent 24 13d7c31c74e0
child 26 19bba8228ff0
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
     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:  Implementation of the text input query with timeout timer.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "SyncMLTimedInputTextQuery.h"
       
    22 #include "SyncMLNotifDebug.h"
       
    23 
       
    24 // CONSTANTS
       
    25 const TInt  KSyncMLuSecsInSec   = 1000000; // Microseconds in a second
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CSyncMLTimedInputTextQuery::CSyncMLTimedInputTextQuery
       
    31 // C++ default constructor can NOT contain any code, that
       
    32 // might leave.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CSyncMLTimedInputTextQuery::CSyncMLTimedInputTextQuery( TDes& aDataText, TBool& aKeypress, TInt aTimeout )
       
    36     : CAknTextQueryDialog(aDataText, ENoTone),iTimeout( aTimeout ),iKeypress(aKeypress)
       
    37     {
       
    38     
       
    39     }
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CSyncMLTimedInputTextQuery::NewL
       
    43 // Two-phased constructor.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CSyncMLTimedInputTextQuery* CSyncMLTimedInputTextQuery::NewL( TDes& aDataText, const TDesC& aPromptText,
       
    47                                                               TBool& aKeypress, TInt  aTimeout )
       
    48     {
       
    49     CSyncMLTimedInputTextQuery* self =
       
    50         new( ELeave ) CSyncMLTimedInputTextQuery ( aDataText, aKeypress, aTimeout );
       
    51     
       
    52     CleanupStack::PushL( self );
       
    53     self->SetPromptL( aPromptText );//chenge to set prompt
       
    54     CleanupStack::Pop( self );
       
    55 
       
    56     return self;
       
    57     }
       
    58 
       
    59     
       
    60 // -----------------------------------------------------------------------------
       
    61 // CSyncMLTimedInputTextQuery::CSyncMLTimedInputTextQuery()
       
    62 // Destructor.
       
    63 // -----------------------------------------------------------------------------
       
    64 //
       
    65 CSyncMLTimedInputTextQuery::~CSyncMLTimedInputTextQuery()
       
    66     {
       
    67     if ( iTimer )
       
    68         {
       
    69         iTimer->Cancel();
       
    70         delete iTimer;
       
    71         iTimer = NULL;
       
    72         }
       
    73     }
       
    74  
       
    75 // -----------------------------------------------------------------------------
       
    76 // CSyncMLTimedInputTextQuery::OkToExitL
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 TBool CSyncMLTimedInputTextQuery::OkToExitL( TInt aButtonId )
       
    80     {
       
    81     if ( aButtonId == KErrTimedOut )
       
    82         {
       
    83         return ETrue;
       
    84         }
       
    85     return CAknTextQueryDialog::OkToExitL( aButtonId );
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CSyncMLTimedInputTextQuery::TimerExpired
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 void CSyncMLTimedInputTextQuery::TimerExpired()
       
    93     {
       
    94     if ( iTimer )
       
    95         {
       
    96         iTimer->Cancel();
       
    97         delete iTimer;
       
    98         iTimer = NULL;
       
    99         iTimeout = KSyncMLNNoAlphanumTimeout;
       
   100         }
       
   101     TRAPD( err, TryExitL( KErrTimedOut ) );
       
   102     
       
   103     if ( err != KErrNone )
       
   104         {
       
   105         FTRACE( FPrint(
       
   106             _L("[SmlNotif]\t CSyncMLTimedInputTextQuery::TimerExpired() TryExitL returned %d"),
       
   107             err ) );
       
   108         }
       
   109     }
       
   110     
       
   111 // -----------------------------------------------------------------------------
       
   112 // CSyncMLTimedInputTextQuery::PostLayoutDynInitL
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 void CSyncMLTimedInputTextQuery::PostLayoutDynInitL()
       
   116     {
       
   117     if ( iTimeout > KSyncMLNNoAlphanumTimeout )
       
   118         {
       
   119         iTimer = CSyncMLQueryTimer::NewL( this );
       
   120         iTimer->After( iTimeout * KSyncMLuSecsInSec );
       
   121         }
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CSyncMLTimedInputTextQuery::NeedToDismissQueryL
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 TBool CSyncMLTimedInputTextQuery::NeedToDismissQueryL(const TKeyEvent& aKeyEvent)
       
   129     {
       
   130     if (aKeyEvent.iCode == EKeyNo)
       
   131         {
       
   132         //CAknQueryControl* control = QueryControl();
       
   133         //if (control && control->QueryType() == EPinLayout)
       
   134           //  {
       
   135           iKeypress = ETrue;
       
   136             DismissQueryL();
       
   137             return ETrue;
       
   138             //}
       
   139         }
       
   140     return EFalse;
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CSyncMLTimedInputTextQuery::DismissQueryL
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CSyncMLTimedInputTextQuery::DismissQueryL()
       
   148 	{
       
   149 	 TryExitL(EEikBidCancel);
       
   150 	}
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CSyncMLTimedInputTextQuery::HandleQueryEditorStateEventL
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 TBool CSyncMLTimedInputTextQuery::HandleQueryEditorStateEventL( 
       
   157         CAknQueryControl* aQueryControl, TQueryControlEvent aEventType, 
       
   158         TQueryValidationStatus aStatus )
       
   159 	{
       
   160     if (aQueryControl)
       
   161         {
       
   162         if (EPhoneLayout == aQueryControl->QueryType())
       
   163             {
       
   164             if (aEventType == EEmergencyCallAttempted)
       
   165                 {
       
   166                 TryExitL(EEikBidCancel);
       
   167                 }
       
   168             else
       
   169                 {
       
   170 
       
   171                 TBuf<KSyncMLMaxDefaultResponseMsgLength> PhoneNo;
       
   172                 aQueryControl->GetText(PhoneNo);
       
   173                 TInt posplus = PhoneNo.LocateReverse('+');
       
   174                 if (posplus == 0 || posplus == KErrNotFound)
       
   175                     {
       
   176                     CAknQueryDialog::HandleQueryEditorStateEventL(
       
   177                             aQueryControl, aEventType, aStatus);
       
   178                     }
       
   179                 else
       
   180                     {
       
   181                     MakeLeftSoftkeyVisible(EFalse);
       
   182                     }
       
   183                 }
       
   184             }
       
   185 
       
   186         else //For all other layouts 
       
   187             {
       
   188             CAknQueryDialog::HandleQueryEditorStateEventL(aQueryControl,
       
   189                     aEventType, aStatus);
       
   190             }
       
   191         }
       
   192     return EFalse;
       
   193     }
       
   194 
       
   195 //  End of File