KIdleTime 5.109.0
Signals | Public Slots | Public Member Functions | Static Public Member Functions | List of all members
KIdleTime

KIdleTime is a singleton reporting information on idle time. More...

#include <KIdleTime>

Signals

void resumingFromIdle ()
 Triggered, if KIdleTime is catching resume events, when the system resumes from an idle state.
 
void timeoutReached (int identifier)
 Triggered when the system has been idle for x milliseconds, identified by the previously set timeout.
 
void timeoutReached (int identifier, int msec)
 Triggered when the system has been idle for x milliseconds, identified by the previously set timeout.
 

Public Slots

int addIdleTimeout (int msec)
 Adds a new timeout to catch.
 
void catchNextResumeEvent ()
 Catches the next resume from idle event.
 
void removeAllIdleTimeouts ()
 Stops catching every set timeout (if any).
 
void removeIdleTimeout (int identifier)
 Stops catching the idle timeout identified by the token identifier, if it was registered earlier with addIdleTimeout.
 
void stopCatchingResumeEvent ()
 Stops listening for resume event.
 

Public Member Functions

 ~KIdleTime () override
 The destructor.
 
int idleTime () const
 Retrieves the idle time of the system, in milliseconds.
 
QHash< int, int > idleTimeouts () const
 Returns the list of timeout identifiers associated with their duration, in milliseconds, the library is currently listening to.
 
void simulateUserActivity ()
 Attempts to simulate user activity.
 

Static Public Member Functions

static KIdleTimeinstance ()
 Returns the singleton instance.
 

Detailed Description

KIdleTime is a singleton reporting information on idle time.

It is useful not only for finding out about the current idle time of the PC, but also for getting notified upon idle time events, such as custom timeouts, or user activity.

Note
All the intervals and times in this library are in milliseconds, unless specified otherwise
Author
Dario Freddi
Since
4.4

Constructor & Destructor Documentation

◆ ~KIdleTime()

KIdleTime::~KIdleTime ( )
override

The destructor.

Member Function Documentation

◆ addIdleTimeout

int KIdleTime::addIdleTimeout ( int  msec)
slot

Adds a new timeout to catch.

When calling this method, after the system will be idle for msec milliseconds, the signal timeoutReached will be triggered. Please note that until you will call removeIdleTimeout or removeAllIdleTimeouts, the signal will be triggered every time the system will be idle for msec milliseconds. This function also returns an unique token for the timeout just added to allow easier identification.

Parameters
msecthe time, in milliseconds, after which the signal will be triggered
Returns
an unique identifier for the timeout being added, that will be streamed by timeoutReached
See also
removeIdleTimeout
removeAllIdleTimeouts
timeoutReached

◆ catchNextResumeEvent

void KIdleTime::catchNextResumeEvent ( )
slot

Catches the next resume from idle event.

This means that whenever user activity will be registered, or simulateUserActivity is called, the signal resumingFromIdle will be triggered.

Please note that this method will trigger the signal just for the very first resume event after the call: this means you explicitly have to request to track every single resume event you are interested in.

Note
This behavior is due to the fact that a resume event happens whenever the user sends an input to the system. This would lead to a massive amount of signals being delivered when the PC is being used. Moreover, you are usually interested in catching just significant resume events, such as the ones after a significant period of inactivity. For tracking user input, you can use the more efficient methods provided by Qt. The purpose of this library is just monitoring the activity of the user.
See also
resumingFromIdle
simulateUserActivity

◆ idleTime()

int KIdleTime::idleTime ( ) const

Retrieves the idle time of the system, in milliseconds.

Returns
the idle time of the system

◆ idleTimeouts()

QHash< int, int > KIdleTime::idleTimeouts ( ) const

Returns the list of timeout identifiers associated with their duration, in milliseconds, the library is currently listening to.

See also
addIdleTimeout
removeIdleTimeout
timeoutReached

◆ instance()

static KIdleTime * KIdleTime::instance ( )
static

Returns the singleton instance.

Use this method to access KIdleTime

Returns
the instance of KIdleTime

◆ removeAllIdleTimeouts

void KIdleTime::removeAllIdleTimeouts ( )
slot

Stops catching every set timeout (if any).

This means that after calling this method, the signal timeoutReached won't be called again until you will add another timeout

See also
timeoutReached
addIdleTimeout

◆ removeIdleTimeout

void KIdleTime::removeIdleTimeout ( int  identifier)
slot

Stops catching the idle timeout identified by the token identifier, if it was registered earlier with addIdleTimeout.

Otherwise does nothing.

Parameters
identifierthe token returned from addIdleTimeout of the timeout you want to stop listening to

◆ resumingFromIdle

void KIdleTime::resumingFromIdle ( )
signal

Triggered, if KIdleTime is catching resume events, when the system resumes from an idle state.

This means that either simulateUserActivity was called or the user sent an input to the system.

See also
catchNextResumeEvent

◆ simulateUserActivity()

void KIdleTime::simulateUserActivity ( )

Attempts to simulate user activity.

This implies that after calling this method, the idle time of the system will become 0 and eventually resumingFromIdle will be triggered

See also
resumingFromIdle

◆ stopCatchingResumeEvent

void KIdleTime::stopCatchingResumeEvent ( )
slot

Stops listening for resume event.

This function serves for canceling catchNextResumeEvent, as it will have effect just when catchNextResumeEvent has been called and resumingFromIdle not yet triggered

See also
resumingFromIdle
catchNextResumeEvent

◆ timeoutReached [1/2]

void KIdleTime::timeoutReached ( int  identifier)
signal

Triggered when the system has been idle for x milliseconds, identified by the previously set timeout.

This signal is triggered whenever each timeout previously registered with addIdleTimeout is reached.

Parameters
identifierthe identifier of the timeout the system has reached
See also
addIdleTimeout
removeIdleTimeout
Deprecated:
Since 5.76, use only timeoutReached(int identifier, int msec)

◆ timeoutReached [2/2]

void KIdleTime::timeoutReached ( int  identifier,
int  msec 
)
signal

Triggered when the system has been idle for x milliseconds, identified by the previously set timeout.

This signal is triggered whenever each timeout previously registered with addIdleTimeout(int) is reached. It is guaranteed that msec will exactly correspond to the identified timeout.

Parameters
identifierthe identifier of the timeout the system has reached
msecthe time, in milliseconds, the system has been idle for
See also
addIdleTimeout
removeIdleTimeout