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,469 +1,514 @@ #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> #include <qlabel.h> #include <qiconview.h> #include <qtimer.h> #include <qpe/qpeapplication.h> #include <qtoolbutton.h> #include <qevent.h> -#include <asdevice.h> #include "networksettings.h" #include "netnode.h" #include "editconnection.h" NetworkSettings::NetworkSettings( QWidget *parent, const char *name, WFlags fl ) : NetworkSettingsGUI(parent,name,fl), NSD() { UpdateTimer = new QTimer( this ); // 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 Profiles_LB->clear(); QPEApplication::setStylusOperation( Profiles_LB->viewport(), QPEApplication::RightOnHold ); connect( Profiles_LB, SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), this, SLOT(SLOT_EditNode(QListBoxItem*)) ); { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); } } if( Profiles_LB->count() ) { Profiles_LB->setSelected( 0, TRUE ); } // if no profiles -> auto popup editing if( NSResources->connections().count() == 0 ) { 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() ), this, SLOT( SLOT_RefreshStates() ) ); /* Add QCopChannel */ connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); } 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 ); } } void NetworkSettings::SLOT_CmdMessage( const QString & S ) { Messages_LB->insertItem( S ); Messages_LB->setCurrentItem( Messages_LB->count()-1 ); Messages_LB->ensureCurrentVisible(); } void NetworkSettings::SLOT_RefreshStates( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember if( LBI ) { NodeCollection * NC; NSResources->system().probeInterfaces(); // update current selection only NC = NSResources->findConnection( LBI->text() ); if( NC ) { State_t OldS = NC->state(); State_t NewS = NC->state(1); if( OldS != NewS ) { updateProfileState( LBI ); } } } /* -> LATER !! bool is; NodeCollection * NC; for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { NC = NSResources->findConnection( Profiles_LB->text(i) ); if( NC ) { State_t OldS = NC->state(); State_t NewS = NC->state(1); if( OldS != NewS ) { is = Profiles_LB->isSelected(i); Profiles_LB->changeItem( NC->statePixmap(NewS), NC->name(), i ); if( is ) { Profiles_LB->setSelected( i, TRUE ); } } } } if( ci >= 0 ) Profiles_LB->setCurrentItem( ci ); */ } void NetworkSettings::SLOT_AddNode( void ) { SLOT_EditNode( 0 ); } void NetworkSettings::SLOT_DeleteNode( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); if ( ! LBI ) return; if( QMessageBox::warning( 0, tr( "Removing profile" ), 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() ); if( ! NC ) { return; } OldName = NC->name(); EC.setConnection( NC ); } EC.showMaximized(); // disable refresh timer UpdateTimer->stop(); // we need to retry while( 1 ) { 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( NC->name() ); if( LCN ) { QMessageBox::warning( 0, tr( "In System Config" ), tr( "Name %1 already exists" ).arg(NC->name()) ); continue; // restart exec } // else new name // new name -> remove item NSResources->removeConnection( OldName ); NSResources->addConnection( NC ); } // else not changed // must add it here since change will trigger event Profiles_LB->changeItem( NC->devicePixmap(), NC->name(), Profiles_LB->index( LBI ) ); } else { // new item int ci = Profiles_LB->count(); NSResources->addConnection( NC ); NC->setNumber( NSResources->assignConnectionNumber() ); Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); Profiles_LB->setSelected( ci, TRUE ); } updateProfileState( LBI ); } } else { // cancelled : reset connection if( LBI ) { NodeCollection * NC = NSResources->findConnection( LBI->text() ); NC->reassign(); } } break; } // reenable UpdateTimer->start( 5000 ); } void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { if( LBI == 0 ) 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() ); if ( ! LBI ) return; updateProfileState( LBI ); } void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { SLOT_ShowNode( 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(); } void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { QDataStream stream( data, IO_ReadOnly ); if( msg == "raise" ) { raise(); return; } /* if ( msg == "someMessage(int,int,int)" ) { int a,b,c; stream >> a >> b >> c; ... } */ } |