1/*
2 * SPDX-FileCopyrightText: 2009 Dario Freddi <drf@kde.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "KIdleTest.h"
8#include <QDebug>
9
10#include "kidletime.h"
11
12//@@snippet_begin(initialize)
13KIdleTest::KIdleTest()
14{
15 // connect to idle events
16 connect(sender: KIdleTime::instance(), signal: &KIdleTime::resumingFromIdle, context: this, slot: &KIdleTest::resumeEvent);
17 connect(sender: KIdleTime::instance(), signal: qOverload<int, int>(&KIdleTime::timeoutReached), context: this, slot: &KIdleTest::timeoutReached);
18
19 // register to get informed for the very next user event
20 KIdleTime::instance()->catchNextResumeEvent();
21
22 printf(format: "Your idle time is %d\n", KIdleTime::instance()->idleTime());
23 printf(format: "Welcome!! Move your mouse or do something to start...\n");
24}
25//@@snippet_end
26
27KIdleTest::~KIdleTest()
28{
29}
30
31//@@snippet_begin(resumeEvent)
32void KIdleTest::resumeEvent()
33{
34 KIdleTime::instance()->removeAllIdleTimeouts();
35
36 printf(format: "Great! Now stay idle for 5 seconds to get a nice message. From 10 seconds on, you can move your mouse to get back here.\n");
37 printf(format: "If you will stay idle for too long, I will simulate your activity after 25 seconds, and make everything start back\n");
38
39 KIdleTime::instance()->addIdleTimeout(msec: 5000);
40 KIdleTime::instance()->addIdleTimeout(msec: 10000);
41 KIdleTime::instance()->addIdleTimeout(msec: 25000);
42}
43//@@snippet_end
44
45//@@snippet_begin(timeoutReached)
46void KIdleTest::timeoutReached(int id, int timeout)
47{
48 Q_UNUSED(id)
49
50 if (timeout == 5000) {
51 printf(format: "5 seconds passed, stay still some more...\n");
52 } else if (timeout == 10000) {
53 KIdleTime::instance()->catchNextResumeEvent();
54 printf(format: "Cool. You can move your mouse to start over\n");
55 } else if (timeout == 25000) {
56 printf(format: "Uff, you're annoying me. Let's start again. I'm simulating your activity now\n");
57 KIdleTime::instance()->simulateUserActivity();
58 } else {
59 qDebug() << "OUCH";
60 }
61}
62//@@snippet_end
63
64#include "moc_KIdleTest.cpp"
65

source code of kidletime/examples/KIdleTest.cpp