mmsharing/mmshui/src/musuiactivitymanger.cpp
branchRCL_3
changeset 33 bc78a40cd63c
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
       
     1 /*
       
     2 * Copyright (c) 2005 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "musuiactivitymanger.h"
       
    21 #include "muslogger.h" // debug logging
       
    22 
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 //
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 CMusUiActivityManager* CMusUiActivityManager::NewL( TInt aTimeout )
       
    29 
       
    30     {
       
    31     CMusUiActivityManager* self = 
       
    32                                  new (ELeave) CMusUiActivityManager( aTimeout );
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop(self);
       
    36     return self;
       
    37     }
       
    38 
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CMusUiActivityManager::~CMusUiActivityManager()
       
    45     {
       
    46     MUS_LOG( "mus: [MUSUI ]  -> CMusUiActivityManager::~CMusUiActivityManager" );
       
    47     Cancel();
       
    48     iTimer.Close();
       
    49     MUS_LOG( "mus: [MUSUI ]  <- CMusUiActivityManager::~CMusUiActivityManager" );
       
    50     }
       
    51 
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CMusUiActivityManager::CMusUiActivityManager( TInt aTimeout )
       
    58                 : CActive( CActive::EPriorityHigh ),
       
    59                   iTimeout( aTimeout )
       
    60 
       
    61     {
       
    62     CActiveScheduler::Add(this);
       
    63     }
       
    64 
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void CMusUiActivityManager::ConstructL()
       
    71     {
       
    72     MUS_LOG( "mus: [MUSUI ]  -> CMusUiActivityManager::ConstructL" );
       
    73     iTimer.CreateLocal();
       
    74     MUS_LOG( "mus: [MUSUI ]  <- CMusUiActivityManager::ConstructL" );
       
    75     }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CMusUiActivityManager::SetTimeout( TInt aTimeout )
       
    83     {
       
    84     MUS_LOG1( "mus: [MUSUI ]     -> CMusUiActivityManager::SetTimeout [%d]", aTimeout );
       
    85     iTimeout = aTimeout;
       
    86     Reset();
       
    87     MUS_LOG( "mus: [MUSUI ]  <- CMusUiActivityManager::SetTimeout" );
       
    88     }
       
    89 
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CMusUiActivityManager::Start()
       
    96     {
       
    97     MUS_LOG( "mus: [MUSUI ]  -> CMusUiActivityManager::Start" );
       
    98     if (!IsActive())
       
    99         {
       
   100         iTimer.Inactivity( iStatus, iTimeout );
       
   101         SetActive();
       
   102         }
       
   103     MUS_LOG( "mus: [MUSUI ]  <- CMusUiActivityManager::Start" );
       
   104     }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 //
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 void CMusUiActivityManager::Reset()
       
   112     {
       
   113     MUS_LOG( "mus: [MUSUI ]  -> CMusUiActivityManager::Reset" );
       
   114     Cancel();
       
   115     Start();
       
   116     MUS_LOG( "mus: [MUSUI ]  <- CMusUiActivityManager::Reset" );
       
   117     }
       
   118 
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void CMusUiActivityManager::DoCancel()
       
   125     {
       
   126     MUS_LOG( "mus: [MUSUI ]  -> CMusUiActivityManager::DoCancel" );
       
   127     iTimer.Cancel();
       
   128     MUS_LOG( "mus: [MUSUI ]  <- CMusUiActivityManager::DoCancel" );
       
   129     }
       
   130 
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CMusUiActivityManager::RunL()
       
   137     {
       
   138 
       
   139     MUS_LOG( "mus: [MUSUI ]  -> CMusUiActivityManager::RunL" );
       
   140     
       
   141     if ( iStatus == KErrNone )
       
   142         {
       
   143         
       
   144         TInt inactivity = User::InactivityTime().Int();
       
   145 
       
   146         if ( inactivity >= iTimeout )
       
   147             {
       
   148             User::ResetInactivityTime();
       
   149             Reset();  
       
   150             }
       
   151         else
       
   152             {
       
   153             iTimer.Inactivity( iStatus, iTimeout );
       
   154             }
       
   155                
       
   156         if ( !IsActive() )
       
   157             {
       
   158             SetActive();
       
   159             }
       
   160 
       
   161         }   
       
   162 
       
   163     MUS_LOG( "mus: [MUSUI ]  <- CMusUiActivityManager::RunL" );
       
   164     }
       
   165 
       
   166 // -------------------------------------------------------------------------
       
   167 //  If RunL() leaves,It should be handled here.
       
   168 // -------------------------------------------------------------------------
       
   169 //
       
   170 TInt CMusUiActivityManager::RunError( TInt aError )
       
   171     {
       
   172 	MUS_LOG( "mus: [MUSUI ]  -> CMusUiActivityManager::RunError" );
       
   173     // Nothing can be done here.
       
   174     aError = KErrNone;
       
   175 
       
   176     MUS_LOG( "mus: [MUSUI ]  <- CMusUiActivityManager::RunError" );
       
   177     return aError;
       
   178     }
       
   179 
       
   180 
       
   181 // end of file