1 /***************************************************************************
2 * Copyright (C) 2008 by Dario Freddi <drf@kdemod.ath.cx> *
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. *
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. *
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 "PollSystemLoader.h"
22 #include "WidgetBasedPoller.h"
23 #include "XSyncBasedPoller.h"
24 #include "TimerBasedPoller.h"
26 PollSystemLoader::PollSystemLoader(QObject
*parent
)
30 reloadAvailableCache();
33 PollSystemLoader::~PollSystemLoader()
35 unloadCurrentSystem();
38 void PollSystemLoader::reloadAvailableCache()
40 m_availableSystems
.clear();
42 // Test each polling system
43 WidgetBasedPoller
*wpl
= new WidgetBasedPoller(this);
44 XSyncBasedPoller
*xpl
= XSyncBasedPoller::instance();
45 TimerBasedPoller
*tpl
= new TimerBasedPoller(this);
47 if (wpl
->isAvailable()) {
48 m_availableSystems
[AbstractSystemPoller::WidgetBased
] = wpl
->name();
50 if (xpl
->isAvailable()) {
51 m_availableSystems
[AbstractSystemPoller::XSyncBased
] = xpl
->name();
53 if (tpl
->isAvailable()) {
54 m_availableSystems
[AbstractSystemPoller::TimerBased
] = tpl
->name();
61 QMap
<AbstractSystemPoller::PollingType
, QString
> PollSystemLoader::getAvailableSystems()
64 return m_availableSystems
;
67 QMap
<int, QString
> PollSystemLoader::getAvailableSystemsAsInt()
71 QMap
<int, QString
> retlist
;
73 foreach(const AbstractSystemPoller::PollingType
&ent
, m_availableSystems
.keys()) {
74 retlist
[(int) ent
] = m_availableSystems
[ent
];
80 bool PollSystemLoader::loadSystem(AbstractSystemPoller::PollingType type
)
83 if (m_poller
->getPollingType() == type
) {
86 unloadCurrentSystem();
91 case AbstractSystemPoller::WidgetBased
:
92 m_poller
= new WidgetBasedPoller(this);
94 case AbstractSystemPoller::TimerBased
:
95 m_poller
= new TimerBasedPoller(this);
97 case AbstractSystemPoller::XSyncBased
:
98 m_poller
= XSyncBasedPoller::instance();
105 if (!m_poller
->isAvailable()) {
109 if (!m_poller
->setUpPoller()) {
116 bool PollSystemLoader::unloadCurrentSystem()
119 m_poller
->unloadPoller();
121 if (m_poller
->getPollingType() != AbstractSystemPoller::XSyncBased
) {
122 m_poller
->deleteLater();
129 #include "PollSystemLoader.moc"