File indexing completed on 2024-10-13 03:37:42

0001 /*
0002  * SPDX-FileCopyrightText: 2009 Dario Freddi <drf@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "KIdleTest.h"
0008 #include <QDebug>
0009 
0010 #include "kidletime.h"
0011 
0012 //@@snippet_begin(initialize)
0013 KIdleTest::KIdleTest()
0014 {
0015     // connect to idle events
0016     connect(KIdleTime::instance(), &KIdleTime::resumingFromIdle, this, &KIdleTest::resumeEvent);
0017     connect(KIdleTime::instance(), qOverload<int, int>(&KIdleTime::timeoutReached), this, &KIdleTest::timeoutReached);
0018 
0019     // register to get informed for the very next user event
0020     KIdleTime::instance()->catchNextResumeEvent();
0021 
0022     printf("Your idle time is %d\n", KIdleTime::instance()->idleTime());
0023     printf("Welcome!! Move your mouse or do something to start...\n");
0024 }
0025 //@@snippet_end
0026 
0027 KIdleTest::~KIdleTest()
0028 {
0029 }
0030 
0031 //@@snippet_begin(resumeEvent)
0032 void KIdleTest::resumeEvent()
0033 {
0034     KIdleTime::instance()->removeAllIdleTimeouts();
0035 
0036     printf("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");
0037     printf("If you will stay idle for too long, I will simulate your activity after 25 seconds, and make everything start back\n");
0038 
0039     KIdleTime::instance()->addIdleTimeout(5000);
0040     KIdleTime::instance()->addIdleTimeout(10000);
0041     KIdleTime::instance()->addIdleTimeout(25000);
0042 }
0043 //@@snippet_end
0044 
0045 //@@snippet_begin(timeoutReached)
0046 void KIdleTest::timeoutReached(int id, int timeout)
0047 {
0048     Q_UNUSED(id)
0049 
0050     if (timeout == 5000) {
0051         printf("5 seconds passed, stay still some more...\n");
0052     } else if (timeout == 10000) {
0053         KIdleTime::instance()->catchNextResumeEvent();
0054         printf("Cool. You can move your mouse to start over\n");
0055     } else if (timeout == 25000) {
0056         printf("Uff, you're annoying me. Let's start again. I'm simulating your activity now\n");
0057         KIdleTime::instance()->simulateUserActivity();
0058     } else {
0059         qDebug() << "OUCH";
0060     }
0061 }
0062 //@@snippet_end
0063 
0064 #include "moc_KIdleTest.cpp"