aboutsummaryrefslogtreecommitdiff
path: root/src/autolockeventfilter.h
diff options
context:
space:
mode:
authorLibravatar Keshav Bhatt <keshavnrj@gmail.com>2022-03-30 17:30:58 +0530
committerLibravatar Keshav Bhatt <keshavnrj@gmail.com>2022-03-30 17:30:58 +0530
commitd06a4abb4755d0e97e8ef03688bc878117d90b4e (patch)
treeace02b248a88ccd08dabee8b9ddc751fb40bb776 /src/autolockeventfilter.h
parent5be4cae996d0411f4ab50af66d95452bf3a6022e (diff)
downloadwhatsie-d06a4abb4755d0e97e8ef03688bc878117d90b4e.tar.gz
whatsie-d06a4abb4755d0e97e8ef03688bc878117d90b4e.zip
feat: app auto locking
- settings to allow app auto locking after set time interval
Diffstat (limited to 'src/autolockeventfilter.h')
-rw-r--r--src/autolockeventfilter.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/autolockeventfilter.h b/src/autolockeventfilter.h
new file mode 100644
index 0000000..2f05504
--- /dev/null
+++ b/src/autolockeventfilter.h
@@ -0,0 +1,48 @@
+#ifndef AUTOLOCKEVENTFILTER_H
+#define AUTOLOCKEVENTFILTER_H
+
+#include <QDebug>
+#include <QEvent>
+#include <QTimer>
+
+class AutoLockEventFilter : public QObject {
+ Q_OBJECT
+
+public:
+ explicit AutoLockEventFilter(int timeoutmillis)
+ : timeoutmillis(timeoutmillis) {
+ autoLockTimer = new QTimer(this);
+ connect(autoLockTimer, &QTimer::timeout, this,
+ QOverload<>::of(&AutoLockEventFilter::lockApp));
+ resetTimer();
+ }
+
+ ~AutoLockEventFilter() {
+ autoLockTimer->stop();
+ autoLockTimer->deleteLater();
+ }
+
+signals:
+ void autoLockTimerTimeout();
+
+private:
+ QTimer *autoLockTimer = nullptr;
+ int timeoutmillis;
+
+public slots:
+ void stopTimer() { autoLockTimer->stop(); }
+ void resetTimer() { autoLockTimer->start(timeoutmillis); }
+ void lockApp() { emit autoLockTimerTimeout(); }
+ void setTimeoutmillis(int newTimeoutmillis) {
+ timeoutmillis = newTimeoutmillis;
+ }
+
+protected:
+ bool eventFilter(QObject *obj, QEvent *ev) {
+ if (ev->type() == QEvent::KeyPress || ev->type() == QEvent::MouseMove) {
+ resetTimer();
+ }
+ return QObject::eventFilter(obj, ev);
+ }
+};
+#endif // AUTOLOCKEVENTFILTER_H