summaryrefslogtreecommitdiffstats
path: root/superkaramba/src/sensorsensor.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit2bda8f7717adf28da4af0d34fb82f63d2868c31d (patch)
tree8d927b7b47a90c4adb646482a52613f58acd6f8c /superkaramba/src/sensorsensor.cpp
downloadtdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.tar.gz
tdeutils-2bda8f7717adf28da4af0d34fb82f63d2868c31d.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeutils@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'superkaramba/src/sensorsensor.cpp')
-rw-r--r--superkaramba/src/sensorsensor.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/superkaramba/src/sensorsensor.cpp b/superkaramba/src/sensorsensor.cpp
new file mode 100644
index 0000000..9ff0d47
--- /dev/null
+++ b/superkaramba/src/sensorsensor.cpp
@@ -0,0 +1,115 @@
+/***************************************************************************
+ * Copyright (C) 2003 by Hans Karlsson *
+ * karlsson.h@home.se *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+#include "sensorsensor.h"
+#include <qglobal.h>
+
+SensorSensor::SensorSensor(int interval, char tempUnit) : Sensor( interval )
+{
+#if defined __FreeBSD__ || defined(Q_OS_NETBSD)
+ sensorMapBSD["VCore 1"] = "VC0";
+ sensorMapBSD["VCore 2"] = "VC1";
+ sensorMapBSD["+3.3V"] = "V33";
+ sensorMapBSD["+5V"] = "V50P";
+ sensorMapBSD["+12V"] = "V12P";
+ sensorMapBSD["-12V"] = "V12N";
+ sensorMapBSD["-5V"] = "V50N";
+ sensorMapBSD["fan1"] = "FAN0";
+ sensorMapBSD["fan2"] = "FAN1";
+ sensorMapBSD["fan3"] = "FAN2";
+ sensorMapBSD["temp1"] = "TEMP0";
+ sensorMapBSD["temp2"] = "TEMP1";
+ sensorMapBSD["temp3"] = "TEMP2";
+#endif
+ if(tempUnit == 'F')
+ extraParams = " -f";
+ connect(&ksp, SIGNAL(receivedStdout(KProcess *, char *, int )),
+ this,SLOT(receivedStdout(KProcess *, char *, int )));
+ connect(&ksp, SIGNAL(processExited(KProcess *)),
+ this,SLOT(processExited( KProcess * )));
+
+ // readValues();
+}
+
+
+SensorSensor::~SensorSensor()
+{
+}
+
+void SensorSensor::receivedStdout(KProcess *, char *buffer, int len )
+{
+ buffer[len] = 0;
+ sensorResult += QString( QCString(buffer) );
+}
+
+void SensorSensor::processExited(KProcess *)
+{
+ QStringList stringList = QStringList::split('\n',sensorResult);
+ sensorResult = "";
+ QStringList::Iterator it = stringList.begin();
+#if defined __FreeBSD__ || defined(Q_OS_NETBSD)
+ QRegExp rx( "^(\\S+)\\s+:\\s+[\\+\\-]?(\\d+\\.?\\d*)");
+#else
+ QRegExp rx( "^(.+):\\s+[\\+\\-]?(\\d+\\.?\\d*)");
+#endif
+ while( it != stringList.end())
+ {
+ rx.search( *it );
+
+ if ( !rx.cap(0).isEmpty())
+ {
+ sensorMap[rx.cap(1)] = rx.cap(2);
+ }
+ it++;
+ }
+
+ QString format;
+ QString type;
+ SensorParams *sp;
+ Meter *meter;
+
+ QObjectListIt lit( *objList );
+ while (lit != 0)
+ {
+ sp = (SensorParams*)(*lit);
+ meter = sp->getMeter();
+ format = sp->getParam("FORMAT");
+ type = sp->getParam("TYPE");
+
+ if (type.length() == 0)
+ type = "temp2";
+
+ if (format.length() == 0 )
+ {
+ format = "%v";
+ }
+
+#if defined __FreeBSD__ || defined(Q_OS_NETBSD)
+ format.replace( QRegExp("%v", false), sensorMap[sensorMapBSD[type]]);
+#else
+ format.replace( QRegExp("%v", false), sensorMap[type]);
+#endif
+ meter->setValue(format);
+ ++lit;
+ }
+}
+
+void SensorSensor::update()
+{
+ ksp.clearArguments();
+#if defined __FreeBSD__ || defined(Q_OS_NETBSD)
+ ksp << "mbmon -r -c 1" << extraParams;
+#else
+ ksp << "sensors" << extraParams;
+#endif
+ ksp.start( KProcess::NotifyOnExit,KProcIO::Stdout);
+}
+
+
+#include "sensorsensor.moc"