KIdleTime 5.109.0
kidletime.h
1/* This file is part of the KDE libraries
2 * SPDX-FileCopyrightText: 2009 Dario Freddi <drf at kde.org>
3 * SPDX-FileCopyrightText: 2021 Harald Sitter <sitter@kde.org>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8#ifndef KIDLETIME_H
9#define KIDLETIME_H
10
11#include <QHash>
12#include <QObject>
13#include <kidletime_export.h>
14#include <memory>
15
16#if __has_include(<chrono>)
17#include <chrono>
18#endif
19
20class KIdleTimePrivate;
21
36class KIDLETIME_EXPORT KIdleTime : public QObject
37{
38 Q_OBJECT
39 Q_DECLARE_PRIVATE(KIdleTime)
40 Q_DISABLE_COPY(KIdleTime)
41
42public:
49
53 ~KIdleTime() override;
54
60 int idleTime() const;
61
70 QHash<int, int> idleTimeouts() const;
71
80
81public Q_SLOTS:
98 int addIdleTimeout(int msec);
99
100#if __has_include(<chrono>)
105 int addIdleTimeout(std::chrono::milliseconds msec)
106 {
107 return addIdleTimeout(int(msec.count()));
108 }
109#endif
110
118 void removeIdleTimeout(int identifier);
119
128
147
158
159Q_SIGNALS:
167
168#if KIDLETIME_ENABLE_DEPRECATED_SINCE(5, 76)
182 KIDLETIME_DEPRECATED_VERSION(5, 76, "Use only timeoutReached(int identifier, int msec)")
183 void timeoutReached(int identifier); // clazy:exclude=overloaded-signal
184#endif
185
199 void timeoutReached(int identifier, int msec); // clazy:exclude=overloaded-signal
200
201private:
202 KIDLETIME_NO_EXPORT KIdleTime();
203
204 std::unique_ptr<KIdleTimePrivate> const d_ptr;
205};
206
207#endif /* KIDLETIME_H */
KIdleTime is a singleton reporting information on idle time.
Definition kidletime.h:37
void catchNextResumeEvent()
Catches the next resume from idle event.
int addIdleTimeout(int msec)
Adds a new timeout to catch.
int idleTime() const
Retrieves the idle time of the system, in milliseconds.
void timeoutReached(int identifier, int msec)
Triggered when the system has been idle for x milliseconds, identified by the previously set timeout.
void resumingFromIdle()
Triggered, if KIdleTime is catching resume events, when the system resumes from an idle state.
~KIdleTime() override
The destructor.
void simulateUserActivity()
Attempts to simulate user activity.
void stopCatchingResumeEvent()
Stops listening for resume event.
void removeIdleTimeout(int identifier)
Stops catching the idle timeout identified by the token identifier, if it was registered earlier with...
void removeAllIdleTimeouts()
Stops catching every set timeout (if any).
static KIdleTime * instance()
Returns the singleton instance.
QHash< int, int > idleTimeouts() const
Returns the list of timeout identifiers associated with their duration, in milliseconds,...