dtor first
[personal-kdebase.git] / workspace / powerdevil / daemon / TimerBasedPoller.cpp
blobb6c683773626224041f687cf9c22e3ee82d57476
1 /***************************************************************************
2 * Copyright (C) 2008 by Dario Freddi <drf@kdemod.ath.cx> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 **************************************************************************/
20 #include "TimerBasedPoller.h"
22 #include <klocalizedstring.h>
24 TimerBasedPoller::TimerBasedPoller(QObject *parent)
25 : AbstractSystemPoller(parent),
26 m_pollTimer(new QTimer(this)),
27 m_lastIdleTime(0),
28 m_catchingIdle(false)
33 TimerBasedPoller::~TimerBasedPoller()
38 QString TimerBasedPoller::name()
40 return i18n("Timer Based");
43 bool TimerBasedPoller::isAvailable()
45 #ifdef HAVE_XSCREENSAVER
46 return true;
47 #else
48 return false;
49 #endif
52 bool TimerBasedPoller::setUpPoller()
54 m_pollTimer->start(800);
56 connect(m_pollTimer, SIGNAL(timeout()), SLOT(poll()));
58 return true;
61 void TimerBasedPoller::unloadPoller()
65 void TimerBasedPoller::setNextTimeout(int nextTimeout)
67 Q_UNUSED(nextTimeout)
68 // We don't need this
71 void TimerBasedPoller::forcePollRequest()
73 poll();
76 ///HACK yucky
77 #ifdef HAVE_XSCREENSAVER
78 #include <X11/extensions/scrnsaver.h>
79 #include <QX11Info>
80 #endif
82 void TimerBasedPoller::poll()
84 /* Hack! Since KRunner still doesn't behave properly, the
85 * correct way to go doesn't work (yet), and it's this one:
86 ------------------------------------------------------------
87 int idle = m_screenSaverIface->GetSessionIdleTime();
88 ------------------------------------------------------------
90 /// In the meanwhile, this X11 hackish way gets its job done.
91 //----------------------------------------------------------
93 int idle = 0;
95 #ifdef HAVE_XSCREENSAVER
96 XScreenSaverInfo * mitInfo = 0;
97 mitInfo = XScreenSaverAllocInfo();
98 XScreenSaverQueryInfo(QX11Info::display(), DefaultRootWindow(QX11Info::display()), mitInfo);
99 idle = mitInfo->idle / 1000;
100 //----------------------------------------------------------
101 #endif
103 if (m_lastIdleTime > idle && m_catchingIdle) {
104 // Hey, a wakeup!
105 emit resumingFromIdle();
106 } else {
107 // Let's poll
108 m_lastIdleTime = idle;
109 emit pollRequest(m_lastIdleTime);
113 void TimerBasedPoller::stopCatchingTimeouts()
115 // Nothing we can do here
118 void TimerBasedPoller::stopCatchingIdleEvents()
120 m_catchingIdle = false;
123 void TimerBasedPoller::catchIdleEvent()
125 m_catchingIdle = true;
128 #include "TimerBasedPoller.moc"