summaryrefslogtreecommitdiffstats
path: root/ksysguard/gui/ksgrd
diff options
context:
space:
mode:
Diffstat (limited to 'ksysguard/gui/ksgrd')
-rw-r--r--ksysguard/gui/ksgrd/CMakeLists.txt43
-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
19 files changed, 2649 insertions, 0 deletions
diff --git a/ksysguard/gui/ksgrd/CMakeLists.txt b/ksysguard/gui/ksgrd/CMakeLists.txt
new file mode 100644
index 000000000..b1ec7c5f8
--- /dev/null
+++ b/ksysguard/gui/ksgrd/CMakeLists.txt
@@ -0,0 +1,43 @@
+#################################################
+#
+# (C) 2010-2011 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${TDE_INCLUDE_DIR}
+ ${TQT_INCLUDE_DIRS}
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+
+##### headers ###################################
+
+install( FILES
+ HostConnector.h SensorAgent.h SensorClient.h
+ SensorManager.h SensorShellAgent.h SensorSocketAgent.h
+ StyleEngine.h StyleSettings.h TimerSettings.h
+ DESTINATION ${INCLUDE_INSTALL_DIR}/ksgrd )
+
+
+##### ksgrd (shared) ############################
+
+tde_add_library( ksgrd SHARED AUTOMOC
+ SOURCES
+ HostConnector.cc SensorAgent.cc SensorManager.cc
+ SensorShellAgent.cc SensorSocketAgent.cc StyleEngine.cc
+ StyleSettings.cc TimerSettings.cc
+ VERSION 1.2.0
+ LINK tdeui-shared
+ DESTINATION ${LIB_INSTALL_DIR}
+)
diff --git a/ksysguard/gui/ksgrd/HostConnector.cc b/ksysguard/gui/ksgrd/HostConnector.cc
new file mode 100644
index 000000000..b6e85b795
--- /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 <tdeapplication.h>
+#include <tdeaccelmanager.h>
+#include <kcombobox.h>
+#include <tdelocale.h>
+
+#include <tqbuttongroup.h>
+#include <tqlabel.h>
+#include <tqlayout.h>
+#include <tqradiobutton.h>
+#include <tqspinbox.h>
+#include <tqtooltip.h>
+#include <tqwhatsthis.h>
+
+#include "HostConnector.h"
+
+HostConnector::HostConnector( TQWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Connect Host" ), Help | Ok | Cancel, Ok,
+ parent, name, true, true )
+{
+ TQFrame *page = plainPage();
+ TQGridLayout *layout = new TQGridLayout( page, 2, 2, 0, spacingHint() );
+ layout->setColStretch( 1, 1 );
+
+ TQLabel *label = new TQLabel( i18n( "Host:" ), page );
+ layout->addWidget( label, 0, 0 );
+
+ mHostNames = new KComboBox( true, page );
+ mHostNames->setMaxCount( 20 );
+ mHostNames->setInsertionPolicy( TQComboBox::AtTop );
+ mHostNames->setAutoCompletion( true );
+ mHostNames->setDuplicatesEnabled( false );
+ layout->addWidget( mHostNames, 0, 1 );
+ label->setBuddy( mHostNames );
+ TQWhatsThis::add( mHostNames, i18n( "Enter the name of the host you want to connect to." ) );
+
+ mHostNameLabel = new TQLabel( page );
+ mHostNameLabel->hide();
+ layout->addWidget( mHostNameLabel, 0, 1 );
+
+ TQButtonGroup *group = new TQButtonGroup( 0, Qt::Vertical,
+ i18n( "Connection Type" ), page );
+ TQGridLayout *groupLayout = new TQGridLayout( group->layout(), 4, 4,
+ spacingHint() );
+ groupLayout->setAlignment( Qt::AlignTop );
+
+ mUseSsh = new TQRadioButton( i18n( "ssh" ), group );
+ mUseSsh->setEnabled( true );
+ mUseSsh->setChecked( true );
+ TQWhatsThis::add( mUseSsh, i18n( "Select this to use the secure shell to login to the remote host." ) );
+ groupLayout->addWidget( mUseSsh, 0, 0 );
+
+ mUseRsh = new TQRadioButton( i18n( "rsh" ), group );
+ TQWhatsThis::add( mUseRsh, i18n( "Select this to use the remote shell to login to the remote host." ) );
+ groupLayout->addWidget( mUseRsh, 0, 1 );
+
+ mUseDaemon = new TQRadioButton( i18n( "Daemon" ), group );
+ TQWhatsThis::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 TQRadioButton( i18n( "Custom command" ), group );
+ TQWhatsThis::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 TQLabel( i18n( "Port:" ), group );
+ groupLayout->addWidget( label, 1, 0 );
+
+ mPort = new TQSpinBox( 1, 65535, 1, group );
+ mPort->setEnabled( false );
+ mPort->setValue( 3112 );
+ TQToolTip::add( mPort, i18n( "Enter the port number on which the ksysguard daemon is listening for connections." ) );
+ groupLayout->addWidget( mPort, 1, 2 );
+
+ label = new TQLabel( i18n( "e.g. 3112" ), group );
+ groupLayout->addWidget( label, 1, 3 );
+
+ label = new TQLabel( i18n( "Command:" ), group );
+ groupLayout->addWidget( label, 2, 0 );
+
+ mCommands = new KComboBox( true, group );
+ mCommands->setEnabled( false );
+ mCommands->setMaxCount( 20 );
+ mCommands->setInsertionPolicy( TQComboBox::AtTop );
+ mCommands->setAutoCompletion( true );
+ mCommands->setDuplicatesEnabled( false );
+ TQWhatsThis::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 TQLabel( 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, TQT_SIGNAL( toggled( bool ) ),
+ mCommands, TQT_SLOT( setEnabled( bool ) ) );
+ connect( mUseDaemon, TQT_SIGNAL( toggled( bool ) ),
+ mPort, TQT_SLOT( setEnabled( bool ) ) );
+ connect( mHostNames->lineEdit(), TQT_SIGNAL( textChanged ( const TQString & ) ),
+ this, TQT_SLOT( slotHostNameChanged( const TQString & ) ) );
+ enableButtonOK( !mHostNames->lineEdit()->text().isEmpty() );
+ TDEAcceleratorManager::manage( this );
+}
+
+HostConnector::~HostConnector()
+{
+}
+
+void HostConnector::slotHostNameChanged( const TQString &_text )
+{
+ enableButtonOK( !_text.isEmpty() );
+}
+
+void HostConnector::setHostNames( const TQStringList &list )
+{
+ mHostNames->insertStringList( list );
+}
+
+TQStringList HostConnector::hostNames() const
+{
+ TQStringList list;
+
+ for ( int i = 0; i < mHostNames->count(); ++i )
+ list.append( mHostNames->text( i ) );
+
+ return list;
+}
+
+void HostConnector::setCommands( const TQStringList &list )
+{
+ mCommands->insertStringList( list );
+}
+
+TQStringList HostConnector::commands() const
+{
+ TQStringList list;
+
+ for ( int i = 0; i < mCommands->count(); ++i )
+ list.append( mCommands->text( i ) );
+
+ return list;
+}
+
+void HostConnector::setCurrentHostName( const TQString &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();
+ }
+}
+
+TQString HostConnector::currentHostName() const
+{
+ return mHostNames->currentText();
+}
+
+TQString 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..dbf654b7e
--- /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 TQLabel;
+class TQRadioButton;
+class TQSpinBox;
+
+class HostConnector : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ HostConnector( TQWidget *parent, const char *name = 0 );
+ ~HostConnector();
+
+ void setHostNames( const TQStringList &list );
+ TQStringList hostNames() const;
+
+ void setCommands( const TQStringList &list );
+ TQStringList commands() const;
+
+ void setCurrentHostName( const TQString &hostName );
+
+ TQString currentHostName() const;
+ TQString 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 TQString &_text );
+ private:
+ KComboBox *mCommands;
+ KComboBox *mHostNames;
+
+ TQLabel *mHostNameLabel;
+
+ TQRadioButton *mUseSsh;
+ TQRadioButton *mUseRsh;
+ TQRadioButton *mUseDaemon;
+ TQRadioButton *mUseCustom;
+
+ TQSpinBox *mPort;
+};
+
+#endif
diff --git a/ksysguard/gui/ksgrd/Makefile.am b/ksysguard/gui/ksgrd/Makefile.am
new file mode 100644
index 000000000..52f5bfd01
--- /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_TDEUI)
+
+# 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..7f9615985
--- /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 <tdelocale.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 TQString &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 TQString &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 = TQString::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 = TQString::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 = TQString::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
+ TQString 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 TQString &hostName )
+{
+ mHostName = hostName;
+}
+
+const TQString &SensorAgent::hostName() const
+{
+ return mHostName;
+}
+
+
+SensorRequest::SensorRequest( const TQString &request, SensorClient *client, int id )
+ : mRequest( request ), mClient( client ), mId( id )
+{
+}
+
+SensorRequest::~SensorRequest()
+{
+}
+
+void SensorRequest::setRequest( const TQString &request )
+{
+ mRequest = request;
+}
+
+TQString 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..36c44095c
--- /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 <tqobject.h>
+#include <tqptrlist.h>
+
+class TDEProcess;
+class KShellProcess;
+
+class TQString;
+
+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 TQString &host, const TQString &shell,
+ const TQString &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 TQString &req, SensorClient *client, int id = 0 );
+
+ virtual void hostInfo( TQString &sh, TQString &cmd, int &port ) const = 0;
+
+ void disconnectClient( SensorClient *client );
+
+ const TQString &hostName() const;
+
+ signals:
+ void reconfigure( const SensorAgent* );
+
+ protected:
+ void processAnswer( const TQString &buffer );
+ void executeCommand();
+
+ SensorManager *sensorManager();
+
+ void setDaemonOnLine( bool value );
+ bool daemonOnLine() const;
+
+ void setTransmitting( bool value );
+ bool transmitting() const;
+
+ void setHostName( const TQString &hostName );
+
+ private:
+ virtual bool writeMsg( const char *msg, int len ) = 0;
+ virtual bool txReady() = 0;
+
+ int mState;
+ TQPtrList<SensorRequest> mInputFIFO;
+ TQPtrList<SensorRequest> mProcessingFIFO;
+ TQString mAnswerBuffer;
+ TQString mErrorBuffer;
+
+ SensorManager *mSensorManager;
+
+ bool mDaemonOnLine;
+ bool mTransmitting;
+ TQString mHostName;
+};
+
+/**
+ This auxilliary class is used to store requests during their processing.
+*/
+class SensorRequest
+{
+ public:
+ SensorRequest( const TQString &request, SensorClient *client, int id );
+ ~SensorRequest();
+
+ void setRequest( const TQString& );
+ TQString request() const;
+
+ void setClient( SensorClient* );
+ SensorClient *client();
+
+ void setId( int );
+ int id();
+
+ private:
+ TQString 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..d4e286cb1
--- /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 <tqptrlist.h>
+#include <tqstring.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 TQString& ) { }
+
+ /**
+ 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 TQString &info, TQChar separator )
+ {
+ mTokens = TQStringList::split( separator, info );
+ }
+
+ ~SensorTokenizer() { }
+
+ const TQString& operator[]( unsigned idx )
+ {
+ return mTokens[ idx ];
+ }
+
+ uint count()
+ {
+ return mTokens.count();
+ }
+
+ private:
+ TQStringList 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 TQString &info )
+ : SensorTokenizer( info, '\t' ) { }
+
+ ~SensorIntegerInfo() { }
+
+ const TQString &name()
+ {
+ return (*this)[ 0 ];
+ }
+
+ long min()
+ {
+ return (*this)[ 1 ].toLong();
+ }
+
+ long max()
+ {
+ return (*this)[ 2 ].toLong();
+ }
+
+ const TQString &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 TQString &info )
+ : SensorTokenizer( info, '\t' ) { }
+
+ ~SensorFloatInfo() { }
+
+ const TQString &name()
+ {
+ return (*this)[ 0 ];
+ }
+
+ double min()
+ {
+ return (*this)[ 1 ].toDouble();
+ }
+
+ double max()
+ {
+ return (*this)[ 2 ].toDouble();
+ }
+
+ const TQString &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 TQString &line )
+ : SensorTokenizer( line, '\t' ) { }
+
+ ~SensorPSLine() { }
+
+ const TQString& 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..7794d9c10
--- /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 <tqcombobox.h>
+#include <tqlabel.h>
+#include <tqpushbutton.h>
+#include <tqradiobutton.h>
+#include <tqspinbox.h>
+
+#include <tdeapplication.h>
+#include <kdebug.h>
+#include <tdelocale.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 TQString( i18n( "CPU Load" ) ) );
+ mDict.insert( "idle", new TQString( i18n( "Idle Load" ) ) );
+ mDict.insert( "sys", new TQString( i18n( "System Load" ) ) );
+ mDict.insert( "nice", new TQString( i18n( "Nice Load" ) ) );
+ mDict.insert( "user", new TQString( i18n( "User Load" ) ) );
+ mDict.insert( "mem", new TQString( i18n( "Memory" ) ) );
+ mDict.insert( "physical", new TQString( i18n( "Physical Memory" ) ) );
+ mDict.insert( "swap", new TQString( i18n( "Swap Memory" ) ) );
+ mDict.insert( "cached", new TQString( i18n( "Cached Memory" ) ) );
+ mDict.insert( "buf", new TQString( i18n( "Buffered Memory" ) ) );
+ mDict.insert( "used", new TQString( i18n( "Used Memory" ) ) );
+ mDict.insert( "application", new TQString( i18n( "Application Memory" ) ) );
+ mDict.insert( "free", new TQString( i18n( "Free Memory" ) ) );
+ mDict.insert( "pscount", new TQString( i18n( "Process Count" ) ) );
+ mDict.insert( "ps", new TQString( i18n( "Process Controller" ) ) );
+ mDict.insert( "disk", new TQString( i18n( "Disk Throughput" ) ) );
+ mDict.insert( "load", new TQString( i18n( "CPU Load", "Load" ) ) );
+ mDict.insert( "total", new TQString( i18n( "Total Accesses" ) ) );
+ mDict.insert( "rio", new TQString( i18n( "Read Accesses" ) ) );
+ mDict.insert( "wio", new TQString( i18n( "Write Accesses" ) ) );
+ mDict.insert( "rblk", new TQString( i18n( "Read Data" ) ) );
+ mDict.insert( "wblk", new TQString( i18n( "Write Data" ) ) );
+ mDict.insert( "pageIn", new TQString( i18n( "Pages In" ) ) );
+ mDict.insert( "pageOut", new TQString( i18n( "Pages Out" ) ) );
+ mDict.insert( "context", new TQString( i18n( "Context Switches" ) ) );
+ mDict.insert( "network", new TQString( i18n( "Network" ) ) );
+ mDict.insert( "interfaces", new TQString( i18n( "Interfaces" ) ) );
+ mDict.insert( "receiver", new TQString( i18n( "Receiver" ) ) );
+ mDict.insert( "transmitter", new TQString( i18n( "Transmitter" ) ) );
+ mDict.insert( "data", new TQString( i18n( "Data" ) ) );
+ mDict.insert( "compressed", new TQString( i18n( "Compressed Packets" ) ) );
+ mDict.insert( "drops", new TQString( i18n( "Dropped Packets" ) ) );
+ mDict.insert( "errors", new TQString( i18n( "Errors" ) ) );
+ mDict.insert( "fifo", new TQString( i18n( "FIFO Overruns" ) ) );
+ mDict.insert( "frame", new TQString( i18n( "Frame Errors" ) ) );
+ mDict.insert( "multicast", new TQString( i18n( "Multicast" ) ) );
+ mDict.insert( "packets", new TQString( i18n( "Packets" ) ) );
+ mDict.insert( "carrier", new TQString( i18n( "Carrier" ) ) );
+ mDict.insert( "collisions", new TQString( i18n( "Collisions" ) ) );
+ mDict.insert( "sockets", new TQString( i18n( "Sockets" ) ) );
+ mDict.insert( "count", new TQString( i18n( "Total Number" ) ) );
+ mDict.insert( "list", new TQString( i18n( "Table" ) ) );
+ mDict.insert( "apm", new TQString( i18n( "Advanced Power Management" ) ) );
+ mDict.insert( "acpi", new TQString( i18n( "ACPI" ) ) );
+ mDict.insert( "thermal_zone", new TQString( i18n( "Thermal Zone" ) ) );
+ mDict.insert( "temperature", new TQString( i18n( "Temperature" ) ) );
+ mDict.insert( "fan", new TQString( i18n( "Fan" ) ) );
+ mDict.insert( "state", new TQString( i18n( "State" ) ) );
+ mDict.insert( "battery", new TQString( i18n( "Battery" ) ) );
+ mDict.insert( "batterycharge", new TQString( i18n( "Battery Charge" ) ) );
+ mDict.insert( "batteryusage", new TQString( i18n( "Battery Usage" ) ) );
+ mDict.insert( "remainingtime", new TQString( i18n( "Remaining Time" ) ) );
+ mDict.insert( "interrupts", new TQString( i18n( "Interrupts" ) ) );
+ mDict.insert( "loadavg1", new TQString( i18n( "Load Average (1 min)" ) ) );
+ mDict.insert( "loadavg5", new TQString( i18n( "Load Average (5 min)" ) ) );
+ mDict.insert( "loadavg15", new TQString( i18n( "Load Average (15 min)" ) ) );
+ mDict.insert( "clock", new TQString( i18n( "Clock Frequency" ) ) );
+ mDict.insert( "lmsensors", new TQString( i18n( "Hardware Sensors" ) ) );
+ mDict.insert( "partitions", new TQString( i18n( "Partition Usage" ) ) );
+ mDict.insert( "usedspace", new TQString( i18n( "Used Space" ) ) );
+ mDict.insert( "freespace", new TQString( i18n( "Free Space" ) ) );
+ mDict.insert( "filllevel", new TQString( i18n( "Fill Level" ) ) );
+
+ for ( int i = 0; i < 32; i++ ) {
+ mDict.insert( "cpu" + TQString::number( i ),
+ new TQString( TQString( i18n( "CPU%1" ) ).arg( i ) ) );
+ mDict.insert( "disk" + TQString::number( i ),
+ new TQString( TQString( i18n( "Disk%1" ) ).arg( i ) ) );
+ }
+
+ for ( int i = 0; i < 6; i++) {
+ mDict.insert( "fan" + TQString::number( i ),
+ new TQString( TQString( i18n( "Fan%1" ) ).arg( i ) ) );
+ mDict.insert( "temp" + TQString::number( i ),
+ new TQString( TQString( i18n( "Temperature%1" ) ).arg( i ) ) );
+ }
+
+ mDict.insert( "int00", new TQString( i18n( "Total" ) ) );
+
+ TQString num;
+ for ( int i = 1; i < 25; i++ ) {
+ num.sprintf( "%.2d", i );
+ mDict.insert( "int" + num,
+ new TQString( TQString( i18n( "Int%1" ) ).arg( i - 1, 3 ) ) );
+ }
+
+ mDescriptions.setAutoDelete( true );
+ // TODO: translated descriptions not yet implemented.
+
+ mUnits.setAutoDelete( true );
+ mUnits.insert( "1/s", new TQString( i18n( "the unit 1 per second", "1/s" ) ) );
+ mUnits.insert( "kBytes", new TQString( i18n( "kBytes" ) ) );
+ mUnits.insert( "min", new TQString( i18n( "the unit minutes", "min" ) ) );
+ mUnits.insert( "MHz", new TQString( i18n( "the frequency unit", "MHz" ) ) );
+
+ mTypes.setAutoDelete( true );
+ mTypes.insert( "integer", new TQString( i18n( "Integer Value" ) ) );
+ mTypes.insert( "float", new TQString( i18n( "Floating Point Value" ) ) );
+ mTypes.insert( "table", new TQString( i18n( "Process Controller" ) ) );
+ mTypes.insert( "listview", new TQString( i18n( "Table" ) ) );
+
+ mBroadcaster = 0;
+
+ mHostConnector = new HostConnector( 0 );
+}
+
+SensorManager::~SensorManager()
+{
+ delete mHostConnector;
+}
+
+bool SensorManager::engageHost( const TQString &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() ) {
+ TQString shell = "";
+ TQString 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 TQString &hostName, const TQString &shell,
+ const TQString &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, TQT_SIGNAL( reconfigure( const SensorAgent* ) ),
+ TQT_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(). */
+ TQCustomEvent* event = new TQCustomEvent( TQEvent::User, (void*)agent );
+ kapp->postEvent( this, event );
+}
+
+bool SensorManager::disengage( const SensorAgent *agent )
+{
+ TQDictIterator<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 TQString &hostName )
+{
+ SensorAgent *agent;
+ if ( ( agent = mAgents.find( hostName ) ) != 0 ) {
+ mAgents.remove( hostName );
+ emit update();
+ return true;
+ }
+
+ return false;
+}
+
+bool SensorManager::resynchronize( const TQString &hostName )
+{
+ SensorAgent *agent;
+
+ if ( ( agent = mAgents.find( hostName ) ) == 0 )
+ return false;
+
+ TQString 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 ) {
+ TQCustomEvent *event = new TQCustomEvent( TQEvent::User );
+ event->setData( new TQString( i18n( "Connection to %1 has been lost." )
+ .arg( agent->hostName() ) ) );
+ kapp->postEvent( mBroadcaster, event );
+ }
+}
+
+void SensorManager::notify( const TQString &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 ) {
+ TQCustomEvent *event = new TQCustomEvent( TQEvent::User );
+ event->setData( new TQString( msg ) );
+ kapp->postEvent( mBroadcaster, event );
+ }
+}
+
+void SensorManager::setBroadcaster( TQWidget *wdg )
+{
+ mBroadcaster = wdg;
+}
+
+void SensorManager::reconfigure( const SensorAgent* )
+{
+ emit update();
+}
+
+bool SensorManager::event( TQEvent *event )
+{
+ if ( event->type() == TQEvent::User ) {
+ disengage( (const SensorAgent*)((TQCustomEvent*)event)->data() );
+ return true;
+ }
+
+ return false;
+}
+
+bool SensorManager::sendRequest( const TQString &hostName, const TQString &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 TQString SensorManager::hostName( const SensorAgent *agent) const
+{
+ TQDictIterator<SensorAgent> it( mAgents );
+
+ while ( it.current() ) {
+ if ( it.current() == agent )
+ return it.currentKey();
+ ++it;
+ }
+
+ return TQString::null;
+}
+
+bool SensorManager::hostInfo( const TQString &hostName, TQString &shell,
+ TQString &command, int &port )
+{
+ SensorAgent *agent;
+ if ( ( agent = mAgents.find( hostName ) ) != 0 ) {
+ agent->hostInfo( shell, command, port );
+ return true;
+ }
+
+ return false;
+}
+
+const TQString &SensorManager::translateUnit( const TQString &unit ) const
+{
+ if ( !unit.isEmpty() && mUnits[ unit ] )
+ return *mUnits[ unit ];
+ else
+ return unit;
+}
+
+const TQString &SensorManager::translateSensorPath( const TQString &path ) const
+{
+ if ( !path.isEmpty() && mDict[ path ] )
+ return *mDict[ path ];
+ else
+ return path;
+}
+
+const TQString &SensorManager::translateSensorType( const TQString &type ) const
+{
+ if ( !type.isEmpty() && mTypes[ type ] )
+ return *mTypes[ type ];
+ else
+ return type;
+}
+
+TQString SensorManager::translateSensor( const TQString &sensor ) const
+{
+ TQString 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( TDEConfig *cfg )
+{
+ mHostConnector->setHostNames( cfg->readListEntry( "HostList" ) );
+ mHostConnector->setCommands( cfg->readListEntry( "CommandList" ) );
+}
+
+void
+SensorManager::saveProperties( TDEConfig *cfg )
+{
+ cfg->writeEntry( "HostList", mHostConnector->hostNames() );
+ cfg->writeEntry( "CommandList", mHostConnector->commands() );
+}
+
+void SensorManager::disconnectClient( SensorClient *client )
+{
+ TQDictIterator<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..1e859c638
--- /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 <tdeconfig.h>
+
+#include <tqdict.h>
+#include <tqobject.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 TQString &hostName );
+ bool engage( const TQString &hostName, const TQString &shell = "ssh",
+ const TQString &command = "", int port = -1 );
+
+ void requestDisengage( const SensorAgent *agent );
+ bool disengage( const SensorAgent *agent );
+ bool disengage( const TQString &hostName );
+ bool resynchronize( const TQString &hostName );
+ void hostLost( const SensorAgent *agent );
+ void notify( const TQString &msg ) const;
+
+ void setBroadcaster( TQWidget *wdg );
+
+ virtual bool event( TQEvent *event );
+
+ bool sendRequest( const TQString &hostName, const TQString &request,
+ SensorClient *client, int id = 0 );
+
+ const TQString hostName( const SensorAgent *sensor ) const;
+ bool hostInfo( const TQString &host, TQString &shell,
+ TQString &command, int &port );
+
+ const TQString& translateUnit( const TQString &unit ) const;
+ const TQString& translateSensorPath( const TQString &path ) const;
+ const TQString& translateSensorType( const TQString &type ) const;
+ TQString translateSensor(const TQString& u) const;
+
+ void readProperties( TDEConfig *cfg );
+ void saveProperties( TDEConfig *cfg );
+
+ void disconnectClient( SensorClient *client );
+
+ public slots:
+ void reconfigure( const SensorAgent *agent );
+
+ signals:
+ void update();
+ void hostConnectionLost( const TQString &hostName );
+
+ protected:
+ TQDict<SensorAgent> mAgents;
+
+ private:
+ /**
+ These dictionary stores the localized versions of the sensor
+ descriptions and units.
+ */
+ TQDict<TQString> mDescriptions;
+ TQDict<TQString> mUnits;
+ TQDict<TQString> mDict;
+ TQDict<TQString> mTypes;
+
+ TQWidget* mBroadcaster;
+
+ HostConnector* mHostConnector;
+};
+
+KDE_EXPORT extern SensorManager* SensorMgr;
+
+class KDE_EXPORT SensorManagerIterator : public TQDictIterator<SensorAgent>
+{
+ public:
+ SensorManagerIterator( const SensorManager *sm )
+ : TQDictIterator<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..7e137ad56
--- /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 TQString &host, const TQString &shell,
+ const TQString &command, int )
+{
+ mRetryCount = 3;
+ mDaemon = new TDEProcess;
+ mDaemon->setUseShell(true);
+ setHostName( host );
+ mShell = shell;
+ mCommand = command;
+
+ connect( mDaemon, TQT_SIGNAL( processExited( TDEProcess* ) ),
+ TQT_SLOT( daemonExited( TDEProcess* ) ) );
+ connect( mDaemon, TQT_SIGNAL( receivedStdout( TDEProcess*, char*, int ) ),
+ TQT_SLOT( msgRcvd( TDEProcess*, char*, int ) ) );
+ connect( mDaemon, TQT_SIGNAL( receivedStderr( TDEProcess*, char*, int ) ),
+ TQT_SLOT( errMsgRcvd( TDEProcess*, char*, int ) ) );
+ connect( mDaemon, TQT_SIGNAL( wroteStdin( TDEProcess* ) ),
+ TQT_SLOT( msgSent( TDEProcess* ) ) );
+
+ TQString cmd;
+ if ( !command.isEmpty() )
+ cmd = command;
+ else
+ cmd = mShell + " " + hostName() + " ksysguardd";
+ *mDaemon << cmd;
+
+ if ( !mDaemon->start( TDEProcess::NotifyOnExit, TDEProcess::All ) ) {
+ sensorManager()->hostLost( this );
+ kdDebug (1215) << "Command '" << cmd << "' failed" << endl;
+ return false;
+ }
+
+ return true;
+}
+
+void SensorShellAgent::hostInfo( TQString &shell, TQString &command,
+ int &port) const
+{
+ shell = mShell;
+ command = mCommand;
+ port = -1;
+}
+
+void SensorShellAgent::msgSent( TDEProcess* )
+{
+ setTransmitting( false );
+
+ // Try to send next request if available.
+ executeCommand();
+}
+
+void SensorShellAgent::msgRcvd( TDEProcess*, char *buffer, int buflen )
+{
+ if ( !buffer || buflen == 0 )
+ return;
+ mRetryCount = 3; //we recieved an answer, so reset our retry count back to 3
+ TQString aux = TQString::fromLocal8Bit( buffer, buflen );
+
+ processAnswer( aux );
+}
+
+void SensorShellAgent::errMsgRcvd( TDEProcess*, char *buffer, int buflen )
+{
+ if ( !buffer || buflen == 0 )
+ return;
+
+ TQString buf = TQString::fromLocal8Bit( buffer, buflen );
+
+ kdDebug(1215) << "SensorShellAgent: Warning, received text over stderr!"
+ << endl << buf << endl;
+}
+
+void SensorShellAgent::daemonExited( TDEProcess *process )
+{
+ kdDebug() << "daemonExited" << endl;
+ if ( mRetryCount-- <= 0 || !mDaemon->start( TDEProcess::NotifyOnExit, TDEProcess::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..2befd346b
--- /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 <tqobject.h>
+#include <tqptrlist.h>
+#include <tqguardedptr.h>
+
+#include <SensorAgent.h>
+
+class TQString;
+
+class TDEProcess;
+
+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 TQString &host, const TQString &shell,
+ const TQString &command = "", int port = -1 );
+
+ void hostInfo( TQString &shell, TQString &command, int &port) const;
+
+ private slots:
+ void msgSent( TDEProcess* );
+ void msgRcvd( TDEProcess*, char *buffer, int buflen );
+ void errMsgRcvd( TDEProcess*, char *buffer, int buflen );
+ void daemonExited( TDEProcess* );
+
+ private:
+ bool writeMsg( const char *msg, int len );
+ bool txReady();
+
+ TQGuardedPtr<TDEProcess> mDaemon;
+ TQString mShell;
+ TQString mCommand;
+ int mRetryCount;
+};
+
+}
+
+#endif
diff --git a/ksysguard/gui/ksgrd/SensorSocketAgent.cc b/ksysguard/gui/ksgrd/SensorSocketAgent.cc
new file mode 100644
index 000000000..30c0cc7e9
--- /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 <tdelocale.h>
+#include <kpassdlg.h>
+
+#include "SensorClient.h"
+#include "SensorManager.h"
+
+#include "SensorSocketAgent.h"
+
+using namespace KSGRD;
+
+SensorSocketAgent::SensorSocketAgent( SensorManager *sm )
+ : SensorAgent( sm )
+{
+ connect( &mSocket, TQT_SIGNAL( gotError( int ) ), TQT_SLOT( error( int ) ) );
+ connect( &mSocket, TQT_SIGNAL( bytesWritten( int ) ), TQT_SLOT( msgSent( int ) ) );
+ connect( &mSocket, TQT_SIGNAL( readyRead() ), TQT_SLOT( msgRcvd() ) );
+ connect( &mSocket, TQT_SIGNAL( closed() ), TQT_SLOT( connectionClosed() ) );
+}
+
+SensorSocketAgent::~SensorSocketAgent()
+{
+ mSocket.writeBlock( "quit\n", strlen( "quit\n" ) );
+ mSocket.flush();
+}
+
+bool SensorSocketAgent::start( const TQString &host, const TQString&,
+ const TQString&, int port )
+{
+ if ( port <= 0 )
+ kdDebug(1215) << "SensorSocketAgent::start: Illegal port " << port << endl;
+
+ setHostName( host );
+ mPort = port;
+
+ mSocket.connect( hostName(), TQString::number(mPort) );
+
+ return true;
+}
+
+void SensorSocketAgent::hostInfo( TQString &shell, TQString &command, int &port ) const
+{
+ shell = TQString::null;
+ command = TQString::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 );
+ TQString buf = TQString::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::TDESocketBase::ConnectionRefused:
+ SensorMgr->notify( i18n( "Connection to %1 refused" )
+ .arg( hostName() ) );
+ break;
+ case KNetwork::TDESocketBase::LookupFailure:
+ SensorMgr->notify( i18n( "Host %1 not found" )
+ .arg( hostName() ) );
+ break;
+ case KNetwork::TDESocketBase::Timeout:
+ SensorMgr->notify( i18n( "Timeout at host %1")
+ .arg( hostName() ) );
+ break;
+ case KNetwork::TDESocketBase::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..7b9062f17
--- /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 <tqptrlist.h>
+#include <kbufferedsocket.h>
+
+#include <SensorAgent.h>
+
+class TQString;
+
+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 TQString &host, const TQString &shell,
+ const TQString &command = "", int port = -1 );
+
+ void hostInfo( TQString &shell, TQString &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::TDEBufferedSocket mSocket;
+ int mPort;
+};
+
+}
+
+#endif
diff --git a/ksysguard/gui/ksgrd/StyleEngine.cc b/ksysguard/gui/ksgrd/StyleEngine.cc
new file mode 100644
index 000000000..ce3e3bd6b
--- /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 <tqimage.h>
+#include <tqpushbutton.h>
+#include <tqspinbox.h>
+
+#include <tdeconfig.h>
+#include <tdelocale.h>
+
+#include "StyleSettings.h"
+
+#include "StyleEngine.h"
+
+using namespace KSGRD;
+
+StyleEngine* KSGRD::Style;
+
+StyleEngine::StyleEngine()
+{
+ mFirstForegroundColor = TQColor( 0x6894c9 ); // light blue
+ mSecondForegroundColor = TQColor( 0x6894c9 ); // light blue
+ mAlarmColor = TQColor( 255, 0, 0 );
+ mBackgroundColor = TQColor( 0x313031 ); // almost black
+ mFontSize = 9;
+
+ mSensorColors.append( TQColor( 0x1889ff ) ); // soft blue
+ mSensorColors.append( TQColor( 0xff7f08 ) ); // reddish
+ mSensorColors.append( TQColor( 0xffeb14 ) ); // bright yellow
+
+ uint v = 0x00ff00;
+ for ( uint i = mSensorColors.count(); i < 32; ++i ) {
+ v = ( ( ( v + 82 ) & 0xff ) << 23 ) | ( v >> 8 );
+ mSensorColors.append( TQColor( v & 0xff, ( v >> 16 ) & 0xff, ( v >> 8 ) & 0xff ) );
+ }
+}
+
+StyleEngine::~StyleEngine()
+{
+}
+
+void StyleEngine::readProperties( TDEConfig *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 );
+
+ TQStringList list = cfg->readListEntry( "sensorColors" );
+ if ( !list.isEmpty() ) {
+ mSensorColors.clear();
+ TQStringList::Iterator it;
+ for ( it = list.begin(); it != list.end(); ++it )
+ mSensorColors.append( TQColor( *it ) );
+ }
+}
+
+void StyleEngine::saveProperties( TDEConfig *cfg )
+{
+ cfg->writeEntry( "fgColor1", mFirstForegroundColor );
+ cfg->writeEntry( "fgColor2", mSecondForegroundColor );
+ cfg->writeEntry( "alarmColor", mAlarmColor );
+ cfg->writeEntry( "backgroundColor", mBackgroundColor );
+ cfg->writeEntry( "fontSize", mFontSize );
+
+ TQStringList list;
+ TQValueList<TQColor>::Iterator it;
+ for ( it = mSensorColors.begin(); it != mSensorColors.end(); ++it )
+ list.append( (*it).name() );
+
+ cfg->writeEntry( "sensorColors", list );
+}
+
+const TQColor &StyleEngine::firstForegroundColor() const
+{
+ return mFirstForegroundColor;
+}
+
+const TQColor &StyleEngine::secondForegroundColor() const
+{
+ return mSecondForegroundColor;
+}
+
+const TQColor &StyleEngine::alarmColor() const
+{
+ return mAlarmColor;
+}
+
+const TQColor &StyleEngine::backgroundColor() const
+{
+ return mBackgroundColor;
+}
+
+uint StyleEngine::fontSize() const
+{
+ return mFontSize;
+}
+
+const TQColor& StyleEngine::sensorColor( uint pos )
+{
+ static TQColor 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, TQT_SIGNAL( applyClicked() ),
+ this, TQT_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..50ec06e0b
--- /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 <tqcolor.h>
+#include <tqobject.h>
+#include <tqptrlist.h>
+
+#include <kdemacros.h>
+
+class TDEConfig;
+
+class TQListBoxItem;
+
+class StyleSettings;
+
+namespace KSGRD {
+
+class KDE_EXPORT StyleEngine : public QObject
+{
+ Q_OBJECT
+
+ public:
+ StyleEngine();
+ ~StyleEngine();
+
+ void readProperties( TDEConfig* );
+ void saveProperties( TDEConfig* );
+
+ const TQColor& firstForegroundColor() const;
+ const TQColor& secondForegroundColor() const;
+ const TQColor& alarmColor() const;
+ const TQColor& backgroundColor() const;
+
+ uint fontSize() const;
+
+ const TQColor& sensorColor( uint pos );
+ uint numSensorColors() const;
+
+ public slots:
+ void configure();
+ void applyToWorksheet();
+
+ signals:
+ void applyStyleToWorksheet();
+
+ private:
+ void apply();
+
+ TQColor mFirstForegroundColor;
+ TQColor mSecondForegroundColor;
+ TQColor mAlarmColor;
+ TQColor mBackgroundColor;
+ uint mFontSize;
+ TQValueList<TQColor> 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..b84d3e407
--- /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 <tqimage.h>
+#include <tqlabel.h>
+#include <tqlayout.h>
+#include <tqlistbox.h>
+#include <tqpixmap.h>
+#include <tqpushbutton.h>
+#include <tqspinbox.h>
+#include <tqtabwidget.h>
+
+#include <tdeaccelmanager.h>
+#include <kcolorbutton.h>
+#include <kcolordialog.h>
+#include <tdelocale.h>
+
+#include "StyleSettings.h"
+
+StyleSettings::StyleSettings( TQWidget *parent, const char *name )
+ : KDialogBase( Tabbed, i18n( "Global Style Settings" ), Help | Ok | Apply |
+ Cancel, Ok, parent, name, true, true )
+{
+ TQFrame *page = addPage( i18n( "Display Style" ) );
+ TQGridLayout *layout = new TQGridLayout( page, 6, 2, 0, spacingHint() );
+
+ TQLabel *label = new TQLabel( i18n( "First foreground color:" ), page );
+ layout->addWidget( label, 0, 0 );
+
+ mFirstForegroundColor = new KColorButton( page );
+ layout->addWidget( mFirstForegroundColor, 0, 1 );
+ label->setBuddy( mFirstForegroundColor );
+
+ label = new TQLabel( i18n( "Second foreground color:" ), page );
+ layout->addWidget( label, 1, 0 );
+
+ mSecondForegroundColor = new KColorButton( page );
+ layout->addWidget( mSecondForegroundColor, 1, 1 );
+ label->setBuddy( mSecondForegroundColor );
+
+ label = new TQLabel( i18n( "Alarm color:" ), page );
+ layout->addWidget( label, 2, 0 );
+
+ mAlarmColor = new KColorButton( page );
+ layout->addWidget( mAlarmColor, 2, 1 );
+ label->setBuddy( mAlarmColor );
+
+ label = new TQLabel( i18n( "Background color:" ), page );
+ layout->addWidget( label, 3, 0 );
+
+ mBackgroundColor = new KColorButton( page );
+ layout->addWidget( mBackgroundColor, 3, 1 );
+ label->setBuddy( mBackgroundColor );
+
+ label = new TQLabel( i18n( "Font size:" ), page );
+ layout->addWidget( label, 4, 0 );
+
+ mFontSize = new TQSpinBox( 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 TQGridLayout( page, 1, 2, 0, spacingHint() );
+
+ mColorListBox = new TQListBox( page );
+ layout->addWidget( mColorListBox, 0, 0 );
+
+ mEditColorButton = new TQPushButton( i18n( "Change Color..." ), page );
+ mEditColorButton->setEnabled( false );
+ layout->addWidget( mEditColorButton, 0, 1, Qt::AlignTop );
+
+ connect( mColorListBox, TQT_SIGNAL( selectionChanged( TQListBoxItem* ) ),
+ TQT_SLOT( selectionChanged( TQListBoxItem* ) ) );
+ connect( mColorListBox, TQT_SIGNAL( doubleClicked( TQListBoxItem* ) ),
+ TQT_SLOT( editSensorColor() ) );
+ connect( mEditColorButton, TQT_SIGNAL( clicked() ),
+ TQT_SLOT( editSensorColor() ) );
+
+ TDEAcceleratorManager::manage( this );
+}
+
+StyleSettings::~StyleSettings()
+{
+}
+
+void StyleSettings::setFirstForegroundColor( const TQColor &color )
+{
+ mFirstForegroundColor->setColor( color );
+}
+
+TQColor StyleSettings::firstForegroundColor() const
+{
+ return mFirstForegroundColor->color();
+}
+
+void StyleSettings::setSecondForegroundColor( const TQColor &color )
+{
+ mSecondForegroundColor->setColor( color );
+}
+
+TQColor StyleSettings::secondForegroundColor() const
+{
+ return mSecondForegroundColor->color();
+}
+
+void StyleSettings::setAlarmColor( const TQColor &color )
+{
+ mAlarmColor->setColor( color );
+}
+
+TQColor StyleSettings::alarmColor() const
+{
+ return mAlarmColor->color();
+}
+
+void StyleSettings::setBackgroundColor( const TQColor &color )
+{
+ mBackgroundColor->setColor( color );
+}
+
+TQColor 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 TQValueList<TQColor> &list )
+{
+ mColorListBox->clear();
+
+ for ( uint i = 0; i < list.count(); ++i ) {
+ TQPixmap pm( 12, 12 );
+ pm.fill( *list.at( i ) );
+ mColorListBox->insertItem( pm, i18n( "Color %1" ).arg( i ) );
+ }
+}
+
+TQValueList<TQColor> StyleSettings::sensorColors()
+{
+ TQValueList<TQColor> list;
+
+ for ( uint i = 0; i < mColorListBox->count(); ++i )
+ list.append( TQColor( mColorListBox->pixmap( i )->convertToImage().pixel( 1, 1 ) ) );
+
+ return list;
+}
+
+void StyleSettings::editSensorColor()
+{
+ int pos = mColorListBox->currentItem();
+
+ if ( pos < 0 )
+ return;
+
+ TQColor color = mColorListBox->pixmap( pos )->convertToImage().pixel( 1, 1 );
+
+ if ( KColorDialog::getColor( color ) == KColorDialog::Accepted ) {
+ TQPixmap pm( 12, 12 );
+ pm.fill( color );
+ mColorListBox->changeItem( pm, mColorListBox->text( pos ), pos );
+ }
+}
+
+void StyleSettings::selectionChanged( TQListBoxItem *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..c3b3d362c
--- /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 <tqcolor.h>
+
+class KColorButton;
+
+class TQListBoxItem;
+class TQPushButton;
+
+class StyleSettings : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ StyleSettings( TQWidget *parent = 0, const char *name = 0 );
+ ~StyleSettings();
+
+ void setFirstForegroundColor( const TQColor &color );
+ TQColor firstForegroundColor() const;
+
+ void setSecondForegroundColor( const TQColor &color );
+ TQColor secondForegroundColor() const;
+
+ void setAlarmColor( const TQColor &color );
+ TQColor alarmColor() const;
+
+ void setBackgroundColor( const TQColor &color );
+ TQColor backgroundColor() const;
+
+ void setFontSize( uint size );
+ uint fontSize() const;
+
+ void setSensorColors( const TQValueList<TQColor> &list );
+ TQValueList<TQColor> sensorColors();
+
+ private slots:
+ void editSensorColor();
+ void selectionChanged( TQListBoxItem* );
+
+ private:
+ KColorButton *mFirstForegroundColor;
+ KColorButton *mSecondForegroundColor;
+ KColorButton *mAlarmColor;
+ KColorButton *mBackgroundColor;
+
+ TQSpinBox *mFontSize;
+
+ TQListBox *mColorListBox;
+ TQPushButton *mEditColorButton;
+};
+
+#endif
diff --git a/ksysguard/gui/ksgrd/TimerSettings.cc b/ksysguard/gui/ksgrd/TimerSettings.cc
new file mode 100644
index 000000000..43e73ab90
--- /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 <tdeaccelmanager.h>
+#include <tdelocale.h>
+
+#include <tqcheckbox.h>
+#include <tqlabel.h>
+#include <tqlayout.h>
+#include <tqspinbox.h>
+#include <tqwhatsthis.h>
+
+#include "TimerSettings.h"
+
+TimerSettings::TimerSettings( TQWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Timer Settings" ), Ok | Cancel,
+ Ok, parent, name, true, true )
+{
+ TQFrame *page = plainPage();
+
+ TQGridLayout *layout = new TQGridLayout( page, 2, 2, 0, spacingHint() );
+
+ mUseGlobalUpdate = new TQCheckBox( i18n( "Use update interval of worksheet" ), page );
+ layout->addMultiCellWidget( mUseGlobalUpdate, 0, 0, 0, 1 );
+
+ mLabel = new TQLabel( i18n( "Update interval:" ), page );
+ layout->addWidget( mLabel, 1, 0 );
+
+ mInterval = new TQSpinBox( 1, 300, 1, page );
+ mInterval->setValue( 2 );
+ mInterval->setSuffix( i18n( " sec" ) );
+ layout->addWidget( mInterval, 1, 1 );
+ mLabel->setBuddy( mInterval );
+ TQWhatsThis::add( mInterval, i18n( "All displays of the sheet are updated at the rate specified here." ) );
+
+ connect( mUseGlobalUpdate, TQT_SIGNAL( toggled( bool ) ),
+ TQT_SLOT( globalUpdateChanged( bool ) ) );
+
+ mUseGlobalUpdate->setChecked( true );
+
+ TDEAcceleratorManager::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..64c49959b
--- /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 TQCheckBox;
+class TQLabel;
+class TQSpinBox;
+
+class KDE_EXPORT TimerSettings : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ TimerSettings( TQWidget *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:
+ TQCheckBox* mUseGlobalUpdate;
+ TQLabel* mLabel;
+ TQSpinBox* mInterval;
+};
+
+#endif