author | wimpie <wimpie> | 2004-04-10 13:06:13 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2004-04-10 13:06:13 (UTC) |
commit | db9f0e2a7fd93157d95f421534fcc3015abe53e0 (patch) (side-by-side diff) | |
tree | 001918ca18d0d74f3e49597f766c070bea71e25c | |
parent | 6bcdc8cd41199dce849b800b4296011faf6281df (diff) | |
download | opie-db9f0e2a7fd93157d95f421534fcc3015abe53e0.zip opie-db9f0e2a7fd93157d95f421534fcc3015abe53e0.tar.gz opie-db9f0e2a7fd93157d95f421534fcc3015abe53e0.tar.bz2 |
*** empty log message ***
34 files changed, 957 insertions, 293 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h index 4a773cd..c168429 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h @@ -1,31 +1,31 @@ #include <asdevice.h> #include "bluetoothBNEPdata.h" class BluetoothBNEPRun : public AsDevice { public : BluetoothBNEPRun( ANetNodeInstance * NNI, BluetoothBNEPData & Data ) : AsDevice( NNI ) { } virtual AsDevice * asDevice( void ) { return (AsDevice *)this; } virtual AsDevice * device( void ) { return asDevice(); } protected : void detectState( NodeCollection * ) { } - bool setState( NodeCollection * , Action_t ) + bool setState( NodeCollection * , Action_t, bool ) { return 0; } bool canSetState( State_t , Action_t ) { return 0; } bool handlesInterface( const QString & ) { return 0; } }; diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h index 6a7902a..aff1f59 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h @@ -1,25 +1,25 @@ #include <asline.h> #include "bluetoothRFCOMMdata.h" class BluetoothRFCOMMRun : public AsLine { public : BluetoothRFCOMMRun( ANetNodeInstance * NNI, BluetoothRFCOMMData & Data ) : AsLine( NNI ) { } virtual AsLine * asLine( void ) { return (AsLine *)this; } protected : void detectState( NodeCollection * ) { } - bool setState( NodeCollection * , Action_t ) + bool setState( NodeCollection * , Action_t, bool ) { return 0; } bool canSetState( State_t , Action_t ) { return 0; } }; diff --git a/noncore/settings/networksettings2/cable/cablerun.cpp b/noncore/settings/networksettings2/cable/cablerun.cpp index edb4b01..5e99237 100644 --- a/noncore/settings/networksettings2/cable/cablerun.cpp +++ b/noncore/settings/networksettings2/cable/cablerun.cpp @@ -1,26 +1,26 @@ #include <fcntl.h> #include <unistd.h> #include "cablerun.h" void CableRun::detectState( NodeCollection * NC ) { int fd = open( D->Device.latin1(), O_RDWR ); if( fd < 0 ) { NC->setCurrentState( Unavailable ); } close( fd ); NC->setCurrentState( Available ); } -bool CableRun::setState( NodeCollection * NC, Action_t A ) { +bool CableRun::setState( NodeCollection * NC, Action_t A, bool ) { if( A == Activate ) { detectState(NC); return (NC->currentState() == Available); } return 1; } bool CableRun::canSetState( State_t , Action_t ) { return 1; } diff --git a/noncore/settings/networksettings2/cable/cablerun.h b/noncore/settings/networksettings2/cable/cablerun.h index 7b341c4..c5b59d5 100644 --- a/noncore/settings/networksettings2/cable/cablerun.h +++ b/noncore/settings/networksettings2/cable/cablerun.h @@ -1,24 +1,24 @@ #include <asline.h> #include "cabledata.h" class CableRun : public AsLine { public : CableRun( ANetNodeInstance * NNI, CableData & Data ) : AsLine( NNI ) { D = &Data; } virtual AsLine * asLine( void ) { return (AsLine *)this; } protected : void detectState( NodeCollection * NC ); - bool setState( NodeCollection * NC, Action_t A ); + bool setState( NodeCollection * NC, Action_t A, bool Force ); bool canSetState( State_t Curr, Action_t A ); private : CableData_t * D; }; diff --git a/noncore/settings/networksettings2/irda/irdarun.h b/noncore/settings/networksettings2/irda/irdarun.h index d9fe5e8..4c903cc 100644 --- a/noncore/settings/networksettings2/irda/irdarun.h +++ b/noncore/settings/networksettings2/irda/irdarun.h @@ -1,25 +1,25 @@ #include <asline.h> #include "irdadata.h" class IRDARun : public AsLine { public : IRDARun( ANetNodeInstance * NNI, IRDAData & Data ) : AsLine( NNI ) { } virtual AsLine * asLine( void ) { return (AsLine *)this; } protected : void detectState( NodeCollection * ) { } - bool setState( NodeCollection * , Action_t ) + bool setState( NodeCollection * , Action_t, bool ) { return 0; } bool canSetState( State_t , Action_t ) { return 0; } }; diff --git a/noncore/settings/networksettings2/lancard/lancardrun.cpp b/noncore/settings/networksettings2/lancard/lancardrun.cpp index 2e4fc43..1544ddc 100644 --- a/noncore/settings/networksettings2/lancard/lancardrun.cpp +++ b/noncore/settings/networksettings2/lancard/lancardrun.cpp @@ -1,192 +1,192 @@ #include <qfile.h> #include <qtextstream.h> #include <qstringlist.h> #include <resources.h> #include "lancardrun.h" void LanCardRun::detectState( NodeCollection * NC ) { // unavailable : no card found // available : card found and assigned to us or free // up : card found and assigned to us and up QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); System & Sys = NSResources->system(); InterfaceInfo * Run; QFile F( S ); if( F.open( IO_ReadOnly ) ) { // could open file -> read interface and assign QString X; QTextStream TS(&F); X = TS.readLine(); // find interface if( handlesInterface( X ) ) { for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); if( X == Run->Name ) { Run->assignNode( netNode() ); assignInterface( Run ); NC->setCurrentState( IsUp ); return; } } } } if( ( Run = assignedInterface() ) ) { // we already have an interface assigned -> still present ? if( ! Run->IsUp ) { // usb is still free -> keep assignment NC->setCurrentState( Available ); return; } // else interface is up but NOT us -> some other profile } // nothing (valid) assigned to us assignInterface( 0 ); // find possible interface for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); if( handlesInterface( *Run ) && ( Run->CardType == ARPHRD_ETHER #ifdef ARPHRD_IEEE1394 || Run->CardType == ARPHRD_IEEE1394 #endif ) && ! Run->IsUp ) { // proper type, and Not UP -> free NC->setCurrentState( Off ); return; } } // no free found NC->setCurrentState( Unavailable ); } -bool LanCardRun::setState( NodeCollection * NC, Action_t A ) { +bool LanCardRun::setState( NodeCollection * NC, Action_t A, bool ) { // we only handle activate and deactivate switch( A ) { case Activate : { if( NC->currentState() != Off ) { return 0; } InterfaceInfo * N = getInterface(); if( ! N ) { // no interface available NC->setCurrentState( Unavailable ); return 0; } // because we were OFF the interface // we get back is NOT assigned N->assignNode( netNode() ); assignInterface( N ); NC->setCurrentState( Available ); return 1; } case Deactivate : if( NC->currentState() == IsUp ) { // bring down first if( ! connection()->setState( Down ) ) // could not ... return 0; } else if( NC->currentState() != Available ) { return 1; } assignedInterface()->assignNode( 0 ); // release assignInterface( 0 ); NC->setCurrentState( Off ); return 1; default : // FT break; } return 0; } bool LanCardRun::canSetState( State_t Curr, Action_t A ) { // we only handle up down activate and deactivate switch( A ) { case Activate : { // at least available if( Curr == Available ) { return 1; } // or we can make one available InterfaceInfo * N = getInterface(); if( ! N || N->assignedNode() != 0 ) { // non available or assigned return 0; } return 1; } case Deactivate : return ( Curr >= Available ); default : // FT break; } return 0; } // get interface that is free or assigned to us InterfaceInfo * LanCardRun::getInterface( void ) { System & S = NSResources->system(); InterfaceInfo * best = 0, * Run; for( QDictIterator<InterfaceInfo> It(S.interfaces()); It.current(); ++It ) { Run = It.current(); if( handlesInterface( *Run ) && ( Run->CardType == ARPHRD_ETHER #ifdef ARPHRD_IEEE1394 || Run->CardType == ARPHRD_IEEE1394 #endif ) ) { // this is a LAN card if( Run->assignedNode() == netNode() ) { // assigned to us return Run; } else if( Run->assignedNode() == 0 ) { // free best = Run; } } } return best; // can be 0 } bool LanCardRun::handlesInterface( const QString & S ) { InterfaceInfo * II; II = NSResources->system().interface( S ); if( ( II = NSResources->system().interface( S ) ) ) { return handlesInterface( *II ); } return Pat.match( S ) >= 0; } bool LanCardRun::handlesInterface( const InterfaceInfo & II ) { if( Pat.match( II.Name ) < 0 ) return 0; if( Data->AnyLanCard ) { return 1; } // must also match hardware address return ( Data->HWAddresses.findIndex( II.MACAddress ) >= 0 ); } diff --git a/noncore/settings/networksettings2/lancard/lancardrun.h b/noncore/settings/networksettings2/lancard/lancardrun.h index e8a535a..b28dda7 100644 --- a/noncore/settings/networksettings2/lancard/lancardrun.h +++ b/noncore/settings/networksettings2/lancard/lancardrun.h @@ -1,39 +1,39 @@ #ifndef LANCARDRUN_H #define LANCARDRUN_H #include <asdevice.h> #include <qregexp.h> #include "lancarddata.h" class LanCardRun : public AsDevice { public : LanCardRun( ANetNodeInstance * NNI, LanCardData & D ) : AsDevice( NNI ), Pat( "eth[0-9]" ) { Data = &D; } virtual AsDevice * device( void ) { return (AsDevice *)this; } virtual AsDevice * asDevice( void ) { return (AsDevice *)this; } protected : void detectState( NodeCollection * NC ); - bool setState( NodeCollection * NC, Action_t A ); + bool setState( NodeCollection * NC, Action_t A, bool Force ); bool canSetState( State_t Curr, Action_t A ); bool handlesInterface( const QString & I ); bool handlesInterface( const InterfaceInfo & II ); private : InterfaceInfo * getInterface( void ); QRegExp Pat; LanCardData * Data; }; #endif diff --git a/noncore/settings/networksettings2/modem/modemrun.h b/noncore/settings/networksettings2/modem/modemrun.h index 6d1662b..336462e 100644 --- a/noncore/settings/networksettings2/modem/modemrun.h +++ b/noncore/settings/networksettings2/modem/modemrun.h @@ -1,25 +1,25 @@ #include <asline.h> #include "modemdata.h" class ModemRun : public AsLine { public : ModemRun( ANetNodeInstance * NNI, ModemData & Data ) : AsLine ( NNI ) { } virtual AsLine * asLine( void ) { return (AsLine *)this; } protected : void detectState( NodeCollection * ) { } - bool setState( NodeCollection *, Action_t ) + bool setState( NodeCollection *, Action_t, bool ) { return 0; } bool canSetState( State_t, Action_t ) { return 0; } }; diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp index c19235a..41e1c53 100644 --- a/noncore/settings/networksettings2/network/networkrun.cpp +++ b/noncore/settings/networksettings2/network/networkrun.cpp @@ -1,66 +1,66 @@ #include <system.h> #include <asdevice.h> #include "networkrun.h" void NetworkRun::detectState( NodeCollection * NC ) { RuntimeInfo * RI = netNode()->nextNode()->runtime(); AsDevice * Next = RI->asDevice(); InterfaceInfo * II = Next->assignedInterface(); if( II ) { // device has assigned interface NC->setCurrentState( (( II->IsUp ) ? IsUp : Available) ); return; } // has no interface -> delegate RI->detectState( NC ); } -bool NetworkRun::setState( NodeCollection * NC, Action_t A ) { +bool NetworkRun::setState( NodeCollection * NC, Action_t A, bool Force ) { // we handle UP and DOWN RuntimeInfo * RI = netNode()->nextNode()->runtime(); AsDevice * Next = RI->asDevice(); InterfaceInfo * II = Next->assignedInterface(); if( A == Up ) { // we can bring UP if lower level is available - if( NC->currentState() == Available ) { + if( NC->currentState() == Available || Force ) { QString S; S.sprintf( "ifup %s=%s-c%d-allowed", II->Name.latin1(), II->Name.latin1(), connection()->number() ); NSResources->system().runAsRoot( S ); } return 1; } else if( A == Down ) { - if( NC->currentState() == IsUp ) { + if( NC->currentState() == IsUp || Force ) { QString S; S.sprintf( "ifdown %s=%s-c%d-allowed", II->Name.latin1(), II->Name.latin1(), connection()->number() ); NSResources->system().runAsRoot( S ); } return 1; } // delegate return RI->setState( NC, A ); } bool NetworkRun::canSetState( State_t Curr, Action_t A ) { // we handle UP and DOWN RuntimeInfo * RI = netNode()->nextNode()->runtime(); if( A == Up ) { return ( Curr == Available ); } else if( A == Down ) { return ( Curr == IsUp ); } // delegate return RI->canSetState( Curr, A ); } bool NetworkRun::handlesInterface( const QString & S ) { // donno -> pass deeper return netNode()->nextNode()->runtime()->handlesInterface(S); } diff --git a/noncore/settings/networksettings2/network/networkrun.h b/noncore/settings/networksettings2/network/networkrun.h index fa16365..522a912 100644 --- a/noncore/settings/networksettings2/network/networkrun.h +++ b/noncore/settings/networksettings2/network/networkrun.h @@ -1,23 +1,23 @@ #include <asconnection.h> #include "networkdata.h" class NetworkRun : public AsConnection { public : NetworkRun( ANetNodeInstance * NNI, NetworkData & Data ) : AsConnection( NNI ) { } virtual AsConnection * asConnection( void ) { return (AsConnection *)this; } protected : void detectState( NodeCollection * ); - bool setState( NodeCollection * ,Action_t A ); + bool setState( NodeCollection * ,Action_t A, bool ); bool canSetState( State_t , Action_t A ); bool handlesInterface( const QString & I ); }; diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index 3ddcbde..b36c7a0 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp @@ -1,423 +1,449 @@ #include <stdio.h> #include <qpe/qpeapplication.h> #include <qlistbox.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 <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" ) ); On_TB->setPixmap( NSResources->getPixmap( "off" ) ); + SLOT_ToProfile(); + // populate main Listbox Profiles_LB->clear(); { 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() ) ); } 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; S = NSD.generateSettings(); if( ! S.isEmpty() ) { QMessageBox::warning( 0, tr( "In System Config" ), S ); } S = NSD.saveSettings(); if( ! S.isEmpty() ) { // problem saving QMessageBox::warning( 0, tr( "Saving setup" ), S ); } } 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.forceGeneration(1); } } void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { QString OldName = ""; 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( NC->maxConnectionNumber()+1 ); 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; EnabledPossible = OnPossible = ConnectPossible = 1; DisabledOn = 1; OnOn = ConnectOn = 0; switch( NC->state() ) { case Unknown : // cannot occur here break; case Unchecked : case Unavailable : // cannot do anything but recheck EnabledPossible = OnPossible = ConnectPossible = 0; break; case Disabled : OnPossible = ConnectPossible = 0; break; case Off : DisabledOn = 0; break; case Available : OnOn = 1; DisabledOn = 0; break; case IsUp : OnOn = ConnectOn = 1; DisabledOn = 0; break; } // 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 ); if( NC->description().isEmpty() ) { Description_LBL->setText( tr( "No description" ) ); } else { Description_LBL->setText( NC->description() ); } - CurProfile_GB->setTitle( LBI->text() ); + Profile_GB->setTitle( LBI->text() ); State_LBL->setText( NC->stateName() ); } 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 ) { QString S = NSD.generateSettings( TRUE ); if( ! S.isEmpty() ) { QMessageBox::warning( 0, tr( "Generating system configuration" ), S ); } } void NetworkSettings::SLOT_Enable( void ) { 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; } if( ! rv ) { QMessageBox::warning( 0, tr( "Activating profile" ), Msg ); return; } updateProfileState( LBI ); } void NetworkSettings::SLOT_On( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); if ( ! LBI ) return; NodeCollection * NC = NSResources->findConnection( LBI->text() ); bool rv; switch( NC->state() ) { case Off : // activate interface rv = NC->setState( Activate ); break; case Available : // deactivate case IsUp : // deactivate (will also bring down if needed) rv = NC->setState( Deactivate ); break; default : // others no change return; } if( ! rv ) { QMessageBox::warning( 0, tr( "Activating profile" ), tr( "Cannot enable profile" ) ); return; } updateProfileState( LBI ); } void NetworkSettings::SLOT_Connect( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); 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 ); break; case Off : // activate and bring up rv = ( NC->setState( Activate ) && NC->setState( Up ) ); break; default : // others no change break; } if( ! rv ) { 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 ) { + QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); + + if ( ! LBI ) + return; + + NodeCollection * NC = + NSResources->findConnection( LBI->text() ); + + NC->setState( Down, 1 ); +} + +void NetworkSettings::SLOT_ToMessages( void ) { + Profile_GB->hide(); + Messages_GB->show(); +} + +void NetworkSettings::SLOT_ToProfile( void ) { + 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; ... } */ } diff --git a/noncore/settings/networksettings2/networksettings.h b/noncore/settings/networksettings2/networksettings.h index d9ea5d4..97852af 100644 --- a/noncore/settings/networksettings2/networksettings.h +++ b/noncore/settings/networksettings2/networksettings.h @@ -1,49 +1,52 @@ #include "nsdata.h" #include "networksettingsGUI.h" #include "resources.h" class ANetNode; class ANetNodeInstance; class QTimer; class QListBoxItem; class NetworkSettings : public NetworkSettingsGUI { Q_OBJECT public : NetworkSettings( QWidget *parent=0, const char *name=0, WFlags fl = 0 ); ~NetworkSettings( void ); static QString appName( void ) { return QString::fromLatin1("networksettings"); } bool isModified( void ) { return NSD.isModified(); } void setModified( bool m ) { NSD.setModified( m ); } public slots : void SLOT_AddNode( void ); void SLOT_DeleteNode( void ); void SLOT_ShowNode( QListBoxItem * ); void SLOT_EditNode( QListBoxItem * ); void SLOT_CheckState( void ); void SLOT_Enable( void ); void SLOT_On( void ); void SLOT_Connect( void ); + void SLOT_Disconnect( void ); void SLOT_GenerateConfig( void ); void SLOT_RefreshStates( void ); void SLOT_QCopMessage( const QCString&,const QByteArray& ); + void SLOT_ToProfile( void ); + void SLOT_ToMessages( void ); private : void updateProfileState( QListBoxItem * it ); QTimer * UpdateTimer; NetworkSettingsData NSD; }; diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index dc66aff..1182543 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -1,299 +1,310 @@ -#include <qpe/qpeapplication.h> #include <time.h> +#include <qpe/qpeapplication.h> +#include <qpainter.h> +#include <qbitmap.h> #include <qtextstream.h> #include <qpixmap.h> #include "resources.h" #include "netnode.h" #include "asdevice.h" #include "asline.h" #include "asconnection.h" #include "asfullsetup.h" QString & deQuote( QString & X ) { if( X[0] == '"' ) { // remove end and trailing "" and \x -> x QChar R; long idx; idx = X.length()-1; X = X.mid( 1, idx ); idx = 0; while( ( idx = X.find( '\\', idx ) ) >= 0 ) { R = X.at( idx + 1 ); X.replace( idx, 2, &R, 1 ); } X = X.left( X.length()-1 ); } return X; } QString quote( QString X ) { if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) { // need to quote this QString OutString = "\""; X.replace( QRegExp("\""), "\\\"" ); X.replace( QRegExp("\\"), "\\\\" ); X.replace( QRegExp(" "), "\\ " ); OutString += X; OutString += "\""; X = OutString; } return X; } // // // ANETNODE // // void ANetNode::saveAttributes( QTextStream & TS ) { saveSpecificAttribute( TS ); } void ANetNode::setAttribute( QString & Attr, QString & Value ){ setSpecificAttribute( Attr, Value ); } // // // ANETNODEINSTANCE // // long ANetNodeInstance::InstanceCounter = -1; void ANetNodeInstance::initialize( void ) { if( InstanceCounter == -1 ) InstanceCounter = time(0); // set name QString N; N.sprintf( "-%ld", InstanceCounter++ ); N.prepend( NodeType->name() ); setName( N.latin1() ); } void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ if( Attr == "name" ) { setName( Value.latin1() ); } else { setSpecificAttribute( Attr, Value ); } } void ANetNodeInstance::saveAttributes( QTextStream & TS ) { TS << "name=" << name() << endl; saveSpecificAttribute( TS ); } ANetNodeInstance * ANetNodeInstance::nextNode( void ) { return connection()->findNext( this ); } // // // NODECOLLECTION // // long NodeCollection::MaxNr = -1; NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { IsModified = 0; Index = -1; Name=""; IsNew = 1; CurrentState = Unchecked; } NodeCollection::NodeCollection( QTextStream & TS ) : QList<ANetNodeInstance>() { long idx; bool InError = 0; QString S, A, N; IsModified = 0; Index = -1; Name=""; IsNew = 0; CurrentState = Unchecked; do { S = TS.readLine(); if( S.isEmpty() ) { if( InError ) { // remove all nodes clear(); } // empty line break; } idx = S.find('='); S.stripWhiteSpace(); A = S.left( idx ); A.lower(); N = S.mid( idx+1, S.length() ); N.stripWhiteSpace(); N = deQuote( N ); if( A == "name" ) { Name = N; } else if( A == "number" ) { setNumber( N.toLong() ); } else if( A == "node" ) { ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); if( NNI && ! InError ) { append( NSResources->findNodeInstance( N ) ); } else { // could not find a node type -> collection invalid InError = 1; } } } while( 1 ); } NodeCollection::~NodeCollection( void ) { } const QString & NodeCollection::description( void ) { ANetNodeInstance * NNI = getToplevel(); return (NNI) ? NNI->runtime()->asFullSetup()->description() : Name; } void NodeCollection::append( ANetNodeInstance * NNI ) { NNI->setConnection( this ); QList<ANetNodeInstance>::append( NNI ); } void NodeCollection::save( QTextStream & TS ) { TS << "name=" << quote( Name ) << endl; TS << "number=" << number() << endl; ANetNodeInstance * NNI; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); TS << "node=" << NNI->name() << endl; } TS << endl; IsNew = 0; } ANetNodeInstance * NodeCollection::getToplevel( void ) { ANetNodeInstance * NNI = 0; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); if( NNI->nodeClass()->isToplevel() ) break; } return NNI; } ANetNodeInstance * NodeCollection::findByName( const QString & S ) { ANetNodeInstance * NNI = 0; for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNI = it.current(); if( NNI->name() == S ) break; } return NNI; } ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) { ANetNodeInstance * NNNI; if( ! NNI ) getToplevel(); for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { NNNI = it.current(); if( NNNI == NNI ) { ++it; return it.current(); } } return 0; // no more next } int NodeCollection::compareItems( QCollection::Item I1, QCollection::Item I2 ) { ANetNodeInstance * NNI1, * NNI2; NNI1 = (ANetNodeInstance *)I1; NNI2 = (ANetNodeInstance *)I2; return strcmp( NNI1->name(), NNI2->name() ); } static char * State2PixmapTbl[] = { "NULL", // Unchecked : no pixmap "check", // Unknown "delete", // unavailable "disabled", // disabled "off", // off "disconnected", // available "connected" // up }; QPixmap NodeCollection::devicePixmap( void ) { - return NSResources->getPixmap( - device()->netNode()->pixmapName()+"-large" ); + QPixmap pm = NSResources->getPixmap( + getToplevel()->nextNode()->pixmapName()+"-large"); + + QPixmap Mini = NSResources->getPixmap( device()->netNode()->pixmapName() ); + + QPainter painter( &pm ); + painter.drawPixmap( pm.width()-Mini.width(), + pm.height()-Mini.height(), + Mini ); + pm.setMask( pm.createHeuristicMask( TRUE ) ); + return pm; } QPixmap NodeCollection::statePixmap( State_t S) { return NSResources->getPixmap( State2PixmapTbl[S] ); } QString NodeCollection::stateName( State_t S) { switch( S ) { case Unknown : return qApp->translate( "networksettings2", "Unknown"); case Unavailable : return qApp->translate( "networksettings2", "Unavailable"); case Disabled : return qApp->translate( "networksettings2", "Disabled"); case Off : return qApp->translate( "networksettings2", "Off"); case Available : return qApp->translate( "networksettings2", "Available"); case IsUp : return qApp->translate( "networksettings2", "IsUp"); case Unchecked : /* FT */ default : break; } return QString(""); } void NodeCollection::reassign( void ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { it.current()->setConnection( this ); } } // // // RUNTIMEINFO // // InterfaceInfo * RuntimeInfo::assignedInterface( void ) { return netNode()->nextNode()->runtime()->assignedInterface(); } AsDevice * RuntimeInfo::device( void ) { return netNode()->nextNode()->runtime()->device(); } diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index 27d54f8..5e36062 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -1,382 +1,382 @@ #ifndef NETNODE_H #define NETNODE_H #include <qtextstream.h> #include <qlist.h> #include <qdict.h> #include <qpixmap.h> #include <qobject.h> #include <time.h> // difference feature interfaces class AsDevice; class AsLine; class AsConnection; class AsFullSetup; // needed for plugin creation function #include <qlist.h> class ANetNode; class ANetNodeInstance; class NodeCollection; class QTextStream; class RuntimeInfo; class InterfaceInfo; extern QString & deQuote( QString & X ); extern QString quote( QString X ); #include "systemfile.h" typedef enum State { // if we have not yet detected the state of the device Unchecked = 0, // if we cannot determine the state Unknown = 1, // if connection cannot be established e.g. because // the hardware is not available Unavailable = 2, // if the connection cannot be establishec but NOT // because it is physically impossible but because // it has been disabled for FUNCTIONAL reasons Disabled = 3, // if connection is available to is currently down // i.e. the corresponding hardware is not activated Off = 4, // if connection is available to be used (i.e. the // devices if fully ready to be used Available = 5, // if connection is being used IsUp = 6 } State_t; typedef enum Action { // to make the device unavailable functionally Disable = 0, // to make the device available functionally Enable = 1, // bring the hardware up Activate = 2, // bring the hardware down Deactivate = 3, // bring the connection up Up = 4, // bring the connection down Down = 5 } Action_t; class ANetNode : public QObject{ public: typedef QArray<ANetNode *> NetNodeList; ANetNode( const char * Name ) : QObject( 0, Name ) {} virtual ~ANetNode(){}; // pixmap needed for this NetNode virtual const QString pixmapName() = 0; // description for this NetNode virtual const QString nodeDescription() = 0; // create a blank instance of a net node virtual ANetNodeInstance * createInstance( void ) = 0; // return feature this NetNode provides virtual const char * provides( void ) = 0; virtual const char ** needs( void ) = 0; // generate files specific for this node (if any) virtual bool generateProperFilesFor( ANetNodeInstance * NNI ) = 0; // return TRUE if this node has data to be inserted in systemfile // with name S virtual bool hasDataFor( const QString & S ) = 0; // generate data specific for the device for the system file S // called only IF data was needed virtual bool generateDeviceDataForCommonFile( SystemFile & SF, long DevNr ) = 0; // does this Node provide a Connection bool isToplevel( void ) { return strcmp( provides(), "fullsetup") == 0 ; } // generate NIC name based on instance nr // only relevant if node instances are devices virtual QString genNic( long ) { return QString(""); } // max number of instances for this node type // only relevant if node instances are devices virtual long instanceCount( void ) { return 1; } // set the value of an attribute void setAttribute( QString & Attr, QString & Value ) ; void saveAttributes( QTextStream & TS ) ; // compiled references to 'needed' NetNodes -> needs list void setAlternatives( NetNodeList * Alt ) { Alternatives = Alt; } NetNodeList & alternatives( void ) { return *Alternatives; } protected : NetNodeList * Alternatives; private : virtual void setSpecificAttribute( QString & , QString & ) = 0; virtual void saveSpecificAttribute( QTextStream & ) = 0; }; class ANetNodeInstance : public QObject { public: ANetNodeInstance( ANetNode * NN ) : QObject() { IsModified=0; NodeType = NN; IsNew = TRUE; } virtual ~ANetNodeInstance( void ) { } virtual RuntimeInfo * runtime( void ) = 0; void setConnection( NodeCollection * NC ) { Connection = NC; } NodeCollection * connection( void ) { return Connection; } // create edit widget under parent virtual QWidget * edit( QWidget * parent ) = 0; // is given data acceptable virtual QString acceptable( void ) = 0; // return data was modified void setModified( bool M ) { IsModified = M; } bool isModified( void ) { return IsModified; } // get data from GUI and store in node virtual void commit( void ) = 0; // get next node ANetNodeInstance * nextNode(); // return NetNode this is an instance of ANetNode * nodeClass( void ) { return NodeType; } // intialize am instance of a net node void initialize( void ); // set the value of an attribute void setAttribute( QString & Attr, QString & Value ) ; void saveAttributes( QTextStream & TS ) ; // return true if node isntance is NEW and not loaded void setNew( bool IsN ) { IsNew = IsN; } bool isNew( void ) { return IsNew; } // return description for this instance QString & description( void ) { return Description; } void setDescription( const QString & S ) { Description = S; } // pixmap for this instance -> from NetNode const QString pixmapName( void ) { return NodeType->pixmapName(); } const char * provides( void ) { return NodeType->provides(); } const char ** needs( void ) { return NodeType->needs(); } // returns node specific data -> only useful for 'buddy' virtual void * data( void ) = 0; // return TRUE if this node has data to be inserted in systemfile // with name S virtual bool hasDataFor( const QString & S ) = 0; // generate data specific for a profile and for the system file S // called only IF data was needed virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr ) = 0; protected : virtual void setSpecificAttribute( QString & , QString & ) = 0; virtual void saveSpecificAttribute( QTextStream & ) = 0; ANetNode * NodeType; // connection to which this node belongs to NodeCollection * Connection; QString Description; bool IsModified; bool IsNew; static long InstanceCounter; }; class RuntimeInfo : public QObject { Q_OBJECT public : RuntimeInfo( ANetNodeInstance * TheNNI ) { NNI = TheNNI; } // downcast implemented by specify runtime classes virtual AsDevice * asDevice( void ) { return 0; } virtual AsConnection * asConnection( void ) { return 0; } virtual AsLine * asLine( void ) { return 0; } virtual AsFullSetup * asFullSetup( void ) { return 0; } // does this node handles this interface e.g.eth0 // recurse deeper if this node cannot answer that question virtual bool handlesInterface( const QString & ) { return 0; } virtual bool handlesInterface( const InterfaceInfo & ) { return 0; } virtual InterfaceInfo * assignedInterface( void ); virtual AsDevice * device( void ); ANetNodeInstance * netNode() { return NNI; } NodeCollection * connection() { return NNI->connection(); } virtual void detectState( NodeCollection * NC ) = 0; - virtual bool setState( NodeCollection * NC, Action_t A ) = 0; + virtual bool setState( NodeCollection * NC, Action_t A, bool Force = 0 ) = 0; virtual bool canSetState( State_t Curr, Action_t A ) = 0; signals : // sent by device if state changes void stateChanged( State_t S, ANetNodeInstance * NNI ); protected : // connection this runtime info belongs to ANetNodeInstance * NNI; }; class NodeCollection : public QList<ANetNodeInstance> { public : NodeCollection( void ); NodeCollection( QTextStream & TS ); ~NodeCollection( void ); int number( void ) { return Number; } void setNumber( int i ) { Number = i; if( MaxNr < i ) MaxNr = i; } bool isNew( void ) { return IsNew; } void setNew( bool N ) { IsNew = N ; } bool isModified( void ) { return IsModified; } void setModified( bool N ) { IsModified = N ; } bool handlesInterface( const QString & S ) { return getToplevel()->runtime()->handlesInterface( S ); } InterfaceInfo * assignedInterface( void ) { return getToplevel()->runtime()->assignedInterface(); } AsDevice * device() { return getToplevel()->runtime()->device(); } State_t state( bool Update = 0 ) { if( CurrentState == Unchecked || Update ) { // need to get current state getToplevel()->runtime()->detectState( this ); } return CurrentState; } // get the ixmap for this device QPixmap devicePixmap( void ); QPixmap statePixmap( State_t S ); QPixmap statePixmap( bool Update = 0 ) { return statePixmap( state(Update) ); } QString stateName( State_t ); QString stateName( bool Update = 0 ) { return stateName( state(Update) ); } - bool setState( Action_t A ) - { return getToplevel()->runtime()->setState( this, A ); } + bool setState( Action_t A, bool Force =0 ) + { return getToplevel()->runtime()->setState( this, A, Force ); } bool canSetState( Action_t A ) { return getToplevel()->runtime()->canSetState( CurrentState, A ); } void save( QTextStream & TS ); void append( ANetNodeInstance * NNI ); // makes sure that all items in the connection point to // that connectoin void reassign( void ); ANetNodeInstance * getToplevel( void ); ANetNodeInstance * findNext( ANetNodeInstance * NNI ); ANetNodeInstance * findByName( const QString & S ); const QString & name() { return Name; } const QString & description( void ); void setName( const QString & N) { Name = N; } State_t currentState( void ) { return CurrentState; } void setCurrentState( State_t S ) { CurrentState = S; } long maxConnectionNumber( void ) { return MaxNr; } static void resetMaxNr( void ) { MaxNr = -1; } private : int compareItems ( QCollection::Item item1, QCollection::Item item2 ); static long MaxNr; long Number; // state of this connection State_t CurrentState; QString Name; // true if this collection was just created (and not // loaded from file bool IsNew; // index in listbox int Index; bool IsModified; }; #endif diff --git a/noncore/settings/networksettings2/networksettings2/networksettings2.pro b/noncore/settings/networksettings2/networksettings2/networksettings2.pro index 11b5f84..f97c93b 100644 --- a/noncore/settings/networksettings2/networksettings2/networksettings2.pro +++ b/noncore/settings/networksettings2/networksettings2/networksettings2.pro @@ -1,26 +1,28 @@ TEMPLATE = lib CONFIG += qt warn_on release #CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/lib$(PROJMAK) HEADERS = netnode.h \ resources.h \ system.h \ asline.h \ GUIUtils.h \ asconnection.h \ asfullsetup.h \ systemfile.h \ + wextensions.h \ asdevice.h SOURCES = netnode.cpp \ GUIUtils.cpp \ system.cpp \ systemfile.cpp \ + wextensions.cpp \ resources.cpp INCLUDEPATH += $(OPIEDIR)/include ../networksettings2 DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe -lopiecore2 INTERFACES = TARGET = networksettings2 VERSION = 1.0.0 include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 4b7a62f..c95ac7f 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -1,369 +1,370 @@ #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <pwd.h> #include <qpixmap.h> #include <qdir.h> #include <qpe/qlibrary.h> #include <qpe/qpeapplication.h> #include <opie2/odebug.h> #include <qtopia/resource.h> #include "netnode.h" #include "resources.h" #define PLUGINDIR "plugins/networksettings2" #define ICONDIR "/pics/networksettings2/" // single resources instance TheNSResources * _NSResources = 0; TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), ConnectionsMap() { _NSResources = this; // load available netnodes findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); // compile provides and needs lists { const char ** NeedsRun; QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); bool Done; for ( ; OuterIt.current(); ++OuterIt ) { // find needs list ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; ANetNode::NetNodeList & NNL = *(NNLP); // must iterate this way to avoid duplication pointers for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); InnerIt.current(); ++InnerIt ) { if( InnerIt.current() == OuterIt.current() ) // avoid recursive continue; const char * Provides = InnerIt.current()->NetNode->provides(); NeedsRun = OuterIt.current()->NetNode->needs(); for( ; *NeedsRun; NeedsRun ++ ) { if( strcmp( Provides, *NeedsRun ) == 0 ) { // inner provides what outer needs NNL.resize( NNL.size() + 1 ); NNL[NNL.size()-1] = InnerIt.current()->NetNode; Done = 1; // break from 2 loops break; } } } OuterIt.current()->NetNode->setAlternatives( NNLP ); } } // define Node types to Description map NodeTypeNameMap.insert( "device", tr( "Network Device" ) ); NodeTypeNameMap.insert( "line", tr( "Character device" ) ); NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) ); NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) ); NodeTypeDescriptionMap.insert( "device", tr( "<p>Devices that can handle IP packets</p>" ) ); NodeTypeDescriptionMap.insert( "line", tr( "<p>Devices that can handle single bytes</p>" ) ); NodeTypeDescriptionMap.insert( "connection", tr( "<p>Nodes that provide working IP connections</p>" ) ); NodeTypeDescriptionMap.insert( "fullsetup", tr( "<p>Fully configured connection profile</p>" ) ); // define system files addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); // get access to the system TheSystem = new System(); detectCurrentUser(); } TheNSResources::~TheNSResources( void ) { delete TheSystem; } /** * Load all modules that are found in the path * @param path a directory that is scaned for any plugins that can be loaded * and attempts to load them */ void TheNSResources::findAvailableNetNodes(const QString &path){ QDir d(path); if(!d.exists()) return; QString lang = ::getenv("LANG"); // Don't want sym links d.setFilter( QDir::Files | QDir::NoSymLinks ); const QFileInfoList *list = d.entryInfoList(); QFileInfoListIterator it( *list ); QFileInfo *fi; while ( (fi=it.current()) ) { if( fi->fileName().contains(".so")){ /* if loaded install translation */ if( loadNetNode(path + "/" + fi->fileName()) ) { QTranslator *trans = new QTranslator(qApp); QString fn = QPEApplication::qpeDir()+ "/i18n/"+lang+"/"+ fi->fileName().left( fi->fileName().find(".") )+ ".qm"; if( trans->load( fn ) ) qApp->installTranslator( trans ); else delete trans; } } ++it; } } /** * Attempt to load a function and resolve a function. * @param pluginFileName - the name of the file in which to attempt to load * @param resolveString - function pointer to resolve * @return true of loading is successful */ bool TheNSResources::loadNetNode( const QString &pluginFileName, const QString &resolveString){ QLibrary *lib = new QLibrary(pluginFileName); void * res = lib->resolve(resolveString); if( ! res ){ delete lib; return 0; } GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; // Try to get an object. QList<ANetNode> PNN; getNetNodeList( PNN ); if( PNN.isEmpty() ) { delete lib; return 0; } ANetNode * NNP; for( QListIterator<ANetNode> it(PNN); it.current(); ++it ) { NetNode_t * NN; NNP = it.current(); NN = new NetNode_t; NN->NetNode = NNP; NN->TheLibrary = lib; NN->NodeCountInLib = PNN.count(); // store mapping printf( "Store %s\n", NN->NetNode->name() ); AllNodeTypes.insert( NN->NetNode->name(), NN ); } return 1; } QPixmap TheNSResources::getPixmap( const QString & QS ) { QString S("networksettings2/"); S += QS; - return Resource::loadPixmap( QString("networksettings2/")+QS ); + fprintf( stderr, "%s\n", S.latin1() ); + return Resource::loadPixmap( S ); } QString TheNSResources::tr( const char * s ) { return qApp->translate( "resource", s ); } const QString & TheNSResources::netNode2Name( const char * s ) { return NodeTypeNameMap[s]; } const QString & TheNSResources::netNode2Description( const char * s ) { return NodeTypeDescriptionMap[s]; } void TheNSResources::addConnection( NodeCollection * NC ) { ANetNodeInstance * NNI; ConnectionsMap.insert( NC->name(), NC ); // add (new) nodes to NodeList for( QListIterator<ANetNodeInstance> it(*NC); it.current(); ++it ) { NNI = it.current(); if( findNodeInstance( NNI->name() ) == 0 ) { // new item addNodeInstance( NNI ); } } } void TheNSResources::removeConnection( const QString & N ) { NodeCollection * NC = findConnection( N ); if( ! NC ) return; // delete netnodes in this connection ANetNodeInstance * NNI; for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) { removeNodeInstance( NNI->name() ); } ConnectionsMap.remove( N ); } NodeCollection * TheNSResources::findConnection( const QString & S ) { return ConnectionsMap[ S ]; } void TheNSResources::renumberConnections( void ) { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections NodeCollection::resetMaxNr(); for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); NC->setNumber( NC->maxConnectionNumber()+1 ); NC->setModified( 1 ); } } typedef struct EnvVars { char * Name; int Len; } EnvVar_t; #define AnEV(x) x, sizeof(x)-1 static EnvVar_t EV[] = { // AnEV( "HOME=" ), -> SPECIAL // AnEV( "LOGNAME=" ), -> SPECIAL AnEV( "USER=" ), AnEV( "LD_LIBRARY_PATH=" ), AnEV( "PATH=" ), AnEV( "QTDIR=" ), AnEV( "OPIEDIR=" ), AnEV( "SHELL=" ), { NULL, 0 } }; void TheNSResources::detectCurrentUser( void ) { // find current running qpe QString QPEEnvFile = ""; // open proc dir and find all dirs in it { QRegExp R("[0-9]+"); QDir ProcDir( "/proc" ); QString QPELoc = QPEApplication::qpeDir() + "bin/qpe"; QFileInfo FI; QStringList EL = ProcDir.entryList( QDir::Dirs ); // print it out for ( QStringList::Iterator it = EL.begin(); it != EL.end(); ++it ) { if( R.match( (*it) ) >= 0 ) { QString S = ProcDir.path()+"/"+ (*it); S.append( "/exe" ); FI.setFile( S ); // get the linke S = FI.readLink(); if( S == QPELoc ) { // found running qpe QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" ); break; } } } } if( QPEEnvFile.isEmpty() ) { // could not find qpe fprintf( stderr, "Could not find qpe\n" ); return; } // FI now contains path ProcDir to the cmd dir { char * Buf = 0; char TB[1024]; long BufSize = 0; int fd; int rd; fd = open( QPEEnvFile.latin1(), O_RDONLY ); if( fd < 0 ) { fprintf( stderr, "Could not open %s : %d\n", QPEEnvFile.latin1(), errno ); return; } while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) { Buf = (char *)realloc( Buf, BufSize+rd ); memcpy( Buf+BufSize, TB, rd ); BufSize += rd; } char * Data = Buf; char * DataEnd = Data+BufSize-1; // get env items out of list while( Data < DataEnd ) { if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) { CurrentUser.UserName = Data+8; CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = strdup( Data ); } else if( strncmp( Data, "HOME=", 5 ) == 0 ) { CurrentUser.HomeDir = Data+5; CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = strdup( Data ); } else { EnvVar_t * Run = EV; while( Run->Name ) { if( strncmp( Data, Run->Name, Run->Len ) == 0 ) { CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 ); CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = strdup( Data ); break; } Run ++; } } Data += strlen( Data )+1; } free( Buf ); if( ! CurrentUser.UserName.isEmpty() ) { // find user info struct passwd pwd; struct passwd * pwdres; if( getpwnam_r( CurrentUser.UserName.latin1(), &pwd, TB, sizeof(TB), &pwdres ) || pwdres == 0 ) { fprintf( stderr, "Could not determine user %s : %d\n", CurrentUser.UserName.latin1(), errno ); return; } CurrentUser.Uid = pwd.pw_uid; CurrentUser.Gid = pwd.pw_gid; } else{ CurrentUser.Uid = CurrentUser.Gid = -1; } } } diff --git a/noncore/settings/networksettings2/networksettingsGUI.ui b/noncore/settings/networksettings2/networksettingsGUI.ui index 1d79123..7ef2f64 100644 --- a/noncore/settings/networksettings2/networksettingsGUI.ui +++ b/noncore/settings/networksettings2/networksettingsGUI.ui @@ -1,457 +1,630 @@ <!DOCTYPE UI><UI> <class>NetworkSettingsGUI</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>NetworkSettingsGUI</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>399</width> - <height>502</height> + <width>160</width> + <height>260</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Network Settings</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>0</number> + <number>2</number> </property> <widget> <class>QFrame</class> <property stdset="1"> <name>name</name> <cstring>Frame4</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>frameShape</name> <enum>NoFrame</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Raised</enum> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>1</number> </property> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>Add_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>Delete_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>CheckState_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>GenConfig_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> </widget> <spacer> <property> <name>name</name> <cstring>Spacer1</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>On_TB</cstring> + <cstring>Enable_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> <property stdset="1"> <name>toggleButton</name> <bool>true</bool> </property> <property stdset="1"> <name>toggleButton</name> <bool>true</bool> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> - <cstring>Enable_TB</cstring> + <cstring>On_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> <property stdset="1"> <name>toggleButton</name> <bool>true</bool> </property> <property stdset="1"> <name>toggleButton</name> <bool>true</bool> </property> </widget> <widget> <class>QToolButton</class> <property stdset="1"> <name>name</name> <cstring>Connect_TB</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>...</string> </property> <property stdset="1"> <name>toggleButton</name> <bool>true</bool> </property> <property stdset="1"> <name>toggleButton</name> <bool>true</bool> </property> </widget> + <widget> + <class>QToolButton</class> + <property stdset="1"> + <name>name</name> + <cstring>Disconnect_TB</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>text</name> + <string>...</string> + </property> + <property stdset="1"> + <name>toggleButton</name> + <bool>true</bool> + </property> + <property stdset="1"> + <name>toggleButton</name> + <bool>true</bool> + </property> + </widget> </hbox> </widget> <widget> <class>QListBox</class> <property stdset="1"> <name>name</name> <cstring>Profiles_LB</cstring> </property> </widget> <widget> <class>QGroupBox</class> <property stdset="1"> <name>name</name> - <cstring>CurProfile_GB</cstring> - </property> - <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>5</hsizetype> - <vsizetype>1</vsizetype> - </sizepolicy> + <cstring>Profile_GB</cstring> </property> <property stdset="1"> <name>title</name> - <string></string> + <string>Profile</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>4</number> </property> <property stdset="1"> <name>spacing</name> - <number>1</number> + <number>2</number> </property> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout3</cstring> </property> <hbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>6</number> </property> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel2</cstring> + <cstring>TextLabel2_2</cstring> </property> <property stdset="1"> <name>text</name> <string>State</string> </property> </widget> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>State_LBL</cstring> </property> <property stdset="1"> <name>text</name> <string>State</string> </property> <property stdset="1"> <name>indent</name> <number>0</number> </property> </widget> <spacer> <property> <name>name</name> - <cstring>Spacer6</cstring> + <cstring>Spacer6_2</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </hbox> </widget> <widget> <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>Description_LBL</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>5</hsizetype> <vsizetype>7</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>frameShape</name> <enum>NoFrame</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Raised</enum> </property> <property stdset="1"> <name>text</name> <string></string> </property> <property stdset="1"> <name>alignment</name> <set>AlignTop|AlignLeft</set> </property> <property> <name>vAlign</name> </property> </widget> + <widget> + <class>QLayoutWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>Layout4</cstring> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <spacer> + <property> + <name>name</name> + <cstring>Spacer4</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Horizontal</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget> + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>ToMessages_BUT</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>0</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>text</name> + <string>Messages ...</string> + </property> + </widget> + </hbox> + </widget> + </vbox> + </widget> + <widget> + <class>QGroupBox</class> + <property stdset="1"> + <name>name</name> + <cstring>Messages_GB</cstring> + </property> + <property stdset="1"> + <name>title</name> + <string>Messages</string> + </property> + <property> + <name>layoutMargin</name> + </property> + <property> + <name>layoutSpacing</name> + </property> + <vbox> + <property stdset="1"> + <name>margin</name> + <number>4</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>2</number> + </property> + <widget> + <class>QListBox</class> + <property stdset="1"> + <name>name</name> + <cstring>Mesages_LB</cstring> + </property> + </widget> + <widget> + <class>QLayoutWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>Layout2</cstring> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <spacer> + <property> + <name>name</name> + <cstring>Spacer3</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Horizontal</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget> + <class>QPushButton</class> + <property stdset="1"> + <name>name</name> + <cstring>ToProfile_BUT</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Profile ...</string> + </property> + </widget> + </hbox> + </widget> </vbox> </widget> </vbox> </widget> <connections> <connection> <sender>Add_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_AddNode()</slot> </connection> <connection> <sender>Delete_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_DeleteNode()</slot> </connection> <connection> <sender>CheckState_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_CheckState()</slot> </connection> <connection> <sender>Enable_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_Enable()</slot> </connection> <connection> <sender>Connect_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_Connect()</slot> </connection> <connection> <sender>On_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_On()</slot> </connection> <connection> <sender>GenConfig_TB</sender> <signal>clicked()</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_GenerateConfig()</slot> </connection> <connection> <sender>Profiles_LB</sender> <signal>clicked(QListBoxItem*)</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_ShowNode( QListBoxItem*)</slot> </connection> <connection> <sender>Profiles_LB</sender> <signal>currentChanged(QListBoxItem*)</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_ShowNode( QListBoxItem*)</slot> </connection> <connection> <sender>Profiles_LB</sender> <signal>doubleClicked(QListBoxItem*)</signal> <receiver>NetworkSettingsGUI</receiver> <slot>SLOT_EditNode( QListBoxItem *)</slot> </connection> + <connection> + <sender>ToProfile_BUT</sender> + <signal>clicked()</signal> + <receiver>NetworkSettingsGUI</receiver> + <slot>SLOT_ToProfile()</slot> + </connection> + <connection> + <sender>ToMessages_BUT</sender> + <signal>clicked()</signal> + <receiver>NetworkSettingsGUI</receiver> + <slot>SLOT_ToMessages()</slot> + </connection> <slot access="public">SLOT_AddNode()</slot> <slot access="public">SLOT_CheckState()</slot> <slot access="public">SLOT_Connect()</slot> <slot access="public">SLOT_DeleteNode()</slot> <slot access="public">SLOT_EditNode( QListBoxItem *)</slot> <slot access="public">SLOT_Enable()</slot> <slot access="public">SLOT_GenerateConfig()</slot> <slot access="public">SLOT_On()</slot> <slot access="public">SLOT_ShowNode( QListBoxItem*)</slot> + <slot access="public">SLOT_ToMessages()</slot> + <slot access="public">SLOT_ToProfile()</slot> + <slot access="public">SLOT_Disconnect()</slot> </connections> </UI> diff --git a/noncore/settings/networksettings2/ppp/ppprun.cpp b/noncore/settings/networksettings2/ppp/ppprun.cpp index 8c75df3..a8abc50 100644 --- a/noncore/settings/networksettings2/ppp/ppprun.cpp +++ b/noncore/settings/networksettings2/ppp/ppprun.cpp @@ -1,82 +1,82 @@ #include <resources.h> #include "ppprun.h" PPPRun::PPPRun( ANetNodeInstance * NNI, PPPData & Data ) : AsConnection( NNI ), AsDevice( NNI ), Pat( "eth[0-9]" ) { D = &Data; } void PPPRun::detectState( NodeCollection * NC ) { if( isMyPPPDRunning( ) ) { if( isMyPPPUp() ) { NC->setCurrentState( IsUp ); } else { NC->setCurrentState( Available ); } } else { NC->setCurrentState( Off ); // at least this // but could also be unavailable AsDevice::netNode()->nextNode()->runtime()->detectState( NC ); } } -bool PPPRun::setState( NodeCollection * NC, Action_t A ) { +bool PPPRun::setState( NodeCollection * NC, Action_t A, bool ) { switch( A ) { case Activate : NC->setCurrentState( Available ); // no break; case Deactivate : if( NC->currentState() == IsUp ) { NC->state( Down ); } // cannot really disable NC->setCurrentState( Available ); break; case Up : if( NC->currentState() != IsUp ) { // start my PPPD NC->setCurrentState( IsUp ); } break; case Down : if( NC->currentState() == IsUp ) { // stop my PPPD NC->setCurrentState( Available ); } break; default : // FT break; } return 1; } bool PPPRun::isMyPPPDRunning( void ) { return 0; } bool PPPRun::isMyPPPUp( void ) { System & S = NSResources->system(); InterfaceInfo * Run; QRegExp R( "ppp[0-9]" ); for( QDictIterator<InterfaceInfo> It(S.interfaces()); It.current(); ++It ) { Run = It.current(); if( R.match( Run->Name ) >= 0 && Run->IsPointToPoint ) { // this is a LAN card if( Run->assignedNode() == AsDevice::netNode() ) { // assigned to us return 1; } } } return 0; } bool PPPRun::handlesInterface( const QString & S ) { return Pat.match( S ) >= 0; } diff --git a/noncore/settings/networksettings2/ppp/ppprun.h b/noncore/settings/networksettings2/ppp/ppprun.h index af51fbe..90a3f25 100644 --- a/noncore/settings/networksettings2/ppp/ppprun.h +++ b/noncore/settings/networksettings2/ppp/ppprun.h @@ -1,47 +1,47 @@ #ifndef PPPRUN_H #define PPPRUN_H #include <qregexp.h> #include <asconnection.h> #include <asdevice.h> #include "pppdata.h" class PPPRun : public AsConnection, public AsDevice { public : PPPRun( ANetNodeInstance * NNI, PPPData & Data ); virtual AsDevice * asDevice( void ) { return (AsDevice *)this; } virtual AsConnection * asConnection( void ) { return (AsConnection *)this; } virtual AsDevice * device( void ) { return (AsDevice *)this; } virtual RuntimeInfo * runtimeInfo( void ) { return ( AsConnection *)this; } protected : void detectState( NodeCollection * NC ); - bool setState( NodeCollection * NC, Action_t A ); + bool setState( NodeCollection * NC, Action_t A, bool ); bool canSetState( State_t S, Action_t A ) { return AsDevice::connection()->findNext( AsDevice::netNode() )->runtime()->canSetState( S,A ); } bool handlesInterface( const QString & I ); private : bool isMyPPPDRunning( void ); bool isMyPPPUp( void ); PPPData_t * D; QRegExp Pat; }; #endif diff --git a/noncore/settings/networksettings2/profile/profileedit.cpp b/noncore/settings/networksettings2/profile/profileedit.cpp index 3f72c52..c9fb650 100644 --- a/noncore/settings/networksettings2/profile/profileedit.cpp +++ b/noncore/settings/networksettings2/profile/profileedit.cpp @@ -1,93 +1,96 @@ #include <qlabel.h> #include <qframe.h> #include <qcheckbox.h> #include <qmultilineedit.h> #include <qcheckbox.h> #include <GUIUtils.h> #include <asdevice.h> #include <resources.h> #include "profileedit.h" ProfileEdit::ProfileEdit( QWidget * Parent, ANetNodeInstance * TNNI ) : - ProfileGUI( Parent ), TrafficRefresh(this) { + ProfileGUI( Parent ), RefreshTimer(this) { InterfaceInfo * II; NNI = TNNI; Dev = NNI->runtime()->device(); if( ( II = Dev->assignedInterface() ) ) { + Refresh_CB->setEnabled( TRUE ); Snd_GB->setEnabled( TRUE ); Rcv_GB->setEnabled( TRUE ); Collisions_FRM->setEnabled( TRUE ); + // show current content SLOT_Refresh(); // fill in static data InterfaceName_LBL->setText( II->Name ); IPAddress_LBL->setText( II->Address ); SubnetMask_LBL->setText( II->Netmask ); Broadcast_LBL->setText( II->BCastAddress ); MACAddress_LBL->setText( II->MACAddress ); if( II->IsPointToPoint ) { PointToPoint_LBL->setText( II->DstAddress ); } QString S; InterfaceName_LBL->setText( II->Name ); if( II->HasMulticast ) { S += "Multicast"; } if( ! S.isEmpty() ) { S.prepend( " : " ); } InterfaceOptions_LBL->setText( S ); + + connect( &RefreshTimer, SIGNAL( timeout() ), + this, SLOT( SLOT_Refresh() ) ); } - connect( &TrafficRefresh, SIGNAL( timeout() ), - this, SLOT( SLOT_Refresh() ) ); } QString ProfileEdit::acceptable( void ) { return QString(); } void ProfileEdit::showData( ProfileData_t & Data ) { Description_LE->setText( Data.Description ); Automatic_CB->setChecked( Data.Automatic ); Confirm_CB->setChecked( Data.Confirm ); Disabled_CB->setChecked( Data.Disabled ); } bool ProfileEdit::commit( ProfileData_t & Data ) { bool SM = 0; TXTM( Data.Description, Description_LE, SM ); CBM( Data.Automatic, Automatic_CB, SM ); CBM( Data.Disabled, Disabled_CB, SM ); CBM( Data.Confirm, Confirm_CB, SM ); return SM; } void ProfileEdit::SLOT_Refresh( void ) { InterfaceInfo * II = Dev->assignedInterface(); NSResources->system().refreshStatistics( *II ); RcvBytes_LBL->setText( II->RcvBytes ); SndBytes_LBL->setText( II->SndBytes ); RcvErrors_LBL->setText( II->RcvErrors ); SndErrors_LBL->setText( II->SndErrors ); RcvDropped_LBL->setText( II->RcvDropped ); SndDropped_LBL->setText( II->SndDropped ); Collisions_LBL->setText( II->Collisions ); } void ProfileEdit::SLOT_AutoRefresh( bool ar ) { if( ar ) { - TrafficRefresh.start( 1000 ); + RefreshTimer.start( 1000 ); SLOT_Refresh(); } else { - TrafficRefresh.stop(); + RefreshTimer.stop(); } } diff --git a/noncore/settings/networksettings2/profile/profileedit.h b/noncore/settings/networksettings2/profile/profileedit.h index 8ca34be..b186b58 100644 --- a/noncore/settings/networksettings2/profile/profileedit.h +++ b/noncore/settings/networksettings2/profile/profileedit.h @@ -1,29 +1,29 @@ #include "profiledata.h" #include "profileGUI.h" #include <qtimer.h> class ANetNodeInstance; class AsDevice; class ProfileEdit : public ProfileGUI { Q_OBJECT public : ProfileEdit( QWidget * parent, ANetNodeInstance * NNI ); QString acceptable( void ); bool commit( ProfileData_t & Data ); void showData( ProfileData_t & Data ); public slots : void SLOT_AutoRefresh( bool ); void SLOT_Refresh( void ); private : - QTimer TrafficRefresh; + QTimer RefreshTimer; ANetNodeInstance * NNI; AsDevice * Dev; }; diff --git a/noncore/settings/networksettings2/profile/profilerun.cpp b/noncore/settings/networksettings2/profile/profilerun.cpp index feebf86..79bb93e 100644 --- a/noncore/settings/networksettings2/profile/profilerun.cpp +++ b/noncore/settings/networksettings2/profile/profilerun.cpp @@ -1,65 +1,65 @@ #include <resources.h> #include "profilerun.h" void ProfileRun::detectState( NodeCollection * NC ) { if( Data->Disabled ) { NC->setCurrentState( Disabled ); } else { // find next item in connection // convert to runtime and ask to detect the state netNode()->nextNode()->runtime()->detectState( NC ); } } -bool ProfileRun::setState( NodeCollection * NC, Action_t A ) { +bool ProfileRun::setState( NodeCollection * NC, Action_t A, bool ) { ANetNodeInstance * NNNI; NNNI = netNode()->nextNode(); switch ( A ) { case Enable : if( NC->currentState() == Disabled ) { Data->Disabled = 0; NC->setCurrentState( Off ); // at least // ... but request deeper NNNI->runtime()->detectState(NC); } return 1; case Disable : switch( NC->currentState() ) { case IsUp : case Available : // bring Deactivate (will bring down) if( ! NNNI->runtime()->setState(NC, Deactivate) ) return 0; default : break; } Data->Disabled = 1; NC->setCurrentState( Disabled ); return 1; default : break; } return NNNI->runtime()->setState(NC, A); } bool ProfileRun::canSetState( State_t Curr, Action_t A ) { RuntimeInfo * RI; switch ( A ) { case Enable : case Disable : // always possible return 1; default : break; } RI = netNode()->nextNode()->runtime(); return ( Curr != Disabled ) ? RI->canSetState(Curr, A) : 0; } bool ProfileRun::handlesInterface( const QString & S ) { // donno -> pass deeper return netNode()->nextNode()->runtime()->handlesInterface(S); } diff --git a/noncore/settings/networksettings2/profile/profilerun.h b/noncore/settings/networksettings2/profile/profilerun.h index 6e8385c..c8ea063 100644 --- a/noncore/settings/networksettings2/profile/profilerun.h +++ b/noncore/settings/networksettings2/profile/profilerun.h @@ -1,31 +1,31 @@ #ifndef PROFILERUN_H #define PROFILERUN_H #include <asfullsetup.h> #include "profiledata.h" class ProfileRun : public AsFullSetup { public : ProfileRun( ANetNodeInstance * NNI, ProfileData & D ) : AsFullSetup( NNI ) { Data = &D; } void detectState( NodeCollection * NC ); - bool setState( NodeCollection * NC, Action_t A ); + bool setState( NodeCollection * NC, Action_t A, bool ); bool canSetState( State_t Curr, Action_t A ); bool handlesInterface( const QString & I ); virtual const QString & description( void ) { return Data->Description; } virtual AsFullSetup * asFullSetup( void ) { return (AsFullSetup *)this; } private : ProfileData * Data; }; #endif diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp index 4ce6721..beacd7b 100644 --- a/noncore/settings/networksettings2/usb/usbrun.cpp +++ b/noncore/settings/networksettings2/usb/usbrun.cpp @@ -1,176 +1,176 @@ #include <qfile.h> #include <qfileinfo.h> #include <qtextstream.h> #include <resources.h> #include "usbrun.h" void USBRun::detectState( NodeCollection * NC ) { // unavailable : no card found // available : card found and assigned to us or free // up : card found and assigned to us and up QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); System & Sys = NSResources->system(); InterfaceInfo * Run; QFile F( S ); if( F.open( IO_ReadOnly ) ) { // could open file -> read interface and assign QString X; QTextStream TS(&F); X = TS.readLine(); // find interface if( handlesInterface( X ) ) { for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); if( X == Run->Name ) { Run->assignNode( netNode() ); assignInterface( Run ); NC->setCurrentState( IsUp ); return; } } } } fprintf( stderr, "Assigned %p\n", assignedInterface() ); if( ( Run = assignedInterface() ) ) { // we already have an interface assigned -> still present ? if( ! Run->IsUp ) { // usb is still free -> keep assignment NC->setCurrentState( Available ); return; } // else interface is up but NOT us -> some other profile } // nothing (valid) assigned to us assignInterface( 0 ); // find possible interface for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); It.current(); ++It ) { Run = It.current(); fprintf( stderr, "%s %d %d=%d %d\n", Run->Name.latin1(), handlesInterface( Run->Name ), Run->CardType, ARPHRD_ETHER, ! Run->IsUp ); if( handlesInterface( Run->Name ) && Run->CardType == ARPHRD_ETHER && ! Run->IsUp ) { fprintf( stderr, "Released(OFF)\n" ); // proper type, and Not UP -> free NC->setCurrentState( Off ); return; } } // no free found fprintf( stderr, "UNA\n" ); NC->setCurrentState( Unavailable ); } -bool USBRun::setState( NodeCollection * NC, Action_t A ) { +bool USBRun::setState( NodeCollection * NC, Action_t A, bool ) { // we only handle activate and deactivate switch( A ) { case Activate : { if( NC->currentState() != Off ) { return 0; } InterfaceInfo * N = getInterface(); if( ! N ) { // no interface available NC->setCurrentState( Unavailable ); return 0; } // because we were OFF the interface // we get back is NOT assigned N->assignNode( netNode() ); assignInterface( N ); fprintf( stderr, "Assing %p\n", N ); NC->setCurrentState( Available ); return 1; } case Deactivate : if( NC->currentState() == IsUp ) { // bring down first if( ! connection()->setState( Down ) ) // could not ... return 0; } else if( NC->currentState() != Available ) { return 1; } assignedInterface()->assignNode( 0 ); // release assignInterface( 0 ); NC->setCurrentState( Off ); return 1; default : // FT break; } return 0; } bool USBRun::canSetState( State_t Curr, Action_t A ) { // we only handle up down activate and deactivate switch( A ) { case Activate : { // at least available if( Curr == Available ) { return 1; } // or we can make one available InterfaceInfo * N = getInterface(); if( ! N || N->assignedNode() != 0 ) { // non available or assigned return 0; } return 1; } case Deactivate : return ( Curr >= Available ); default : // FT break; } return 0; } // get interface that is free or assigned to us InterfaceInfo * USBRun::getInterface( void ) { System & S = NSResources->system(); InterfaceInfo * best = 0, * Run; QRegExp R( "usb[0-9abcdef]" ); for( QDictIterator<InterfaceInfo> It(S.interfaces()); It.current(); ++It ) { Run = It.current(); if( handlesInterface( Run->Name ) && Run->CardType == ARPHRD_ETHER ) { // this is a USB card if( Run->assignedNode() == netNode() ) { // assigned to us return Run; } else if( Run->assignedNode() == 0 ) { // free best = Run; } } } return best; // can be 0 } bool USBRun::handlesInterface( const QString & S ) { return Pat.match( S ) >= 0; } diff --git a/noncore/settings/networksettings2/usb/usbrun.h b/noncore/settings/networksettings2/usb/usbrun.h index 6c6e4e4..03e21ab 100644 --- a/noncore/settings/networksettings2/usb/usbrun.h +++ b/noncore/settings/networksettings2/usb/usbrun.h @@ -1,37 +1,37 @@ #ifndef USBRUN_H #define USBRUN_H #include <asdevice.h> #include <qregexp.h> #include "usbdata.h" class USBRun : public AsDevice { public : USBRun( ANetNodeInstance * NNI, USBData & Data ) : AsDevice( NNI ), Pat( "usb[0-9abcdef]" ) { } virtual AsDevice * device( void ) { return (AsDevice *)this; } virtual AsDevice * asDevice( void ) { return (AsDevice *)this; } protected : void detectState( NodeCollection * ); - bool setState( NodeCollection * , Action_t A ); + bool setState( NodeCollection * , Action_t A, bool ); bool canSetState( State_t , Action_t A ); bool handlesInterface( const QString & I ); private : InterfaceInfo * getInterface( void ); QRegExp Pat; }; #endif diff --git a/noncore/settings/networksettings2/vpn/vpnrun.h b/noncore/settings/networksettings2/vpn/vpnrun.h index 4d26298..c19b609 100644 --- a/noncore/settings/networksettings2/vpn/vpnrun.h +++ b/noncore/settings/networksettings2/vpn/vpnrun.h @@ -1,32 +1,32 @@ #ifndef VPNRUN_H #define VPNRUN_H #include <asconnection.h> #include "vpndata.h" class VPNRun : public AsConnection { public : VPNRun( ANetNodeInstance * NNI, VPNData & Data ) : AsConnection( NNI ) { } virtual AsConnection * asConnection( void ) { return (AsConnection *)this; } protected : void detectState( NodeCollection * ) { } - bool setState( NodeCollection *, Action_t ) + bool setState( NodeCollection *, Action_t, bool ) { return 0; } bool canSetState( State_t, Action_t ) { return 0; } bool handlesInterface( const QString & I ); }; #endif diff --git a/noncore/settings/networksettings2/wlan/wlanGUI.ui b/noncore/settings/networksettings2/wlan/wlanGUI.ui index 9614369..1aec138 100644 --- a/noncore/settings/networksettings2/wlan/wlanGUI.ui +++ b/noncore/settings/networksettings2/wlan/wlanGUI.ui @@ -1,975 +1,1021 @@ <!DOCTYPE UI><UI> <class>WLanGUI</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>WLanGUI</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>192</width> - <height>329</height> + <width>209</width> + <height>307</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Form1</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>0</number> + <number>1</number> </property> <widget> <class>QTabWidget</class> <property stdset="1"> <name>name</name> <cstring>WLan_TAB</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>true</bool> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>ConfigPage</cstring> </property> <attribute> <name>title</name> <string>General</string> </attribute> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>Layout6</cstring> + <cstring>Layout11</cstring> </property> <property> - <name>layoutMargin</name> + <name>layoutSpacing</name> </property> <grid> <property stdset="1"> <name>margin</name> - <number>1</number> + <number>0</number> </property> <property stdset="1"> <name>spacing</name> - <number>6</number> + <number>1</number> </property> - <widget row="1" column="0" > - <class>QLabel</class> + <widget row="0" column="1" > + <class>QComboBox</class> + <item> + <property> + <name>text</name> + <string>Auto</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>Managed</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>Ad-Hoc</string> + </property> + </item> <property stdset="1"> <name>name</name> - <cstring>essidLabel</cstring> + <cstring>Mode_CB</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>true</bool> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>1</hsizetype> - <vsizetype>1</vsizetype> + <vsizetype>0</vsizetype> </sizepolicy> </property> - <property stdset="1"> - <name>text</name> - <string>ESS-ID</string> - </property> </widget> - <widget row="1" column="1" > - <class>QComboBox</class> - <item> - <property> - <name>text</name> - <string>any</string> - </property> - </item> + <widget row="2" column="0" > + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>ESSID_CB</cstring> - </property> - <property stdset="1"> - <name>sizePolicy</name> - <sizepolicy> - <hsizetype>7</hsizetype> - <vsizetype>0</vsizetype> - </sizepolicy> + <cstring>essidLabel_2</cstring> </property> <property stdset="1"> - <name>editable</name> + <name>enabled</name> <bool>true</bool> </property> <property stdset="1"> - <name>currentItem</name> - <number>0</number> - </property> - <property stdset="1"> - <name>sizeLimit</name> - <number>5</number> - </property> - <property stdset="1"> - <name>autoCompletion</name> - <bool>true</bool> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> </property> <property stdset="1"> - <name>duplicatesEnabled</name> - <bool>false</bool> + <name>text</name> + <string>Name</string> </property> </widget> <widget row="0" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>modeLabel</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>true</bool> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>1</hsizetype> <vsizetype>1</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>Mode</string> </property> </widget> - <widget row="0" column="1" > - <class>QComboBox</class> - <item> - <property> - <name>text</name> - <string>Infrastructure</string> - </property> - </item> - <item> - <property> - <name>text</name> - <string>Auto</string> - </property> - </item> - <item> - <property> - <name>text</name> - <string>Managed</string> - </property> - </item> - <item> - <property> - <name>text</name> - <string>Ad-Hoc</string> - </property> - </item> + <widget row="1" column="1" > + <class>QLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>Mode_CB</cstring> + <cstring>ESSID_LE</cstring> + </property> + </widget> + <widget row="1" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>essidLabel</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>true</bool> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>1</hsizetype> - <vsizetype>0</vsizetype> + <vsizetype>1</vsizetype> </sizepolicy> </property> + <property stdset="1"> + <name>text</name> + <string>ESS-ID</string> + </property> + </widget> + <widget row="2" column="1" > + <class>QLineEdit</class> + <property stdset="1"> + <name>name</name> + <cstring>NodeName_LE</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string><UseHostName></string> + </property> </widget> </grid> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout8</cstring> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <grid> <property stdset="1"> <name>margin</name> <number>1</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget row="0" column="0" rowspan="1" colspan="3" > <class>QCheckBox</class> <property stdset="1"> <name>name</name> <cstring>SpecifyAP_CB</cstring> </property> <property stdset="1"> <name>text</name> - <string>Specify &Access Point</string> + <string>Specify Access Point</string> </property> </widget> <widget row="1" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>macLabel</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>0</hsizetype> <vsizetype>1</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>MAC</string> </property> </widget> <widget row="1" column="2" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>APMac_LE</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>1</vsizetype> </sizepolicy> </property> </widget> <spacer row="1" column="0" > <property> <name>name</name> <cstring>Spacer8</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Horizontal</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Fixed</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </grid> </widget> - <widget> - <class>QLayoutWidget</class> - <property stdset="1"> - <name>name</name> - <cstring>Layout7</cstring> - </property> - <property> - <name>layoutMargin</name> - </property> - <hbox> - <property stdset="1"> - <name>margin</name> - <number>1</number> - </property> - <property stdset="1"> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QCheckBox</class> - <property stdset="1"> - <name>name</name> - <cstring>SpecifyChannel_CB</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Specific &Channel</string> - </property> - </widget> - <widget> - <class>QSpinBox</class> - <property stdset="1"> - <name>name</name> - <cstring>ChannelNr_SB</cstring> - </property> - <property stdset="1"> - <name>enabled</name> - <bool>false</bool> - </property> - <property stdset="1"> - <name>maxValue</name> - <number>15</number> - </property> - <property stdset="1"> - <name>minValue</name> - <number>1</number> - </property> - <property stdset="1"> - <name>value</name> - <number>1</number> - </property> - </widget> - </hbox> - </widget> <spacer> <property> <name>name</name> <cstring>Spacer7</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </vbox> </widget> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>WepPage</cstring> </property> <attribute> <name>title</name> <string>Encryption</string> </attribute> <vbox> <property stdset="1"> <name>margin</name> <number>2</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QCheckBox</class> <property stdset="1"> <name>name</name> - <cstring>EnableWEB_CB</cstring> + <cstring>EnableWEP_CB</cstring> </property> <property stdset="1"> <name>text</name> <string>&Enable Encryption</string> </property> </widget> <widget> <class>QButtonGroup</class> <property stdset="1"> <name>name</name> <cstring>KeyButtonGroup</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>title</name> <string>&Key Setting</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <grid> <property stdset="1"> <name>margin</name> <number>2</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget row="0" column="0" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>Key1_RB</cstring> </property> <property stdset="1"> <name>text</name> <string>Key &1</string> </property> <property stdset="1"> <name>checked</name> <bool>true</bool> </property> </widget> <widget row="3" column="0" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>Key4_RB</cstring> </property> <property stdset="1"> <name>text</name> <string>Key &4</string> </property> </widget> <widget row="0" column="1" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>Key1_LE</cstring> </property> <property stdset="1"> <name>frame</name> <bool>true</bool> </property> </widget> <widget row="1" column="0" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>Key2_RB</cstring> </property> <property stdset="1"> <name>text</name> <string>Key &2</string> </property> </widget> <widget row="2" column="0" > <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>Key3_RB</cstring> </property> <property stdset="1"> <name>text</name> <string>Key &3</string> </property> </widget> <widget row="1" column="1" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>Key2_LE</cstring> </property> + <property stdset="1"> + <name>enabled</name> + <bool>false</bool> + </property> </widget> <widget row="3" column="1" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>Key4_LE</cstring> </property> + <property stdset="1"> + <name>enabled</name> + <bool>false</bool> + </property> </widget> <widget row="2" column="1" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>Key3_LE</cstring> </property> + <property stdset="1"> + <name>enabled</name> + <bool>false</bool> + </property> </widget> </grid> </widget> <widget> <class>QCheckBox</class> <property stdset="1"> <name>name</name> - <cstring>CheckBox4</cstring> + <cstring>AcceptNonEncrypted_CB</cstring> </property> <property stdset="1"> <name>enabled</name> <bool>false</bool> </property> <property stdset="1"> <name>text</name> <string>Accept Non-Encrypted packets</string> </property> </widget> <spacer> <property> <name>name</name> <cstring>Spacer30</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </vbox> </widget> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>tab</cstring> </property> <attribute> <name>title</name> <string>State</string> </attribute> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>Layout12</cstring> + <cstring>Layout13</cstring> </property> <property> <name>layoutSpacing</name> </property> <grid> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> - <widget row="0" column="0" > - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel1_3</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Station</string> - </property> - </widget> - <widget row="3" column="1" > + <widget row="4" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>Channel_LBL</cstring> + <cstring>Frequency_LBL</cstring> </property> <property stdset="1"> <name>frameShape</name> - <enum>Panel</enum> + <enum>Box</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Plain</enum> </property> <property stdset="1"> <name>indent</name> <number>0</number> </property> </widget> - <widget row="3" column="0" > - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel4_3</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Channel</string> - </property> - </widget> <widget row="2" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel3_3</cstring> + <cstring>TextLabel9_2</cstring> </property> <property stdset="1"> <name>text</name> - <string>Mode</string> + <string>AP</string> </property> </widget> - <widget row="1" column="0" > + <widget row="5" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel2_3</cstring> + <cstring>Channel_LBL</cstring> </property> <property stdset="1"> - <name>text</name> - <string>ESSID</string> + <name>frameShape</name> + <enum>Box</enum> </property> - </widget> - <widget row="4" column="0" > - <class>QLabel</class> <property stdset="1"> - <name>name</name> - <cstring>TextLabel9_2</cstring> + <name>frameShadow</name> + <enum>Plain</enum> </property> <property stdset="1"> - <name>text</name> - <string>AP</string> + <name>indent</name> + <number>0</number> </property> </widget> <widget row="0" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>Station_LBL</cstring> </property> <property stdset="1"> <name>frameShape</name> - <enum>Panel</enum> + <enum>Box</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Plain</enum> </property> <property stdset="1"> <name>indent</name> <number>0</number> </property> </widget> - <widget row="5" column="1" > + <widget row="6" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel4_2_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Rate</string> + </property> + </widget> + <widget row="6" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>Rate_LBL</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>1</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>frameShape</name> - <enum>Panel</enum> + <enum>Box</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Plain</enum> </property> <property stdset="1"> <name>indent</name> <number>0</number> </property> </widget> - <widget row="5" column="0" > + <widget row="2" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel4_2_2</cstring> + <cstring>AP_LBL</cstring> </property> <property stdset="1"> - <name>text</name> - <string>Rate</string> + <name>frameShape</name> + <enum>Box</enum> + </property> + <property stdset="1"> + <name>frameShadow</name> + <enum>Plain</enum> + </property> + <property stdset="1"> + <name>indent</name> + <number>0</number> </property> </widget> - <widget row="4" column="1" > + <widget row="3" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>AP_LBL</cstring> + <cstring>Mode_LBL</cstring> </property> <property stdset="1"> <name>frameShape</name> - <enum>Panel</enum> + <enum>Box</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Plain</enum> </property> <property stdset="1"> <name>indent</name> <number>0</number> </property> </widget> <widget row="1" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>ESSID_LBL</cstring> </property> <property stdset="1"> <name>frameShape</name> - <enum>Panel</enum> + <enum>Box</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Plain</enum> </property> <property stdset="1"> <name>indent</name> <number>0</number> </property> </widget> - <widget row="2" column="1" > + <widget row="3" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>Mode_LBL</cstring> + <cstring>TextLabel3_3</cstring> </property> <property stdset="1"> - <name>frameShape</name> - <enum>Panel</enum> + <name>text</name> + <string>Mode</string> </property> + </widget> + <widget row="5" column="0" > + <class>QLabel</class> <property stdset="1"> - <name>frameShadow</name> - <enum>Plain</enum> + <name>name</name> + <cstring>TextLabel4_3</cstring> </property> <property stdset="1"> - <name>indent</name> - <number>0</number> + <name>text</name> + <string>Channel</string> + </property> + </widget> + <widget row="0" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel1_3</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Station</string> + </property> + </widget> + <widget row="1" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel2_3</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>ESSID</string> + </property> + </widget> + <widget row="4" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel4_3_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Frequency</string> </property> </widget> </grid> </widget> <widget> <class>QGroupBox</class> <property stdset="1"> <name>name</name> <cstring>GroupBox1</cstring> </property> <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> <name>title</name> <string>Link Quality</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <grid> <property stdset="1"> <name>margin</name> <number>2</number> </property> <property stdset="1"> <name>spacing</name> - <number>2</number> + <number>0</number> </property> <widget row="1" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel2_2_2</cstring> </property> <property stdset="1"> <name>text</name> <string>Noise</string> </property> </widget> <widget row="2" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel3_2_2</cstring> </property> <property stdset="1"> <name>text</name> <string>Quality</string> </property> </widget> <widget row="1" column="2" > <class>QProgressBar</class> <property stdset="1"> <name>name</name> <cstring>Noise_PB</cstring> </property> <property stdset="1"> <name>progress</name> - <number>0</number> + <number>10</number> </property> </widget> <widget row="2" column="2" > <class>QProgressBar</class> <property stdset="1"> <name>name</name> <cstring>Quality_PB</cstring> </property> <property stdset="1"> <name>progress</name> - <number>0</number> + <number>10</number> </property> </widget> <widget row="0" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel1_2_2</cstring> </property> <property stdset="1"> <name>text</name> <string>Signal</string> </property> </widget> - <spacer row="0" column="1" > - <property> - <name>name</name> - <cstring>Spacer28</cstring> - </property> - <property stdset="1"> - <name>orientation</name> - <enum>Horizontal</enum> - </property> - <property stdset="1"> - <name>sizeType</name> - <enum>Fixed</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>16</width> - <height>20</height> - </size> - </property> - </spacer> <widget row="0" column="2" > <class>QProgressBar</class> <property stdset="1"> <name>name</name> <cstring>Signal_PB</cstring> </property> <property stdset="1"> <name>frameShadow</name> <enum>Plain</enum> </property> <property stdset="1"> <name>lineWidth</name> <number>1</number> </property> <property stdset="1"> <name>progress</name> - <number>0</number> + <number>10</number> </property> </widget> </grid> </widget> <spacer> <property> <name>name</name> <cstring>Spacer11</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> + <widget> + <class>QLayoutWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>Layout21</cstring> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget> + <class>QCheckBox</class> + <property stdset="1"> + <name>name</name> + <cstring>Refresh_CB</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>5</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>text</name> + <string>Live feed </string> + </property> + </widget> + <spacer> + <property> + <name>name</name> + <cstring>Spacer16</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Horizontal</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> </vbox> </widget> </widget> </vbox> </widget> <connections> <connection> - <sender>EnableWEB_CB</sender> + <sender>EnableWEP_CB</sender> <signal>toggled(bool)</signal> <receiver>KeyButtonGroup</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>SpecifyAP_CB</sender> <signal>toggled(bool)</signal> <receiver>APMac_LE</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>SpecifyAP_CB</sender> <signal>toggled(bool)</signal> <receiver>macLabel</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> - <sender>SpecifyChannel_CB</sender> + <sender>EnableWEP_CB</sender> + <signal>toggled(bool)</signal> + <receiver>AcceptNonEncrypted_CB</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>Key1_RB</sender> + <signal>toggled(bool)</signal> + <receiver>Key1_LE</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>Key2_RB</sender> + <signal>toggled(bool)</signal> + <receiver>Key2_LE</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>Key3_RB</sender> <signal>toggled(bool)</signal> - <receiver>ChannelNr_SB</receiver> + <receiver>Key3_LE</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> - <sender>EnableWEB_CB</sender> + <sender>Key4_RB</sender> <signal>toggled(bool)</signal> - <receiver>CheckBox4</receiver> + <receiver>Key4_LE</receiver> <slot>setEnabled(bool)</slot> </connection> + <connection> + <sender>Refresh_CB</sender> + <signal>toggled(bool)</signal> + <receiver>WLanGUI</receiver> + <slot>SLOT_AutoRefresh(bool)</slot> + </connection> + <slot access="public">SLOT_AutoRefresh(bool)</slot> </connections> </UI> diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp index 78e756c..61969f2 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp @@ -1,36 +1,140 @@ +#include <unistd.h> #include "wlanedit.h" #include "wlan_NNI.h" #include "wlan_NN.h" AWLan::AWLan( WLanNetNode * PNN ) : ANetNodeInstance( PNN ) { GUI = 0; RT = 0; + Data.ESSID = ""; + Data.NodeName = tr("<UseHostName>"); + Data.Mode = 0; + Data.SpecificAP = 0; + Data.APMac = ""; + Data.Encrypted = 0; + Data.AcceptNonEncrypted = 0; + Data.Key[0] = ""; + Data.Key[1] = ""; + Data.Key[2] = ""; + Data.Key[3] = ""; } -void AWLan::setSpecificAttribute( QString & , QString & ) { +void AWLan::setSpecificAttribute( QString & A, QString & V ) { + if( A == "essid" ) { + Data.ESSID = V; + } else if( A == "nodename" ) { + Data.NodeName = V; + } else if( A == "mode" ) { + Data.Mode = V.toShort(); + } else if( A == "specificap" ) { + Data.SpecificAP = (V=="yes"); + } else if( A == "apmac" ) { + Data.APMac = V; + } else if( A == "encrypted" ) { + Data.Encrypted = (V=="yes"); + } else if( A == "acceptnonencrypted" ) { + Data.AcceptNonEncrypted = (V=="yes"); + } else if( A == "key0" ) { + Data.Key[0] = V; + } else if( A == "key1" ) { + Data.Key[1] = V; + } else if( A == "key2" ) { + Data.Key[2] = V; + } else if( A == "key3" ) { + Data.Key[3] = V; + } } -void AWLan::saveSpecificAttribute( QTextStream & ) { +void AWLan::saveSpecificAttribute( QTextStream & S ) { + S << "essid=" << quote( Data.ESSID ) << endl; + S << "nodename=" << quote( Data.NodeName ) << endl; + S << "mode=" << Data.Mode << endl; + S << "specificap=" + << ((Data.SpecificAP) ? "yes" : "no") + << endl; + S << "apmac=" << Data.APMac << endl; + S << "encrypted=" + << ((Data.Encrypted) ? "yes" : "no") + << endl; + S << "acceptnonencrypted=" + << ((Data.AcceptNonEncrypted) ? "yes" : "no") + << endl; + for( int i = 0 ;i < 4 ; i ++ ) { + S << "key" << i << "=" << Data.Key[i] << endl; + } } QWidget * AWLan::edit( QWidget * parent ) { - GUI = new WLanEdit( parent ); + GUI = new WLanEdit( parent, this ); GUI->showData( Data ); return GUI; } QString AWLan::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AWLan::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } bool AWLan::generateDataForCommonFile( - SystemFile &, + SystemFile & S, long ) { - return 1; + + S << " wireless_essid \"" + << Data.ESSID + << "\"" + << endl; + + if( ! Data.NodeName.isEmpty() ) { + if( Data.NodeName == tr("<UseHostName>") ) { + char Buf[100]; + if( gethostname(Buf, sizeof(Buf) ) == 0 ) { + Buf[99] = '\0'; // just to make sure + S << " wireless_nick " + << Buf + << endl; + } + } else { + S << " wireless_nick \"" + << Data.NodeName + << "\"" + << endl; + } + } + + char * M; + switch ( Data.Mode ) { + case 0 : + M = "Auto"; + break; + case 1 : + M = "Managed"; + break; + case 2 : + M = "Ad-Hoc"; + break; + } + + S << " wireless_mode " + << M + << endl; + if( Data.Encrypted ) { + for( int i = 0; i < 4; i ++ ) { + if( ! Data.Key[i].isEmpty() ) { + S << " wireless_key" + << i + << " " + << Data.Key[i] + << endl; + } + } + S << " wireless_keymode " + << ((Data.AcceptNonEncrypted) ? "open" : "restricted") + << endl; + } + return 0; } diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.h b/noncore/settings/networksettings2/wlan/wlan_NNI.h index d861d13..2211c47 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.h +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.h @@ -1,47 +1,47 @@ #ifndef WLAN_H #define WLAN_H #include <netnode.h> #include "wlandata.h" #include "wlanrun.h" class WLanNetNode; class WLanEdit; class AWLan : public ANetNodeInstance { public : AWLan( WLanNetNode * PNN ); QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); RuntimeInfo * runtime( void ) { if( RT == 0 ) RT = new WLanRun( this, Data ); return RT; } virtual void * data( void ) { return (void *)&Data; } virtual bool hasDataFor( const QString & ) - { return 0; } + { return 1; } virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : WLanEdit * GUI; WLanData Data; WLanRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/wlan/wlandata.h b/noncore/settings/networksettings2/wlan/wlandata.h index ba1f2c2..36990a9 100644 --- a/noncore/settings/networksettings2/wlan/wlandata.h +++ b/noncore/settings/networksettings2/wlan/wlandata.h @@ -1,17 +1,16 @@ #ifndef WLAN_DATA_H #define WLAN_DATA_H #include <qstring.h> typedef struct WLanData { - QString Device; - QString LockFile; - long Speed; - short Parity; - short DataBits; - short StopBits; - bool HardwareControl; - bool SoftwareControl; - + QString ESSID; + QString NodeName; + short Mode; + bool SpecificAP; + QString APMac; + bool Encrypted; + QString Key[4]; + bool AcceptNonEncrypted; } WLanData_t; #endif diff --git a/noncore/settings/networksettings2/wlan/wlanedit.cpp b/noncore/settings/networksettings2/wlan/wlanedit.cpp index c884886..8d3979e 100644 --- a/noncore/settings/networksettings2/wlan/wlanedit.cpp +++ b/noncore/settings/networksettings2/wlan/wlanedit.cpp @@ -1,16 +1,115 @@ +#include <qlineedit.h> +#include <qprogressbar.h> +#include <qcombobox.h> +#include <qlabel.h> +#include <qregexp.h> +#include <qcheckbox.h> #include <GUIUtils.h> +#include <resources.h> +#include <wextensions.h> + #include "wlanedit.h" +#include "wlan_NN.h" +#include "wlan_NNI.h" + +WLanEdit::WLanEdit( QWidget * Parent, ANetNodeInstance * TNNI ) : + WLanGUI( Parent ), RefreshTimer(this){ + + InterfaceInfo * II; + + NNI = TNNI; + Dev = NNI->runtime()->device(); + WE = 0; + if( ( II = Dev->assignedInterface() ) ) { + // show data + WE = new WExtensions( II->Name ); + + if( WE->doesHaveWirelessExtensions() ) { + QString S; + Station_LBL->setText( WE->station() ); + ESSID_LBL->setText( WE->essid() ); + Mode_LBL->setText( WE->mode() ); + S.setNum( WE->frequency() ); + Frequency_LBL->setText( S ); + S.setNum( WE->channel() ); + Channel_LBL->setText( S ); + S.setNum( WE->rate() ); + Rate_LBL->setText( S ); + AP_LBL->setText( WE->ap() ); + + SLOT_Refresh(); + + connect( &RefreshTimer, SIGNAL( timeout() ), + this, SLOT( SLOT_Refresh() ) ); + } + } +} -WLanEdit::WLanEdit( QWidget * Parent ) : WLanGUI( Parent ){ +WLanEdit::~WLanEdit( void ) { + if( WE ) + delete WE; } QString WLanEdit::acceptable( void ) { + if( ESSID_LE->text().isEmpty() ) { + return QString("ESSID is mandatory"); + } + if( SpecifyAP_CB->isChecked() && + APMac_LE->text().isEmpty() ) { + return QString("APMac must have value"); + } return QString(); } void WLanEdit::showData( WLanData_t & Data ) { + Mode_CB->setCurrentItem( Data.Mode ); + ESSID_LE->setText( Data.ESSID ); + NodeName_LE->setText( Data.NodeName ); + SpecifyAP_CB->setChecked( Data.SpecificAP ); + APMac_LE->setText( Data.APMac ); + + EnableWEP_CB->setChecked( Data.Encrypted ); + AcceptNonEncrypted_CB->setChecked( Data.AcceptNonEncrypted ); + Key1_LE->setText( Data.Key[0] ); + Key2_LE->setText( Data.Key[1] ); + Key3_LE->setText( Data.Key[2] ); + Key4_LE->setText( Data.Key[3] ); } bool WLanEdit::commit( WLanData_t & Data ) { + bool SM = 0; + + TXTM( Data.ESSID, ESSID_LE, SM ); + TXTM( Data.NodeName, NodeName_LE, SM ); + TXTM( Data.APMac, APMac_LE, SM ); + TXTM( Data.Key[0], Key1_LE, SM ); + TXTM( Data.Key[1], Key2_LE, SM ); + TXTM( Data.Key[2], Key3_LE, SM ); + TXTM( Data.Key[3], Key4_LE, SM ); + CBM( Data.SpecificAP, SpecifyAP_CB, SM ); + CBM( Data.Encrypted, EnableWEP_CB, SM ); + CBM( Data.AcceptNonEncrypted, AcceptNonEncrypted_CB, SM ); + CIM( Data.Mode, Mode_CB, SM ); return 0; } + +void WLanEdit::SLOT_Refresh( void ) { + if( WE ) { + int signal, noise, quality; + WE->stats( signal, noise, quality); + + Signal_PB->setProgress( signal ); + Noise_PB->setProgress( noise ); + Quality_PB->setProgress( quality ); + } +} + +void WLanEdit::SLOT_AutoRefresh( bool ar ) { + if( ar ) { + RefreshTimer.start( 1000 ); + SLOT_Refresh(); + } else { + RefreshTimer.stop(); + } +} + diff --git a/noncore/settings/networksettings2/wlan/wlanedit.h b/noncore/settings/networksettings2/wlan/wlanedit.h index b7442d5..e550c14 100644 --- a/noncore/settings/networksettings2/wlan/wlanedit.h +++ b/noncore/settings/networksettings2/wlan/wlanedit.h @@ -1,12 +1,32 @@ +#include <qtimer.h> +#include <wextensions.h> #include "wlandata.h" #include "wlanGUI.h" +class ANetNodeInstance; +class AsDevice; +class WExtensions; + class WLanEdit : public WLanGUI { public : - WLanEdit( QWidget * parent ); + WLanEdit( QWidget * parent, ANetNodeInstance * NNI ); + ~WLanEdit( void ); QString acceptable( void ); void showData( WLanData_t & Data ); bool commit( WLanData_t & Data ); + +public slots : + + void SLOT_AutoRefresh( bool ); + void SLOT_Refresh( void ); + +private : + + ANetNodeInstance * NNI; + AsDevice * Dev; + QTimer RefreshTimer; + WExtensions * WE; + }; diff --git a/noncore/settings/networksettings2/wlan/wlanrun.cpp b/noncore/settings/networksettings2/wlan/wlanrun.cpp index 79f11f7..3f1d4a9 100644 --- a/noncore/settings/networksettings2/wlan/wlanrun.cpp +++ b/noncore/settings/networksettings2/wlan/wlanrun.cpp @@ -1,5 +1,185 @@ + +#include <qfile.h> +#include <qtextstream.h> +#include <qstringlist.h> +#include <resources.h> #include "wlanrun.h" +void WLanRun::detectState( NodeCollection * NC ) { + + // unavailable : no card found + // available : card found and assigned to us or free + // up : card found and assigned to us and up + + QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); + System & Sys = NSResources->system(); + InterfaceInfo * Run; + + QFile F( S ); + + if( F.open( IO_ReadOnly ) ) { + // could open file -> read interface and assign + QString X; + QTextStream TS(&F); + X = TS.readLine(); + // find interface + if( handlesInterface( X ) ) { + for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( X == Run->Name ) { + Run->assignNode( netNode() ); + assignInterface( Run ); + NC->setCurrentState( IsUp ); + return; + } + } + } + } + + if( ( Run = assignedInterface() ) ) { + // we already have an interface assigned -> still present ? + if( ! Run->IsUp ) { + // usb is still free -> keep assignment + NC->setCurrentState( Available ); + return; + } // else interface is up but NOT us -> some other profile + } + + // nothing (valid) assigned to us + assignInterface( 0 ); + + // find possible interface + for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( handlesInterface( *Run ) && + ( Run->CardType == ARPHRD_ETHER +#ifdef ARPHRD_IEEE1394 + || Run->CardType == ARPHRD_IEEE1394 +#endif + ) && + ! Run->IsUp + ) { + // proper type, and Not UP -> free + NC->setCurrentState( Off ); + return; + } + } + // no free found + + NC->setCurrentState( Unavailable ); + +} + +bool WLanRun::setState( NodeCollection * NC, Action_t A, bool ) { + + // we only handle activate and deactivate + switch( A ) { + case Activate : + { + if( NC->currentState() != Off ) { + return 0; + } + InterfaceInfo * N = getInterface(); + if( ! N ) { + // no interface available + NC->setCurrentState( Unavailable ); + return 0; + } + // because we were OFF the interface + // we get back is NOT assigned + N->assignNode( netNode() ); + assignInterface( N ); + NC->setCurrentState( Available ); + return 1; + } + case Deactivate : + if( NC->currentState() == IsUp ) { + // bring down first + if( ! connection()->setState( Down ) ) + // could not ... + return 0; + } else if( NC->currentState() != Available ) { + return 1; + } + assignedInterface()->assignNode( 0 ); // release + assignInterface( 0 ); + NC->setCurrentState( Off ); + return 1; + default : + // FT + break; + } + return 0; +} + +bool WLanRun::canSetState( State_t Curr, Action_t A ) { + // we only handle up down activate and deactivate + switch( A ) { + case Activate : + { // at least available + if( Curr == Available ) { + return 1; + } + // or we can make one available + InterfaceInfo * N = getInterface(); + if( ! N || N->assignedNode() != 0 ) { + // non available or assigned + return 0; + } + return 1; + } + case Deactivate : + return ( Curr >= Available ); + default : + // FT + break; + } + return 0; +} + +// get interface that is free or assigned to us +InterfaceInfo * WLanRun::getInterface( void ) { + + System & S = NSResources->system(); + InterfaceInfo * best = 0, * Run; + + for( QDictIterator<InterfaceInfo> It(S.interfaces()); + It.current(); + ++It ) { + Run = It.current(); + if( handlesInterface( *Run ) && + ( Run->CardType == ARPHRD_ETHER +#ifdef ARPHRD_IEEE1394 + || Run->CardType == ARPHRD_IEEE1394 +#endif + ) + ) { + // this is a LAN card + if( Run->assignedNode() == netNode() ) { + // assigned to us + return Run; + } else if( Run->assignedNode() == 0 ) { + // free + best = Run; + } + } + } + return best; // can be 0 +} + bool WLanRun::handlesInterface( const QString & S ) { + InterfaceInfo * II; + II = NSResources->system().interface( S ); + if( ( II = NSResources->system().interface( S ) ) ) { + return handlesInterface( *II ); + } return Pat.match( S ) >= 0; } + +bool WLanRun::handlesInterface( const InterfaceInfo & II ) { + return ( Pat.match( II.Name ) < 0 ); +} diff --git a/noncore/settings/networksettings2/wlan/wlanrun.h b/noncore/settings/networksettings2/wlan/wlanrun.h index f46bcb7..25d5b96 100644 --- a/noncore/settings/networksettings2/wlan/wlanrun.h +++ b/noncore/settings/networksettings2/wlan/wlanrun.h @@ -1,40 +1,37 @@ #ifndef WLANRUN_H #define WLANRUN_H #include <qregexp.h> #include <asdevice.h> #include "wlandata.h" class WLanRun : public AsDevice { public : WLanRun( ANetNodeInstance * NNI, WLanData & Data ) : AsDevice( NNI ), Pat( "wlan[0-9]" ) { } virtual AsDevice * device( void ) { return (AsDevice *)this; } virtual AsDevice * asDevice( void ) { return (AsDevice *)this; } protected : - void detectState( NodeCollection * ) - { } - - bool setState( NodeCollection *, Action_t ) - { return 0; } - - bool canSetState( State_t, Action_t ) - { return 0; } - + void detectState( NodeCollection * ); + bool setState( NodeCollection *, Action_t, bool ); + bool canSetState( State_t, Action_t ); bool handlesInterface( const QString & I ); + bool handlesInterface( const InterfaceInfo & II ); private : + InterfaceInfo * getInterface( void ); QRegExp Pat; + WLanData * Data; }; #endif |