mmsharing/livecommsui/lcuiengine/src/lcactivitymanager.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     1 /*
       
     2 * Copyright (c) 2009 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 //  INCLUDES
       
    19 #include <e32base.h>
       
    20 #include <centralrepository.h>
       
    21 #include <hwrmlightdomaincrkeys.h>
       
    22 #include <QtCore>
       
    23 #include "lcactivitymanager.h"
       
    24 #include "lclogger.h"
       
    25 
       
    26 
       
    27 const int lcDefaultInactivityTimeout = 5; //timeout in seconds, used if fetching 
       
    28                                           //value from cenrep fails
       
    29 const int lcInvalidTimerId = -1;
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 LcActivityManager::LcActivityManager() : 
       
    36     mTimerId(lcInvalidTimerId)
       
    37 {
       
    38     if (initInactivityTimeout() != 0) {
       
    39         mInactivityTimeout = lcDefaultInactivityTimeout;
       
    40     }    
       
    41 }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 LcActivityManager::~LcActivityManager()
       
    48 {
       
    49     stopTimer();
       
    50 }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void LcActivityManager::enableActivitySimulation(bool enable)
       
    57 {
       
    58     if (enable) {
       
    59         restartTimer();
       
    60     } else {
       
    61         stopTimer();
       
    62     }
       
    63 }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 bool LcActivityManager::isActivitySimulationEnabled()
       
    70 {
       
    71     return (mTimerId != lcInvalidTimerId);
       
    72 }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 int LcActivityManager::initInactivityTimeout()
       
    79 {
       
    80     CRepository* repository = 0;
       
    81     TRAPD(err, repository = CRepository::NewL(KCRUidLightSettings));
       
    82     if (err == KErrNone) {
       
    83         // Let's fetching display light timeout value (in seconds )
       
    84         TInt displayTimeOut(0);
       
    85         err = repository->Get(KDisplayLightsTimeout, displayTimeOut);
       
    86         if (displayTimeOut > 2) {
       
    87             //taking away 2 seconds just in case, to ensure we keep
       
    88             //simulating user activity frequently enough
       
    89             displayTimeOut -= 2;
       
    90         }
       
    91         mInactivityTimeout = displayTimeOut;
       
    92     }
       
    93     delete repository;
       
    94     return err;
       
    95 }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 void LcActivityManager::stopTimer()
       
   102 {
       
   103     if (mTimerId != lcInvalidTimerId) {
       
   104         killTimer(mTimerId);
       
   105         mTimerId = lcInvalidTimerId;
       
   106     }
       
   107 }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void LcActivityManager::restartTimer()
       
   114 {
       
   115     stopTimer();
       
   116 
       
   117     int timeLeftInSeconds = mInactivityTimeout - User::InactivityTime().Int();
       
   118     if ( timeLeftInSeconds < 1 ) {
       
   119         User::ResetInactivityTime();
       
   120         timeLeftInSeconds = mInactivityTimeout;
       
   121     }
       
   122     
       
   123     LC_QDEBUG_2( "livecomms [UI] -> LcActivityManager::startTimer(), interval: ", timeLeftInSeconds);
       
   124     
       
   125     mTimerId = startTimer(timeLeftInSeconds*1000);
       
   126 }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void LcActivityManager::timerEvent(QTimerEvent* event)
       
   133 {
       
   134     if (event->timerId() == mTimerId) {
       
   135         LC_QDEBUG( "livecomms [UI] -> LcActivityManager::timerEvent()" );
       
   136         restartTimer(); 
       
   137     }
       
   138 }