appinstaller/AppinstUi/Plugin/CommonUI/Src/CUICancelTimer.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2002-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:   This file contains the implementation of CCUICancelTimer
       
    15 *                class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <eikenv.h>
       
    22 
       
    23 #include "CUICancelTimer.h"
       
    24 
       
    25 using namespace SwiUI::CommonUI;
       
    26 
       
    27 const TInt KCancelTries = 4;
       
    28 const TInt KCancelFirstTryInterval = 1; // 1us
       
    29 const TInt KCancelTryInterval = 500000; // 0,5 sec
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CCUICancelTimer::CCUICancelTimer
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CCUICancelTimer::CCUICancelTimer( MCUICancellable* aCancellable )
       
    40     : CTimer( CActive::EPriorityHigh ),
       
    41       iCancellable( aCancellable ),
       
    42       iTryCount( KCancelTries )
       
    43     {
       
    44     CActiveScheduler::Add( this );    
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CCUICancelTimer::ConstructL
       
    49 // Symbian 2nd phase constructor can leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CCUICancelTimer::ConstructL()
       
    53     {    
       
    54     CTimer::ConstructL(); 
       
    55     iEikEnv = CEikonEnv::Static();    
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CCUICancelTimer::NewL
       
    60 // Two-phased constructor.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 EXPORT_C CCUICancelTimer* CCUICancelTimer::NewL( MCUICancellable* aCancellable )
       
    64     {
       
    65     CCUICancelTimer* self = new( ELeave ) CCUICancelTimer( aCancellable );
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL();
       
    68     CleanupStack::Pop( self );
       
    69     return self;    
       
    70     }
       
    71     
       
    72 // Destructor
       
    73 EXPORT_C CCUICancelTimer::~CCUICancelTimer()
       
    74     {
       
    75     Cancel();    
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CCUICancelTimer::InstallL
       
    80 // Perform installation.
       
    81 // (other items were commented in a header).
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 EXPORT_C void CCUICancelTimer::StartCancelling()
       
    85     {
       
    86     iCancellable->StartedCancellingL();
       
    87     iCancellable->CancelEngine();
       
    88     if ( iCancellable->IsShowingDialog() )
       
    89         {
       
    90         TKeyEvent key;
       
    91         key.iRepeats = 0;
       
    92         key.iCode = EKeyEscape;
       
    93         key.iModifiers = 0;
       
    94         iEikEnv->SimulateKeyEventL( key, EEventKey );
       
    95         }  
       
    96     iTryCount--;
       
    97     TTimeIntervalMicroSeconds32 timeout( KCancelFirstTryInterval );
       
    98     After( timeout );    
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CCUICancelTimer::RunL
       
   103 // Called when timer has triggered.
       
   104 // (other items were commented in a header).
       
   105 // -----------------------------------------------------------------------------
       
   106 //    
       
   107 void CCUICancelTimer::RunL()
       
   108     {
       
   109     if ( --iTryCount >= 0 )
       
   110         {
       
   111         iCancellable->CancelEngine();
       
   112         if ( iCancellable->IsShowingDialog() )
       
   113             {
       
   114             TKeyEvent key;
       
   115             key.iRepeats = 0;
       
   116             key.iCode = EKeyEscape;
       
   117             key.iModifiers = 0;
       
   118             iEikEnv->SimulateKeyEventL( key, EEventKey );
       
   119             }  
       
   120         TTimeIntervalMicroSeconds32 timeout( KCancelTryInterval );
       
   121         After( timeout );        
       
   122         }    
       
   123     else if ( iCancellable->IsShowingDialog() )
       
   124         {
       
   125         // In this case we we are still showing a dialog, even we have tried
       
   126         // to dismiss it. So force the cancel
       
   127         iCancellable->ForceCancel();
       
   128         }    
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CCUICancelTimer::RunError
       
   133 // Handles a leave occurring in the request completion event handler RunL().
       
   134 // (other items were commented in a header).
       
   135 // -----------------------------------------------------------------------------
       
   136 // 
       
   137 TInt CCUICancelTimer::RunError( TInt /*aError*/ )
       
   138     {
       
   139     iCancellable->ForceCancel();    
       
   140 
       
   141     return KErrNone;    
       
   142     }
       
   143 
       
   144 //  End of File