From 145abc15d57fb29701a12e8a14dcb9c1fd72e9be Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 7 Dec 2020 22:58:44 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro --- ksysguard/gui/ksgrd/CMakeLists.txt | 6 +- ksysguard/gui/ksgrd/HostConnector.cc | 217 --------------- ksysguard/gui/ksgrd/HostConnector.cpp | 217 +++++++++++++++ ksysguard/gui/ksgrd/Makefile.am | 16 +- ksysguard/gui/ksgrd/SensorAgent.cc | 260 ------------------ ksysguard/gui/ksgrd/SensorAgent.cpp | 260 ++++++++++++++++++ ksysguard/gui/ksgrd/SensorManager.cc | 437 ------------------------------ ksysguard/gui/ksgrd/SensorManager.cpp | 437 ++++++++++++++++++++++++++++++ ksysguard/gui/ksgrd/SensorShellAgent.cc | 141 ---------- ksysguard/gui/ksgrd/SensorShellAgent.cpp | 141 ++++++++++ ksysguard/gui/ksgrd/SensorSocketAgent.cc | 137 ---------- ksysguard/gui/ksgrd/SensorSocketAgent.cpp | 137 ++++++++++ ksysguard/gui/ksgrd/StyleEngine.cc | 176 ------------ ksysguard/gui/ksgrd/StyleEngine.cpp | 176 ++++++++++++ ksysguard/gui/ksgrd/StyleSettings.cc | 201 -------------- ksysguard/gui/ksgrd/StyleSettings.cpp | 201 ++++++++++++++ ksysguard/gui/ksgrd/TimerSettings.cc | 94 ------- ksysguard/gui/ksgrd/TimerSettings.cpp | 94 +++++++ 18 files changed, 1674 insertions(+), 1674 deletions(-) delete mode 100644 ksysguard/gui/ksgrd/HostConnector.cc create mode 100644 ksysguard/gui/ksgrd/HostConnector.cpp delete mode 100644 ksysguard/gui/ksgrd/SensorAgent.cc create mode 100644 ksysguard/gui/ksgrd/SensorAgent.cpp delete mode 100644 ksysguard/gui/ksgrd/SensorManager.cc create mode 100644 ksysguard/gui/ksgrd/SensorManager.cpp delete mode 100644 ksysguard/gui/ksgrd/SensorShellAgent.cc create mode 100644 ksysguard/gui/ksgrd/SensorShellAgent.cpp delete mode 100644 ksysguard/gui/ksgrd/SensorSocketAgent.cc create mode 100644 ksysguard/gui/ksgrd/SensorSocketAgent.cpp delete mode 100644 ksysguard/gui/ksgrd/StyleEngine.cc create mode 100644 ksysguard/gui/ksgrd/StyleEngine.cpp delete mode 100644 ksysguard/gui/ksgrd/StyleSettings.cc create mode 100644 ksysguard/gui/ksgrd/StyleSettings.cpp delete mode 100644 ksysguard/gui/ksgrd/TimerSettings.cc create mode 100644 ksysguard/gui/ksgrd/TimerSettings.cpp (limited to 'ksysguard/gui/ksgrd') diff --git a/ksysguard/gui/ksgrd/CMakeLists.txt b/ksysguard/gui/ksgrd/CMakeLists.txt index b1ec7c5f8..daf5a0e37 100644 --- a/ksysguard/gui/ksgrd/CMakeLists.txt +++ b/ksysguard/gui/ksgrd/CMakeLists.txt @@ -34,9 +34,9 @@ install( FILES tde_add_library( ksgrd SHARED AUTOMOC SOURCES - HostConnector.cc SensorAgent.cc SensorManager.cc - SensorShellAgent.cc SensorSocketAgent.cc StyleEngine.cc - StyleSettings.cc TimerSettings.cc + HostConnector.cpp SensorAgent.cpp SensorManager.cpp + SensorShellAgent.cpp SensorSocketAgent.cpp StyleEngine.cpp + StyleSettings.cpp TimerSettings.cpp 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 deleted file mode 100644 index b6e85b795..000000000 --- a/ksysguard/gui/ksgrd/HostConnector.cc +++ /dev/null @@ -1,217 +0,0 @@ -/* - KSysGuard, the KDE System Guard - - Copyright (c) 1999, 2000 Chris Schlaeger - - 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 -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#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.cpp b/ksysguard/gui/ksgrd/HostConnector.cpp new file mode 100644 index 000000000..b6e85b795 --- /dev/null +++ b/ksysguard/gui/ksgrd/HostConnector.cpp @@ -0,0 +1,217 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999, 2000 Chris Schlaeger + + 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 +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#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/Makefile.am b/ksysguard/gui/ksgrd/Makefile.am index 52f5bfd01..4eead4247 100644 --- a/ksysguard/gui/ksgrd/Makefile.am +++ b/ksysguard/gui/ksgrd/Makefile.am @@ -9,14 +9,14 @@ 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 + HostConnector.cpp \ + SensorAgent.cpp \ + SensorManager.cpp \ + SensorShellAgent.cpp \ + SensorSocketAgent.cpp \ + StyleEngine.cpp \ + StyleSettings.cpp \ + TimerSettings.cpp ksgrdincludedir = $(includedir)/ksgrd ksgrdinclude_HEADERS = \ diff --git a/ksysguard/gui/ksgrd/SensorAgent.cc b/ksysguard/gui/ksgrd/SensorAgent.cc deleted file mode 100644 index 7f9615985..000000000 --- a/ksysguard/gui/ksgrd/SensorAgent.cc +++ /dev/null @@ -1,260 +0,0 @@ -/* - KSysGuard, the KDE System Guard - - Copyright (c) 1999 - 2001 Chris Schlaeger - - 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 - -#include -#include -#include - -#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.cpp b/ksysguard/gui/ksgrd/SensorAgent.cpp new file mode 100644 index 000000000..7f9615985 --- /dev/null +++ b/ksysguard/gui/ksgrd/SensorAgent.cpp @@ -0,0 +1,260 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999 - 2001 Chris Schlaeger + + 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 + +#include +#include +#include + +#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/SensorManager.cc b/ksysguard/gui/ksgrd/SensorManager.cc deleted file mode 100644 index 237e73b23..000000000 --- a/ksysguard/gui/ksgrd/SensorManager.cc +++ /dev/null @@ -1,437 +0,0 @@ -/* - KSysGuard, the KDE System Guard - - Copyright (c) 1999 - 2001 Chris Schlaeger - - 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 . - Please do not commit any changes without consulting me first. Thanks! - -*/ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#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( "active", new TQString( i18n( "Active Memory" ) ) ); - mDict.insert( "inactive", new TQString( i18n( "Inactive Memory" ) ) ); - mDict.insert( "wired", new TQString( i18n( "Wired Memory" ) ) ); - mDict.insert( "execpages", new TQString( i18n( "Exec Pages" ) ) ); - mDict.insert( "filepages", new TQString( i18n( "File Pages" ) ) ); - 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 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 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 it( mAgents ); - - for ( ; it.current(); ++it) - it.current()->disconnectClient( client ); -} - -#include "SensorManager.moc" diff --git a/ksysguard/gui/ksgrd/SensorManager.cpp b/ksysguard/gui/ksgrd/SensorManager.cpp new file mode 100644 index 000000000..237e73b23 --- /dev/null +++ b/ksysguard/gui/ksgrd/SensorManager.cpp @@ -0,0 +1,437 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999 - 2001 Chris Schlaeger + + 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 . + Please do not commit any changes without consulting me first. Thanks! + +*/ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#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( "active", new TQString( i18n( "Active Memory" ) ) ); + mDict.insert( "inactive", new TQString( i18n( "Inactive Memory" ) ) ); + mDict.insert( "wired", new TQString( i18n( "Wired Memory" ) ) ); + mDict.insert( "execpages", new TQString( i18n( "Exec Pages" ) ) ); + mDict.insert( "filepages", new TQString( i18n( "File Pages" ) ) ); + 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 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 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 it( mAgents ); + + for ( ; it.current(); ++it) + it.current()->disconnectClient( client ); +} + +#include "SensorManager.moc" diff --git a/ksysguard/gui/ksgrd/SensorShellAgent.cc b/ksysguard/gui/ksgrd/SensorShellAgent.cc deleted file mode 100644 index 7e137ad56..000000000 --- a/ksysguard/gui/ksgrd/SensorShellAgent.cc +++ /dev/null @@ -1,141 +0,0 @@ -/* - KSysGuard, the KDE System Guard - - Copyright (c) 1999 - 2001 Chris Schlaeger - - 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 - -#include -#include -#include - -#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.cpp b/ksysguard/gui/ksgrd/SensorShellAgent.cpp new file mode 100644 index 000000000..7e137ad56 --- /dev/null +++ b/ksysguard/gui/ksgrd/SensorShellAgent.cpp @@ -0,0 +1,141 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999 - 2001 Chris Schlaeger + + 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 + +#include +#include +#include + +#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/SensorSocketAgent.cc b/ksysguard/gui/ksgrd/SensorSocketAgent.cc deleted file mode 100644 index 30c0cc7e9..000000000 --- a/ksysguard/gui/ksgrd/SensorSocketAgent.cc +++ /dev/null @@ -1,137 +0,0 @@ -/* - KSysGuard, the KDE System Guard - - Copyright (c) 1999 - 2001 Chris Schlaeger - - 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 - -#include -#include -#include - -#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.cpp b/ksysguard/gui/ksgrd/SensorSocketAgent.cpp new file mode 100644 index 000000000..30c0cc7e9 --- /dev/null +++ b/ksysguard/gui/ksgrd/SensorSocketAgent.cpp @@ -0,0 +1,137 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999 - 2001 Chris Schlaeger + + 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 + +#include +#include +#include + +#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/StyleEngine.cc b/ksysguard/gui/ksgrd/StyleEngine.cc deleted file mode 100644 index ce3e3bd6b..000000000 --- a/ksysguard/gui/ksgrd/StyleEngine.cc +++ /dev/null @@ -1,176 +0,0 @@ -/* - KSysGuard, the KDE System Guard - - Copyright (c) 1999 - 2001 Chris Schlaeger - - 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 . - Please do not commit any changes without consulting me first. Thanks! - -*/ - -#include -#include -#include - -#include -#include - -#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::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.cpp b/ksysguard/gui/ksgrd/StyleEngine.cpp new file mode 100644 index 000000000..ce3e3bd6b --- /dev/null +++ b/ksysguard/gui/ksgrd/StyleEngine.cpp @@ -0,0 +1,176 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999 - 2001 Chris Schlaeger + + 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 . + Please do not commit any changes without consulting me first. Thanks! + +*/ + +#include +#include +#include + +#include +#include + +#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::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/StyleSettings.cc b/ksysguard/gui/ksgrd/StyleSettings.cc deleted file mode 100644 index b84d3e407..000000000 --- a/ksysguard/gui/ksgrd/StyleSettings.cc +++ /dev/null @@ -1,201 +0,0 @@ -/* - KSysGuard, the KDE System Guard - - Copyright (c) 1999 - 2001 Chris Schlaeger - - 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 . - Please do not commit any changes without consulting me first. Thanks! - -*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#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 &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 StyleSettings::sensorColors() -{ - TQValueList 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.cpp b/ksysguard/gui/ksgrd/StyleSettings.cpp new file mode 100644 index 000000000..b84d3e407 --- /dev/null +++ b/ksysguard/gui/ksgrd/StyleSettings.cpp @@ -0,0 +1,201 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 1999 - 2001 Chris Schlaeger + + 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 . + Please do not commit any changes without consulting me first. Thanks! + +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#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 &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 StyleSettings::sensorColors() +{ + TQValueList 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/TimerSettings.cc b/ksysguard/gui/ksgrd/TimerSettings.cc deleted file mode 100644 index 43e73ab90..000000000 --- a/ksysguard/gui/ksgrd/TimerSettings.cc +++ /dev/null @@ -1,94 +0,0 @@ -/* - KSysGuard, the KDE System Guard - - Copyright (c) 2003 Tobias Koenig - - 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 . - Please do not commit any changes without consulting me first. Thanks! - -*/ - -#include -#include - -#include -#include -#include -#include -#include - -#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.cpp b/ksysguard/gui/ksgrd/TimerSettings.cpp new file mode 100644 index 000000000..43e73ab90 --- /dev/null +++ b/ksysguard/gui/ksgrd/TimerSettings.cpp @@ -0,0 +1,94 @@ +/* + KSysGuard, the KDE System Guard + + Copyright (c) 2003 Tobias Koenig + + 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 . + Please do not commit any changes without consulting me first. Thanks! + +*/ + +#include +#include + +#include +#include +#include +#include +#include + +#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" -- cgit v1.2.1