You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
354 lines
11 KiB
354 lines
11 KiB
15 years ago
|
/*
|
||
|
KSysGuard, the KDE System Guard
|
||
|
|
||
|
Copyright (c) 1999, 2000, 2001 Chris Schlaeger <cs@kde.org>
|
||
|
|
||
|
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 <cs@kde.org>.
|
||
|
Please do not commit any changes without consulting me first. Thanks!
|
||
|
|
||
|
*/
|
||
|
|
||
14 years ago
|
#include <tqcheckbox.h>
|
||
|
#include <tqdom.h>
|
||
|
#include <tqlineedit.h>
|
||
|
#include <tqlistview.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqspinbox.h>
|
||
|
#include <tqtooltip.h>
|
||
15 years ago
|
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <knumvalidator.h>
|
||
|
#include <ksgrd/SensorManager.h>
|
||
|
#include <ksgrd/StyleEngine.h>
|
||
|
|
||
|
#include "BarGraph.h"
|
||
|
#include "DancingBarsSettings.h"
|
||
|
|
||
|
#include "DancingBars.h"
|
||
|
|
||
14 years ago
|
DancingBars::DancingBars( TQWidget *parent, const char *name, const TQString &title,
|
||
15 years ago
|
int, int, bool noFrame_, bool isApplet )
|
||
|
: KSGRD::SensorDisplay( parent, name, title, noFrame_, isApplet )
|
||
|
{
|
||
|
mBars = 0;
|
||
14 years ago
|
mFlags = TQBitArray(100);
|
||
15 years ago
|
mFlags.fill( false );
|
||
|
|
||
|
if ( noFrame() )
|
||
|
mPlotter = new BarGraph( this );
|
||
|
else
|
||
|
mPlotter = new BarGraph( frame() );
|
||
|
|
||
13 years ago
|
setMinimumSize( sizeHint() );
|
||
15 years ago
|
|
||
|
/* All RMB clicks to the mPlotter widget will be handled by
|
||
|
* SensorDisplay::eventFilter. */
|
||
|
mPlotter->installEventFilter( this );
|
||
|
|
||
|
setPlotterWidget( mPlotter );
|
||
|
|
||
|
setModified( false );
|
||
|
}
|
||
|
|
||
|
DancingBars::~DancingBars()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void DancingBars::configureSettings()
|
||
|
{
|
||
|
mSettingsDialog = new DancingBarsSettings( this );
|
||
|
|
||
|
mSettingsDialog->setTitle( title() );
|
||
|
mSettingsDialog->setMinValue( mPlotter->getMin() );
|
||
|
mSettingsDialog->setMaxValue( mPlotter->getMax() );
|
||
|
|
||
|
double l, u;
|
||
|
bool la, ua;
|
||
|
mPlotter->getLimits( l, la, u, ua );
|
||
|
|
||
|
mSettingsDialog->setUseUpperLimit( ua );
|
||
|
mSettingsDialog->setUpperLimit( u );
|
||
|
|
||
|
mSettingsDialog->setUseLowerLimit( la );
|
||
|
mSettingsDialog->setLowerLimit( l );
|
||
|
|
||
|
mSettingsDialog->setForegroundColor( mPlotter->normalColor );
|
||
|
mSettingsDialog->setAlarmColor( mPlotter->alarmColor );
|
||
|
mSettingsDialog->setBackgroundColor( mPlotter->backgroundColor );
|
||
|
mSettingsDialog->setFontSize( mPlotter->fontSize );
|
||
|
|
||
14 years ago
|
TQValueList< TQStringList > list;
|
||
15 years ago
|
for ( uint i = mBars - 1; i < mBars; i-- ) {
|
||
14 years ago
|
TQStringList entry;
|
||
13 years ago
|
entry << sensors().at( i )->hostName();
|
||
|
entry << KSGRD::SensorMgr->translateSensor( sensors().at( i )->name() );
|
||
15 years ago
|
entry << mPlotter->footers[ i ];
|
||
13 years ago
|
entry << KSGRD::SensorMgr->translateUnit( sensors().at( i )->unit() );
|
||
|
entry << ( sensors().at( i )->isOk() ? i18n( "OK" ) : i18n( "Error" ) );
|
||
15 years ago
|
|
||
|
list.append( entry );
|
||
|
}
|
||
|
mSettingsDialog->setSensors( list );
|
||
|
|
||
14 years ago
|
connect( mSettingsDialog, TQT_SIGNAL( applyClicked() ), TQT_SLOT( applySettings() ) );
|
||
15 years ago
|
|
||
|
if ( mSettingsDialog->exec() )
|
||
|
applySettings();
|
||
|
|
||
|
delete mSettingsDialog;
|
||
|
mSettingsDialog = 0;
|
||
|
}
|
||
|
|
||
|
void DancingBars::applySettings()
|
||
|
{
|
||
|
setTitle( mSettingsDialog->title() );
|
||
|
mPlotter->changeRange( mSettingsDialog->minValue(), mSettingsDialog->maxValue() );
|
||
|
mPlotter->setLimits( mSettingsDialog->useLowerLimit() ?
|
||
|
mSettingsDialog->lowerLimit() : 0,
|
||
|
mSettingsDialog->useLowerLimit(),
|
||
|
mSettingsDialog->useUpperLimit() ?
|
||
|
mSettingsDialog->upperLimit() : 0,
|
||
|
mSettingsDialog->useUpperLimit() );
|
||
|
|
||
|
mPlotter->normalColor = mSettingsDialog->foregroundColor();
|
||
|
mPlotter->alarmColor = mSettingsDialog->alarmColor();
|
||
|
mPlotter->backgroundColor = mSettingsDialog->backgroundColor();
|
||
|
mPlotter->fontSize = mSettingsDialog->fontSize();
|
||
|
|
||
14 years ago
|
TQValueList< TQStringList > list = mSettingsDialog->sensors();
|
||
|
TQValueList< TQStringList >::Iterator it;
|
||
15 years ago
|
|
||
|
for ( uint i = 0; i < sensors().count(); i++ ) {
|
||
|
bool found = false;
|
||
|
for ( it = list.begin(); it != list.end(); ++it ) {
|
||
13 years ago
|
if ( (*it)[ 0 ] == sensors().at( i )->hostName() &&
|
||
|
(*it)[ 1 ] == KSGRD::SensorMgr->translateSensor( sensors().at( i )->name() ) ) {
|
||
15 years ago
|
mPlotter->footers[ i ] = (*it)[ 2 ];
|
||
|
found = true;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ( !found )
|
||
|
removeSensor( i );
|
||
|
}
|
||
|
|
||
13 years ago
|
repaint();
|
||
15 years ago
|
setModified( true );
|
||
|
}
|
||
|
|
||
|
void DancingBars::applyStyle()
|
||
|
{
|
||
|
mPlotter->normalColor = KSGRD::Style->firstForegroundColor();
|
||
|
mPlotter->alarmColor = KSGRD::Style->alarmColor();
|
||
|
mPlotter->backgroundColor = KSGRD::Style->backgroundColor();
|
||
|
mPlotter->fontSize = KSGRD::Style->fontSize();
|
||
|
|
||
13 years ago
|
repaint();
|
||
15 years ago
|
setModified( true );
|
||
|
}
|
||
|
|
||
14 years ago
|
bool DancingBars::addSensor( const TQString &hostName, const TQString &name,
|
||
|
const TQString &type, const TQString &title )
|
||
15 years ago
|
{
|
||
|
if ( type != "integer" && type != "float" )
|
||
|
return false;
|
||
|
|
||
|
if ( mBars >= 32 )
|
||
|
return false;
|
||
|
|
||
|
if ( !mPlotter->addBar( title ) )
|
||
|
return false;
|
||
|
|
||
|
registerSensor( new KSGRD::SensorProperties( hostName, name, type, title ) );
|
||
|
|
||
|
/* To differentiate between answers from value requests and info
|
||
|
* requests we add 100 to the beam index for info requests. */
|
||
|
sendRequest( hostName, name + "?", mBars + 100 );
|
||
|
++mBars;
|
||
|
mSampleBuffer.resize( mBars );
|
||
|
|
||
14 years ago
|
TQString tooltip;
|
||
15 years ago
|
for ( uint i = 0; i < mBars; ++i ) {
|
||
14 years ago
|
tooltip += TQString( "%1%2:%3" ).arg( i != 0 ? "\n" : "" )
|
||
13 years ago
|
.arg( sensors().at( i )->hostName() )
|
||
|
.arg( sensors().at( i )->name() );
|
||
15 years ago
|
}
|
||
14 years ago
|
TQToolTip::remove( mPlotter );
|
||
|
TQToolTip::add( mPlotter, tooltip );
|
||
15 years ago
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool DancingBars::removeSensor( uint pos )
|
||
|
{
|
||
|
if ( pos >= mBars ) {
|
||
|
kdDebug(1215) << "DancingBars::removeSensor: idx out of range ("
|
||
|
<< pos << ")" << endl;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
mPlotter->removeBar( pos );
|
||
|
mBars--;
|
||
|
KSGRD::SensorDisplay::removeSensor( pos );
|
||
|
|
||
14 years ago
|
TQString tooltip;
|
||
15 years ago
|
for ( uint i = 0; i < mBars; ++i ) {
|
||
14 years ago
|
tooltip += TQString( "%1%2:%3" ).arg( i != 0 ? "\n" : "" )
|
||
13 years ago
|
.arg( sensors().at( i )->hostName() )
|
||
|
.arg( sensors().at( i )->name() );
|
||
15 years ago
|
}
|
||
14 years ago
|
TQToolTip::remove( mPlotter );
|
||
|
TQToolTip::add( mPlotter, tooltip );
|
||
15 years ago
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
void DancingBars::updateSamples( const TQMemArray<double> &samples )
|
||
15 years ago
|
{
|
||
|
mPlotter->updateSamples( samples );
|
||
|
}
|
||
|
|
||
14 years ago
|
void DancingBars::resizeEvent( TQResizeEvent* )
|
||
15 years ago
|
{
|
||
|
if ( noFrame() )
|
||
|
mPlotter->setGeometry( 0, 0, width(), height() );
|
||
|
else
|
||
|
frame()->setGeometry( 0, 0, width(), height() );
|
||
|
}
|
||
|
|
||
13 years ago
|
TQSize DancingBars::sizeHint()
|
||
15 years ago
|
{
|
||
|
if ( noFrame() )
|
||
13 years ago
|
return ( mPlotter->sizeHint() );
|
||
15 years ago
|
else
|
||
13 years ago
|
return ( frame()->sizeHint() );
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void DancingBars::answerReceived( int id, const TQString &answer )
|
||
15 years ago
|
{
|
||
|
/* We received something, so the sensor is probably ok. */
|
||
|
sensorError( id, false );
|
||
|
|
||
|
if ( id < 100 ) {
|
||
|
mSampleBuffer[ id ] = answer.toDouble();
|
||
|
if ( mFlags.testBit( id ) == true ) {
|
||
|
kdDebug(1215) << "ERROR: DancingBars lost sample (" << mFlags
|
||
|
<< ", " << mBars << ")" << endl;
|
||
|
sensorError( id, true );
|
||
|
}
|
||
|
mFlags.setBit( id, true );
|
||
|
|
||
|
bool allBitsAvailable = true;
|
||
|
for ( uint i = 0; i < mBars; ++i )
|
||
|
allBitsAvailable &= mFlags.testBit( i );
|
||
|
|
||
|
if ( allBitsAvailable ) {
|
||
|
mPlotter->updateSamples( mSampleBuffer );
|
||
|
mFlags.fill( false );
|
||
|
}
|
||
|
} else if ( id >= 100 ) {
|
||
|
KSGRD::SensorIntegerInfo info( answer );
|
||
|
if ( id == 100 )
|
||
|
if ( mPlotter->getMin() == 0.0 && mPlotter->getMax() == 0.0 ) {
|
||
|
/* We only use this information from the sensor when the
|
||
|
* display is still using the default values. If the
|
||
|
* sensor has been restored we don't touch the already set
|
||
|
* values. */
|
||
|
mPlotter->changeRange( info.min(), info.max() );
|
||
|
}
|
||
|
|
||
13 years ago
|
sensors().at( id - 100 )->setUnit( info.unit() );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
bool DancingBars::restoreSettings( TQDomElement &element )
|
||
15 years ago
|
{
|
||
|
SensorDisplay::restoreSettings( element );
|
||
|
|
||
|
mPlotter->changeRange( element.attribute( "min", "0" ).toDouble(),
|
||
|
element.attribute( "max", "0" ).toDouble() );
|
||
|
|
||
|
mPlotter->setLimits( element.attribute( "lowlimit", "0" ).toDouble(),
|
||
|
element.attribute( "lowlimitactive", "0" ).toInt(),
|
||
|
element.attribute( "uplimit", "0" ).toDouble(),
|
||
|
element.attribute( "uplimitactive", "0" ).toInt() );
|
||
|
|
||
|
mPlotter->normalColor = restoreColor( element, "normalColor",
|
||
|
KSGRD::Style->firstForegroundColor() );
|
||
|
mPlotter->alarmColor = restoreColor( element, "alarmColor",
|
||
|
KSGRD::Style->alarmColor() );
|
||
|
mPlotter->backgroundColor = restoreColor( element, "backgroundColor",
|
||
|
KSGRD::Style->backgroundColor() );
|
||
14 years ago
|
mPlotter->fontSize = element.attribute( "fontSize", TQString( "%1" ).arg(
|
||
15 years ago
|
KSGRD::Style->fontSize() ) ).toInt();
|
||
|
|
||
14 years ago
|
TQDomNodeList dnList = element.elementsByTagName( "beam" );
|
||
15 years ago
|
for ( uint i = 0; i < dnList.count(); ++i ) {
|
||
14 years ago
|
TQDomElement el = dnList.item( i ).toElement();
|
||
15 years ago
|
addSensor( el.attribute( "hostName" ), el.attribute( "sensorName" ),
|
||
|
( el.attribute( "sensorType" ).isEmpty() ? "integer" :
|
||
|
el.attribute( "sensorType" ) ), el.attribute( "sensorDescr" ) );
|
||
|
}
|
||
|
|
||
|
setModified( false );
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool DancingBars::saveSettings( TQDomDocument &doc, TQDomElement &element,
|
||
15 years ago
|
bool save )
|
||
|
{
|
||
|
element.setAttribute( "min", mPlotter->getMin() );
|
||
|
element.setAttribute( "max", mPlotter->getMax() );
|
||
|
double l, u;
|
||
|
bool la, ua;
|
||
|
mPlotter->getLimits( l, la, u, ua );
|
||
|
element.setAttribute( "lowlimit", l );
|
||
|
element.setAttribute( "lowlimitactive", la );
|
||
|
element.setAttribute( "uplimit", u );
|
||
|
element.setAttribute( "uplimitactive", ua );
|
||
|
|
||
|
saveColor( element, "normalColor", mPlotter->normalColor );
|
||
|
saveColor( element, "alarmColor", mPlotter->alarmColor );
|
||
|
saveColor( element, "backgroundColor", mPlotter->backgroundColor );
|
||
|
element.setAttribute( "fontSize", mPlotter->fontSize );
|
||
|
|
||
|
for ( uint i = 0; i < mBars; ++i ) {
|
||
14 years ago
|
TQDomElement beam = doc.createElement( "beam" );
|
||
15 years ago
|
element.appendChild( beam );
|
||
13 years ago
|
beam.setAttribute( "hostName", sensors().at( i )->hostName() );
|
||
|
beam.setAttribute( "sensorName", sensors().at( i )->name() );
|
||
|
beam.setAttribute( "sensorType", sensors().at( i )->type() );
|
||
15 years ago
|
beam.setAttribute( "sensorDescr", mPlotter->footers[ i ] );
|
||
|
}
|
||
|
|
||
|
SensorDisplay::saveSettings( doc, element );
|
||
|
|
||
|
if ( save )
|
||
|
setModified( false );
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool DancingBars::hasSettingsDialog() const
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
#include "DancingBars.moc"
|