• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

Engines

systemmonitor.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright (C) 2007 John Tapsell <tapsell@kde.org>
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU Library General Public License version 2 as
00006  *   published by the Free Software Foundation
00007  *
00008  *   This program is distributed in the hope that it will be useful,
00009  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *   GNU General Public License for more details
00012  *
00013  *   You should have received a copy of the GNU Library General Public
00014  *   License along with this program; if not, write to the
00015  *   Free Software Foundation, Inc.,
00016  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00017  */
00018 
00019 #include "systemmonitor.h"
00020 
00021 #include <QTimer>
00022 #include <QProcess>
00023 
00024 #include <KLocale>
00025 
00026 #include <Plasma/DataContainer>
00027 
00028 #include "../../ksysguard/gui/ksgrd/SensorManager.h"
00029 
00030 SystemMonitorEngine::SystemMonitorEngine(QObject* parent, const QVariantList& args)
00031     : Plasma::DataEngine(parent)
00032 {
00033     Q_UNUSED(args)
00034     
00035     KSGRD::SensorMgr = new KSGRD::SensorManager(this);
00036     KSGRD::SensorMgr->engage( "localhost", "", "ksysguardd" );
00037 
00038     m_waitingFor= 0;
00039     KSGRD::SensorMgr->sendRequest( "localhost", "monitors", (KSGRD::SensorClient*)this, -1);
00040 }
00041 
00042 SystemMonitorEngine::~SystemMonitorEngine()
00043 {
00044 }
00045 
00046 QStringList SystemMonitorEngine::sources() const { 
00047     return m_sensors; 
00048 }
00049 bool SystemMonitorEngine::sourceRequestEvent(const QString &name)
00050 {
00051     return false;
00052 }
00053 bool SystemMonitorEngine::updateSourceEvent(const QString &sensorName)
00054 {
00055     KSGRD::SensorMgr->sendRequest( "localhost", sensorName, (KSGRD::SensorClient*)this, m_sensors.indexOf(sensorName));
00056     return false;
00057 }
00058 
00059 void SystemMonitorEngine::updateSensors()
00060 {
00061     DataEngine::SourceDict sources = containerDict();
00062     DataEngine::SourceDict::iterator it = sources.begin();
00063     if(m_waitingFor != 0)
00064         scheduleSourcesUpdated();
00065     m_waitingFor = 0;
00066     while (it != sources.end()) {
00067         m_waitingFor++;
00068         QString sensorName = it.key();
00069     KSGRD::SensorMgr->sendRequest( "localhost", sensorName, (KSGRD::SensorClient*)this, -1);
00070     ++it;
00071     }
00072 }
00073 
00074 void SystemMonitorEngine::answerReceived( int id, const QList<QByteArray>&answer ) {
00075     if(id==-1) {
00076         QStringList sensors;
00077     foreach(const QByteArray &sens, answer) { 
00078         QStringList newSensorInfo = QString::fromUtf8(sens).split('\t');
00079         QString newSensor = newSensorInfo[0];
00080         sensors.append(newSensor);
00081         setData(newSensor, "value", QVariant());
00082     }
00083     m_sensors = sensors;
00084     return;
00085     }
00086     m_waitingFor--;
00087     QString reply;
00088     if(!answer.isEmpty())
00089         reply = QString::fromUtf8(answer[0]);
00090 
00091     DataEngine::SourceDict sources = containerDict();
00092     DataEngine::SourceDict::const_iterator it = sources.constFind(m_sensors.value(id));
00093     if (it != sources.constEnd()) {
00094         it.value()->setData("value", reply);
00095     }
00096 
00097     if(m_waitingFor == 0)
00098         scheduleSourcesUpdated();
00099 }
00100 void SystemMonitorEngine::sensorLost( int ) { 
00101     m_waitingFor--;
00102 }
00103 #include "systemmonitor.moc"
00104 

Engines

Skip menu "Engines"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal