Diffstat (limited to 'noncore/settings/networksettings2/networksettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings.cpp | 277 |
1 files changed, 161 insertions, 116 deletions
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index ce0eabc..a0d4c7c 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp @@ -1,10 +1,14 @@ #include <stdio.h> #include <unistd.h> #include <errno.h> +#include <opie2/odebug.h> +#include <opie2/oledbox.h> + #include <qpe/qpeapplication.h> #include <qlistbox.h> +#include <qlayout.h> #include <qgroupbox.h> #include <qtimer.h> #include <qlistbox.h> #include <qmessagebox.h> @@ -14,9 +18,8 @@ #include <qpe/qpeapplication.h> #include <qtoolbutton.h> #include <qevent.h> -#include <asdevice.h> #include "networksettings.h" #include "netnode.h" #include "editconnection.h" @@ -30,15 +33,26 @@ NetworkSettings::NetworkSettings( QWidget *parent, // set pixmaps Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); - Enable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); - Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); - Disconnect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); + Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); + Up_TB->setPixmap( NSResources->getPixmap( "more" ) ); + Down_TB->setPixmap( NSResources->getPixmap( "less" ) ); + + QVBoxLayout* V = new QVBoxLayout( LED_Frm ); + QHBoxLayout * H = new QHBoxLayout( 0 ); + V->addStretch(1); + V->addLayout( H ); + Leds[0] = new OLedBox( red, LED_Frm ); + H->addWidget( Leds[0], 0, Qt::AlignVCenter ); + Leds[1] = new OLedBox( red, LED_Frm ); + H->addWidget( Leds[1], 0, Qt::AlignVCenter ); + Leds[2] = new OLedBox( red, LED_Frm ); + H->addWidget( Leds[2], 0, Qt::AlignVCenter ); + V->addStretch(1); - On_TB->setPixmap( NSResources->getPixmap( "off" ) ); SLOT_ToProfile(); // populate main Listbox @@ -71,9 +85,17 @@ NetworkSettings::NetworkSettings( QWidget *parent, QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); } connect( &(NSResources->system()), - SIGNAL( lineFromCommand(const QString &) ), + SIGNAL( stdoutLine(const QString &) ), + this, SLOT( SLOT_CmdMessage(const QString &) ) ); + + connect( &(NSResources->system()), + SIGNAL( stderrLine(const QString &) ), + this, SLOT( SLOT_CmdMessage(const QString &) ) ); + + connect( &(NSResources->system()), + SIGNAL( processEvent(const QString &) ), this, SLOT( SLOT_CmdMessage(const QString &) ) ); UpdateTimer->start( 5000 ); connect( UpdateTimer, SIGNAL( timeout() ), @@ -86,18 +108,23 @@ NetworkSettings::NetworkSettings( QWidget *parent, NetworkSettings::~NetworkSettings() { QString S; - if( isModified() ) { + owarn << "Dispose NS" << oendl; + if( NSD.isModified() ) { + owarn << "Modified" << oendl; S = NSD.saveSettings(); if( ! S.isEmpty() ) { + S.insert( 0, "<p>" ); + S.append( "</p>" ); // problem saving QMessageBox::warning( 0, tr( "Saving setup" ), S ); } SLOT_GenerateConfig(); + NSD.setModified( 0 ); } } @@ -166,16 +193,15 @@ void NetworkSettings::SLOT_DeleteNode( void ) { tr( "Remove selected profile ?" ), 1, 0 ) == 1 ) { NSResources->removeConnection( LBI->text() ); delete LBI; - setModified( 1 ); + NSD.setModified( 1 ); } } void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { QString OldName = ""; - printf( "------------------ Edit NOde\n" ); EditConnection EC( this ); if( LBI ) { NodeCollection * NC = NSResources->findConnection( LBI->text() ); @@ -195,9 +221,8 @@ void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { if( EC.exec() == QDialog::Accepted ) { // toplevel item -> store NodeCollection * NC = EC.connection(); if( NC->isModified() ) { - setModified( 1 ); if( LBI ) { if( NC->name() != OldName ) { // find if new name is free NodeCollection * LCN = NSResources->findConnection( @@ -248,64 +273,57 @@ void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); - // is button possible - bool EnabledPossible, OnPossible, ConnectPossible; - // is button On or Off - bool DisabledOn, OnOn, ConnectOn; + if( NC->description().isEmpty() ) { + Description_LBL->setText( tr( "<<No description>>" ) ); + } else { + Description_LBL->setText( NC->description() ); + } + + Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); - EnabledPossible = OnPossible = ConnectPossible = 1; - DisabledOn = 1; - OnOn = ConnectOn = 0; + bool FrmActive = 1; + bool IsEnabled = 1; + int leds = 0; + owarn << "State " << NC->state() << oendl; switch( NC->state() ) { - case Unknown : - // cannot occur here + case Disabled : // no further work + IsEnabled = 0; + FrmActive = 0; + owarn << "LEds " << leds << oendl; break; + case Unknown : case Unchecked : case Unavailable : - // cannot do anything but recheck - EnabledPossible = OnPossible = ConnectPossible = 0; - break; - case Disabled : - OnPossible = ConnectPossible = 0; + FrmActive = 0; break; case Off : - DisabledOn = 0; + leds = 1; break; case Available : - OnOn = 1; - Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); - DisabledOn = 0; + leds = 2; break; case IsUp : - OnOn = ConnectOn = 1; - Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); - DisabledOn = 0; + leds = 3; break; } - if( ! OnOn ) { - Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); - } - - // set button state - Enable_TB->setEnabled( EnabledPossible ); - On_TB->setEnabled( OnPossible ); - Connect_TB->setEnabled( ConnectPossible ); - - Enable_TB->setOn( DisabledOn ); - On_TB->setOn( OnOn ); - Connect_TB->setOn( ConnectOn ); + Disable_TB->setOn( ! IsEnabled ); + LED_Frm->setEnabled( FrmActive ); - if( NC->description().isEmpty() ) { - Description_LBL->setText( tr( "<<No description>>" ) ); - } else { - Description_LBL->setText( NC->description() ); + for( int i = 0 ; i < leds; i ++ ) { + Leds[i]->setColor( red ); + Leds[i]->setOn( true ); + } + for( int i = leds ; i < 3; i ++ ) { + Leds[i]->setColor( red ); + Leds[i]->setOn( false ); } - Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); + Up_TB->setEnabled( leds < 3 && leds != 0 ); + Down_TB->setEnabled( leds > 0 ); } void NetworkSettings::SLOT_CheckState( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); @@ -320,138 +338,165 @@ void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { } } void NetworkSettings::SLOT_GenerateConfig( void ) { - NSD.regenerate(); + QString S = NSD.generateSettings(); + if( ! S.isEmpty() ) { + S.insert( 0, "<p>" ); + S.append( "</p>" ); + QMessageBox::warning( + 0, + tr( "Generate config" ), + S); + } } -void NetworkSettings::SLOT_Enable( void ) { +void NetworkSettings::SLOT_Disable( bool T ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); QString Msg; + if ( ! LBI ) return; - NodeCollection * NC = - NSResources->findConnection( LBI->text() ); - - bool rv; - switch( NC->state() ) { - case Disabled : - Msg = tr( "Cannot enable profile" ); - rv = NC->setState( Enable ); - break; - default : - Msg = tr( "Cannot disable profile" ); - rv = NC->setState( Disable ); - break; - } + NodeCollection * NC = NSResources->findConnection( LBI->text() ); - if( ! rv ) { + owarn << "Prepare to disable" << oendl; + Msg = NC->setState( (T) ? Disable : Enable ); + if( ! Msg.isEmpty() ) { + Msg.insert( 0, "<p>" ); + Msg.append( "</p>" ); QMessageBox::warning( 0, tr( "Activating profile" ), Msg ); return; } + + // reload new state + NC->state( true ); updateProfileState( LBI ); } -void NetworkSettings::SLOT_On( void ) { +void NetworkSettings::SLOT_Up( void ) { + // bring more up + QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); + QString Msg; + int led = -1; if ( ! LBI ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); - bool rv; switch( NC->state() ) { - case Off : - // activate interface - rv = NC->setState( Activate ); + case Disabled : // cannot modify this state + case Unknown : // cannot modify this state + case Unchecked : // cannot modify this state + case Unavailable : // cannot modify this state + case IsUp : // highest UP state + return; + case Off : // -> activate + led = 1; + Down_TB->setEnabled( true ); + Log(( "Activate interface %s\n", NC->name().latin1() )); + Msg = NC->setState( Activate ); break; - case Available : // deactivate - case IsUp : // deactivate (will also bring down if needed) - rv = NC->setState( Deactivate ); + case Available : // -> up + led = 2; + Log(( "Bring up interface %s\n", NC->name().latin1() )); + Msg = NC->setState( Up ); + if( Msg.isEmpty() ) { + Up_TB->setEnabled( false ); + } break; - default : - // others no change - return; - } + } - if( ! rv ) { + if( ! Msg.isEmpty() ) { + Msg.insert( 0, "<p>" ); + Msg.append( "</p>" ); QMessageBox::warning( 0, - tr( "Activating profile" ), - tr( "Cannot enable profile" ) ); + tr( "Increase availability" ), + Msg ); return; } + updateProfileState( LBI ); + + // set color of led we should change + if( led > 0 ) { + Leds[led]->setColor( blue ); + Leds[led]->setOn( true ); + } + } -void NetworkSettings::SLOT_Connect( void ) { +void NetworkSettings::SLOT_Down( void ) { + // bring more down + QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); + int led = -1; + QString Msg; if ( ! LBI ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); - bool rv = 1 ; switch( NC->state() ) { - case IsUp : - // down interface - rv = NC->setState( Down ); - break; - case Available : - // up interface - rv = NC->setState( Up ); + case Disabled : // cannot modify this state + case Unknown : // cannot modify this state + case Unchecked : // cannot modify this state + case Unavailable : // cannot modify this state + case Off : // highest DOWN state break; - case Off : - // activate and bring up - rv = ( NC->setState( Activate ) && - NC->setState( Up ) ); + case Available : // -> down + led = 0; + Log(( "Deactivate interface %s\n", NC->name().latin1() )); + Msg = NC->setState( Deactivate ); + Down_TB->setEnabled( false ); break; - default : - // others no change + case IsUp : // highest UP state + led = 1; + Up_TB->setEnabled( true ); + Log(( "Bring down interface %s\n", NC->name().latin1() )); + Msg = NC->setState( Down, 1 ); + if( Msg.isEmpty() ) { + // remove 'up' file to make sure + unlink ( QString().sprintf( "/tmp/Profile-%d.up", NC->number() ).latin1() );; + } break; - } + } - if( ! rv ) { + if( ! Msg.isEmpty() ) { + Msg.insert( 0, "<p>" ); + Msg.append( "</p>" ); QMessageBox::warning( 0, - tr( "Activating profile" ), - tr( "Cannot enable profile" ) ); - } - - // we do not update the GUI but wait for the REAL upping of the device -} - -void NetworkSettings::SLOT_Disconnect( void ) { - QString S; - QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); - - if ( ! LBI ) + tr( "Decrease availability" ), + Msg ); return; + } - NodeCollection * NC = - NSResources->findConnection( LBI->text() ); + updateProfileState( LBI ); - Log(( "Force interface %s down\n", NC->name().latin1() )); - NC->setState( Down, 1 ); - // remove 'up' file to make sure - S.sprintf( "/tmp/Profile-%d.up", NC->number() ); - unlink( S.latin1() ); + // set color of led we should change + if( led >= 0 ) { + Leds[led]->setColor( blue ); + } } void NetworkSettings::SLOT_ToMessages( void ) { + Profiles_LB->hide(); Profile_GB->hide(); Messages_GB->show(); } void NetworkSettings::SLOT_ToProfile( void ) { + Profiles_LB->show(); Profile_GB->show(); Messages_GB->hide(); } |