Commit 5fe73c52 authored by Karel Slaný's avatar Karel Slaný
Browse files

Added Locker::setInactivityInterval().

parent a3686334
......@@ -42,11 +42,11 @@
Locker::Locker(QObject *parent)
: QObject(parent),
m_inactivityInterval(0),
m_inactivityTimer(),
m_ignoreImmediateSuspension(false)
{
m_inactivityTimer.setInterval(10000); /* 10 s */
m_inactivityTimer.start();
/* Don't start time yet. */
connect(&m_inactivityTimer, SIGNAL(timeout()),
this, SLOT(inactivityTimeOut()));
......@@ -57,6 +57,18 @@ void Locker::ignoreNextSuspension(void)
m_ignoreImmediateSuspension = true;
}
void Locker::setInactivityInterval(int secs)
{
m_inactivityTimer.stop();
if (secs > 0) {
m_inactivityInterval = secs;
m_inactivityTimer.setInterval(m_inactivityInterval * 1000);
m_inactivityTimer.start();
} else {
m_inactivityInterval = 0;
}
}
void Locker::processNewState(Qt::ApplicationState state)
{
switch (state) {
......@@ -95,8 +107,10 @@ bool Locker::eventFilter(QObject *watched, QEvent *event)
case QEvent::MouseMove:
case QEvent::KeyPress:
case QEvent::TouchBegin:
m_inactivityTimer.stop(); /* Reset the timer. */
m_inactivityTimer.start();
if (m_inactivityInterval > 0) {
m_inactivityTimer.stop(); /* Reset the timer. */
m_inactivityTimer.start();
}
break;
default:
/* Do nothing. */
......
......@@ -51,6 +51,14 @@ public:
Q_INVOKABLE
void ignoreNextSuspension(void);
/*!
* @brief Set inactivity locking interval in seconds.
*
* @param[in] secs Interval length in seconds.
*/
Q_INVOKABLE
void setInactivityInterval(int secs);
public slots:
/*!
* @brief Processes supplied application state. Emits lockApp signal
......@@ -76,13 +84,17 @@ protected:
* inactivity timer on those events.
*
* @param[in] watched Watched object.
* @param[in] event Incomming event.
* @param[in] event Incoming event.
* @return Returns whatever the parent class would return.
*/
virtual
bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;
private:
int m_inactivityInterval; /*!<
* Interval length in seconds, value less or
* equal to 0 is off.
*/
QTimer m_inactivityTimer; /*!< Inactivity timer. */
bool m_ignoreImmediateSuspension; /*!<
* Set true if next suspension should
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment