author | wimpie <wimpie> | 2004-08-12 12:46:55 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2004-08-12 12:46:55 (UTC) |
commit | 8f215ba9ceb395f262517855a99d7d2d303ca760 (patch) (side-by-side diff) | |
tree | aa5f9b14c249217b4d3fc30f4771bdaf1c3545d3 | |
parent | ef64880308b5035cc8ca2e4e79325db613af525b (diff) | |
download | opie-8f215ba9ceb395f262517855a99d7d2d303ca760.zip opie-8f215ba9ceb395f262517855a99d7d2d303ca760.tar.gz opie-8f215ba9ceb395f262517855a99d7d2d303ca760.tar.bz2 |
MANY changes
- now generates peers/pap-chap secrets files
(no chatscript yet)
(not all usefull ppp options included yet)
- still not ready for prime time yet
69 files changed, 1308 insertions, 1190 deletions
diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp index d8420b9..398dcdc 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp @@ -35,16 +35,8 @@ QWidget * ABluetoothBNEP::edit( QWidget * parent ) { QString ABluetoothBNEP::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ABluetoothBNEP::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } - -bool ABluetoothBNEP::hasDataFor( const QString & ) { - return 0; -} - -bool ABluetoothBNEP::generateDataForCommonFile( SystemFile & , long ){ - return 0; -} diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.h b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.h index bb3e7e7..1bf0f48 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.h @@ -9,32 +9,28 @@ class BluetoothBNEPNetNode; class BluetoothBNEPEdit; class ABluetoothBNEP : public ANetNodeInstance { public : ABluetoothBNEP( BluetoothBNEPNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new BluetoothBNEPRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new BluetoothBNEPRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & S ); - virtual bool generateDataForCommonFile( SystemFile & SF, long ); - protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : BluetoothBNEPEdit * GUI; diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp index cff2639..7ec8288 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp @@ -23,16 +23,8 @@ QWidget * ABluetoothRFCOMM::edit( QWidget * parent ) { QString ABluetoothRFCOMM::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ABluetoothRFCOMM::commit( void ) { if( GUI->commit( Data ) ) setModified( 1 ); } - -bool ABluetoothRFCOMM::hasDataFor( const QString & ) { - return 0; -} - -bool ABluetoothRFCOMM::generateDataForCommonFile( SystemFile & , long ){ - return 0; -} diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.h index 97bd29c..820fc17 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.h @@ -9,32 +9,28 @@ class BluetoothRFCOMMNetNode; class BluetoothRFCOMMEdit; class ABluetoothRFCOMM : public ANetNodeInstance { public : ABluetoothRFCOMM( BluetoothRFCOMMNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new BluetoothRFCOMMRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new BluetoothRFCOMMRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & S ); - virtual bool generateDataForCommonFile( SystemFile & SF, long ); - protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : BluetoothRFCOMMEdit * GUI; diff --git a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h index aff1f59..65fd686 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h +++ b/noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h @@ -7,16 +7,19 @@ public : BluetoothRFCOMMRun( ANetNodeInstance * NNI, BluetoothRFCOMMData & Data ) : AsLine( NNI ) { } virtual AsLine * asLine( void ) { return (AsLine *)this; } + virtual QString deviceFile( void ) + { return QString( "/dev/rfcomm..." ); } + protected : void detectState( NodeCollection * ) { } bool setState( NodeCollection * , Action_t, bool ) { return 0; } diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp index b59b4f0..443a627 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp +++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp @@ -41,39 +41,16 @@ ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) { const char ** BluetoothBNEPNetNode::needs( void ) { return BluetoothBNEPNeeds; } const char * BluetoothBNEPNetNode::provides( void ) { return "device"; } -bool BluetoothBNEPNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool BluetoothBNEPNetNode::hasDataFor( const QString & S ) { - return S == "interfaces"; -} - -bool BluetoothBNEPNetNode::generateDeviceDataForCommonFile( - SystemFile & S , - long DevNr) { - QString NIC = 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; -} - QString BluetoothBNEPNetNode::genNic( long nr ) { QString S; return S.sprintf( "bnep%ld", nr ); } void BluetoothBNEPNetNode::setSpecificAttribute( QString & A, QString & V ) { if( A == "interfacecount" ) { @@ -119,31 +96,16 @@ ANetNodeInstance * BluetoothRFCOMMNetNode::createInstance( void ) { 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 & ) { - return 0; -} - -bool BluetoothRFCOMMNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void BluetoothRFCOMMNetNode::setSpecificAttribute( QString &, QString & ) { } void BluetoothRFCOMMNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h index 2e5e1d2..4d6a3c1 100644 --- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h +++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h @@ -2,75 +2,60 @@ #define BLUETOOTH_NETNODE_H #include "netnode.h" class ABluetoothBNEP; class BluetoothBNEPNetNode : public ANetNode { - Q_OBJECT + Q_OBJECT public: - BluetoothBNEPNetNode(); - virtual ~BluetoothBNEPNetNode(); + BluetoothBNEPNetNode(); + virtual ~BluetoothBNEPNetNode(); - virtual const QString pixmapName() - { return "Devices/bluetooth"; } + virtual QString genNic( long ); + virtual long instanceCount( void ) + { return InstanceCount; } + virtual const QString pixmapName() + { return "Devices/bluetooth"; } - 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 generateDeviceDataForCommonFile( - SystemFile & , long DevNr ); - - virtual long instanceCount( void ) - { return InstanceCount; } - virtual QString genNic( long ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char * provides( void ); + virtual const char ** needs( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); // number of interfaces for this device long InstanceCount; }; class BluetoothRFCOMMNetNode : public ANetNode { - Q_OBJECT + Q_OBJECT public: - BluetoothRFCOMMNetNode(); - virtual ~BluetoothRFCOMMNetNode(); - - virtual const QString pixmapName() - { return "Devices/bluetooth"; } - - virtual const QString nodeDescription() ; - - virtual ANetNodeInstance * createInstance( void ); + BluetoothRFCOMMNetNode(); + virtual ~BluetoothRFCOMMNetNode(); - virtual const char ** needs( void ); - virtual const char * provides( void ); + virtual const QString pixmapName() + { return "Devices/bluetooth"; } - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & S ); - virtual bool generateDeviceDataForCommonFile( - SystemFile & , long ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" diff --git a/noncore/settings/networksettings2/cable/cable_NN.cpp b/noncore/settings/networksettings2/cable/cable_NN.cpp index b8c690b..38568df 100644 --- a/noncore/settings/networksettings2/cable/cable_NN.cpp +++ b/noncore/settings/networksettings2/cable/cable_NN.cpp @@ -31,27 +31,16 @@ ANetNodeInstance * CableNetNode::createInstance( void ) { const char ** CableNetNode::needs( void ) { return CableNeeds; } const char * CableNetNode::provides( void ) { return "line"; } -bool CableNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool CableNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void CableNetNode::setSpecificAttribute( QString & , QString & ) { } void CableNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { diff --git a/noncore/settings/networksettings2/cable/cable_NN.h b/noncore/settings/networksettings2/cable/cable_NN.h index c48037a..5cc2b2d 100644 --- a/noncore/settings/networksettings2/cable/cable_NN.h +++ b/noncore/settings/networksettings2/cable/cable_NN.h @@ -2,38 +2,30 @@ #define CABLE_NETNODE_H #include "netnode.h" class ACable; class CableNetNode : public ANetNode { - Q_OBJECT + Q_OBJECT public: - CableNetNode(); - virtual ~CableNetNode(); + CableNetNode(); + virtual ~CableNetNode(); - virtual const QString pixmapName() - { return "Devices/cable"; } + virtual const QString pixmapName() + { return "Devices/cable"; } - 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 & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" diff --git a/noncore/settings/networksettings2/cable/cable_NNI.cpp b/noncore/settings/networksettings2/cable/cable_NNI.cpp index ca21135..4bd9421 100644 --- a/noncore/settings/networksettings2/cable/cable_NNI.cpp +++ b/noncore/settings/networksettings2/cable/cable_NNI.cpp @@ -44,30 +44,46 @@ void ACable::saveSpecificAttribute( QTextStream & TS ) { TS << "databits=" << Data.DataBits << endl; TS << "stopbits=" << Data.StopBits << endl; TS << "hardwarecontrol=" << ((Data.HardwareControl) ? "yes" : "no") << endl; TS << "softwarecontrol=" << ((Data.SoftwareControl) ? "yes" : "no") << endl; } +short ACable::generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { + short rvl, rvd; + + rvl = 1; + if( ID == "peers" ) { + TS << Data.Device + << endl; + TS << Data.Speed + << endl; + TS << "lock " + << Data.LockFile + << endl; + rvl = 0; + } + + rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr ); + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; +} + QWidget * ACable::edit( QWidget * parent ) { GUI = new CableEdit( parent ); GUI->showData( Data ); return GUI; } QString ACable::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ACable::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } - -bool ACable::generateDataForCommonFile( - SystemFile & , - long ) { - return 1; -} - diff --git a/noncore/settings/networksettings2/cable/cable_NNI.h b/noncore/settings/networksettings2/cable/cable_NNI.h index bf3e292..d06cbbe 100644 --- a/noncore/settings/networksettings2/cable/cable_NNI.h +++ b/noncore/settings/networksettings2/cable/cable_NNI.h @@ -9,34 +9,32 @@ class CableNetNode; class CableEdit; class ACable : public ANetNodeInstance { public : ACable( CableNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new CableRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new CableRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); - + short generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : CableEdit * GUI; diff --git a/noncore/settings/networksettings2/cable/cablerun.cpp b/noncore/settings/networksettings2/cable/cablerun.cpp index 5e99237..85660f6 100644 --- a/noncore/settings/networksettings2/cable/cablerun.cpp +++ b/noncore/settings/networksettings2/cable/cablerun.cpp @@ -1,15 +1,15 @@ #include <fcntl.h> #include <unistd.h> #include "cablerun.h" void CableRun::detectState( NodeCollection * NC ) { - int fd = open( D->Device.latin1(), O_RDWR ); + int fd = open( Data->Device.latin1(), O_RDWR ); if( fd < 0 ) { NC->setCurrentState( Unavailable ); } close( fd ); NC->setCurrentState( Available ); } @@ -19,8 +19,12 @@ bool CableRun::setState( NodeCollection * NC, Action_t A, bool ) { return (NC->currentState() == Available); } return 1; } bool CableRun::canSetState( State_t , Action_t ) { return 1; } + +QString CableRun::deviceFile( void ) { + return Data->Device; +} diff --git a/noncore/settings/networksettings2/cable/cablerun.h b/noncore/settings/networksettings2/cable/cablerun.h index c5b59d5..20608f6 100644 --- a/noncore/settings/networksettings2/cable/cablerun.h +++ b/noncore/settings/networksettings2/cable/cablerun.h @@ -1,24 +1,26 @@ #include <asline.h> #include "cabledata.h" class CableRun : public AsLine { public : CableRun( ANetNodeInstance * NNI, - CableData & Data ) : AsLine( NNI ) - { D = &Data; } + CableData_t & D ) : AsLine( NNI ) + { Data = &D; } virtual AsLine * asLine( void ) { return (AsLine *)this; } + virtual QString deviceFile( void ); + protected : void detectState( NodeCollection * NC ); bool setState( NodeCollection * NC, Action_t A, bool Force ); bool canSetState( State_t Curr, Action_t A ); private : - CableData_t * D; + CableData_t * Data; }; diff --git a/noncore/settings/networksettings2/irda/irda_NN.cpp b/noncore/settings/networksettings2/irda/irda_NN.cpp index 49bc06e..9483e22 100644 --- a/noncore/settings/networksettings2/irda/irda_NN.cpp +++ b/noncore/settings/networksettings2/irda/irda_NN.cpp @@ -31,27 +31,16 @@ ANetNodeInstance * IRDANetNode::createInstance( void ) { const char ** IRDANetNode::needs( void ) { return IRDANeeds; } const char * IRDANetNode::provides( void ) { return "line"; } -bool IRDANetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool IRDANetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void IRDANetNode::setSpecificAttribute( QString & , QString & ) { } void IRDANetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { diff --git a/noncore/settings/networksettings2/irda/irda_NN.h b/noncore/settings/networksettings2/irda/irda_NN.h index fa6408d..900bbc6 100644 --- a/noncore/settings/networksettings2/irda/irda_NN.h +++ b/noncore/settings/networksettings2/irda/irda_NN.h @@ -2,38 +2,30 @@ #define IRDA_NETNODE_H #include "netnode.h" class AIRDA; class IRDANetNode : public ANetNode { - Q_OBJECT + Q_OBJECT public: - IRDANetNode(); - virtual ~IRDANetNode(); + IRDANetNode(); + virtual ~IRDANetNode(); - virtual const QString pixmapName() - { return "Devices/irda"; } + virtual const QString pixmapName() + { return "Devices/irda"; } - 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 & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" diff --git a/noncore/settings/networksettings2/irda/irda_NNI.cpp b/noncore/settings/networksettings2/irda/irda_NNI.cpp index f00a1d5..9cf443b 100644 --- a/noncore/settings/networksettings2/irda/irda_NNI.cpp +++ b/noncore/settings/networksettings2/irda/irda_NNI.cpp @@ -24,14 +24,8 @@ QString AIRDA::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AIRDA::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } -bool AIRDA::generateDataForCommonFile( - SystemFile & , - long ) { - return 1; -} - diff --git a/noncore/settings/networksettings2/irda/irda_NNI.h b/noncore/settings/networksettings2/irda/irda_NNI.h index 210d87d..e21b68f 100644 --- a/noncore/settings/networksettings2/irda/irda_NNI.h +++ b/noncore/settings/networksettings2/irda/irda_NNI.h @@ -9,34 +9,28 @@ class IRDANetNode; class IRDAEdit; class AIRDA : public ANetNodeInstance { public : AIRDA( IRDANetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new IRDARun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new IRDARun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); - protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : IRDAEdit * GUI; diff --git a/noncore/settings/networksettings2/irda/irdarun.h b/noncore/settings/networksettings2/irda/irdarun.h index 4c903cc..4258aff 100644 --- a/noncore/settings/networksettings2/irda/irdarun.h +++ b/noncore/settings/networksettings2/irda/irdarun.h @@ -7,16 +7,19 @@ public : IRDARun( ANetNodeInstance * NNI, IRDAData & Data ) : AsLine( NNI ) { } virtual AsLine * asLine( void ) { return (AsLine *)this; } + virtual QString deviceFile( void ) + { return QString( "/dev/irda" ); } + protected : void detectState( NodeCollection * ) { } bool setState( NodeCollection * , Action_t, bool ) { return 0; } diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.cpp b/noncore/settings/networksettings2/lancard/lancard_NN.cpp index 05cd06d..20ae7f6 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NN.cpp +++ b/noncore/settings/networksettings2/lancard/lancard_NN.cpp @@ -33,39 +33,16 @@ ANetNodeInstance * LanCardNetNode::createInstance( void ) { const char ** LanCardNetNode::needs( void ) { return LanCardNeeds; } const char * LanCardNetNode::provides( void ) { return "device"; } -bool LanCardNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool LanCardNetNode::hasDataFor( const QString & S ) { - return S == "interfaces"; -} - -bool LanCardNetNode::generateDeviceDataForCommonFile( - SystemFile & S , - long DevNr ) { - QString NIC = 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; -} - QString LanCardNetNode::genNic( long nr ) { QString S; return S.sprintf( "eth%ld", nr ); } void LanCardNetNode::setSpecificAttribute( QString & A, QString & V ) { if( A == "interfacecount" ) { InstanceCount = V.toLong(); diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.h b/noncore/settings/networksettings2/lancard/lancard_NN.h index d58823c..6882af7 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NN.h +++ b/noncore/settings/networksettings2/lancard/lancard_NN.h @@ -13,33 +13,26 @@ class LanCardNetNode : public ANetNode{ public: LanCardNetNode(); virtual ~LanCardNetNode(); virtual const QString pixmapName() { return "Devices/card"; } - virtual const QString nodeDescription() ; + virtual QString genNic( long ); + virtual long instanceCount( void ) + { return InstanceCount; } + 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 generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - - virtual long instanceCount( void ) - { return InstanceCount; } - - virtual QString genNic( long ); - virtual QStringList & addressesOfNIC( void ) + QStringList & addressesOfNIC( void ) { return NICMACAddresses; } private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); // number of interfaces for this device diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp index 99c033e..9fb05b9 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp +++ b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp @@ -38,14 +38,8 @@ QString ALanCard::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ALanCard::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } -bool ALanCard::generateDataForCommonFile( - SystemFile & , - long ) { - return 1; -} - diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.h b/noncore/settings/networksettings2/lancard/lancard_NNI.h index 4e91523..8e55a19 100644 --- a/noncore/settings/networksettings2/lancard/lancard_NNI.h +++ b/noncore/settings/networksettings2/lancard/lancard_NNI.h @@ -9,33 +9,28 @@ class LanCardNetNode; class LanCardEdit; class ALanCard : public ANetNodeInstance { public : ALanCard( LanCardNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new LanCardRun( this, Data ) ); + } + 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; } - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDataForCommonFile( - SystemFile & S, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : LanCardEdit * GUI; diff --git a/noncore/settings/networksettings2/main.cpp b/noncore/settings/networksettings2/main.cpp index 6c969fc..b32b323 100644 --- a/noncore/settings/networksettings2/main.cpp +++ b/noncore/settings/networksettings2/main.cpp @@ -1,10 +1,11 @@ #include "nsdata.h" #include "activateprofile.h" +#include "activatevpn.h" #include "networksettings.h" #include <qpe/qpeapplication.h> #include <opie2/oapplicationfactory.h> using namespace Opie::Core; #ifdef GONE @@ -16,16 +17,18 @@ OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> ) // just standard GUI #define ACT_GUI 0 // used by interfaces to request for allow of up/down #define ACT_REQUEST 1 // regenerate config files #define ACT_REGEN 2 // used by interfaces to request user prompt #define ACT_PROMPT 3 +// used by interfaces to trigger VPN +#define ACT_VPN 4 int main( int argc, char * argv[] ) { int rv = 0; int Action = ACT_GUI; // could be overruled by -qws QApplication::Type GuiType = QApplication::GuiClient; #ifdef _WS_QWS_ @@ -39,16 +42,19 @@ int main( int argc, char * argv[] ) { rmv = 0; if( strcmp( argv[i], "--regen" ) == 0 ) { Action = ACT_REGEN; GuiType = QApplication::Tty; rmv = 1; } else if( strcmp( argv[i], "--prompt" ) == 0 ) { Action = ACT_PROMPT; rmv = 1; + } else if( strcmp( argv[i], "--triggervpn" ) == 0 ) { + Action = ACT_VPN; + rmv = 1; } if( rmv ) { memmove( argv+i, argv+i+rmv, sizeof( char * ) * (argc-i-rmv) ); i --; argc -= rmv; } } @@ -73,53 +79,53 @@ int main( int argc, char * argv[] ) { TheApp = new QApplication( argc, argv, GuiType ); #endif // init qt with app widget switch( Action ) { case ACT_REQUEST : { NetworkSettingsData NS; - Log(("ACT_REQUEST\n")); if( NS.canStart( argv[1] ) ) { QString S; - Log(("NEED FOR PROMPT\n" )); S.sprintf( QPEApplication::qpeDir()+ "/bin/networksettings2" ); char * MyArgv[4]; MyArgv[0] = "networksettings2"; MyArgv[1] = "--prompt"; MyArgv[2] = argv[1]; MyArgv[3] = NULL; NSResources->system().execAsUser( S, MyArgv ); // if we come here , failed printf( "%s-cNN-disallowed", argv[1] ); } } break; case ACT_REGEN : { NetworkSettingsData NS; - Log(("REGEN\n" )); // regen returns 0 if OK rv = (NS.regenerate()) ? 1 : 0; } break; case ACT_PROMPT : { ActivateProfile AP(argv[1]); - Log(("PROMPT\n" )); if( AP.exec() == QDialog::Accepted ) { printf( "%s-c%ld-allowed", argv[1], AP.selectedProfile() ); } else { printf( "%s-cNN-disallowed", argv[1] ); } } break; + case ACT_VPN : + { ActivateVPN AVPN; + AVPN.exec(); + } + break; case ACT_GUI : { QWidget * W = new NetworkSettings(0); - Log(("GUI\n" )); TheApp->setMainWidget( W ); W->show(); #ifdef _WS_QWS_ W->showMaximized(); #else W->resize( W->sizeHint() ); #endif rv = TheApp->exec(); diff --git a/noncore/settings/networksettings2/modem/modem_NN.cpp b/noncore/settings/networksettings2/modem/modem_NN.cpp index 18aa480..ee61b10 100644 --- a/noncore/settings/networksettings2/modem/modem_NN.cpp +++ b/noncore/settings/networksettings2/modem/modem_NN.cpp @@ -32,27 +32,16 @@ ANetNodeInstance * ModemNetNode::createInstance( void ) { const char ** ModemNetNode::needs( void ) { return ModemNeeds; } const char * ModemNetNode::provides( void ) { return "line"; } -bool ModemNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool ModemNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void ModemNetNode::setSpecificAttribute( QString & , QString & ) { } void ModemNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { diff --git a/noncore/settings/networksettings2/modem/modem_NN.h b/noncore/settings/networksettings2/modem/modem_NN.h index 2f496dd..a76525f 100644 --- a/noncore/settings/networksettings2/modem/modem_NN.h +++ b/noncore/settings/networksettings2/modem/modem_NN.h @@ -13,28 +13,20 @@ public: ModemNetNode(); virtual ~ModemNetNode(); virtual const QString pixmapName() { return "Devices/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 & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { diff --git a/noncore/settings/networksettings2/modem/modem_NNI.cpp b/noncore/settings/networksettings2/modem/modem_NNI.cpp index 6c76b56..91df22b 100644 --- a/noncore/settings/networksettings2/modem/modem_NNI.cpp +++ b/noncore/settings/networksettings2/modem/modem_NNI.cpp @@ -24,14 +24,8 @@ QString AModem::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AModem::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } -bool AModem::generateDataForCommonFile( - SystemFile & , - long ) { - return 1; -} - diff --git a/noncore/settings/networksettings2/modem/modem_NNI.h b/noncore/settings/networksettings2/modem/modem_NNI.h index a623704..ca7c279 100644 --- a/noncore/settings/networksettings2/modem/modem_NNI.h +++ b/noncore/settings/networksettings2/modem/modem_NNI.h @@ -9,34 +9,28 @@ class ModemNetNode; class ModemEdit; class AModem : public ANetNodeInstance { public : AModem( ModemNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new ModemRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new ModemRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); - protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : ModemEdit * GUI; diff --git a/noncore/settings/networksettings2/modem/modemrun.h b/noncore/settings/networksettings2/modem/modemrun.h index 336462e..491a677 100644 --- a/noncore/settings/networksettings2/modem/modemrun.h +++ b/noncore/settings/networksettings2/modem/modemrun.h @@ -7,16 +7,19 @@ public : ModemRun( ANetNodeInstance * NNI, ModemData & Data ) : AsLine ( NNI ) { } virtual AsLine * asLine( void ) { return (AsLine *)this; } + virtual QString deviceFile( void ) + { return QString("/dev/modem"); } + protected : void detectState( NodeCollection * ) { } bool setState( NodeCollection *, Action_t, bool ) { return 0; } diff --git a/noncore/settings/networksettings2/network/network_NN.cpp b/noncore/settings/networksettings2/network/network_NN.cpp index b4313c4..1feffdb 100644 --- a/noncore/settings/networksettings2/network/network_NN.cpp +++ b/noncore/settings/networksettings2/network/network_NN.cpp @@ -1,8 +1,9 @@ +#include <asdevice.h> #include "network_NN.h" #include "network_NNI.h" static const char * NetworkNeeds[] = { "device", 0 }; @@ -25,33 +26,52 @@ const QString NetworkNetNode::nodeDescription(){ " ); } ANetNodeInstance * NetworkNetNode::createInstance( void ) { return new ANetwork( this ); } -const char ** NetworkNetNode::needs( void ) { - return NetworkNeeds; +bool NetworkNetNode::hasDataForFile( const QString & S ) { + return S == "interfaces"; } -const char * NetworkNetNode::provides( void ) { - return "connection"; +short NetworkNetNode::generateFile( const QString & ID, + const QString & , + QTextStream & TS, + ANetNodeInstance * NNI, + long DevNr ) { + + QString NIC = NNI->runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); + + if( ID == "interfaces" ) { + Log(("Generate entry for %s in %s\n", NIC.latin1(), ID.latin1() )); + // generate mapping stanza for this interface + TS << "# check if " + << NIC + << " can be brought UP" + << endl; + TS << "mapping " + << NIC + << endl; + TS << " script networksettings2-request" + << endl + << endl; + return 0; + } + return 1; } -bool NetworkNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; +const char ** NetworkNetNode::needs( void ) { + return NetworkNeeds; } -bool NetworkNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; +const char * NetworkNetNode::provides( void ) { + return "connection"; } void NetworkNetNode::setSpecificAttribute( QString & , QString & ) { } void NetworkNetNode::saveSpecificAttribute( QTextStream & ) { } diff --git a/noncore/settings/networksettings2/network/network_NN.h b/noncore/settings/networksettings2/network/network_NN.h index 6548c32..745d1a7 100644 --- a/noncore/settings/networksettings2/network/network_NN.h +++ b/noncore/settings/networksettings2/network/network_NN.h @@ -2,38 +2,37 @@ #define NETWORK_NETNODE_H #include "netnode.h" class ANetwork; class NetworkNetNode : public ANetNode{ - Q_OBJECT + Q_OBJECT public: - NetworkNetNode(); - virtual ~NetworkNetNode(); + NetworkNetNode(); + virtual ~NetworkNetNode(); - virtual const QString pixmapName() - { return "Devices/tcpip"; } + virtual bool hasDataForFile( const QString & S ); - virtual const QString nodeDescription() ; + virtual short generateFile( const QString & ID, + const QString & Path, + QTextStream & TS, + ANetNodeInstance * NNI, + long DevNr ); + virtual const QString pixmapName() + { return "Devices/tcpip"; } - virtual ANetNodeInstance * createInstance( void ); - - virtual const char ** needs( void ); - virtual const char * provides( void ); - - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp index 3e368a2..324c6e2 100644 --- a/noncore/settings/networksettings2/network/network_NNI.cpp +++ b/noncore/settings/networksettings2/network/network_NNI.cpp @@ -94,96 +94,126 @@ QString ANetwork::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void ANetwork::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } -bool ANetwork::hasDataFor( const QString & S ) { +bool ANetwork::hasDataForFile( const QString & S ) { return S == "interfaces"; } -bool ANetwork::generateDataForCommonFile( SystemFile & S, long DevNr ) { +short ANetwork::generateFile( const QString & ID, + const QString & Path, + QTextStream &TS, + long DevNr + ) { + + short rvl, rvd ; QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); - if( S.name() == "interfaces" ) { + rvl = 1; + if( ID == "interfaces" ) { + Log(("Generate Network for %s\n", ID.latin1() )); // 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" - << endl; + TS << "iface " + << NIC + << "-c" + << connection()->number() + << "-allowed inet dhcp" + << endl; + TS << " up echo \"" + << NIC + << "\" > /tmp/profile-" + << connection()->number() + << ".up" + << endl; if( Data.SendHostname ) { - S << " hostname " - << Data.Hostname - << endl; + TS << " hostname " + << Data.Hostname + << endl; } - S << " down rm -f /tmp/profile-" - << connection()->number() - << ".up" - << endl; + TS << " down rm -f /tmp/profile-" + << connection()->number() + << ".up" + << endl; } else { - S << "iface " - << NIC << "-c" - << connection()->number() - << "-allowed inet static" - << endl; - S << " up echo \"" - << NIC - << "\" > /tmp/profile-" - << connection()->number() - << ".up" - << endl; - S << " down rm -f /tmp/profile-" - << connection()->number() - << ".up" - << endl; - S << " address " << Data.IPAddress << endl; - S << " broadcast " << Data.Broadcast << endl; - S << " netmask " << Data.NetMask << endl; + TS << "iface " + << NIC << "-c" + << connection()->number() + << "-allowed inet static" + << endl; + TS << " up echo \"" + << NIC + << "\" > /tmp/profile-" + << connection()->number() + << ".up" + << endl; + TS << " down rm -f /tmp/profile-" + << connection()->number() + << ".up" + << endl; + TS << " address " + << Data.IPAddress + << endl; + TS << " broadcast " + << Data.Broadcast + << endl; + TS << " 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; + TS << " network " + << NW + << endl; } } for ( QStringList::Iterator it = Data.PreUp_SL.begin(); it != Data.PreUp_SL.end(); ++it ) { - S << " pre-up " << (*it) << endl; + TS << " pre-up " + << (*it) + << endl; } for ( QStringList::Iterator it = Data.PostUp_SL.begin(); it != Data.PostUp_SL.end(); ++it ) { - S << " up " << (*it) << endl; + TS << " up " + << (*it) + << endl; } for ( QStringList::Iterator it = Data.PreDown_SL.begin(); it != Data.PreDown_SL.end(); ++it ) { - S << " down " << (*it) << endl; + TS << " down " + << (*it) + << endl; } for ( QStringList::Iterator it = Data.PostDown_SL.begin(); it != Data.PostDown_SL.end(); ++it ) { - S << " post-down " << (*it) << endl; + TS << " post-down " + << (*it) + << endl; } + rvl = 0; } - return 0; + + // embed other info in it + rvd = connection()->getToplevel()->generateFileEmbedded( ID, Path, TS, DevNr ); + + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; } diff --git a/noncore/settings/networksettings2/network/network_NNI.h b/noncore/settings/networksettings2/network/network_NNI.h index 0058793..5e42503 100644 --- a/noncore/settings/networksettings2/network/network_NNI.h +++ b/noncore/settings/networksettings2/network/network_NNI.h @@ -10,32 +10,33 @@ class NetworkEdit; class SystemFile; class ANetwork : public ANetNodeInstance{ public : ANetwork( NetworkNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new NetworkRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new NetworkRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & S ); - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); + virtual bool hasDataForFile( const QString & S ); + virtual short generateFile( const QString & ID, + const QString & Path, + QTextStream &TS, + long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index 6ee4106..ce0eabc 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp @@ -1,22 +1,24 @@ #include <stdio.h> #include <unistd.h> +#include <errno.h> #include <qpe/qpeapplication.h> #include <qlistbox.h> #include <qgroupbox.h> #include <qtimer.h> #include <qlistbox.h> #include <qmessagebox.h> #include <qlabel.h> #include <qiconview.h> #include <qtimer.h> #include <qpe/qpeapplication.h> #include <qtoolbutton.h> +#include <qevent.h> #include <asdevice.h> #include "networksettings.h" #include "netnode.h" #include "editconnection.h" NetworkSettings::NetworkSettings( QWidget *parent, const char *name, @@ -36,16 +38,23 @@ NetworkSettings::NetworkSettings( QWidget *parent, Disconnect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); On_TB->setPixmap( NSResources->getPixmap( "off" ) ); SLOT_ToProfile(); // populate main Listbox Profiles_LB->clear(); + QPEApplication::setStylusOperation( + Profiles_LB->viewport(), QPEApplication::RightOnHold ); + + connect( Profiles_LB, + SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), + this, SLOT(SLOT_EditNode(QListBoxItem*)) ); + { Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; // for all connections for( QDictIterator<NodeCollection> it(M); it.current(); ++it ) { NC = it.current(); Profiles_LB->insertItem( NC->devicePixmap(), @@ -73,32 +82,28 @@ NetworkSettings::NetworkSettings( QWidget *parent, /* Add QCopChannel */ connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); } NetworkSettings::~NetworkSettings() { QString S; - S = NSD.generateSettings(); - if( ! S.isEmpty() ) { - QMessageBox::warning( - 0, - tr( "In System Config" ), - S - ); - } + if( isModified() ) { + S = NSD.saveSettings(); + if( ! S.isEmpty() ) { + // problem saving + QMessageBox::warning( + 0, + tr( "Saving setup" ), S ); + } - S = NSD.saveSettings(); - if( ! S.isEmpty() ) { - // problem saving - QMessageBox::warning( - 0, - tr( "Saving setup" ), S ); + SLOT_GenerateConfig(); } + } void NetworkSettings::SLOT_CmdMessage( const QString & S ) { Messages_LB->insertItem( S ); Messages_LB->setCurrentItem( Messages_LB->count()-1 ); Messages_LB->ensureCurrentVisible(); } @@ -140,19 +145,16 @@ void NetworkSettings::SLOT_RefreshStates( void ) { } } } if( ci >= 0 ) Profiles_LB->setCurrentItem( ci ); */ } -void NetworkSettings::SLOT_NoLongerBusy( void ) { - NSResources->busy( FALSE ); -} void NetworkSettings::SLOT_AddNode( void ) { SLOT_EditNode( 0 ); } void NetworkSettings::SLOT_DeleteNode( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); if ( ! LBI ) @@ -161,38 +163,38 @@ void NetworkSettings::SLOT_DeleteNode( void ) { 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 = ""; + + printf( "------------------ Edit NOde\n" ); EditConnection EC( this ); if( LBI ) { NodeCollection * NC = NSResources->findConnection( LBI->text() ); if( ! NC ) { return; } OldName = NC->name(); EC.setConnection( NC ); } EC.showMaximized(); // disable refresh timer UpdateTimer->stop(); - NSResources->busy( TRUE ); - QTimer::singleShot( 1000, this, SLOT( SLOT_NoLongerBusy() )); + // 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 ) { @@ -314,25 +316,17 @@ void NetworkSettings::SLOT_CheckState( void ) { void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { SLOT_ShowNode( LBI ); } } void NetworkSettings::SLOT_GenerateConfig( void ) { - QString S = NSD.generateSettings( TRUE ); - - if( ! S.isEmpty() ) { - QMessageBox::warning( - 0, - tr( "Generating system configuration" ), - S - ); - } + NSD.regenerate(); } void NetworkSettings::SLOT_Enable( void ) { QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); QString Msg; if ( ! LBI ) return; diff --git a/noncore/settings/networksettings2/networksettings.h b/noncore/settings/networksettings2/networksettings.h index 8ffde06..8ec5d08 100644 --- a/noncore/settings/networksettings2/networksettings.h +++ b/noncore/settings/networksettings2/networksettings.h @@ -1,16 +1,17 @@ #include "nsdata.h" #include "networksettingsGUI.h" #include "resources.h" class ANetNode; class ANetNodeInstance; class QTimer; class QListBoxItem; +class QEvent; class NetworkSettings : public NetworkSettingsGUI { Q_OBJECT public : NetworkSettings( QWidget *parent=0, @@ -23,17 +24,16 @@ public : bool isModified( void ) { return NSD.isModified(); } void setModified( bool m ) { NSD.setModified( m ); } public slots : - void SLOT_NoLongerBusy( void ); void SLOT_AddNode( void ); void SLOT_DeleteNode( void ); void SLOT_ShowNode( QListBoxItem * ); void SLOT_EditNode( QListBoxItem * ); void SLOT_CheckState( void ); void SLOT_Enable( void ); void SLOT_On( void ); void SLOT_Connect( void ); @@ -45,10 +45,9 @@ public slots : void SLOT_ToMessages( void ); void SLOT_CmdMessage( const QString & S ); private : void updateProfileState( QListBoxItem * it ); QTimer * UpdateTimer; NetworkSettingsData NSD; - }; diff --git a/noncore/settings/networksettings2/networksettings.pro b/noncore/settings/networksettings2/networksettings.pro index ff147b1..f04289b 100644 --- a/noncore/settings/networksettings2/networksettings.pro +++ b/noncore/settings/networksettings2/networksettings.pro @@ -1,21 +1,24 @@ # CONFIG = qt warn_on debug #CONFIG = qt warn_on release HEADERS = networksettings.h \ activateprofile.h \ + activatevpn.h \ editconnection.h SOURCES = main.cpp \ networksettings.cpp \ nsdata.cpp \ activateprofile.cpp \ + activatevpn.cpp \ editconnection.cpp INCLUDEPATH += $(OPIEDIR)/include networksettings2/ DEPENDPATH += $(OPIEDIR)/include networksettings2/ LIBS += -lqpe -L$(OPIEDIR)/plugins/networksettings2 -lnetworksettings2 -lopiecore2 INTERFACES = networksettingsGUI.ui \ editconnectionGUI.ui \ + activatevpnGUI.ui \ activateprofileGUI.ui TARGET = $(OPIEDIR)/bin/networksettings2 include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/networksettings2/Utils.h b/noncore/settings/networksettings2/networksettings2/Utils.h index 63ef51c..739476e 100644 --- a/noncore/settings/networksettings2/networksettings2/Utils.h +++ b/noncore/settings/networksettings2/networksettings2/Utils.h @@ -1,8 +1,9 @@ #ifndef __UTILS_H #define __UTILS_H #define Log(x) VLog x extern void VLog( char * Format, ... ); extern void LogClose( void ); +extern QString removeSpaces( const QString & X ); #endif diff --git a/noncore/settings/networksettings2/networksettings2/asline.h b/noncore/settings/networksettings2/networksettings2/asline.h index 6bd93ec..ee4de38 100644 --- a/noncore/settings/networksettings2/networksettings2/asline.h +++ b/noncore/settings/networksettings2/networksettings2/asline.h @@ -8,11 +8,13 @@ class AsLine : public RuntimeInfo { public : AsLine( ANetNodeInstance * NNI ) : RuntimeInfo( NNI ) { } + virtual QString deviceFile( void ) = 0; + }; #endif diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp index 8c80e0b..4a2440a 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.cpp +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -139,17 +139,17 @@ NodeCollection::NodeCollection( QTextStream & TS ) : A.lower(); N = S.mid( idx+1, S.length() ); N.stripWhiteSpace(); N = deQuote( N ); if( A == "name" ) { Name = N; } else if( A == "number" ) { - Log(( "read number %s\n", N.latin1() )); + Log(( "Profile number %s\n", N.latin1() )); setNumber( N.toLong() ); } else if( A == "node" ) { ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); if( NNI && ! InError ) { append( NSResources->findNodeInstance( N ) ); } else { // could not find a node type -> collection invalid InError = 1; @@ -290,18 +290,37 @@ void NodeCollection::reassign( void ) { for( QListIterator<ANetNodeInstance> it(*this); it.current(); ++it ) { it.current()->setConnection( this ); } } bool NodeCollection::triggersVPN() { - return getToplevel()->runtime()->asFullSetup()->triggersVPN(); + return getToplevel()->runtime()->asFullSetup()->triggersVPN(); } + +bool NodeCollection::hasDataForFile( const QString & S ) { + return ( firstWithDataForFile( S ) != 0 ); +} + +ANetNodeInstance * NodeCollection::firstWithDataForFile( const QString & S ) { + for( QListIterator<ANetNodeInstance> it(*this); + it.current(); + ++it ) { + if( it.current()->hasDataForFile( S ) ) { + Log(( "Node %s has data for %s\n", + it.current()->nodeClass()->name(), + S.latin1() )); + return it.current(); + } + } + return 0; +} + // // // RUNTIMEINFO // // InterfaceInfo * RuntimeInfo::assignedInterface( void ) { return netNode()->nextNode()->runtime()->assignedInterface(); diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h index ca35c27..d3d7b34 100644 --- a/noncore/settings/networksettings2/networksettings2/netnode.h +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -1,15 +1,16 @@ #ifndef NETNODE_H #define NETNODE_H #include <qtextstream.h> #include <qlist.h> #include <qdict.h> #include <qpixmap.h> +#include <qstringlist.h> #include <qobject.h> #include <time.h> #include <Utils.h> // difference feature interfaces class AsDevice; class AsLine; @@ -27,208 +28,295 @@ class RuntimeInfo; class InterfaceInfo; extern QString & deQuote( QString & X ); extern QString quote( QString X ); #include "systemfile.h" typedef enum State { - // if we have not yet detected the state of the device - Unchecked = 0, - // if we cannot determine the state - Unknown = 1, - // if connection cannot be established e.g. because - // the hardware is not available - Unavailable = 2, - // if the connection cannot be establishec but NOT - // because it is physically impossible but because - // it has been disabled for FUNCTIONAL reasons - Disabled = 3, - // if connection is available to is currently down - // i.e. the corresponding hardware is not activated - Off = 4, - // if connection is available to be used (i.e. the - // devices if fully ready to be used - Available = 5, - // if connection is being used - IsUp = 6 + // if we have not yet detected the state of the device + Unchecked = 0, + // if we cannot determine the state + Unknown = 1, + // if connection cannot be established e.g. because + // the hardware is not available + Unavailable = 2, + // if the connection cannot be establishec but NOT + // because it is physically impossible but because + // it has been disabled for FUNCTIONAL reasons + Disabled = 3, + // if connection is available to is currently down + // i.e. the corresponding hardware is not activated + Off = 4, + // if connection is available to be used (i.e. the + // devices if fully ready to be used + Available = 5, + // if connection is being used + IsUp = 6 } State_t; typedef enum Action { - // to make the device unavailable functionally - Disable = 0, - // to make the device available functionally - Enable = 1, - // bring the hardware up - Activate = 2, - // bring the hardware down - Deactivate = 3, - // bring the connection up - Up = 4, - // bring the connection down - Down = 5 + // to make the device unavailable functionally + Disable = 0, + // to make the device available functionally + Enable = 1, + // bring the hardware up + Activate = 2, + // bring the hardware down + Deactivate = 3, + // bring the connection up + Up = 4, + // bring the connection down + Down = 5 } Action_t; class ANetNode : public QObject{ public: - typedef QArray<ANetNode *> NetNodeList; - - ANetNode( const char * Name ) : QObject( 0, Name ) {} - virtual ~ANetNode(){}; - - // pixmap needed for this NetNode - virtual const QString pixmapName() = 0; - - // description for this NetNode - virtual const QString nodeDescription() = 0; - - // create a blank instance of a net node - virtual ANetNodeInstance * createInstance( void ) = 0; - - // return feature this NetNode provides - virtual const char * provides( void ) = 0; - virtual const char ** needs( void ) = 0; - - // generate files specific for this node (if any) - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ) = 0; - // return TRUE if this node has data to be inserted in systemfile - // with name S - virtual bool hasDataFor( const QString & S ) = 0; - // generate data specific for the device for the system file S - // called only IF data was needed - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ) = 0; - - // does this Node provide a Connection - bool isToplevel( void ) - { return strcmp( provides(), "fullsetup") == 0 ; } - - // generate NIC name based on instance nr - // only relevant if node instances are devices - virtual QString genNic( long ) - { return QString(""); } - - // max number of instances for this node type - // only relevant if node instances are devices - virtual long instanceCount( void ) - { return 1; } - - // set the value of an attribute - void setAttribute( QString & Attr, QString & Value ) ; - void saveAttributes( QTextStream & TS ) ; - - // compiled references to 'needed' NetNodes -> needs list - void setAlternatives( NetNodeList * Alt ) - { Alternatives = Alt; } - NetNodeList & alternatives( void ) - { return *Alternatives; } + typedef QArray<ANetNode *> NetNodeList; + + ANetNode( const char * Name ) : QObject( 0, Name ) {} + virtual ~ANetNode(){}; + + // + // + // standard methods with sensible default + // + // + + inline int done( void ) + { return Done; } + inline void setDone( int D ) + { Done = D; } + + // does this Node provide a Connection + inline bool isToplevel( void ) + { return strcmp( provides(), "fullsetup") == 0 ; } + + // set the value of an attribute + void setAttribute( QString & Attr, QString & Value ) ; + void saveAttributes( QTextStream & TS ) ; + + // compiled references to 'needed' NetNodes -> needs list + inline void setAlternatives( NetNodeList * Alt ) + { Alternatives = Alt; } + inline NetNodeList & alternatives( void ) + { return *Alternatives; } + + // + // + // Virtual methods with sensible default + // + // + + // do instances of this noce class have data for this file + virtual bool hasDataForFile( const QString & ) + { return 0; } + + // generate instance independent stuff + // 0 : data output, 1 no data, 2 error + virtual short generateFile( const QString & , + const QString & , + QTextStream & , + long ) + { return 1; } + + // generate instance dependent but profile common stuff + // 0 : data output, 1 no data, 2 error + virtual short generateFile( const QString & , + const QString & , + QTextStream & , + ANetNodeInstance * , + long ) + { return 1; } + + + // generate NIC name based on instance nr + // only relevant if node instances are devices + virtual QString genNic( long ) + { return QString(""); } + + // max number of instances for this node type + // only relevant if node instances are devices + virtual long instanceCount( void ) + { return 1; } + + // return list of files that are specific for this node class + virtual QStringList * properFiles( void ) + { return 0; } + + // + // + // pure virtual methods with sensible default + // + // + + // pixmap needed for this NetNode + virtual const QString pixmapName() = 0; + + // description for this NetNode + virtual const QString nodeDescription() = 0; + + // create a blank instance of a net node + virtual ANetNodeInstance * createInstance( void ) = 0; + + // return feature this NetNode provides + virtual const char * provides( void ) = 0; + virtual const char ** needs( void ) = 0; protected : - NetNodeList * Alternatives; + NetNodeList * Alternatives; private : - virtual void setSpecificAttribute( QString & , QString & ) = 0; - virtual void saveSpecificAttribute( QTextStream & ) = 0; + virtual void setSpecificAttribute( QString & , QString & ) = 0; + virtual void saveSpecificAttribute( QTextStream & ) = 0; + int Done; }; class ANetNodeInstance : public QObject { public: - ANetNodeInstance( ANetNode * NN ) : QObject() - { IsModified=0; NodeType = NN; IsNew = TRUE; } - virtual ~ANetNodeInstance( void ) { } - - virtual RuntimeInfo * runtime( void ) = 0; - - void setConnection( NodeCollection * NC ) - { Connection = NC; } - NodeCollection * connection( void ) - { return Connection; } - - // create edit widget under parent - virtual QWidget * edit( QWidget * parent ) = 0; - // is given data acceptable - virtual QString acceptable( void ) = 0; - - // return data was modified - void setModified( bool M ) - { IsModified = M; } - bool isModified( void ) - { return IsModified; } - - // get data from GUI and store in node - virtual void commit( void ) = 0; - - // get next node - ANetNodeInstance * nextNode(); - // return NetNode this is an instance of - ANetNode * nodeClass( void ) - { return NodeType; } - - // intialize am instance of a net node - void initialize( void ); - - // set the value of an attribute - void setAttribute( QString & Attr, QString & Value ) ; - void saveAttributes( QTextStream & TS ) ; + ANetNodeInstance( ANetNode * NN ) : QObject() + { IsModified=0; NodeType = NN; IsNew = TRUE; } + virtual ~ANetNodeInstance( void ) { } + + inline int done( void ) + { return Done; } + inline void setDone( int D ) + { Done = D; } + + // return data was modified + inline void setModified( bool M ) + { IsModified = M; } + inline bool isModified( void ) + { return IsModified; } + + // get next node + ANetNodeInstance * nextNode(); + // return NetNode this is an instance of + ANetNode * nodeClass( void ) + { return NodeType; } + + // intialize am instance of a net node + void initialize( void ); + + // set the value of an attribute + void setAttribute( QString & Attr, QString & Value ) ; + void saveAttributes( QTextStream & TS ) ; + + // return true if node isntance is NEW and not loaded + inline void setNew( bool IsN ) + { IsNew = IsN; } + inline bool isNew( void ) + { return IsNew; } + + // return description for this instance + inline QString & description( void ) + { return Description; } + inline void setDescription( const QString & S ) + { Description = S; } + + // pixmap for this instance -> from NetNode + inline const QString pixmapName( void ) + { return NodeType->pixmapName(); } + + inline const char * provides( void ) + { return NodeType->provides(); } + + inline const char ** needs( void ) + { return NodeType->needs(); } + + inline void setConnection( NodeCollection * NC ) + { Connection = NC; } + inline NodeCollection * connection( void ) + { return Connection; } + + // + // + // Virtual methods with sensible defaults + // + // + + + + // open proper file identified by S + virtual QFile * openFile( const QString & ) + { return 0; } + + // check if this node (or sub nodes) have data for this file + virtual bool hasDataForFile( const QString & S ) + { return nodeClass()->hasDataForFile( S ); } + + // generate code specific for this node but embedded + // in the section of the parent + // this is called within the code of the parent + virtual short generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) + { ANetNodeInstance * NNI = nextNode(); + return (NNI) ? NNI->generateFileEmbedded( ID, Path, TS, DevNr ) : 1; + } - // return true if node isntance is NEW and not loaded - void setNew( bool IsN ) - { IsNew = IsN; } - bool isNew( void ) - { return IsNew; } + // generate code specific for this node + // (or find the first node that does) + virtual short generateFile( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) + { ANetNodeInstance * NNI = nextNode(); + return (NNI) ? NNI->generateFile( ID, Path, TS, DevNr ) : 1; + } - // return description for this instance - QString & description( void ) - { return Description; } - void setDescription( const QString & S ) - { Description = S; } + // return true if this node instance is triggered by this trigger + // could be delegated to deeper instances + virtual bool triggeredBy( const QString & ) + { return 0; } - // pixmap for this instance -> from NetNode - const QString pixmapName( void ) - { return NodeType->pixmapName(); } + // + // + // Pure virtual functions + // + // - const char * provides( void ) - { return NodeType->provides(); } + // return runtime information for this node + virtual RuntimeInfo * runtime( void ) = 0; - const char ** needs( void ) - { return NodeType->needs(); } + // create edit widget under parent + virtual QWidget * edit( QWidget * parent ) = 0; - // returns node specific data -> only useful for 'buddy' - virtual void * data( void ) = 0; + // is given data acceptable + virtual QString acceptable( void ) = 0; - // return TRUE if this node has data to be inserted in systemfile - // with name S - virtual bool hasDataFor( const QString & S ) = 0; + // get data from GUI and store in node + virtual void commit( void ) = 0; - // generate data specific for a profile and for the system file S - // called only IF data was needed - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ) = 0; + // 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; + virtual void setSpecificAttribute( QString & , QString & ) = 0; + virtual void saveSpecificAttribute( QTextStream & ) = 0; - ANetNode * NodeType; - // connection to which this node belongs to - NodeCollection * Connection; - QString Description; - bool IsModified; - bool IsNew; + ANetNode * NodeType; + // connection to which this node belongs to + NodeCollection * Connection; + QString Description; + bool IsModified; + bool IsNew; + int Done; - static long InstanceCounter; + static long InstanceCounter; }; class RuntimeInfo : public QObject { Q_OBJECT public : @@ -277,95 +365,116 @@ protected : class NodeCollection : public QList<ANetNodeInstance> { public : NodeCollection( void ); NodeCollection( QTextStream & TS ); ~NodeCollection( void ); - int number( void ) + inline int done( void ) + { return Done; } + inline void setDone( int D ) + { Done = D; } + + inline int number( void ) { return Number; } - void setNumber( int i ) + inline void setNumber( int i ) { Number = i; } - bool isNew( void ) + inline bool isNew( void ) { return IsNew; } - void setNew( bool N ) + inline void setNew( bool N ) { IsNew = N ; } - bool isModified( void ) + inline bool isModified( void ) { return IsModified; } - void setModified( bool N ) + inline void setModified( bool N ) { IsModified = N ; } - bool handlesInterface( const QString & S ) { + inline bool handlesInterface( const QString & S ) { return getToplevel()->runtime()->handlesInterface( S ); } - InterfaceInfo * assignedInterface( void ) { + inline InterfaceInfo * assignedInterface( void ) { return getToplevel()->runtime()->assignedInterface(); } - AsDevice * device() { + inline AsDevice * device() { return getToplevel()->runtime()->device(); } bool triggersVPN(); - State_t state( bool Update = 0 ) + inline State_t state( bool Update = 0 ) { Log(( "%s state %d(=%d?)\n", Name.latin1(), CurrentState, Unchecked )); if( CurrentState == Unchecked || Update ) { Log(( "TL %p TLR %p\n", getToplevel(), getToplevel()->runtime() )); // need to get current state getToplevel()->runtime()->detectState( this ); } return CurrentState; } // get the ixmap for this device QPixmap devicePixmap( void ); QPixmap statePixmap( State_t S ); - QPixmap statePixmap( bool Update = 0 ) + inline QPixmap statePixmap( bool Update = 0 ) { return statePixmap( state(Update) ); } QString stateName( State_t ); - QString stateName( bool Update = 0 ) + inline QString stateName( bool Update = 0 ) { return stateName( state(Update) ); } - bool setState( Action_t A, bool Force =0 ) + inline bool setState( Action_t A, bool Force =0 ) { return getToplevel()->runtime()->setState( this, A, Force ); } - bool canSetState( Action_t A ) + inline bool canSetState( Action_t A ) { return getToplevel()->runtime()->canSetState( CurrentState, A ); } void save( QTextStream & TS ); void append( ANetNodeInstance * NNI ); // makes sure that all items in the connection point to // that connectoin void reassign( void ); ANetNodeInstance * getToplevel( void ); ANetNodeInstance * findNext( ANetNodeInstance * NNI ); ANetNodeInstance * findByName( const QString & S ); - const QString & name() + inline const QString & name() { return Name; } const QString & description( void ); - void setName( const QString & N) + inline void setName( const QString & N) { Name = N; } - State_t currentState( void ) + inline State_t currentState( void ) { return CurrentState; } - void setCurrentState( State_t S ) + inline void setCurrentState( State_t S ) { CurrentState = S; } + // return TRUE if this node can have data to be inserted in + // file identified by S + bool hasDataForFile( const QString & S ); + ANetNodeInstance * firstWithDataForFile( const QString & S ); + + // generate items for this file -> toplevel call + short generateFile( const QString & FID, // identification of file + const QString & FName, // effective filename of file + QTextStream & TS, // stream to file + long DN // device number + ) + { return getToplevel()->generateFile( FID, FName, TS, DN ); } + + bool triggeredBy( const QString & Trigger ) + { return getToplevel()->triggeredBy( Trigger ); } + private : int compareItems ( QCollection::Item item1, QCollection::Item item2 ); long Number; // state of this connection @@ -373,12 +482,13 @@ private : QString Name; // true if this collection was just created (and not // loaded from file bool IsNew; // index in listbox int Index; bool IsModified; + int Done; }; #endif diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp index 71e84cd..7ece817 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.cpp +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -72,28 +72,37 @@ TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), NodeTypeDescriptionMap.insert( "line", tr( "<p>Devices that can handle single bytes</p>" ) ); NodeTypeDescriptionMap.insert( "connection", tr( "<p>Nodes that provide working IP connections</p>" ) ); NodeTypeDescriptionMap.insert( "fullsetup", tr( "<p>Fully configured connection profile</p>" ) ); // define system files - addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); + addSystemFile( "interfaces", "/tmp/interfaces", 1 ); // get access to the system TheSystem = new System(); } TheNSResources::~TheNSResources( void ) { delete TheSystem; } -void TheNSResources::busy( bool B ) { +void TheNSResources::addSystemFile( const QString & ID, + const QString & P, + bool KDI ) { + if( ! SystemFiles.find( ID ) ) { + // new system file + SystemFiles.insert( ID, new SystemFile( ID, P, KDI ) ); + } // else existed +} + +void TheNSResources::busy( bool ) { /* if( B ) { ShowWait->show(); qApp->process } else { ShowWait->hide(); } */ diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h index 55d2f29..16355ba 100644 --- a/noncore/settings/networksettings2/networksettings2/resources.h +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -61,18 +61,19 @@ public : { return AllNodeTypes.find(X)!=0; } ANetNode * findNetNode( const QString & N ) { NetNode_t * NNT = AllNodeTypes.find(N); return (NNT) ? NNT->NetNode : 0; } Name2SystemFile_t & systemFiles( void ) { return SystemFiles; } - void addSystemFile( SystemFile * SF ) - { SystemFiles.insert( SF->name(), SF ); } + void addSystemFile( const QString & ID, + const QString & P, + bool KDI ); ANetNodeInstance * createNodeInstance( const QString & S ) { ANetNodeInstance * NNI = 0; NetNode_t * NNT = AllNodeTypes[S]; if( ! NNT ) { return 0; } NNI = NNT->NetNode->createInstance(); diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp index a579396..271e73d 100644 --- a/noncore/settings/networksettings2/networksettings2/system.cpp +++ b/noncore/settings/networksettings2/networksettings2/system.cpp @@ -385,18 +385,21 @@ void System::execAsUser( QString & Cmd, char * argv[] ) { static FILE * logf = 0; void VLog( char * Format, ... ) { va_list l; va_start(l, Format ); if( logf == (FILE *)0 ) { - // logf = fopen( "/tmp/ns2log", "a" ); - logf = stderr; + if( getenv("NS2STDERR") ) { + logf = stderr; + } else { + logf = fopen( "/tmp/ns2log", "a" ); + } if( ! logf ) { fprintf( stderr, "Cannot open logfile /tmp/ns2log %d\n", errno ); logf = (FILE *)1; } else { fprintf( logf, "____ OPEN LOGFILE ____\n"); } } @@ -406,12 +409,21 @@ void VLog( char * Format, ... ) { } va_end( l ); } void LogClose( void ) { if( (long)logf > 1 ) { fprintf( logf, "____ CLOSE LOGFILE ____\n"); - fclose( logf ); + if( logf != stderr ) { + fclose( logf ); + } logf = 0; } } + +QString removeSpaces( const QString & X ) { + QStringList SL; + + SL = QStringList::split( " ", X ); + return SL.join( "_" ); +} diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.cpp b/noncore/settings/networksettings2/networksettings2/systemfile.cpp index b3fc1a5..2b40834 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.cpp +++ b/noncore/settings/networksettings2/networksettings2/systemfile.cpp @@ -6,17 +6,19 @@ #include <qtextstream.h> #include "resources.h" #include "systemfile.h" #define TEMPLATEDIR "networktemplates/" QString TemplDir; -SystemFile::SystemFile( const QString & N, const QString & P ){ +SystemFile::SystemFile( const QString & N, + const QString & P, + bool KDI ){ Name = N; Path = P; F = 0; // get template info { QString S; QFileInfo FI; // find location of templates @@ -52,16 +54,18 @@ SystemFile::SystemFile( const QString & N, const QString & P ){ 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() ); } + + KnowsDeviceInstances = KDI; } SystemFile::~SystemFile( void ) { if( F ) delete F; } bool SystemFile::open( void ) { @@ -91,95 +95,95 @@ bool SystemFile::close( void ) { 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 + return 0; // error // copy file to this file F->writeBlock( Fl.readAll() ); } - return 0; + return 1; } bool SystemFile::postSection( void ) { if( hasPostSection ) { QFile Fl( TemplDir + Name + "/postsection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error // copy file to this file F->writeBlock( Fl.readAll() ); } - return 0; + return 1; } bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) { if( hasPreNodeSection ) { QFile Fl( TemplDir + Name + "/prenodesection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); while( ! TX.eof() ) { Out = S. arg(NNI->nodeClass()->name()); (*this) << Out << endl; S = TX.readLine(); } } - return 0; + return 1; } bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long ) { if( hasPostNodeSection ) { QFile Fl( TemplDir + Name + "/postnodesection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); while( ! TX.eof() ) { Out = S. arg(NNI->name()); (*this) << Out << endl; S = TX.readLine(); } } - return 0; + return 1; } bool SystemFile::preDeviceSection( ANetNode * NN ) { if( hasPreDeviceSection ) { QFile Fl( TemplDir + Name + "/predevicesection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); while( ! TX.eof() ) { Out = S.arg(NN->name()); (*this) << Out << endl; S = TX.readLine(); } } - return 0; + return 1; } bool SystemFile::postDeviceSection( ANetNode * NN ) { if( hasPostDeviceSection ) { QFile Fl( TemplDir + Name + "/postdevicesection" ); if( ! Fl.open( IO_ReadOnly ) ) - return 1; // error + return 0; // error QTextStream TX( &Fl ); QString Out; QString S = TX.readLine(); while( ! TX.eof() ) { Out = S.arg(NN->name()); (*this) << Out << endl; S = TX.readLine(); } } - return 0; + return 1; } diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.h b/noncore/settings/networksettings2/networksettings2/systemfile.h index f57dab0..ceed605 100644 --- a/noncore/settings/networksettings2/networksettings2/systemfile.h +++ b/noncore/settings/networksettings2/networksettings2/systemfile.h @@ -6,21 +6,27 @@ class QFile; class ANetNodeInstance; class SystemFile : public QTextStream { public : - SystemFile( const QString & Name, const QString & Path ); + SystemFile( const QString & Name, + const QString & Path, + bool KnowsDevicesInstances ); ~SystemFile( void ); - const QString & name( void ) + const QString & name( void ) const { return Name; } + const QString & path( void ) const + { return Path; } + bool knowsDeviceInstances( void ) const + { return KnowsDeviceInstances; } bool open( void ); bool close( void ); bool preSection( void ); bool postSection( void ); bool preNodeSection( ANetNodeInstance * NNI, long DevNr ); bool postNodeSection( ANetNodeInstance * NNI, long DevNr ); @@ -33,11 +39,12 @@ private : QString Path; QFile * F; bool hasPreSection; bool hasPostSection; bool hasPreNodeSection; bool hasPostNodeSection; bool hasPreDeviceSection; bool hasPostDeviceSection; + bool KnowsDeviceInstances; }; #endif diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 3b17548..d709c0a 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp @@ -15,17 +15,16 @@ NetworkSettingsData::NetworkSettingsData( void ) { // init global resources structure new TheNSResources(); CfgFile.sprintf( "%s/Settings/NS2.conf", NSResources->currentUser().HomeDir.latin1() ); Log(( "Cfg from %s\n", CfgFile.latin1() )); // load settings - Force = 0; IsModified = 0; loadSettings(); } // saving is done by caller NetworkSettingsData::~NetworkSettingsData( void ) { delete NSResources; } @@ -213,176 +212,298 @@ QString NetworkSettingsData::saveSettings( void ) { // // proper files AND system files regenerated // setModified( 0 ); return ErrS; } -QString NetworkSettingsData::generateSettings( bool ForceReq ) { - bool ForceIt; +QString NetworkSettingsData::generateSettings( void ) { QString S = ""; - - // include own force flag - ForceIt = (Force) ? 1 : ForceReq; - - if( ! ForceIt && ! isModified() ) - return S; + Name2SystemFile_t & SFM = NSResources->systemFiles(); + Name2Connection_t & M = NSResources->connections(); + NodeCollection * NC; + ANetNodeInstance * NNI; + ANetNodeInstance * FirstWithData; + SystemFile * SF; + AsDevice * CurDev; + ANetNode * NN, * CurDevNN = 0; + long NoOfDevs; + long DevCtStart; + bool needToGenerate; // regenerate system files Log( ( "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; - ANetNode * CurDevNN; - 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->nodeClass()->hasDataFor( SF->name() ) || - NNI->hasDataFor( SF->name() ) - ) && - NNI->isModified() ) { - needToRegenerate = 1; - break; + // + // generate files proper to each netnodeinstance + // + { Name2Instance_t & NNIs = NSResources->netNodeInstances(); + + for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); + NNIIt.current(); + ++NNIIt ) { + // for all nodes find those that are modified + NNI = NNIIt.current(); + + { // get list of proper files for this nodeclass (if any) + QStringList * PF = NNI->nodeClass()->properFiles(); + + if( PF ) { + for ( QStringList::Iterator it = PF->begin(); + it != PF->end(); + ++it ) { + QFile * F = NNI->openFile( (*it) ); + if( F ) { + QTextStream TS( F ); + if( NNI->generateFile( (*it), F->name(), TS, -1 ) == 2 ) { + // problem generating + S = qApp->translate( "NetworkSettings", + "<p>Cannot generate files proper to \"%1\"</p>" ). + arg(NNI->nodeClass()->name()) ; + delete F; + return S; } + delete F; } } - if( needToRegenerate ) - break; } - if( needToRegenerate ) - break; } } + } - // - // generate files proper to each netnodeinstance - // - { Name2Instance_t & NNIs = NSResources->netNodeInstances(); - - 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->nodeClass()->generateProperFilesFor( NNI ) ) { - // problem generating - S = qApp->translate( "NetworkSettings", - "<p>Cannot generate files proper to \"%1\"</p>" ). - arg(NNI->nodeClass()->name()) ; - return S; + // + // generate all system files + // + for( QDictIterator<SystemFile> sfit(SFM); + sfit.current(); + ++sfit ) { + SF = sfit.current(); + + // reset all + for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); + nnit.current(); + ++nnit ) { + nnit.current()->NetNode->setDone(0); + } + + for( QDictIterator<ANetNodeInstance> nniit( + NSResources->netNodeInstances() ); + nniit.current(); + ++nniit ) { + nniit.current()->setDone(0); + } + + for( QDictIterator<NodeCollection> ncit(M); + ncit.current(); + ++ncit ) { + ncit.current()->setDone(0); + } + + Log( ( "Generating %s\n", SF->name().latin1() )); + + needToGenerate = 0; + + // are there netnodes that have instances and need + // to write data in this system file ? + for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); + ! needToGenerate && nnit.current(); + ++nnit ) { + + NN = nnit.current()->NetNode; + + if( NN->hasDataForFile( SF->name() ) ) { + // netnode can have data + + // are there instances of this node ? + for( QDictIterator<ANetNodeInstance> nniit( + NSResources->netNodeInstances() ); + ! needToGenerate && nniit.current(); + ++nniit ) { + if( nniit.current()->nodeClass() == NN ) { + // yes + Log(("Node %s has data\n", + nniit.current()->name() )); + needToGenerate = 1; + break; } } } } - // - // generate all system files - // - for( QDictIterator<SystemFile> sfit(SFM); - sfit.current(); - ++sfit ) { - SF = sfit.current(); + if( ! needToGenerate ) { + // no instances found that might need to write data + // in this systemfile + Log(("No nodes for systemfile %s\n", SF->name().latin1() )); + continue; + } - Log( ( "Generating %s\n", SF->name().latin1() )); - SF->open(); + // ok generate this system file + SF->open(); - do { // so we can break; + // global presection for this system file + if( ! SF->preSection() ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). + arg( SF->name() ); + return S; + } - // global presection for this system file - if( SF->preSection() ) { + // find connections that want to write to this file + for( QDictIterator<NodeCollection> ncit(M); + ncit.current(); + ++ncit ) { + + NC = ncit.current(); + + if( NC->done() ) { + // already done + continue; + } + + if( ! NC->hasDataForFile( SF->name() ) ) { + // no data + continue; + } + + Log(("Generating %s for connection %s\n", + SF->name().latin1(), NC->name().latin1() )); + // find highest item that wants to write data to this file + FirstWithData = NC->firstWithDataForFile( SF->name() ); + + // find device on which this connection works + CurDev = NC->device(); + // class of that node + CurDevNN = CurDev->netNode()->nodeClass(); + + Log(( "%s is done %d\n", + FirstWithData->nodeClass()->name(), + FirstWithData->nodeClass()->done() )); + + if( ! FirstWithData->nodeClass()->done() ) { + // generate fixed part + if( ! SF->preDeviceSection( CurDevNN ) ) { S = qApp->translate( "NetworkSettings", - "<p>Error in preSection for file \"%1\"</p>" ). + "<p>Error in section \"Pre-Device\" 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 ) { - - CurDevNN = nnit.current()->NetNode; - - // are there instances for this netnode ? - NNI = 0; - for( QDictIterator<ANetNodeInstance> nniit( - NSResources->netNodeInstances() ); - nniit.current(); - ++nniit ) { - if( nniit.current()->nodeClass() == CurDevNN ) { - NNI = nniit.current(); - break; - } + if( FirstWithData->nodeClass()->generateFile( + SF->name(), SF->path(), *SF, -1 ) == 2 ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; + } + FirstWithData->nodeClass()->setDone( 1 ); + } + + NoOfDevs = 0; + DevCtStart = -1; + + if( SF->knowsDeviceInstances() ) { + DevCtStart = 0; + NoOfDevs = CurDevNN->instanceCount(); + } + + Log(( "Node %s is done %d\n", + CurDev->netNode()->nodeClass()->name(), + CurDev->netNode()->nodeClass()->done() )); + + if( ! CurDev->netNode()->nodeClass()->done() ) { + // first time this device is handled + // generate common device specific part + for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { + + if( FirstWithData->nodeClass()->generateFile( + SF->name(), SF->path(), *SF, CurDev->netNode(), i ) == 2 ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; } + } + CurDev->netNode()->nodeClass()->setDone( 1 ); + } - if( ! NNI ) - // no instances -> next netnode type - continue; + // generate profile specific info + // for all nodeconnections that work on the same device + for( QDictIterator<NodeCollection> ncit2(M); + ncit2.current(); + ++ncit2 ) { - // 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 < CurDevNN->instanceCount(); i ++ ) { - S = generateSystemFileNode( *SF, CurDev, NNI, i ); - if( ! S.isEmpty() ) - return S; - } - } else { - S = generateSystemFileNode( *SF, 0, NNI, -1 ); - if( ! S.isEmpty() ) + if( ncit2.current()->device() != CurDev ) { + // different device + continue; + } + + Log(("Connection %s of same family\n", ncit2.current()->name().latin1() )); + // generate + NNI = ncit2.current()->firstWithDataForFile( SF->name() ); + for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { + if( ! SF->preNodeSection( NNI, i ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; + } + + switch( NNI->generateFile( + SF->name(), SF->path(), *SF, i ) ) { + case 0 : + (*SF) << endl; + break; + case 1 : + break; + case 2 : + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); return S; } - } - if( SF->postSection() ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in postSection for file \"%1\"</p>" ). - arg( SF->name() ); - return S; + if( ! SF->postNodeSection( NNI, i ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; + } } - } while( 0 ); - SF->close(); + ncit2.current()->setDone( 1 ); + + } + } + + if( ! SF->postDeviceSection( CurDevNN ) ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). + arg( SF->name() ). + arg( CurDevNN->name() ); + return S; + } + + + if( ! SF->postSection() ) { + S = qApp->translate( "NetworkSettings", + "<p>Error in section \"Closure\" for file \"%1\"</p>" ). + arg( SF->name() ); + return S; } + + // end of file + 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(); @@ -458,116 +579,15 @@ bool NetworkSettingsData::canStart( const char * Interface ) { return 0; } /* Called by the system to regenerate config files */ bool NetworkSettingsData::regenerate( void ) { - QString S; - // load situation - S = generateSettings( TRUE ); + QString S = generateSettings(); if( ! S.isEmpty() ) { fprintf( stdout, "%s\n", S.latin1() ); return 1; } return 0; } - -QString NetworkSettingsData::generateSystemFileNode( - SystemFile &SF, - AsDevice * CurDev, - ANetNodeInstance * DevNNI, - long DevInstNr ) { - - QString S=""; - ANetNode * CurDevNN = DevNNI->nodeClass(); - Name2Connection_t & M = NSResources->connections(); - - if( SF.preDeviceSection( CurDevNN ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Pre-Device Part\" for file \"%1\" and nodetype \"%2\"</p>" ). - arg( SF.name() ). - arg( CurDevNN->name() ); - return S; - } - - if( CurDevNN->hasDataFor( SF.name() ) ) { - if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Device Part\" for file \"%1\" and node \"%2\"</p>" ). - arg( SF.name() ). - arg( CurDevNN->name() ); - 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 ) { - NodeCollection * NC = ncit.current(); - - // currenly only those connections that work on - // the current device (or on no device if no current) - AsDevice * Dev = NC->device(); - - if( CurDev ) { - if( CurDevNN != Dev->netNode()->nodeClass() ) { - // other device type -> later - continue; - } - } else { - if( Dev ) { - // other - continue; - } - } - - // generate 'entry' - if( SF.preNodeSection( DevNNI, DevInstNr ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). - arg( SF.name() ). - arg( CurDevNN->name() ); - return S; - } - - // ask all nodes in connection - for( QListIterator<ANetNodeInstance> cncit(*NC); - cncit.current(); - ++cncit ) { - ANetNodeInstance * NNI = cncit.current(); - - if( NNI->hasDataFor( SF.name() ) ) { - if( NNI->generateDataForCommonFile(SF,DevInstNr) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Node Part\" for file \"%1\" and node \"%2\"</p>" ). - arg( SF.name() ). - arg( NNI->nodeClass()->name() ); - return S; - } - } - } - - if( SF.postNodeSection( DevNNI, DevInstNr ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). - arg( SF.name() ). - arg( CurDevNN->name() ); - return S; - } - SF << endl; - } - - if( SF.postDeviceSection( CurDevNN ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in \"Post-Device Part\" for file \"%1\" and node \"%2\"</p>" ). - arg( SF.name() ). - arg( CurDevNN->name() ); - return S; - } - - return S; -} diff --git a/noncore/settings/networksettings2/nsdata.h b/noncore/settings/networksettings2/nsdata.h index 57eb722..507185e 100644 --- a/noncore/settings/networksettings2/nsdata.h +++ b/noncore/settings/networksettings2/nsdata.h @@ -8,39 +8,30 @@ class NetworkSettingsData { public : NetworkSettingsData( void ); ~NetworkSettingsData( void ); void loadSettings( void ); QString saveSettings( void ); - QString generateSettings( bool Force = FALSE ); + QString generateSettings( void ); bool isModified( void ) { return IsModified; } void setModified( bool m ) { IsModified = m; } QList<NodeCollection> collectPossible( const char * Interface ); // return TRUE if we need gui to decide bool canStart( const char * Interface ); bool regenerate( void ); - void forceGeneration( bool m ) - { Force = m; } - private : - QString NetworkSettingsData::generateSystemFileNode( - SystemFile & SF, - AsDevice * CurDev, - ANetNodeInstance * DevNNI, - long DevInstNr ); bool IsModified; - bool Force; // collect strings in config file nobody wants QStringList LeftOvers; }; #endif diff --git a/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui b/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui index 826843a..0c5f4c8 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui +++ b/noncore/settings/networksettings2/ppp/PPPAuthGUI.ui @@ -6,17 +6,17 @@ <name>name</name> <cstring>PPPAuthGUI</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>249</width> + <width>245</width> <height>209</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>PPPAuth</string> </property> <property> @@ -52,21 +52,21 @@ <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <vbox> <property stdset="1"> <name>margin</name> - <number>0</number> + <number>3</number> </property> <property stdset="1"> <name>spacing</name> - <number>0</number> + <number>2</number> </property> <widget> <class>QRadioButton</class> <property stdset="1"> <name>name</name> <cstring>Login_RB</cstring> </property> <property stdset="1"> @@ -186,25 +186,64 @@ <cstring>PasswordSend_LE</cstring> </property> </widget> </grid> </widget> </hbox> </widget> <widget> - <class>QRadioButton</class> + <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> - <cstring>PapChap_RB</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Pap/Chap/EAP</string> + <cstring>Layout3</cstring> </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget> + <class>QRadioButton</class> + <property stdset="1"> + <name>name</name> + <cstring>Pap_RB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Pap</string> + </property> + </widget> + <widget> + <class>QRadioButton</class> + <property stdset="1"> + <name>name</name> + <cstring>Chap_RB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Chap</string> + </property> + </widget> + <widget> + <class>QRadioButton</class> + <property stdset="1"> + <name>name</name> + <cstring>EAP_RB</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>EAP</string> + </property> + </widget> + </hbox> </widget> <widget> <class>QLayoutWidget</class> <property stdset="1"> <name>name</name> <cstring>Layout5</cstring> </property> <hbox> @@ -270,137 +309,80 @@ </property> <grid> <property stdset="1"> <name>margin</name> <number>2</number> </property> <property stdset="1"> <name>spacing</name> - <number>1</number> + <number>2</number> </property> - <widget row="2" column="0" > + <widget row="1" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel1_2</cstring> </property> <property stdset="1"> <name>text</name> <string>Server</string> </property> </widget> - <widget row="3" column="0" > + <widget row="2" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>TextLabel1_3</cstring> </property> <property stdset="1"> <name>text</name> <string>Secret</string> </property> </widget> - <widget row="0" column="1" > - <class>QComboBox</class> - <item> - <property> - <name>text</name> - <string>PAP</string> - </property> - </item> - <item> - <property> - <name>text</name> - <string>CHAP</string> - </property> - </item> - <item> - <property> - <name>text</name> - <string>EAP</string> - </property> - </item> - <property stdset="1"> - <name>name</name> - <cstring>AuthMethod_CB</cstring> - </property> - </widget> - <widget row="1" column="0" > - <class>QLabel</class> + <widget row="1" column="1" > + <class>QLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel1</cstring> + <cstring>Server_LE</cstring> </property> <property stdset="1"> <name>text</name> - <string>Client</string> + <string>*</string> </property> </widget> - <widget row="0" column="0" > - <class>QLabel</class> + <widget row="2" column="1" > + <class>QLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>TextLabel1_4</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>Method</string> + <cstring>Secret_LE</cstring> </property> </widget> - <widget row="1" column="1" rowspan="1" colspan="2" > + <widget row="0" column="1" > <class>QLineEdit</class> <property stdset="1"> <name>name</name> <cstring>Client_LE</cstring> </property> <property stdset="1"> <name>text</name> <string>*</string> </property> </widget> - <widget row="2" column="1" rowspan="1" colspan="2" > - <class>QLineEdit</class> + <widget row="0" column="0" > + <class>QLabel</class> <property stdset="1"> <name>name</name> - <cstring>Server_LE</cstring> + <cstring>TextLabel1</cstring> </property> <property stdset="1"> <name>text</name> - <string>*</string> - </property> - </widget> - <widget row="3" column="1" rowspan="1" colspan="2" > - <class>QLineEdit</class> - <property stdset="1"> - <name>name</name> - <cstring>Secret_LE</cstring> + <string>Client</string> </property> </widget> - <spacer row="0" column="2" > - <property> - <name>name</name> - <cstring>Spacer7</cstring> - </property> - <property stdset="1"> - <name>orientation</name> - <enum>Horizontal</enum> - </property> - <property stdset="1"> - <name>sizeType</name> - <enum>Expanding</enum> - </property> - <property> - <name>sizeHint</name> - <size> - <width>20</width> - <height>20</height> - </size> - </property> - </spacer> </grid> </widget> </hbox> </widget> <widget> <class>QRadioButton</class> <property stdset="1"> <name>name</name> @@ -412,21 +394,33 @@ </property> </widget> </vbox> </widget> </vbox> </widget> <connections> <connection> - <sender>PapChap_RB</sender> + <sender>Pap_RB</sender> <signal>toggled(bool)</signal> <receiver>GroupBox3</receiver> <slot>setEnabled(bool)</slot> </connection> <connection> <sender>Login_RB</sender> <signal>toggled(bool)</signal> <receiver>GroupBox1</receiver> <slot>setEnabled(bool)</slot> </connection> + <connection> + <sender>Chap_RB</sender> + <signal>toggled(bool)</signal> + <receiver>GroupBox3</receiver> + <slot>setEnabled(bool)</slot> + </connection> + <connection> + <sender>EAP_RB</sender> + <signal>toggled(bool)</signal> + <receiver>GroupBox3</receiver> + <slot>setEnabled(bool)</slot> + </connection> </connections> </UI> diff --git a/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp b/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp index f305cc4..450d560 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp +++ b/noncore/settings/networksettings2/ppp/PPPAuthedit.cpp @@ -4,82 +4,102 @@ #include <qradiobutton.h> #include <qlineedit.h> #include <GUIUtils.h> #include "PPPAuthedit.h" PPPAuthEdit::PPPAuthEdit( QWidget * Parent ) : PPPAuthGUI( Parent ){ } +bool PPPAuthEdit::PAP_Checked( void ) { + return ( Pap_RB->isChecked() || + Chap_RB->isChecked() || + EAP_RB->isChecked() + ); +} + QString PPPAuthEdit::acceptable( void ) { if( Login_RB->isChecked() ) { if( LoginSend_LE->text().isEmpty() ) return tr("Login send missing"); if( LoginExpect_LE->text().isEmpty() ) return tr("Login expect missing"); if( PasswordSend_LE->text().isEmpty() ) return tr("Password send missing"); if( PasswordExpect_LE->text().isEmpty() ) return tr("Password expect missing"); - } else if( PapChap_RB->isChecked() ) { + } else if( PAP_Checked() ) { if( Client_LE->text().isEmpty() ) return tr("Pap/Chap/EAP client id missing"); if( Server_LE->text().isEmpty() ) return tr("Pap/Chap/EAP server id missing"); if( Secret_LE->text().isEmpty() ) return tr("Pap/Chap/EAP secret id missing"); } return QString(); } bool PPPAuthEdit::commit( PPPData_t & D ) { bool SM = 0; if( ( D.Auth.Mode == 0 && ! Login_RB->isChecked() ) || - ( D.Auth.Mode == 1 && ! PapChap_RB->isChecked() ) || + ( D.Auth.Mode == 1 && ! PAP_Checked() ) || ( D.Auth.Mode == 2 && ! Terminal_RB->isChecked() ) ) { // mode modifed SM = 1; D.Auth.Mode = ( Login_RB->isChecked() ) ? 0 : - ( ( PapChap_RB->isChecked() ) ? - 1 : 2 ); + ( PAP_Checked() ) ? 1 : 2; } if( Login_RB->isChecked() ) { TXTM( D.Auth.Login.Expect, LoginExpect_LE, SM ); TXTM( D.Auth.Login.Send, LoginSend_LE, SM ); TXTM( D.Auth.Password.Expect, PasswordExpect_LE, SM ); TXTM( D.Auth.Password.Send, PasswordSend_LE, SM ); - } else if( PapChap_RB->isChecked() ) { + } else if( PAP_Checked() ) { TXTM( D.Auth.Client, Client_LE, SM ); TXTM( D.Auth.Server, Server_LE, SM ); TXTM( D.Auth.Secret, Secret_LE, SM ); - CIM( D.Auth.PCEMode, AuthMethod_CB, SM ); + if( Pap_RB->isChecked() ) { + D.Auth.PCEMode = 0; + } else if( Chap_RB->isChecked() ) { + D.Auth.PCEMode = 1; + } else if( EAP_RB->isChecked() ) { + D.Auth.PCEMode = 2; + } } return SM; } void PPPAuthEdit::showData( PPPData_t & D ) { switch( D.Auth.Mode ) { case 0 : - Login_RB->isChecked(); + Login_RB->setChecked( TRUE ); break; case 1 : - PapChap_RB->isChecked(); + switch( D.Auth.PCEMode ) { + case 0 : + Pap_RB->setChecked( TRUE ); + break; + case 1 : + Chap_RB->setChecked( TRUE ); + break; + case 2 : + EAP_RB->setChecked( TRUE ); + break; + } break; case 2 : - Terminal_RB->isChecked(); + Terminal_RB->setChecked( TRUE ); break; } LoginExpect_LE->setText( D.Auth.Login.Expect ); PasswordExpect_LE->setText( D.Auth.Password.Expect ); LoginSend_LE->setText( D.Auth.Login.Send ); PasswordSend_LE->setText( D.Auth.Password.Send ); Client_LE->setText( D.Auth.Client ); Server_LE->setText( D.Auth.Server ); Secret_LE->setText( D.Auth.Secret ); - - AuthMethod_CB->setCurrentItem( D.Auth.PCEMode ); } diff --git a/noncore/settings/networksettings2/ppp/PPPAuthedit.h b/noncore/settings/networksettings2/ppp/PPPAuthedit.h index cbd540e..2392569 100644 --- a/noncore/settings/networksettings2/ppp/PPPAuthedit.h +++ b/noncore/settings/networksettings2/ppp/PPPAuthedit.h @@ -4,12 +4,14 @@ class PPPAuthEdit : public PPPAuthGUI { public : PPPAuthEdit( QWidget * parent ); QString acceptable( void ); bool commit( PPPData_t & Data ); void showData( PPPData_t & Data ); + bool PAP_Checked( void ); + private : }; diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.cpp b/noncore/settings/networksettings2/ppp/ppp_NN.cpp index b7edf87..ff4465c 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NN.cpp @@ -1,21 +1,36 @@ +#include <qfile.h> +#include <qtextstream.h> #include "ppp_NN.h" #include "ppp_NNI.h" +QStringList * PPPNetNode::ProperFiles = 0; + static const char * PPPNeeds[] = { "line", "modem", 0 }; /** * Constructor, find all of the possible interfaces */ PPPNetNode::PPPNetNode() : ANetNode(tr("PPP Connection")) { + + // proper files : will leak + ProperFiles =new QStringList; + *ProperFiles << "peers"; + *ProperFiles << "chatscript"; + + // system files + NSResources->addSystemFile( + "pap-secrets", "/tmp/pap-secrets", 0 ); + NSResources->addSystemFile( + "chap-secrets", "/tmp/chap-secrets", 0 ); } /** * Delete any interfaces that we own. */ PPPNetNode::~PPPNetNode(){ } @@ -34,25 +49,27 @@ ANetNodeInstance * PPPNetNode::createInstance( void ) { const char ** PPPNetNode::needs( void ) { return PPPNeeds; } const char * PPPNetNode::provides( void ) { return "connection"; } -bool PPPNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; +QStringList * PPPNetNode::properFiles( void ) { + return ProperFiles; + } -bool PPPNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; +// need to generate : +// /etc/ppp/pap-secrets +// /etc/ppp/pap-secrets +bool PPPNetNode::hasDataForFile( const QString & S ) { + return S == "pap-secrets" || + S == "chap-secrets" ; } QString PPPNetNode::genNic( long NicNr ) { QString S; return S.sprintf( "ppp%ld", NicNr ); } void PPPNetNode::setSpecificAttribute( QString & , QString & ) { diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.h b/noncore/settings/networksettings2/ppp/ppp_NN.h index b1483c4..249be5a 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NN.h +++ b/noncore/settings/networksettings2/ppp/ppp_NN.h @@ -2,45 +2,42 @@ #define PPP_NETNODE_H #include "netnode.h" class APPP; class PPPNetNode : public ANetNode{ - Q_OBJECT + Q_OBJECT public: - PPPNetNode(); - virtual ~PPPNetNode(); + PPPNetNode(); + virtual ~PPPNetNode(); - virtual const QString pixmapName() - { return "Devices/ppp"; } + virtual const QString pixmapName() + { return "Devices/ppp"; } - virtual const QString nodeDescription() ; + virtual bool hasDataForFile( const QString & S ); - virtual ANetNodeInstance * createInstance( void ); + virtual const QString nodeDescription() ; + virtual ANetNodeInstance * createInstance( void ); + virtual const char ** needs( void ); + virtual const char * provides( void ); - virtual const char ** needs( void ); - virtual const char * provides( void ); - - virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - - virtual QString genNic( long NicNr ); + virtual QString genNic( long NicNr ); + virtual QStringList * properFiles( void ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); + + static QStringList * ProperFiles; }; extern "C" { void create_plugin( QList<ANetNode> & PNN ); }; #endif diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp index d0fd31c..ba639de 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.cpp +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.cpp @@ -1,8 +1,10 @@ +#include <qfile.h> +#include <qfileinfo.h> #include "PPPedit.h" #include "ppp_NNI.h" #include "ppp_NN.h" APPP::APPP( PPPNetNode * PNN ) : ANetNodeInstance( PNN ) { Data.DNS.ServerAssigned = 1; Data.DNS.DomainName = ""; @@ -108,14 +110,112 @@ QString APPP::acceptable( void ) { } void APPP::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } -bool APPP::generateDataForCommonFile( - SystemFile & , - long) { - return 1; +QFile * APPP::openFile( const QString & ID ) { + QFile * F = 0; + QString S; + + if( ID == "peers" ) { + S = removeSpaces( QString("/tmp/") + connection()->name() ); + + F = new QFile( S ); + + if( ! F->open( IO_WriteOnly ) ) { + Log(("Cannot open file %s\n", S.latin1() )); + return 0; + } + } else if ( ID == "chatscripts" ) { + S = removeSpaces( QString("/tmp/") + connection()->name() + ".chat" ); + F = new QFile( S ); + + if( ! F->open( IO_WriteOnly ) ) { + Log(("Cannot open file %s\n", S.latin1() )); + return 0; + } + } + if( F ) { + Log(("Generate proper file %s = %s\n", + ID.latin1(), F->name().latin1())); + } + return F; } +short APPP::generateFile( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { + short rvl, rvd; + + rvl = 1; + rvd = 1; + + if( ID == "pap-secrets" ) { + Log(("Generate PPP for %s\n", ID.latin1() )); + if( Data.Auth.Mode == 1 && Data.Auth.PCEMode == 0 ) { + TS << "# secrets for " + << connection()->name().latin1() + << endl; + TS << Data.Auth.Client + << " " + << Data.Auth.Server + << " " + << Data.Auth.Secret + << endl; + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } + } else if( ID == "chap-secrets" ) { + Log(("Generate PPP for %s\n", ID.latin1() )); + if( Data.Auth.Mode == 1 && Data.Auth.PCEMode != 0 ) { + // used for both EAP and Chap + TS << "# secrets for " + << connection()->name().latin1() + << endl; + TS << Data.Auth.Client + << " " + << Data.Auth.Server + << " " + << Data.Auth.Secret + << endl; + + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } + } else if ( ID == "peers" ) { + QFileInfo FI(Path); + Log(("Generate PPP for %s\n", ID.latin1() )); + + TS << "connect \"/usr/sbin/chat -v -f /etc/ppp/" + << FI.baseName() + << ".chat\"" + << endl; + + if( Data.IP.GWIsDefault ) { + TS << "defaultroute" + << endl; + } + + TS << "linkname " + << removeSpaces( ID.latin1() ) + << endl; + + // insert other data here + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } else if ( ID == "chatscripts" ) { + Log(("Generate PPP for %s\n", ID.latin1() )); + rvl = 0; + rvd = connection()->getToplevel()->generateFileEmbedded( + ID, Path, TS, DevNr ); + } + + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; +} diff --git a/noncore/settings/networksettings2/ppp/ppp_NNI.h b/noncore/settings/networksettings2/ppp/ppp_NNI.h index 989c2f0..0bf8fa9 100644 --- a/noncore/settings/networksettings2/ppp/ppp_NNI.h +++ b/noncore/settings/networksettings2/ppp/ppp_NNI.h @@ -2,41 +2,44 @@ #define PPP_H #include <netnode.h> #include "pppdata.h" #include "ppprun.h" class PPPNetNode; class PPPEdit; +class QTextStream; class APPP : public ANetNodeInstance { public : APPP( PPPNetNode * PNN ); - QWidget * edit( QWidget * parent ); - QString acceptable( void ); - void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) + { if( RT == 0 ) { RT = new PPPRun( this, Data ); + } return RT->runtimeInfo(); } + QWidget * edit( QWidget * parent ); + QString acceptable( void ); + void commit( void ); + virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } + virtual QFile * openFile( const QString & ID ); + short generateFile( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : PPPEdit * GUI; diff --git a/noncore/settings/networksettings2/profile/profile_NN.cpp b/noncore/settings/networksettings2/profile/profile_NN.cpp index 59c34a3..945b48d 100644 --- a/noncore/settings/networksettings2/profile/profile_NN.cpp +++ b/noncore/settings/networksettings2/profile/profile_NN.cpp @@ -4,17 +4,17 @@ static const char * ProfileNeeds[] = { "connection", 0 }; /** * Constructor, find all of the possible interfaces */ -ProfileNetNode::ProfileNetNode() : ANetNode( tr("Regular profile")) { +ProfileNetNode::ProfileNetNode() : ANetNode( tr("Regular connection profile")) { } /** * Delete any interfaces that we own. */ ProfileNetNode::~ProfileNetNode(){ } @@ -33,27 +33,16 @@ ANetNodeInstance * ProfileNetNode::createInstance( void ) { const char ** ProfileNetNode::needs( void ) { return ProfileNeeds; } const char * ProfileNetNode::provides( void ) { return "fullsetup"; } -bool ProfileNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool ProfileNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void ProfileNetNode::setSpecificAttribute( QString & , QString & ) { } void ProfileNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { diff --git a/noncore/settings/networksettings2/profile/profile_NN.h b/noncore/settings/networksettings2/profile/profile_NN.h index e602bd7..1f1ee2c 100644 --- a/noncore/settings/networksettings2/profile/profile_NN.h +++ b/noncore/settings/networksettings2/profile/profile_NN.h @@ -13,28 +13,20 @@ public: ProfileNetNode(); virtual ~ProfileNetNode(); virtual const QString pixmapName() { return "Devices/commprofile"; } 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 & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr); - private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { diff --git a/noncore/settings/networksettings2/profile/profile_NNI.cpp b/noncore/settings/networksettings2/profile/profile_NNI.cpp index cb52b2a..f0f0b97 100644 --- a/noncore/settings/networksettings2/profile/profile_NNI.cpp +++ b/noncore/settings/networksettings2/profile/profile_NNI.cpp @@ -45,14 +45,33 @@ QString AProfile::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AProfile::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } -bool AProfile::generateDataForCommonFile( - SystemFile & , - long) { - return 1; +short AProfile::generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { + + short rvl, rvd; + + rvl = 1; + + if( ID == "interfaces" ) { + Log(("Generate Profile for %s\n", ID.latin1() )); + if( Data.TriggerVPN ) { + // this profile triggers VPN -> insert trigger + TS << " up networksettings2 --triggervpn" + << endl; + rvl = 0; + } + } + rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr ); + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; } + + diff --git a/noncore/settings/networksettings2/profile/profile_NNI.h b/noncore/settings/networksettings2/profile/profile_NNI.h index 2c2db7f..957f4af 100644 --- a/noncore/settings/networksettings2/profile/profile_NNI.h +++ b/noncore/settings/networksettings2/profile/profile_NNI.h @@ -9,36 +9,35 @@ class ProfileNetNode; class ProfileEdit; class AProfile : public ANetNodeInstance { public : AProfile( ProfileNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new ProfileRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - const QString & description( void ) - { return Data.Description; } - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new ProfileRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } + virtual short generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr); + const QString & description( void ) + { return Data.Description; } protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : diff --git a/noncore/settings/networksettings2/usb/usb_NN.cpp b/noncore/settings/networksettings2/usb/usb_NN.cpp index c10a09c..14c479a 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.cpp +++ b/noncore/settings/networksettings2/usb/usb_NN.cpp @@ -32,39 +32,16 @@ ANetNodeInstance * USBNetNode::createInstance( void ) { const char ** USBNetNode::needs( void ) { return USBNeeds; } const char * USBNetNode::provides( void ) { return "device"; } -bool USBNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool USBNetNode::hasDataFor( const QString & S ) { - return (S== "interfaces"); -} - -bool USBNetNode::generateDeviceDataForCommonFile( - SystemFile & S , - long DevNr ) { - QString NIC = 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; -} - QString USBNetNode::genNic( long ) { return QString( "usbf" ); } void USBNetNode::setSpecificAttribute( QString & , QString & ) { } void USBNetNode::saveSpecificAttribute( QTextStream & ) { diff --git a/noncore/settings/networksettings2/usb/usb_NN.h b/noncore/settings/networksettings2/usb/usb_NN.h index fea89f0..73da15a 100644 --- a/noncore/settings/networksettings2/usb/usb_NN.h +++ b/noncore/settings/networksettings2/usb/usb_NN.h @@ -13,27 +13,20 @@ public: USBNetNode(); virtual ~USBNetNode(); virtual const QString pixmapName() { return "Devices/usb"; } 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 generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - virtual QString genNic( long nr ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; diff --git a/noncore/settings/networksettings2/usb/usb_NNI.cpp b/noncore/settings/networksettings2/usb/usb_NNI.cpp index e90204c..50c6e8d 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.cpp +++ b/noncore/settings/networksettings2/usb/usb_NNI.cpp @@ -27,26 +27,35 @@ QString AUSB::acceptable( void ) { } void AUSB::commit( void ) { if( GUI && GUI->commit( Data ) ) { setModified( 1 ); } } -bool AUSB::hasDataFor( const QString & S ) { - return (S== "interfaces"); -} - -bool AUSB::generateDataForCommonFile( SystemFile & S, long DevNr ) { +short AUSB::generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { + QString NIC = runtime()->device()->netNode()->nodeClass()->genNic( DevNr ); + short rvl, rvd; + + rvl = 1; - if( S.name() == "interfaces" ) { + if( ID == "interfaces" ) { + Log(("Generate USB for %s\n", ID.latin1() )); // generate mapping stanza for this interface - S << " pre-up " - << QPEApplication::qpeDir() - << "bin/setmacaddress.sh " - << NIC - << " || true" - << endl; + TS << " pre-up " + << QPEApplication::qpeDir() + << "bin/setmacaddress.sh " + << NIC + << " || true" + << endl; + rvl = 0; } - return 0; + rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr ); + + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; + } diff --git a/noncore/settings/networksettings2/usb/usb_NNI.h b/noncore/settings/networksettings2/usb/usb_NNI.h index d2ee217..fcdfd91 100644 --- a/noncore/settings/networksettings2/usb/usb_NNI.h +++ b/noncore/settings/networksettings2/usb/usb_NNI.h @@ -9,32 +9,32 @@ class USBNetNode; class USBEdit; class AUSB : public ANetNodeInstance { public : AUSB( USBNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new USBRun( this, Data ) ); + } + 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; } - virtual bool hasDataFor( const QString & S); - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); + virtual short generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : diff --git a/noncore/settings/networksettings2/vpn/vpn_NN.cpp b/noncore/settings/networksettings2/vpn/vpn_NN.cpp index 6c7b308..9d3b6e7 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NN.cpp +++ b/noncore/settings/networksettings2/vpn/vpn_NN.cpp @@ -1,14 +1,13 @@ #include "vpn_NN.h" #include "vpn_NNI.h" static const char * VPNNeeds[] = - { "connection", - 0 + { 0 }; /** * Constructor, find all of the possible interfaces */ VPNNetNode::VPNNetNode() : ANetNode(tr("VPN Connection")) { } @@ -33,27 +32,16 @@ ANetNodeInstance * VPNNetNode::createInstance( void ) { const char ** VPNNetNode::needs( void ) { return VPNNeeds; } const char * VPNNetNode::provides( void ) { return "connection"; } -bool VPNNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool VPNNetNode::generateDeviceDataForCommonFile( - SystemFile & , - long ) { - return 0; -} - void VPNNetNode::setSpecificAttribute( QString & , QString & ) { } void VPNNetNode::saveSpecificAttribute( QTextStream & ) { } extern "C" { void create_plugin( QList<ANetNode> & PNN ) { diff --git a/noncore/settings/networksettings2/vpn/vpn_NN.h b/noncore/settings/networksettings2/vpn/vpn_NN.h index 5b6632e..3c7b5e0 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NN.h +++ b/noncore/settings/networksettings2/vpn/vpn_NN.h @@ -13,28 +13,20 @@ public: VPNNetNode(); virtual ~VPNNetNode(); virtual const QString pixmapName() { return "Devices/vpn"; } 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 & ) - { return 0; } - virtual bool generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); }; extern "C" { diff --git a/noncore/settings/networksettings2/vpn/vpn_NNI.cpp b/noncore/settings/networksettings2/vpn/vpn_NNI.cpp index ee999e8..6c20aeb 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NNI.cpp +++ b/noncore/settings/networksettings2/vpn/vpn_NNI.cpp @@ -23,14 +23,8 @@ QString AVPN::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AVPN::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } -bool AVPN::generateDataForCommonFile( - SystemFile & , - long) { - return 1; -} - diff --git a/noncore/settings/networksettings2/vpn/vpn_NNI.h b/noncore/settings/networksettings2/vpn/vpn_NNI.h index c3eb016..aee5891 100644 --- a/noncore/settings/networksettings2/vpn/vpn_NNI.h +++ b/noncore/settings/networksettings2/vpn/vpn_NNI.h @@ -9,33 +9,29 @@ class VPNNetNode; class VPNEdit; class AVPN : public ANetNodeInstance { public : AVPN( VPNNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new VPNRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new VPNRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 0; } - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); + protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : VPNEdit * GUI; diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.cpp b/noncore/settings/networksettings2/wlan/wlan_NN.cpp index ce8a734..e4c3f60 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NN.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NN.cpp @@ -33,39 +33,16 @@ ANetNodeInstance * WLanNetNode::createInstance( void ) { const char ** WLanNetNode::needs( void ) { return WLanNeeds; } const char * WLanNetNode::provides( void ) { return "device"; } -bool WLanNetNode::generateProperFilesFor( - ANetNodeInstance * ) { - return 0; -} - -bool WLanNetNode::hasDataFor( const QString & S ) { - return S == "interfaces"; -} - -bool WLanNetNode::generateDeviceDataForCommonFile( - SystemFile & S, - long DevNr ) { - QString NIC = 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; -} - QString WLanNetNode::genNic( long nr ) { QString S; return S.sprintf( "wlan%ld", nr ); } void WLanNetNode::setSpecificAttribute( QString & A, QString & V ) { if( A == "interfacecount" ) { InstanceCount = V.toLong(); diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.h b/noncore/settings/networksettings2/wlan/wlan_NN.h index b5ff3fd..c13c05c 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NN.h +++ b/noncore/settings/networksettings2/wlan/wlan_NN.h @@ -13,31 +13,22 @@ public: WLanNetNode(); virtual ~WLanNetNode(); virtual const QString pixmapName() { return "Devices/wlan"; } 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 generateDeviceDataForCommonFile( - SystemFile & SF, long DevNr ); - virtual long instanceCount( void ) { return InstanceCount; } - virtual QString genNic( long ); private: virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); // number of interfaces for this device diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp index 61969f2..0e4fc4c 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp @@ -74,67 +74,78 @@ QString AWLan::acceptable( void ) { return ( GUI ) ? GUI->acceptable( ) : QString(); } void AWLan::commit( void ) { if( GUI && GUI->commit( Data ) ) setModified( 1 ); } -bool AWLan::generateDataForCommonFile( - SystemFile & S, - long ) { +short AWLan::generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ) { - S << " wireless_essid \"" - << Data.ESSID - << "\"" - << endl; + short rvl, rvd; - if( ! Data.NodeName.isEmpty() ) { - if( Data.NodeName == tr("<UseHostName>") ) { - char Buf[100]; - if( gethostname(Buf, sizeof(Buf) ) == 0 ) { - Buf[99] = '\0'; // just to make sure - S << " wireless_nick " - << Buf - << endl; + rvl = 1; + + if( ID == "interfaces" ) { + Log(("Generate WLanNNI for %s\n", ID.latin1() )); + TS << " wireless_essid \"" + << Data.ESSID + << "\"" + << endl; + + if( ! Data.NodeName.isEmpty() ) { + if( Data.NodeName == tr("<UseHostName>") ) { + char Buf[100]; + if( gethostname(Buf, sizeof(Buf) ) == 0 ) { + Buf[99] = '\0'; // just to make sure + TS << " wireless_nick " + << Buf + << endl; + } + } else { + TS << " wireless_nick \"" + << Data.NodeName + << "\"" + << endl; } - } else { - S << " wireless_nick \"" - << Data.NodeName - << "\"" - << endl; } - } - char * M; - switch ( Data.Mode ) { - case 0 : - M = "Auto"; - break; - case 1 : - M = "Managed"; - break; - case 2 : - M = "Ad-Hoc"; - break; - } + char * M = "Auto"; + switch ( Data.Mode ) { + case 0 : + break; + case 1 : + M = "Managed"; + break; + case 2 : + M = "Ad-Hoc"; + break; + } - S << " wireless_mode " - << M - << endl; - if( Data.Encrypted ) { - for( int i = 0; i < 4; i ++ ) { - if( ! Data.Key[i].isEmpty() ) { - S << " wireless_key" - << i - << " " - << Data.Key[i] - << endl; + TS << " wireless_mode " + << M + << endl; + if( Data.Encrypted ) { + for( int i = 0; i < 4; i ++ ) { + if( ! Data.Key[i].isEmpty() ) { + TS << " wireless_key" + << i + << " " + << Data.Key[i] + << endl; + } } + TS << " wireless_keymode " + << ((Data.AcceptNonEncrypted) ? "open" : "restricted") + << endl; } - S << " wireless_keymode " - << ((Data.AcceptNonEncrypted) ? "open" : "restricted") - << endl; + rvl = 0; } - return 0; + rvd = ANetNodeInstance::generateFileEmbedded( ID, Path, TS, DevNr); + + return (rvd == 2 || rvl == 2 ) ? 2 : + (rvd == 0 || rvl == 0 ) ? 0 : 1; } diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.h b/noncore/settings/networksettings2/wlan/wlan_NNI.h index 2211c47..a9be65f 100644 --- a/noncore/settings/networksettings2/wlan/wlan_NNI.h +++ b/noncore/settings/networksettings2/wlan/wlan_NNI.h @@ -9,33 +9,33 @@ class WLanNetNode; class WLanEdit; class AWLan : public ANetNodeInstance { public : AWLan( WLanNetNode * PNN ); + RuntimeInfo * runtime( void ) + { return + ( RT ) ? RT : ( RT = new WLanRun( this, Data ) ); + } + QWidget * edit( QWidget * parent ); QString acceptable( void ); void commit( void ); - RuntimeInfo * runtime( void ) - { if( RT == 0 ) - RT = new WLanRun( this, Data ); - return RT; - } - virtual void * data( void ) { return (void *)&Data; } - virtual bool hasDataFor( const QString & ) - { return 1; } - virtual bool generateDataForCommonFile( - SystemFile & SF, long DevNr ); + virtual short generateFileEmbedded( const QString & ID, + const QString & Path, + QTextStream & TS, + long DevNr ); + protected : virtual void setSpecificAttribute( QString & Attr, QString & Value ); virtual void saveSpecificAttribute( QTextStream & TS ); private : WLanEdit * GUI; |