2 * Copyright (C) 2003 by Scott Monachello <smonach@cox.net>
3 * 2007 the ktimetracker developers
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the
17 * Free Software Foundation, Inc.
18 * 51 Franklin Street, Fifth Floor
19 * Boston, MA 02110-1301 USA.
23 #ifndef KTIMETRACKER_IDLE_TIME_DETECTOR_H
24 #define KTIMETRACKER_IDLE_TIME_DETECTOR_H
26 #include "ktimetrackerutility.h" // SecsPerMinute
29 #include <config-ktimetracker.h> // HAVE_LIBXSS
33 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
35 #include <X11/Xutil.h>
36 #include <X11/extensions/scrnsaver.h>
40 // Minutes between each idle overrun test.
41 const int testInterval
= secsPerMinute
* 1000;
44 * Keep track of how long the computer has been idle.
47 class IdleTimeDetector
:public QObject
53 Initializes and idle test timer
54 @param maxIdle minutes before the idle timer will go off.
56 IdleTimeDetector(int maxIdle
);
59 Returns true if it is possible to do idle detection.
60 Idle detection relys on a feature in the X server, which might not
63 bool isIdleDetectionPossible();
67 Tells the listener to extract time from current timing.
68 The time to extract is due to the idle time since the dialog wass
69 shown, and until the user answers the dialog.
70 @param minutes Minutes to extract.
72 void extractTime(int minutes
);
75 Tells the listener to stop timing
77 void stopAllTimers(QDateTime time
);
83 Sets the maximum allowed idle.
84 @param maxIdle Maximum allowed idle time in minutes
86 void setMaxIdle(int maxIdle
);
89 Starts detecting idle time
91 void startIdleDetection();
94 Stops detecting idle time.
96 void stopIdleDetection();
99 Sets whether idle detection should be done at all
100 @param on If true idle detection is done based on
101 startIdleDetection and @ref stopIdleDetection
103 void toggleOverAllIdleDetection(bool on
);
107 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
108 void informOverrun();
109 #endif // HAVE_LIBXSS
115 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
116 XScreenSaverInfo
*_mit_info
;
118 bool _idleDetectionPossible
;
119 bool _overAllIdleDetect
; // Based on preferences.
122 QDateTime start
; // when the idletimedetectordialog started
123 QDateTime idlestart
; // when the idleness started
127 #endif // KTIMETRACKER_IDLE_TIME_DETECTOR_H