not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / dataengines / systemmonitor / systemmonitor.cpp
blobb72a8f5eeb88aad1de13f8b2511c94a746dfd92d
1 /*
2 * Copyright (C) 2007 John Tapsell <tapsell@kde.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details
13 * You should have received a copy of the GNU Library General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "systemmonitor.h"
21 #include <QTimer>
22 #include <QProcess>
24 #include <KLocale>
26 #include <Plasma/DataContainer>
28 #include "../../ksysguard/gui/ksgrd/SensorManager.h"
30 SystemMonitorEngine::SystemMonitorEngine(QObject* parent, const QVariantList& args)
31 : Plasma::DataEngine(parent)
33 Q_UNUSED(args)
35 KSGRD::SensorMgr = new KSGRD::SensorManager(this);
36 KSGRD::SensorMgr->engage( "localhost", "", "ksysguardd" );
38 m_waitingFor= 0;
39 KSGRD::SensorMgr->sendRequest( "localhost", "monitors", (KSGRD::SensorClient*)this, -1);
42 SystemMonitorEngine::~SystemMonitorEngine()
46 QStringList SystemMonitorEngine::sources() const {
47 return m_sensors;
49 bool SystemMonitorEngine::sourceRequestEvent(const QString &name)
51 return false;
53 bool SystemMonitorEngine::updateSourceEvent(const QString &sensorName)
55 KSGRD::SensorMgr->sendRequest( "localhost", sensorName, (KSGRD::SensorClient*)this, m_sensors.indexOf(sensorName));
56 return false;
59 void SystemMonitorEngine::updateSensors()
61 DataEngine::SourceDict sources = containerDict();
62 DataEngine::SourceDict::iterator it = sources.begin();
63 if(m_waitingFor != 0)
64 scheduleSourcesUpdated();
65 m_waitingFor = 0;
66 while (it != sources.end()) {
67 m_waitingFor++;
68 QString sensorName = it.key();
69 KSGRD::SensorMgr->sendRequest( "localhost", sensorName, (KSGRD::SensorClient*)this, -1);
70 ++it;
74 void SystemMonitorEngine::answerReceived( int id, const QList<QByteArray>&answer ) {
75 if(id==-1) {
76 QStringList sensors;
77 foreach(const QByteArray &sens, answer) {
78 QStringList newSensorInfo = QString::fromUtf8(sens).split('\t');
79 QString newSensor = newSensorInfo[0];
80 sensors.append(newSensor);
81 setData(newSensor, "value", QVariant());
83 m_sensors = sensors;
84 return;
86 m_waitingFor--;
87 QString reply;
88 if(!answer.isEmpty())
89 reply = QString::fromUtf8(answer[0]);
91 DataEngine::SourceDict sources = containerDict();
92 DataEngine::SourceDict::const_iterator it = sources.constFind(m_sensors.value(id));
93 if (it != sources.constEnd()) {
94 it.value()->setData("value", reply);
97 if(m_waitingFor == 0)
98 scheduleSourcesUpdated();
100 void SystemMonitorEngine::sensorLost( int ) {
101 m_waitingFor--;
103 #include "systemmonitor.moc"