3 #include "idletimedetector.h"
5 #include <tqdatetime.h>
6 #include <tqmessagebox.h>
10 #include <tdelocale.h>
15 kdDebug(5970) <<
"Entering IdleTimeDetector::IdleTimeDetector" << endl;
19 kdDebug(5970) <<
"IdleTimeDetector: LIBXSS detected @ compile time" << endl;
20 int event_base, error_base;
21 if(XScreenSaverQueryExtension(tqt_xdisplay(), &event_base, &error_base))
23 _idleDetectionPossible =
true;
24 _mit_info = XScreenSaverAllocInfo ();
28 _idleDetectionPossible =
false;
31 _timer =
new TQTimer(
this);
32 connect(_timer, TQT_SIGNAL(timeout()),
this, TQT_SLOT(check()));
34 _idleDetectionPossible =
false;
41 return _idleDetectionPossible;
44 void IdleTimeDetector::check()
46 kdDebug(5970) <<
"Entering IdleTimeDetector::check" << endl;
48 if (_idleDetectionPossible)
50 XScreenSaverQueryInfo(tqt_xdisplay(), tqt_xrootwin(), _mit_info);
51 int idleSeconds = (_mit_info->idle/1000);
52 if (idleSeconds >= _maxIdle)
53 informOverrun(idleSeconds);
64 void IdleTimeDetector::informOverrun(
int idleSeconds)
66 kdDebug(5970) <<
"Entering IdleTimeDetector::informOverrun" << endl;
67 if (!_overAllIdleDetect)
74 clock_gettime(CLOCK_MONOTONIC, &tm);
75 int start = tm.tv_sec - idleSeconds;
77 TQDateTime idleStart = TQDateTime::currentDateTime().addSecs(-idleSeconds);
78 int id = TQMessageBox::warning( 0, i18n(
"Idle Detection"),
79 i18n(
"Desktop has been idle since %1."
80 " What should we do?").arg(TDEGlobal::locale()->formatTime(idleStart.time())),
81 i18n(
"Revert && Stop"),
82 i18n(
"Revert && Continue"),
83 i18n(
"Continue Timing"),0,2);
85 clock_gettime(CLOCK_MONOTONIC, &tm);
86 int diff = tm.tv_sec - start;
91 kdDebug(5970) <<
"Now it is " << TQDateTime::currentDateTime() << endl;
92 kdDebug(5970) <<
"Reverting timer to " << TDEGlobal::locale()->formatTime(idleStart.time()).ascii() << endl;
100 _timer->start(testInterval);
105 _timer->start(testInterval);
108 #endif // HAVE_LIBXSS
112 kdDebug(5970) <<
"Entering IdleTimeDetector::startIdleDetection" << endl;
114 kdDebug(5970) <<
"Starting Timer" << endl;
115 if (!_timer->isActive())
116 _timer->start(testInterval);
123 if (_timer->isActive())
125 #endif // HAVE_LIBXSS
129 _overAllIdleDetect = on;
132 #include "idletimedetector.moc"
void stopIdleDetection()
Stops detecting idle time.
bool isIdleDetectionPossible()
Returns true if it is possible to do idle detection.
void startIdleDetection()
Starts detecting idle time.
void stopAllTimersAt(TQDateTime qdt)
Tells the listener to stop timing for TQDateTime.
void extractTime(int minutes)
Tells the listener to extract time from current timing.
void setMaxIdle(int maxIdle)
Sets the maximum allowed idle.
void toggleOverAllIdleDetection(bool on)
Sets whether idle detection should be done at all.
IdleTimeDetector(int maxIdle)
Initializes and idle test timer.