26 #include <QHBoxLayout>
29 #include <QVBoxLayout>
36 #include <KWindowSystem>
46 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
47 int event_base, error_base;
48 if(XScreenSaverQueryExtension(QX11Info::display(), &event_base, &error_base)) _idleDetectionPossible =
true;
49 else _idleDetectionPossible =
false;
50 _timer =
new QTimer(
this);
51 connect(_timer, SIGNAL(timeout()),
this, SLOT(
check()));
53 _idleDetectionPossible =
false;
59 return _idleDetectionPossible;
64 kDebug(5970) <<
"Entering function";
65 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
66 kDebug(5970) <<
"kompiled for libxss and x11, idledetectionpossible is " << _idleDetectionPossible;
67 if (_idleDetectionPossible)
69 _mit_info = XScreenSaverAllocInfo();
70 XScreenSaverQueryInfo(QX11Info::display(), QX11Info::appRootWindow(), _mit_info);
72 kDebug(5970) <<
"The desktop has been idle for " << idleminutes <<
" minutes.";
73 kDebug(5970) <<
"The idle time in miliseconds is " << _mit_info->idle;
74 if (idleminutes >= _maxIdle)
88 kDebug(5970) <<
"Entering function";
89 QDateTime end = QDateTime::currentDateTime();
95 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
96 void IdleTimeDetector::informOverrun()
98 if (!_overAllIdleDetect)
102 start = QDateTime::currentDateTime();
103 idlestart = start.addSecs(-60 * _maxIdle);
104 QString backThen = KGlobal::locale()->formatTime(idlestart.time());
108 dialog->setMainWidget(wid);
109 QVBoxLayout *lay1 =
new QVBoxLayout(wid);
110 QHBoxLayout *lay2 =
new QHBoxLayout();
111 lay1->addLayout(lay2);
112 QString idlemsg= i18n(
"Desktop has been idle since %1. What do you want to do ?", backThen);
113 QLabel *label =
new QLabel( idlemsg, wid );
114 lay2->addWidget( label );
115 connect( dialog , SIGNAL(cancelClicked()) ,
this , SLOT(
revert()) );
116 connect( wid , SIGNAL(changed(
bool)) , wid , SLOT(enabledButtonApply(
bool)) );
117 QString explanation=i18n(
"Continue timing. Timing has started at %1", backThen);
118 QString explanationrevert=i18n(
"Stop timing and revert back to the time at %1.", backThen);
119 dialog->setButtonText(KDialog::Ok, i18n(
"Continue timing."));
120 dialog->setButtonText(KDialog::Cancel, i18n(
"Revert timing"));
121 dialog->setButtonWhatsThis(KDialog::Ok, explanation);
122 dialog->setButtonWhatsThis(KDialog::Cancel, explanationrevert);
124 KWindowSystem::self()->setOnDesktop( dialog->winId(), KWindowSystem::self()->currentDesktop() );
125 KWindowSystem::self()->demandAttention( dialog->winId() );
126 kDebug(5970) <<
"Setting WinId " << dialog->winId() <<
" to deskTop " << KWindowSystem::self()->currentDesktop();
129 #endif // HAVE_LIBXSS
133 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
134 if (!_timer->isActive())
141 #if defined(HAVE_LIBXSS) && defined(Q_WS_X11)
142 if (_timer->isActive())
144 #endif // HAVE_LIBXSS
149 _overAllIdleDetect = on;
152 #include "idletimedetector.moc"
void stopIdleDetection()
Stops detecting idle time.
bool isIdleDetectionPossible()
Returns true if it is possible to do idle detection.
void subtractTime(int minutes)
Tells the listener to subtract time from current timing.
void startIdleDetection()
Starts detecting idle time.
void stopAllTimers(QDateTime time)
Tells the listener to stop 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.