diff options
Diffstat (limited to 'ksim/monitors/i8k')
-rw-r--r-- | ksim/monitors/i8k/Makefile.am | 15 | ||||
-rw-r--r-- | ksim/monitors/i8k/i8k.desktop | 62 | ||||
-rw-r--r-- | ksim/monitors/i8k/ksimi8k.cpp | 257 | ||||
-rw-r--r-- | ksim/monitors/i8k/ksimi8k.h | 102 |
4 files changed, 436 insertions, 0 deletions
diff --git a/ksim/monitors/i8k/Makefile.am b/ksim/monitors/i8k/Makefile.am new file mode 100644 index 0000000..d46a0d9 --- /dev/null +++ b/ksim/monitors/i8k/Makefile.am @@ -0,0 +1,15 @@ +kde_module_LTLIBRARIES = ksim_i8k.la +ksim_i8k_la_SOURCES = ksimi8k.cpp + +ksim_i8k_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) +ksim_i8k_la_LIBADD = ../../library/libksimcore.la + +EXTRA_DIST = i8k.desktop + +INCLUDES= -I$(top_srcdir)/ksim/library \ + $(all_includes) + +METASOURCES = AUTO + +mon_DATA = i8k.desktop +mondir = $(kde_datadir)/ksim/monitors diff --git a/ksim/monitors/i8k/i8k.desktop b/ksim/monitors/i8k/i8k.desktop new file mode 100644 index 0000000..322fda3 --- /dev/null +++ b/ksim/monitors/i8k/i8k.desktop @@ -0,0 +1,62 @@ +[Desktop Entry] +Comment=Dell I8K Hardware Monitor Plugin +Comment[ar]=ملحق لمراقبة عتاد Dell I8K +Comment[bg]=Мониторинг на Dell I8K +Comment[bs]=Dell I8K dodatak za nadzor hardvera +Comment[ca]=Connector per a controlar el maquinari Dell I8K +Comment[cs]=Modul sledování hardwaru pro Dell I8K +Comment[cy]=Ategyn Arsylwydd Caledwedd Dell I8K +Comment[de]=Dell I8K Hardware Überwachungs-Plugin +Comment[el]=Πρόσθετο εποπτείας υλικού Dell I8K +Comment[es]=Extensión de monitorización de hardware para Dell I8K +Comment[et]=Dell I8K riistvara monitooringu plugin +Comment[eu]=Dell I8K Hardwarearen Plugin Begiralea +Comment[fa]=وصلۀ نمایشگر سختافزار Dell I8K +Comment[fi]=Dell I8K-laitteistomonitoriliitännäinen +Comment[fr]=Module de surveillance du Dell l8K +Comment[ga]=Breiseán Monatóireachta Cruaearraí Dell I8K +Comment[hi]=डेल I8K हार्डवेयर मॉनीटर प्लगइन +Comment[hu]=Dell I8K hardvermonitor bővítőmodul +Comment[is]=Íforrit til að fylgjast með Dell I8K vélbúnaði +Comment[it]=Plugin di controllo hardware Dell I8K +Comment[ja]=Dell I8K ハードウェアモニタプラグイン +Comment[ka]=Dell I8K მოწყობილობათა მონიტორის მოდული +Comment[kk]=Dell I8K жабдықтарын бақылау модулі +Comment[km]=កម្មវិធីជំនួយរបស់កម្មវិធីត្រួតពិនិត្យផ្នែករឹង Dell I8K +Comment[lt]=Dell I8K aparatinės įrangos stebėjimo priedas +Comment[mk]=Приклучок за следење на хардверот Dell I8K +Comment[ms]=Plug masuk Pemerhati Perkakasan Dell I8K +Comment[nb]=Programtillegg for overvåkning av maskinvare Dell I8K +Comment[nds]=Kiekmoduul för Dell I8K-Hardware +Comment[ne]=डेल I8K हार्डवेयर मोनिटर प्लगइन +Comment[nl]=Dell I8000 Hardware Monitor-plugin +Comment[nn]=Programtillegg for overvaking av Dell I8K-maskinvare +Comment[pa]=Dell I8K ਜੰਤਰ ਨਿਗਰਾਨ ਪਲੱਗਿੰਨ +Comment[pl]=Wtyczka monitorowania Dell I8K +Comment[pt]='Plugin' de monitorização de hardware para o Dell I8K +Comment[pt_BR]=Plug-in de monitoramento do Hardware Dell I8K +Comment[ro]=Modul monitorizare Dell I8K +Comment[ru]=Модуль монитора оборудования Dell I8K +Comment[sk]=Modul pre monitorovanie hardware Dell I8K +Comment[sl]=Vstavek za opazovanje strojne opreme Dell I8K +Comment[sr]=Прикључак за надгледање Dell-овог I8K хардвера +Comment[sr@Latn]=Priključak za nadgledanje Dell-ovog I8K hardvera +Comment[sv]=Insticksprogram för Dell I8K-övervakning +Comment[ta]=டெல்I8K வன்பொருள் கண்காணி சொருகுபொருள் +Comment[tg]=Модули Дидабони Сахтафзори Dell I8K +Comment[tr]=Dell I8K Donanım Monitör Plugini +Comment[uk]=Втулок датчика апаратного забезпечення Dell I8K +Comment[wa]=Tchôke-divins di corwaitaedje di l' éndjolreye pol Dell I8K +Comment[zh_CN]=Dell I8K 硬件邮件监视器插件 +Comment[zh_TW]=Dell I8K 硬體監視器外掛程式 +Icon=hdd_mount +Name=Dell I8K +Name[fr]=Dell l8K +Name[he]=Dell l8k +Name[hi]=डेल I8K +Name[nb]=Dell 18K +Name[ne]=डेल I8K +Name[sr]=Dell-ов I8K +Name[sr@Latn]=Dell-ov I8K +Name[ta]= டெல் I8K +X-KSIM-LIBRARY=i8k diff --git a/ksim/monitors/i8k/ksimi8k.cpp b/ksim/monitors/i8k/ksimi8k.cpp new file mode 100644 index 0000000..ff995b0 --- /dev/null +++ b/ksim/monitors/i8k/ksimi8k.cpp @@ -0,0 +1,257 @@ +/* Dell i8K Hardware Monitor Plug-in for KSim + * + * Copyright (C) 2003 Nadeem Hasan <nhasan@kde.org> + * + * 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 "ksimi8k.h" + +#include <qlayout.h> +#include <qtimer.h> +#include <qfile.h> +#include <qtextstream.h> +#include <qregexp.h> +#include <qlabel.h> +#include <qcheckbox.h> + +#include <label.h> +#include <klocale.h> +#include <kapplication.h> +#include <kconfig.h> +#include <kaboutapplication.h> +#include <knuminput.h> +#include <kdebug.h> + +KSIM_INIT_PLUGIN(I8KPlugin); + +I8KPlugin::I8KPlugin(const char *name) + : KSim::PluginObject(name) +{ + setConfigFileName(instanceName()); +} + +I8KPlugin::~I8KPlugin() +{ +} + +KSim::PluginView *I8KPlugin::createView(const char *className) +{ + return new I8KView(this, className); +} + +KSim::PluginPage *I8KPlugin::createConfigPage(const char *className) +{ + return new I8KConfig(this, className); +} + +void I8KPlugin::showAbout() +{ + QString version = kapp->aboutData()->version(); + + KAboutData aboutData(instanceName(), + I18N_NOOP("KSim I8K Plugin"), version.latin1(), + I18N_NOOP("Dell I8K Hardware Monitor plugin"), + KAboutData::License_GPL, "(C) 2003 Nadeem Hasan"); + + aboutData.addAuthor("Nadeem Hasan", I18N_NOOP("Author"), + "nhasan@kde.org"); + + KAboutApplication(&aboutData).exec(); +} + +I8KView::I8KView(KSim::PluginObject *parent, const char *name) + : KSim::PluginView(parent, name), + m_timer( 0L ), m_procFile( 0L ), m_procStream( 0L ) +{ + initGUI(); + + m_timer = new QTimer( this ); + + m_reData = new QRegExp( "\\S+\\s+\\S+\\s+\\S+\\s+(\\d+)\\s+\\S+" + "\\s+\\S+\\s+(\\d+)\\s+(\\d+)\\s+\\S+\\s+\\S+" ); + + openStream(); + reparseConfig(); +} + +I8KView::~I8KView() +{ + closeStream(); + + delete m_timer; + delete m_reData; +} + +void I8KView::reparseConfig() +{ + config()->setGroup("I8KPlugin"); + + m_unit = config()->readEntry( "Unit", "C" ); + m_interval = config()->readNumEntry( "Interval", 5 ); + + if ( m_procStream ) + { + m_timer->stop(); + m_timer->start( m_interval*1000 ); + } + + updateView(); +} + +void I8KView::openStream() +{ + kdDebug( 2003 ) << "i8k: Trying /proc/i8k...." << endl; + + m_timer->stop(); + + if ( ( m_procFile = fopen( "/proc/i8k", "r" ) ) ) + { + m_procStream = new QTextIStream( m_procFile ); + disconnect( m_timer, 0, 0, 0 ); + connect( m_timer, SIGNAL( timeout() ), SLOT( updateView() ) ); + m_timer->start( m_interval*1000 ); + + kdDebug( 2003 ) << "i8k: Success" << endl; + } + else + { + // i8k module is not loaded. Try again after 30 secs. + disconnect( m_timer, 0, 0, 0 ); + connect( m_timer, SIGNAL( timeout() ), SLOT( openStream() ) ); + m_timer->start( 30*1000 ); + kdDebug( 2003 ) << "i8k: Failed...retry after 30 secs" << endl; + } +} + +void I8KView::closeStream() +{ + if ( m_procFile ) + fclose( m_procFile ); + + if ( m_procStream ) + delete m_procStream; + + m_procFile = 0L; + m_procStream = 0L; + m_timer->stop(); +} + +void I8KView::initGUI() +{ + QVBoxLayout *layout = new QVBoxLayout( this ); + + m_fan1Label = new KSim::Label( this ); + m_fan2Label = new KSim::Label( this ); + m_tempLabel = new KSim::Label( this ); + + layout->addWidget( m_fan1Label ); + layout->addWidget( m_fan2Label ); + layout->addWidget( m_tempLabel ); +} + +void I8KView::updateView() +{ + kdDebug( 2003 ) << "i8k: Updating..." << endl; + int cputemp=0, rightspeed=0, leftspeed=0; + + if ( m_procStream ) + { + fseek( m_procFile, 0L, SEEK_SET ); + + QString line = m_procStream->read(); + + if ( line.isEmpty() ) + { + // i8k module is no longer available, is it possible? + closeStream(); + openStream(); + return; + } + + if ( m_reData->search( line ) > -1 ) + { + QStringList matches = m_reData->capturedTexts(); + + cputemp = matches[ 1 ].toInt(); + leftspeed = matches[ 2 ].toInt(); + rightspeed = matches[ 3 ].toInt(); + + if ( m_unit == "F" ) + cputemp = ( cputemp*9/5 ) + 32; + } + } + + if ( rightspeed > 0 ) + m_fan1Label->setText( i18n( "Right fan: %1 RPM" ).arg( rightspeed ) ); + else + m_fan1Label->setText( i18n( "Right fan: Off" ) ); + + if ( leftspeed > 0 ) + m_fan2Label->setText( i18n( "Left fan: %1 RPM" ).arg( leftspeed ) ); + else + m_fan2Label->setText( i18n( "Left fan: Off" ) ); + + m_tempLabel->setText( i18n( "CPU temp: %1°%2" ).arg( cputemp ) + .arg( m_unit ) ); +} + +I8KConfig::I8KConfig(KSim::PluginObject *parent, const char *name) + : KSim::PluginPage(parent, name) +{ + m_unit = new QCheckBox( i18n( "Show temperature in Fahrenheit" ), + this ); + QLabel *label = new QLabel( i18n( "Update interval:" ), this ); + m_interval = new KIntNumInput( this ); + m_interval->setRange( 2, 60, 1, true ); + m_interval->setSuffix( i18n( " sec" ) ); + + QGridLayout *layout = new QGridLayout( this, 3, 2, 0, + KDialog::spacingHint() ); + + layout->addMultiCellWidget( m_unit, 0, 0, 0, 1 ); + layout->addWidget( label, 1, 0 ); + layout->addWidget( m_interval, 1, 1 ); + layout->setColStretch( 1, 1 ); + layout->setRowStretch( 2, 1 ); +} + +I8KConfig::~I8KConfig() +{ +} + +void I8KConfig::readConfig() +{ + config()->setGroup("I8KPlugin"); + + QString unit = config()->readEntry( "Unit", "C" ); + int interval = config()->readNumEntry( "Interval", 5 ); + + m_unit->setChecked( unit == "F" ); + m_interval->setValue( interval ); +} + +void I8KConfig::saveConfig() +{ + config()->setGroup("I8KPlugin"); + + config()->writeEntry( "Unit", m_unit->isChecked()? "F" : "C" ); + config()->writeEntry( "Interval", m_interval->value() ); +} + +#include "ksimi8k.moc" + +/* vim: et sw=2 ts=2 +*/ diff --git a/ksim/monitors/i8k/ksimi8k.h b/ksim/monitors/i8k/ksimi8k.h new file mode 100644 index 0000000..4357508 --- /dev/null +++ b/ksim/monitors/i8k/ksimi8k.h @@ -0,0 +1,102 @@ +/* Dell i8K Hardware Monitor Plug-in for KSim + * + * Copyright (C) 2003 Nadeem Hasan <nhasan@kde.org> + * + * 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 KSIMI8K_H +#define KSIMI8K_H + +#include <stdio.h> + +#include <pluginmodule.h> + +class QTimer; +class QTextIStream; +class QRegExp; +class QCheckBox; +class KIntNumInput; + +namespace KSim +{ + class Label; +} + +class I8KPlugin : public KSim::PluginObject +{ + public: + I8KPlugin(const char *name); + ~I8KPlugin(); + + virtual KSim::PluginView *createView(const char *); + virtual KSim::PluginPage *createConfigPage(const char *); + + virtual void showAbout(); +}; + +class I8KView : public KSim::PluginView +{ + Q_OBJECT + public: + I8KView(KSim::PluginObject *parent, const char *name); + ~I8KView(); + + virtual void reparseConfig(); + + protected: + + void initGUI(); + void closeStream(); + + protected slots: + + void openStream(); + void updateView(); + + private: + + QString m_unit; + int m_interval; + + KSim::Label *m_fan1Label, *m_fan2Label, *m_tempLabel; + QTimer *m_timer; + FILE *m_procFile; + QTextIStream *m_procStream; + QRegExp *m_reData; +}; + +class I8KConfig : public KSim::PluginPage +{ + Q_OBJECT + public: + I8KConfig(KSim::PluginObject *parent, const char *name); + ~I8KConfig(); + + virtual void saveConfig(); + virtual void readConfig(); + + private slots: + + private: + + QCheckBox *m_unit; + KIntNumInput *m_interval; +}; + +#endif // KSIMI8K_H + +/* vim: et sw=2 ts=2 +*/ |