locker.h 2.91 KB
Newer Older
Karel Slaný's avatar
Karel Slaný committed
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
Karel Slaný's avatar
Karel Slaný committed
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Karel Slaný's avatar
Karel Slaný committed
16 17 18 19 20 21 22 23
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

24
#pragma once
Karel Slaný's avatar
Karel Slaný committed
25 26

#include <QObject>
27
#include <QTimer>
Karel Slaný's avatar
Karel Slaný committed
28

29 30 31
/*!
 * @brief Application locker class.
 */
Karel Slaný's avatar
Karel Slaný committed
32 33 34
class Locker : public QObject {
	Q_OBJECT
public:
35 36 37 38 39
	/*!
	 * @brief Constructor.
	 *
	 * @param[in] parent Parent object.
	 */
40
	explicit Locker(QObject *parent = Q_NULLPTR);
Karel Slaný's avatar
Karel Slaný committed
41

42 43 44 45 46 47 48 49 50 51 52
	/*!
	 * @brief Sets internal flag. Following immediate application
	 *     suspension call will be ignored.
	 *
	 * @note This is useful when the control is handed over to another
	 *     application (e.g. when opening an attachment in associated
	 *     application).
	 */
	Q_INVOKABLE
	void ignoreNextSuspension(void);

53 54 55 56 57 58 59 60
	/*!
	 * @brief Set inactivity locking interval in seconds.
	 *
	 * @param[in] secs Interval length in seconds.
	 */
	Q_INVOKABLE
	void setInactivityInterval(int secs);

Karel Slaný's avatar
Karel Slaný committed
61
public slots:
62
	/*!
63 64 65
	 * @brief Processes supplied application state. Calls
	 *     inactivityTimeOut() if suspension state achieved which should
	 *     not be ignored.
66
	 */
Karel Slaný's avatar
Karel Slaný committed
67 68
	void processNewState(Qt::ApplicationState state);

69 70
private slots:
	/*!
71
	 * @brief Emits lockApp signal if PIN is set.
72 73 74
	 */
	void inactivityTimeOut(void);

Karel Slaný's avatar
Karel Slaný committed
75
signals:
76 77 78
	/*!
	 * @brief Signal emitted when the application should be locked.
	 */
Karel Slaný's avatar
Karel Slaný committed
79
	void lockApp(void);
80 81 82 83 84 85 86

protected:
	/*!
	 * @brief Watches for MouseMove, KeyPress and TouchBegin events. Resets
	 *     inactivity timer on those events.
	 *
	 * @param[in] watched Watched object.
87
	 * @param[in] event Incoming event.
88 89 90 91 92 93
	 * @return Returns whatever the parent class would return.
	 */
	virtual
	bool eventFilter(QObject *watched, QEvent *event) Q_DECL_OVERRIDE;

private:
94 95 96 97
	int m_inactivityInterval; /*!<
	                           * Interval length in seconds, value less or
	                           * equal to 0 is off.
	                           */
98
	QTimer m_inactivityTimer; /*!< Inactivity timer. */
99 100 101 102
	bool m_ignoreImmediateSuspension; /*!<
	                                   * Set true if next suspension should
	                                   * be ignored.
	                                   */
Karel Slaný's avatar
Karel Slaný committed
103
};