Remove some dead KMail1 legacy code.
[kdepim.git] / ktimetracker / idletimedetector.h
blobb32b2144bc30576b6c526b9fe0676357e0d85517
1 /*
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
27 #include <QDateTime>
28 #include <QObject>
29 #include <config-ktimetracker.h> // HAVE_LIBXSS
31 class QTimer;
33 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
34 #include <X11/Xlib.h>
35 #include <X11/Xutil.h>
36 #include <X11/extensions/scrnsaver.h>
37 #include <fixx11h.h>
38 #endif // HAVE_LIBXSS
40 // Minutes between each idle overrun test.
41 const int testInterval= secsPerMinute * 1000;
43 /**
44 * Keep track of how long the computer has been idle.
47 class IdleTimeDetector :public QObject
49 Q_OBJECT
51 public:
52 /**
53 Initializes and idle test timer
54 @param maxIdle minutes before the idle timer will go off.
55 **/
56 IdleTimeDetector(int maxIdle);
58 /**
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
61 always be present.
62 **/
63 bool isIdleDetectionPossible();
65 Q_SIGNALS:
66 /**
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.
71 **/
72 void extractTime(int minutes);
74 /**
75 Tells the listener to stop timing
76 **/
77 void stopAllTimers(QDateTime time);
79 public Q_SLOTS:
80 void revert();
82 /**
83 Sets the maximum allowed idle.
84 @param maxIdle Maximum allowed idle time in minutes
85 **/
86 void setMaxIdle(int maxIdle);
88 /**
89 Starts detecting idle time
90 **/
91 void startIdleDetection();
93 /**
94 Stops detecting idle time.
95 **/
96 void stopIdleDetection();
98 /**
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);
106 protected:
107 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
108 void informOverrun();
109 #endif // HAVE_LIBXSS
111 protected Q_SLOTS:
112 void check();
114 private:
115 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
116 XScreenSaverInfo *_mit_info;
117 #endif
118 bool _idleDetectionPossible;
119 bool _overAllIdleDetect; // Based on preferences.
120 int _maxIdle;
121 QTimer *_timer;
122 QDateTime start; // when the idletimedetectordialog started
123 QDateTime idlestart; // when the idleness started
124 int idleminutes;
127 #endif // KTIMETRACKER_IDLE_TIME_DETECTOR_H