securitydialogs/AutolockSrv/autolockuseractivityservice/stub/src/autolockuseractivityservice_p.cpp
branchGCC_SURGE
changeset 40 604cd42065d1
parent 29 b63e8c2d8cff
parent 38 e0432375ea67
equal deleted inserted replaced
29:b63e8c2d8cff 40:604cd42065d1
     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: autolockuseractivityservice_p.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 #include "autolockuseractivityservice.h"
       
    19 #include "autolockuseractivityservice_p.h"
       
    20 
       
    21 #include <QTimer>
       
    22 #include <QObject>
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 /*!
       
    27     Constructor.
       
    28     \param servicePublic public implementation.
       
    29 */
       
    30 AutolockUserActivityServicePrivate::AutolockUserActivityServicePrivate(AutolockUserActivityService *servicePublic) :
       
    31     m_q(servicePublic), mInactivityPeriod(9)
       
    32 {
       
    33     mActivityTimer = new QTimer();
       
    34     QObject::connect(mActivityTimer, SIGNAL(timeout()), m_q, SIGNAL(active()));
       
    35 
       
    36     mInactivityTimer = new QTimer();
       
    37     QObject::connect(mInactivityTimer, SIGNAL(timeout()), m_q, SIGNAL(notActive()));
       
    38 }
       
    39 
       
    40 /*!
       
    41     Destructor.
       
    42 */
       
    43 AutolockUserActivityServicePrivate::~AutolockUserActivityServicePrivate()
       
    44 {
       
    45     delete mActivityTimer;
       
    46     delete mInactivityTimer;
       
    47 }
       
    48 
       
    49 /*!
       
    50     Sets the inactivity period after which to emit signal of inactivity.
       
    51     \param seconds after which inactivity is detected.
       
    52 */
       
    53 void AutolockUserActivityServicePrivate::setInactivityPeriod(int seconds)
       
    54 {
       
    55     mInactivityPeriod = seconds;
       
    56     if (isWatching()) {
       
    57         mInactivityTimer->start(seconds * 1000);
       
    58     }
       
    59 }
       
    60 
       
    61 /*!
       
    62     Retrives the current inactivity period setting.
       
    63     \retval inactivity period set.
       
    64 */
       
    65 int AutolockUserActivityServicePrivate::inactivityPeriod() const
       
    66 {
       
    67     return mInactivityPeriod;
       
    68 }
       
    69 
       
    70 /*!
       
    71     Starts or stops activity manager user activity watching.
       
    72     \param shouldWatch determines if we shoul start watching or stop watching.
       
    73 */
       
    74 void AutolockUserActivityServicePrivate::watch(bool shouldWatch)
       
    75 {
       
    76     if (shouldWatch && !isWatching()) {
       
    77         mActivityTimer->start(5000);
       
    78         mInactivityTimer->start(mInactivityPeriod * 1000);
       
    79     } else if (!shouldWatch && isWatching()) {
       
    80         mActivityTimer->stop();
       
    81         mInactivityTimer->stop();
       
    82     }
       
    83 }
       
    84 
       
    85 /*!
       
    86     Checks if activity service is currently watching for user activity.
       
    87     \retval true if user acitivity service is active.
       
    88 */
       
    89 bool AutolockUserActivityServicePrivate::isWatching() const
       
    90 {
       
    91     return (mActivityTimer->isActive() || mInactivityTimer->isActive());
       
    92 }
       
    93 
       
    94