summaryrefslogtreecommitdiffstats
path: root/src/sources
diff options
context:
space:
mode:
Diffstat (limited to 'src/sources')
-rw-r--r--src/sources/Makefile.am20
-rw-r--r--src/sources/acpithermalsrc.cpp65
-rw-r--r--src/sources/acpithermalsrc.h64
-rw-r--r--src/sources/batterysrc.cpp141
-rw-r--r--src/sources/batterysrc.h76
-rw-r--r--src/sources/cpuinfofreqsrc.cpp57
-rw-r--r--src/sources/cpuinfofreqsrc.h63
-rw-r--r--src/sources/hddtempsrc.cpp100
-rw-r--r--src/sources/hddtempsrc.h74
-rw-r--r--src/sources/hwmonfansrc.cpp91
-rw-r--r--src/sources/hwmonfansrc.h66
-rw-r--r--src/sources/hwmonthermalsrc.cpp94
-rw-r--r--src/sources/hwmonthermalsrc.h66
-rw-r--r--src/sources/i8ksrc.cpp111
-rw-r--r--src/sources/i8ksrc.h74
-rw-r--r--src/sources/ibmacpifansrc.cpp57
-rw-r--r--src/sources/ibmacpifansrc.h63
-rw-r--r--src/sources/ibmacpithermalsrc.cpp88
-rw-r--r--src/sources/ibmacpithermalsrc.h73
-rw-r--r--src/sources/ibmhdaps.cpp63
-rw-r--r--src/sources/ibmhdaps.h65
-rw-r--r--src/sources/ibookg4thermalsrc.cpp63
-rw-r--r--src/sources/ibookg4thermalsrc.h66
-rw-r--r--src/sources/labelsource.cpp133
-rw-r--r--src/sources/labelsource.h107
-rw-r--r--src/sources/labelsourcePrefs.cpp110
-rw-r--r--src/sources/labelsourcePrefs.ui186
-rw-r--r--src/sources/nvidiathermalsrc.cpp175
-rw-r--r--src/sources/nvidiathermalsrc.h86
-rw-r--r--src/sources/omnibookthermalsrc.cpp58
-rw-r--r--src/sources/omnibookthermalsrc.h64
-rw-r--r--src/sources/source.cpp222
-rw-r--r--src/sources/source.h249
-rw-r--r--src/sources/sourceprefs.cpp88
-rw-r--r--src/sources/sourceprefs.ui127
-rw-r--r--src/sources/sysfreqsrc.cpp66
-rw-r--r--src/sources/sysfreqsrc.h63
-rw-r--r--src/sources/threadedtrigger.cpp67
-rw-r--r--src/sources/threadedtrigger.h89
-rw-r--r--src/sources/triggeredsource.cpp48
-rw-r--r--src/sources/triggeredsource.h72
-rw-r--r--src/sources/updateevent.cpp29
-rw-r--r--src/sources/updateevent.h38
-rw-r--r--src/sources/uptimesrc.cpp70
-rw-r--r--src/sources/uptimesrc.h74
45 files changed, 3921 insertions, 0 deletions
diff --git a/src/sources/Makefile.am b/src/sources/Makefile.am
new file mode 100644
index 0000000..4da707d
--- /dev/null
+++ b/src/sources/Makefile.am
@@ -0,0 +1,20 @@
+INCLUDES = -I$(top_srcdir)/src/cpufreqd -I$(top_srcdir)/src/sources $(all_includes)
+METASOURCES = AUTO
+libsources_la_LDFLAGS = $(all_libraries)
+libsources_la_LIBADD = $(LIB_QT) $(LIB_KDECORE)
+noinst_LTLIBRARIES = libsources.la
+libsources_la_SOURCES = acpithermalsrc.cpp batterysrc.cpp cpuinfofreqsrc.cpp \
+ hddtempsrc.cpp hwmonfansrc.cpp hwmonthermalsrc.cpp i8ksrc.cpp ibmacpifansrc.cpp \
+ ibmacpithermalsrc.cpp ibmhdaps.cpp ibookg4thermalsrc.cpp labelsource.cpp labelsourcePrefs.ui \
+ nvidiathermalsrc.cpp omnibookthermalsrc.cpp source.cpp sourceprefs.ui \
+ sysfreqsrc.cpp threadedtrigger.cpp triggeredsource.cpp updateevent.cpp \
+ uptimesrc.cpp
+
+noinst_HEADERS = acpithermalsrc.h batterysrc.h cpuinfofreqsrc.h hddtempsrc.h \
+ hwmonfansrc.h hwmonthermalsrc.h i8ksrc.h ibmacpifansrc.h ibmacpithermalsrc.h \
+ ibmhdaps.h ibookg4thermalsrc.h labelsource.h nvidiathermalsrc.h \
+ omnibookthermalsrc.h source.h sysfreqsrc.h \
+ threadedtrigger.h triggeredsource.h updateevent.h uptimesrc.h
+
+AM_CXXFLAGS = @libhal_CFLAGS@ @nvcontrol_CFLAGS@
+LIBS += @libhal_LIBS@ @nvcontrol_LIBS@
diff --git a/src/sources/acpithermalsrc.cpp b/src/sources/acpithermalsrc.cpp
new file mode 100644
index 0000000..fdc0260
--- /dev/null
+++ b/src/sources/acpithermalsrc.cpp
@@ -0,0 +1,65 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "acpithermalsrc.h"
+#include <qtextstream.h>
+#include <qdir.h>
+#include <klocale.h>
+
+ACPIThermalSrc::ACPIThermalSrc(QWidget* inParent, const QFile& inSourceFile):
+ LabelSource(inParent),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this){
+ mID = mSourceFile.name().section('/', -2, -2, QString::SectionSkipEmpty);
+ mName = mID;
+ mDescription = i18n("This source is provided by the Linux ACPI Thermal Zone driver.");
+}
+
+ACPIThermalSrc::~ACPIThermalSrc(){
+}
+
+std::list<Source*>ACPIThermalSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ QDir d( "/proc/acpi/thermal_zone" );
+ if( d.exists() ){
+ d.setFilter( QDir::Dirs | QDir::NoSymLinks );
+ d.setSorting( QDir::Name);
+ for( unsigned int i = 0; i < d.count(); i++ ){
+ if((d[i] != ".") && (d[i] != "..")){
+ QFile acpiFile(d.canonicalPath() + "/" + d[i] + "/temperature");
+ list.push_back(new ACPIThermalSrc(inParent, acpiFile));
+ }
+ }
+ }
+ return list;
+}
+
+QString ACPIThermalSrc::fetchValue() {
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ QTextStream textStream(&mSourceFile);
+ s = textStream.readLine();
+ mSourceFile.close();
+ s = s.remove("temperature:").stripWhiteSpace();
+ s = formatTemperature(s.left(s.length()-1));
+ }
+ return s;
+}
+
diff --git a/src/sources/acpithermalsrc.h b/src/sources/acpithermalsrc.h
new file mode 100644
index 0000000..1da73f5
--- /dev/null
+++ b/src/sources/acpithermalsrc.h
@@ -0,0 +1,64 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef ACPITHERMALSRC_H
+#define ACPITHERMALSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * ACPIThermalSrc reads temperature values from /proc/acpi/thermal/
+ * which is provided by the thermal.ko kernel module.
+ * @author Ken Werner
+ */
+class ACPIThermalSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+ ACPIThermalSrc(QWidget* inParent, const QFile& inSourceFile);
+ virtual ~ACPIThermalSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //ACPITHERMALSRC_H
diff --git a/src/sources/batterysrc.cpp b/src/sources/batterysrc.cpp
new file mode 100644
index 0000000..b8f73ac
--- /dev/null
+++ b/src/sources/batterysrc.cpp
@@ -0,0 +1,141 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "batterysrc.h"
+#include <klocale.h>
+#include <kdebug.h>
+
+#define DBUS_DEBUG_MESSAGE(func, _dbus_err_) \
+ kdDebug() << "error in " << func << ": " << _dbus_err_.name << ", " << _dbus_err_.message << endl
+
+#define FREE_DBUS_ERROR(func, _dbus_err_) \
+ do { \
+ if(dbus_error_is_set(&_dbus_err_)) { \
+ DBUS_DEBUG_MESSAGE(func, _dbus_err_); \
+ dbus_error_free(&_dbus_err_); \
+ } \
+ } while(0)
+
+BatterySrc::BatterySrc(QWidget* inParent, QString inUDI):
+ LabelSource(inParent),
+ mTrigger(this, 5000),
+ mUDI(inUDI),
+ mLibHalContext(NULL){
+ mID = mUDI.section('/', -1);
+ mName = mID;
+ mDescription = i18n("This source displays the current state of charge of your battery.");
+
+ dbus_error_init(&mDBusError);
+ if((mLibHalContext = libhal_ctx_new()) == NULL){
+ kdDebug() << "error: libmLibHalContext_new" << endl;
+ return;
+ }
+ if(!libhal_ctx_set_dbus_connection(mLibHalContext, dbus_bus_get (DBUS_BUS_SYSTEM, &mDBusError))){
+ FREE_DBUS_ERROR("libhal_ctx_set_dbus_connection", mDBusError);
+ libhal_ctx_free(mLibHalContext);
+ mLibHalContext = NULL;
+ return;
+ }
+ if(!libhal_ctx_init(mLibHalContext, &mDBusError)){
+ FREE_DBUS_ERROR("libhal_ctx_init", mDBusError);
+ libhal_ctx_free(mLibHalContext);
+ mLibHalContext = NULL;
+ return;
+ }
+}
+
+BatterySrc::~BatterySrc(){
+ if(mLibHalContext != NULL){
+ if(!libhal_ctx_shutdown(mLibHalContext, &mDBusError)){
+ FREE_DBUS_ERROR("libhal_ctx_shutdown", mDBusError);
+ }
+ libhal_ctx_free(mLibHalContext);
+ }
+}
+
+std::list<Source*>BatterySrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+
+ LibHalContext* libHalContext;
+ DBusError dBusError;
+ dbus_error_init(&dBusError);
+ if((libHalContext = libhal_ctx_new()) == NULL){
+ kdDebug() << "error: libmLibHalContext_new" << endl;
+ return list;
+ }
+ if(!libhal_ctx_set_dbus_connection(libHalContext, dbus_bus_get (DBUS_BUS_SYSTEM, &dBusError))){
+ FREE_DBUS_ERROR("libhal_ctx_set_dbus_connection", dBusError);
+ libhal_ctx_free(libHalContext);
+ return list;
+ }
+ if(!libhal_ctx_init(libHalContext, &dBusError)){
+ FREE_DBUS_ERROR("libhal_ctx_init", dBusError);
+ libhal_ctx_free(libHalContext);
+ return list;
+ }
+
+ int num = 0;
+ char** udis = libhal_manager_find_device_string_match(libHalContext, "info.category", "battery", &num, &dBusError);
+ if(!dbus_error_is_set(&dBusError)){
+ for(int i = 0; i < num; ++i){
+ if(libhal_device_get_property_type(libHalContext, udis[i], "battery.charge_level.last_full", &dBusError) == LIBHAL_PROPERTY_TYPE_INT32 && libhal_device_get_property_type(libHalContext, udis[i], "battery.charge_level.current", &dBusError) == LIBHAL_PROPERTY_TYPE_INT32){
+ if(!dbus_error_is_set(&dBusError)) // todo: check whether this check is redundant
+ list.push_back(new BatterySrc(inParent, udis[i]));
+ }
+ if(dbus_error_is_set(&dBusError)) {
+ DBUS_DEBUG_MESSAGE("libhal_device_get_property_type", dBusError);
+ dbus_error_free(&dBusError);
+ }
+ }
+ } else {
+ DBUS_DEBUG_MESSAGE("libhal_manager_find_device_string_match", dBusError);
+ dbus_error_free(&dBusError);
+ }
+ if(!libhal_ctx_shutdown(libHalContext, &dBusError)){
+ FREE_DBUS_ERROR("libhal_ctx_shutdown", dBusError);
+ }
+ // clean up
+ libhal_ctx_free(libHalContext);
+ libhal_free_string_array(udis);
+ return list;
+}
+
+QString BatterySrc::fetchValue() {
+ QString s = "n/a";
+ if(mLibHalContext != NULL){
+ int last_full = 0;
+ int current = 0;
+
+ last_full = libhal_device_get_property_int(mLibHalContext, mUDI.ascii(), "battery.charge_level.last_full", &mDBusError);
+ if(dbus_error_is_set(&mDBusError)){
+ DBUS_DEBUG_MESSAGE("libhal_device_get_property_int", mDBusError);
+ dbus_error_free(&mDBusError);
+ return s;
+ }
+ current = libhal_device_get_property_int(mLibHalContext, mUDI.ascii(), "battery.charge_level.current", &mDBusError);
+ if(dbus_error_is_set(&mDBusError)){
+ DBUS_DEBUG_MESSAGE("libhal_device_get_property_int", mDBusError);
+ dbus_error_free(&mDBusError);
+ return s;
+ }
+ s = QString::number(qRound((current * 100.0) / last_full)) + " %";
+ }
+ return s;
+}
diff --git a/src/sources/batterysrc.h b/src/sources/batterysrc.h
new file mode 100644
index 0000000..e491fcc
--- /dev/null
+++ b/src/sources/batterysrc.h
@@ -0,0 +1,76 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef BATTERYSRC_H
+#define BATTERYSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <qstring.h>
+#include <list>
+#include <hal/libhal.h>
+
+/**
+ * BatterySrc fetches the state of charge of the battery from HAL
+ * @author Ken Werner
+ */
+class BatterySrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source
+ */
+ BatterySrc(QWidget* inParent, QString inUDI);
+ virtual ~BatterySrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+
+ /**
+ * The hal udi of that battery source
+ */
+ QString mUDI;
+
+ /**
+ * The local hal context
+ */
+ LibHalContext* mLibHalContext;
+
+ /**
+ * The local dbus error object
+ */
+ DBusError mDBusError;
+
+};
+#endif //BATTERYSRC_H
diff --git a/src/sources/cpuinfofreqsrc.cpp b/src/sources/cpuinfofreqsrc.cpp
new file mode 100644
index 0000000..6227439
--- /dev/null
+++ b/src/sources/cpuinfofreqsrc.cpp
@@ -0,0 +1,57 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "cpuinfofreqsrc.h"
+#include <qtextstream.h>
+#include <qfile.h>
+#include <klocale.h>
+
+CpuinfoFreqSrc::CpuinfoFreqSrc(QWidget* inParent, const QFile& inSourceFile):
+ LabelSource(inParent),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this){
+ mID = "proc";
+ mName = mID;
+ mDescription = i18n("This source is provided by the Linux kernel proc vfs interface.");
+}
+
+CpuinfoFreqSrc::~CpuinfoFreqSrc(){
+}
+
+std::list<Source*>CpuinfoFreqSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ QFile cpuinfoFreqFile( "/proc/cpuinfo" );
+ if(cpuinfoFreqFile.open(IO_ReadOnly))
+ list.push_back(new CpuinfoFreqSrc(inParent, cpuinfoFreqFile));
+ return list;
+}
+
+QString CpuinfoFreqSrc::fetchValue(){
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ while( mSourceFile.readLine( s, 64 ) != -1 )
+ if( s.startsWith( "cpu MHz") )
+ break;
+ s = s.section( ':', 1, 1 ).stripWhiteSpace();
+ s = KHzinHumanReadable(uint(s.toDouble() * 1000));
+ mSourceFile.close();
+ }
+ return s;
+}
diff --git a/src/sources/cpuinfofreqsrc.h b/src/sources/cpuinfofreqsrc.h
new file mode 100644
index 0000000..da3f734
--- /dev/null
+++ b/src/sources/cpuinfofreqsrc.h
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef CPUINFOFREQSRC_H
+#define CPUINFOFREQSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * CpuinfoFreqSrc reads temperature values from /proc/cpuinfo
+ */
+class CpuinfoFreqSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+ CpuinfoFreqSrc(QWidget* inParent, const QFile& inSourceFile);
+ virtual ~CpuinfoFreqSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //CPUINFOFREQSRC_H
+
diff --git a/src/sources/hddtempsrc.cpp b/src/sources/hddtempsrc.cpp
new file mode 100644
index 0000000..eb0419e
--- /dev/null
+++ b/src/sources/hddtempsrc.cpp
@@ -0,0 +1,100 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "hddtempsrc.h"
+
+#include <qsocketdevice.h>
+#include <qhostaddress.h>
+#include <qcstring.h>
+
+#include <klocale.h>
+
+//#include <kdebug.h>
+
+const Q_ULONG HDDTempSrc::BUFFERSIZE = 128;
+const Q_UINT32 HDDTempSrc::ADDRESS = (127<<24)|1;
+const Q_UINT16 HDDTempSrc::PORT = 7634;
+
+HDDTempSrc::HDDTempSrc(QWidget* inParent, uint inIndex, const QString& inDevice, const QString& inModelName):
+ LabelSource(inParent),
+ mIndex(inIndex),
+ mTrigger(this){
+ mID = "HDDTemp" + QString().setNum(inIndex);
+ mName = mID;
+ mDescription = i18n("This source is provided by hddtemp. (%1, %2)").arg(inDevice).arg(inModelName);
+}
+
+HDDTempSrc::~HDDTempSrc(){
+}
+
+std::list<Source*>HDDTempSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ QSocketDevice sd;
+ sd.setBlocking(true);
+ if(sd.connect((ADDRESS), PORT)){
+ //kdDebug() << "hddtemp is availalble" << endl;
+ QCString tmp(0);
+ Q_LONG numBytes = 0;
+ Q_LONG numTotalBytes = 0;
+ do{
+ tmp.resize(numTotalBytes+BUFFERSIZE);
+ numBytes = sd.readBlock(tmp.data()+numTotalBytes, BUFFERSIZE);
+ // numBytes could be -1 too in case of an error!
+ numTotalBytes += QMAX(numBytes, 0);
+ }while(numBytes>0);
+ sd.close();
+ tmp.resize(numTotalBytes+1);
+ //kdDebug() << "following data was read: " << tmp << endl;
+ // split the string
+ QStringList sl = QStringList::split(tmp[0], tmp);
+ // create the sources
+ if(sl.size() > 0 && sl.size()%4 == 0){
+ for(uint i = 0; i < sl.size(); i += 4)
+ list.push_back(new HDDTempSrc(inParent, i/4, sl[i], sl[i+1]));
+ }
+ }//else
+ //kdDebug() << "hddtemp is not availalble" << endl; // << sd.error() << endl;
+ return list;
+}
+
+QString HDDTempSrc::fetchValue(){
+ QString s = "n/a";
+ QSocketDevice sd;
+ sd.setBlocking(true);
+ if(sd.connect((ADDRESS), PORT)){
+ QCString tmp(0);
+ Q_LONG numBytes = 0;
+ Q_LONG numTotalBytes = 0;
+ do{
+ tmp.resize(numTotalBytes+BUFFERSIZE);
+ numBytes = sd.readBlock(tmp.data()+numTotalBytes, BUFFERSIZE);
+ // numBytes could be -1 too in case of an error!
+ numTotalBytes += QMAX(numBytes, 0);
+ }while(numBytes>0);
+ sd.close();
+ tmp.resize(numTotalBytes+1);
+ QStringList sl = QStringList::split(tmp[0], tmp);
+ if(sl.size() > 0 && sl.size()%4 == 0){
+ s = formatTemperature(sl[mIndex*4+2]);
+ }
+ }
+ return s;
+}
+
diff --git a/src/sources/hddtempsrc.h b/src/sources/hddtempsrc.h
new file mode 100644
index 0000000..60d8151
--- /dev/null
+++ b/src/sources/hddtempsrc.h
@@ -0,0 +1,74 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef HDDTEMPSRC_H
+#define HDDTEMPSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <list>
+
+/**
+ * HDDTempSrc reads temperature of your harddisk provided by hddtemp
+ */
+class HDDTempSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+
+ /**
+ * defines how many bytes are read at once from the network
+ */
+ static const Q_ULONG BUFFERSIZE;
+
+ /**
+ * defines the address
+ */
+ static const Q_UINT32 ADDRESS;
+
+ /**
+ * defines the port
+ */
+ static const Q_UINT16 PORT;
+
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+ HDDTempSrc(QWidget* inParent, uint inIndex, const QString& inDevice, const QString& inModelName);
+ virtual ~HDDTempSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ uint mIndex;
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //HDDTEMPSRC_H
+
diff --git a/src/sources/hwmonfansrc.cpp b/src/sources/hwmonfansrc.cpp
new file mode 100644
index 0000000..16dcd84
--- /dev/null
+++ b/src/sources/hwmonfansrc.cpp
@@ -0,0 +1,91 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "hwmonfansrc.h"
+#include <qtextstream.h>
+#include <qdir.h>
+#include <klocale.h>
+
+HwMonFanSrc::HwMonFanSrc(QWidget* inParent, const QFile& inSourceFile, unsigned int inIndex):
+ LabelSource(inParent),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this, 3000){
+ //mName = "HwMon " + inSourceFile.name()[inSourceFile.name().length() - 7];
+ mID = "hwmonFan" + QString::number(inIndex);
+ mName = mID;
+ mDescription = i18n("This fan source is provided by hwmon. (%1)").arg(inSourceFile.name());
+}
+
+HwMonFanSrc::~HwMonFanSrc(){
+}
+
+std::list<Source*>HwMonFanSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ // /sys/class/hwmon/hwmon*/device/fan*_input
+ QDir d("/sys/class/hwmon/");
+ QDir subd;
+ QString device = "/device";
+ // check the i2c interface if hwmon isn't available
+ // /sys/bus/i2c/devices/*/fan*_input
+ if(!d.exists()){
+ d.setPath("/sys/bus/i2c/devices/");
+ device = "";
+ }
+
+ if(d.exists()){
+ unsigned int index = 1;
+ d.setFilter(QDir::Dirs);
+ d.setSorting(QDir::Name);
+ for(unsigned int i = 0; i < d.count(); i++ ){
+ if((d[i] != ".") && (d[i] != "..")){
+ subd = d.canonicalPath() + "/" + d[i] + device;
+ subd.setFilter(QDir::Files);
+ subd.setSorting(QDir::Name);
+ for ( unsigned int j = 0; j < subd.count(); j++ ){
+ if((subd[j] != ".") && (subd[j] != "..") && (QDir::match(subd.canonicalPath() + "/fan*_input", subd.canonicalPath() + "/" + subd[j]))){
+ QFile f(subd.canonicalPath() + "/" + subd[j]);
+ if(f.open(IO_ReadOnly)){
+ QTextStream textStream( &f );
+ QString s = textStream.readLine();
+ f.close();
+ if(!s.startsWith("-")){
+ list.push_back(new HwMonFanSrc(inParent, f, index));
+ index++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return list;
+}
+
+QString HwMonFanSrc::fetchValue(){
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ QTextStream textStream( &mSourceFile );
+ s = textStream.readLine().stripWhiteSpace();
+ mSourceFile.close();
+ s.append(" rpm");
+ }
+ return s;
+}
+
diff --git a/src/sources/hwmonfansrc.h b/src/sources/hwmonfansrc.h
new file mode 100644
index 0000000..8f8396e
--- /dev/null
+++ b/src/sources/hwmonfansrc.h
@@ -0,0 +1,66 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef HWMONFANSRC_H
+#define HWMONFANSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * HwMonThermalSrc reads fan rpm values from /sys/class/hwmon/\*\/device/fan*_input
+ * that is provided by the hwmon kernel by the lmsensors kernel modules since version 2.6.14.
+ * /sys/bus/i2c/devices/\*\/fan*_input is used as a fall back.
+ * see /usr/src/linux/Documentation/hwmon/sysfs-interface
+ */
+class HwMonFanSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+ HwMonFanSrc(QWidget* inParent, const QFile& inSourceFile, unsigned int inIndex);
+ virtual ~HwMonFanSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //HWMONFANSRC_H
+
diff --git a/src/sources/hwmonthermalsrc.cpp b/src/sources/hwmonthermalsrc.cpp
new file mode 100644
index 0000000..38ab38f
--- /dev/null
+++ b/src/sources/hwmonthermalsrc.cpp
@@ -0,0 +1,94 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "hwmonthermalsrc.h"
+#include <qtextstream.h>
+#include <qdir.h>
+#include <klocale.h>
+
+HwMonThermalSrc::HwMonThermalSrc(QWidget* inParent, const QFile& inSourceFile, unsigned int inIndex):
+ LabelSource(inParent),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this, 3000){
+ //mName = "HwMon " + inSourceFile.name()[inSourceFile.name().length() - 7];
+ mID = "hwmon" + QString::number(inIndex);
+ mName = mID;
+ mDescription = i18n("This thermal source is provided by hwmon. (%1)").arg(inSourceFile.name());
+}
+
+HwMonThermalSrc::~HwMonThermalSrc(){
+}
+
+std::list<Source*>HwMonThermalSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ // /sys/class/hwmon/*/device/temp*_input
+ QDir d("/sys/class/hwmon/");
+ QDir subd;
+ QString device = "/device";
+ // check the i2c interface if hwmon isn't available
+ // /sys/bus/i2c/devices/*/temp*_input
+ if(!d.exists()){
+ d.setPath("/sys/bus/i2c/devices/");
+ device = "";
+ }
+
+ if(d.exists()){
+ unsigned int index = 1;
+ d.setFilter(QDir::Dirs);
+ d.setSorting(QDir::Name);
+ for(unsigned int i = 0; i < d.count(); i++ ){
+ if((d[i] != ".") && (d[i] != "..")){
+ subd = d.canonicalPath() + "/" + d[i] + device;
+ subd.setFilter(QDir::Files);
+ subd.setSorting(QDir::Name);
+ for(unsigned int j = 0; j < subd.count(); j++){
+ if((subd[j] != ".") && (subd[j] != "..") && (QDir::match(subd.canonicalPath() + "/temp*_input", subd.canonicalPath() + "/" + subd[j]))){
+ QFile f(subd.canonicalPath() + "/" + subd[j]);
+ if(f.open(IO_ReadOnly)){
+ QTextStream textStream( &f );
+ QString s = textStream.readLine();
+ f.close();
+ if(!s.startsWith("-")){
+ list.push_back(new HwMonThermalSrc(inParent, f, index));
+ index++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return list;
+}
+
+QString HwMonThermalSrc::fetchValue(){
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ QTextStream textStream( &mSourceFile );
+ s = textStream.readLine();
+ mSourceFile.close();
+ s = s.stripWhiteSpace();
+ if(s.length() > 3)
+ s = s.remove(s.length() - 3, 3);
+ s = formatTemperature(s);
+ }
+ return s;
+}
+
diff --git a/src/sources/hwmonthermalsrc.h b/src/sources/hwmonthermalsrc.h
new file mode 100644
index 0000000..8372745
--- /dev/null
+++ b/src/sources/hwmonthermalsrc.h
@@ -0,0 +1,66 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef HWMONTHERMALSRC_H
+#define HWMONTHERMALSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * HwMonThermalSrc reads temperature values from /sys/class/hwmon/\*\/device/temp*_input
+ * that is provided by the hwmon kernel by the lmsensors kernel modules since version 2.6.14.
+ * /sys/bus/i2c/devices/\*\/temp*_input is used as a fall back.
+ * see /usr/src/linux/Documentation/hwmon/sysfs-interface
+ */
+class HwMonThermalSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+ HwMonThermalSrc(QWidget* inParent, const QFile& inSourceFile, unsigned int inIndex);
+ virtual ~HwMonThermalSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //HWMONTHERMALSRC_H
+
diff --git a/src/sources/i8ksrc.cpp b/src/sources/i8ksrc.cpp
new file mode 100644
index 0000000..2123919
--- /dev/null
+++ b/src/sources/i8ksrc.cpp
@@ -0,0 +1,111 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "i8ksrc.h"
+#include <qtextstream.h>
+#include <qdir.h>
+#include <klocale.h>
+
+I8kSrc::I8kSrc(QWidget* inParent, const QFile& inSourceFile, unsigned int inIndex):
+ LabelSource(inParent),
+ mIndex(inIndex),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this){
+ mID = I8kSrc::index2Name(inIndex);
+ mName = mID;
+ mDescription = i18n("This source is provided by i8k kernel module.");
+}
+
+I8kSrc::~I8kSrc(){
+}
+
+std::list<Source*>I8kSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ QFile i8kFile("/proc/i8k");
+ if(i8kFile.open(IO_ReadOnly)){
+ QTextStream textStream(&i8kFile);
+ QString s = textStream.readLine();
+ i8kFile.close();
+ QStringList entries = QStringList::split(' ', s);
+ if(entries.size() && entries[0] == "1.0"){ // support for version 1.0
+ // CPU temp
+ if(entries.size() >= 4 && !entries[3].startsWith("-"))
+ list.push_back(new I8kSrc(inParent, i8kFile, 3));
+ // left fan
+ if(entries.size() >= 7 && !entries[4].startsWith("-"))
+ list.push_back(new I8kSrc(inParent, i8kFile, 6));
+ // left fan
+ if(entries.size() >= 8 && !entries[5].startsWith("-"))
+ list.push_back(new I8kSrc(inParent, i8kFile, 7));
+ }
+ }
+ return list;
+}
+QString I8kSrc::fetchValue(){
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ QTextStream textStream(&mSourceFile);
+ s = textStream.readLine();
+ mSourceFile.close();
+ s = s.section(' ', mIndex, mIndex, QString::SectionSkipEmpty).stripWhiteSpace();
+ switch(mIndex){
+ case 3: // CPU temperature (Celsius)
+ s = formatTemperature(s);
+ break;
+ case 6: // left fan rpm
+ case 7: // right fan rpm
+ if(s.length() > 1)
+ s.truncate(s.length() - 1); //s = QString::number(s.toInt()/10);
+ s.append(" rpm");
+ break;
+ default:
+ break;
+ }
+ }
+ return s;
+}
+
+QString I8kSrc::index2Name(unsigned int inIndex){
+ switch(inIndex){
+ case 0: // /proc/i8k format version
+ return "i8k Format Version";
+ case 1: // BIOS version
+ return "Bios";
+ case 2: // serial number
+ return "Serial";
+ case 3: // CPU temperature (Celsius)
+ return "CPU";
+ case 4: // left fan status
+ return "left Fan Status";
+ case 5: // right fan status
+ return "right Fan Status";
+ case 6: // left fan rpm
+ return "left Fan";
+ case 7: // right fan rpm
+ return "right Fan";
+ case 8: // ac status
+ return "AC Status";
+ case 9: // buttons status
+ return "Button Status";
+ default:
+ return "unknown" + QString().setNum(inIndex);
+ }
+}
+
diff --git a/src/sources/i8ksrc.h b/src/sources/i8ksrc.h
new file mode 100644
index 0000000..037e518
--- /dev/null
+++ b/src/sources/i8ksrc.h
@@ -0,0 +1,74 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef I8KSRC_H
+#define I8KSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * I8kSrc reads CPU thermal and fan rpm values from /proc/i8k
+ * which is provided by the i8k kernel module.
+ */
+class I8kSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+ I8kSrc(QWidget* inParent, const QFile& inSourceFile, unsigned int inIndex);
+ virtual ~I8kSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * Returns the name (such as CPU, GPU, ...) of the sensor according to a given index
+ */
+ static QString index2Name(unsigned int inIndex);
+
+ /**
+ * the index of the source in /proc/acpi/ibm/thermal
+ */
+ unsigned int mIndex;
+
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //I8KSRC_H
+
diff --git a/src/sources/ibmacpifansrc.cpp b/src/sources/ibmacpifansrc.cpp
new file mode 100644
index 0000000..f2edf33
--- /dev/null
+++ b/src/sources/ibmacpifansrc.cpp
@@ -0,0 +1,57 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "ibmacpifansrc.h"
+#include <qtextstream.h>
+#include <qfile.h>
+#include <klocale.h>
+
+IBMACPIFanSrc::IBMACPIFanSrc(QWidget* inParent, const QFile& inSourceFile):
+ LabelSource(inParent),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this){
+ mID = "Fan";
+ mName = mID;
+ mDescription = i18n("This source is provided by the ACPI driver for IBM ThinkPads.");
+}
+
+IBMACPIFanSrc::~IBMACPIFanSrc(){
+}
+
+std::list<Source*>IBMACPIFanSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ QFile ibmFile( "/proc/acpi/ibm/fan" );
+ if(ibmFile.open(IO_ReadOnly))
+ list.push_back(new IBMACPIFanSrc(inParent, ibmFile));
+ return list;
+}
+
+QString IBMACPIFanSrc::fetchValue(){
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ while( mSourceFile.readLine( s, 64 ) != -1 )
+ if(s.startsWith("speed:"))
+ break;
+ s = s.section( ':', 1, 1 ).stripWhiteSpace() + " rpm";
+ mSourceFile.close();
+ }
+ return s;
+}
+
diff --git a/src/sources/ibmacpifansrc.h b/src/sources/ibmacpifansrc.h
new file mode 100644
index 0000000..7af22fc
--- /dev/null
+++ b/src/sources/ibmacpifansrc.h
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef IBMACPIFANSRC_H
+#define IBMACPIFANSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * IBMACPIFanSrc reads fan values from /proc/acpi/ibm/thermal
+ * which is provided by the ibm-acpi kernel module.
+ */
+class IBMACPIFanSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File and index
+ */
+ IBMACPIFanSrc(QWidget* inParent, const QFile& inSourceFile);
+ virtual ~IBMACPIFanSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //IBMACPIFANSRC_H
diff --git a/src/sources/ibmacpithermalsrc.cpp b/src/sources/ibmacpithermalsrc.cpp
new file mode 100644
index 0000000..f19281c
--- /dev/null
+++ b/src/sources/ibmacpithermalsrc.cpp
@@ -0,0 +1,88 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "ibmacpithermalsrc.h"
+#include <qtextstream.h>
+#include <qfile.h>
+#include <klocale.h>
+//#include "hal/libhal.h"
+// hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.product
+
+IBMACPIThermalSrc::IBMACPIThermalSrc(QWidget* inParent, const QFile& inSourceFile, unsigned int inIndex):
+ LabelSource(inParent),
+ mIndex(inIndex),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this){
+ //mName = mName.setNum(inIndex+1).prepend("IBM");
+ mID = IBMACPIThermalSrc::index2Name(inIndex);
+ mName = mID;
+ mDescription = i18n("This source is provided by the ACPI driver for IBM ThinkPads.");
+}
+
+IBMACPIThermalSrc::~IBMACPIThermalSrc(){
+}
+
+std::list<Source*>IBMACPIThermalSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ QFile ibmFile( "/proc/acpi/ibm/thermal" );
+ if(ibmFile.open(IO_ReadOnly)){
+ QTextStream textStream( &ibmFile );
+ QString s = textStream.readLine();
+ ibmFile.close();
+ s = s.remove("temperatures:");
+ QStringList entries = QStringList::split(' ' ,s);
+ for ( unsigned int i = 0; i < entries.size(); i++ ){
+ if(!entries[i].startsWith("-") && !entries[i].startsWith("0"))
+ list.push_back(new IBMACPIThermalSrc(inParent, ibmFile, i));
+ }
+ }
+ return list;
+}
+
+QString IBMACPIThermalSrc::fetchValue(){
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ QTextStream textStream( &mSourceFile );
+ s = textStream.readLine();
+ mSourceFile.close();
+ s = s.section(':', 1, 1).section(' ', mIndex, mIndex, QString::SectionSkipEmpty).stripWhiteSpace();
+ s = formatTemperature(s);
+ }
+ return s;
+}
+
+QString IBMACPIThermalSrc::index2Name(unsigned int inIndex){
+ switch(inIndex){
+ case 0:
+ return "CPU";
+ case 1:
+ return "MiniPCI";
+ case 2:
+ return "HDD";
+ case 3:
+ return "GPU";
+ case 4:
+ return "Battery1";
+ case 6:
+ return "Battery2";
+ default:
+ return "ibmacpi" + QString().setNum(inIndex);
+ }
+}
diff --git a/src/sources/ibmacpithermalsrc.h b/src/sources/ibmacpithermalsrc.h
new file mode 100644
index 0000000..0ea937e
--- /dev/null
+++ b/src/sources/ibmacpithermalsrc.h
@@ -0,0 +1,73 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef IBMACPITHERMALSRC_H
+#define IBMACPITHERMALSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * IBMACPIThermalSrc reads temperature values from /proc/acpi/ibm/thermal
+ * which is provided by the ibm-acpi kernel module.
+ */
+class IBMACPIThermalSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File and index
+ */
+ IBMACPIThermalSrc(QWidget* inParent, const QFile& inSourceFile, unsigned int inIndex);
+ virtual ~IBMACPIThermalSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * Returns the name (such as CPU, GPU, ...) of the sensor according to a given index
+ */
+ static QString index2Name(unsigned int inIndex);
+
+ /**
+ * the index of the source in /proc/acpi/ibm/thermal
+ */
+ unsigned int mIndex;
+
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //IBMACPITHERMALSRC_H
diff --git a/src/sources/ibmhdaps.cpp b/src/sources/ibmhdaps.cpp
new file mode 100644
index 0000000..05d945b
--- /dev/null
+++ b/src/sources/ibmhdaps.cpp
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "ibmhdaps.h"
+#include <qtextstream.h>
+#include <qdir.h>
+#include <klocale.h>
+
+IBMHDAPSSrc::IBMHDAPSSrc(QWidget* inParent, const QFile& inSourceFile):
+ LabelSource(inParent),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this){
+ mID = "HDAPS" + mSourceFile.name().section( '/', -1, -1, QString::SectionSkipEmpty ).remove("temp");
+ mName = mID;
+ mDescription = i18n("This thermal source is provided by the IBM HDAPS driver.");
+}
+
+IBMHDAPSSrc::~IBMHDAPSSrc(){
+}
+
+std::list<Source*>IBMHDAPSSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ QDir hdapsDir( "/sys/bus/platform/drivers/hdaps/hdaps" );
+ if ( hdapsDir.exists() ){
+ hdapsDir.setFilter( QDir::Files | QDir::NoSymLinks );
+ hdapsDir.setSorting( QDir::Name);
+ for ( unsigned int i = 0; i < hdapsDir.count(); i++ ){
+ if(hdapsDir[i].startsWith("temp")){
+ QFile hdapsFile(hdapsDir.canonicalPath() + "/" + hdapsDir[i]);
+ list.push_back(new IBMHDAPSSrc(inParent, hdapsFile));
+ }
+ }
+ }
+ return list;
+}
+
+QString IBMHDAPSSrc::fetchValue(){
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ QTextStream textStream( &mSourceFile );
+ s = textStream.readLine().stripWhiteSpace();
+ mSourceFile.close();
+ s = formatTemperature(s);
+ }
+ return s;
+}
diff --git a/src/sources/ibmhdaps.h b/src/sources/ibmhdaps.h
new file mode 100644
index 0000000..d696f9f
--- /dev/null
+++ b/src/sources/ibmhdaps.h
@@ -0,0 +1,65 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef IBMHDAPSSRC_H
+#define IBMHDAPSSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * IBMHDAPSSrc reads temperature values of the IBM Hard Drive Active Protection System (HDAPS)
+ * from /sys/bus/platform/drivers/hdaps/hdaps/temp1
+ * which is provided by the hdapds.ko kernel module.
+ * @author Ken Werner
+ */
+class IBMHDAPSSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+ IBMHDAPSSrc(QWidget* inParent, const QFile& inSourceFile);
+ virtual ~IBMHDAPSSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //IBMHDAPSSRC_H
diff --git a/src/sources/ibookg4thermalsrc.cpp b/src/sources/ibookg4thermalsrc.cpp
new file mode 100644
index 0000000..ba3a69a
--- /dev/null
+++ b/src/sources/ibookg4thermalsrc.cpp
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * Copyright (C) 2006 by *
+ * Flavio Castelli, [email protected] *
+ * Ken Werner, [email protected] *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "ibookg4thermalsrc.h"
+#include <qtextstream.h>
+#include <klocale.h>
+
+IbookG4ThermalSrc::IbookG4ThermalSrc(QWidget* inParent, const QFile& inSourceFile, const QString& inName):
+ LabelSource(inParent),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this){
+ mID = inName;
+ mName = mID;
+ mDescription = i18n("This source shows a thermal sensor of your iBook.");
+}
+
+IbookG4ThermalSrc::~IbookG4ThermalSrc(){
+}
+
+std::list<Source*>IbookG4ThermalSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ QFile ibookCPUFile("/sys/devices/temperatures/sensor1_temperature");
+ if(ibookCPUFile.open(IO_ReadOnly)){
+ list.push_back(new IbookG4ThermalSrc(inParent, ibookCPUFile, QString("CPU")));
+ ibookCPUFile.close();
+ }
+ QFile ibookGPUFile("/sys/devices/temperatures/sensor2_temperature");
+ if(ibookGPUFile.open(IO_ReadOnly)){
+ list.push_back(new IbookG4ThermalSrc(inParent, ibookGPUFile, QString("GPU")));
+ ibookGPUFile.close();
+ }
+ return list;
+}
+
+QString IbookG4ThermalSrc::fetchValue(){
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ QTextStream textStream( &mSourceFile );
+ s = textStream.readLine().stripWhiteSpace();
+ mSourceFile.close();
+ s= formatTemperature(s);
+ }
+ return s;
+}
+
diff --git a/src/sources/ibookg4thermalsrc.h b/src/sources/ibookg4thermalsrc.h
new file mode 100644
index 0000000..36e8340
--- /dev/null
+++ b/src/sources/ibookg4thermalsrc.h
@@ -0,0 +1,66 @@
+/***************************************************************************
+ * Copyright (C) 2006 by *
+ * Flavio Castelli, [email protected] *
+ * Ken Werner, [email protected] *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef IBOOKG4THERMALSRC_H
+#define IBOOKG4THERMALSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * @author Flavio Castelli
+ * @author Ken Werner
+ * IbookG4ThermalSrc reads temperature values from /sys/devices/temperatures/sensor[1,2]_temperature
+ * It may work on other Apple machines as well (please let me know)
+ */
+class IbookG4ThermalSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+ IbookG4ThermalSrc(QWidget* inParent, const QFile& inSourceFile, const QString& inName);
+ virtual ~IbookG4ThermalSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif // IBOOKG4THERMALSRC_H
diff --git a/src/sources/labelsource.cpp b/src/sources/labelsource.cpp
new file mode 100644
index 0000000..a2e5026
--- /dev/null
+++ b/src/sources/labelsource.cpp
@@ -0,0 +1,133 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "labelsource.h"
+#include <qlabel.h>
+#include <kcolorbutton.h>
+#include <kfontrequester.h>
+#include <qcombobox.h>
+#include <qcheckbox.h>
+#include <klocale.h>
+
+//#include "kdebug.h"
+
+LabelSource::LabelSource(QWidget* inParent):
+ TriggeredSource(inParent),
+ mParent(inParent),
+ mLabelSourcePrefs(NULL){
+}
+
+LabelSource::~LabelSource(){
+}
+
+QWidget* LabelSource::getWidget(){
+ //kdDebug() << "LabelSource::getWidget called: " << mID << endl;
+ return mLabel;
+}
+
+void LabelSource::createSubPrefs(QWidget* inParent){
+ if(!mLabelSourcePrefs){
+ mLabelSourcePrefs = new LabelSourcePrefs(inParent, "labelsourceprefsui");
+ // disable nameCheckBox if taskbarCheckBox is disabled
+ connect(mSourcePrefs->taskbarCheckBox, SIGNAL(toggled(bool)), mLabelSourcePrefs->colorLabel, SLOT(setEnabled(bool)));
+ connect(mSourcePrefs->taskbarCheckBox, SIGNAL(toggled(bool)), mLabelSourcePrefs->colorButton, SLOT(setEnabled(bool)));
+ connect(mSourcePrefs->taskbarCheckBox, SIGNAL(toggled(bool)), mLabelSourcePrefs->fontLabel, SLOT(setEnabled(bool)));
+ connect(mSourcePrefs->taskbarCheckBox, SIGNAL(toggled(bool)), mLabelSourcePrefs->fontRequester, SLOT(setEnabled(bool)));
+ connect(mSourcePrefs->taskbarCheckBox, SIGNAL(toggled(bool)), mLabelSourcePrefs->alignmentLabel, SLOT(setEnabled(bool)));
+ connect(mSourcePrefs->taskbarCheckBox, SIGNAL(toggled(bool)), mLabelSourcePrefs->alignmentComboBox, SLOT(setEnabled(bool)));
+ addPrefs(mLabelSourcePrefs);
+ }
+}
+
+void LabelSource::updatePrefsGUI(){
+ TriggeredSource::updatePrefsGUI(); // update prefs of the super class
+ mLabelSourcePrefs->colorButton->setColor(mLabel->paletteForegroundColor());
+ mLabelSourcePrefs->fontRequester->setFont(mLabel->font());
+ switch (mLabel->alignment()) {
+ case Qt::AlignCenter:
+ mLabelSourcePrefs->alignmentComboBox->setCurrentItem(1);
+ break;
+ case Qt::AlignRight:
+ mLabelSourcePrefs->alignmentComboBox->setCurrentItem(2);
+ break;
+ default: // Qt::AlignLeft
+ break;
+ mLabelSourcePrefs->alignmentComboBox->setCurrentItem(0);
+ }
+}
+
+void LabelSource::setPrefsWidgetsEnabled(bool isEnabled, bool isShownOnApplet){
+ TriggeredSource::setPrefsWidgetsEnabled(isEnabled, isShownOnApplet);
+ // disable/enable some widgets if source is disabled/enabled if(isEnabled)
+ mLabelSourcePrefs->colorLabel->setEnabled(isEnabled && isShownOnApplet);
+ mLabelSourcePrefs->colorButton->setEnabled(isEnabled && isShownOnApplet);
+ mLabelSourcePrefs->fontLabel->setEnabled(isEnabled && isShownOnApplet);
+ mLabelSourcePrefs->fontRequester->setEnabled(isEnabled && isShownOnApplet);
+ mLabelSourcePrefs->alignmentLabel->setEnabled(isEnabled && isShownOnApplet);
+ mLabelSourcePrefs->alignmentComboBox->setEnabled(isEnabled && isShownOnApplet);
+}
+
+void LabelSource::applyPrefs(){
+ TriggeredSource::applyPrefs(); // call apply prefs of the super class
+ mLabel->setPaletteForegroundColor(mLabelSourcePrefs->colorButton->color());
+ mLabel->setFont(mLabelSourcePrefs->fontRequester->font());
+ int alignID = mLabelSourcePrefs->alignmentComboBox->currentItem();
+ Qt::AlignmentFlags align = Qt::AlignCenter;
+ if(alignID == 0){
+ align = Qt::AlignLeft;
+ }else if(alignID == 2){
+ align = Qt::AlignRight;
+ }
+ mLabel->setAlignment(align);
+ updateLabel(mValue);
+}
+
+void LabelSource::savePrefs(KConfig* inKConfig){
+ TriggeredSource::savePrefs(inKConfig);
+ inKConfig->writeEntry(mID + "_color", mLabelSourcePrefs->colorButton->color());
+ inKConfig->writeEntry(mID + "_font", mLabelSourcePrefs->fontRequester->font());
+ inKConfig->writeEntry(mID + "_align", mLabel->alignment());
+}
+
+void LabelSource::loadPrefs(KConfig* inKConfig){
+ TriggeredSource::loadPrefs(inKConfig);
+ QColor color = inKConfig->readColorEntry(mID + "_color");
+ if(!color.isValid())
+ color.setRgb(0,0,0);
+ mLabel->setPaletteForegroundColor(color);
+ mLabel->setFont(inKConfig->readFontEntry(mID + "_font"));
+ mLabel->setAlignment(inKConfig->readNumEntry(mID + "_align"));
+}
+
+void LabelSource::updateLabel(const QString& inValue){
+ // update the label text
+ QString text = (getName().isEmpty() || !showName()) ? inValue : getName() + ": " + inValue;
+ //kdDebug() << "updateLabel " << getName() << ", value: " << text << endl;
+ //if(mLabel->text() != text)
+ mLabel->setText(text);
+}
+
+void LabelSource::realizeWidget(){
+ Source::realizeWidget();
+ // the prefs dialog is created in the addPrefs method
+ mLabel = new QLabel(i18n("n/a"), mParent);
+ mLabel->setTextFormat(Qt::PlainText);
+ connect(this, SIGNAL(valueUpdated(const QString&)), this, SLOT(updateLabel(const QString&)));
+}
diff --git a/src/sources/labelsource.h b/src/sources/labelsource.h
new file mode 100644
index 0000000..1a50ae0
--- /dev/null
+++ b/src/sources/labelsource.h
@@ -0,0 +1,107 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef LABELSOURCE_H
+#define LABELSOURCE_H
+
+#include "triggeredsource.h"
+#include "labelsourcePrefs.h"
+
+class QLabel;
+
+/**
+ * LabelSource displays its value on a configurable QLabel
+ * @author Ken Werner
+ */
+class LabelSource : public TriggeredSource{
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new DefaultSource from the given File
+ */
+ LabelSource(QWidget* inParent);
+
+ virtual ~LabelSource();
+
+ /**
+ * Returns the Label of this source that is displayed in the kicker
+ */
+ QWidget* getWidget();
+
+ /**
+ * fills the prefs gui with appropriate values
+ */
+ virtual void updatePrefsGUI();
+
+ /**
+ * realizes the widget. that means, create the QLabel.
+ */
+ virtual void realizeWidget();
+
+protected slots:
+ /**
+ * updates the label
+ */
+ virtual void updateLabel(const QString& inValue);
+
+ /**
+ * Applies the prefs
+ */
+ virtual void applyPrefs();
+
+ /**
+ * Saves the prefs (implicit apply)
+ */
+ virtual void savePrefs(KConfig* inKConfig);
+
+ /**
+ * Loads the prefs
+ */
+ virtual void loadPrefs(KConfig* inKConfig);
+
+ /**
+ * This method enables or disables various widgets of the preferences dialog depending on isEnabled and isShownOnApplet
+ * This method can be extended in sub classes
+ */
+ virtual void setPrefsWidgetsEnabled(bool isEnabled, bool isShownOnApplet);
+
+protected:
+ /**
+ * Allows subclasses adding their own preferences using the addPrefs method
+ */
+ virtual void createSubPrefs(QWidget* inParent);
+
+ /**
+ * Displays the content of that source
+ */
+ QLabel* mLabel;
+
+ /**
+ * the parent of the label we are going to create
+ */
+ QWidget* mParent;
+
+private:
+ /**
+ * the LabelSources part of the preferences gui
+ */
+ LabelSourcePrefs* mLabelSourcePrefs;
+};
+#endif //LABELSOURCE_H
diff --git a/src/sources/labelsourcePrefs.cpp b/src/sources/labelsourcePrefs.cpp
new file mode 100644
index 0000000..fda5ea3
--- /dev/null
+++ b/src/sources/labelsourcePrefs.cpp
@@ -0,0 +1,110 @@
+#include <kdialog.h>
+#include <klocale.h>
+/****************************************************************************
+** Form implementation generated from reading ui file './labelsourcePrefs.ui'
+**
+** Created: Thu Jun 21 19:16:51 2007
+** by: The User Interface Compiler ($Id: qt/main.cpp 3.3.7 edited Aug 31 2005 $)
+**
+** WARNING! All changes made in this file will be lost!
+****************************************************************************/
+
+#include "labelsourcePrefs.h"
+
+#include <qvariant.h>
+#include <qpushbutton.h>
+#include <qframe.h>
+#include <qlabel.h>
+#include <kcolorbutton.h>
+#include <kfontrequester.h>
+#include <qcombobox.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+#include <qwhatsthis.h>
+
+/*
+ * Constructs a LabelSourcePrefs as a child of 'parent', with the
+ * name 'name' and widget flags set to 'f'.
+ */
+LabelSourcePrefs::LabelSourcePrefs( QWidget* parent, const char* name, WFlags fl )
+ : QWidget( parent, name, fl )
+{
+ if ( !name )
+ setName( "LabelSourcePrefs" );
+ LabelSourcePrefsLayout = new QVBoxLayout( this, 0, 6, "LabelSourcePrefsLayout");
+
+ defaultSourcePrefsFrame = new QFrame( this, "defaultSourcePrefsFrame" );
+ defaultSourcePrefsFrame->setFrameShape( QFrame::NoFrame );
+ defaultSourcePrefsFrame->setFrameShadow( QFrame::Plain );
+ defaultSourcePrefsFrameLayout = new QVBoxLayout( defaultSourcePrefsFrame, 0, 6, "defaultSourcePrefsFrameLayout");
+
+ taskbartitleLabel = new QLabel( defaultSourcePrefsFrame, "taskbartitleLabel" );
+ QFont taskbartitleLabel_font( taskbartitleLabel->font() );
+ taskbartitleLabel_font.setBold( TRUE );
+ taskbartitleLabel->setFont( taskbartitleLabel_font );
+ defaultSourcePrefsFrameLayout->addWidget( taskbartitleLabel );
+
+ layout13 = new QHBoxLayout( 0, 0, 6, "layout13");
+
+ colorLabel = new QLabel( defaultSourcePrefsFrame, "colorLabel" );
+ layout13->addWidget( colorLabel );
+
+ colorButton = new KColorButton( defaultSourcePrefsFrame, "colorButton" );
+ layout13->addWidget( colorButton );
+ spacer1 = new QSpacerItem( 350, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
+ layout13->addItem( spacer1 );
+ defaultSourcePrefsFrameLayout->addLayout( layout13 );
+
+ layout17 = new QHBoxLayout( 0, 0, 6, "layout17");
+
+ fontLabel = new QLabel( defaultSourcePrefsFrame, "fontLabel" );
+ layout17->addWidget( fontLabel );
+
+ fontRequester = new KFontRequester( defaultSourcePrefsFrame, "fontRequester" );
+ layout17->addWidget( fontRequester );
+ defaultSourcePrefsFrameLayout->addLayout( layout17 );
+
+ layout18 = new QHBoxLayout( 0, 0, 6, "layout18");
+
+ alignmentLabel = new QLabel( defaultSourcePrefsFrame, "alignmentLabel" );
+ layout18->addWidget( alignmentLabel );
+
+ alignmentComboBox = new QComboBox( FALSE, defaultSourcePrefsFrame, "alignmentComboBox" );
+ layout18->addWidget( alignmentComboBox );
+ spacer2 = new QSpacerItem( 350, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
+ layout18->addItem( spacer2 );
+ defaultSourcePrefsFrameLayout->addLayout( layout18 );
+ LabelSourcePrefsLayout->addWidget( defaultSourcePrefsFrame );
+ languageChange();
+ resize( QSize(299, 135).expandedTo(minimumSizeHint()) );
+ clearWState( WState_Polished );
+}
+
+/*
+ * Destroys the object and frees any allocated resources
+ */
+LabelSourcePrefs::~LabelSourcePrefs()
+{
+ // no need to delete child widgets, Qt does it all for us
+}
+
+/*
+ * Sets the strings of the subwidgets using the current
+ * language.
+ */
+void LabelSourcePrefs::languageChange()
+{
+ setCaption( tr2i18n( "LabelSourcePrefs" ) );
+ taskbartitleLabel->setText( tr2i18n( "<br>\n"
+"Taskbar visual settings" ) );
+ colorLabel->setText( tr2i18n( "Foreground color:" ) );
+ colorButton->setText( QString::null );
+ fontLabel->setText( tr2i18n( "Font:" ) );
+ alignmentLabel->setText( tr2i18n( "Alignment:" ) );
+ alignmentComboBox->clear();
+ alignmentComboBox->insertItem( tr2i18n( "Left" ) );
+ alignmentComboBox->insertItem( tr2i18n( "Center" ) );
+ alignmentComboBox->insertItem( tr2i18n( "Right" ) );
+}
+
+#include "labelsourcePrefs.moc"
diff --git a/src/sources/labelsourcePrefs.ui b/src/sources/labelsourcePrefs.ui
new file mode 100644
index 0000000..c998dd4
--- /dev/null
+++ b/src/sources/labelsourcePrefs.ui
@@ -0,0 +1,186 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>LabelSourcePrefs</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>LabelSourcePrefs</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>299</width>
+ <height>135</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>LabelSourcePrefs</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <widget class="QFrame">
+ <property name="name">
+ <cstring>defaultSourcePrefsFrame</cstring>
+ </property>
+ <property name="frameShape">
+ <enum>NoFrame</enum>
+ </property>
+ <property name="frameShadow">
+ <enum>Plain</enum>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>taskbartitleLabel</cstring>
+ </property>
+ <property name="font">
+ <font>
+ <bold>1</bold>
+ </font>
+ </property>
+ <property name="text">
+ <string>&lt;br&gt;
+Taskbar visual settings</string>
+ </property>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout13</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>colorLabel</cstring>
+ </property>
+ <property name="text">
+ <string>Foreground color:</string>
+ </property>
+ </widget>
+ <widget class="KColorButton">
+ <property name="name">
+ <cstring>colorButton</cstring>
+ </property>
+ <property name="text">
+ <string></string>
+ </property>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer1</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>350</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </hbox>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout17</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>fontLabel</cstring>
+ </property>
+ <property name="text">
+ <string>Font:</string>
+ </property>
+ </widget>
+ <widget class="KFontRequester">
+ <property name="name">
+ <cstring>fontRequester</cstring>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>layout18</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>alignmentLabel</cstring>
+ </property>
+ <property name="text">
+ <string>Alignment:</string>
+ </property>
+ </widget>
+ <widget class="QComboBox">
+ <item>
+ <property name="text">
+ <string>Left</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Center</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Right</string>
+ </property>
+ </item>
+ <property name="name">
+ <cstring>alignmentComboBox</cstring>
+ </property>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer2</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>350</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </hbox>
+ </widget>
+ </vbox>
+ </widget>
+ </vbox>
+</widget>
+<layoutdefaults spacing="6" margin="11"/>
+<includehints>
+ <includehint>kcolorbutton.h</includehint>
+ <includehint>kfontrequester.h</includehint>
+</includehints>
+</UI>
diff --git a/src/sources/nvidiathermalsrc.cpp b/src/sources/nvidiathermalsrc.cpp
new file mode 100644
index 0000000..000ece7
--- /dev/null
+++ b/src/sources/nvidiathermalsrc.cpp
@@ -0,0 +1,175 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "nvidiathermalsrc.h"
+#include <qstringlist.h>
+#include <qregexp.h>
+#include <klocale.h>
+#include <kdebug.h>
+
+#ifndef HAVE_NVCONTROL
+ #include <kprocio.h>
+#else
+ #include <qpaintdevice.h> // for the Device* pointer
+
+ // include the NVCtrl include stuff
+ #include <X11/Xlib.h>
+ #include <fixx11h.h> // needed for Qt, to include X11 header
+extern "C" {
+ #include <NVCtrlLib.h>
+}
+#endif
+
+#ifndef HAVE_NVCONTROL
+NVidiaThermalSrc::NVidiaThermalSrc(QWidget* inParent, const QString& inID, const QString& inName):
+ LabelSource(inParent), mProcess(0) {
+#else
+NVidiaThermalSrc::NVidiaThermalSrc(QWidget* inParent, const QString& inID, const QString& inName, unsigned int attrib):
+ LabelSource(inParent), mAttrib(attrib) {
+#endif
+ mID = inID;
+ mName = inName;
+ mDescription = i18n("This source is provided by the nVidia GPU card driver tools");
+
+ mRefreshTimer = new QTimer(this, "default refresh handler" );
+ // connect the timer
+ connect(mRefreshTimer, SIGNAL(timeout()), this, SLOT(fetchValue()));
+ connect(this, SIGNAL(enabledChanged(bool, Source*)), this, SLOT(enable(bool)));
+}
+
+NVidiaThermalSrc::~NVidiaThermalSrc(){
+#ifndef HAVE_NVCONTROL
+ delete mProcess;
+#endif
+}
+
+std::list<Source*>NVidiaThermalSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+#ifndef HAVE_NVCONTROL
+ // see if the path contains nvidia-settings. if yes,
+ // execute it and look for the query type "GPUCoreTemp"
+ // and "GPUAmbientTemp" and create two instances for each
+ // of them
+ // start nvidia-settings, if available and wait for it to exit.
+ KProcIO proc;
+ proc << "nvidia-settings"
+ << "-n" // don't load config
+ << "-q" << "GPUCoreTemp"
+ << "-q" << "GPUAmbientTemp";
+ if(!proc.start(KProcess::Block))
+ return list;
+
+ // now see what it printed...
+ QString ln;
+ QString pout;
+ while(proc.readln(ln) != -1)
+ pout+= ln + '\n';
+
+ if(pout.contains("Attribute 'GPUCoreTemp'"))
+ list.push_back(new NVidiaThermalSrc(inParent, "GPUCoreTemp", "NVidiaCore"));
+ if(pout.contains("Attribute 'GPUAmbientTemp'"))
+ list.push_back(new NVidiaThermalSrc(inParent, "GPUAmbientTemp", "NVidiaAmbient"));
+#else
+ int evt_base = 0, err_base = 0, temp;
+ Display * dpy = QPaintDevice::x11AppDisplay();
+
+ // do we have the XNVCtrl extension loaded?
+ if(!XNVCTRLQueryExtension(dpy, &evt_base, &err_base))
+ return list;
+
+ // core temp support?
+ if(XNVCTRLQueryAttribute (dpy, 0, 0,
+ NV_CTRL_GPU_CORE_TEMPERATURE, &temp)
+ )
+ list.push_back(new NVidiaThermalSrc(inParent, "GPUCoreTemp", "NVidiaCore",
+ NV_CTRL_GPU_CORE_TEMPERATURE));
+
+ // ambient temp support?
+ if(XNVCTRLQueryAttribute (dpy, 0, 0,
+ NV_CTRL_AMBIENT_TEMPERATURE, &temp)
+ )
+ list.push_back(new NVidiaThermalSrc(inParent, "GPUAmbientTemp", "NVidiaAmbient",
+ NV_CTRL_AMBIENT_TEMPERATURE));
+#endif
+ return list;
+}
+
+void NVidiaThermalSrc::enable(bool inEnable){
+ if(inEnable && !mRefreshTimer->isActive()){ // start the timer
+ fetchValue();
+ mRefreshTimer->start(3000);
+ }else if(!inEnable && mRefreshTimer->isActive()) // stops the timer
+ mRefreshTimer->stop();
+}
+
+
+void NVidiaThermalSrc::evaluateStdout(){
+#ifndef HAVE_NVCONTROL
+ QString val = i18n("n/a");
+
+ // now see what it printed...
+ QString ln;
+ QString pout;
+ while(mProcess->readln(ln) != -1)
+ pout+= ln + '\n';
+ QRegExp regexp("Attribute\\s'" + mID + "'.*(\\d+)\\.");
+ if(regexp.search(pout) != -1)
+ val = formatTemperature(regexp.cap(1));
+ mValue = val;
+ emit valueUpdated(mValue); // calls updateLabel(mValue) of LabelSource
+
+ // delete the object, to be ready for a new run
+ delete mProcess;
+ mProcess = 0;
+#endif
+}
+
+#ifndef HAVE_NVCONTROL
+void NVidiaThermalSrc::createProcess() {
+ mProcess = new KProcIO;
+ connect(mProcess, SIGNAL(processExited(KProcess*)), this, SLOT(evaluateStdout()));
+ *mProcess << "nvidia-settings" << "-n"
+ << "-q" << mID;
+}
+#endif
+
+QString NVidiaThermalSrc::fetchValue(){
+#ifndef HAVE_NVCONTROL
+ if(!mProcess) {
+ createProcess();
+ if(!mProcess->start()) {
+ mValue = "n/a";
+ delete mProcess;
+ mProcess = 0;
+ }
+ }
+ return getValue();
+#else
+ int temp;
+ Display * dpy = QPaintDevice::x11AppDisplay();
+ if(XNVCTRLQueryAttribute (dpy, 0, 0, mAttrib, &temp))
+ mValue = formatTemperature(QString::number(temp));
+ else
+ mValue = "n/a";
+ emit valueUpdated(mValue); // calls updateLabel(mValue) of LabelSource
+ return mValue;
+#endif
+}
+
diff --git a/src/sources/nvidiathermalsrc.h b/src/sources/nvidiathermalsrc.h
new file mode 100644
index 0000000..db2d0ab
--- /dev/null
+++ b/src/sources/nvidiathermalsrc.h
@@ -0,0 +1,86 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef NVIDIATHERMALSRC_H
+#define NVIDIATHERMALSRC_H
+
+#include <config.h>
+#include "labelsource.h"
+#include <list>
+#include <qtimer.h>
+
+class KProcIO;
+/**
+ * NVidiaThermalSrc calls nvidia-settings to fetch the thermal values of the GPU
+ * @author Ken Werner
+ */
+class NVidiaThermalSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+#ifndef HAVE_NVCONTROL
+ NVidiaThermalSrc(QWidget* inParent, const QString& inID, const QString& inName);
+#else
+ NVidiaThermalSrc(QWidget* inParent, const QString& inID, const QString& inName, unsigned int attrib);
+#endif
+ virtual ~NVidiaThermalSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * runs the nvidia-settings command
+ */
+ virtual QString fetchValue();
+
+protected slots:
+ /**
+ * enables (starts the timer) or disables (stops the timer)
+ * this method is called if mSource gets enabled or disabled
+ */
+ void enable(bool inEnable);
+
+private:
+#ifndef HAVE_NVCONTROL
+ /**
+ * create mProcess and connects its exited signal to
+ * the evaluateStdout slot.
+ */
+ void createProcess();
+ KProcIO* mProcess;
+#else
+ unsigned int mAttrib;
+#endif
+ /**
+ * The refresh timer
+ */
+ QTimer* mRefreshTimer;
+
+private slots:
+ /**
+ * updates the label
+ */
+ virtual void evaluateStdout();
+};
+#endif //NVIDIATHERMALSRC_H
diff --git a/src/sources/omnibookthermalsrc.cpp b/src/sources/omnibookthermalsrc.cpp
new file mode 100644
index 0000000..a8a8203
--- /dev/null
+++ b/src/sources/omnibookthermalsrc.cpp
@@ -0,0 +1,58 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "omnibookthermalsrc.h"
+#include <qtextstream.h>
+#include <qfile.h>
+#include <klocale.h>
+
+OmnibookThermalSrc::OmnibookThermalSrc(QWidget* inParent, const QFile& inSourceFile):
+ LabelSource(inParent),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this){
+ mID = "CPU";
+ mName = mID;
+ mDescription = i18n("This source is provided by the Omnibook Configuration Tools & Patches.");
+}
+
+OmnibookThermalSrc::~OmnibookThermalSrc(){
+}
+
+std::list<Source*>OmnibookThermalSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ QFile omiFile( "/proc/omnibook/temperature" );
+ if(omiFile.open(IO_ReadOnly)){
+ list.push_back(new OmnibookThermalSrc(inParent, omiFile));
+ }
+ return list;
+}
+
+QString OmnibookThermalSrc::fetchValue(){
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ QTextStream textStream( &mSourceFile );
+ s = textStream.readLine();
+ mSourceFile.close();
+ s = s.section(':',-1,-1, QString::SectionSkipEmpty).stripWhiteSpace();
+ s = formatTemperature(s.left(s.length()-1));
+ }
+ return s;
+}
+
diff --git a/src/sources/omnibookthermalsrc.h b/src/sources/omnibookthermalsrc.h
new file mode 100644
index 0000000..e4133ce
--- /dev/null
+++ b/src/sources/omnibookthermalsrc.h
@@ -0,0 +1,64 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef OMNIBOOKTHERMALSRC_H
+#define OMNIBOOKTHERMALSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * OmnibookThermalSrc reads temperature values from /proc/omnibook/temperature
+ * which is provided by the omnibook kernel module.
+ */
+class OmnibookThermalSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+ OmnibookThermalSrc(QWidget* inParent, const QFile& inSourceFile);
+ virtual ~OmnibookThermalSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //OMNIBOOKTHERMALSRC_H
+
diff --git a/src/sources/source.cpp b/src/sources/source.cpp
new file mode 100644
index 0000000..605537f
--- /dev/null
+++ b/src/sources/source.cpp
@@ -0,0 +1,222 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "source.h"
+#include <math.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qcheckbox.h>
+#include <qlabel.h>
+#include <klocale.h>
+#include <kglobal.h>
+
+//#include "kdebug.h"
+
+Source::Source(QWidget* inParent):
+ mID(""),
+ mPosition(0),
+ mName(""),
+ mDescription(""),
+ mEnabled(true),
+ mMaybeEnabled(true),
+ mShowOnApplet(true),
+ mMaybeShowOnApplet(true),
+ mShowName(true),
+ mToolTipEnabled(true),
+ mSourcePrefs(0) {
+}
+
+Source::~Source(){
+}
+
+const QString& Source::getID() const{
+ return mID;
+}
+
+
+int Source::getPosition() const{
+ return mPosition;
+}
+
+void Source::setPosition(int inPosition, KConfig* inKConfig){
+ mPosition = inPosition;
+ inKConfig->writeEntry(mID + "_position", mPosition);
+}
+
+const QString& Source::getName() const{
+ return mName;
+}
+
+const QString& Source::getDescription() const{
+ return mDescription;
+}
+
+bool Source::isMetric() const{
+ return mIsMetric;
+}
+
+bool Source::isEnabled() const{
+ return mEnabled;
+}
+
+bool Source::showOnApplet() const{
+ return mShowOnApplet;
+}
+
+bool Source::showName() const{
+ return mShowName;
+}
+
+bool Source::isToolTipEnabled() const{
+ return mToolTipEnabled;
+}
+
+void Source::setMaybeEnabled(bool inMaybeEnabled){
+ if(inMaybeEnabled != mMaybeEnabled){
+ mMaybeEnabled = inMaybeEnabled;
+ // disable/enable some widgets if source is disabled/enabled
+ setPrefsWidgetsEnabled(mMaybeEnabled, mSourcePrefs->taskbarCheckBox->isChecked());
+ }
+}
+
+QWidget* Source::createPrefs(QWidget* inParent){
+ if(!mSourcePrefs){
+ mSourcePrefs = new SourcePrefs(inParent, "sourceprefsui");
+
+ // disable nameCheckBox if taskbarCheckBox is disabled
+ connect(mSourcePrefs->taskbarCheckBox, SIGNAL(toggled(bool)), mSourcePrefs->nameCheckBox, SLOT(setEnabled(bool)));
+
+ // add prefs widgets from sub classes
+ createSubPrefs(mSourcePrefs);
+
+ // add bottom vspacer
+ mSourcePrefs->layout()->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding) );
+
+ updatePrefsGUI(); // fill the prefs gui
+ }
+ return mSourcePrefs;
+}
+
+SourcePrefs* Source::getPrefs(){
+ return mSourcePrefs;
+}
+
+void Source::updatePrefsGUI(){
+ // set values
+ mSourcePrefs->nameLineEdit->setText(mName);
+ mSourcePrefs->descriptionLabel->setText(mDescription);
+ mSourcePrefs->taskbarCheckBox->setChecked(mShowOnApplet);
+ mSourcePrefs->nameCheckBox->setChecked(mShowName);
+ mSourcePrefs->tooltipCheckBox->setChecked(mToolTipEnabled);
+
+ // disable/enable some widgets if source is disabled/enabled
+ setPrefsWidgetsEnabled(mEnabled, mShowOnApplet);
+}
+
+void Source::setPrefsWidgetsEnabled(bool isEnabled, bool isShownOnApplet){
+ mSourcePrefs->nameLabel->setEnabled(isEnabled);
+ mSourcePrefs->nameLineEdit->setEnabled(isEnabled);
+ mSourcePrefs->taskbarCheckBox->setEnabled(isEnabled);
+ mSourcePrefs->nameCheckBox->setEnabled(isEnabled && isShownOnApplet);
+ mSourcePrefs->tooltipCheckBox->setEnabled(isEnabled);
+}
+
+void Source::addPrefs(QWidget* inParent){
+ if(inParent != NULL)
+ mSourcePrefs->layout()->add(inParent);
+}
+
+void Source::applyPrefs(){
+ mMaybeShowOnApplet = mSourcePrefs->taskbarCheckBox->isChecked();
+ mShowName = mSourcePrefs->nameCheckBox->isChecked();
+ mName = mSourcePrefs->nameLineEdit->text();
+ mToolTipEnabled = mSourcePrefs->tooltipCheckBox->isChecked();
+
+ //kdDebug() << "Source::applyPrefs() mEnabled: " << mEnabled << ", mMaybeEnabled: " << mMaybeEnabled << endl;
+ if(mEnabled != mMaybeEnabled){
+ mEnabled = mMaybeEnabled;
+ //kdDebug() << "Source::applyPrefs() emit enabledChanged: " << mEnabled << endl;
+ emit enabledChanged(mEnabled, this);
+ // force hide/show on kicker. if the user just
+ // disabled/enabled the source, we want to show / hide
+ // the source too, also if the "show on kicker" property
+ // did not changed. so, force this here.
+ mShowOnApplet = !mMaybeShowOnApplet;
+ }
+
+ if(!mEnabled)
+ emit displaySource(false, this);
+ else if(mMaybeShowOnApplet != mShowOnApplet) {
+ emit displaySource(mMaybeShowOnApplet, this);
+ }
+ mShowOnApplet = mMaybeShowOnApplet;
+}
+
+void Source::savePrefs(KConfig* inKConfig){
+ inKConfig->writeEntry(mID + "_position", mPosition);
+ inKConfig->writeEntry(mID + "_enabled", mEnabled);
+ inKConfig->writeEntry(mID + "_showOnApplet", mShowOnApplet);
+ inKConfig->writeEntry(mID + "_showName", mShowName);
+ inKConfig->writeEntry(mID + "_name", mName);
+ inKConfig->writeEntry(mID + "_toolTipEnabled", mToolTipEnabled);
+}
+
+void Source::loadPrefs(KConfig* inKConfig){
+ mPosition = inKConfig->readNumEntry(mID + "_position", mPosition);
+ mEnabled = inKConfig->readBoolEntry(mID + "_enabled", mEnabled);
+ mMaybeEnabled = mEnabled;
+ mShowOnApplet = inKConfig->readBoolEntry(mID + "_showOnApplet", mShowOnApplet);
+ mMaybeShowOnApplet = mShowOnApplet;
+ mShowName = inKConfig->readBoolEntry(mID + "_showName", mShowName);
+ mName = inKConfig->readEntry(mID + "_name", mName);
+ mToolTipEnabled = inKConfig->readBoolEntry(mID + "_toolTipEnabled", mToolTipEnabled);
+
+ // initializing
+ // this signal is usually catched by the ThreadedTrigger who enables or disables the fetch loop
+ emit enabledChanged(mEnabled, this);
+}
+
+// utility methods
+QString Source::formatTemperature(const QString& temp) const {
+ if(mIsMetric) {
+ return temp + QString::fromUtf8(" °C");
+ } else {
+ return QString::number(celsiusToFahrenheit(temp.toInt())).append(QString::fromUtf8(" °F"));
+ }
+}
+
+QString Source::KHzinHumanReadable( uint value ) const{
+ if( value >= 1000000 )
+ return QString::number( round(value/1000000.0, 1) ) + " GHz";
+ else if( value >= 1000 )
+ return QString::number( round(value/1000.0, -1) ) + " MHz";
+ else
+ return QString::number( value ) + " KHz";
+}
+double Source::round(double inValue, int inDigits) const{
+ return floor(inValue * pow( 10, inDigits) + 0.5) * pow(10, -inDigits);
+}
+int Source::celsiusToFahrenheit(int inCelsius) const{
+ return qRound(1.8 * inCelsius + 32);
+}
+
+void Source::realizeWidget(){
+ mIsMetric = KGlobal::locale()->measureSystem() == KLocale::Metric;
+}
diff --git a/src/sources/source.h b/src/sources/source.h
new file mode 100644
index 0000000..6f72666
--- /dev/null
+++ b/src/sources/source.h
@@ -0,0 +1,249 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef SOURCE_H
+#define SOURCE_H
+#include <qstring.h>
+
+#include "sourceprefs.h"
+#include <kconfig.h>
+
+// Forward Declarationss
+class QVBoxLayout;
+
+/**
+ * This abstract Source is the super class of all sources and provides just the basics.
+ * @author Ken Werner
+ */
+class Source : public QObject {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source
+ */
+ Source(QWidget* inParent);
+ virtual ~Source();
+
+ /**
+ * Returns the internal Name of this source
+ */
+ const QString& getID() const;
+
+ /**
+ * Returns the position of this source in the layout
+ */
+ int getPosition() const;
+
+ /**
+ * Sets the position of this source in the layout
+ */
+ void setPosition(int inPosition, KConfig* inKConfig);
+
+ /**
+ * Returns the Name of this source
+ */
+ const QString& getName() const;
+
+ /**
+ * Returns the Description of this source
+ */
+ const QString& getDescription() const;
+
+ /**
+ * Returns true if this source is currently enabled otherwise false
+ */
+ bool isEnabled() const;
+
+ /**
+ * Returns true if this source is shown on the kicker applet (taskbar) otherwise false
+ */
+ bool showOnApplet() const;
+
+ /**
+ * Returns true if this source shows it's name in kicker otherwise false
+ */
+ bool showName() const;
+
+ /**
+ * Returns true if this source is currently enabled otherwise false
+ */
+ bool isToolTipEnabled() const;
+
+ /**
+ * Returns the widget of this source that is displayed in the kicker
+ */
+ virtual QWidget* getWidget() = 0;
+
+ /**
+ * Returns the formatted value of this source
+ */
+ virtual QString getValue() const = 0;
+
+ /**
+ * Creates the preference panel of this source and calls createSubPrefs
+ */
+ virtual QWidget* createPrefs(QWidget* inParent);
+
+ /**
+ * returnes the preference panel of this source
+ */
+ virtual SourcePrefs* getPrefs();
+
+ /**
+ * fills the prefs gui with appropriate values
+ */
+ virtual void updatePrefsGUI();
+
+ /**
+ * realizes the event. this function will be called
+ * by the applet to tell the Source to actually create
+ * its widget. it will always be called from the GUI thread.
+ */
+ virtual void realizeWidget() = 0;
+
+public slots:
+ /**
+ * Might enable or disable the source
+ * Source is only enabled/disabled if applyPrefs is called afterwards
+ */
+ virtual void setMaybeEnabled(bool inMaybeEnabled);
+
+ /**
+ * Applies the preferences
+ */
+ virtual void applyPrefs();
+
+ /**
+ * Saves the preferences (implicit apply)
+ */
+ virtual void savePrefs(KConfig* inKConfig);
+
+ /**
+ * Loads the preferences
+ */
+ virtual void loadPrefs(KConfig* inKConfig);
+
+signals:
+ /**
+ * This signal is emitted whenever the enabled flag (mEnabled) of this source has changed
+ */
+ void enabledChanged(bool inEnabled, Source* inSource); // needed by kima.cpp to add sources to its layout
+ /**
+ * This signal is emitted whenever this Source should be added or removed from the display (layout) of the kicker applet
+ */
+ void displaySource(bool inDisplay, Source* inSource);
+
+protected:
+ /**
+ * This method can be overridden in sub classes to add specific the preference panels
+ */
+ virtual void addPrefs(QWidget* inParent);
+
+ /**
+ * Allows subclasses adding their own preferences using the addPrefs method
+ */
+ virtual void createSubPrefs(QWidget* inParent) = 0;
+
+ /**
+ * This method enables or disables various widgets of the preferences dialog depending on isEnabled and isShownOnApplet
+ * This method can be extended in sub classes
+ */
+ virtual void setPrefsWidgetsEnabled(bool isEnabled, bool isShownOnApplet);
+
+ /**
+ * returns true if the measure system is set metric, false if imperial
+ */
+ bool isMetric() const;
+
+ /**
+ * The ID of the source
+ * must be unique among the sources
+ */
+ QString mID;
+ /**
+ * The Position of the source in the layout
+ */
+ int mPosition;
+ /**
+ * The name of that source showed in the kicker
+ */
+ QString mName;
+ /**
+ * The description of that source
+ */
+ QString mDescription;
+ /**
+ * Indicates whether that source is enabled (showed on the kicker) or not
+ */
+ bool mEnabled;
+ /**
+ * stores the SourcListItem checkbox value
+ * and is updated through SourceListItem
+ */
+ bool mMaybeEnabled;
+ /**
+ * Indicates whether to show that source on the kicker applet (taskbar) or not
+ * mEnabled controls whether this source is displayed or not, see mIsDisplayed
+ */
+ bool mShowOnApplet;
+ /**
+ * Indicates whether that source is shown on the kicker applet (taskbar) or not. this is temporary and stores only what the user configured in the preferences dialog. it is applied to mShowOnApplet in applyPrefs
+ */
+ bool mMaybeShowOnApplet;
+ /**
+ * Indicates whether to show the name in kicker or not
+ */
+ bool mShowName;
+ /**
+ * Indicates whether that source is showed on the tooltip or not
+ */
+ bool mToolTipEnabled;
+
+ // utility methods
+ /**
+ * formats the given temperature into a string which has
+ * a degree sign / fahrenheit sign depending on the locale used.
+ */
+ QString formatTemperature(const QString& temp) const;
+ /**
+ * Translates a given frequency in KHz to a human readable string
+ */
+ QString KHzinHumanReadable(uint value) const;
+ /**
+ * Translates degree Celsius to degree Fahrenheit
+ */
+ int celsiusToFahrenheit(int inCelsius) const;
+ /**
+ * Returns inValue rounded to inDigits
+ */
+ double round(double inValue, int inDigits=0) const;
+
+ /**
+ * The preference panel of that source
+ */
+ SourcePrefs* mSourcePrefs;
+private:
+
+ /**
+ * indicates whether the measure system is set metric or imperial
+ */
+ bool mIsMetric;
+};
+#endif //SOURCE_H
diff --git a/src/sources/sourceprefs.cpp b/src/sources/sourceprefs.cpp
new file mode 100644
index 0000000..cabce8b
--- /dev/null
+++ b/src/sources/sourceprefs.cpp
@@ -0,0 +1,88 @@
+#include <kdialog.h>
+#include <klocale.h>
+/****************************************************************************
+** Form implementation generated from reading ui file './sourceprefs.ui'
+**
+** Created: Thu Jun 21 19:16:51 2007
+** by: The User Interface Compiler ($Id: qt/main.cpp 3.3.7 edited Aug 31 2005 $)
+**
+** WARNING! All changes made in this file will be lost!
+****************************************************************************/
+
+#include "sourceprefs.h"
+
+#include <qvariant.h>
+#include <qpushbutton.h>
+#include <qlabel.h>
+#include <qlineedit.h>
+#include <qcheckbox.h>
+#include <qlayout.h>
+#include <qtooltip.h>
+#include <qwhatsthis.h>
+
+/*
+ * Constructs a SourcePrefs as a child of 'parent', with the
+ * name 'name' and widget flags set to 'f'.
+ */
+SourcePrefs::SourcePrefs( QWidget* parent, const char* name, WFlags fl )
+ : QWidget( parent, name, fl )
+{
+ if ( !name )
+ setName( "SourcePrefs" );
+ SourcePrefsLayout = new QVBoxLayout( this, 0, 6, "SourcePrefsLayout");
+
+ descriptionLabel = new QLabel( this, "descriptionLabel" );
+ SourcePrefsLayout->addWidget( descriptionLabel );
+
+ hBoxLayout = new QHBoxLayout( 0, 0, 6, "hBoxLayout");
+
+ nameLabel = new QLabel( this, "nameLabel" );
+ hBoxLayout->addWidget( nameLabel );
+
+ nameLineEdit = new QLineEdit( this, "nameLineEdit" );
+ hBoxLayout->addWidget( nameLineEdit );
+ spacer8 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
+ hBoxLayout->addItem( spacer8 );
+ SourcePrefsLayout->addLayout( hBoxLayout );
+
+ taskbarCheckBox = new QCheckBox( this, "taskbarCheckBox" );
+ SourcePrefsLayout->addWidget( taskbarCheckBox );
+
+ hBoxLayout2 = new QHBoxLayout( 0, 0, 6, "hBoxLayout2");
+ spacer8_2 = new QSpacerItem( 20, 20, QSizePolicy::Fixed, QSizePolicy::Minimum );
+ hBoxLayout2->addItem( spacer8_2 );
+
+ nameCheckBox = new QCheckBox( this, "nameCheckBox" );
+ hBoxLayout2->addWidget( nameCheckBox );
+ SourcePrefsLayout->addLayout( hBoxLayout2 );
+
+ tooltipCheckBox = new QCheckBox( this, "tooltipCheckBox" );
+ SourcePrefsLayout->addWidget( tooltipCheckBox );
+ languageChange();
+ resize( QSize(203, 127).expandedTo(minimumSizeHint()) );
+ clearWState( WState_Polished );
+}
+
+/*
+ * Destroys the object and frees any allocated resources
+ */
+SourcePrefs::~SourcePrefs()
+{
+ // no need to delete child widgets, Qt does it all for us
+}
+
+/*
+ * Sets the strings of the subwidgets using the current
+ * language.
+ */
+void SourcePrefs::languageChange()
+{
+ setCaption( tr2i18n( "SourcePrefs" ) );
+ descriptionLabel->setText( tr2i18n( "description" ) );
+ nameLabel->setText( tr2i18n( "Name:" ) );
+ taskbarCheckBox->setText( tr2i18n( "Show this source in Taskbar" ) );
+ nameCheckBox->setText( tr2i18n( "Show name in Taskbar" ) );
+ tooltipCheckBox->setText( tr2i18n( "Show this source in ToolTip" ) );
+}
+
+#include "sourceprefs.moc"
diff --git a/src/sources/sourceprefs.ui b/src/sources/sourceprefs.ui
new file mode 100644
index 0000000..6d42984
--- /dev/null
+++ b/src/sources/sourceprefs.ui
@@ -0,0 +1,127 @@
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+<class>SourcePrefs</class>
+<widget class="QWidget">
+ <property name="name">
+ <cstring>SourcePrefs</cstring>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>203</width>
+ <height>127</height>
+ </rect>
+ </property>
+ <property name="caption">
+ <string>SourcePrefs</string>
+ </property>
+ <vbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <property name="margin">
+ <number>0</number>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>descriptionLabel</cstring>
+ </property>
+ <property name="text">
+ <string>description</string>
+ </property>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>hBoxLayout</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <widget class="QLabel">
+ <property name="name">
+ <cstring>nameLabel</cstring>
+ </property>
+ <property name="text">
+ <string>Name:</string>
+ </property>
+ </widget>
+ <widget class="QLineEdit">
+ <property name="name">
+ <cstring>nameLineEdit</cstring>
+ </property>
+ </widget>
+ <spacer>
+ <property name="name">
+ <cstring>spacer8</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Expanding</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </hbox>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>taskbarCheckBox</cstring>
+ </property>
+ <property name="text">
+ <string>Show this source in Taskbar</string>
+ </property>
+ </widget>
+ <widget class="QLayoutWidget">
+ <property name="name">
+ <cstring>hBoxLayout2</cstring>
+ </property>
+ <hbox>
+ <property name="name">
+ <cstring>unnamed</cstring>
+ </property>
+ <spacer>
+ <property name="name">
+ <cstring>spacer8</cstring>
+ </property>
+ <property name="orientation">
+ <enum>Horizontal</enum>
+ </property>
+ <property name="sizeType">
+ <enum>Fixed</enum>
+ </property>
+ <property name="sizeHint">
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>nameCheckBox</cstring>
+ </property>
+ <property name="text">
+ <string>Show name in Taskbar</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ <widget class="QCheckBox">
+ <property name="name">
+ <cstring>tooltipCheckBox</cstring>
+ </property>
+ <property name="text">
+ <string>Show this source in ToolTip</string>
+ </property>
+ </widget>
+ </vbox>
+</widget>
+<layoutdefaults spacing="6" margin="11"/>
+</UI>
diff --git a/src/sources/sysfreqsrc.cpp b/src/sources/sysfreqsrc.cpp
new file mode 100644
index 0000000..239f20b
--- /dev/null
+++ b/src/sources/sysfreqsrc.cpp
@@ -0,0 +1,66 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "sysfreqsrc.h"
+#include <qtextstream.h>
+#include <qfile.h>
+#include <qdir.h>
+#include <klocale.h>
+
+SysFreqSrc::SysFreqSrc(QWidget* inParent, const QFile& inSourceFile):
+ LabelSource(inParent),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this){
+ mID = "cpufreq" + mSourceFile.name().section( '/', -3, -3, QString::SectionSkipEmpty ).remove("cpu");
+ mName = mID;
+ mDescription = i18n("This source is provided by the Linux kernel cpufreq subsystem.");
+}
+
+SysFreqSrc::~SysFreqSrc(){
+}
+
+std::list<Source*>SysFreqSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+
+ QDir cpuDir( "/sys/devices/system/cpu" );
+ if ( cpuDir.exists() ){
+ cpuDir.setFilter( QDir::Dirs | QDir::NoSymLinks );
+ cpuDir.setSorting( QDir::Name);
+ for ( unsigned int i = 0; i < cpuDir.count(); i++ ){
+ if(cpuDir[i].startsWith("cpu")){
+ QFile sysFreqFile(cpuDir.canonicalPath() + "/" + cpuDir[i] + "/cpufreq/scaling_cur_freq");
+ if(sysFreqFile.open(IO_ReadOnly))
+ list.push_back(new SysFreqSrc(inParent, sysFreqFile));
+ }
+ }
+ }
+ return list;
+}
+
+QString SysFreqSrc::fetchValue(){
+ QString s = "n/a";
+ if(mSourceFile.open(IO_ReadOnly)){
+ QTextStream textStream(&mSourceFile);
+ s = KHzinHumanReadable(textStream.readLine().toUInt());
+ mSourceFile.close();
+ }
+ return s;
+}
+
diff --git a/src/sources/sysfreqsrc.h b/src/sources/sysfreqsrc.h
new file mode 100644
index 0000000..c2a9a60
--- /dev/null
+++ b/src/sources/sysfreqsrc.h
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef SYSFREQSRC_H
+#define SYSFREQSRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * SysFreqSrc reads frequency values from /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
+ */
+class SysFreqSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File
+ */
+ SysFreqSrc(QWidget* inParent, const QFile& inSourceFile);
+ virtual ~SysFreqSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+private:
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //SYSFREQSRC_H
+
diff --git a/src/sources/threadedtrigger.cpp b/src/sources/threadedtrigger.cpp
new file mode 100644
index 0000000..11f07b5
--- /dev/null
+++ b/src/sources/threadedtrigger.cpp
@@ -0,0 +1,67 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "threadedtrigger.h"
+#include <qapplication.h>
+
+//#include "kdebug.h"
+
+ThreadedTrigger::ThreadedTrigger(TriggeredSource* inSource, unsigned long inRefreshSleep):
+ mSource(inSource),
+ mRefreshSleep(inRefreshSleep),
+ mRunning(false)
+ {
+ connect(mSource, SIGNAL(enabledChanged(bool, Source*)), this, SLOT(enable(bool)));
+}
+
+ThreadedTrigger::~ThreadedTrigger(){
+ enable(false);
+}
+
+void ThreadedTrigger::enable(bool inEnable){
+ if(inEnable && !mRunning){ // start this thread (calls run())
+ //kdDebug() << "start thread " << mSource->getName() << endl;
+ // start the thread
+ mRunning = true;
+ this->start(QThread::LowPriority);
+ }else if(!inEnable && mRunning){ // stops the thread
+ //kdDebug() << "stop thread " << mSource->getName() << endl;
+ mRunning = false;
+ mWaitMutex.lock();
+ mWaitCond.wakeOne();
+ mWaitMutex.unlock();
+ this->wait();
+ }
+}
+
+void ThreadedTrigger::run(){
+ mWaitMutex.lock();
+ while( mRunning ) {
+ QString text = mSource->fetchValue();
+ UpdateEvent* ue = new UpdateEvent(text); // Qt will delete the ue when done
+ QApplication::postEvent(mSource, ue); // send the event to the TriggeredSource
+ if(mWaitCond.wait(&mWaitMutex, mRefreshSleep))
+ break; // we were woken up
+ }
+ // if we are here, the mutex must be locked:
+ // 1. QWaitCondition::wait locks it when it returns
+ // 2. mWaitMutex is locked when we enter the loop
+ mWaitMutex.unlock(); // unlock it again
+}
diff --git a/src/sources/threadedtrigger.h b/src/sources/threadedtrigger.h
new file mode 100644
index 0000000..8d84d5f
--- /dev/null
+++ b/src/sources/threadedtrigger.h
@@ -0,0 +1,89 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef THREADEDTRIGGER_H
+#define THREADEDTRIGGER_H
+
+#include "source.h"
+#include "updateevent.h"
+#include "triggeredsource.h"
+#include <qwaitcondition.h>
+#include <qmutex.h>
+#include <qthread.h>
+#include <qevent.h>
+#include <qobject.h>
+
+/**
+ * ThreadedTrigger calls the fetchValue method of a source asynchronous using a thread
+ * @author Ken Werner
+ */
+class ThreadedTrigger : public QObject, QThread{
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new ThreadedTrigger
+ */
+ ThreadedTrigger(TriggeredSource* inSource, unsigned long inRefreshSleep = 1000);
+
+ virtual ~ThreadedTrigger();
+
+protected:
+ /**
+ * fetches tcalls the fetchValue method periodically
+ * and sends an UpdateEvent to the source
+ */
+ virtual void run();
+
+protected slots:
+ /**
+ * enables (starts the thread) or disables (stops the thread)
+ * this method is called if mSource gets enabled or disabled
+ */
+ void enable(bool inEnable);
+
+private:
+ /**
+ * pointer to the TriggeredSource
+ **/
+ TriggeredSource* mSource;
+
+ /**
+ * time in milli seconds between two value fetches
+ */
+ unsigned long mRefreshSleep;
+
+ /**
+ * indicates whether this thread runs
+ */
+ bool mRunning;
+
+ /*
+ * this is the condition, on which this thread sleeps
+ * mRefreshSleep milliseconds.
+ */
+ QWaitCondition mWaitCond;
+
+ /*
+ * this mutex ensures that the thread always sleeps on the
+ * condition, if we signal it.
+ */
+ QMutex mWaitMutex;
+};
+#endif //THREADEDTRIGGER_H
diff --git a/src/sources/triggeredsource.cpp b/src/sources/triggeredsource.cpp
new file mode 100644
index 0000000..88dde5e
--- /dev/null
+++ b/src/sources/triggeredsource.cpp
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "triggeredsource.h"
+#include "updateevent.h"
+#include <qapplication.h>
+
+//#include "kdebug.h"
+
+TriggeredSource::TriggeredSource(QWidget* inParent):
+ Source(inParent){
+}
+
+TriggeredSource::~TriggeredSource(){
+}
+
+void TriggeredSource::customEvent(QCustomEvent* event){
+ if(event->type() == UpdateEvent::TYPE ){
+ UpdateEvent* ue = static_cast<UpdateEvent*>(event);
+ // update mValue
+ mValue = ue->getMessage();
+ //kdDebug() << "emit valueUpdated(mValue); value: " << mValue << endl;
+ emit valueUpdated(mValue);
+ }else{
+ Source::customEvent(event);
+ }
+}
+
+QString TriggeredSource::getValue() const{
+ return mValue;
+}
diff --git a/src/sources/triggeredsource.h b/src/sources/triggeredsource.h
new file mode 100644
index 0000000..9beba25
--- /dev/null
+++ b/src/sources/triggeredsource.h
@@ -0,0 +1,72 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef TRIGGEREDSOURCE_H
+#define TRIGGEREDSOURCE_H
+
+#include "source.h"
+#include <qevent.h>
+
+/**
+ * TriggeredSource provides fetchValue and
+ * can be triggered asynchronously by ThreadedTrigger
+ * @author Ken Werner
+ */
+class TriggeredSource : public Source{
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new TriggeredSource
+ */
+ TriggeredSource(QWidget* inParent);
+
+ virtual ~TriggeredSource();
+
+public slots:
+
+ /**
+ * Returns the formatted value of this source
+ */
+ virtual QString getValue() const;
+
+ /**
+ * Fetches and returns the value of this source
+ * This method might be called from a thread so don't call it directly
+ */
+ virtual QString fetchValue() = 0;
+
+signals:
+ /**
+ * This signal is emitted whenever the value of this source (mValue) is updated
+ */
+ void valueUpdated(const QString& inValue);
+
+protected:
+ /**
+ * consumes the UpdateEvent
+ */
+ virtual void customEvent(QCustomEvent* event);
+
+ /**
+ * the buffered value of this source
+ */
+ QString mValue;
+};
+#endif //TRIGGEREDSOURCE_H
diff --git a/src/sources/updateevent.cpp b/src/sources/updateevent.cpp
new file mode 100644
index 0000000..f16f6b5
--- /dev/null
+++ b/src/sources/updateevent.cpp
@@ -0,0 +1,29 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Johannes Schaub *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "updateevent.h"
+
+UpdateEvent::UpdateEvent(const QString& inMessage):
+ QCustomEvent(UpdateEvent::TYPE),
+ mMessage(inMessage){
+}
+const QString& UpdateEvent::getMessage() const{
+ return mMessage;
+}
diff --git a/src/sources/updateevent.h b/src/sources/updateevent.h
new file mode 100644
index 0000000..ae6ef24
--- /dev/null
+++ b/src/sources/updateevent.h
@@ -0,0 +1,38 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Johannes Schaub *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef UPDATEEVENT_H
+#define UPDATEEVENT_H
+
+#include <qevent.h>
+
+/**
+ * UpdateEvent is a custom event to update the QObject of the ThreadedTrigger periodically
+ */
+class UpdateEvent: public QCustomEvent{
+public:
+ UpdateEvent(const QString& inMessage);
+ static const int TYPE = QEvent::User + 1;
+ const QString& getMessage() const;
+private:
+ QString mMessage;
+};
+
+#endif //UPDATEEVENT_H
diff --git a/src/sources/uptimesrc.cpp b/src/sources/uptimesrc.cpp
new file mode 100644
index 0000000..fd392f5
--- /dev/null
+++ b/src/sources/uptimesrc.cpp
@@ -0,0 +1,70 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#include "uptimesrc.h"
+#include <qtextstream.h>
+#include <klocale.h>
+
+UptimeSrc::UptimeSrc(QWidget* inParent, const QFile& inSourceFile):
+ LabelSource(inParent),
+ mSourceFile(inSourceFile.name()),
+ mTrigger(this, 30000){ // 30 seconds
+ mEnabled = false; // disable this source by default to to save kicker space
+ mID = "Uptime";
+ mName = mID;
+ mDescription = i18n("This source is provided by /proc/uptime.");
+}
+
+UptimeSrc::~UptimeSrc(){
+}
+
+std::list<Source*>UptimeSrc::createInstances(QWidget* inParent){
+ std::list<Source*> list;
+ QFile uptimeFile("/proc/uptime" );
+ if(uptimeFile.open(IO_ReadOnly))
+ list.push_back(new UptimeSrc(inParent, uptimeFile));
+ return list;
+}
+
+QString UptimeSrc::fetchValue(){
+ QString s = "n/a";
+ int secs;
+ if(mSourceFile.open(IO_ReadOnly)) {
+ QTextStream stream( &mSourceFile );
+ stream >> secs;
+
+ //QString seconds = QString::number(secs % 60).rightJustify(2, '0');
+ QString minutes = QString::number(secs / 60 % 60).rightJustify(2, '0');
+ QString hours = QString::number(secs / 3600 % 24).rightJustify(2, '0');
+ QString days = QString::number(secs / 86400);
+ if(days != "0")
+ s = mTimeFormatLong.arg(days).arg(hours).arg(minutes);
+ else
+ s = mTimeFormatShort.arg(hours).arg(minutes);
+ mSourceFile.close();
+ }
+ return s;
+}
+
+void UptimeSrc::realizeWidget() {
+ LabelSource::realizeWidget();
+ mTimeFormatLong = i18n("%1d %2:%3");
+ mTimeFormatShort = i18n("%1:%2");
+}
diff --git a/src/sources/uptimesrc.h b/src/sources/uptimesrc.h
new file mode 100644
index 0000000..e92a521
--- /dev/null
+++ b/src/sources/uptimesrc.h
@@ -0,0 +1,74 @@
+/***************************************************************************
+ * Copyright (C) 2007 by Ken Werner *
+ * *
+ * 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. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ***************************************************************************/
+
+#ifndef UPTIMESRC_H
+#define UPTIMESRC_H
+#include "labelsource.h"
+#include "threadedtrigger.h"
+#include <qfile.h>
+#include <list>
+
+/**
+ * UptimeSrc reads fan values from /proc/acpi/ibm/thermal
+ * which is provided by the ibm-acpi kernel module.
+ */
+class UptimeSrc : public LabelSource {
+ Q_OBJECT //macro which activates signals and slots (moc)
+public:
+ /**
+ * Creates a new Source from the given File and index
+ */
+ UptimeSrc(QWidget* inParent, const QFile& inSourceFile);
+ virtual ~UptimeSrc();
+
+ /**
+ * Creates instances of that Source (and returns pointers to them)
+ */
+ static std::list<Source*> createInstances(QWidget* inParent);
+
+ /**
+ * Fetches and returns the value of this source
+ * This method is called from a thread so don't call it directly
+ */
+ virtual QString fetchValue();
+
+
+ /**
+ * get the format for the akku time left from i18n.
+ */
+ virtual void realizeWidget();
+private:
+ /**
+ * The file from which the value is read
+ */
+ QFile mSourceFile;
+
+ /**
+ * the format of the time display. short and long version
+ */
+ QString mTimeFormatShort;
+ QString mTimeFormatLong;
+
+ /**
+ * triggers the fetchValue method
+ */
+ ThreadedTrigger mTrigger;
+};
+#endif //UPTIMESRC_H