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"
26 #include <Plasma/DataContainer>
28 #include "../../ksysguard/gui/ksgrd/SensorManager.h"
30 SystemMonitorEngine::SystemMonitorEngine(QObject
* parent
, const QVariantList
& args
)
31 : Plasma::DataEngine(parent
)
35 KSGRD::SensorMgr
= new KSGRD::SensorManager(this);
36 KSGRD::SensorMgr
->engage( "localhost", "", "ksysguardd" );
39 KSGRD::SensorMgr
->sendRequest( "localhost", "monitors", (KSGRD::SensorClient
*)this, -1);
42 SystemMonitorEngine::~SystemMonitorEngine()
46 QStringList
SystemMonitorEngine::sources() const {
49 bool SystemMonitorEngine::sourceRequestEvent(const QString
&name
)
53 bool SystemMonitorEngine::updateSourceEvent(const QString
&sensorName
)
55 KSGRD::SensorMgr
->sendRequest( "localhost", sensorName
, (KSGRD::SensorClient
*)this, m_sensors
.indexOf(sensorName
));
59 void SystemMonitorEngine::updateSensors()
61 DataEngine::SourceDict sources
= containerDict();
62 DataEngine::SourceDict::iterator it
= sources
.begin();
64 scheduleSourcesUpdated();
66 while (it
!= sources
.end()) {
68 QString sensorName
= it
.key();
69 KSGRD::SensorMgr
->sendRequest( "localhost", sensorName
, (KSGRD::SensorClient
*)this, -1);
74 void SystemMonitorEngine::answerReceived( int id
, const QList
<QByteArray
>&answer
) {
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());
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
);
98 scheduleSourcesUpdated();
100 void SystemMonitorEngine::sensorLost( int ) {
103 #include "systemmonitor.moc"