summaryrefslogtreecommitdiffstats
path: root/ksysguard/gui/ksgrd
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /ksysguard/gui/ksgrd
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'ksysguard/gui/ksgrd')
-rw-r--r--ksysguard/gui/ksgrd/HostConnector.cc217
-rw-r--r--ksysguard/gui/ksgrd/HostConnector.h74
-rw-r--r--ksysguard/gui/ksgrd/Makefile.am34
-rw-r--r--ksysguard/gui/ksgrd/SensorAgent.cc260
-rw-r--r--ksysguard/gui/ksgrd/SensorAgent.h137
-rw-r--r--ksysguard/gui/ksgrd/SensorClient.h209
-rw-r--r--ksysguard/gui/ksgrd/SensorManager.cc432
-rw-r--r--ksysguard/gui/ksgrd/SensorManager.h126
-rw-r--r--ksysguard/gui/ksgrd/SensorShellAgent.cc141
-rw-r--r--ksysguard/gui/ksgrd/SensorShellAgent.h77
-rw-r--r--ksysguard/gui/ksgrd/SensorSocketAgent.cc137
-rw-r--r--ksysguard/gui/ksgrd/SensorSocketAgent.h71
-rw-r--r--ksysguard/gui/ksgrd/StyleEngine.cc176
-rw-r--r--ksysguard/gui/ksgrd/StyleEngine.h86
-rw-r--r--ksysguard/gui/ksgrd/StyleSettings.cc201
-rw-r--r--ksysguard/gui/ksgrd/StyleSettings.h78
-rw-r--r--ksysguard/gui/ksgrd/TimerSettings.cc94
-rw-r--r--ksysguard/gui/ksgrd/TimerSettings.h56
18 files changed, 2606 insertions, 0 deletions
diff --git a/ksysguard/gui/ksgrd/HostConnector.cc b/ksysguard/gui/ksgrd/HostConnector.cc
new file mode 100644
index 000000000..5762d08b3
--- /dev/null
+++ b/ksysguard/gui/ksgrd/HostConnector.cc
@@ -0,0 +1,217 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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 <kapplication.h>
+#include <kaccelmanager.h>
+#include <kcombobox.h>
+#include <klocale.h>
+
+#include <qbuttongroup.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qradiobutton.h>
+#include <qspinbox.h>
+#include <qtooltip.h>
+#include <qwhatsthis.h>
+
+#include "HostConnector.h"
+
+HostConnector::HostConnector( QWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Connect Host" ), Help | Ok | Cancel, Ok,
+ parent, name, true, true )
+{
+ QFrame *page = plainPage();
+ QGridLayout *layout = new QGridLayout( page, 2, 2, 0, spacingHint() );
+ layout->setColStretch( 1, 1 );
+
+ QLabel *label = new QLabel( i18n( "Host:" ), page );
+ layout->addWidget( label, 0, 0 );
+
+ mHostNames = new KComboBox( true, page );
+ mHostNames->setMaxCount( 20 );
+ mHostNames->setInsertionPolicy( QComboBox::AtTop );
+ mHostNames->setAutoCompletion( true );
+ mHostNames->setDuplicatesEnabled( false );
+ layout->addWidget( mHostNames, 0, 1 );
+ label->setBuddy( mHostNames );
+ QWhatsThis::add( mHostNames, i18n( "Enter the name of the host you want to connect to." ) );
+
+ mHostNameLabel = new QLabel( page );
+ mHostNameLabel->hide();
+ layout->addWidget( mHostNameLabel, 0, 1 );
+
+ QButtonGroup *group = new QButtonGroup( 0, Qt::Vertical,
+ i18n( "Connection Type" ), page );
+ QGridLayout *groupLayout = new QGridLayout( group->layout(), 4, 4,
+ spacingHint() );
+ groupLayout->setAlignment( Qt::AlignTop );
+
+ mUseSsh = new QRadioButton( i18n( "ssh" ), group );
+ mUseSsh->setEnabled( true );
+ mUseSsh->setChecked( true );
+ QWhatsThis::add( mUseSsh, i18n( "Select this to use the secure shell to login to the remote host." ) );
+ groupLayout->addWidget( mUseSsh, 0, 0 );
+
+ mUseRsh = new QRadioButton( i18n( "rsh" ), group );
+ QWhatsThis::add( mUseRsh, i18n( "Select this to use the remote shell to login to the remote host." ) );
+ groupLayout->addWidget( mUseRsh, 0, 1 );
+
+ mUseDaemon = new QRadioButton( i18n( "Daemon" ), group );
+ QWhatsThis::add( mUseDaemon, i18n( "Select this if you want to connect to a ksysguard daemon that is running on the machine you want to connect to, and is listening for client requests." ) );
+ groupLayout->addWidget( mUseDaemon, 0, 2 );
+
+ mUseCustom = new QRadioButton( i18n( "Custom command" ), group );
+ QWhatsThis::add( mUseCustom, i18n( "Select this to use the command you entered below to start ksysguardd on the remote host." ) );
+ groupLayout->addWidget( mUseCustom, 0, 3 );
+
+ label = new QLabel( i18n( "Port:" ), group );
+ groupLayout->addWidget( label, 1, 0 );
+
+ mPort = new QSpinBox( 1, 65535, 1, group );
+ mPort->setEnabled( false );
+ mPort->setValue( 3112 );
+ QToolTip::add( mPort, i18n( "Enter the port number on which the ksysguard daemon is listening for connections." ) );
+ groupLayout->addWidget( mPort, 1, 2 );
+
+ label = new QLabel( i18n( "e.g. 3112" ), group );
+ groupLayout->addWidget( label, 1, 3 );
+
+ label = new QLabel( i18n( "Command:" ), group );
+ groupLayout->addWidget( label, 2, 0 );
+
+ mCommands = new KComboBox( true, group );
+ mCommands->setEnabled( false );
+ mCommands->setMaxCount( 20 );
+ mCommands->setInsertionPolicy( QComboBox::AtTop );
+ mCommands->setAutoCompletion( true );
+ mCommands->setDuplicatesEnabled( false );
+ QWhatsThis::add( mCommands, i18n( "Enter the command that runs ksysguardd on the host you want to monitor." ) );
+ groupLayout->addMultiCellWidget( mCommands, 2, 2, 2, 3 );
+ label->setBuddy( mCommands );
+
+ label = new QLabel( i18n( "e.g. ssh -l root remote.host.org ksysguardd" ), group );
+ groupLayout->addMultiCellWidget( label, 3, 3, 2, 3 );
+
+ layout->addMultiCellWidget( group, 1, 1, 0, 1 );
+
+ connect( mUseCustom, SIGNAL( toggled( bool ) ),
+ mCommands, SLOT( setEnabled( bool ) ) );
+ connect( mUseDaemon, SIGNAL( toggled( bool ) ),
+ mPort, SLOT( setEnabled( bool ) ) );
+ connect( mHostNames->lineEdit(), SIGNAL( textChanged ( const QString & ) ),
+ this, SLOT( slotHostNameChanged( const QString & ) ) );
+ enableButtonOK( !mHostNames->lineEdit()->text().isEmpty() );
+ KAcceleratorManager::manage( this );
+}
+
+HostConnector::~HostConnector()
+{
+}
+
+void HostConnector::slotHostNameChanged( const QString &_text )
+{
+ enableButtonOK( !_text.isEmpty() );
+}
+
+void HostConnector::setHostNames( const QStringList &list )
+{
+ mHostNames->insertStringList( list );
+}
+
+QStringList HostConnector::hostNames() const
+{
+ QStringList list;
+
+ for ( int i = 0; i < mHostNames->count(); ++i )
+ list.append( mHostNames->text( i ) );
+
+ return list;
+}
+
+void HostConnector::setCommands( const QStringList &list )
+{
+ mCommands->insertStringList( list );
+}
+
+QStringList HostConnector::commands() const
+{
+ QStringList list;
+
+ for ( int i = 0; i < mCommands->count(); ++i )
+ list.append( mCommands->text( i ) );
+
+ return list;
+}
+
+void HostConnector::setCurrentHostName( const QString &hostName )
+{
+ if ( !hostName.isEmpty() ) {
+ mHostNames->hide();
+ mHostNameLabel->setText( hostName );
+ mHostNameLabel->show();
+ enableButtonOK( true );//enable true when mHostNames is empty and hidden fix #66955
+ } else {
+ mHostNameLabel->hide();
+ mHostNames->show();
+ mHostNames->setFocus();
+ }
+}
+
+QString HostConnector::currentHostName() const
+{
+ return mHostNames->currentText();
+}
+
+QString HostConnector::currentCommand() const
+{
+ return mCommands->currentText();
+}
+
+int HostConnector::port() const
+{
+ return mPort->value();
+}
+
+bool HostConnector::useSsh() const
+{
+ return mUseSsh->isChecked();
+}
+
+bool HostConnector::useRsh() const
+{
+ return mUseRsh->isChecked();
+}
+
+bool HostConnector::useDaemon() const
+{
+ return mUseDaemon->isChecked();
+}
+
+bool HostConnector::useCustom() const
+{
+ return mUseCustom->isChecked();
+}
+
+void HostConnector::slotHelp()
+{
+ kapp->invokeHelp( "CONNECTINGTOOTHERHOSTS", "ksysguard/the-sensor-browser.html" );
+}
+
+#include "HostConnector.moc"
diff --git a/ksysguard/gui/ksgrd/HostConnector.h b/ksysguard/gui/ksgrd/HostConnector.h
new file mode 100644
index 000000000..eadf728cd
--- /dev/null
+++ b/ksysguard/gui/ksgrd/HostConnector.h
@@ -0,0 +1,74 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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 KSG_HOSTCONNECTOR_H
+#define KSG_HOSTCONNECTOR_H
+
+#include <kdialogbase.h>
+
+class KComboBox;
+
+class QLabel;
+class QRadioButton;
+class QSpinBox;
+
+class HostConnector : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ HostConnector( QWidget *parent, const char *name = 0 );
+ ~HostConnector();
+
+ void setHostNames( const QStringList &list );
+ QStringList hostNames() const;
+
+ void setCommands( const QStringList &list );
+ QStringList commands() const;
+
+ void setCurrentHostName( const QString &hostName );
+
+ QString currentHostName() const;
+ QString currentCommand() const;
+ int port() const;
+
+ bool useSsh() const;
+ bool useRsh() const;
+ bool useDaemon() const;
+ bool useCustom() const;
+
+ protected slots:
+ virtual void slotHelp();
+ void slotHostNameChanged( const QString &_text );
+ private:
+ KComboBox *mCommands;
+ KComboBox *mHostNames;
+
+ QLabel *mHostNameLabel;
+
+ QRadioButton *mUseSsh;
+ QRadioButton *mUseRsh;
+ QRadioButton *mUseDaemon;
+ QRadioButton *mUseCustom;
+
+ QSpinBox *mPort;
+};
+
+#endif
diff --git a/ksysguard/gui/ksgrd/Makefile.am b/ksysguard/gui/ksgrd/Makefile.am
new file mode 100644
index 000000000..ff5f0aa47
--- /dev/null
+++ b/ksysguard/gui/ksgrd/Makefile.am
@@ -0,0 +1,34 @@
+
+# set the include path for X, qt and KDE
+INCLUDES= -I$(srcdir)/../SensorDisplayLib $(all_includes)
+
+lib_LTLIBRARIES = libksgrd.la
+
+libksgrd_la_LDFLAGS = -no-undefined -version-info 3:0:2 $(all_libraries)
+libksgrd_la_LIBADD = $(LIB_KDEUI)
+
+# Which sources should be compiled for ksysguard.
+libksgrd_la_SOURCES = \
+ HostConnector.cc \
+ SensorAgent.cc \
+ SensorManager.cc \
+ SensorShellAgent.cc \
+ SensorSocketAgent.cc \
+ StyleEngine.cc \
+ StyleSettings.cc \
+ TimerSettings.cc
+
+ksgrdincludedir = $(includedir)/ksgrd
+ksgrdinclude_HEADERS = \
+ HostConnector.h \
+ SensorAgent.h \
+ SensorClient.h \
+ SensorManager.h \
+ SensorShellAgent.h \
+ SensorSocketAgent.h \
+ StyleEngine.h \
+ StyleSettings.h \
+ TimerSettings.h
+
+# just to make sure, automake makes them
+libksgrd_la_METASOURCES = AUTO
diff --git a/ksysguard/gui/ksgrd/SensorAgent.cc b/ksysguard/gui/ksgrd/SensorAgent.cc
new file mode 100644
index 000000000..a24bf5594
--- /dev/null
+++ b/ksysguard/gui/ksgrd/SensorAgent.cc
@@ -0,0 +1,260 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 - 2001 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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 <stdlib.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kpassdlg.h>
+
+#include "SensorClient.h"
+#include "SensorManager.h"
+
+#include "SensorAgent.h"
+
+/**
+ This can be used to debug communication problems with the daemon.
+ Should be set to 0 in any production version.
+*/
+#define SA_TRACE 0
+
+using namespace KSGRD;
+
+SensorAgent::SensorAgent( SensorManager *sm )
+ : mSensorManager( sm )
+{
+ /* SensorRequests migrate from the inputFIFO to the processingFIFO. So
+ * we only have to delete them when they are removed from the
+ * processingFIFO. */
+ mInputFIFO.setAutoDelete( false );
+ mProcessingFIFO.setAutoDelete( true );
+
+ mDaemonOnLine = false;
+ mTransmitting = false;
+ mState = 0;
+}
+
+SensorAgent::~SensorAgent()
+{
+}
+
+bool SensorAgent::sendRequest( const QString &req, SensorClient *client, int id )
+{
+ /* The request is registered with the FIFO so that the answer can be
+ * routed back to the requesting client. */
+ mInputFIFO.prepend( new SensorRequest( req, client, id ) );
+
+#if SA_TRACE
+ kdDebug(1215) << "-> " << req << "(" << mInputFIFO.count() << "/"
+ << mProcessingFIFO.count() << ")" << endl;
+#endif
+ executeCommand();
+
+ return false;
+}
+
+void SensorAgent::processAnswer( const QString &buffer )
+{
+#if SA_TRACE
+ kdDebug(1215) << "<- " << buffer << endl;
+#endif
+
+ for ( uint i = 0; i < buffer.length(); i++ ) {
+ if ( buffer[ i ] == '\033' ) {
+ mState = ( mState + 1 ) & 1;
+ if ( !mErrorBuffer.isEmpty() && mState == 0 ) {
+ if ( mErrorBuffer == "RECONFIGURE\n" )
+ emit reconfigure( this );
+ else {
+ /* We just received the end of an error message, so we
+ * can display it. */
+ SensorMgr->notify( i18n( "Message from %1:\n%2" )
+ .arg( mHostName )
+ .arg( mErrorBuffer ) );
+ }
+ mErrorBuffer = QString::null;
+ }
+ } else if ( mState == 0 ) // receiving to answerBuffer
+ mAnswerBuffer += buffer[ i ];
+ else // receiving to errorBuffer
+ mErrorBuffer += buffer[ i ];
+ }
+
+ int end;
+ // And now the real information
+ while ( ( end = mAnswerBuffer.find( "\nksysguardd> " ) ) >= 0 ) {
+#if SA_TRACE
+ kdDebug(1215) << "<= " << mAnswerBuffer.left( end )
+ << "(" << mInputFIFO.count() << "/"
+ << mProcessingFIFO.count() << ")" << endl;
+#endif
+ if ( !mDaemonOnLine ) {
+ /* First '\nksysguardd> ' signals that the daemon is
+ * ready to serve requests now. */
+ mDaemonOnLine = true;
+#if SA_TRACE
+ kdDebug(1215) << "Daemon now online!" << endl;
+#endif
+ mAnswerBuffer = QString::null;
+ break;
+ }
+
+ // remove pending request from FIFO
+ SensorRequest* req = mProcessingFIFO.last();
+ if ( !req ) {
+ kdDebug(1215) << "ERROR: Received answer but have no pending "
+ << "request! : " << mAnswerBuffer.left( end ) << endl;
+ mAnswerBuffer = QString::null;
+ } else {
+ if ( !req->client() ) {
+ /* The client has disappeared before receiving the answer
+ * to his request. */
+ } else {
+ if ( mAnswerBuffer.left( end ) == "UNKNOWN COMMAND" ) {
+ /* Notify client that the sensor seems to be no longer
+ * available. */
+ req->client()->sensorLost( req->id() );
+ } else {
+ // Notify client of newly arrived answer.
+ req->client()->answerReceived( req->id(), mAnswerBuffer.left( end ) );
+ }
+ }
+ mProcessingFIFO.removeLast();
+ }
+ // chop off the processed part of the answer buffer
+ mAnswerBuffer.remove( 0, end + strlen( "\nksysguardd> " ) );
+ }
+
+ executeCommand();
+}
+
+void SensorAgent::executeCommand()
+{
+ /* This function is called whenever there is a chance that we have a
+ * command to pass to the daemon. But the command many only be send
+ * if the daemon is online and there is no other command currently
+ * being sent. */
+ if ( mDaemonOnLine && txReady() && !mInputFIFO.isEmpty() ) {
+ // take oldest request for input FIFO
+ SensorRequest* req = mInputFIFO.last();
+ mInputFIFO.removeLast();
+
+#if SA_TRACE
+ kdDebug(1215) << ">> " << req->request().ascii() << "(" << mInputFIFO.count()
+ << "/" << mProcessingFIFO.count() << ")" << endl;
+#endif
+ // send request to daemon
+ QString cmdWithNL = req->request() + "\n";
+ if ( writeMsg( cmdWithNL.ascii(), cmdWithNL.length() ) )
+ mTransmitting = true;
+ else
+ kdDebug(1215) << "SensorAgent::writeMsg() failed" << endl;
+
+ // add request to processing FIFO
+ mProcessingFIFO.prepend( req );
+ }
+}
+
+void SensorAgent::disconnectClient( SensorClient *client )
+{
+ for ( SensorRequest *req = mInputFIFO.first(); req; req = mInputFIFO.next() )
+ if ( req->client() == client )
+ req->setClient( 0 );
+ for ( SensorRequest *req = mProcessingFIFO.first(); req; req = mProcessingFIFO.next() )
+ if ( req->client() == client )
+ req->setClient( 0 );
+}
+
+SensorManager *SensorAgent::sensorManager()
+{
+ return mSensorManager;
+}
+
+void SensorAgent::setDaemonOnLine( bool value )
+{
+ mDaemonOnLine = value;
+}
+
+bool SensorAgent::daemonOnLine() const
+{
+ return mDaemonOnLine;
+}
+
+void SensorAgent::setTransmitting( bool value )
+{
+ mTransmitting = value;
+}
+
+bool SensorAgent::transmitting() const
+{
+ return mTransmitting;
+}
+
+void SensorAgent::setHostName( const QString &hostName )
+{
+ mHostName = hostName;
+}
+
+const QString &SensorAgent::hostName() const
+{
+ return mHostName;
+}
+
+
+SensorRequest::SensorRequest( const QString &request, SensorClient *client, int id )
+ : mRequest( request ), mClient( client ), mId( id )
+{
+}
+
+SensorRequest::~SensorRequest()
+{
+}
+
+void SensorRequest::setRequest( const QString &request )
+{
+ mRequest = request;
+}
+
+QString SensorRequest::request() const
+{
+ return mRequest;
+}
+
+void SensorRequest::setClient( SensorClient *client )
+{
+ mClient = client;
+}
+
+SensorClient *SensorRequest::client()
+{
+ return mClient;
+}
+
+void SensorRequest::setId( int id )
+{
+ mId = id;
+}
+
+int SensorRequest::id()
+{
+ return mId;
+}
+
+#include "SensorAgent.moc"
diff --git a/ksysguard/gui/ksgrd/SensorAgent.h b/ksysguard/gui/ksgrd/SensorAgent.h
new file mode 100644
index 000000000..e30deb510
--- /dev/null
+++ b/ksysguard/gui/ksgrd/SensorAgent.h
@@ -0,0 +1,137 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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 KSG_SENSORAGENT_H
+#define KSG_SENSORAGENT_H
+
+#include <qobject.h>
+#include <qptrlist.h>
+
+class KProcess;
+class KShellProcess;
+
+class QString;
+
+namespace KSGRD {
+
+class SensorClient;
+class SensorManager;
+class SensorRequest;
+
+/**
+ The SensorAgent depending on the type of requested connection
+ starts a ksysguardd process or connects through a tcp connection to
+ a running ksysguardd and handles the asynchronous communication. It
+ keeps a list of pending requests that have not been answered yet by
+ ksysguardd. The current implementation only allowes one pending
+ requests. Incoming requests are queued in an input FIFO.
+*/
+class KDE_EXPORT SensorAgent : public QObject
+{
+ Q_OBJECT
+
+ public:
+ SensorAgent( SensorManager *sm );
+ virtual ~SensorAgent();
+
+ virtual bool start( const QString &host, const QString &shell,
+ const QString &command = "", int port = -1 ) = 0;
+
+ /**
+ This function should only be used by the the SensorManager and
+ never by the SensorClients directly since the pointer returned by
+ engaged is not guaranteed to be valid. Only the SensorManager knows
+ whether a SensorAgent pointer is still valid or not.
+
+ This function sends out a command to the sensor and notifies the
+ agent to return the answer to 'client'. The 'id' can be used by the
+ client to identify the answer. It is only passed through and never
+ used by the SensorAgent. So it can be any value the client suits to
+ use.
+ */
+ bool sendRequest( const QString &req, SensorClient *client, int id = 0 );
+
+ virtual void hostInfo( QString &sh, QString &cmd, int &port ) const = 0;
+
+ void disconnectClient( SensorClient *client );
+
+ const QString &hostName() const;
+
+ signals:
+ void reconfigure( const SensorAgent* );
+
+ protected:
+ void processAnswer( const QString &buffer );
+ void executeCommand();
+
+ SensorManager *sensorManager();
+
+ void setDaemonOnLine( bool value );
+ bool daemonOnLine() const;
+
+ void setTransmitting( bool value );
+ bool transmitting() const;
+
+ void setHostName( const QString &hostName );
+
+ private:
+ virtual bool writeMsg( const char *msg, int len ) = 0;
+ virtual bool txReady() = 0;
+
+ int mState;
+ QPtrList<SensorRequest> mInputFIFO;
+ QPtrList<SensorRequest> mProcessingFIFO;
+ QString mAnswerBuffer;
+ QString mErrorBuffer;
+
+ SensorManager *mSensorManager;
+
+ bool mDaemonOnLine;
+ bool mTransmitting;
+ QString mHostName;
+};
+
+/**
+ This auxilliary class is used to store requests during their processing.
+*/
+class SensorRequest
+{
+ public:
+ SensorRequest( const QString &request, SensorClient *client, int id );
+ ~SensorRequest();
+
+ void setRequest( const QString& );
+ QString request() const;
+
+ void setClient( SensorClient* );
+ SensorClient *client();
+
+ void setId( int );
+ int id();
+
+ private:
+ QString mRequest;
+ SensorClient *mClient;
+ int mId;
+};
+
+}
+
+#endif
diff --git a/ksysguard/gui/ksgrd/SensorClient.h b/ksysguard/gui/ksgrd/SensorClient.h
new file mode 100644
index 000000000..30586a8a2
--- /dev/null
+++ b/ksysguard/gui/ksgrd/SensorClient.h
@@ -0,0 +1,209 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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.
+
+ KSysGuard is currently maintained by Chris Schlaeger <[email protected]>.
+ Please do not commit any changes without consulting me first. Thanks!
+
+*/
+
+#ifndef KSG_SENSORCLIENT_H
+#define KSG_SENSORCLIENT_H
+
+#include <qptrlist.h>
+#include <qstring.h>
+
+namespace KSGRD {
+
+/**
+ Every object that should act as a client to a sensor must inherit from
+ this class. A pointer to the client object is passed as SensorClient*
+ to the SensorAgent. When the requested information is available or a
+ problem occurred one of the member functions is called.
+ */
+class SensorClient
+{
+ public:
+ SensorClient() { }
+ virtual ~SensorClient() { }
+
+ /**
+ This function is called whenever the information form the sensor has
+ been received by the sensor agent. This function must be reimplemented
+ by the sensor client to receive and process this information.
+ */
+ virtual void answerReceived( int, const QString& ) { }
+
+ /**
+ In case of an unexpected fatal problem with the sensor the sensor
+ agent will call this function to notify the client about it.
+ */
+ virtual void sensorLost( int ) { }
+};
+
+/**
+ Every object that has a SensorClient as a child must inherit from
+ this class to support the advanced update interval settings.
+ */
+class SensorBoard
+{
+ public:
+ SensorBoard() { }
+ virtual ~SensorBoard() { }
+
+ void updateInterval( int interval ) { mUpdateInterval = interval; }
+
+ int updateInterval() { return mUpdateInterval; }
+
+ private:
+ int mUpdateInterval;
+};
+
+/**
+ The following classes are utility classes that provide a
+ convenient way to retrieve pieces of information from the sensor
+ answers. For each type of answer there is a separate class.
+ */
+class SensorTokenizer
+{
+ public:
+ SensorTokenizer( const QString &info, QChar separator )
+ {
+ mTokens = QStringList::split( separator, info );
+ }
+
+ ~SensorTokenizer() { }
+
+ const QString& operator[]( unsigned idx )
+ {
+ return mTokens[ idx ];
+ }
+
+ uint count()
+ {
+ return mTokens.count();
+ }
+
+ private:
+ QStringList mTokens;
+};
+
+/**
+ An integer info contains 4 fields seperated by TABS, a description
+ (name), the minimum and the maximum values and the unit.
+ e.g. Swap Memory 0 133885952 KB
+ */
+class SensorIntegerInfo : public SensorTokenizer
+{
+ public:
+ SensorIntegerInfo( const QString &info )
+ : SensorTokenizer( info, '\t' ) { }
+
+ ~SensorIntegerInfo() { }
+
+ const QString &name()
+ {
+ return (*this)[ 0 ];
+ }
+
+ long min()
+ {
+ return (*this)[ 1 ].toLong();
+ }
+
+ long max()
+ {
+ return (*this)[ 2 ].toLong();
+ }
+
+ const QString &unit()
+ {
+ return (*this)[ 3 ];
+ }
+};
+
+/**
+ An float info contains 4 fields seperated by TABS, a description
+ (name), the minimum and the maximum values and the unit.
+ e.g. CPU Voltage 0.0 5.0 V
+ */
+class SensorFloatInfo : public SensorTokenizer
+{
+ public:
+ SensorFloatInfo( const QString &info )
+ : SensorTokenizer( info, '\t' ) { }
+
+ ~SensorFloatInfo() { }
+
+ const QString &name()
+ {
+ return (*this)[ 0 ];
+ }
+
+ double min()
+ {
+ return (*this)[ 1 ].toDouble();
+ }
+
+ double max()
+ {
+ return (*this)[ 2 ].toDouble();
+ }
+
+ const QString &unit()
+ {
+ return (*this)[ 3 ];
+ }
+};
+
+/**
+ A PS line consists of information about a process. Each piece of
+ information is seperated by a TAB. The first 4 fields are process name,
+ PID, PPID and real user ID. Those fields are mandatory.
+ */
+class SensorPSLine : public SensorTokenizer
+{
+ public:
+ SensorPSLine( const QString &line )
+ : SensorTokenizer( line, '\t' ) { }
+
+ ~SensorPSLine() { }
+
+ const QString& name()
+ {
+ return (*this)[ 0 ];
+ }
+
+ long pid()
+ {
+ return (*this)[ 1 ].toLong();
+ }
+
+ long ppid()
+ {
+ return (*this)[ 2 ].toLong();
+ }
+
+ long uid()
+ {
+ return (*this)[ 3 ].toLong();
+ }
+};
+
+}
+
+#endif
diff --git a/ksysguard/gui/ksgrd/SensorManager.cc b/ksysguard/gui/ksgrd/SensorManager.cc
new file mode 100644
index 000000000..065da717a
--- /dev/null
+++ b/ksysguard/gui/ksgrd/SensorManager.cc
@@ -0,0 +1,432 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 - 2001 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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.
+
+ KSysGuard is currently maintained by Chris Schlaeger <[email protected]>.
+ Please do not commit any changes without consulting me first. Thanks!
+
+*/
+
+#include <qcombobox.h>
+#include <qlabel.h>
+#include <qpushbutton.h>
+#include <qradiobutton.h>
+#include <qspinbox.h>
+
+#include <kapplication.h>
+#include <kdebug.h>
+#include <klocale.h>
+
+#include "HostConnector.h"
+#include "SensorShellAgent.h"
+#include "SensorSocketAgent.h"
+
+#include "SensorManager.h"
+
+using namespace KSGRD;
+
+SensorManager* KSGRD::SensorMgr;
+
+SensorManager::SensorManager()
+{
+ mAgents.setAutoDelete( true );
+ mDict.setAutoDelete( true );
+
+ // Fill the sensor description dictionary.
+ mDict.insert( "cpu", new QString( i18n( "CPU Load" ) ) );
+ mDict.insert( "idle", new QString( i18n( "Idle Load" ) ) );
+ mDict.insert( "sys", new QString( i18n( "System Load" ) ) );
+ mDict.insert( "nice", new QString( i18n( "Nice Load" ) ) );
+ mDict.insert( "user", new QString( i18n( "User Load" ) ) );
+ mDict.insert( "mem", new QString( i18n( "Memory" ) ) );
+ mDict.insert( "physical", new QString( i18n( "Physical Memory" ) ) );
+ mDict.insert( "swap", new QString( i18n( "Swap Memory" ) ) );
+ mDict.insert( "cached", new QString( i18n( "Cached Memory" ) ) );
+ mDict.insert( "buf", new QString( i18n( "Buffered Memory" ) ) );
+ mDict.insert( "used", new QString( i18n( "Used Memory" ) ) );
+ mDict.insert( "application", new QString( i18n( "Application Memory" ) ) );
+ mDict.insert( "free", new QString( i18n( "Free Memory" ) ) );
+ mDict.insert( "pscount", new QString( i18n( "Process Count" ) ) );
+ mDict.insert( "ps", new QString( i18n( "Process Controller" ) ) );
+ mDict.insert( "disk", new QString( i18n( "Disk Throughput" ) ) );
+ mDict.insert( "load", new QString( i18n( "CPU Load", "Load" ) ) );
+ mDict.insert( "total", new QString( i18n( "Total Accesses" ) ) );
+ mDict.insert( "rio", new QString( i18n( "Read Accesses" ) ) );
+ mDict.insert( "wio", new QString( i18n( "Write Accesses" ) ) );
+ mDict.insert( "rblk", new QString( i18n( "Read Data" ) ) );
+ mDict.insert( "wblk", new QString( i18n( "Write Data" ) ) );
+ mDict.insert( "pageIn", new QString( i18n( "Pages In" ) ) );
+ mDict.insert( "pageOut", new QString( i18n( "Pages Out" ) ) );
+ mDict.insert( "context", new QString( i18n( "Context Switches" ) ) );
+ mDict.insert( "network", new QString( i18n( "Network" ) ) );
+ mDict.insert( "interfaces", new QString( i18n( "Interfaces" ) ) );
+ mDict.insert( "receiver", new QString( i18n( "Receiver" ) ) );
+ mDict.insert( "transmitter", new QString( i18n( "Transmitter" ) ) );
+ mDict.insert( "data", new QString( i18n( "Data" ) ) );
+ mDict.insert( "compressed", new QString( i18n( "Compressed Packets" ) ) );
+ mDict.insert( "drops", new QString( i18n( "Dropped Packets" ) ) );
+ mDict.insert( "errors", new QString( i18n( "Errors" ) ) );
+ mDict.insert( "fifo", new QString( i18n( "FIFO Overruns" ) ) );
+ mDict.insert( "frame", new QString( i18n( "Frame Errors" ) ) );
+ mDict.insert( "multicast", new QString( i18n( "Multicast" ) ) );
+ mDict.insert( "packets", new QString( i18n( "Packets" ) ) );
+ mDict.insert( "carrier", new QString( i18n( "Carrier" ) ) );
+ mDict.insert( "collisions", new QString( i18n( "Collisions" ) ) );
+ mDict.insert( "sockets", new QString( i18n( "Sockets" ) ) );
+ mDict.insert( "count", new QString( i18n( "Total Number" ) ) );
+ mDict.insert( "list", new QString( i18n( "Table" ) ) );
+ mDict.insert( "apm", new QString( i18n( "Advanced Power Management" ) ) );
+ mDict.insert( "acpi", new QString( i18n( "ACPI" ) ) );
+ mDict.insert( "thermal_zone", new QString( i18n( "Thermal Zone" ) ) );
+ mDict.insert( "temperature", new QString( i18n( "Temperature" ) ) );
+ mDict.insert( "fan", new QString( i18n( "Fan" ) ) );
+ mDict.insert( "state", new QString( i18n( "State" ) ) );
+ mDict.insert( "battery", new QString( i18n( "Battery" ) ) );
+ mDict.insert( "batterycharge", new QString( i18n( "Battery Charge" ) ) );
+ mDict.insert( "batteryusage", new QString( i18n( "Battery Usage" ) ) );
+ mDict.insert( "remainingtime", new QString( i18n( "Remaining Time" ) ) );
+ mDict.insert( "interrupts", new QString( i18n( "Interrupts" ) ) );
+ mDict.insert( "loadavg1", new QString( i18n( "Load Average (1 min)" ) ) );
+ mDict.insert( "loadavg5", new QString( i18n( "Load Average (5 min)" ) ) );
+ mDict.insert( "loadavg15", new QString( i18n( "Load Average (15 min)" ) ) );
+ mDict.insert( "clock", new QString( i18n( "Clock Frequency" ) ) );
+ mDict.insert( "lmsensors", new QString( i18n( "Hardware Sensors" ) ) );
+ mDict.insert( "partitions", new QString( i18n( "Partition Usage" ) ) );
+ mDict.insert( "usedspace", new QString( i18n( "Used Space" ) ) );
+ mDict.insert( "freespace", new QString( i18n( "Free Space" ) ) );
+ mDict.insert( "filllevel", new QString( i18n( "Fill Level" ) ) );
+
+ for ( int i = 0; i < 32; i++ ) {
+ mDict.insert( "cpu" + QString::number( i ),
+ new QString( QString( i18n( "CPU%1" ) ).arg( i ) ) );
+ mDict.insert( "disk" + QString::number( i ),
+ new QString( QString( i18n( "Disk%1" ) ).arg( i ) ) );
+ }
+
+ for ( int i = 0; i < 6; i++) {
+ mDict.insert( "fan" + QString::number( i ),
+ new QString( QString( i18n( "Fan%1" ) ).arg( i ) ) );
+ mDict.insert( "temp" + QString::number( i ),
+ new QString( QString( i18n( "Temperature%1" ) ).arg( i ) ) );
+ }
+
+ mDict.insert( "int00", new QString( i18n( "Total" ) ) );
+
+ QString num;
+ for ( int i = 1; i < 25; i++ ) {
+ num.sprintf( "%.2d", i );
+ mDict.insert( "int" + num,
+ new QString( QString( i18n( "Int%1" ) ).arg( i - 1, 3 ) ) );
+ }
+
+ mDescriptions.setAutoDelete( true );
+ // TODO: translated descriptions not yet implemented.
+
+ mUnits.setAutoDelete( true );
+ mUnits.insert( "1/s", new QString( i18n( "the unit 1 per second", "1/s" ) ) );
+ mUnits.insert( "kBytes", new QString( i18n( "kBytes" ) ) );
+ mUnits.insert( "min", new QString( i18n( "the unit minutes", "min" ) ) );
+ mUnits.insert( "MHz", new QString( i18n( "the frequency unit", "MHz" ) ) );
+
+ mTypes.setAutoDelete( true );
+ mTypes.insert( "integer", new QString( i18n( "Integer Value" ) ) );
+ mTypes.insert( "float", new QString( i18n( "Floating Point Value" ) ) );
+ mTypes.insert( "table", new QString( i18n( "Process Controller" ) ) );
+ mTypes.insert( "listview", new QString( i18n( "Table" ) ) );
+
+ mBroadcaster = 0;
+
+ mHostConnector = new HostConnector( 0 );
+}
+
+SensorManager::~SensorManager()
+{
+ delete mHostConnector;
+}
+
+bool SensorManager::engageHost( const QString &hostName )
+{
+ bool retVal = true;
+
+ if ( hostName.isEmpty() || mAgents.find( hostName ) == 0 ) {
+ if(hostName == "localhost") {
+ //There was a bug where the xml file would end up not specifying to connect to localhost.
+ //This work around makes sure we always connect to localhost
+ return engage( "localhost", "", "ksysguardd", -1);
+ }
+ mHostConnector->setCurrentHostName( hostName );
+
+ if ( mHostConnector->exec() ) {
+ QString shell = "";
+ QString command = "";
+ int port = -1;
+
+ /* Check which radio button is selected and set parameters
+ * appropriately. */
+ if ( mHostConnector->useSsh() )
+ shell = "ssh";
+ else if ( mHostConnector->useRsh() )
+ shell = "rsh";
+ else if ( mHostConnector->useDaemon() )
+ port = mHostConnector->port();
+ else
+ command = mHostConnector->currentCommand();
+
+ if ( hostName.isEmpty() )
+ retVal = engage( mHostConnector->currentHostName(), shell,
+ command, port );
+ else
+ retVal = engage( hostName, shell, command, port );
+ }
+ }
+
+ return retVal;
+}
+
+bool SensorManager::engage( const QString &hostName, const QString &shell,
+ const QString &command, int port )
+{
+ SensorAgent *agent;
+
+ if ( ( agent = mAgents.find( hostName ) ) == 0 ) {
+ if ( port == -1 )
+ agent = new SensorShellAgent( this );
+ else
+ agent = new SensorSocketAgent( this );
+
+ if ( !agent->start( hostName.ascii(), shell, command, port ) ) {
+ delete agent;
+ return false;
+ }
+
+ mAgents.insert( hostName, agent );
+ connect( agent, SIGNAL( reconfigure( const SensorAgent* ) ),
+ SLOT( reconfigure( const SensorAgent* ) ) );
+
+ emit update();
+ return true;
+ }
+
+ return false;
+}
+
+void SensorManager::requestDisengage( const SensorAgent *agent )
+{
+ /* When a sensor agent becomes disfunctional it calls this function
+ * to request that it is being removed from the SensorManager. It must
+ * not call disengage() directly since it would trigger ~SensorAgent()
+ * while we are still in a SensorAgent member function.
+ * So we have to post an event which is later caught by
+ * SensorManger::customEvent(). */
+ QCustomEvent* event = new QCustomEvent( QEvent::User, (void*)agent );
+ kapp->postEvent( this, event );
+}
+
+bool SensorManager::disengage( const SensorAgent *agent )
+{
+ QDictIterator<SensorAgent> it( mAgents );
+
+ for ( ; it.current(); ++it )
+ if ( it.current() == agent ) {
+ mAgents.remove( it.currentKey() );
+ emit update();
+ return true;
+ }
+
+ return false;
+}
+
+bool SensorManager::disengage( const QString &hostName )
+{
+ SensorAgent *agent;
+ if ( ( agent = mAgents.find( hostName ) ) != 0 ) {
+ mAgents.remove( hostName );
+ emit update();
+ return true;
+ }
+
+ return false;
+}
+
+bool SensorManager::resynchronize( const QString &hostName )
+{
+ SensorAgent *agent;
+
+ if ( ( agent = mAgents.find( hostName ) ) == 0 )
+ return false;
+
+ QString shell, command;
+ int port;
+ hostInfo( hostName, shell, command, port );
+
+ disengage( hostName );
+
+ kdDebug (1215) << "Re-synchronizing connection to " << hostName << endl;
+
+ return engage( hostName, shell, command );
+}
+
+void SensorManager::hostLost( const SensorAgent *agent )
+{
+ emit hostConnectionLost( agent->hostName() );
+
+ if ( mBroadcaster ) {
+ QCustomEvent *event = new QCustomEvent( QEvent::User );
+ event->setData( new QString( i18n( "Connection to %1 has been lost." )
+ .arg( agent->hostName() ) ) );
+ kapp->postEvent( mBroadcaster, event );
+ }
+}
+
+void SensorManager::notify( const QString &msg ) const
+{
+ /* This function relays text messages to the toplevel widget that
+ * displays the message in a pop-up box. It must be used for objects
+ * that might have been deleted before the pop-up box is closed. */
+ if ( mBroadcaster ) {
+ QCustomEvent *event = new QCustomEvent( QEvent::User );
+ event->setData( new QString( msg ) );
+ kapp->postEvent( mBroadcaster, event );
+ }
+}
+
+void SensorManager::setBroadcaster( QWidget *wdg )
+{
+ mBroadcaster = wdg;
+}
+
+void SensorManager::reconfigure( const SensorAgent* )
+{
+ emit update();
+}
+
+bool SensorManager::event( QEvent *event )
+{
+ if ( event->type() == QEvent::User ) {
+ disengage( (const SensorAgent*)((QCustomEvent*)event)->data() );
+ return true;
+ }
+
+ return false;
+}
+
+bool SensorManager::sendRequest( const QString &hostName, const QString &req,
+ SensorClient *client, int id )
+{
+ SensorAgent *agent = mAgents.find( hostName );
+ if( !agent && hostName == "localhost") {
+ //we should always be able to reconnect to localhost
+ engage("localhost", "", "ksysguardd", -1);
+ agent = mAgents.find( hostName );
+ }
+ if ( agent ) {
+ agent->sendRequest( req, client, id );
+ return true;
+ }
+
+ return false;
+}
+
+const QString SensorManager::hostName( const SensorAgent *agent) const
+{
+ QDictIterator<SensorAgent> it( mAgents );
+
+ while ( it.current() ) {
+ if ( it.current() == agent )
+ return it.currentKey();
+ ++it;
+ }
+
+ return QString::null;
+}
+
+bool SensorManager::hostInfo( const QString &hostName, QString &shell,
+ QString &command, int &port )
+{
+ SensorAgent *agent;
+ if ( ( agent = mAgents.find( hostName ) ) != 0 ) {
+ agent->hostInfo( shell, command, port );
+ return true;
+ }
+
+ return false;
+}
+
+const QString &SensorManager::translateUnit( const QString &unit ) const
+{
+ if ( !unit.isEmpty() && mUnits[ unit ] )
+ return *mUnits[ unit ];
+ else
+ return unit;
+}
+
+const QString &SensorManager::translateSensorPath( const QString &path ) const
+{
+ if ( !path.isEmpty() && mDict[ path ] )
+ return *mDict[ path ];
+ else
+ return path;
+}
+
+const QString &SensorManager::translateSensorType( const QString &type ) const
+{
+ if ( !type.isEmpty() && mTypes[ type ] )
+ return *mTypes[ type ];
+ else
+ return type;
+}
+
+QString SensorManager::translateSensor( const QString &sensor ) const
+{
+ QString token, out;
+ int start = 0, end = 0;
+ for ( ; ; ) {
+ end = sensor.find( '/', start );
+ if ( end > 0 )
+ out += translateSensorPath( sensor.mid( start, end - start ) ) + "/";
+ else {
+ out += translateSensorPath( sensor.right( sensor.length() - start ) );
+ break;
+ }
+ start = end + 1;
+ }
+
+ return out;
+}
+
+void SensorManager::readProperties( KConfig *cfg )
+{
+ mHostConnector->setHostNames( cfg->readListEntry( "HostList" ) );
+ mHostConnector->setCommands( cfg->readListEntry( "CommandList" ) );
+}
+
+void
+SensorManager::saveProperties( KConfig *cfg )
+{
+ cfg->writeEntry( "HostList", mHostConnector->hostNames() );
+ cfg->writeEntry( "CommandList", mHostConnector->commands() );
+}
+
+void SensorManager::disconnectClient( SensorClient *client )
+{
+ QDictIterator<SensorAgent> it( mAgents );
+
+ for ( ; it.current(); ++it)
+ it.current()->disconnectClient( client );
+}
+
+#include "SensorManager.moc"
diff --git a/ksysguard/gui/ksgrd/SensorManager.h b/ksysguard/gui/ksgrd/SensorManager.h
new file mode 100644
index 000000000..8eb778009
--- /dev/null
+++ b/ksysguard/gui/ksgrd/SensorManager.h
@@ -0,0 +1,126 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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 KSG_SENSORMANAGER_H
+#define KSG_SENSORMANAGER_H
+
+#include <kconfig.h>
+
+#include <qdict.h>
+#include <qobject.h>
+
+#include <SensorAgent.h>
+
+class HostConnector;
+
+namespace KSGRD {
+
+class SensorManagerIterator;
+
+/**
+ The SensorManager handles all interaction with the connected
+ hosts. Connections to a specific hosts are handled by
+ SensorAgents. Use engage() to establish a connection and
+ disengage() to terminate the connection. If you don't know if a
+ certain host is already connected use engageHost(). If there is no
+ connection yet or the hostname is empty, a dialog will be shown to
+ enter the connections details.
+ */
+class KDE_EXPORT SensorManager : public QObject
+{
+ Q_OBJECT
+
+ friend class SensorManagerIterator;
+
+ public:
+ SensorManager();
+ ~SensorManager();
+
+ bool engageHost( const QString &hostName );
+ bool engage( const QString &hostName, const QString &shell = "ssh",
+ const QString &command = "", int port = -1 );
+
+ void requestDisengage( const SensorAgent *agent );
+ bool disengage( const SensorAgent *agent );
+ bool disengage( const QString &hostName );
+ bool resynchronize( const QString &hostName );
+ void hostLost( const SensorAgent *agent );
+ void notify( const QString &msg ) const;
+
+ void setBroadcaster( QWidget *wdg );
+
+ virtual bool event( QEvent *event );
+
+ bool sendRequest( const QString &hostName, const QString &request,
+ SensorClient *client, int id = 0 );
+
+ const QString hostName( const SensorAgent *sensor ) const;
+ bool hostInfo( const QString &host, QString &shell,
+ QString &command, int &port );
+
+ const QString& translateUnit( const QString &unit ) const;
+ const QString& translateSensorPath( const QString &path ) const;
+ const QString& translateSensorType( const QString &type ) const;
+ QString translateSensor(const QString& u) const;
+
+ void readProperties( KConfig *cfg );
+ void saveProperties( KConfig *cfg );
+
+ void disconnectClient( SensorClient *client );
+
+ public slots:
+ void reconfigure( const SensorAgent *agent );
+
+ signals:
+ void update();
+ void hostConnectionLost( const QString &hostName );
+
+ protected:
+ QDict<SensorAgent> mAgents;
+
+ private:
+ /**
+ These dictionary stores the localized versions of the sensor
+ descriptions and units.
+ */
+ QDict<QString> mDescriptions;
+ QDict<QString> mUnits;
+ QDict<QString> mDict;
+ QDict<QString> mTypes;
+
+ QWidget* mBroadcaster;
+
+ HostConnector* mHostConnector;
+};
+
+KDE_EXPORT extern SensorManager* SensorMgr;
+
+class KDE_EXPORT SensorManagerIterator : public QDictIterator<SensorAgent>
+{
+ public:
+ SensorManagerIterator( const SensorManager *sm )
+ : QDictIterator<SensorAgent>( sm->mAgents ) { }
+
+ ~SensorManagerIterator() { }
+};
+
+}
+
+#endif
diff --git a/ksysguard/gui/ksgrd/SensorShellAgent.cc b/ksysguard/gui/ksgrd/SensorShellAgent.cc
new file mode 100644
index 000000000..0f06e88fe
--- /dev/null
+++ b/ksysguard/gui/ksgrd/SensorShellAgent.cc
@@ -0,0 +1,141 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 - 2001 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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 <stdlib.h>
+
+#include <kdebug.h>
+#include <kpassdlg.h>
+#include <kprocess.h>
+
+#include "SensorClient.h"
+#include "SensorManager.h"
+
+#include "SensorShellAgent.h"
+
+using namespace KSGRD;
+
+SensorShellAgent::SensorShellAgent( SensorManager *sm )
+ : SensorAgent( sm ), mDaemon( 0 )
+{
+}
+
+SensorShellAgent::~SensorShellAgent()
+{
+ if ( mDaemon ) {
+ mDaemon->writeStdin( "quit\n", strlen( "quit\n" ) );
+ delete mDaemon;
+ mDaemon = 0;
+ }
+}
+
+bool SensorShellAgent::start( const QString &host, const QString &shell,
+ const QString &command, int )
+{
+ mRetryCount = 3;
+ mDaemon = new KProcess;
+ mDaemon->setUseShell(true);
+ setHostName( host );
+ mShell = shell;
+ mCommand = command;
+
+ connect( mDaemon, SIGNAL( processExited( KProcess* ) ),
+ SLOT( daemonExited( KProcess* ) ) );
+ connect( mDaemon, SIGNAL( receivedStdout( KProcess*, char*, int ) ),
+ SLOT( msgRcvd( KProcess*, char*, int ) ) );
+ connect( mDaemon, SIGNAL( receivedStderr( KProcess*, char*, int ) ),
+ SLOT( errMsgRcvd( KProcess*, char*, int ) ) );
+ connect( mDaemon, SIGNAL( wroteStdin( KProcess* ) ),
+ SLOT( msgSent( KProcess* ) ) );
+
+ QString cmd;
+ if ( !command.isEmpty() )
+ cmd = command;
+ else
+ cmd = mShell + " " + hostName() + " ksysguardd";
+ *mDaemon << cmd;
+
+ if ( !mDaemon->start( KProcess::NotifyOnExit, KProcess::All ) ) {
+ sensorManager()->hostLost( this );
+ kdDebug (1215) << "Command '" << cmd << "' failed" << endl;
+ return false;
+ }
+
+ return true;
+}
+
+void SensorShellAgent::hostInfo( QString &shell, QString &command,
+ int &port) const
+{
+ shell = mShell;
+ command = mCommand;
+ port = -1;
+}
+
+void SensorShellAgent::msgSent( KProcess* )
+{
+ setTransmitting( false );
+
+ // Try to send next request if available.
+ executeCommand();
+}
+
+void SensorShellAgent::msgRcvd( KProcess*, char *buffer, int buflen )
+{
+ if ( !buffer || buflen == 0 )
+ return;
+ mRetryCount = 3; //we recieved an answer, so reset our retry count back to 3
+ QString aux = QString::fromLocal8Bit( buffer, buflen );
+
+ processAnswer( aux );
+}
+
+void SensorShellAgent::errMsgRcvd( KProcess*, char *buffer, int buflen )
+{
+ if ( !buffer || buflen == 0 )
+ return;
+
+ QString buf = QString::fromLocal8Bit( buffer, buflen );
+
+ kdDebug(1215) << "SensorShellAgent: Warning, received text over stderr!"
+ << endl << buf << endl;
+}
+
+void SensorShellAgent::daemonExited( KProcess *process )
+{
+ kdDebug() << "daemonExited" << endl;
+ if ( mRetryCount-- <= 0 || !mDaemon->start( KProcess::NotifyOnExit, KProcess::All ) ) {
+ kdDebug() << "daemon could not be restart" << endl;
+ setDaemonOnLine( false );
+ sensorManager()->hostLost( this );
+ sensorManager()->requestDisengage( this );
+ }
+}
+
+bool SensorShellAgent::writeMsg( const char *msg, int len )
+{
+ return mDaemon->writeStdin( msg, len );
+}
+
+bool SensorShellAgent::txReady()
+{
+ return !transmitting();
+}
+
+#include "SensorShellAgent.moc"
diff --git a/ksysguard/gui/ksgrd/SensorShellAgent.h b/ksysguard/gui/ksgrd/SensorShellAgent.h
new file mode 100644
index 000000000..e13413d55
--- /dev/null
+++ b/ksysguard/gui/ksgrd/SensorShellAgent.h
@@ -0,0 +1,77 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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 KSG_SENSORSHELLAGENT_H
+#define KSG_SENSORSHELLAGENT_H
+
+#include <qobject.h>
+#include <qptrlist.h>
+#include <qguardedptr.h>
+
+#include <SensorAgent.h>
+
+class QString;
+
+class KProcess;
+
+namespace KSGRD {
+
+class SensorClient;
+class SensorManager;
+
+/**
+ The SensorShellAgent starts a ksysguardd process and handles the
+ asynchronous communication. It keeps a list of pending requests
+ that have not been answered yet by ksysguard. The current
+ implementation only allowes one pending requests. Incoming requests
+ are queued in an input FIFO.
+ */
+class SensorShellAgent : public SensorAgent
+{
+ Q_OBJECT
+
+ public:
+ SensorShellAgent( SensorManager *sm );
+ ~SensorShellAgent();
+
+ bool start( const QString &host, const QString &shell,
+ const QString &command = "", int port = -1 );
+
+ void hostInfo( QString &shell, QString &command, int &port) const;
+
+ private slots:
+ void msgSent( KProcess* );
+ void msgRcvd( KProcess*, char *buffer, int buflen );
+ void errMsgRcvd( KProcess*, char *buffer, int buflen );
+ void daemonExited( KProcess* );
+
+ private:
+ bool writeMsg( const char *msg, int len );
+ bool txReady();
+
+ QGuardedPtr<KProcess> mDaemon;
+ QString mShell;
+ QString mCommand;
+ int mRetryCount;
+};
+
+}
+
+#endif
diff --git a/ksysguard/gui/ksgrd/SensorSocketAgent.cc b/ksysguard/gui/ksgrd/SensorSocketAgent.cc
new file mode 100644
index 000000000..dcb5b7f3b
--- /dev/null
+++ b/ksysguard/gui/ksgrd/SensorSocketAgent.cc
@@ -0,0 +1,137 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 - 2001 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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 <stdlib.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <kpassdlg.h>
+
+#include "SensorClient.h"
+#include "SensorManager.h"
+
+#include "SensorSocketAgent.h"
+
+using namespace KSGRD;
+
+SensorSocketAgent::SensorSocketAgent( SensorManager *sm )
+ : SensorAgent( sm )
+{
+ connect( &mSocket, SIGNAL( gotError( int ) ), SLOT( error( int ) ) );
+ connect( &mSocket, SIGNAL( bytesWritten( int ) ), SLOT( msgSent( int ) ) );
+ connect( &mSocket, SIGNAL( readyRead() ), SLOT( msgRcvd() ) );
+ connect( &mSocket, SIGNAL( closed() ), SLOT( connectionClosed() ) );
+}
+
+SensorSocketAgent::~SensorSocketAgent()
+{
+ mSocket.writeBlock( "quit\n", strlen( "quit\n" ) );
+ mSocket.flush();
+}
+
+bool SensorSocketAgent::start( const QString &host, const QString&,
+ const QString&, int port )
+{
+ if ( port <= 0 )
+ kdDebug(1215) << "SensorSocketAgent::start: Illegal port " << port << endl;
+
+ setHostName( host );
+ mPort = port;
+
+ mSocket.connect( hostName(), QString::number(mPort) );
+
+ return true;
+}
+
+void SensorSocketAgent::hostInfo( QString &shell, QString &command, int &port ) const
+{
+ shell = QString::null;
+ command = QString::null;
+ port = mPort;
+}
+
+void SensorSocketAgent::msgSent( int )
+{
+ if ( mSocket.bytesToWrite() != 0 )
+ return;
+
+ setTransmitting( false );
+
+ // Try to send next request if available.
+ executeCommand();
+}
+
+void SensorSocketAgent::msgRcvd()
+{
+ int buflen = mSocket.bytesAvailable();
+ char* buffer = new char[ buflen ];
+
+ mSocket.readBlock( buffer, buflen );
+ QString buf = QString::fromLocal8Bit( buffer, buflen );
+ delete [] buffer;
+
+ processAnswer( buf );
+}
+
+void SensorSocketAgent::connectionClosed()
+{
+ setDaemonOnLine( false );
+ sensorManager()->hostLost( this );
+ sensorManager()->requestDisengage( this );
+}
+
+void SensorSocketAgent::error( int id )
+{
+ switch ( id ) {
+ case KNetwork::KSocketBase::ConnectionRefused:
+ SensorMgr->notify( i18n( "Connection to %1 refused" )
+ .arg( hostName() ) );
+ break;
+ case KNetwork::KSocketBase::LookupFailure:
+ SensorMgr->notify( i18n( "Host %1 not found" )
+ .arg( hostName() ) );
+ break;
+ case KNetwork::KSocketBase::Timeout:
+ SensorMgr->notify( i18n( "Timeout at host %1")
+ .arg( hostName() ) );
+ break;
+ case KNetwork::KSocketBase::NetFailure:
+ SensorMgr->notify( i18n( "Network failure host %1")
+ .arg( hostName() ) );
+ break;
+ default:
+ kdDebug(1215) << "SensorSocketAgent::error() unknown error " << id << endl;
+ }
+
+ setDaemonOnLine( false );
+ sensorManager()->requestDisengage( this );
+}
+
+bool SensorSocketAgent::writeMsg( const char *msg, int len )
+{
+ return ( mSocket.writeBlock( msg, len ) == len );
+}
+
+bool SensorSocketAgent::txReady()
+{
+ return !transmitting();
+}
+
+#include "SensorSocketAgent.moc"
diff --git a/ksysguard/gui/ksgrd/SensorSocketAgent.h b/ksysguard/gui/ksgrd/SensorSocketAgent.h
new file mode 100644
index 000000000..b422d3a9b
--- /dev/null
+++ b/ksysguard/gui/ksgrd/SensorSocketAgent.h
@@ -0,0 +1,71 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999, 2000 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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 KSG_SENSORSOCKETAGENT_H
+#define KSG_SENSORSOCKETAGENT_H
+
+#include <qptrlist.h>
+#include <kbufferedsocket.h>
+
+#include <SensorAgent.h>
+
+class QString;
+
+namespace KSGRD {
+
+class SensorClient;
+
+/**
+ The SensorSocketAgent connects to a ksysguardd via a TCP
+ connection. It keeps a list of pending requests that have not been
+ answered yet by ksysguard. The current implementation only allowes
+ one pending requests. Incoming requests are queued in an input
+ FIFO.
+ */
+class SensorSocketAgent : public SensorAgent
+{
+ Q_OBJECT
+
+ public:
+ SensorSocketAgent( SensorManager *sm );
+ ~SensorSocketAgent();
+
+ bool start( const QString &host, const QString &shell,
+ const QString &command = "", int port = -1 );
+
+ void hostInfo( QString &shell, QString &command, int &port ) const;
+
+ private slots:
+ void connectionClosed();
+ void msgSent( int );
+ void msgRcvd();
+ void error( int );
+
+ private:
+ bool writeMsg( const char *msg, int len );
+ bool txReady();
+
+ KNetwork::KBufferedSocket mSocket;
+ int mPort;
+};
+
+}
+
+#endif
diff --git a/ksysguard/gui/ksgrd/StyleEngine.cc b/ksysguard/gui/ksgrd/StyleEngine.cc
new file mode 100644
index 000000000..ccea0a7c2
--- /dev/null
+++ b/ksysguard/gui/ksgrd/StyleEngine.cc
@@ -0,0 +1,176 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 - 2001 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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.
+
+ KSysGuard is currently maintained by Chris Schlaeger <[email protected]>.
+ Please do not commit any changes without consulting me first. Thanks!
+
+*/
+
+#include <qimage.h>
+#include <qpushbutton.h>
+#include <qspinbox.h>
+
+#include <kconfig.h>
+#include <klocale.h>
+
+#include "StyleSettings.h"
+
+#include "StyleEngine.h"
+
+using namespace KSGRD;
+
+StyleEngine* KSGRD::Style;
+
+StyleEngine::StyleEngine()
+{
+ mFirstForegroundColor = QColor( 0x6894c9 ); // light blue
+ mSecondForegroundColor = QColor( 0x6894c9 ); // light blue
+ mAlarmColor = QColor( 255, 0, 0 );
+ mBackgroundColor = QColor( 0x313031 ); // almost black
+ mFontSize = 9;
+
+ mSensorColors.append( QColor( 0x1889ff ) ); // soft blue
+ mSensorColors.append( QColor( 0xff7f08 ) ); // reddish
+ mSensorColors.append( QColor( 0xffeb14 ) ); // bright yellow
+
+ uint v = 0x00ff00;
+ for ( uint i = mSensorColors.count(); i < 32; ++i ) {
+ v = ( ( ( v + 82 ) & 0xff ) << 23 ) | ( v >> 8 );
+ mSensorColors.append( QColor( v & 0xff, ( v >> 16 ) & 0xff, ( v >> 8 ) & 0xff ) );
+ }
+}
+
+StyleEngine::~StyleEngine()
+{
+}
+
+void StyleEngine::readProperties( KConfig *cfg )
+{
+ mFirstForegroundColor = cfg->readColorEntry( "fgColor1", &mFirstForegroundColor );
+ mSecondForegroundColor = cfg->readColorEntry( "fgColor2", &mSecondForegroundColor );
+ mAlarmColor = cfg->readColorEntry( "alarmColor", &mAlarmColor );
+ mBackgroundColor = cfg->readColorEntry( "backgroundColor", &mBackgroundColor );
+ mFontSize = cfg->readNumEntry( "fontSize", mFontSize );
+
+ QStringList list = cfg->readListEntry( "sensorColors" );
+ if ( !list.isEmpty() ) {
+ mSensorColors.clear();
+ QStringList::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it )
+ mSensorColors.append( QColor( *it ) );
+ }
+}
+
+void StyleEngine::saveProperties( KConfig *cfg )
+{
+ cfg->writeEntry( "fgColor1", mFirstForegroundColor );
+ cfg->writeEntry( "fgColor2", mSecondForegroundColor );
+ cfg->writeEntry( "alarmColor", mAlarmColor );
+ cfg->writeEntry( "backgroundColor", mBackgroundColor );
+ cfg->writeEntry( "fontSize", mFontSize );
+
+ QStringList list;
+ QValueList<QColor>::Iterator it;
+ for ( it = mSensorColors.begin(); it != mSensorColors.end(); ++it )
+ list.append( (*it).name() );
+
+ cfg->writeEntry( "sensorColors", list );
+}
+
+const QColor &StyleEngine::firstForegroundColor() const
+{
+ return mFirstForegroundColor;
+}
+
+const QColor &StyleEngine::secondForegroundColor() const
+{
+ return mSecondForegroundColor;
+}
+
+const QColor &StyleEngine::alarmColor() const
+{
+ return mAlarmColor;
+}
+
+const QColor &StyleEngine::backgroundColor() const
+{
+ return mBackgroundColor;
+}
+
+uint StyleEngine::fontSize() const
+{
+ return mFontSize;
+}
+
+const QColor& StyleEngine::sensorColor( uint pos )
+{
+ static QColor dummy;
+
+ if ( pos < mSensorColors.count() )
+ return *mSensorColors.at( pos );
+ else
+ return dummy;
+}
+
+uint StyleEngine::numSensorColors() const
+{
+ return mSensorColors.count();
+}
+
+void StyleEngine::configure()
+{
+ mSettingsDialog = new StyleSettings( 0 );
+
+ mSettingsDialog->setFirstForegroundColor( mFirstForegroundColor );
+ mSettingsDialog->setSecondForegroundColor( mSecondForegroundColor );
+ mSettingsDialog->setAlarmColor( mAlarmColor );
+ mSettingsDialog->setBackgroundColor( mBackgroundColor );
+ mSettingsDialog->setFontSize( mFontSize );
+ mSettingsDialog->setSensorColors( mSensorColors );
+
+ connect( mSettingsDialog, SIGNAL( applyClicked() ),
+ this, SLOT( applyToWorksheet() ) );
+
+ if ( mSettingsDialog->exec() )
+ apply();
+
+ delete mSettingsDialog;
+ mSettingsDialog = 0;
+}
+
+void StyleEngine::applyToWorksheet()
+{
+ apply();
+ emit applyStyleToWorksheet();
+}
+
+void StyleEngine::apply()
+{
+ if ( !mSettingsDialog )
+ return;
+
+ mFirstForegroundColor = mSettingsDialog->firstForegroundColor();
+ mSecondForegroundColor = mSettingsDialog->secondForegroundColor();
+ mAlarmColor = mSettingsDialog->alarmColor();
+ mBackgroundColor = mSettingsDialog->backgroundColor();
+ mFontSize = mSettingsDialog->fontSize();
+
+ mSensorColors = mSettingsDialog->sensorColors();
+}
+
+#include "StyleEngine.moc"
diff --git a/ksysguard/gui/ksgrd/StyleEngine.h b/ksysguard/gui/ksgrd/StyleEngine.h
new file mode 100644
index 000000000..d896a2422
--- /dev/null
+++ b/ksysguard/gui/ksgrd/StyleEngine.h
@@ -0,0 +1,86 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 - 2001 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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.
+
+ KSysGuard is currently maintained by Chris Schlaeger <[email protected]>.
+ Please do not commit any changes without consulting me first. Thanks!
+
+*/
+
+#ifndef KSG_STYLEENGINE_H
+#define KSG_STYLEENGINE_H
+
+#include <qcolor.h>
+#include <qobject.h>
+#include <qptrlist.h>
+
+#include <kdemacros.h>
+
+class KConfig;
+
+class QListBoxItem;
+
+class StyleSettings;
+
+namespace KSGRD {
+
+class KDE_EXPORT StyleEngine : public QObject
+{
+ Q_OBJECT
+
+ public:
+ StyleEngine();
+ ~StyleEngine();
+
+ void readProperties( KConfig* );
+ void saveProperties( KConfig* );
+
+ const QColor& firstForegroundColor() const;
+ const QColor& secondForegroundColor() const;
+ const QColor& alarmColor() const;
+ const QColor& backgroundColor() const;
+
+ uint fontSize() const;
+
+ const QColor& sensorColor( uint pos );
+ uint numSensorColors() const;
+
+ public slots:
+ void configure();
+ void applyToWorksheet();
+
+ signals:
+ void applyStyleToWorksheet();
+
+ private:
+ void apply();
+
+ QColor mFirstForegroundColor;
+ QColor mSecondForegroundColor;
+ QColor mAlarmColor;
+ QColor mBackgroundColor;
+ uint mFontSize;
+ QValueList<QColor> mSensorColors;
+
+ StyleSettings *mSettingsDialog;
+};
+
+KDE_EXPORT extern StyleEngine* Style;
+
+}
+
+#endif
diff --git a/ksysguard/gui/ksgrd/StyleSettings.cc b/ksysguard/gui/ksgrd/StyleSettings.cc
new file mode 100644
index 000000000..19a924cbe
--- /dev/null
+++ b/ksysguard/gui/ksgrd/StyleSettings.cc
@@ -0,0 +1,201 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 - 2001 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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.
+
+ KSysGuard is currently maintained by Chris Schlaeger <[email protected]>.
+ Please do not commit any changes without consulting me first. Thanks!
+
+*/
+
+#include <qimage.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlistbox.h>
+#include <qpixmap.h>
+#include <qpushbutton.h>
+#include <qspinbox.h>
+#include <qtabwidget.h>
+
+#include <kaccelmanager.h>
+#include <kcolorbutton.h>
+#include <kcolordialog.h>
+#include <klocale.h>
+
+#include "StyleSettings.h"
+
+StyleSettings::StyleSettings( QWidget *parent, const char *name )
+ : KDialogBase( Tabbed, i18n( "Global Style Settings" ), Help | Ok | Apply |
+ Cancel, Ok, parent, name, true, true )
+{
+ QFrame *page = addPage( i18n( "Display Style" ) );
+ QGridLayout *layout = new QGridLayout( page, 6, 2, 0, spacingHint() );
+
+ QLabel *label = new QLabel( i18n( "First foreground color:" ), page );
+ layout->addWidget( label, 0, 0 );
+
+ mFirstForegroundColor = new KColorButton( page );
+ layout->addWidget( mFirstForegroundColor, 0, 1 );
+ label->setBuddy( mFirstForegroundColor );
+
+ label = new QLabel( i18n( "Second foreground color:" ), page );
+ layout->addWidget( label, 1, 0 );
+
+ mSecondForegroundColor = new KColorButton( page );
+ layout->addWidget( mSecondForegroundColor, 1, 1 );
+ label->setBuddy( mSecondForegroundColor );
+
+ label = new QLabel( i18n( "Alarm color:" ), page );
+ layout->addWidget( label, 2, 0 );
+
+ mAlarmColor = new KColorButton( page );
+ layout->addWidget( mAlarmColor, 2, 1 );
+ label->setBuddy( mAlarmColor );
+
+ label = new QLabel( i18n( "Background color:" ), page );
+ layout->addWidget( label, 3, 0 );
+
+ mBackgroundColor = new KColorButton( page );
+ layout->addWidget( mBackgroundColor, 3, 1 );
+ label->setBuddy( mBackgroundColor );
+
+ label = new QLabel( i18n( "Font size:" ), page );
+ layout->addWidget( label, 4, 0 );
+
+ mFontSize = new QSpinBox( 7, 48, 1, page );
+ mFontSize->setValue( 8 );
+ layout->addWidget( mFontSize, 4, 1 );
+ label->setBuddy( mFontSize );
+
+ layout->setRowStretch( 5, 1 );
+
+ page = addPage( i18n( "Sensor Colors" ) );
+ layout = new QGridLayout( page, 1, 2, 0, spacingHint() );
+
+ mColorListBox = new QListBox( page );
+ layout->addWidget( mColorListBox, 0, 0 );
+
+ mEditColorButton = new QPushButton( i18n( "Change Color..." ), page );
+ mEditColorButton->setEnabled( false );
+ layout->addWidget( mEditColorButton, 0, 1, Qt::AlignTop );
+
+ connect( mColorListBox, SIGNAL( selectionChanged( QListBoxItem* ) ),
+ SLOT( selectionChanged( QListBoxItem* ) ) );
+ connect( mColorListBox, SIGNAL( doubleClicked( QListBoxItem* ) ),
+ SLOT( editSensorColor() ) );
+ connect( mEditColorButton, SIGNAL( clicked() ),
+ SLOT( editSensorColor() ) );
+
+ KAcceleratorManager::manage( this );
+}
+
+StyleSettings::~StyleSettings()
+{
+}
+
+void StyleSettings::setFirstForegroundColor( const QColor &color )
+{
+ mFirstForegroundColor->setColor( color );
+}
+
+QColor StyleSettings::firstForegroundColor() const
+{
+ return mFirstForegroundColor->color();
+}
+
+void StyleSettings::setSecondForegroundColor( const QColor &color )
+{
+ mSecondForegroundColor->setColor( color );
+}
+
+QColor StyleSettings::secondForegroundColor() const
+{
+ return mSecondForegroundColor->color();
+}
+
+void StyleSettings::setAlarmColor( const QColor &color )
+{
+ mAlarmColor->setColor( color );
+}
+
+QColor StyleSettings::alarmColor() const
+{
+ return mAlarmColor->color();
+}
+
+void StyleSettings::setBackgroundColor( const QColor &color )
+{
+ mBackgroundColor->setColor( color );
+}
+
+QColor StyleSettings::backgroundColor() const
+{
+ return mBackgroundColor->color();
+}
+
+void StyleSettings::setFontSize( uint size )
+{
+ mFontSize->setValue( size );
+}
+
+uint StyleSettings::fontSize() const
+{
+ return mFontSize->value();
+}
+
+void StyleSettings::setSensorColors( const QValueList<QColor> &list )
+{
+ mColorListBox->clear();
+
+ for ( uint i = 0; i < list.count(); ++i ) {
+ QPixmap pm( 12, 12 );
+ pm.fill( *list.at( i ) );
+ mColorListBox->insertItem( pm, i18n( "Color %1" ).arg( i ) );
+ }
+}
+
+QValueList<QColor> StyleSettings::sensorColors()
+{
+ QValueList<QColor> list;
+
+ for ( uint i = 0; i < mColorListBox->count(); ++i )
+ list.append( QColor( mColorListBox->pixmap( i )->convertToImage().pixel( 1, 1 ) ) );
+
+ return list;
+}
+
+void StyleSettings::editSensorColor()
+{
+ int pos = mColorListBox->currentItem();
+
+ if ( pos < 0 )
+ return;
+
+ QColor color = mColorListBox->pixmap( pos )->convertToImage().pixel( 1, 1 );
+
+ if ( KColorDialog::getColor( color ) == KColorDialog::Accepted ) {
+ QPixmap pm( 12, 12 );
+ pm.fill( color );
+ mColorListBox->changeItem( pm, mColorListBox->text( pos ), pos );
+ }
+}
+
+void StyleSettings::selectionChanged( QListBoxItem *item )
+{
+ mEditColorButton->setEnabled( item != 0 );
+}
+
+#include "StyleSettings.moc"
diff --git a/ksysguard/gui/ksgrd/StyleSettings.h b/ksysguard/gui/ksgrd/StyleSettings.h
new file mode 100644
index 000000000..d16b5e723
--- /dev/null
+++ b/ksysguard/gui/ksgrd/StyleSettings.h
@@ -0,0 +1,78 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 1999 - 2001 Chris Schlaeger <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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.
+
+ KSysGuard is currently maintained by Chris Schlaeger <[email protected]>.
+ Please do not commit any changes without consulting me first. Thanks!
+
+*/
+
+#ifndef KSG_STYLESETTINGS_H
+#define KSG_STYLESETTINGS_H
+
+#include <kdialogbase.h>
+
+#include <qcolor.h>
+
+class KColorButton;
+
+class QListBoxItem;
+class QPushButton;
+
+class StyleSettings : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ StyleSettings( QWidget *parent = 0, const char *name = 0 );
+ ~StyleSettings();
+
+ void setFirstForegroundColor( const QColor &color );
+ QColor firstForegroundColor() const;
+
+ void setSecondForegroundColor( const QColor &color );
+ QColor secondForegroundColor() const;
+
+ void setAlarmColor( const QColor &color );
+ QColor alarmColor() const;
+
+ void setBackgroundColor( const QColor &color );
+ QColor backgroundColor() const;
+
+ void setFontSize( uint size );
+ uint fontSize() const;
+
+ void setSensorColors( const QValueList<QColor> &list );
+ QValueList<QColor> sensorColors();
+
+ private slots:
+ void editSensorColor();
+ void selectionChanged( QListBoxItem* );
+
+ private:
+ KColorButton *mFirstForegroundColor;
+ KColorButton *mSecondForegroundColor;
+ KColorButton *mAlarmColor;
+ KColorButton *mBackgroundColor;
+
+ QSpinBox *mFontSize;
+
+ QListBox *mColorListBox;
+ QPushButton *mEditColorButton;
+};
+
+#endif
diff --git a/ksysguard/gui/ksgrd/TimerSettings.cc b/ksysguard/gui/ksgrd/TimerSettings.cc
new file mode 100644
index 000000000..4806f7d8a
--- /dev/null
+++ b/ksysguard/gui/ksgrd/TimerSettings.cc
@@ -0,0 +1,94 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2003 Tobias Koenig <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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.
+
+ KSysGuard is currently maintained by Chris Schlaeger <[email protected]>.
+ Please do not commit any changes without consulting me first. Thanks!
+
+*/
+
+#include <kaccelmanager.h>
+#include <klocale.h>
+
+#include <qcheckbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qspinbox.h>
+#include <qwhatsthis.h>
+
+#include "TimerSettings.h"
+
+TimerSettings::TimerSettings( QWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Timer Settings" ), Ok | Cancel,
+ Ok, parent, name, true, true )
+{
+ QFrame *page = plainPage();
+
+ QGridLayout *layout = new QGridLayout( page, 2, 2, 0, spacingHint() );
+
+ mUseGlobalUpdate = new QCheckBox( i18n( "Use update interval of worksheet" ), page );
+ layout->addMultiCellWidget( mUseGlobalUpdate, 0, 0, 0, 1 );
+
+ mLabel = new QLabel( i18n( "Update interval:" ), page );
+ layout->addWidget( mLabel, 1, 0 );
+
+ mInterval = new QSpinBox( 1, 300, 1, page );
+ mInterval->setValue( 2 );
+ mInterval->setSuffix( i18n( " sec" ) );
+ layout->addWidget( mInterval, 1, 1 );
+ mLabel->setBuddy( mInterval );
+ QWhatsThis::add( mInterval, i18n( "All displays of the sheet are updated at the rate specified here." ) );
+
+ connect( mUseGlobalUpdate, SIGNAL( toggled( bool ) ),
+ SLOT( globalUpdateChanged( bool ) ) );
+
+ mUseGlobalUpdate->setChecked( true );
+
+ KAcceleratorManager::manage( this );
+}
+
+TimerSettings::~TimerSettings()
+{
+}
+
+void TimerSettings::setUseGlobalUpdate( bool value )
+{
+ mUseGlobalUpdate->setChecked( value );
+}
+
+bool TimerSettings::useGlobalUpdate() const
+{
+ return mUseGlobalUpdate->isChecked();
+}
+
+void TimerSettings::setInterval( int interval )
+{
+ mInterval->setValue( interval );
+}
+
+int TimerSettings::interval() const
+{
+ return mInterval->value();
+}
+
+void TimerSettings::globalUpdateChanged( bool value )
+{
+ mInterval->setEnabled( !value );
+ mLabel->setEnabled( !value );
+}
+
+#include "TimerSettings.moc"
diff --git a/ksysguard/gui/ksgrd/TimerSettings.h b/ksysguard/gui/ksgrd/TimerSettings.h
new file mode 100644
index 000000000..daf2eda6f
--- /dev/null
+++ b/ksysguard/gui/ksgrd/TimerSettings.h
@@ -0,0 +1,56 @@
+/*
+ KSysGuard, the KDE System Guard
+
+ Copyright (c) 2003 Tobias Koenig <[email protected]>
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of version 2 of the GNU General Public
+ License as published by the Free Software Foundation.
+
+ 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.
+
+ KSysGuard is currently maintained by Chris Schlaeger <[email protected]>.
+ Please do not commit any changes without consulting me first. Thanks!
+
+*/
+
+#ifndef KSG_TIMERSETTINGS_H
+#define KSG_TIMERSETTINGS_H
+
+#include <kdialogbase.h>
+
+class QCheckBox;
+class QLabel;
+class QSpinBox;
+
+class KDE_EXPORT TimerSettings : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ TimerSettings( QWidget *parent, const char *name = 0 );
+ ~TimerSettings();
+
+ void setUseGlobalUpdate( bool value );
+ bool useGlobalUpdate() const;
+
+ void setInterval( int interval );
+ int interval() const;
+
+ private slots:
+ void globalUpdateChanged( bool );
+
+ private:
+ QCheckBox* mUseGlobalUpdate;
+ QLabel* mLabel;
+ QSpinBox* mInterval;
+};
+
+#endif