author | wimpie <wimpie> | 2004-04-04 11:42:05 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2004-04-04 11:42:05 (UTC) |
commit | 8d2d2664e5f544b8292806e617deb7a0e4170dc0 (patch) (side-by-side diff) | |
tree | 3e3764f82d52f8c32b0ed9d92c13ec483dc34114 | |
parent | 321f82bb3d43cbab358434fef52fe76f17e7d1e3 (diff) | |
download | opie-8d2d2664e5f544b8292806e617deb7a0e4170dc0.zip opie-8d2d2664e5f544b8292806e617deb7a0e4170dc0.tar.gz opie-8d2d2664e5f544b8292806e617deb7a0e4170dc0.tar.bz2 |
Error in generation of files
53 files changed, 517 insertions, 110 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h index e65b378..347da0c 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEPrun.h @@ -1,32 +1,36 @@ #include <asdevice.h> #include "bluetoothBNEPdata.h" class BluetoothBNEPRun : public AsDevice { public : BluetoothBNEPRun( ANetNodeInstance * NNI, BluetoothBNEPData & Data ) : AsDevice( NNI ) { } virtual long count( void ) { return 3; } virtual QString genNic( long nr ) { QString S; return S.sprintf( "bnep%ld", nr ); } + + virtual AsDevice * asDevice( void ) + { return (AsDevice *)this; } + virtual AsDevice * device( void ) { return asDevice(); } protected : void detectState( NodeCollection * ) { } bool setState( NodeCollection * , Action_t ) { 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 87116e2..6a7902a 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h @@ -1,22 +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 ) { return 0; } bool canSetState( State_t , Action_t ) { return 0; } }; diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp index 91be153..47272c4 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp @@ -4,117 +4,124 @@ // // // BLUETOOTH PAN/NAP node // // static const char * BluetoothBNEPNeeds[] = { 0 }; /** * Constructor, find all of the possible interfaces */ BluetoothBNEPNetNode::BluetoothBNEPNetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ BluetoothBNEPNetNode::~BluetoothBNEPNetNode(){ } const QString BluetoothBNEPNetNode::nodeDescription(){ return tr("\ <p>Sets up a bluetooth link using the bluetooth Network profile.</p>\ <p>Use this to connect two computing devices.</p>\ " ); } ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) { return new ABluetoothBNEP( this ); } const char ** BluetoothBNEPNetNode::needs( void ) { return BluetoothBNEPNeeds; } const char * BluetoothBNEPNetNode::provides( void ) { return "device"; } bool BluetoothBNEPNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool BluetoothBNEPNetNode::hasDataFor( const QString & ) { - return 0; +bool BluetoothBNEPNetNode::hasDataFor( const QString & S, bool DS ) { + return DS && S == "interfaces"; } bool BluetoothBNEPNetNode::generateDataForCommonFile( SystemFile & , long , ANetNodeInstance * ) { return 1; } +bool BluetoothBNEPNetNode::generateDeviceDataForCommonFile( + SystemFile & , + long , + ANetNodeInstance * ) { + return 1; +} + // // // BLUETOOTH PAN/NAP node // // static const char * BluetoothRFCOMMNeeds[] = { 0 }; BluetoothRFCOMMNetNode::BluetoothRFCOMMNetNode() : ANetNode() { } BluetoothRFCOMMNetNode::~BluetoothRFCOMMNetNode(){ } const QString BluetoothRFCOMMNetNode::nodeDescription(){ return tr("\ <p>Sets up a bluetooth link using the bluetooth serial profile.</p>\ <p>Use this to connect to a GSM.</p>\ " ); } ANetNodeInstance * BluetoothRFCOMMNetNode::createInstance( void ) { return new ABluetoothRFCOMM( this ); } const char ** BluetoothRFCOMMNetNode::needs( void ) { return BluetoothRFCOMMNeeds; } const char * BluetoothRFCOMMNetNode::provides( void ) { return "line"; } bool BluetoothRFCOMMNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 0; } -bool BluetoothRFCOMMNetNode::hasDataFor( const QString & ) { +bool BluetoothRFCOMMNetNode::hasDataFor( const QString &, bool ) { return 0; } bool BluetoothRFCOMMNetNode::generateDataForCommonFile( SystemFile & , long, ANetNodeInstance * ) { return 0; } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new BluetoothBNEPNetNode() ); PNN.append( new BluetoothRFCOMMNetNode() ); } } diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h index 705201c..d72b0d4 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h +++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h @@ -1,75 +1,79 @@ #ifndef BLUETOOTH_NETNODE_H #define BLUETOOTH_NETNODE_H #include "netnode.h" class ABluetoothBNEP; class BluetoothBNEPNetNode : public ANetNode { Q_OBJECT public: BluetoothBNEPNetNode(); virtual ~BluetoothBNEPNetNode(); virtual const QString pixmapName() { return "Devices/bluetooth"; } virtual const QString nodeName() { return tr("Bluetooth PAN/NAP"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DS ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; class BluetoothRFCOMMNetNode : public ANetNode { Q_OBJECT public: BluetoothRFCOMMNetNode(); virtual ~BluetoothRFCOMMNetNode(); virtual const QString pixmapName() { return "Devices/bluetooth"; } virtual const QString nodeName() { return tr("Bluetooth serial link"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool ); virtual bool generateDataForCommonFile( SystemFile & SF, long, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/cable/cable_NN.cpp b/noncore/settings/networksettings2/cable/cable_NN.cpp index 756903e..6f62772 100644 --- a/noncore/settings/networksettings2/cable/cable_NN.cpp +++ b/noncore/settings/networksettings2/cable/cable_NN.cpp @@ -1,59 +1,66 @@ #include "cable_NN.h" #include "cable_NNI.h" static const char * CableNeeds[] = { 0 }; /** * Constructor, find all of the possible interfaces */ CableNetNode::CableNetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ CableNetNode::~CableNetNode(){ } const QString CableNetNode::nodeDescription(){ return tr("\ <p>Sets up a wired serial or parallel.</p>\ " ); } ANetNodeInstance * CableNetNode::createInstance( void ) { return new ACable( this ); } const char ** CableNetNode::needs( void ) { return CableNeeds; } const char * CableNetNode::provides( void ) { return "line"; } bool CableNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool CableNetNode::hasDataFor( const QString & ) { +bool CableNetNode::hasDataFor( const QString &, bool ) { return 0; } bool CableNetNode::generateDataForCommonFile( SystemFile & , long , ANetNodeInstance * ) { return 1; } +bool CableNetNode::generateDeviceDataForCommonFile( + SystemFile & , + long , + ANetNodeInstance * ) { + return 1; +} + extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new CableNetNode() ); } } diff --git a/noncore/settings/networksettings2/cable/cable_NN.h b/noncore/settings/networksettings2/cable/cable_NN.h index da99c1c..3875af6 100644 --- a/noncore/settings/networksettings2/cable/cable_NN.h +++ b/noncore/settings/networksettings2/cable/cable_NN.h @@ -1,44 +1,46 @@ #ifndef CABLE_NETNODE_H #define CABLE_NETNODE_H #include "netnode.h" class ACable; class CableNetNode : public ANetNode { Q_OBJECT public: CableNetNode(); virtual ~CableNetNode(); virtual const QString pixmapName() { return "Devices/cable"; } virtual const QString nodeName() { return tr("Cable Connection"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DS ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/cable/cablerun.h b/noncore/settings/networksettings2/cable/cablerun.h index 36ee640..7b341c4 100644 --- a/noncore/settings/networksettings2/cable/cablerun.h +++ b/noncore/settings/networksettings2/cable/cablerun.h @@ -1,21 +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 canSetState( State_t Curr, Action_t A ); private : CableData_t * D; }; diff --git a/noncore/settings/networksettings2/irda/irda_NN.cpp b/noncore/settings/networksettings2/irda/irda_NN.cpp index 3b9c938..4347191 100644 --- a/noncore/settings/networksettings2/irda/irda_NN.cpp +++ b/noncore/settings/networksettings2/irda/irda_NN.cpp @@ -1,59 +1,66 @@ #include "irda_NN.h" #include "irda_NNI.h" static const char * IRDANeeds[] = { 0 }; /** * Constructor, find all of the possible interfaces */ IRDANetNode::IRDANetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ IRDANetNode::~IRDANetNode(){ } const QString IRDANetNode::nodeDescription(){ return tr("\ <p>Sets up a infra red serial link.</p>\ " ); } ANetNodeInstance * IRDANetNode::createInstance( void ) { return new AIRDA( this ); } const char ** IRDANetNode::needs( void ) { return IRDANeeds; } const char * IRDANetNode::provides( void ) { return "line"; } bool IRDANetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool IRDANetNode::hasDataFor( const QString & ) { +bool IRDANetNode::hasDataFor( const QString &, bool ) { return 0; } bool IRDANetNode::generateDataForCommonFile( SystemFile & , long , ANetNodeInstance * ) { return 1; } +bool IRDANetNode::generateDeviceDataForCommonFile( + SystemFile & , + long , + ANetNodeInstance * ) { + return 1; +} + extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new IRDANetNode() ); } } diff --git a/noncore/settings/networksettings2/irda/irda_NN.h b/noncore/settings/networksettings2/irda/irda_NN.h index 6574c17..a772f69 100644 --- a/noncore/settings/networksettings2/irda/irda_NN.h +++ b/noncore/settings/networksettings2/irda/irda_NN.h @@ -1,44 +1,46 @@ #ifndef IRDA_NETNODE_H #define IRDA_NETNODE_H #include "netnode.h" class AIRDA; class IRDANetNode : public ANetNode { Q_OBJECT public: IRDANetNode(); virtual ~IRDANetNode(); virtual const QString pixmapName() { return "Devices/irda"; } virtual const QString nodeName() { return tr("Infrared link"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DS ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/irda/irdarun.h b/noncore/settings/networksettings2/irda/irdarun.h index adc9c24..d9fe5e8 100644 --- a/noncore/settings/networksettings2/irda/irdarun.h +++ b/noncore/settings/networksettings2/irda/irdarun.h @@ -1,22 +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 ) { return 0; } bool canSetState( State_t , Action_t ) { return 0; } }; diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.cpp b/noncore/settings/networksettings2/lancard/lancard_NN.cpp index a45496d..7d36918 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NN.cpp +++ b/noncore/settings/networksettings2/lancard/lancard_NN.cpp @@ -1,60 +1,67 @@ #include "lancard_NN.h" #include "lancard_NNI.h" static const char * LanCardNeeds[] = { 0 }; /** * Constructor, find all of the possible interfaces */ LanCardNetNode::LanCardNetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ LanCardNetNode::~LanCardNetNode(){ } const QString LanCardNetNode::nodeDescription(){ return tr("\ <p>Sets up a wired regular LAN card.</p>\ <p>Use this to set up 10/100/1000 MBit LAN cards.</p>\ " ); } ANetNodeInstance * LanCardNetNode::createInstance( void ) { return new ALanCard( this ); } const char ** LanCardNetNode::needs( void ) { return LanCardNeeds; } const char * LanCardNetNode::provides( void ) { return "device"; } bool LanCardNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool LanCardNetNode::hasDataFor( const QString & ) { - return 0; +bool LanCardNetNode::hasDataFor( const QString & S, bool DS ) { + return DS && S == "interfaces"; } bool LanCardNetNode::generateDataForCommonFile( SystemFile & , long , ANetNodeInstance * ) { return 1; } +bool LanCardNetNode::generateDeviceDataForCommonFile( + SystemFile & S , + long DevNr , + ANetNodeInstance * NNI ) { + return ((ALanCard *)NNI)->generateDeviceDataForCommonFile(S, DevNr); +} + extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new LanCardNetNode() ); } } diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.h b/noncore/settings/networksettings2/lancard/lancard_NN.h index 71b49d0..9690c76 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NN.h +++ b/noncore/settings/networksettings2/lancard/lancard_NN.h @@ -1,44 +1,46 @@ #ifndef LANCARD_NETNODE_H #define LANCARD_NETNODE_H #include "netnode.h" class ALanCard; class LanCardNetNode : public ANetNode{ Q_OBJECT public: LanCardNetNode(); virtual ~LanCardNetNode(); virtual const QString pixmapName() { return "Devices/card"; } virtual const QString nodeName() { return tr("LAN card"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DS ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp index 9595e2e..a6401db 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp +++ b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp @@ -1,44 +1,58 @@ #include "lancardedit.h" #include "lancard_NNI.h" #include "lancard_NN.h" ALanCard::ALanCard( LanCardNetNode * PNN ) : ANetNodeInstance( PNN ) { Data.AnyLanCard = 1; Data.HWAddresses.clear(); GUI = 0; RT = 0; } void ALanCard::setSpecificAttribute( QString & A, QString & V ) { if( A == "matchanycard" ) { Data.AnyLanCard = (V == "yes" ); } else if( A == "match" ) { Data.HWAddresses.append( V ); } } void ALanCard::saveSpecificAttribute( QTextStream & TS) { TS << "matchanycard=" << ((Data.AnyLanCard) ? "yes" : "no") << endl; for( QStringList::Iterator it = Data.HWAddresses.begin(); it != Data.HWAddresses.end(); ++it ) { TS << "match=" << quote( *it ) << endl; } } QWidget * ALanCard::edit( QWidget * parent ) { GUI = new LanCardEdit( parent ); GUI->showData( Data ); return GUI; } QString ALanCard::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ALanCard::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } + +bool ALanCard::generateDeviceDataForCommonFile( SystemFile & S, long DevNr ) { + AsDevice * Dev = runtime()->device(); + QString NIC = Dev->genNic( DevNr ); + + if( S.name() == "interfaces" ) { + // generate mapping stanza for this interface + S << "# check if " << NIC << " can be brought UP" << endl; + S << "mapping " << NIC << endl; + S << " script networksettings2-request" << endl << endl; + } + return 0; +} + diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.h b/noncore/settings/networksettings2/lancard/lancard_NNI.h index 8fc8868..16f5f56 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NNI.h +++ b/noncore/settings/networksettings2/lancard/lancard_NNI.h @@ -1,43 +1,45 @@ #ifndef LANCARD_H #define LANCARD_H #include <netnode.h> #include "lancarddata.h" #include "lancardrun.h" class LanCardNetNode; class LanCardEdit; class ALanCard : public ANetNodeInstance { public : ALanCard( LanCardNetNode * PNN ); QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); RuntimeInfo * runtime( void ) { if( RT == 0 ) RT = new LanCardRun( this, Data ); return RT; } virtual void * data( void ) { return (void *)&Data; } + bool generateDeviceDataForCommonFile( SystemFile & S, long DevNr ); + protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : LanCardEdit * GUI; LanCardData Data; LanCardRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/lancard/lancardrun.cpp b/noncore/settings/networksettings2/lancard/lancardrun.cpp index b3b592b..951756d 100644 --- a/noncore/settings/networksettings2/lancard/lancardrun.cpp +++ b/noncore/settings/networksettings2/lancard/lancardrun.cpp @@ -1,139 +1,147 @@ #include <qfile.h> #include <qtextstream.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; } } } } - // we are certainly not UP + 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->Name ) && Run->CardType == ARPHRD_ETHER && ! 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 ) { // 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; - } - if( NC->currentState() != Available ) { + } 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(); diff --git a/noncore/settings/networksettings2/lancard/lancardrun.h b/noncore/settings/networksettings2/lancard/lancardrun.h index 5f004e0..8dbd1b1 100644 --- a/noncore/settings/networksettings2/lancard/lancardrun.h +++ b/noncore/settings/networksettings2/lancard/lancardrun.h @@ -1,38 +1,42 @@ #ifndef LANCARDRUN_H #define LANCARDRUN_H #include <asdevice.h> #include <qregexp.h> #include "lancarddata.h" class LanCardRun : public AsDevice { public : LanCardRun( ANetNodeInstance * NNI, LanCardData & Data ) : AsDevice( NNI ), Pat( "eth[0-9]" ) { } virtual long count( void ) { return 2; } virtual QString genNic( long nr ) { QString S; return S.sprintf( "eth%ld", nr ); } + virtual AsDevice * device( void ) - { return asDevice(); } + { return (AsDevice *)this; } + + virtual AsDevice * asDevice( void ) + { return (AsDevice *)this; } protected : void detectState( NodeCollection * NC ); bool setState( NodeCollection * NC, Action_t A ); bool canSetState( State_t Curr, Action_t A ); bool handlesInterface( const QString & I ); private : InterfaceInfo * getInterface( void ); QRegExp Pat; }; #endif diff --git a/noncore/settings/networksettings2/modem/modem_NN.cpp b/noncore/settings/networksettings2/modem/modem_NN.cpp index 48e1ad8..2807963 100644 --- a/noncore/settings/networksettings2/modem/modem_NN.cpp +++ b/noncore/settings/networksettings2/modem/modem_NN.cpp @@ -1,60 +1,67 @@ #include "modem_NN.h" #include "modem_NNI.h" static const char * ModemNeeds[] = { "line" }; /** * Constructor, find all of the possible interfaces */ ModemNetNode::ModemNetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ ModemNetNode::~ModemNetNode(){ } const QString ModemNetNode::nodeDescription(){ return tr("\ <p>Sets up a dialing procedures.</p>\ <p>Use this to dial up over modems, ISDN, GSM, ...</p>\ " ); } ANetNodeInstance * ModemNetNode::createInstance( void ) { return new AModem( this ); } const char ** ModemNetNode::needs( void ) { return ModemNeeds; } const char * ModemNetNode::provides( void ) { return "line"; } bool ModemNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool ModemNetNode::hasDataFor( const QString & ) { +bool ModemNetNode::hasDataFor( const QString &, bool ) { return 0; } bool ModemNetNode::generateDataForCommonFile( SystemFile & , long , ANetNodeInstance * ) { return 1; } +bool ModemNetNode::generateDeviceDataForCommonFile( + SystemFile & , + long , + ANetNodeInstance * ) { + return 1; +} + extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new ModemNetNode() ); } } diff --git a/noncore/settings/networksettings2/modem/modem_NN.h b/noncore/settings/networksettings2/modem/modem_NN.h index 5eceed2..bd921c6 100644 --- a/noncore/settings/networksettings2/modem/modem_NN.h +++ b/noncore/settings/networksettings2/modem/modem_NN.h @@ -1,44 +1,46 @@ #ifndef MODEM_NETNODE_H #define MODEM_NETNODE_H #include "netnode.h" class AModem; class ModemNetNode : public ANetNode{ Q_OBJECT public: ModemNetNode(); virtual ~ModemNetNode(); virtual const QString pixmapName() { return "Devices/modem"; } virtual const QString nodeName() { return tr("Dialup modem"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DS ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/modem/modemrun.h b/noncore/settings/networksettings2/modem/modemrun.h index 719ab2f..6d1662b 100644 --- a/noncore/settings/networksettings2/modem/modemrun.h +++ b/noncore/settings/networksettings2/modem/modemrun.h @@ -1,22 +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 ) { return 0; } bool canSetState( State_t, Action_t ) { return 0; } }; diff --git a/noncore/settings/networksettings2/network/network_NN.cpp b/noncore/settings/networksettings2/network/network_NN.cpp index bb371ad..a6b15c6 100644 --- a/noncore/settings/networksettings2/network/network_NN.cpp +++ b/noncore/settings/networksettings2/network/network_NN.cpp @@ -1,64 +1,71 @@ #include "network_NN.h" #include "network_NNI.h" static const char * NetworkNeeds[] = { "device", 0 }; /** * Constructor, find all of the possible interfaces */ NetworkNetNode::NetworkNetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ NetworkNetNode::~NetworkNetNode(){ } const QString NetworkNetNode::nodeDescription(){ return tr("\ <p>Sets up TCP/IP options.</p>\ <p>Use this to configure the TCP/IP protocol</p>\ " ); } ANetNodeInstance * NetworkNetNode::createInstance( void ) { return new ANetwork( this ); } const char ** NetworkNetNode::needs( void ) { return NetworkNeeds; } const char * NetworkNetNode::provides( void ) { return "connection"; } bool NetworkNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool NetworkNetNode::hasDataFor( const QString & S ) { - if( S == "interfaces" ) { +bool NetworkNetNode::hasDataFor( const QString & S, bool DS ) { + if( ! DS && S == "interfaces" ) { return 1; } return 0; } bool NetworkNetNode::generateDataForCommonFile( SystemFile & S, long DevNr, ANetNodeInstance * NNI ) { return ((ANetwork *)NNI)->generateDataForCommonFile(S, DevNr); } +bool NetworkNetNode::generateDeviceDataForCommonFile( + SystemFile & , + long , + ANetNodeInstance * ) { + return 1; +} + extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new NetworkNetNode() ); } } diff --git a/noncore/settings/networksettings2/network/network_NN.h b/noncore/settings/networksettings2/network/network_NN.h index 220e00f..62a3f10 100644 --- a/noncore/settings/networksettings2/network/network_NN.h +++ b/noncore/settings/networksettings2/network/network_NN.h @@ -1,44 +1,46 @@ #ifndef NETWORK_NETNODE_H #define NETWORK_NETNODE_H #include "netnode.h" class ANetwork; class NetworkNetNode : public ANetNode{ Q_OBJECT public: NetworkNetNode(); virtual ~NetworkNetNode(); virtual const QString pixmapName() { return "Devices/tcpip"; } virtual const QString nodeName() { return tr("IP Configuration"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DS ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp index 7130764..eac2d66 100644 --- a/noncore/settings/networksettings2/network/network_NNI.cpp +++ b/noncore/settings/networksettings2/network/network_NNI.cpp @@ -59,101 +59,96 @@ void ANetwork::saveSpecificAttribute( QTextStream & TS ) { TS << "ipaddress=" << Data.IPAddress << endl; TS << "netmask=" << Data.NetMask << endl; TS << "broadcast=" << Data.Broadcast << endl; TS << "gateway=" << Data.Gateway << endl; TS << "dns1=" << Data.DNS1 << endl; TS << "dns2=" << Data.DNS2 << endl; for ( QStringList::Iterator it = Data.PreUp_SL.begin(); it != Data.PreUp_SL.end(); ++it ) { TS << "preup=" << quote(*it) << endl; } for ( QStringList::Iterator it = Data.PreDown_SL.begin(); it != Data.PreDown_SL.end(); ++it ) { TS << "predown=" << quote(*it) << endl; } for ( QStringList::Iterator it = Data.PostUp_SL.begin(); it != Data.PostUp_SL.end(); ++it ) { TS << "postup=" << quote(*it) << endl; } for ( QStringList::Iterator it = Data.PostDown_SL.begin(); it != Data.PostDown_SL.end(); ++it ) { TS << "postdown=" << quote(*it) << endl; } } QWidget * ANetwork::edit( QWidget * parent ) { GUI = new NetworkEdit( parent ); GUI->showData( Data ); return GUI; } QString ANetwork::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ANetwork::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } bool ANetwork::generateDataForCommonFile( SystemFile & S, long DevNr ) { AsDevice * Dev = runtime()->device(); QString NIC = Dev->genNic( DevNr ); if( S.name() == "interfaces" ) { - // generate mapping stanza for this interface - S << "# check if " << NIC << " can be brought UP" << endl; - S << "mapping " << NIC << endl; - S << " script networksettings2-request" << endl << endl; - // we can safely call from here since device item is deeper if( Data.UseDHCP ) { S << "iface " << NIC << "-c" << connection()->number() << "-allowed inet dhcp" << endl; S << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() << ".up" << Data.IPAddress << endl; if( Data.SendHostname ) { S << " hostname "<< Data.Hostname << endl; } S << " down rm -f /tmp/profile-" << connection()->number() << ".up" << Data.IPAddress << endl; } else { S << "iface " << NIC << "-c" << connection()->number() << "-allowed inet static" << endl; S << " up echo \"" << NIC << "\" > /tmp/profile-" << connection()->number() << ".up" << Data.IPAddress << endl; S << " down rm -f /tmp/profile-" << connection()->number() << ".up" << Data.IPAddress << endl; S << " address " << Data.IPAddress << endl; S << " broadcast " << Data.Broadcast << endl; S << " netmask " << Data.NetMask << endl; // derive network address = IPAddress & netmask { QString NW; QStringList ipal = QStringList::split( '.', Data.IPAddress ); QStringList nmal = QStringList::split( '.', Data.NetMask ); NW = QString( "%1.%2.%3.%4" ). arg( ipal[0].toShort() & nmal[0].toShort() ). arg( ipal[1].toShort() & nmal[1].toShort() ). arg( ipal[2].toShort() & nmal[2].toShort() ). arg( ipal[3].toShort() & nmal[3].toShort() ); S << " network " << NW << endl; } } for ( QStringList::Iterator it = Data.PreUp_SL.begin(); it != Data.PreUp_SL.end(); ++it ) { S << " pre-up " << (*it) << endl; } for ( QStringList::Iterator it = Data.PostUp_SL.begin(); it != Data.PostUp_SL.end(); ++it ) { S << " up " << (*it) << endl; } for ( QStringList::Iterator it = Data.PreDown_SL.begin(); it != Data.PreDown_SL.end(); diff --git a/noncore/settings/networksettings2/network/networkedit.cpp b/noncore/settings/networksettings2/network/networkedit.cpp index b17d745..182213b 100644 --- a/noncore/settings/networksettings2/network/networkedit.cpp +++ b/noncore/settings/networksettings2/network/networkedit.cpp @@ -7,103 +7,103 @@ #include "networkedit.h" NetworkEdit::NetworkEdit( QWidget * Parent ) : NetworkGUI( Parent ){ AddPreDown_TB->setPixmap( NSResources->getPixmap( "add" ) ); AddPreUp_TB->setPixmap( NSResources->getPixmap( "add" ) ); AddPostDown_TB->setPixmap( NSResources->getPixmap( "add" ) ); AddPostUp_TB->setPixmap( NSResources->getPixmap( "add" ) ); DeletePreDown_TB->setPixmap( NSResources->getPixmap( "remove" ) ); DeletePreUp_TB->setPixmap( NSResources->getPixmap( "remove" ) ); DeletePostDown_TB->setPixmap( NSResources->getPixmap( "remove" ) ); DeletePostUp_TB->setPixmap( NSResources->getPixmap( "remove" ) ); UpPreDown_TB->setPixmap( NSResources->getPixmap( "up" ) ); UpPreUp_TB->setPixmap( NSResources->getPixmap( "up" ) ); UpPostDown_TB->setPixmap( NSResources->getPixmap( "up" ) ); UpPostUp_TB->setPixmap( NSResources->getPixmap( "up" ) ); DownPreDown_TB->setPixmap( NSResources->getPixmap( "down" ) ); DownPreUp_TB->setPixmap( NSResources->getPixmap( "down" ) ); DownPostDown_TB->setPixmap( NSResources->getPixmap( "down" ) ); DownPostUp_TB->setPixmap( NSResources->getPixmap( "down" ) ); } QString NetworkEdit::acceptable( void ) { if( DHCP_CB->isChecked() ) { if( SendHostname_CB->isChecked() ) if( Hostname_LE->text().isEmpty() ) return tr("Hostname needed"); return QString(); } if( IPAddress_LE->text().isEmpty() ) return tr("IPAddress needed"); if( Broadcast_LE->text().isEmpty() ) return tr("Broadcast needed"); if( SubnetMask_LE->text().isEmpty() ) return tr("Subnet mask needed"); // valid IP ? if( ! validIP( IPAddress_LE->text() ) ) return tr("IPAddress not valid"); if( ! validIP( SubnetMask_LE->text() ) ) return tr("Subnet mask not valid"); if( ! validIP( Broadcast_LE->text() ) ) return tr("Broadcast address not valid"); - if( Gateway_LE->text().isEmpty() && + if( Gateway_LE->text().isEmpty() || ! validIP( Gateway_LE->text() ) ) return tr("Gateway address not valid"); - if( DNS1_LE->text().isEmpty() && + if( ! DNS1_LE->text().isEmpty() && ! validIP( DNS1_LE->text() ) ) return tr("DNS1 address not valid"); - if( DNS2_LE->text().isEmpty() && + if( ! DNS2_LE->text().isEmpty() && ! validIP( DNS2_LE->text() ) ) return tr("DNS2 address not valid"); return QString(); } bool NetworkEdit::commit( NetworkData_t & Data ) { bool SM = 0; CBM( Data.UseDHCP, DHCP_CB, SM ); TXTM( Data.IPAddress, IPAddress_LE, SM ); CBM( Data.SendHostname, SendHostname_CB, SM ); TXTM( Data.Hostname, Hostname_LE, SM ); TXTM( Data.Gateway, Gateway_LE, SM ); TXTM( Data.Broadcast, Broadcast_LE, SM ); TXTM( Data.NetMask, SubnetMask_LE, SM ); TXTM( Data.DNS1, DNS1_LE, SM ); TXTM( Data.DNS2, DNS2_LE, SM ); SM |= updateList( Data.PreUp_SL, PreUp_LB ); SM |= updateList( Data.PostUp_SL, PostUp_LB ); SM |= updateList( Data.PreDown_SL, PreDown_LB ); SM |= updateList( Data.PostDown_SL, PostDown_LB ); return SM; } void NetworkEdit::showData( NetworkData_t & Data ) { DHCP_CB->setChecked( Data.UseDHCP ); SendHostname_CB->setChecked( Data.SendHostname ); Hostname_LE->setText( Data.Hostname ); IPAddress_LE->setText( Data.IPAddress ); Gateway_LE->setText( Data.Gateway ); SubnetMask_LE->setText( Data.NetMask ); Broadcast_LE->setText( Data.Broadcast ); DNS1_LE->setText( Data.DNS1 ); DNS2_LE->setText( Data.DNS2 ); populateList( Data.PreUp_SL, PreUp_LB ); populateList( Data.PostUp_SL, PostUp_LB ); populateList( Data.PreDown_SL, PreDown_LB ); populateList( Data.PostDown_SL, PostDown_LB ); } bool NetworkEdit::updateList( QStringList & SL, QListBox * LB ) { bool Changed; QStringList NewSL; // collect new list for( unsigned int i = 0; i < LB->count() ; i ++ ) { diff --git a/noncore/settings/networksettings2/network/networkrun.cpp b/noncore/settings/networksettings2/network/networkrun.cpp index 8deca14..f34fdbf 100644 --- a/noncore/settings/networksettings2/network/networkrun.cpp +++ b/noncore/settings/networksettings2/network/networkrun.cpp @@ -1,63 +1,65 @@ #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) ); } // has no interface -> delegate RI->detectState( NC ); } bool NetworkRun::setState( NodeCollection * NC, Action_t A ) { // 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 ) { QString S; - S.sprintf( "ifup %s", II->Name.latin1() ); + S.sprintf( "ifup %s=%s-c%d-allowed", + II->Name.latin1(), II->Name.latin1(), + connection()->number() ); NSResources->system().execute( S ); - NC->setCurrentState( IsUp ); } return 1; } else if( A == Down ) { if( NC->currentState() == IsUp ) { QString S; - S.sprintf( "ifdown %s", II->Name.latin1() ); + S.sprintf( "ifdown %s=%s-c%d-allowed", + II->Name.latin1(), II->Name.latin1(), + connection()->number() ); NSResources->system().execute( S ); - NC->setCurrentState( Available ); } 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 f3d840e..fa16365 100644 --- a/noncore/settings/networksettings2/network/networkrun.h +++ b/noncore/settings/networksettings2/network/networkrun.h @@ -1,20 +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 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 e1110e2..c3e6572 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp @@ -123,127 +123,145 @@ void NetworkSettings::SLOT_RefreshStates( void ) { 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( "Generating system configuration" ), + tr( "Name %1 already exists" ).arg(NC->name()) + ); + continue; // restart exec + } // else new name // new name -> remove item NSResources->removeConnection( OldName ); - // must add it here since change will trigger event 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 ); @@ -288,124 +306,118 @@ void NetworkSettings::SLOT_GenerateConfig( void ) { } 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 Available : // deactivate + case IsUp : // deactivate (will also bring down if needed) rv = NC->setState( Deactivate ); break; - case IsUp : - // bring down and deactivate - rv = ( NC->setState( Down ) && - 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; + 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 - return; + break; } if( ! rv ) { QMessageBox::warning( 0, tr( "Activating profile" ), tr( "Cannot enable profile" ) ); - return; } // we do not update the GUI but wait for the REAL upping of the device } 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/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index 56333c5..f4a5e30 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -50,101 +50,105 @@ typedef enum State { // 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(){}; virtual ~ANetNode(){}; // pixmap needed for this NetNode virtual const QString pixmapName() = 0; // name of this NetNode virtual const QString nodeName() = 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 system file S + virtual bool hasDataFor( const QString & S, bool DeviceSpecific ) = 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, ANetNodeInstance * NNI ) = 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, ANetNodeInstance * NNI ) = 0; // does this Node provide a Connection bool isToplevel( void ) { return strcmp( provides(), "fullsetup") == 0 ; } // compiled references to 'needed' NetNodes -> needs list void setAlternatives( NetNodeList * Alt ) { Alternatives = Alt; } NetNodeList & alternatives( void ) { return *Alternatives; } protected : NetNodeList * Alternatives; private : }; 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 @@ -170,105 +174,105 @@ public: QString & nodeName( void ) { return NodeName; } void setNodeName( const QString & S ) { NodeName = S; } // 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; protected : virtual void setSpecificAttribute( QString & , QString & ) = 0; virtual void saveSpecificAttribute( QTextStream & ) = 0; ANetNode * NodeType; // connection to which this node belongs to NodeCollection * Connection; QString NodeName; QString Description; bool IsModified; bool IsNew; static long InstanceCounter; }; class RuntimeInfo : public QObject { Q_OBJECT public : RuntimeInfo( ANetNodeInstance * TheNNI ) { NNI = TheNNI; } - // downcast + // downcast implemented by specify runtime classes AsDevice * asDevice( void ) - { return (AsDevice *)this; } + { return 0; } AsConnection * asConnection( void ) - { return (AsConnection *)this; } + { return 0; } AsLine * asLine( void ) - { return (AsLine *)this; } + { return 0; } AsFullSetup * asFullSetup( void ) - { return (AsFullSetup *)this; } + { 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 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 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 ; } @@ -339,101 +343,104 @@ public : { 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; }; // // special node that is used to remember entries for plugins // that seem missing. This way we never loose data // class FakeNetNode : public ANetNode { public: FakeNetNode( ) { }; virtual ~FakeNetNode(){}; const QString pixmapName() { return QString(""); } const QString nodeName() { return QString("Fake node" ); } const QString nodeDescription() { return QString("Fake node" ); } ANetNodeInstance * createInstance( void ); const char * provides( void ) { return ""; } virtual const char ** needs( void ) { return 0; } virtual bool generateProperFilesFor( ANetNodeInstance * ) { return 0; } - virtual bool hasDataFor( const QString & ) + virtual bool hasDataFor( const QString &, bool DS ) { return 0; } virtual bool generateDataForCommonFile( SystemFile & , long , ANetNodeInstance * ) {return 1; } + virtual bool generateDeviceDataForCommonFile( + SystemFile & , long , ANetNodeInstance * ) + {return 1; } private : }; class FakeNetNodeInstance : public ANetNodeInstance { public: FakeNetNodeInstance( ANetNode * NN ) : ANetNodeInstance( NN ), ValAttrPairs() { } virtual ~FakeNetNodeInstance( void ) { } virtual RuntimeInfo * runtime( void ) { return 0; } // create edit widget under parent virtual QWidget * edit( QWidget * ) { return 0; } // is given data acceptable virtual QString acceptable( void ) { return QString(""); } // get data from GUI and store in node virtual void commit( void ) {} // get next node ANetNodeInstance * nextNode() { return 0; } // return NetNode this is an instance of // intialize am instance of a net node void initialize( void ){} // returns node specific data -> only useful for 'buddy' virtual void * data( void ) { return 0; } protected : virtual void setSpecificAttribute( QString & , QString & ); virtual void saveSpecificAttribute( QTextStream & ); QDict<QString> ValAttrPairs; }; extern FakeNetNode * FakeNode; diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index 85dcd7d..a68f3c0 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp @@ -1,96 +1,97 @@ #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> #include <qfile.h> #include <qtextstream.h> #include <net/if.h> #include <net/if_arp.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/ioctl.h> #include <sys/socket.h> #include "resources.h" #include "system.h" #define PROCNETDEV "/proc/net/dev" static char Dig2Hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; // get HIGH nibble of byte #define HN(x) Dig2Hex[(((x)&0xf0)>>4)] // get LOW nibble of byte #define LN(x) Dig2Hex[((x)&0x0f)] System::System( void ) : ProbedInterfaces() { probeInterfaces(); } System::~System( void ) { if( ProcDevNet ) delete ProcDevNet; } int System::execute( const QString & S ) { QString MyS = S; + char * usr = getenv("USER"); int rv; if( S.isEmpty() ) { // loophole to start shell return 8888; } - if( getenv("USER") != "root" ) { - // use SUDO + if( usr == 0 || strcmp( usr, "root" ) ) { + // unknown or non-root user -> use SUDO MyS.prepend( "sudo " ); } fprintf( stderr, "Executing %s\n", MyS.latin1() ); rv = system( MyS.latin1() ) ; switch( rv ) { case -1 : // cannot fork return 1; case 127 : // cannot start shell return 2; default : if( WEXITSTATUS(rv) != 0 ) { // error in command return 3; } } // all is fine return 0; } void System::refreshStatistics( InterfaceInfo & I ) { if( ! ProcDevNet ) { return; } // cannot seek on dev ProcDevNet->close(); ProcDevNet->open( IO_ReadOnly ); QString line; QTextStream procTs(ProcDevNet); QStringList SL; int loc = -1; int version; procTs.readLine(); line = procTs.readLine(); // get version if( line.find("compressed") ) version = 3; else if( line.find( "bytes" ) ) version = 2; else version = 1; while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { if( (loc = line.find(":") ) == -1) { diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.cpp b/noncore/settings/networksettings2/networksettings2/systemfile.cpp index 7249976..394ff52 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.cpp +++ b/noncore/settings/networksettings2/networksettings2/systemfile.cpp @@ -1,144 +1,187 @@ #include <stdio.h> #include <qpe/qpeapplication.h> #include <qfileinfo.h> #include <qmessagebox.h> #include <qfile.h> #include <qtextstream.h> #include "resources.h" #include "systemfile.h" #define TEMPLATEDIR "networktemplates/" QString TemplDir; SystemFile::SystemFile( const QString & N, const QString & P ){ Name = N; Path = P; F = 0; // get template info { QString S; QFileInfo FI; // find location of templates TemplDir = QPEApplication::qpeDir() + "etc/" + TEMPLATEDIR; FI.setFile( TemplDir ); if( ! FI.isDir() ) { // try current dir TemplDir = "./" TEMPLATEDIR; FI.setFile( TemplDir ); if( ! FI.isDir() ) { hasPreSection = hasPostSection = hasPreNodeSection = - hasPostNodeSection = 0; + hasPostNodeSection = + hasPreDeviceSection = + hasPostDeviceSection = 0; return; } } // have found location S = TemplDir + Name + "/presection"; FI.setFile( S ); hasPreSection = ( FI.exists() && FI.isReadable() ); S = TemplDir + Name + "/postsection"; FI.setFile( S ); hasPostSection = ( FI.exists() && FI.isReadable() ); S = TemplDir + Name + "/prenodesection"; FI.setFile( S ); hasPreNodeSection = ( FI.exists() && FI.isReadable() ); S = TemplDir + Name + "/postnodesection"; FI.setFile( S ); hasPostNodeSection = ( FI.exists() && FI.isReadable() ); + S = TemplDir + Name + "/predevicesection"; + FI.setFile( S ); + hasPreDeviceSection = ( FI.exists() && FI.isReadable() ); + S = TemplDir + Name + "/postdevicesection"; + FI.setFile( S ); + hasPostDeviceSection = ( FI.exists() && FI.isReadable() ); } } SystemFile::~SystemFile( void ) { if( F ) delete F; } bool SystemFile::open( void ) { if( F ) { F->close(); delete F; } F = new QFile( Path + "bup" ); if( ! F->open( IO_WriteOnly ) ) { return 0; } setDevice( F ); return 1; } bool SystemFile::close( void ) { if( ! F ) { return 1 ; } QString OldP = Path + "bup"; F->close(); delete F; F = 0; return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); } bool SystemFile::preSection( void ) { if( hasPreSection ) { QFile Fl( TemplDir + Name + "/presection" ); if( ! Fl.open( IO_ReadOnly ) ) return 1; // error // copy file to this file F->writeBlock( Fl.readAll() ); } return 0; } bool SystemFile::postSection( void ) { if( hasPostSection ) { QFile Fl( TemplDir + Name + "/postsection" ); if( ! Fl.open( IO_ReadOnly ) ) return 1; // error // copy file to this file F->writeBlock( Fl.readAll() ); } return 0; } bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) { if( hasPreNodeSection ) { - QFile Fl( TemplDir + Name + "/prenodesectoin" ); + QFile Fl( TemplDir + Name + "/prenodesection" ); if( ! Fl.open( IO_ReadOnly ) ) return 1; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); while( ! TX.eof() ) { Out = S. arg(NNI->netNode()->nodeName()); (*this) << Out << endl; S = TX.readLine(); } } return 0; } bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long DevNr ) { if( hasPostNodeSection ) { - QFile Fl( TemplDir + Name + "/postnodesectoin" ); + QFile Fl( TemplDir + Name + "/postnodesection" ); if( ! Fl.open( IO_ReadOnly ) ) return 1; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); while( ! TX.eof() ) { Out = S. arg(NNI->nodeName()); (*this) << Out << endl; S = TX.readLine(); } } return 0; } +bool SystemFile::preDeviceSection( ANetNodeInstance * NNI, long ) { + if( hasPreDeviceSection ) { + QFile Fl( TemplDir + Name + "/predevicesection" ); + if( ! Fl.open( IO_ReadOnly ) ) + return 1; // error + QTextStream TX( &Fl ); + QString Out; + QString S = TX.readLine(); + while( ! TX.eof() ) { + Out = S. + arg(NNI->netNode()->nodeName()); + (*this) << Out << endl; + S = TX.readLine(); + } + } + return 0; +} + +bool SystemFile::postDeviceSection( ANetNodeInstance * NNI, long DevNr ) { + if( hasPostDeviceSection ) { + QFile Fl( TemplDir + Name + "/postdevicesection" ); + if( ! Fl.open( IO_ReadOnly ) ) + return 1; // error + QTextStream TX( &Fl ); + QString Out; + QString S = TX.readLine(); + while( ! TX.eof() ) { + Out = S. + arg(NNI->nodeName()); + (*this) << Out << endl; + S = TX.readLine(); + } + } + return 0; +} diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.h b/noncore/settings/networksettings2/networksettings2/systemfile.h index 8b6bcb9..35e0dfc 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.h +++ b/noncore/settings/networksettings2/networksettings2/systemfile.h @@ -1,39 +1,43 @@ #ifndef __SYSTEMFILE__H #define __SYSTEMFILE__H #include <qstring.h> #include <qtextstream.h> class QFile; class ANetNodeInstance; class SystemFile : public QTextStream { public : SystemFile( const QString & Name, const QString & Path ); ~SystemFile( void ); const QString & name( void ) { return Name; } bool open( void ); bool close( void ); bool preSection( void ); bool postSection( void ); bool preNodeSection( ANetNodeInstance * NNI, long DevNr ); bool postNodeSection( ANetNodeInstance * NNI, long DevNr ); + bool preDeviceSection( ANetNodeInstance * NNI, long DevNr ); + bool postDeviceSection( ANetNodeInstance * NNI, long DevNr ); private : QString Name; QString Path; QFile * F; bool hasPreSection; - bool hasPreNodeSection; bool hasPostSection; + bool hasPreNodeSection; bool hasPostNodeSection; + bool hasPreDeviceSection; + bool hasPostDeviceSection; }; #endif diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 3f5e958..6541596 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp @@ -143,245 +143,397 @@ QString NetworkSettingsData::saveSettings( void ) { for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { // all nodes in those connections for( QListIterator<ANetNodeInstance> nit(*(it.current())); nit.current(); ++nit ) { // header NNI = nit.current(); TS << '[' <<NNI->netNode()->nodeName() << ']' << endl; NNI->saveAttributes( TS ); TS << endl; } TS << "[connection]" << endl; it.current()->save(TS); } } QDir D("."); D.rename( CfgFile + ".bup", CfgFile ); // // proper files AND system files regenerated // setModified( 0 ); return ErrS; } QString NetworkSettingsData::generateSettings( bool ForceReq ) { bool ForceIt; QString S = ""; // include own force flag ForceIt = (Force) ? 1 : ForceReq; if( ! ForceIt && ! isModified() ) return S; // regenerate system files printf( "Generating settings from %s\n", CfgFile.latin1() ); { Name2SystemFile_t & SFM = NSResources->systemFiles(); Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; ANetNodeInstance * NNI; SystemFile * SF; + AsDevice * CurDev; bool needToRegenerate = ForceIt; // // check if we need to generate at least one of the system files // if( ! ForceIt ) { for( QDictIterator<SystemFile> sfit(SFM); sfit.current(); ++sfit ) { SF = sfit.current(); // check if there are nodes that are modified and require // data for this system file // for all connections for( QDictIterator<NodeCollection> ncit(M); ncit.current(); ++ncit ) { NC = ncit.current(); if( NC->isModified() ) { // does this connection 'touch' this system file ? for( QListIterator<ANetNodeInstance> cncit(*NC); cncit.current(); ++cncit ) { NNI = cncit.current(); - if( NNI->netNode()->hasDataFor( SF->name() ) && + if( ( NNI->netNode()->hasDataFor( SF->name(), 1 ) || + NNI->netNode()->hasDataFor( SF->name(), 0 ) + ) && NNI->isModified() ) { needToRegenerate = 1; break; } } } if( needToRegenerate ) break; } if( needToRegenerate ) break; } } // we cannot renumber with a FORCE request since // we probably are NOT going to save the config // e.g. when using --regen option if( ! ForceReq && needToRegenerate ) { NSResources->renumberConnections(); setModified(1); } // // generate files proper to each netnodeinstance // { Name2Instance_t & NNIs = NSResources->netNodeInstances(); - ANetNodeInstance * NNI; for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); NNIIt.current(); ++NNIIt ){ // for all nodes find those that are modified NNI = NNIIt.current(); if( ForceIt || NNI->isModified() ) { if( ! NNI->netNode()->generateProperFilesFor( NNI ) ) { // problem generating S = qApp->translate( "NetworkSettings", "<p>Cannot generate files proper to %1</p>" ). arg(NNI->netNode()->nodeName()) ; return S; } } } } // - // generate system files + // generate all system files // for( QDictIterator<SystemFile> sfit(SFM); sfit.current(); ++sfit ) { SF = sfit.current(); - // - // regenerate current file - // printf( "Generating %s\n", SF->name().latin1() ); SF->open(); do { // so we can break; + // global presection for this system file if( SF->preSection() ) { S = qApp->translate( "NetworkSettings", "<p>Error in preSection for file %1</p>" ). arg( SF->name() ); return S; } + // find all netnodes and figure out if + // for that node there are instances + for( QDictIterator<NetNode_t> nnit( + NSResources->netNodes() ); + nnit.current(); + ++nnit ) { + ANetNode * NN; + + NN = nnit.current()->NetNode; + + // are there instances ? + NNI = 0; + for( QDictIterator<ANetNodeInstance> nniit( + NSResources->netNodeInstances() ); + nniit.current(); + ++nniit ) { + if( nniit.current()->netNode() == NN ) { + NNI = nniit.current(); + break; + } + } + + if( ! NNI ) + // no instances + continue; + + // has this node data for this system file ? + if( (CurDev = NNI->runtime()->asDevice() ) ) { + // generate start for this nodetype for all possible devices of this type + for( int i = 0; i < CurDev->count(); i ++ ) { + if( SF->preDeviceSection( NNI, i ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in preDeviceSection for file %1 and node %2</p>" ). + arg( SF->name() ). + arg( NN->nodeName() ); + return S; + } + + if( ! NN->hasDataFor( SF->name(), 1 ) ) { + if( NN->generateDeviceDataForCommonFile( *SF, i, NNI ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in node part for file %1 and node %2</p>" ). + arg( SF->name() ). + arg( NN->nodeName() ); + return S; + } + } + } + } else { + // just request this once + if( SF->preDeviceSection( NNI, -1 ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in preDeviceSection for file %1 and node %2</p>" ). + arg( SF->name() ). + arg( NN->nodeName() ); + return S; + } + + if( ! NN->hasDataFor( SF->name(), 1 ) ) { + if( NN->generateDeviceDataForCommonFile( *SF, -1, NNI ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in node part for file %1 and node %2</p>" ). + arg( SF->name() ). + arg( NN->nodeName() ); + return S; + } + } + } + + // now generate profile specific data for all + // connections working on a device of the current + // netnode type for( QDictIterator<NodeCollection> ncit(M); ncit.current(); ++ncit ) { NC = ncit.current(); + NNI = NC->getToplevel(); + + // no output needed + if( ! NNI->netNode()->hasDataFor( SF->name(), 0 ) ) + continue; + // get the netnode that serves as the device for this // connection AsDevice * Dev = NC->device(); - // generate 'entry' for every possible device this profile handles + if( CurDev ) { + if( CurDev != Dev ) { + // other device -> later + continue; + } - for( QListIterator<ANetNodeInstance> cncit(*NC); - cncit.current(); - ++cncit ) { - NNI = cncit.current(); - for( int i = 0; i < Dev->count(); i ++ ) { - if( NNI->netNode()->hasDataFor( SF->name() ) ) { + // generate 'entry' for every combination of device and profile + // each node delegates to deeper level + for( int i = 0; i < CurDev->count(); i ++ ) { if( SF->preNodeSection( NNI, i ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in preNodeSection for file %1 and node %2</p>" ). arg( SF->name() ). arg( NNI->netNode()->nodeName() ); return S; } + // ask all nodes in connection + + for( QListIterator<ANetNodeInstance> cncit(*NC); + cncit.current(); + ++cncit ) { + NNI = cncit.current(); + + if( NNI->netNode()->hasDataFor( SF->name(), 0 ) ) { if( NNI->netNode()->generateDataForCommonFile(*SF,i,NNI) ) { S = qApp->translate( "NetworkSettings", "<p>Error in node part for file %1 and node %2</p>" ). arg( SF->name() ). arg( NNI->netNode()->nodeName() ); return S; } + } + } if( SF->postNodeSection( NNI, i ) ) { S = qApp->translate( "NetworkSettings", "<p>Error in postNodeSection for file %1 and node %2</p>" ). arg( SF->name() ). arg( NNI->netNode()->nodeName() ); return S; } } + + } else { + if( Dev ) { + // other + continue; } + + // one entry to generate + if( SF->preNodeSection( NNI, -1 ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in preNodeSection for file %1 and node %2</p>" ). + arg( SF->name() ). + arg( NNI->netNode()->nodeName() ); + return S; + } + + if( NNI->netNode()->generateDataForCommonFile(*SF,-1,NNI) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in node part for file %1 and node %2</p>" ). + arg( SF->name() ). + arg( NNI->netNode()->nodeName() ); + return S; + } + + if( SF->postNodeSection( NNI, -1 ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in postNodeSection for file %1 and node %2</p>" ). + arg( SF->name() ). + arg( NNI->netNode()->nodeName() ); + return S; + } + } + + // generated some data + if( SF->postNodeSection( NNI, -1 ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in postNodeSection for file %1 and node %2</p>" ). + arg( SF->name() ). + arg( NNI->netNode()->nodeName() ); + return S; } *SF << endl; } + if( CurDev ) { + // generate 'entry' for every combination of device and profile + // each node delegates to deeper level + for( int i = 0; i < CurDev->count(); i ++ ) { + if( SF->postDeviceSection( NNI, i ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in postDeviceSection for file %1 and node %2</p>" ). + arg( SF->name() ). + arg( NNI->netNode()->nodeName() ); + return S; + } + } + } else { + if( SF->postDeviceSection( NNI, -1 ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in postDeviceSection for file %1 and node %2</p>" ). + arg( SF->name() ). + arg( NNI->netNode()->nodeName() ); + return S; + } + } + } + if( SF->postSection() ) { S = qApp->translate( "NetworkSettings", "<p>Error in postSection for file %1</p>" ). arg( SF->name() ); return S; } + } while( 0 ); SF->close(); } } Force = 0; return S; } QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { // collect connections that can work on top of this interface NodeCollection * NC; QList<NodeCollection> PossibleConnections; Name2Connection_t & M = NSResources->connections(); // for all connections for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); // check if this profile handles the requested interface if( NC->handlesInterface( Interface ) && // if different Intf. NC->state() != Disabled && // if not enabled NC->state() != IsUp // if already used ) { PossibleConnections.append( NC ); } } return PossibleConnections; } /* Called by the system to see if interface can be brought UP if allowed, echo Interface-allowed else Interface-disallowed */ void NetworkSettingsData::canStart( const char * Interface ) { // load situation NodeCollection * NC = 0; QList<NodeCollection> PossibleConnections; PossibleConnections = collectPossible( Interface ); switch( PossibleConnections.count() ) { case 0 : // no connections break; case 1 : // one connection diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.cpp b/noncore/settings/networksettings2/ppp/ppp_NN.cpp index 309c9a1..51d17ec 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NN.cpp @@ -1,62 +1,69 @@ #include "ppp_NN.h" #include "ppp_NNI.h" static const char * PPPNeeds[] = { "line", "modem", 0 }; /** * Constructor, find all of the possible interfaces */ PPPNetNode::PPPNetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ PPPNetNode::~PPPNetNode(){ } const QString PPPNetNode::nodeDescription(){ return tr("\ <p>Sets up IP using PPP.</p>\ <p>Use this for dialup devices or serial setups</p>\ " ); } ANetNodeInstance * PPPNetNode::createInstance( void ) { return new APPP( this ); } const char ** PPPNetNode::needs( void ) { return PPPNeeds; } const char * PPPNetNode::provides( void ) { return "connection"; } bool PPPNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool PPPNetNode::hasDataFor( const QString & ) { +bool PPPNetNode::hasDataFor( const QString &, bool ) { return 0; } bool PPPNetNode::generateDataForCommonFile( SystemFile & , long, ANetNodeInstance * ) { return 1; } +bool PPPNetNode::generateDeviceDataForCommonFile( + SystemFile & , + long , + ANetNodeInstance * ) { + return 1; +} + extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new PPPNetNode() ); } } diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.h b/noncore/settings/networksettings2/ppp/ppp_NN.h index 3f9a338..8d56e7f 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.h +++ b/noncore/settings/networksettings2/ppp/ppp_NN.h @@ -1,44 +1,46 @@ #ifndef PPP_NETNODE_H #define PPP_NETNODE_H #include "netnode.h" class APPP; class PPPNetNode : public ANetNode{ Q_OBJECT public: PPPNetNode(); virtual ~PPPNetNode(); virtual const QString pixmapName() { return "Devices/ppp"; } virtual const QString nodeName() { return tr("PPP Connection"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DS ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/ppp/ppprun.cpp b/noncore/settings/networksettings2/ppp/ppprun.cpp index 4ac0c5a..8c75df3 100644 --- a/noncore/settings/networksettings2/ppp/ppprun.cpp +++ b/noncore/settings/networksettings2/ppp/ppprun.cpp @@ -1,75 +1,67 @@ #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 - ANetNodeInstance * NNI; - RuntimeInfo * RI; - NNI = AsDevice::netNode(); - printf( "%p\n", NNI ); - NNI = NNI->nextNode(); - printf( "%p\n", NNI ); - RI = NNI->runtime(); - printf( "%p\n", RI ); - RI->detectState( NC ); + AsDevice::netNode()->nextNode()->runtime()->detectState( NC ); } } bool PPPRun::setState( NodeCollection * NC, Action_t A ) { 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 && diff --git a/noncore/settings/networksettings2/ppp/ppprun.h b/noncore/settings/networksettings2/ppp/ppprun.h index abb9176..765aff2 100644 --- a/noncore/settings/networksettings2/ppp/ppprun.h +++ b/noncore/settings/networksettings2/ppp/ppprun.h @@ -1,43 +1,49 @@ #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 QString genNic( long NicNr ) { QString S; return S.sprintf( "ppp%ld", NicNr ); } + virtual AsDevice * asDevice( void ) + { return (AsDevice *)this; } + virtual AsConnection * asConnection( void ) + { return (AsConnection *)this; } + virtual AsDevice * device( void ) - { return AsDevice::asDevice(); } + { return (AsDevice *)this; } + virtual RuntimeInfo * runtimeInfo( void ) { return ( AsConnection *)this; } protected : void detectState( NodeCollection * NC ); bool setState( NodeCollection * NC, Action_t A ); 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/profile_NN.cpp b/noncore/settings/networksettings2/profile/profile_NN.cpp index c39b86f..fcf1ca6 100644 --- a/noncore/settings/networksettings2/profile/profile_NN.cpp +++ b/noncore/settings/networksettings2/profile/profile_NN.cpp @@ -1,61 +1,68 @@ #include "profile_NN.h" #include "profile_NNI.h" static const char * ProfileNeeds[] = { "connection", 0 }; /** * Constructor, find all of the possible interfaces */ ProfileNetNode::ProfileNetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ ProfileNetNode::~ProfileNetNode(){ } const QString ProfileNetNode::nodeDescription(){ return tr("\ <p>Define use of an IP connection.</p>\ <p>Configure if and when this connection needs to be established</p>\ " ); } ANetNodeInstance * ProfileNetNode::createInstance( void ) { return new AProfile( this ); } const char ** ProfileNetNode::needs( void ) { return ProfileNeeds; } const char * ProfileNetNode::provides( void ) { return "fullsetup"; } bool ProfileNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool ProfileNetNode::hasDataFor( const QString & ) { +bool ProfileNetNode::hasDataFor( const QString &, bool ) { return 0; } bool ProfileNetNode::generateDataForCommonFile( SystemFile & , long, ANetNodeInstance * ) { return 1; } +bool ProfileNetNode::generateDeviceDataForCommonFile( + SystemFile & , + long , + ANetNodeInstance * ) { + return 1; +} + extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new ProfileNetNode() ); } } diff --git a/noncore/settings/networksettings2/profile/profile_NN.h b/noncore/settings/networksettings2/profile/profile_NN.h index 3c06947..b64a6dd 100644 --- a/noncore/settings/networksettings2/profile/profile_NN.h +++ b/noncore/settings/networksettings2/profile/profile_NN.h @@ -1,44 +1,46 @@ #ifndef PROFILE_NETNODE_H #define PROFILE_NETNODE_H #include "netnode.h" class AProfile; class ProfileNetNode : public ANetNode{ Q_OBJECT public: ProfileNetNode(); virtual ~ProfileNetNode(); virtual const QString pixmapName() { return "Devices/commprofile"; } virtual const QString nodeName() { return tr("Regular profile"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DS ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/profile/profilerun.cpp b/noncore/settings/networksettings2/profile/profilerun.cpp index 90c37ed..feebf86 100644 --- a/noncore/settings/networksettings2/profile/profilerun.cpp +++ b/noncore/settings/networksettings2/profile/profilerun.cpp @@ -1,67 +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 ) { 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; } return 1; case Disable : - if( NC->currentState() == IsUp ) { - // bring down -> make available - NNNI->runtime()->setState(NC, Down); - } - if( NC->currentState() == Available ) { - // make unavailable - NNNI->runtime()->setState(NC, Deactivate); - } - if( NC->currentState() > Available ) { - // could not 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 d3797b5..6e8385c 100644 --- a/noncore/settings/networksettings2/profile/profilerun.h +++ b/noncore/settings/networksettings2/profile/profilerun.h @@ -1,28 +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 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/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp index c65771d..be4a2bc 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.cpp +++ b/noncore/settings/networksettings2/usb/usb_NN.cpp @@ -1,60 +1,67 @@ #include "usb_NN.h" #include "usb_NNI.h" static const char * USBNeeds[] = { 0 }; /** * Constructor, find all of the possible interfaces */ USBNetNode::USBNetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ USBNetNode::~USBNetNode(){ } const QString USBNetNode::nodeDescription(){ return tr("\ <p>Configure Ethernet over USB.</p>\ <p>Use this for a computer to computer USB cable connection</p>\ " ); } ANetNodeInstance * USBNetNode::createInstance( void ) { return new AUSB( this ); } const char ** USBNetNode::needs( void ) { return USBNeeds; } const char * USBNetNode::provides( void ) { return "device"; } bool USBNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool USBNetNode::hasDataFor( const QString & S ) { +bool USBNetNode::hasDataFor( const QString & S, bool ) { return (S== "interfaces"); } bool USBNetNode::generateDataForCommonFile( SystemFile & S , long DevNr, ANetNodeInstance * NNI) { return ((AUSB *)NNI)->generateDataForCommonFile(S, DevNr); } +bool USBNetNode::generateDeviceDataForCommonFile( + SystemFile & S , + long DevNr, + ANetNodeInstance * NNI) { + return ((AUSB *)NNI)->generateDeviceDataForCommonFile(S, DevNr); +} + extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new USBNetNode() ); } } diff --git a/noncore/settings/networksettings2/usb/usb_NN.h b/noncore/settings/networksettings2/usb/usb_NN.h index 8b97452..8ff5289 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.h +++ b/noncore/settings/networksettings2/usb/usb_NN.h @@ -1,44 +1,46 @@ #ifndef USB_NETNODE_H #define USB_NETNODE_H #include "netnode.h" class AUSB; class USBNetNode : public ANetNode{ Q_OBJECT public: USBNetNode(); virtual ~USBNetNode(); virtual const QString pixmapName() { return "Devices/usb"; } virtual const QString nodeName() { return tr("USB Cable Connect"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DeviceSpec ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/usb/usb_NNI.cpp b/noncore/settings/networksettings2/usb/usb_NNI.cpp index 4729416..6fcd6d5 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.cpp +++ b/noncore/settings/networksettings2/usb/usb_NNI.cpp @@ -1,46 +1,57 @@ #include <qpe/qpeapplication.h> #include "usbedit.h" #include "usb_NNI.h" #include "usb_NN.h" AUSB::AUSB( USBNetNode * PNN ) : ANetNodeInstance( PNN ) { GUI = 0; RT = 0; } void AUSB::setSpecificAttribute( QString & , QString & ) { } void AUSB::saveSpecificAttribute( QTextStream & ) { } QWidget * AUSB::edit( QWidget * parent ) { GUI = new USBEdit( parent ); GUI->showData( Data ); return GUI; } QString AUSB::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AUSB::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } bool AUSB::generateDataForCommonFile( SystemFile & S, long DevNr ) { AsDevice * Dev = runtime()->device(); QString NIC = Dev->genNic( DevNr ); if( S.name() == "interfaces" ) { // generate mapping stanza for this interface S << " pre-up " << QPEApplication::qpeDir() << "bin/setmacaddress.sh " << NIC << " || true" << endl; } return 0; } +bool AUSB::generateDeviceDataForCommonFile( SystemFile & S, long DevNr ) { + AsDevice * Dev = runtime()->device(); + QString NIC = Dev->genNic( DevNr ); + if( S.name() == "interfaces" ) { + // generate mapping stanza for this interface + S << "# check if " << NIC << " can be brought UP" << endl; + S << "mapping " << NIC << endl; + S << " script networksettings2-request" << endl << endl; + } + return 0; +} diff --git a/noncore/settings/networksettings2/usb/usb_NNI.h b/noncore/settings/networksettings2/usb/usb_NNI.h index b09f17a..5dead36 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.h +++ b/noncore/settings/networksettings2/usb/usb_NNI.h @@ -1,44 +1,45 @@ #ifndef USB_H #define USB_H #include <netnode.h> #include "usbdata.h" #include "usbrun.h" class USBNetNode; class USBEdit; class AUSB : public ANetNodeInstance { public : AUSB( USBNetNode * PNN ); QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); RuntimeInfo * runtime( void ) { if( RT == 0 ) RT = new USBRun( this, Data ); return RT; } virtual void * data( void ) { return (void *)&Data; } bool generateDataForCommonFile( SystemFile & S, long DevNr ); + bool generateDeviceDataForCommonFile( SystemFile & S, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : USBEdit * GUI; USBData Data; USBRun * RT; }; #endif diff --git a/noncore/settings/networksettings2/usb/usbrun.cpp b/noncore/settings/networksettings2/usb/usbrun.cpp index 49b5a77..3007e79 100644 --- a/noncore/settings/networksettings2/usb/usbrun.cpp +++ b/noncore/settings/networksettings2/usb/usbrun.cpp @@ -1,144 +1,155 @@ #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, "NUP\n" ); - // definitively not up + 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, "OFF\n" ); + 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 ) { // 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; - } - if( NC->currentState() != Available ) { + } 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 ) { diff --git a/noncore/settings/networksettings2/usb/usbrun.h b/noncore/settings/networksettings2/usb/usbrun.h index c9c9121..60f9fe8 100644 --- a/noncore/settings/networksettings2/usb/usbrun.h +++ b/noncore/settings/networksettings2/usb/usbrun.h @@ -1,38 +1,41 @@ #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 long count( void ) { return 1; } virtual QString genNic( long nr ); + virtual AsDevice * device( void ) - { return asDevice(); } + { return (AsDevice *)this; } + virtual AsDevice * asDevice( void ) + { return (AsDevice *)this; } protected : void detectState( NodeCollection * ); bool setState( NodeCollection * , Action_t A ); 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/vpn_NN.cpp b/noncore/settings/networksettings2/vpn/vpn_NN.cpp index c800929..f570fb2 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NN.cpp +++ b/noncore/settings/networksettings2/vpn/vpn_NN.cpp @@ -1,61 +1,68 @@ #include "vpn_NN.h" #include "vpn_NNI.h" static const char * VPNNeeds[] = { "connection", 0 }; /** * Constructor, find all of the possible interfaces */ VPNNetNode::VPNNetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ VPNNetNode::~VPNNetNode(){ } const QString VPNNetNode::nodeDescription(){ return tr("\ <p>Configure private IP connection.</p>\ <p>Defines Secure tunnels over non secure IP sessions</p>\ " ); } ANetNodeInstance * VPNNetNode::createInstance( void ) { return new AVPN( this ); } const char ** VPNNetNode::needs( void ) { return VPNNeeds; } const char * VPNNetNode::provides( void ) { return "connection"; } bool VPNNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool VPNNetNode::hasDataFor( const QString & ) { +bool VPNNetNode::hasDataFor( const QString &, bool ) { return 0; } bool VPNNetNode::generateDataForCommonFile( SystemFile & , long, ANetNodeInstance * ) { return 1; } +bool VPNNetNode::generateDeviceDataForCommonFile( + SystemFile & , + long , + ANetNodeInstance * ) { + return 1; +} + extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new VPNNetNode() ); } } diff --git a/noncore/settings/networksettings2/vpn/vpn_NN.h b/noncore/settings/networksettings2/vpn/vpn_NN.h index a113ab9..cdb5117 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NN.h +++ b/noncore/settings/networksettings2/vpn/vpn_NN.h @@ -1,44 +1,46 @@ #ifndef VPN_NETNODE_H #define VPN_NETNODE_H #include "netnode.h" class AVPN; class VPNNetNode : public ANetNode{ Q_OBJECT public: VPNNetNode(); virtual ~VPNNetNode(); virtual const QString pixmapName() { return "Devices/vpn"; } virtual const QString nodeName() { return tr("VPN Connection"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DS ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/vpn/vpnrun.h b/noncore/settings/networksettings2/vpn/vpnrun.h index c221fd0..4d26298 100644 --- a/noncore/settings/networksettings2/vpn/vpnrun.h +++ b/noncore/settings/networksettings2/vpn/vpnrun.h @@ -1,30 +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 ) { return 0; } bool canSetState( State_t, Action_t ) { return 0; } bool handlesInterface( const QString & I ); }; #endif diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.cpp b/noncore/settings/networksettings2/wlan/wlan_NN.cpp index 5a26e41..e1e20c0 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NN.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NN.cpp @@ -1,60 +1,67 @@ #include "wlan_NN.h" #include "wlan_NNI.h" static const char * WLanNeeds[] = { 0 }; /** * Constructor, find all of the possible interfaces */ WLanNetNode::WLanNetNode() : ANetNode() { } /** * Delete any interfaces that we own. */ WLanNetNode::~WLanNetNode(){ } const QString WLanNetNode::nodeDescription(){ return tr("\ <p>Configure Wi/Fi or WLan network cards.</p>\ <p>Defines Wireless options for those cards</p>\ " ); } ANetNodeInstance * WLanNetNode::createInstance( void ) { return new AWLan( this ); } const char ** WLanNetNode::needs( void ) { return WLanNeeds; } const char * WLanNetNode::provides( void ) { return "device"; } bool WLanNetNode::generateProperFilesFor( ANetNodeInstance * ) { return 1; } -bool WLanNetNode::hasDataFor( const QString & ) { - return 0; +bool WLanNetNode::hasDataFor( const QString & S, bool DS ) { + return DS && S == "interfaces"; } bool WLanNetNode::generateDataForCommonFile( SystemFile & , long, ANetNodeInstance * ) { return 1; } +bool WLanNetNode::generateDeviceDataForCommonFile( + SystemFile & S, + long DevNr, + ANetNodeInstance * NNI ) { + return ((AWLan *)NNI)->generateDeviceDataForCommonFile(S, DevNr); +} + extern "C" { void create_plugin( QList<ANetNode> & PNN ) { PNN.append( new WLanNetNode() ); } } diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.h b/noncore/settings/networksettings2/wlan/wlan_NN.h index 0728a79..9111995 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NN.h +++ b/noncore/settings/networksettings2/wlan/wlan_NN.h @@ -1,44 +1,46 @@ #ifndef WLAN_NETNODE_H #define WLAN_NETNODE_H #include "netnode.h" class AWLan; class WLanNetNode : public ANetNode{ Q_OBJECT public: WLanNetNode(); virtual ~WLanNetNode(); virtual const QString pixmapName() { return "Devices/wlan"; } virtual const QString nodeName() { return tr("WLan Device"); } virtual const QString nodeDescription() ; virtual ANetNodeInstance * createInstance( void ); virtual const char ** needs( void ); virtual const char * provides( void ); virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); + virtual bool hasDataFor( const QString & S, bool DS ); virtual bool generateDataForCommonFile( SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); + virtual bool generateDeviceDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ); private: }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp index 92f3457..8b948e0 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp @@ -1,30 +1,42 @@ #include "wlanedit.h" #include "wlan_NNI.h" #include "wlan_NN.h" AWLan::AWLan( WLanNetNode * PNN ) : ANetNodeInstance( PNN ) { GUI = 0; RT = 0; } void AWLan::setSpecificAttribute( QString & , QString & ) { } void AWLan::saveSpecificAttribute( QTextStream & ) { } QWidget * AWLan::edit( QWidget * parent ) { GUI = new WLanEdit( parent ); 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::generateDeviceDataForCommonFile( SystemFile & S, long DevNr ) { + AsDevice * Dev = runtime()->device(); + QString NIC = Dev->genNic( DevNr ); + + if( S.name() == "interfaces" ) { + // generate mapping stanza for this interface + S << "# check if " << NIC << " can be brought UP" << endl; + S << "mapping " << NIC << endl; + S << " script networksettings2-request" << endl << endl; + } + return 0; +} diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.h b/noncore/settings/networksettings2/wlan/wlan_NNI.h index 8b695b5..e464c84 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.h +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.h @@ -1,43 +1,45 @@ #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; } + bool generateDeviceDataForCommonFile( SystemFile & S, 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/wlanrun.h b/noncore/settings/networksettings2/wlan/wlanrun.h index 4cbb059..b853262 100644 --- a/noncore/settings/networksettings2/wlan/wlanrun.h +++ b/noncore/settings/networksettings2/wlan/wlanrun.h @@ -1,42 +1,44 @@ #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 long count( void ) { return 2; } virtual QString genNic( long nr ) { QString S; return S.sprintf( "wlan%ld", nr ); } virtual AsDevice * device( void ) - { return asDevice(); } + { 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; } bool handlesInterface( const QString & I ); private : QRegExp Pat; }; #endif |