summaryrefslogtreecommitdiff
authorwimpie <wimpie>2004-08-12 12:46:55 (UTC)
committer wimpie <wimpie>2004-08-12 12:46:55 (UTC)
commit8f215ba9ceb395f262517855a99d7d2d303ca760 (patch) (side-by-side diff)
treeaa5f9b14c249217b4d3fc30f4771bdaf1c3545d3
parentef64880308b5035cc8ca2e4e79325db613af525b (diff)
downloadopie-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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.cpp8
-rw-r--r--noncore/settings/networksettings2/bluetooth/bluetoothBNEP_NNI.h14
-rw-r--r--noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.cpp8
-rw-r--r--noncore/settings/networksettings2/bluetooth/bluetoothRFCOMM_NNI.h14
-rw-r--r--noncore/settings/networksettings2/bluetooth/bluetoothRFCOMMrun.h3
-rw-r--r--noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp38
-rw-r--r--noncore/settings/networksettings2/bluetooth/bluetooth_NN.h57
-rw-r--r--noncore/settings/networksettings2/cable/cable_NN.cpp11
-rw-r--r--noncore/settings/networksettings2/cable/cable_NN.h26
-rw-r--r--noncore/settings/networksettings2/cable/cable_NNI.cpp30
-rw-r--r--noncore/settings/networksettings2/cable/cable_NNI.h20
-rw-r--r--noncore/settings/networksettings2/cable/cablerun.cpp6
-rw-r--r--noncore/settings/networksettings2/cable/cablerun.h8
-rw-r--r--noncore/settings/networksettings2/irda/irda_NN.cpp11
-rw-r--r--noncore/settings/networksettings2/irda/irda_NN.h26
-rw-r--r--noncore/settings/networksettings2/irda/irda_NNI.cpp6
-rw-r--r--noncore/settings/networksettings2/irda/irda_NNI.h16
-rw-r--r--noncore/settings/networksettings2/irda/irdarun.h3
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NN.cpp23
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NN.h17
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NNI.cpp6
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NNI.h15
-rw-r--r--noncore/settings/networksettings2/main.cpp16
-rw-r--r--noncore/settings/networksettings2/modem/modem_NN.cpp11
-rw-r--r--noncore/settings/networksettings2/modem/modem_NN.h8
-rw-r--r--noncore/settings/networksettings2/modem/modem_NNI.cpp6
-rw-r--r--noncore/settings/networksettings2/modem/modem_NNI.h16
-rw-r--r--noncore/settings/networksettings2/modem/modemrun.h3
-rw-r--r--noncore/settings/networksettings2/network/network_NN.cpp42
-rw-r--r--noncore/settings/networksettings2/network/network_NN.h31
-rw-r--r--noncore/settings/networksettings2/network/network_NNI.cpp122
-rw-r--r--noncore/settings/networksettings2/network/network_NNI.h19
-rw-r--r--noncore/settings/networksettings2/networksettings.cpp52
-rw-r--r--noncore/settings/networksettings2/networksettings.h3
-rw-r--r--noncore/settings/networksettings2/networksettings.pro3
-rw-r--r--noncore/settings/networksettings2/networksettings2/Utils.h1
-rw-r--r--noncore/settings/networksettings2/networksettings2/asline.h2
-rw-r--r--noncore/settings/networksettings2/networksettings2/netnode.cpp23
-rw-r--r--noncore/settings/networksettings2/networksettings2/netnode.h460
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.cpp13
-rw-r--r--noncore/settings/networksettings2/networksettings2/resources.h5
-rw-r--r--noncore/settings/networksettings2/networksettings2/system.cpp18
-rw-r--r--noncore/settings/networksettings2/networksettings2/systemfile.cpp30
-rw-r--r--noncore/settings/networksettings2/networksettings2/systemfile.h11
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp476
-rw-r--r--noncore/settings/networksettings2/nsdata.h11
-rw-r--r--noncore/settings/networksettings2/ppp/PPPAuthGUI.ui158
-rw-r--r--noncore/settings/networksettings2/ppp/PPPAuthedit.cpp42
-rw-r--r--noncore/settings/networksettings2/ppp/PPPAuthedit.h2
-rw-r--r--noncore/settings/networksettings2/ppp/ppp_NN.cpp31
-rw-r--r--noncore/settings/networksettings2/ppp/ppp_NN.h31
-rw-r--r--noncore/settings/networksettings2/ppp/ppp_NNI.cpp108
-rw-r--r--noncore/settings/networksettings2/ppp/ppp_NNI.h21
-rw-r--r--noncore/settings/networksettings2/profile/profile_NN.cpp13
-rw-r--r--noncore/settings/networksettings2/profile/profile_NN.h8
-rw-r--r--noncore/settings/networksettings2/profile/profile_NNI.cpp27
-rw-r--r--noncore/settings/networksettings2/profile/profile_NNI.h23
-rw-r--r--noncore/settings/networksettings2/usb/usb_NN.cpp23
-rw-r--r--noncore/settings/networksettings2/usb/usb_NN.h7
-rw-r--r--noncore/settings/networksettings2/usb/usb_NNI.cpp35
-rw-r--r--noncore/settings/networksettings2/usb/usb_NNI.h18
-rw-r--r--noncore/settings/networksettings2/vpn/vpn_NN.cpp14
-rw-r--r--noncore/settings/networksettings2/vpn/vpn_NN.h8
-rw-r--r--noncore/settings/networksettings2/vpn/vpn_NNI.cpp6
-rw-r--r--noncore/settings/networksettings2/vpn/vpn_NNI.h16
-rw-r--r--noncore/settings/networksettings2/wlan/wlan_NN.cpp23
-rw-r--r--noncore/settings/networksettings2/wlan/wlan_NN.h9
-rw-r--r--noncore/settings/networksettings2/wlan/wlan_NNI.cpp107
-rw-r--r--noncore/settings/networksettings2/wlan/wlan_NNI.h20
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
@@ -1,50 +1,42 @@
#include "bluetoothBNEPedit.h"
#include "bluetoothBNEP_NNI.h"
#include "bluetooth_NN.h"
ABluetoothBNEP::ABluetoothBNEP( BluetoothBNEPNetNode * PNN ) :
ANetNodeInstance( PNN ), Data() {
GUI = 0;
RT = 0;
Data.AllowAll = 1;
}
void ABluetoothBNEP::setSpecificAttribute( QString & S, QString & A ) {
if( S == "bdaddress" ) {
Data.BDAddress << A;
} else if ( S == "allowall" ) {
Data.AllowAll = 1;
}
}
void ABluetoothBNEP::saveSpecificAttribute( QTextStream & TS ) {
TS << "allowall=" << Data.AllowAll << endl;
for ( QStringList::Iterator it = Data.BDAddress.begin();
it != Data.BDAddress.end();
++it ) {
TS << "bdaddress=" << (*it) << endl;
}
}
QWidget * ABluetoothBNEP::edit( QWidget * parent ) {
GUI = new BluetoothBNEPEdit( parent );
GUI->showData( Data );
return GUI;
}
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
@@ -1,46 +1,42 @@
#ifndef BLUETOOTHBNEP_H
#define BLUETOOTHBNEP_H
#include <netnode.h>
#include "bluetoothBNEPdata.h"
#include "bluetoothBNEPrun.h"
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;
BluetoothBNEPData Data;
BluetoothBNEPRun * RT;
};
#endif
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
@@ -1,38 +1,30 @@
#include "bluetoothRFCOMMedit.h"
#include "bluetoothRFCOMM_NNI.h"
#include "bluetooth_NN.h"
ABluetoothRFCOMM::ABluetoothRFCOMM( BluetoothRFCOMMNetNode * PNN ) : ANetNodeInstance( PNN ) {
GUI = 0;
RT = 0;
}
void ABluetoothRFCOMM::setSpecificAttribute( QString & , QString & ) {
}
void ABluetoothRFCOMM::saveSpecificAttribute( QTextStream & ) {
}
QWidget * ABluetoothRFCOMM::edit( QWidget * parent ) {
GUI = new BluetoothRFCOMMEdit( parent );
GUI->showData( Data );
return GUI;
}
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
@@ -1,45 +1,41 @@
#ifndef BLUETOOTHRFCOMM_H
#define BLUETOOTHRFCOMM_H
#include <netnode.h>
#include "bluetoothRFCOMMdata.h"
#include "bluetoothRFCOMMrun.h"
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;
BluetoothRFCOMMData Data;
BluetoothRFCOMMRun * RT;
};
#endif
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
@@ -1,25 +1,28 @@
#include <asline.h>
#include "bluetoothRFCOMMdata.h"
class BluetoothRFCOMMRun : public AsLine {
public :
BluetoothRFCOMMRun( ANetNodeInstance * NNI,
BluetoothRFCOMMData & Data ) : AsLine( NNI )
{ }
virtual AsLine * asLine( void )
{ return (AsLine *)this; }
+ virtual QString deviceFile( void )
+ { return QString( "/dev/rfcomm..." ); }
+
protected :
void detectState( NodeCollection * )
{ }
bool setState( NodeCollection * , Action_t, bool )
{ return 0; }
bool canSetState( State_t , Action_t )
{ return 0; }
};
diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp
index b59b4f0..443a627 100644
--- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp
+++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.cpp
@@ -1,153 +1,115 @@
#include "bluetooth_NN.h"
#include "bluetoothBNEP_NNI.h"
#include "bluetoothRFCOMM_NNI.h"
//
//
// BLUETOOTH PAN/NAP node
//
//
static const char * BluetoothBNEPNeeds[] =
{ 0
};
/**
* Constructor, find all of the possible interfaces
*/
BluetoothBNEPNetNode::BluetoothBNEPNetNode() :
ANetNode(tr("Bluetooth PAN/NAP")) {
InstanceCount = 7; // default
}
/**
* Delete any interfaces that we own.
*/
BluetoothBNEPNetNode::~BluetoothBNEPNetNode(){
}
const QString BluetoothBNEPNetNode::nodeDescription(){
return tr("\
<p>Sets up a bluetooth link using the bluetooth Network profile.</p>\
<p>Use this to connect two computing devices.</p>\
"
);
}
ANetNodeInstance * BluetoothBNEPNetNode::createInstance( void ) {
return new ABluetoothBNEP( this );
}
const char ** BluetoothBNEPNetNode::needs( void ) {
return BluetoothBNEPNeeds;
}
const char * BluetoothBNEPNetNode::provides( void ) {
return "device";
}
-bool BluetoothBNEPNetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 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" ) {
InstanceCount = V.toLong();
}
}
void BluetoothBNEPNetNode::saveSpecificAttribute( QTextStream & TS) {
TS << "interfacecount="
<< InstanceCount
<< endl;
}
//
//
// BLUETOOTH RFCOMM
//
//
static const char * BluetoothRFCOMMNeeds[] =
{ 0
};
BluetoothRFCOMMNetNode::BluetoothRFCOMMNetNode() :
ANetNode( tr("Bluetooth serial link") ) {
}
BluetoothRFCOMMNetNode::~BluetoothRFCOMMNetNode(){
}
const QString BluetoothRFCOMMNetNode::nodeDescription(){
return tr("\
<p>Sets up a bluetooth link using the bluetooth serial profile.</p>\
<p>Use this to connect to a GSM.</p>\
"
);
}
ANetNodeInstance * BluetoothRFCOMMNetNode::createInstance( void ) {
return new ABluetoothRFCOMM( this );
}
const char ** BluetoothRFCOMMNetNode::needs( void ) {
return BluetoothRFCOMMNeeds;
}
const char * BluetoothRFCOMMNetNode::provides( void ) {
return "line";
}
-bool BluetoothRFCOMMNetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 0;
-}
-
-bool BluetoothRFCOMMNetNode::hasDataFor( const QString & ) {
- 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 ) {
PNN.append( new BluetoothBNEPNetNode() );
PNN.append( new BluetoothRFCOMMNetNode() );
}
}
diff --git a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h
index 2e5e1d2..4d6a3c1 100644
--- a/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h
+++ b/noncore/settings/networksettings2/bluetooth/bluetooth_NN.h
@@ -1,81 +1,66 @@
#ifndef BLUETOOTH_NETNODE_H
#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"
{
void create_plugin( QList<ANetNode> & PNN );
};
#endif
diff --git a/noncore/settings/networksettings2/cable/cable_NN.cpp b/noncore/settings/networksettings2/cable/cable_NN.cpp
index b8c690b..38568df 100644
--- a/noncore/settings/networksettings2/cable/cable_NN.cpp
+++ b/noncore/settings/networksettings2/cable/cable_NN.cpp
@@ -1,60 +1,49 @@
#include "cable_NN.h"
#include "cable_NNI.h"
static const char * CableNeeds[] =
{ 0
};
/**
* Constructor, find all of the possible interfaces
*/
CableNetNode::CableNetNode() : ANetNode(tr("Cable Connection")) {
}
/**
* Delete any interfaces that we own.
*/
CableNetNode::~CableNetNode(){
}
const QString CableNetNode::nodeDescription(){
return tr("\
<p>Sets up a wired serial or parallel.</p>\
"
);
}
ANetNodeInstance * CableNetNode::createInstance( void ) {
return new ACable( this );
}
const char ** CableNetNode::needs( void ) {
return CableNeeds;
}
const char * CableNetNode::provides( void ) {
return "line";
}
-bool CableNetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 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 ) {
PNN.append( new CableNetNode() );
}
}
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
@@ -1,44 +1,36 @@
#ifndef CABLE_NETNODE_H
#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"
{
void create_plugin( QList<ANetNode> & PNN );
};
#endif
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
@@ -1,73 +1,89 @@
#include "cableedit.h"
#include "cable_NNI.h"
#include "cable_NN.h"
ACable::ACable( CableNetNode * PNN ) : ANetNodeInstance( PNN ) {
// default values
Data.Device = "/dev/ttyS0";
Data.LockFile = "/var/Lock";
Data.Speed = 115200;
Data.DataBits = 8;
Data.Parity = 0;
Data.StopBits = 1;
Data.HardwareControl = 0;
Data.SoftwareControl = 0;
GUI = 0;
RT = 0;
}
void ACable::setSpecificAttribute( QString & A, QString & V) {
if( A == "device" ) {
Data.Device = V;
} else if ( A == "lockfile" ) {
Data.LockFile = V;
} else if ( A == "speed" ) {
Data.Speed = V.toLong();
} else if ( A == "parity" ) {
Data.Parity = V.toShort();
} else if ( A == "databits" ) {
Data.DataBits = V.toShort();
} else if ( A == "stopbits" ) {
Data.StopBits = V.toShort();
} else if ( A == "hardwarecontrol" ) {
Data.HardwareControl = ( V == "yes" );
} else if ( A == "softwarecontrol" ) {
Data.SoftwareControl = ( V == "yes" );
}
}
void ACable::saveSpecificAttribute( QTextStream & TS ) {
TS << "device=" << quote( Data.Device ) << endl;
TS << "lockfile=" << quote( Data.LockFile ) << endl;
TS << "speed=" << Data.Speed << endl;
TS << "parity=" << Data.Parity << endl;
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
@@ -1,48 +1,46 @@
#ifndef CABLE_H
#define CABLE_H
#include <netnode.h>
#include "cabledata.h"
#include "cablerun.h"
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;
CableData_t Data;
CableRun * RT;
};
#endif
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,26 +1,30 @@
#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 );
}
bool CableRun::setState( NodeCollection * NC, Action_t A, bool ) {
if( A == Activate ) {
detectState(NC);
return (NC->currentState() == Available);
}
return 1;
}
bool CableRun::canSetState( State_t , Action_t ) {
return 1;
}
+
+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
@@ -1,60 +1,49 @@
#include "irda_NN.h"
#include "irda_NNI.h"
static const char * IRDANeeds[] =
{ 0
};
/**
* Constructor, find all of the possible interfaces
*/
IRDANetNode::IRDANetNode() : ANetNode(tr("Infrared link")) {
}
/**
* Delete any interfaces that we own.
*/
IRDANetNode::~IRDANetNode(){
}
const QString IRDANetNode::nodeDescription(){
return tr("\
<p>Sets up a infra red serial link.</p>\
"
);
}
ANetNodeInstance * IRDANetNode::createInstance( void ) {
return new AIRDA( this );
}
const char ** IRDANetNode::needs( void ) {
return IRDANeeds;
}
const char * IRDANetNode::provides( void ) {
return "line";
}
-bool IRDANetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 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 ) {
PNN.append( new IRDANetNode() );
}
}
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
@@ -1,44 +1,36 @@
#ifndef IRDA_NETNODE_H
#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"
{
void create_plugin( QList<ANetNode> & PNN );
};
#endif
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
@@ -1,37 +1,31 @@
#include "irdaedit.h"
#include "irda_NNI.h"
#include "irda_NN.h"
AIRDA::AIRDA( IRDANetNode * PNN ) : ANetNodeInstance( PNN ) {
GUI = 0;
RT = 0;
}
void AIRDA::setSpecificAttribute( QString & , QString & ) {
}
void AIRDA::saveSpecificAttribute( QTextStream & ) {
}
QWidget * AIRDA::edit( QWidget * parent ) {
GUI = new IRDAEdit( parent );
GUI->showData( Data );
return GUI;
}
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
@@ -1,48 +1,42 @@
#ifndef IRDA_H
#define IRDA_H
#include <netnode.h>
#include "irdadata.h"
#include "irdarun.h"
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;
IRDAData Data;
IRDARun * RT;
};
#endif
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
@@ -1,25 +1,28 @@
#include <asline.h>
#include "irdadata.h"
class IRDARun : public AsLine {
public :
IRDARun( ANetNodeInstance * NNI,
IRDAData & Data ) : AsLine( NNI )
{ }
virtual AsLine * asLine( void )
{ return (AsLine *)this; }
+ virtual QString deviceFile( void )
+ { return QString( "/dev/irda" ); }
+
protected :
void detectState( NodeCollection * )
{ }
bool setState( NodeCollection * , Action_t, bool )
{ return 0; }
bool canSetState( State_t , Action_t )
{ return 0; }
};
diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.cpp b/noncore/settings/networksettings2/lancard/lancard_NN.cpp
index 05cd06d..20ae7f6 100644
--- a/noncore/settings/networksettings2/lancard/lancard_NN.cpp
+++ b/noncore/settings/networksettings2/lancard/lancard_NN.cpp
@@ -1,94 +1,71 @@
#include "lancard_NN.h"
#include "lancard_NNI.h"
static const char * LanCardNeeds[] =
{ 0 };
/**
* Constructor, find all of the possible interfaces
*/
LanCardNetNode::LanCardNetNode() : ANetNode(tr("LAN card")), NICMACAddresses() {
InstanceCount = 2;
}
/**
* Delete any interfaces that we own.
*/
LanCardNetNode::~LanCardNetNode(){
}
const QString LanCardNetNode::nodeDescription(){
return tr("\
<p>Sets up a wired regular LAN card.</p>\
<p>Use this to set up 10/100/1000 MBit LAN cards.</p>\
"
);
}
ANetNodeInstance * LanCardNetNode::createInstance( void ) {
return new ALanCard( this );
}
const char ** LanCardNetNode::needs( void ) {
return LanCardNeeds;
}
const char * LanCardNetNode::provides( void ) {
return "device";
}
-bool LanCardNetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 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();
} else if ( A == "macaddress" ) {
NICMACAddresses.append( V );
}
}
void LanCardNetNode::saveSpecificAttribute( QTextStream & TS) {
TS << "interfacecount="
<< InstanceCount
<< endl;
for( QStringList::Iterator it = NICMACAddresses.begin();
it != NICMACAddresses.end();
++it ) {
TS << "macaddress="
<< (*it)
<< endl;
}
}
extern "C" {
void create_plugin( QList<ANetNode> & PNN ) {
PNN.append( new LanCardNetNode() );
}
}
diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.h b/noncore/settings/networksettings2/lancard/lancard_NN.h
index d58823c..6882af7 100644
--- a/noncore/settings/networksettings2/lancard/lancard_NN.h
+++ b/noncore/settings/networksettings2/lancard/lancard_NN.h
@@ -1,57 +1,50 @@
#ifndef LANCARD_NETNODE_H
#define LANCARD_NETNODE_H
#include <qstringlist.h>
#include "netnode.h"
class ALanCard;
class LanCardNetNode : public ANetNode{
Q_OBJECT
public:
LanCardNetNode();
virtual ~LanCardNetNode();
virtual const QString pixmapName()
{ return "Devices/card"; }
- virtual const QString 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
long InstanceCount;
QStringList NICMACAddresses;
};
extern "C"
{
void create_plugin( QList<ANetNode> & PNN );
};
#endif
diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp
index 99c033e..9fb05b9 100644
--- a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp
+++ b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp
@@ -1,51 +1,45 @@
#include "lancardedit.h"
#include "lancard_NNI.h"
#include "lancard_NN.h"
ALanCard::ALanCard( LanCardNetNode * PNN ) : ANetNodeInstance( PNN ) {
Data.AnyLanCard = 1;
Data.HWAddresses.clear();
GUI = 0;
RT = 0;
}
void ALanCard::setSpecificAttribute( QString & A, QString & V ) {
if( A == "matchanycard" ) {
Data.AnyLanCard = (V == "yes" );
} else if( A == "match" ) {
Data.HWAddresses.append( V );
}
}
void ALanCard::saveSpecificAttribute( QTextStream & TS) {
TS << "matchanycard=" <<
((Data.AnyLanCard) ? "yes" : "no") << endl;
for( QStringList::Iterator it = Data.HWAddresses.begin();
it != Data.HWAddresses.end(); ++it ) {
TS << "match=" << quote( *it ) << endl;
}
}
QWidget * ALanCard::edit( QWidget * parent ) {
GUI = new LanCardEdit( parent );
GUI->showData( this );
return GUI;
}
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
@@ -1,47 +1,42 @@
#ifndef LANCARD_H
#define LANCARD_H
#include <netnode.h>
#include "lancarddata.h"
#include "lancardrun.h"
class LanCardNetNode;
class LanCardEdit;
class ALanCard : public ANetNodeInstance {
public :
ALanCard( LanCardNetNode * PNN );
+ 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;
LanCardData Data;
LanCardRun * RT;
};
#endif
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,140 +1,146 @@
#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
OPIE_EXPORT_APP( OApplicationFactory<NetworkSettings> )
#else
// 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_
QPEApplication * TheApp;
#else
QApplication * TheApp;
#endif
for ( int i = 1; i < argc; i ++ ) {
int rmv;
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;
}
}
if( strstr( argv[0], "-request" ) ) {
// called from system to request something
GuiType = QApplication::Tty;
Action = ACT_REQUEST;
}
// Start Qt
#ifdef _WS_QWS_
// because QPEApplication does not handle GuiType well
if( GuiType == QApplication::Tty ) {
// this cast is NOT correct but we do not use
// TheApp anymore ...
TheApp = (QPEApplication *)new QApplication( argc, argv, GuiType );
} else {
TheApp = new QPEApplication( argc, argv, GuiType );
}
#else
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();
delete W;
}
break;
}
LogClose();
return rv;
}
#endif
// main.cpp
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
@@ -1,61 +1,50 @@
#include "modem_NN.h"
#include "modem_NNI.h"
static const char * ModemNeeds[] =
{ "line"
};
/**
* Constructor, find all of the possible interfaces
*/
ModemNetNode::ModemNetNode() : ANetNode(tr("Dialup modem")) {
}
/**
* Delete any interfaces that we own.
*/
ModemNetNode::~ModemNetNode(){
}
const QString ModemNetNode::nodeDescription(){
return tr("\
<p>Sets up a dialing procedures.</p>\
<p>Use this to dial up over modems, ISDN, GSM, ...</p>\
"
);
}
ANetNodeInstance * ModemNetNode::createInstance( void ) {
return new AModem( this );
}
const char ** ModemNetNode::needs( void ) {
return ModemNeeds;
}
const char * ModemNetNode::provides( void ) {
return "line";
}
-bool ModemNetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 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 ) {
PNN.append( new ModemNetNode() );
}
}
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
@@ -1,44 +1,36 @@
#ifndef MODEM_NETNODE_H
#define MODEM_NETNODE_H
#include "netnode.h"
class AModem;
class ModemNetNode : public ANetNode{
Q_OBJECT
public:
ModemNetNode();
virtual ~ModemNetNode();
virtual const QString pixmapName()
{ return "Devices/modem"; }
virtual const QString 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"
{
void create_plugin( QList<ANetNode> & PNN );
};
#endif
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
@@ -1,37 +1,31 @@
#include "modemedit.h"
#include "modem_NNI.h"
#include "modem_NN.h"
AModem::AModem( ModemNetNode * PNN ) : ANetNodeInstance( PNN ) {
GUI = 0;
RT = 0;
}
void AModem::setSpecificAttribute( QString & , QString & ) {
}
void AModem::saveSpecificAttribute( QTextStream & ) {
}
QWidget * AModem::edit( QWidget * parent ) {
GUI = new ModemEdit( parent );
GUI->showData( Data );
return GUI;
}
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
@@ -1,48 +1,42 @@
#ifndef Modem_H
#define Modem_H
#include <netnode.h>
#include "modemdata.h"
#include "modemrun.h"
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;
ModemData Data;
ModemRun * RT;
};
#endif
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
@@ -1,25 +1,28 @@
#include <asline.h>
#include "modemdata.h"
class ModemRun : public AsLine {
public :
ModemRun( ANetNodeInstance * NNI,
ModemData & Data ) : AsLine ( NNI )
{ }
virtual AsLine * asLine( void )
{ return (AsLine *)this; }
+ virtual QString deviceFile( void )
+ { return QString("/dev/modem"); }
+
protected :
void detectState( NodeCollection * )
{ }
bool setState( NodeCollection *, Action_t, bool )
{ return 0; }
bool canSetState( State_t, Action_t )
{ return 0; }
};
diff --git a/noncore/settings/networksettings2/network/network_NN.cpp b/noncore/settings/networksettings2/network/network_NN.cpp
index b4313c4..1feffdb 100644
--- a/noncore/settings/networksettings2/network/network_NN.cpp
+++ b/noncore/settings/networksettings2/network/network_NN.cpp
@@ -1,62 +1,82 @@
+#include <asdevice.h>
#include "network_NN.h"
#include "network_NNI.h"
static const char * NetworkNeeds[] =
{ "device",
0
};
/**
* Constructor, find all of the possible interfaces
*/
NetworkNetNode::NetworkNetNode() : ANetNode(tr("IP Configuration")) {
}
/**
* Delete any interfaces that we own.
*/
NetworkNetNode::~NetworkNetNode(){
}
const QString NetworkNetNode::nodeDescription(){
return tr("\
<p>Sets up TCP/IP options.</p>\
<p>Use this to configure the TCP/IP protocol</p>\
"
);
}
ANetNodeInstance * NetworkNetNode::createInstance( void ) {
return new ANetwork( this );
}
-const char ** NetworkNetNode::needs( void ) {
- return NetworkNeeds;
+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 & ) {
}
extern "C" {
void create_plugin( QList<ANetNode> & PNN ) {
PNN.append( new NetworkNetNode() );
}
}
diff --git a/noncore/settings/networksettings2/network/network_NN.h b/noncore/settings/networksettings2/network/network_NN.h
index 6548c32..745d1a7 100644
--- a/noncore/settings/networksettings2/network/network_NN.h
+++ b/noncore/settings/networksettings2/network/network_NN.h
@@ -1,44 +1,43 @@
#ifndef NETWORK_NETNODE_H
#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"
{
void create_plugin( QList<ANetNode> & PNN );
};
#endif
diff --git a/noncore/settings/networksettings2/network/network_NNI.cpp b/noncore/settings/networksettings2/network/network_NNI.cpp
index 3e368a2..324c6e2 100644
--- a/noncore/settings/networksettings2/network/network_NNI.cpp
+++ b/noncore/settings/networksettings2/network/network_NNI.cpp
@@ -1,189 +1,219 @@
#include <system.h>
#include <asdevice.h>
#include "networkedit.h"
#include "network_NNI.h"
#include "network_NN.h"
ANetwork::ANetwork( NetworkNetNode * PNN ) : ANetNodeInstance( PNN ) {
Data.UseDHCP = 1;
Data.IPAddress = "";
Data.NetMask = "";
Data.Broadcast = "";
Data.Gateway = "";
Data.DNS1 = "";
Data.DNS2 = "";
Data.SendHostname = 0;
Data.Hostname = "";
Data.PreUp_SL.clear();
Data.PreDown_SL.clear();
Data.PostUp_SL.clear();
Data.PostDown_SL.clear();
GUI = 0;
RT = 0;
}
void ANetwork::setSpecificAttribute( QString & A, QString & V ) {
if( A == "usedhcp" ) {
Data.UseDHCP = (V == "yes");
} else if( A == "sendhostname" ) {
Data.SendHostname = (V=="yes");
} else if( A == "hostname" ) {
Data.Hostname = V;
} else if( A == "ipaddress" ) {
Data.IPAddress = V;
} else if( A == "netmask" ) {
Data.NetMask = V;
} else if( A == "broadcast" ) {
Data.Broadcast = V;
} else if( A == "gateway" ) {
Data.Gateway = V;
} else if( A == "dns1" ) {
Data.DNS1 = V;
} else if( A == "dns2" ) {
Data.DNS2 = V;
} else if( A == "preup" ) {
Data.PreUp_SL.append( V );
} else if( A == "predown" ) {
Data.PreDown_SL.append( V );
} else if( A == "postup" ) {
Data.PostUp_SL.append( V );
} else if( A == "postdown" ) {
Data.PostDown_SL.append( V );
}
}
void ANetwork::saveSpecificAttribute( QTextStream & TS ) {
TS << "usedhcp=" << ((Data.UseDHCP) ? "yes" : "no") << endl;
TS << "sendhostname=" << ((Data.SendHostname) ? "yes" : "no") << endl;
TS << "hostname=" << Data.Hostname << endl;
TS << "ipaddress=" << Data.IPAddress << endl;
TS << "netmask=" << Data.NetMask << endl;
TS << "broadcast=" << Data.Broadcast << endl;
TS << "gateway=" << Data.Gateway << endl;
TS << "dns1=" << Data.DNS1 << endl;
TS << "dns2=" << Data.DNS2 << endl;
for ( QStringList::Iterator it = Data.PreUp_SL.begin();
it != Data.PreUp_SL.end();
++it ) {
TS << "preup=" << quote(*it) << endl;
}
for ( QStringList::Iterator it = Data.PreDown_SL.begin();
it != Data.PreDown_SL.end();
++it ) {
TS << "predown=" << quote(*it) << endl;
}
for ( QStringList::Iterator it = Data.PostUp_SL.begin();
it != Data.PostUp_SL.end();
++it ) {
TS << "postup=" << quote(*it) << endl;
}
for ( QStringList::Iterator it = Data.PostDown_SL.begin();
it != Data.PostDown_SL.end();
++it ) {
TS << "postdown=" << quote(*it) << endl;
}
}
QWidget * ANetwork::edit( QWidget * parent ) {
GUI = new NetworkEdit( parent );
GUI->showData( Data );
return GUI;
}
QString ANetwork::acceptable( void ) {
return ( GUI ) ? GUI->acceptable( ) : QString();
}
void ANetwork::commit( void ) {
if( GUI && GUI->commit( Data ) )
setModified( 1 );
}
-bool ANetwork::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
@@ -1,47 +1,48 @@
#ifndef NETWORK_H
#define NETWORK_H
#include <netnode.h>
#include "networkdata.h"
#include "networkrun.h"
class NetworkNetNode;
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 :
NetworkEdit * GUI;
NetworkData_t Data;
NetworkRun * RT;
};
#endif
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,475 +1,469 @@
#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,
WFlags fl ) : NetworkSettingsGUI(parent,name,fl),
NSD() {
UpdateTimer = new QTimer( this );
// set pixmaps
Add_TB->setPixmap( NSResources->getPixmap( "add" ) );
Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) );
CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) );
Enable_TB->setPixmap( NSResources->getPixmap( "disabled" ) );
GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) );
Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) );
Disconnect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) );
On_TB->setPixmap( NSResources->getPixmap( "off" ) );
SLOT_ToProfile();
// populate main Listbox
Profiles_LB->clear();
+ QPEApplication::setStylusOperation(
+ Profiles_LB->viewport(), QPEApplication::RightOnHold );
+
+ connect( Profiles_LB,
+ SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)),
+ this, SLOT(SLOT_EditNode(QListBoxItem*)) );
+
{ Name2Connection_t & M = NSResources->connections();
NodeCollection * NC;
// for all connections
for( QDictIterator<NodeCollection> it(M);
it.current();
++it ) {
NC = it.current();
Profiles_LB->insertItem( NC->devicePixmap(),
NC->name() );
}
}
if( Profiles_LB->count() ) {
Profiles_LB->setSelected( 0, TRUE );
}
// if no profiles -> auto popup editing
if( NSResources->connections().count() == 0 ) {
QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) );
}
connect( &(NSResources->system()),
SIGNAL( lineFromCommand(const QString &) ),
this, SLOT( SLOT_CmdMessage(const QString &) ) );
UpdateTimer->start( 5000 );
connect( UpdateTimer, SIGNAL( timeout() ),
this, SLOT( SLOT_RefreshStates() ) );
/* Add QCopChannel */
connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) );
}
NetworkSettings::~NetworkSettings() {
QString S;
- 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();
}
void NetworkSettings::SLOT_RefreshStates( void ) {
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember
if( LBI ) {
NodeCollection * NC;
NSResources->system().probeInterfaces();
// update current selection only
NC = NSResources->findConnection( LBI->text() );
if( NC ) {
State_t OldS = NC->state();
State_t NewS = NC->state(1);
if( OldS != NewS ) {
updateProfileState( LBI );
}
}
}
/* -> LATER !!
bool is;
NodeCollection * NC;
for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) {
NC = NSResources->findConnection( Profiles_LB->text(i) );
if( NC ) {
State_t OldS = NC->state();
State_t NewS = NC->state(1);
if( OldS != NewS ) {
is = Profiles_LB->isSelected(i);
Profiles_LB->changeItem( NC->statePixmap(NewS),
NC->name(),
i );
if( is ) {
Profiles_LB->setSelected( i, TRUE );
}
}
}
}
if( ci >= 0 )
Profiles_LB->setCurrentItem( ci );
*/
}
-void NetworkSettings::SLOT_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 )
return;
if( QMessageBox::warning(
0,
tr( "Removing profile" ),
tr( "Remove selected profile ?" ),
1, 0 ) == 1 ) {
NSResources->removeConnection( LBI->text() );
delete LBI;
setModified( 1 );
- NSD.forceGeneration(1);
}
}
void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) {
QString OldName = "";
+
+ 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 ) {
if( NC->name() != OldName ) {
// find if new name is free
NodeCollection * LCN = NSResources->findConnection(
NC->name() );
if( LCN ) {
QMessageBox::warning(
0,
tr( "In System Config" ),
tr( "Name %1 already exists" ).arg(NC->name())
);
continue; // restart exec
} // else new name
// new name -> remove item
NSResources->removeConnection( OldName );
NSResources->addConnection( NC );
} // else not changed
// must add it here since change will trigger event
Profiles_LB->changeItem( NC->devicePixmap(),
NC->name(),
Profiles_LB->index( LBI )
);
} else {
// new item
int ci = Profiles_LB->count();
NSResources->addConnection( NC );
NC->setNumber( NSResources->assignConnectionNumber() );
Profiles_LB->insertItem( NC->devicePixmap(), NC->name() );
Profiles_LB->setSelected( ci, TRUE );
}
updateProfileState( LBI );
}
} else {
// cancelled : reset connection
if( LBI ) {
NodeCollection * NC = NSResources->findConnection( LBI->text() );
NC->reassign();
}
}
break;
}
// reenable
UpdateTimer->start( 5000 );
}
void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) {
if( LBI == 0 )
return;
NodeCollection * NC = NSResources->findConnection( LBI->text() );
// is button possible
bool EnabledPossible, OnPossible, ConnectPossible;
// is button On or Off
bool DisabledOn, OnOn, ConnectOn;
EnabledPossible = OnPossible = ConnectPossible = 1;
DisabledOn = 1;
OnOn = ConnectOn = 0;
switch( NC->state() ) {
case Unknown :
// cannot occur here
break;
case Unchecked :
case Unavailable :
// cannot do anything but recheck
EnabledPossible = OnPossible = ConnectPossible = 0;
break;
case Disabled :
OnPossible = ConnectPossible = 0;
break;
case Off :
DisabledOn = 0;
break;
case Available :
OnOn = 1;
Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) );
DisabledOn = 0;
break;
case IsUp :
OnOn = ConnectOn = 1;
Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) );
DisabledOn = 0;
break;
}
if( ! OnOn ) {
Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) );
}
// set button state
Enable_TB->setEnabled( EnabledPossible );
On_TB->setEnabled( OnPossible );
Connect_TB->setEnabled( ConnectPossible );
Enable_TB->setOn( DisabledOn );
On_TB->setOn( OnOn );
Connect_TB->setOn( ConnectOn );
if( NC->description().isEmpty() ) {
Description_LBL->setText( tr( "<<No description>>" ) );
} else {
Description_LBL->setText( NC->description() );
}
Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() );
}
void NetworkSettings::SLOT_CheckState( void ) {
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
if ( ! LBI )
return;
updateProfileState( LBI );
}
void NetworkSettings::updateProfileState( QListBoxItem * LBI ) {
if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) {
SLOT_ShowNode( LBI );
}
}
void NetworkSettings::SLOT_GenerateConfig( void ) {
- QString S = NSD.generateSettings( TRUE );
-
- if( ! S.isEmpty() ) {
- QMessageBox::warning(
- 0,
- tr( "Generating system configuration" ),
- S
- );
- }
+ NSD.regenerate();
}
void NetworkSettings::SLOT_Enable( void ) {
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
QString Msg;
if ( ! LBI )
return;
NodeCollection * NC =
NSResources->findConnection( LBI->text() );
bool rv;
switch( NC->state() ) {
case Disabled :
Msg = tr( "Cannot enable profile" );
rv = NC->setState( Enable );
break;
default :
Msg = tr( "Cannot disable profile" );
rv = NC->setState( Disable );
break;
}
if( ! rv ) {
QMessageBox::warning(
0,
tr( "Activating profile" ),
Msg );
return;
}
updateProfileState( LBI );
}
void NetworkSettings::SLOT_On( void ) {
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
if ( ! LBI )
return;
NodeCollection * NC =
NSResources->findConnection( LBI->text() );
bool rv;
switch( NC->state() ) {
case Off :
// activate interface
rv = NC->setState( Activate );
break;
case Available : // deactivate
case IsUp : // deactivate (will also bring down if needed)
rv = NC->setState( Deactivate );
break;
default :
// others no change
return;
}
if( ! rv ) {
QMessageBox::warning(
0,
tr( "Activating profile" ),
tr( "Cannot enable profile" ) );
return;
}
updateProfileState( LBI );
}
void NetworkSettings::SLOT_Connect( void ) {
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
if ( ! LBI )
return;
NodeCollection * NC =
NSResources->findConnection( LBI->text() );
bool rv = 1 ;
switch( NC->state() ) {
case IsUp :
// down interface
rv = NC->setState( Down );
break;
case Available :
// up interface
rv = NC->setState( Up );
break;
case Off :
// activate and bring up
rv = ( NC->setState( Activate ) &&
NC->setState( Up ) );
break;
default :
// others no change
break;
}
if( ! rv ) {
QMessageBox::warning(
0,
tr( "Activating profile" ),
tr( "Cannot enable profile" ) );
}
// we do not update the GUI but wait for the REAL upping of the device
}
void NetworkSettings::SLOT_Disconnect( void ) {
QString S;
QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
if ( ! LBI )
return;
NodeCollection * NC =
NSResources->findConnection( LBI->text() );
Log(( "Force interface %s down\n", NC->name().latin1() ));
NC->setState( Down, 1 );
// remove 'up' file to make sure
S.sprintf( "/tmp/Profile-%d.up", NC->number() );
unlink( S.latin1() );
}
void NetworkSettings::SLOT_ToMessages( void ) {
Profile_GB->hide();
Messages_GB->show();
}
void NetworkSettings::SLOT_ToProfile( void ) {
Profile_GB->show();
Messages_GB->hide();
}
void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) {
QDataStream stream( data, IO_ReadOnly );
if( msg == "raise" ) {
raise();
return;
} /* if ( msg == "someMessage(int,int,int)" ) {
int a,b,c;
stream >> a >> b >> c;
...
} */
}
diff --git a/noncore/settings/networksettings2/networksettings.h b/noncore/settings/networksettings2/networksettings.h
index 8ffde06..8ec5d08 100644
--- a/noncore/settings/networksettings2/networksettings.h
+++ b/noncore/settings/networksettings2/networksettings.h
@@ -1,54 +1,53 @@
#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,
const char *name=0,
WFlags fl = 0 );
~NetworkSettings( void );
static QString appName( void )
{ return QString::fromLatin1("networksettings"); }
bool isModified( void )
{ return NSD.isModified(); }
void setModified( bool m )
{ NSD.setModified( m ); }
public slots :
- void SLOT_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 );
void SLOT_Disconnect( void );
void SLOT_GenerateConfig( void );
void SLOT_RefreshStates( void );
void SLOT_QCopMessage( const QCString&,const QByteArray& );
void SLOT_ToProfile( void );
void SLOT_ToMessages( void );
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
@@ -1,18 +1,20 @@
#ifndef ASLINE_H
#define ASLINE_H
#include <netnode.h>
// pure virtual (component oriented) interface of any
// plugin that offers a line
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
@@ -1,312 +1,331 @@
#include <time.h>
#include <qpe/qpeapplication.h>
#include <qpainter.h>
#include <qbitmap.h>
#include <qtextstream.h>
#include <qpixmap.h>
#include "resources.h"
#include "netnode.h"
#include "asdevice.h"
#include "asline.h"
#include "asconnection.h"
#include "asfullsetup.h"
QString & deQuote( QString & X ) {
if( X[0] == '"' ) {
// remove end and trailing "" and \x -> x
QChar R;
long idx;
idx = X.length()-1;
X = X.mid( 1, idx );
idx = 0;
while( ( idx = X.find( '\\', idx ) ) >= 0 ) {
R = X.at( idx + 1 );
X.replace( idx, 2, &R, 1 );
}
X = X.left( X.length()-1 );
}
return X;
}
QString quote( QString X ) {
if( X.find( QRegExp( "[ \n\"\\\t]" ) ) >= 0 ) {
// need to quote this
QString OutString = "\"";
X.replace( QRegExp("\""), "\\\"" );
X.replace( QRegExp("\\"), "\\\\" );
X.replace( QRegExp(" "), "\\ " );
OutString += X;
OutString += "\"";
X = OutString;
}
return X;
}
//
//
// ANETNODE
//
//
void ANetNode::saveAttributes( QTextStream & TS ) {
saveSpecificAttribute( TS );
}
void ANetNode::setAttribute( QString & Attr, QString & Value ){
setSpecificAttribute( Attr, Value );
}
//
//
// ANETNODEINSTANCE
//
//
long ANetNodeInstance::InstanceCounter = -1;
void ANetNodeInstance::initialize( void ) {
if( InstanceCounter == -1 )
InstanceCounter = time(0);
// set name
QString N;
N.sprintf( "-%ld", InstanceCounter++ );
N.prepend( NodeType->name() );
setName( N.latin1() );
}
void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){
if( Attr == "name" ) {
setName( Value.latin1() );
} else {
setSpecificAttribute( Attr, Value );
}
}
void ANetNodeInstance::saveAttributes( QTextStream & TS ) {
TS << "name=" << name() << endl;
saveSpecificAttribute( TS );
}
ANetNodeInstance * ANetNodeInstance::nextNode( void ) {
return connection()->findNext( this );
}
//
//
// NODECOLLECTION
//
//
NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() {
IsModified = 0;
Index = -1;
Name="";
IsNew = 1;
CurrentState = Unchecked;
}
NodeCollection::NodeCollection( QTextStream & TS ) :
QList<ANetNodeInstance>() {
long idx;
bool InError = 0;
QString S, A, N;
IsModified = 0;
Index = -1;
Name="";
IsNew = 0;
CurrentState = Unchecked;
do {
S = TS.readLine();
if( S.isEmpty() ) {
if( InError ) {
// remove all nodes
clear();
}
// empty line
break;
}
idx = S.find('=');
S.stripWhiteSpace();
A = S.left( idx );
A.lower();
N = S.mid( idx+1, S.length() );
N.stripWhiteSpace();
N = deQuote( N );
if( A == "name" ) {
Name = N;
} else if( A == "number" ) {
- 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;
}
}
} while( 1 );
}
NodeCollection::~NodeCollection( void ) {
}
const QString & NodeCollection::description( void ) {
ANetNodeInstance * NNI = getToplevel();
return (NNI) ? NNI->runtime()->asFullSetup()->description() : Name;
}
void NodeCollection::append( ANetNodeInstance * NNI ) {
NNI->setConnection( this );
QList<ANetNodeInstance>::append( NNI );
}
void NodeCollection::save( QTextStream & TS ) {
TS << "name=" << quote( Name ) << endl;
TS << "number=" << number() << endl;
ANetNodeInstance * NNI;
for( QListIterator<ANetNodeInstance> it(*this);
it.current();
++it ) {
NNI = it.current();
TS << "node=" << NNI->name() << endl;
}
TS << endl;
IsNew = 0;
}
ANetNodeInstance * NodeCollection::getToplevel( void ) {
ANetNodeInstance * NNI = 0;
for( QListIterator<ANetNodeInstance> it(*this);
it.current();
++it ) {
NNI = it.current();
if( NNI->nodeClass()->isToplevel() )
break;
}
return NNI;
}
ANetNodeInstance * NodeCollection::findByName( const QString & S ) {
ANetNodeInstance * NNI = 0;
for( QListIterator<ANetNodeInstance> it(*this);
it.current();
++it ) {
NNI = it.current();
if( NNI->name() == S )
break;
}
return NNI;
}
ANetNodeInstance * NodeCollection::findNext( ANetNodeInstance * NNI ) {
ANetNodeInstance * NNNI;
if( ! NNI )
getToplevel();
for( QListIterator<ANetNodeInstance> it(*this);
it.current();
++it ) {
NNNI = it.current();
if( NNNI == NNI ) {
++it;
return it.current();
}
}
return 0; // no more next
}
int NodeCollection::compareItems( QCollection::Item I1,
QCollection::Item I2 ) {
ANetNodeInstance * NNI1, * NNI2;
NNI1 = (ANetNodeInstance *)I1;
NNI2 = (ANetNodeInstance *)I2;
return strcmp( NNI1->name(), NNI2->name() );
}
static char * State2PixmapTbl[] = {
"NULL", // Unchecked : no pixmap
"check", // Unknown
"delete", // unavailable
"disabled", // disabled
"off", // off
"disconnected", // available
"connected" // up
};
QPixmap NodeCollection::devicePixmap( void ) {
QPixmap pm = NSResources->getPixmap(
getToplevel()->nextNode()->pixmapName()+"-large");
QPixmap Mini = NSResources->getPixmap( device()->netNode()->pixmapName() );
QPainter painter( &pm );
painter.drawPixmap( pm.width()-Mini.width(),
pm.height()-Mini.height(),
Mini );
pm.setMask( pm.createHeuristicMask( TRUE ) );
return pm;
}
QPixmap NodeCollection::statePixmap( State_t S) {
return NSResources->getPixmap( State2PixmapTbl[S] );
}
QString NodeCollection::stateName( State_t S) {
switch( S ) {
case Unknown :
return qApp->translate( "networksettings2", "Unknown");
case Unavailable :
return qApp->translate( "networksettings2", "Unavailable");
case Disabled :
return qApp->translate( "networksettings2", "Disabled");
case Off :
return qApp->translate( "networksettings2", "Off");
case Available :
return qApp->translate( "networksettings2", "Available");
case IsUp :
return qApp->translate( "networksettings2", "IsUp");
case Unchecked : /* FT */
default :
break;
}
return QString("");
}
void NodeCollection::reassign( void ) {
for( QListIterator<ANetNodeInstance> it(*this);
it.current();
++it ) {
it.current()->setConnection( this );
}
}
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();
}
AsDevice * RuntimeInfo::device( void ) {
return netNode()->nextNode()->runtime()->device();
}
diff --git a/noncore/settings/networksettings2/networksettings2/netnode.h b/noncore/settings/networksettings2/networksettings2/netnode.h
index ca35c27..d3d7b34 100644
--- a/noncore/settings/networksettings2/networksettings2/netnode.h
+++ b/noncore/settings/networksettings2/networksettings2/netnode.h
@@ -1,384 +1,494 @@
#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;
class AsConnection;
class AsFullSetup;
// needed for plugin creation function
#include <qlist.h>
class ANetNode;
class ANetNodeInstance;
class NodeCollection;
class QTextStream;
class RuntimeInfo;
class InterfaceInfo;
extern QString & deQuote( QString & X );
extern QString quote( QString X );
#include "systemfile.h"
typedef enum State {
- // if we have not yet detected the state of the device
- Unchecked = 0,
- // if we cannot determine the state
- Unknown = 1,
- // if connection cannot be established e.g. because
- // the hardware is not available
- Unavailable = 2,
- // if the connection cannot be establishec but NOT
- // because it is physically impossible but because
- // it has been disabled for FUNCTIONAL reasons
- Disabled = 3,
- // if connection is available to is currently down
- // i.e. the corresponding hardware is not activated
- Off = 4,
- // if connection is available to be used (i.e. the
- // devices if fully ready to be used
- Available = 5,
- // if connection is being used
- IsUp = 6
+ // 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 :
RuntimeInfo( ANetNodeInstance * TheNNI )
{ NNI = TheNNI; }
// downcast implemented by specify runtime classes
virtual AsDevice * asDevice( void )
{ return 0; }
virtual AsConnection * asConnection( void )
{ return 0; }
virtual AsLine * asLine( void )
{ return 0; }
virtual AsFullSetup * asFullSetup( void )
{ return 0; }
// does this node handles this interface e.g.eth0
// recurse deeper if this node cannot answer that question
virtual bool handlesInterface( const QString & )
{ return 0; }
virtual bool handlesInterface( const InterfaceInfo & )
{ return 0; }
virtual InterfaceInfo * assignedInterface( void );
virtual AsDevice * device( void );
ANetNodeInstance * netNode()
{ return NNI; }
NodeCollection * connection()
{ return NNI->connection(); }
virtual void detectState( NodeCollection * NC ) = 0;
virtual bool setState( NodeCollection * NC, Action_t A, bool Force = 0 ) = 0;
virtual bool canSetState( State_t Curr, Action_t A ) = 0;
signals :
// sent by device if state changes
void stateChanged( State_t S, ANetNodeInstance * NNI );
protected :
// connection this runtime info belongs to
ANetNodeInstance * NNI;
};
class NodeCollection : public QList<ANetNodeInstance> {
public :
NodeCollection( void );
NodeCollection( QTextStream & TS );
~NodeCollection( void );
- int number( void )
+ 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
State_t CurrentState;
QString Name;
// true if this collection was just created (and not
// loaded from file
bool IsNew;
// index in listbox
int Index;
bool IsModified;
+ 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
@@ -1,444 +1,453 @@
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <qpixmap.h>
#include <qdir.h>
#include <qpe/qlibrary.h>
#include <qpe/qpeapplication.h>
#include <opie2/odebug.h>
#include <qtopia/resource.h>
#include "netnode.h"
#include "resources.h"
#define PLUGINDIR "plugins/networksettings2"
#define ICONDIR "/pics/networksettings2/"
// single resources instance
TheNSResources * _NSResources = 0;
TheNSResources::TheNSResources( void ) : NodeTypeNameMap(),
ConnectionsMap() {
_NSResources = this;
detectCurrentUser();
// load available netnodes
findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR );
// compile provides and needs lists
{ const char ** NeedsRun;
QDictIterator<NetNode_t> OuterIt( AllNodeTypes );
bool Done;
for ( ; OuterIt.current(); ++OuterIt ) {
// find needs list
ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList;
ANetNode::NetNodeList & NNL = *(NNLP);
// must iterate this way to avoid duplication pointers
for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes );
InnerIt.current(); ++InnerIt ) {
if( InnerIt.current() == OuterIt.current() )
// avoid recursive
continue;
const char * Provides = InnerIt.current()->NetNode->provides();
NeedsRun = OuterIt.current()->NetNode->needs();
for( ; *NeedsRun; NeedsRun ++ ) {
if( strcmp( Provides, *NeedsRun ) == 0 ) {
// inner provides what outer needs
NNL.resize( NNL.size() + 1 );
NNL[NNL.size()-1] = InnerIt.current()->NetNode;
Done = 1; // break from 2 loops
break;
}
}
}
OuterIt.current()->NetNode->setAlternatives( NNLP );
}
}
// define Node types to Description map
NodeTypeNameMap.insert( "device", tr( "Network Device" ) );
NodeTypeNameMap.insert( "line", tr( "Character device" ) );
NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) );
NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) );
NodeTypeDescriptionMap.insert( "device",
tr( "<p>Devices that can handle IP packets</p>" ) );
NodeTypeDescriptionMap.insert( "line",
tr( "<p>Devices that can handle single bytes</p>" ) );
NodeTypeDescriptionMap.insert( "connection",
tr( "<p>Nodes that provide working IP connections</p>" ) );
NodeTypeDescriptionMap.insert( "fullsetup",
tr( "<p>Fully configured connection profile</p>" ) );
// define system files
- addSystemFile( new SystemFile( "interfaces", "./interfaces" ) );
+ 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();
}
*/
}
/**
* Load all modules that are found in the path
* @param path a directory that is scaned for any plugins that can be loaded
* and attempts to load them
*/
void TheNSResources::findAvailableNetNodes(const QString &path){
Log(("Locate plugins in %s\n", path.latin1() ));
QDir d(path);
if(!d.exists())
return;
QString lang = ::getenv("LANG");
// Don't want sym links
d.setFilter( QDir::Files | QDir::NoSymLinks );
const QFileInfoList *list = d.entryInfoList();
QFileInfoListIterator it( *list );
QFileInfo *fi;
while ( (fi=it.current()) ) {
if( fi->fileName().contains(".so")){
/* if loaded install translation */
if( loadNetNode(path + "/" + fi->fileName()) ) {
QTranslator *trans = new QTranslator(qApp);
QString fn = QPEApplication::qpeDir()+
"/i18n/"+lang+"/"+
fi->fileName().left( fi->fileName().find(".") )+
".qm";
if( trans->load( fn ) )
qApp->installTranslator( trans );
else
delete trans;
}
}
++it;
}
}
// used to find unique connection number
int TheNSResources::assignConnectionNumber( void ) {
bool found = 1;
for( int trial = 0; ; trial ++ ) {
found = 1;
for( QDictIterator<NodeCollection> it(ConnectionsMap);
it.current();
++it ) {
if( it.current()->number() == trial ) {
found = 0;
break;
}
}
if( found ) {
Log(("Assign profile number %d\n", trial ));
return trial;
}
}
}
/**
* Attempt to load a function and resolve a function.
* @param pluginFileName - the name of the file in which to attempt to load
* @param resolveString - function pointer to resolve
* @return true of loading is successful
*/
bool TheNSResources::loadNetNode(
const QString &pluginFileName, const QString &resolveString){
QLibrary *lib = new QLibrary(pluginFileName);
void * res = lib->resolve(resolveString);
if( ! res ){
delete lib;
return 0;
}
GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res;
// Try to get an object.
QList<ANetNode> PNN;
getNetNodeList( PNN );
if( PNN.isEmpty() ) {
delete lib;
return 0;
}
ANetNode * NNP;
for( QListIterator<ANetNode> it(PNN);
it.current();
++it ) {
NetNode_t * NN;
NNP = it.current();
NN = new NetNode_t;
NN->NetNode = NNP;
NN->TheLibrary = lib;
NN->NodeCountInLib = PNN.count();
// store mapping
AllNodeTypes.insert( NN->NetNode->name(), NN );
}
return 1;
}
QPixmap TheNSResources::getPixmap( const QString & QS ) {
QPixmap P;
QString S("networksettings2/");
S += QS;
Log(("%s\n", S.latin1() ));
P = Resource::loadPixmap( S );
return ( P.isNull() ) ? QPixmap() : P;
}
QString TheNSResources::tr( const char * s ) {
return qApp->translate( "resource", s );
}
const QString & TheNSResources::netNode2Name( const char * s ) {
return NodeTypeNameMap[s];
}
const QString & TheNSResources::netNode2Description( const char * s ) {
return NodeTypeDescriptionMap[s];
}
void TheNSResources::addConnection( NodeCollection * NC ) {
ANetNodeInstance * NNI;
ConnectionsMap.insert( NC->name(), NC );
// add (new) nodes to NodeList
for( QListIterator<ANetNodeInstance> it(*NC);
it.current();
++it ) {
NNI = it.current();
if( findNodeInstance( NNI->name() ) == 0 ) {
// new item
addNodeInstance( NNI );
}
}
}
void TheNSResources::removeConnection( const QString & N ) {
NodeCollection * NC = findConnection( N );
if( ! NC )
return;
// delete netnodes in this connection
ANetNodeInstance * NNI;
for( NNI = NC->first(); NNI != 0; NNI = NC->next() ) {
removeNodeInstance( NNI->name() );
}
ConnectionsMap.remove( N );
}
NodeCollection * TheNSResources::findConnection( const QString & S ) {
return ConnectionsMap[ S ];
}
/*
void TheNSResources::renumberConnections( void ) {
Name2Connection_t & M = NSResources->connections();
NodeCollection * NC;
// for all connections
NodeCollection::resetMaxNr();
for( QDictIterator<NodeCollection> it(M);
it.current();
++it ) {
NC = it.current();
NC->setNumber( NC->maxConnectionNumber()+1 );
NC->setModified( 1 );
}
}
*/
typedef struct EnvVars {
char * Name;
int Len;
} EnvVar_t;
#define AnEV(x) x, sizeof(x)-1
static EnvVar_t EV[] = {
// AnEV( "HOME=" ), -> SPECIAL
// AnEV( "LOGNAME=" ), -> SPECIAL
AnEV( "USER=" ),
AnEV( "LD_LIBRARY_PATH=" ),
AnEV( "PATH=" ),
AnEV( "QTDIR=" ),
AnEV( "OPIEDIR=" ),
AnEV( "SHELL=" ),
{ NULL, 0 }
};
void TheNSResources::detectCurrentUser( void ) {
// find current running qpe
QString QPEEnvFile = "";
if( getenv( "OPIEDIR" ) == 0 ) {
// nothing known
{ // open proc dir and find all dirs in it
QRegExp R("[0-9]+");
QDir ProcDir( "/proc" );
QFileInfo FI;
QStringList EL = ProcDir.entryList( QDir::Dirs );
// print it out
for ( QStringList::Iterator it = EL.begin();
it != EL.end();
++it ) {
if( R.match( (*it) ) >= 0 ) {
QString S = ProcDir.path()+"/"+ (*it);
S.append( "/exe" );
FI.setFile( S );
// get the link
S = FI.readLink();
if( S.right( 8 ) == "/bin/qpe" ) {
// found running qpe
QPEEnvFile.sprintf( ProcDir.path()+ "/" + (*it) + "/environ" );
break;
}
}
}
}
if( QPEEnvFile.isEmpty() ) {
// could not find qpe
Log(("Could not find qpe\n" ));
return;
}
// FI now contains path ProcDir to the cmd dir
{ char * Buf = 0;
char TB[1024];
long BufSize = 0;
int fd;
int rd;
fd = open( QPEEnvFile.latin1(), O_RDONLY );
if( fd < 0 ) {
Log(("Could not open %s : %d\n",
QPEEnvFile.latin1(), errno ));
return;
}
while( (rd = read( fd, TB, sizeof(TB) ) ) > 0 ) {
Buf = (char *)realloc( Buf, BufSize+rd );
memcpy( Buf+BufSize, TB, rd );
BufSize += rd;
}
char * Data = Buf;
char * DataEnd = Data+BufSize-1;
// get env items out of list
while( Data < DataEnd ) {
if( strncmp( Data, "LOGNAME=", 8 ) == 0 ) {
CurrentUser.UserName = Data+8;
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
strdup( Data );
} else if( strncmp( Data, "HOME=", 5 ) == 0 ) {
CurrentUser.HomeDir = Data+5;
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
strdup( Data );
} else {
EnvVar_t * Run = EV;
while( Run->Name ) {
if( strncmp( Data, Run->Name, Run->Len ) == 0 ) {
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
strdup( Data );
// put OPIEDIR in env
if( strcmp( Run->Name, "OPIEDIR=" ) == 0 ) {
putenv( CurrentUser.EnvList[CurrentUser.EnvList.size()-1] );
}
break;
}
Run ++;
}
}
Data += strlen( Data )+1;
}
free( Buf );
if( ! CurrentUser.UserName.isEmpty() ) {
// find user info
struct passwd pwd;
struct passwd * pwdres;
if( getpwnam_r( CurrentUser.UserName.latin1(),
&pwd, TB, sizeof(TB), &pwdres ) ||
pwdres == 0 ) {
Log(("Could not determine user %s : %d\n",
CurrentUser.UserName.latin1(), errno ));
return;
}
CurrentUser.Uid = pwd.pw_uid;
CurrentUser.Gid = pwd.pw_gid;
} else{
CurrentUser.Uid =
CurrentUser.Gid = -1;
}
}
} else {
CurrentUser.UserName = getenv( "LOGNAME" );
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
strdup( CurrentUser.UserName );
CurrentUser.HomeDir = getenv( "HOME" );
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] =
strdup( CurrentUser.HomeDir );
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("USER");
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("LD_LIBRARY_PATH");
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("PATH");
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("QTDIR");
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("OPIEDIR");
CurrentUser.EnvList.resize( CurrentUser.EnvList.size()+1 );
CurrentUser.EnvList[CurrentUser.EnvList.size()-1] = getenv("SHELL");
CurrentUser.Uid = getuid();
CurrentUser.Gid = getgid();
}
}
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
@@ -1,131 +1,132 @@
#ifndef __RESOURCES__H
#define __RESOURCES__H
#include <qstring.h>
#include <qdict.h>
#include <qmap.h>
#include <qlist.h>
#include "netnode.h"
#include "systemfile.h"
#include "system.h"
class QLibrary;
class QPixmap;
class ANetNode;
class ANetNodeInstance;
typedef void (*GetNetNodeListFt_t)(QList<ANetNode>& PNN );
typedef struct NetNode_S {
ANetNode * NetNode;
QLibrary * TheLibrary;
long NodeCountInLib;
} NetNode_t;
class CurrentQPEUser {
public :
CurrentQPEUser() : UserName(), HomeDir(), EnvList() {}
QString UserName;
QString HomeDir;
int Uid;
int Gid;
QArray<char *> EnvList;
};
typedef QDict<NetNode_t> Name2NetNode_t;
typedef QDict<ANetNodeInstance > Name2Instance_t;
typedef QDict<NodeCollection> Name2Connection_t;
typedef QDict<SystemFile> Name2SystemFile_t;
class TheNSResources {
public :
TheNSResources( void );
~TheNSResources( );
// give busy feedback
void busy( bool B );
System & system()
{ return *TheSystem; }
int assignConnectionNumber(void);
QPixmap getPixmap( const QString & Name );
Name2NetNode_t & netNodes( void )
{ return AllNodeTypes; }
bool netNodeExists( const QString & X )
{ 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();
NNI->initialize();
return NNI;
}
Name2Instance_t & netNodeInstances( void )
{ return AllNodes; }
void addNodeInstance( ANetNodeInstance * I )
{ AllNodes.insert( I->name(), I ); }
void removeNodeInstance( const QString & N )
{ AllNodes.remove( N );}
ANetNodeInstance * findNodeInstance( const QString & S )
{ return (AllNodes.find(S)!=0) ? AllNodes[S] : 0; }
const QString & netNode2Name( const char * Type );
const QString & netNode2Description( const char * Type );
void addConnection( NodeCollection * NC );
void removeConnection( const QString & N );
NodeCollection * findConnection( const QString & N );
Name2Connection_t & connections( void )
{ return ConnectionsMap; }
CurrentQPEUser & currentUser( void )
{ return CurrentUser; }
private :
void detectCurrentUser( void );
QString tr( const char * path );
void findAvailableNetNodes( const QString &path );
bool loadNetNode(
const QString &pluginFileName,
const QString &resolveString = "create_plugin");
QMap< QString, QString> NodeTypeNameMap;
QMap< QString, QString> NodeTypeDescriptionMap;
Name2Connection_t ConnectionsMap;
System * TheSystem;
Name2SystemFile_t SystemFiles;
// all node type classes
Name2NetNode_t AllNodeTypes;
// all nodes
Name2Instance_t AllNodes;
CurrentQPEUser CurrentUser;
};
extern TheNSResources * _NSResources;
#define NSResources _NSResources
#endif
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
@@ -1,417 +1,429 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <qdir.h>
#include <qregexp.h>
#include <qstringlist.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qapplication.h>
#include "resources.h"
#include "system.h"
#define PROCNETDEV "/proc/net/dev"
static char Dig2Hex[] = {
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'
};
// get HIGH nibble of byte
#define HN(x) Dig2Hex[(((x)&0xf0)>>4)]
// get LOW nibble of byte
#define LN(x) Dig2Hex[((x)&0x0f)]
System::System( void ) : QObject(), ProbedInterfaces() {
probeInterfaces();
}
System::~System( void ) {
if( ProcDevNet )
delete ProcDevNet;
}
int System::runAsRoot( const QString & S ) {
QString MyS = S;
char * usr = getenv("USER");
char ch;
if( S.isEmpty() ) {
// loophole to start shell
return 8888;
}
if( usr == 0 || strcmp( usr, "root" ) ) {
// unknown or non-root user -> use SUDO
MyS.prepend( "sudo " );
}
Log(("Executing %s\n", MyS.latin1() ));
emit lineFromCommand( tr("Command : ") + MyS );
emit lineFromCommand( "---------------" );
Log(( "Command : %s\n", MyS.latin1() ) );
MyS += " 2>&1 ";
OutputOfCmd = popen( MyS.latin1(), "r" ) ;
if( ! OutputOfCmd ) {
// cannot fork
return 1;
}
// read all data
QString Line = "";
while( 1 ) {
if( fread( &ch, 1, 1, OutputOfCmd ) < 1 )
// eof
break;
if( ch == '\n' || ch == '\r' ) {
if( ! Line.isEmpty() ) {
Log(( "read cmd output : **%s**\n", Line.latin1() ) );
emit lineFromCommand( Line );
Line = "";
qApp->processEvents();
}
} else {
Line += ch;
}
}
if( ! Line.isEmpty() ) {
emit lineFromCommand( Line );
Log(( "read cmd output : **%s**\n", Line.latin1() ) );
}
Log(( "End of command\n", Line.latin1() ) );
if( pclose( OutputOfCmd ) < 0 ) {
// error in command
return 3;
}
// all is fine
return 0;
}
void System::refreshStatistics( InterfaceInfo & I ) {
if( ! ProcDevNet ) {
return;
}
// cannot seek on dev
ProcDevNet->close();
ProcDevNet->open( IO_ReadOnly );
QString line;
QTextStream procTs(ProcDevNet);
QStringList SL;
int loc = -1;
int version;
procTs.readLine();
line = procTs.readLine();
// get version
if( line.find("compressed") )
version = 3;
else if( line.find( "bytes" ) )
version = 2;
else
version = 1;
while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
if( (loc = line.find(":") ) == -1) {
continue;
}
if( I.Name != line.left(loc) )
continue;
// tokenize
SL = QStringList::split( ' ', line, FALSE );
// update data
switch( version ) {
case 1 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];
I.RcvDropped = SL[4];
I.SndBytes = SL[6];
I.SndErrors = SL[8];
I.SndDropped = SL[9];
I.Collisions = SL[11];
break;
case 2 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];
I.RcvDropped = SL[4];
I.SndBytes = SL[7];
I.SndErrors = SL[9];
I.SndDropped = SL[10];
I.Collisions = SL[12];
break;
case 3 :
I.RcvBytes = SL[1];
I.RcvErrors = SL[3];
I.RcvDropped = SL[4];
I.SndBytes = SL[9];
I.SndErrors = SL[11];
I.SndDropped = SL[12];
I.Collisions = SL[14];
break;
}
break;
}
}
//
// THIS UPDATES THE LIST -> INTERFACES ARE NOT DELETED BUT
// FLAGGED AS ! 'IsUp' IF NO LONGER PRESENT
//
void System::probeInterfaces( void ) {
// probe interfaces
int sockfd;
// get list of all interfaces
struct ifreq ifrs;
InterfaceInfo * IFI;
// flag all as 'down'
for( QDictIterator<InterfaceInfo> it( ProbedInterfaces );
it.current();
++it ) {
it.current()->IsUp = 0;
}
sockfd = socket(PF_INET, SOCK_DGRAM, 0);
if(sockfd == -1)
return;
// read interfaces from /proc/dev/net
// SIOCGIFCONF does not return ALL interfaces ???!?
ProcDevNet = new QFile(PROCNETDEV);
if( ! ProcDevNet->open(IO_ReadOnly) ) {
delete ProcDevNet;
ProcDevNet =0;
return;
}
QString line;
QString NicName;
QTextStream procTs(ProcDevNet);
int loc = -1;
procTs.readLine(); // eat a line
procTs.readLine(); // eat a line
while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) {
if((loc = line.find(":")) == -1) {
continue;
}
NicName = line.left(loc);
// set name for ioctl
strcpy( ifrs.ifr_name, NicName.latin1() );
if ( ! ( IFI = ProbedInterfaces.find( NicName ) ) ) {
// new nic
Log(("NEWNIC %s\n", NicName.latin1()));
IFI = new InterfaceInfo;
IFI->Name = line.left(loc);
IFI->NetNode = 0;
ProbedInterfaces.insert( IFI->Name, IFI );
// get dynamic info
if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) {
IFI->IsPointToPoint = ((ifrs.ifr_flags & IFF_POINTOPOINT) == IFF_POINTOPOINT);
} else {
IFI->IsPointToPoint = 0;
}
// settings that never change
IFI->DstAddress = "";
if( IFI->IsPointToPoint ) {
if( ioctl(sockfd, SIOCGIFDSTADDR, &ifrs) >= 0 ) {
IFI->DstAddress =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_dstaddr)->sin_addr);
}
}
IFI->CardType = 999999;
IFI->MACAddress = "";
if( ioctl(sockfd, SIOCGIFHWADDR, &ifrs) >= 0 ) {
Log(("%s = %d\n", IFI->Name.latin1(),
ifrs.ifr_hwaddr.sa_family ));
IFI->CardType = ifrs.ifr_hwaddr.sa_family;
switch( ifrs.ifr_hwaddr.sa_family ) {
case ARPHRD_ETHER : // regular MAC address
// valid address -> convert to regular ::: format
// length = 6 bytes = 12 DIGITS -> 6 :
IFI->MACAddress.sprintf(
"%c%c:%c%c:%c%c:%c%c:%c%c:%c%c",
HN( ifrs.ifr_hwaddr.sa_data[0] ),
LN( ifrs.ifr_hwaddr.sa_data[0] ),
HN( ifrs.ifr_hwaddr.sa_data[1] ),
LN( ifrs.ifr_hwaddr.sa_data[1] ),
HN( ifrs.ifr_hwaddr.sa_data[2] ),
LN( ifrs.ifr_hwaddr.sa_data[2] ),
HN( ifrs.ifr_hwaddr.sa_data[3] ),
LN( ifrs.ifr_hwaddr.sa_data[3] ),
HN( ifrs.ifr_hwaddr.sa_data[4] ),
LN( ifrs.ifr_hwaddr.sa_data[4] ),
HN( ifrs.ifr_hwaddr.sa_data[5] ),
LN( ifrs.ifr_hwaddr.sa_data[5] )
);
break;
#ifdef ARPHRD_IEEE1394
case ARPHRD_IEEE1394 : // Firewire Eth address
IFI->MACAddress.sprintf(
"%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-%c%c-00-00",
HN( ifrs.ifr_hwaddr.sa_data[0] ),
LN( ifrs.ifr_hwaddr.sa_data[0] ),
HN( ifrs.ifr_hwaddr.sa_data[1] ),
LN( ifrs.ifr_hwaddr.sa_data[1] ),
HN( ifrs.ifr_hwaddr.sa_data[2] ),
LN( ifrs.ifr_hwaddr.sa_data[2] ),
HN( ifrs.ifr_hwaddr.sa_data[3] ),
LN( ifrs.ifr_hwaddr.sa_data[3] ),
HN( ifrs.ifr_hwaddr.sa_data[4] ),
LN( ifrs.ifr_hwaddr.sa_data[4] ),
HN( ifrs.ifr_hwaddr.sa_data[5] ),
LN( ifrs.ifr_hwaddr.sa_data[5] ),
HN( ifrs.ifr_hwaddr.sa_data[6] ),
LN( ifrs.ifr_hwaddr.sa_data[6] ),
HN( ifrs.ifr_hwaddr.sa_data[7] ),
LN( ifrs.ifr_hwaddr.sa_data[7] ),
HN( ifrs.ifr_hwaddr.sa_data[8] ),
LN( ifrs.ifr_hwaddr.sa_data[8] ),
HN( ifrs.ifr_hwaddr.sa_data[9] ),
LN( ifrs.ifr_hwaddr.sa_data[9] ),
HN( ifrs.ifr_hwaddr.sa_data[10] ),
LN( ifrs.ifr_hwaddr.sa_data[10] ),
HN( ifrs.ifr_hwaddr.sa_data[11] ),
LN( ifrs.ifr_hwaddr.sa_data[11] ),
HN( ifrs.ifr_hwaddr.sa_data[12] ),
LN( ifrs.ifr_hwaddr.sa_data[12] ),
HN( ifrs.ifr_hwaddr.sa_data[13] ),
LN( ifrs.ifr_hwaddr.sa_data[13] )
);
break;
#endif
case ARPHRD_PPP : // PPP
break;
case ARPHRD_IEEE80211 : // WLAN
break;
case ARPHRD_IRDA : // IRDA
break;
}
}
} else // else already probed before -> just update
Log(("OLDNIC %s\n", NicName.latin1()));
// get dynamic info
if( ioctl(sockfd, SIOCGIFFLAGS, &ifrs) >= 0 ) {
IFI->IsUp = ((ifrs.ifr_flags & IFF_UP) == IFF_UP);
IFI->HasMulticast = ((ifrs.ifr_flags & IFF_MULTICAST) == IFF_MULTICAST);
} else {
IFI->IsUp = 0;
IFI->HasMulticast = 0;
}
if( ioctl(sockfd, SIOCGIFADDR, &ifrs) >= 0 ) {
IFI->Address =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_addr)->sin_addr);
} else {
IFI->Address = "";
IFI->IsUp = 0;
}
if( ioctl(sockfd, SIOCGIFBRDADDR, &ifrs) >= 0 ) {
IFI->BCastAddress =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_broadaddr)->sin_addr);
} else {
IFI->BCastAddress = "";
}
if( ioctl(sockfd, SIOCGIFNETMASK, &ifrs) >= 0 ) {
IFI->Netmask =
inet_ntoa(((struct sockaddr_in*)&ifrs.ifr_netmask)->sin_addr);
} else {
IFI->Netmask = "";
}
Log(("NIC %s UP %d\n", NicName.latin1(), IFI->IsUp ));
}
}
void System::execAsUser( QString & Cmd, char * argv[] ) {
CurrentQPEUser CU = NSResources->currentUser();
if( CU.UserName.isEmpty() ) {
// if we come here, the exec was not successfull
Log(("User not known \n" ));
return;
}
// now we are ready to exec the requested command
setuid( CU.Uid );
setgid( CU.Gid );
char ** envp = (char **)alloca( sizeof( char *) *
(CU.EnvList.count()+1) );
for( unsigned int i = 0 ; i < CU.EnvList.count() ; i ++ ) {
*(envp+i) = CU.EnvList[i];
}
envp[CU.EnvList.count()]=NULL;
execve( Cmd.latin1(), argv, envp );
// if we come here, the exec was not successfull
Log(("Could not exec : %d\n", errno ));
}
#include <stdarg.h>
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");
}
}
if( (long)logf > 1 ) {
vfprintf( logf, Format, l );
}
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
@@ -1,185 +1,189 @@
#include <stdio.h>
#include <qpe/qpeapplication.h>
#include <qfileinfo.h>
#include <qmessagebox.h>
#include <qfile.h>
#include <qtextstream.h>
#include "resources.h"
#include "systemfile.h"
#define TEMPLATEDIR "networktemplates/"
QString TemplDir;
-SystemFile::SystemFile( const QString & N, const QString & P ){
+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
TemplDir = QPEApplication::qpeDir() + "etc/" + TEMPLATEDIR;
FI.setFile( TemplDir );
if( ! FI.isDir() ) {
// try current dir
TemplDir = "./" TEMPLATEDIR;
FI.setFile( TemplDir );
if( ! FI.isDir() ) {
hasPreSection =
hasPostSection =
hasPreNodeSection =
hasPostNodeSection =
hasPreDeviceSection =
hasPostDeviceSection = 0;
return;
}
}
// have found location
S = TemplDir + Name + "/presection";
FI.setFile( S );
hasPreSection = ( FI.exists() && FI.isReadable() );
S = TemplDir + Name + "/postsection";
FI.setFile( S );
hasPostSection = ( FI.exists() && FI.isReadable() );
S = TemplDir + Name + "/prenodesection";
FI.setFile( S );
hasPreNodeSection = ( FI.exists() && FI.isReadable() );
S = TemplDir + Name + "/postnodesection";
FI.setFile( S );
hasPostNodeSection = ( FI.exists() && FI.isReadable() );
S = TemplDir + Name + "/predevicesection";
FI.setFile( S );
hasPreDeviceSection = ( FI.exists() && FI.isReadable() );
S = TemplDir + Name + "/postdevicesection";
FI.setFile( S );
hasPostDeviceSection = ( FI.exists() && FI.isReadable() );
}
+
+ KnowsDeviceInstances = KDI;
}
SystemFile::~SystemFile( void ) {
if( F )
delete F;
}
bool SystemFile::open( void ) {
if( F ) {
F->close();
delete F;
}
F = new QFile( Path + "bup" );
if( ! F->open( IO_WriteOnly ) ) {
return 0;
}
setDevice( F );
return 1;
}
bool SystemFile::close( void ) {
if( ! F ) {
return 1 ;
}
QString OldP = Path + "bup";
F->close();
delete F;
F = 0;
return ( rename( OldP.latin1(), Path.latin1() ) >= 0 );
}
bool SystemFile::preSection( void ) {
if( hasPreSection ) {
QFile Fl( TemplDir + Name + "/presection" );
if( ! Fl.open( IO_ReadOnly ) )
- return 1; // error
+ 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
@@ -1,43 +1,50 @@
#ifndef __SYSTEMFILE__H
#define __SYSTEMFILE__H
#include <qstring.h>
#include <qtextstream.h>
class QFile;
class ANetNodeInstance;
class SystemFile : public QTextStream {
public :
- SystemFile( const QString & Name, const QString & Path );
+ SystemFile( 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 );
bool preDeviceSection( ANetNode * NN );
bool postDeviceSection( ANetNode * NN );
private :
QString Name;
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
@@ -1,573 +1,593 @@
#include <stdlib.h>
#include <qpe/qpeapplication.h>
#include <qtextstream.h>
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
#include "nsdata.h"
#include <asdevice.h>
#include <resources.h>
static QString CfgFile;
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;
}
void NetworkSettingsData::loadSettings( void ) {
QString Line, S;
QString Attr, Value;
long idx;
QFile F( CfgFile );
QTextStream TS( &F );
do {
if( ! F.open(IO_ReadOnly) )
break;
/* load the file ->
FORMAT :
[NETNODETYPE]
Entries ...
<EMPTYLINE>
[connection]
Name=Name
Node=Name
<EMPTYLINE>
*/
while( ! TS.atEnd() ) {
S = Line = TS.readLine();
if ( S.isEmpty() || S[0] != '[' )
continue;
S = S.mid( 1, S.length()-2 );
if( ! NSResources ) {
continue;
}
if( S == "connection" ) {
// load connections -> collections of nodes
NodeCollection * NC = new NodeCollection( TS );
NSResources->addConnection( NC );
} else {
ANetNode * NN = 0;
ANetNodeInstance* NNI = 0;
if( S.startsWith( "nodetype " ) ) {
S = S.mid( 9, S.length()-9 );
S = deQuote(S);
// try to find netnode
NN = NSResources->findNetNode( S );
Log( ( "Node %s : %p\n", S.latin1(), NN ) );
} else {
// try to find instance
NNI = NSResources->createNodeInstance( S );
Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI ));
}
if( NN == 0 && NNI == 0 ) {
LeftOvers.append( Line );
}
do {
S = Line = TS.readLine();
if( NN || NNI ) {
if( S.isEmpty() ) {
// empty line
break;
}
idx = S.find( '=' );
if( idx > 0 ) {
Attr = S.left( idx );
Value = S.mid( idx+1, S.length() );
} else {
Value="";
Attr = S;
}
Value.stripWhiteSpace();
Attr.stripWhiteSpace();
Attr.lower();
// dequote Attr
Value = deQuote(Value);
if( NN ) {
// set the attribute
NN->setAttribute( Attr, Value );
} else {
// set the attribute
NNI->setAttribute( Attr, Value );
}
} else {
LeftOvers.append( Line );
// add empty line too as delimiter
if( S.isEmpty() ) {
// empty line
break;
}
}
} while( 1 );
if( NNI ) {
// loading from file -> exists
NNI->setNew( FALSE );
NSResources->addNodeInstance( NNI );
}
}
}
} while( 0 );
}
QString NetworkSettingsData::saveSettings( void ) {
QString ErrS = "";
if( ! isModified() )
return ErrS;
QString S;
QFile F( CfgFile + ".bup" );
Log( ( "Saving settings to %s\n", CfgFile.latin1() ));
if( ! F.open( IO_WriteOnly | IO_Truncate ) ) {
ErrS = qApp->translate( "NetworkSettings",
"<p>Could not save setup to \"%1\" !</p>" ).
arg(CfgFile);
// problem
return ErrS;
}
QTextStream TS( &F );
// save leftovers
for ( QStringList::Iterator it = LeftOvers.begin();
it != LeftOvers.end(); ++it ) {
TS << (*it) << endl;
}
// save global configs
for( QDictIterator<NetNode_t> it( NSResources->netNodes() );
it.current();
++it ) {
TS << "[nodetype "
<< quote( QString( it.current()->NetNode->name() ) )
<< "]"
<< endl;
it.current()->NetNode->saveAttributes( TS );
TS << endl;
}
{ Name2Connection_t & M = NSResources->connections();
ANetNodeInstance * NNI;
// for all connections
for( QDictIterator<NodeCollection> it(M);
it.current();
++it ) {
// all nodes in those connections
for( QListIterator<ANetNodeInstance> nit(*(it.current()));
nit.current();
++nit ) {
// header
NNI = nit.current();
TS << '['
<< QString(NNI->nodeClass()->name())
<< ']'
<< endl;
NNI->saveAttributes( TS );
TS << endl;
}
TS << "[connection]" << endl;
it.current()->save(TS);
}
}
QDir D(".");
D.rename( CfgFile + ".bup", CfgFile );
//
// proper files AND system files regenerated
//
setModified( 0 );
return ErrS;
}
-QString NetworkSettingsData::generateSettings( bool ForceReq ) {
- bool ForceIt;
+QString 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();
// for all connections
for( QDictIterator<NodeCollection> it(M);
it.current();
++it ) {
NC = it.current();
// check if this profile handles the requested interface
if( NC->handlesInterface( Interface ) && // if different Intf.
NC->state() != Disabled && // if not enabled
NC->state() != IsUp // if already used
) {
Log( ( "Append %s for %s\n", NC->name().latin1(), Interface));
PossibleConnections.append( NC );
}
}
return PossibleConnections;
}
/*
Called by the system to see if interface can be brought UP
if allowed, echo Interface-allowed else Interface-disallowed
*/
bool NetworkSettingsData::canStart( const char * Interface ) {
// load situation
NodeCollection * NC = 0;
QList<NodeCollection> PossibleConnections;
PossibleConnections = collectPossible( Interface );
Log( ( "Possiblilies %d\n", PossibleConnections.count() ));
switch( PossibleConnections.count() ) {
case 0 : // no connections
break;
case 1 : // one connection
NC = PossibleConnections.first();
break;
default : // need to ask user ?
return 1;
}
if( NC ) {
switch( NC->state() ) {
case Unchecked :
case Unknown :
case Unavailable :
case Disabled :
// this profile does not allow interface to be UP
// -> try others
break;
case Off :
// try to UP the device
if( ! NC->setState( Activate ) ) {
// cannot bring device Online -> try other alters
break;
}
// FT
case Available :
case IsUp : // also called for 'ifdown'
// device is ready -> done
printf( "%s-c%d-allowed\n", Interface, NC->number() );
return 0;
}
}
// if we come here no alternatives are possible
printf( "%s-cnn-disallowed\n", 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
@@ -1,46 +1,37 @@
#ifndef __NSDATA_H
#define __NSDATA_H
#include "netnode.h"
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
@@ -1,432 +1,426 @@
<!DOCTYPE UI><UI>
<class>PPPAuthGUI</class>
<widget>
<class>QWidget</class>
<property stdset="1">
<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>
<name>layoutMargin</name>
</property>
<property>
<name>layoutSpacing</name>
</property>
<vbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>0</number>
</property>
<widget>
<class>QButtonGroup</class>
<property stdset="1">
<name>name</name>
<cstring>ButtonGroup1</cstring>
</property>
<property stdset="1">
<name>frameShape</name>
<enum>NoFrame</enum>
</property>
<property stdset="1">
<name>title</name>
<string></string>
</property>
<property>
<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">
<name>text</name>
<string>Login</string>
</property>
<property stdset="1">
<name>checked</name>
<bool>true</bool>
</property>
</widget>
<widget>
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>
<cstring>Layout3</cstring>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<spacer>
<property>
<name>name</name>
<cstring>Spacer3</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Horizontal</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>Fixed</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>16</width>
<height>20</height>
</size>
</property>
</spacer>
<widget>
<class>QGroupBox</class>
<property stdset="1">
<name>name</name>
<cstring>GroupBox1</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>5</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>frameShape</name>
<enum>NoFrame</enum>
</property>
<property stdset="1">
<name>title</name>
<string></string>
</property>
<property>
<name>layoutMargin</name>
</property>
<property>
<name>layoutSpacing</name>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>2</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>1</number>
</property>
<widget row="0" column="0" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>LoginExpect_LE</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>ogin:</string>
</property>
</widget>
<widget row="0" column="1" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>LoginSend_LE</cstring>
</property>
</widget>
<widget row="1" column="0" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>PasswordExpect_LE</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>assword:</string>
</property>
</widget>
<widget row="1" column="1" >
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<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>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<spacer>
<property>
<name>name</name>
<cstring>Spacer3_2</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Horizontal</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>Fixed</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>16</width>
<height>20</height>
</size>
</property>
</spacer>
<widget>
<class>QGroupBox</class>
<property stdset="1">
<name>name</name>
<cstring>GroupBox3</cstring>
</property>
<property stdset="1">
<name>enabled</name>
<bool>false</bool>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>5</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>frameShape</name>
<enum>NoFrame</enum>
</property>
<property stdset="1">
<name>title</name>
<string></string>
</property>
<property>
<name>layoutMargin</name>
</property>
<property>
<name>layoutSpacing</name>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>2</number>
</property>
<property stdset="1">
<name>spacing</name>
- <number>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>
<cstring>Terminal_RB</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Terminal</string>
</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
@@ -1,85 +1,105 @@
#include <stdio.h>
#include <qcombobox.h>
#include <qmessagebox.h>
#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
@@ -1,15 +1,17 @@
#include "pppdata.h"
#include "PPPAuthGUI.h"
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,68 +1,85 @@
+#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(){
}
const QString PPPNetNode::nodeDescription(){
return tr("\
<p>Sets up IP using PPP.</p>\
<p>Use this for dialup devices or serial setups</p>\
"
);
}
ANetNodeInstance * PPPNetNode::createInstance( void ) {
return new APPP( this );
}
const char ** PPPNetNode::needs( void ) {
return PPPNeeds;
}
const char * PPPNetNode::provides( void ) {
return "connection";
}
-bool PPPNetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 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 & ) {
}
void PPPNetNode::saveSpecificAttribute( QTextStream & ) {
}
extern "C" {
void create_plugin( QList<ANetNode> & PNN ) {
PNN.append( new PPPNetNode() );
}
}
diff --git a/noncore/settings/networksettings2/ppp/ppp_NN.h b/noncore/settings/networksettings2/ppp/ppp_NN.h
index b1483c4..249be5a 100644
--- a/noncore/settings/networksettings2/ppp/ppp_NN.h
+++ b/noncore/settings/networksettings2/ppp/ppp_NN.h
@@ -1,46 +1,43 @@
#ifndef PPP_NETNODE_H
#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,121 +1,221 @@
+#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 = "";
Data.Auth.Mode = 0;
Data.Auth.Login.Expect = "ogin:";
Data.Auth.Password.Expect = "assword:";
Data.Auth.PCEMode = 0;
Data.Auth.Client = "*";
Data.Auth.Server = "*";
Data.Auth.Secret = "";
Data.IP.IPAutomatic = 1;
Data.IP.IPAddress = "";
Data.IP.IPSubMask = "";
Data.IP.GWAutomatic = 1;
Data.IP.GWAddress = "";
Data.IP.GWIsDefault = 1;
GUI = 0;
RT = 0;
}
void APPP::setSpecificAttribute( QString & A, QString & V ) {
if( A.startsWith( "dns" ) ) {
if( A == "dnsserverassigned" ) {
Data.DNS.ServerAssigned = (V == "yes");
} else if( A == "dnsdomainname" ) {
Data.DNS.DomainName = V;
} else if( A == "dnsserver" ) {
Data.DNS.Servers.resize( Data.DNS.Servers.size()+1 );
Data.DNS.Servers[Data.DNS.Servers.size()-1] =
new QString( V );
}
} else if( A.startsWith( "auth" ) ) {
if( A == "authmode" ) {
Data.Auth.Mode = V.toShort();
} else if( A == "authloginexpect" ) {
Data.Auth.Login.Expect = V;
} else if( A == "authloginsend" ) {
Data.Auth.Login.Send = V;
} else if( A == "authpasswordexpect" ) {
Data.Auth.Password.Expect = V;
} else if( A == "authpasswordsend" ) {
Data.Auth.Password.Send = V;
} else if( A == "authpcemode" ) {
Data.Auth.PCEMode = V.toShort();
} else if( A == "authclient" ) {
Data.Auth.Client = V;
} else if( A == "authserver" ) {
Data.Auth.Server = V;
} else if( A == "authsecret" ) {
Data.Auth.Secret = V;
}
} else if( A.startsWith( "ip" ) ) {
if( A == "ipautomatic" ) {
Data.IP.IPAutomatic = (V == "yes");
} else if( A == "gwautomatic" ) {
Data.IP.GWAutomatic = (V == "yes");
} else if( A == "gwisdefault" ) {
Data.IP.GWIsDefault = (V == "yes");
} else if( A == "ipaddress" ) {
Data.IP.IPAddress = V;
} else if( A == "ipsubmask" ) {
Data.IP.IPSubMask = V;
} else if( A == "gwaddress" ) {
Data.IP.GWAddress = V;
}
}
}
void APPP::saveSpecificAttribute( QTextStream & TS ) {
TS << "dnsserverassigned=" <<
( ( Data.DNS.ServerAssigned ) ? "yes" : "no" ) << endl;
TS << "dnsdomainname=" << Data.DNS.DomainName << endl;
for( unsigned int i = 0; i < Data.DNS.Servers.size(); i ++ ) {
TS << "dnsserver=" << *(Data.DNS.Servers[i]) << endl;
}
TS << "authmode=" << Data.Auth.Mode << endl;
TS << "authloginexpect=" << quote( Data.Auth.Login.Expect ) << endl;
TS << "authloginsend=" << quote( Data.Auth.Login.Send ) << endl;
TS << "authpasswordexpect=" << quote( Data.Auth.Password.Expect ) << endl;
TS << "authpasswordsend=" << quote( Data.Auth.Password.Send ) << endl;
TS << "authpcemode=" << Data.Auth.PCEMode << endl;
TS << "authclient=" << Data.Auth.Client << endl;
TS << "authserver=" << Data.Auth.Server << endl;
TS << "authsecret=" << quote( Data.Auth.Secret ) << endl;
TS << "ipautomatic=" << ( ( Data.IP.IPAutomatic ) ? "yes" : "no" ) << endl;
TS << "gwautomatic=" << ( ( Data.IP.GWAutomatic ) ? "yes" : "no" ) << endl;
TS << "gwisdefault=" << ( ( Data.IP.GWIsDefault ) ? "yes" : "no" ) << endl;
TS << "ipaddress=" << Data.IP.IPAddress << endl;
TS << "ipsubmask=" << Data.IP.IPSubMask << endl;
TS << "gwaddress=" << Data.IP.GWAddress << endl;
}
QWidget * APPP::edit( QWidget * parent ) {
GUI = new PPPEdit( parent );
GUI->showData( Data );
return GUI;
}
QString APPP::acceptable( void ) {
return ( GUI ) ? GUI->acceptable( ) : QString();
}
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
@@ -1,48 +1,51 @@
#ifndef PPP_H
#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;
PPPData Data;
PPPRun * RT;
};
#endif
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
@@ -1,62 +1,51 @@
#include "profile_NN.h"
#include "profile_NNI.h"
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(){
}
const QString ProfileNetNode::nodeDescription(){
return tr("\
<p>Define use of an IP connection.</p>\
<p>Configure if and when this connection needs to be established</p>\
"
);
}
ANetNodeInstance * ProfileNetNode::createInstance( void ) {
return new AProfile( this );
}
const char ** ProfileNetNode::needs( void ) {
return ProfileNeeds;
}
const char * ProfileNetNode::provides( void ) {
return "fullsetup";
}
-bool ProfileNetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 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 ) {
PNN.append( new ProfileNetNode() );
}
}
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
@@ -1,44 +1,36 @@
#ifndef PROFILE_NETNODE_H
#define PROFILE_NETNODE_H
#include "netnode.h"
class AProfile;
class ProfileNetNode : public ANetNode{
Q_OBJECT
public:
ProfileNetNode();
virtual ~ProfileNetNode();
virtual const QString pixmapName()
{ return "Devices/commprofile"; }
virtual const QString 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"
{
void create_plugin( QList<ANetNode> & PNN );
};
#endif
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
@@ -1,58 +1,77 @@
#include "profileedit.h"
#include "profile_NNI.h"
#include "profile_NN.h"
AProfile::AProfile( ProfileNetNode * PNN ) : ANetNodeInstance( PNN ) {
Data.Automatic = 1;
Data.Confirm = 0;
Data.Description = "";
Data.Disabled = 0;
Data.TriggerVPN = 0;
GUI = 0;
RT = 0;
}
void AProfile::setSpecificAttribute( QString & Attr, QString & Value ) {
if ( Attr == "automatic" ) {
Data.Automatic = (Value=="yes");
} else if ( Attr == "preconfirm" ) {
Data.Confirm = (Value=="yes");
} else if ( Attr == "disabled" ) {
Data.Disabled = (Value=="yes");
} else if ( Attr == "triggervpn" ) {
Data.TriggerVPN = (Value=="yes");
} else if ( Attr == "description" ) {
Data.Description = Value;
}
}
void AProfile::saveSpecificAttribute( QTextStream & TS ) {
TS << "automatic=" << ((Data.Automatic) ? "yes" : "no") << endl;
TS << "preconfirm=" << ((Data.Confirm) ? "yes" : "no") << endl;
TS << "disabled=" << ((Data.Disabled) ? "yes" : "no") << endl;
TS << "triggervpn=" << ((Data.TriggerVPN) ? "yes" : "no") << endl;
TS << "description=" << Data.Description << endl;
}
QWidget * AProfile::edit( QWidget * parent ) {
GUI = new ProfileEdit( parent, this );
GUI->showData( Data );
return GUI;
}
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
@@ -1,51 +1,50 @@
#ifndef PROFILE_H
#define PROFILE_H
#include <netnode.h>
#include "profiledata.h"
#include "profilerun.h"
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 :
ProfileEdit * GUI;
ProfileData Data;
ProfileRun * RT;
};
#endif
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
@@ -1,77 +1,54 @@
#include "usb_NN.h"
#include "usb_NNI.h"
static const char * USBNeeds[] =
{ 0
};
/**
* Constructor, find all of the possible interfaces
*/
USBNetNode::USBNetNode() : ANetNode(tr("USB Cable Connect")) {
}
/**
* Delete any interfaces that we own.
*/
USBNetNode::~USBNetNode(){
}
const QString USBNetNode::nodeDescription(){
return tr("\
<p>Configure Ethernet over USB.</p>\
<p>Use this for a computer to computer USB cable connection</p>\
"
);
}
ANetNodeInstance * USBNetNode::createInstance( void ) {
return new AUSB( this );
}
const char ** USBNetNode::needs( void ) {
return USBNeeds;
}
const char * USBNetNode::provides( void ) {
return "device";
}
-bool USBNetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 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 & ) {
}
extern "C" {
void create_plugin( QList<ANetNode> & PNN ) {
PNN.append( new USBNetNode() );
}
}
diff --git a/noncore/settings/networksettings2/usb/usb_NN.h b/noncore/settings/networksettings2/usb/usb_NN.h
index fea89f0..73da15a 100644
--- a/noncore/settings/networksettings2/usb/usb_NN.h
+++ b/noncore/settings/networksettings2/usb/usb_NN.h
@@ -1,45 +1,38 @@
#ifndef USB_NETNODE_H
#define USB_NETNODE_H
#include "netnode.h"
class AUSB;
class USBNetNode : public ANetNode{
Q_OBJECT
public:
USBNetNode();
virtual ~USBNetNode();
virtual const QString pixmapName()
{ return "Devices/usb"; }
virtual const QString 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 );
};
extern "C"
{
void create_plugin( QList<ANetNode> & PNN );
};
#endif
diff --git a/noncore/settings/networksettings2/usb/usb_NNI.cpp b/noncore/settings/networksettings2/usb/usb_NNI.cpp
index e90204c..50c6e8d 100644
--- a/noncore/settings/networksettings2/usb/usb_NNI.cpp
+++ b/noncore/settings/networksettings2/usb/usb_NNI.cpp
@@ -1,52 +1,61 @@
#include <qpe/qpeapplication.h>
#include "usbedit.h"
#include "usb_NNI.h"
#include "usb_NN.h"
AUSB::AUSB( USBNetNode * PNN ) : ANetNodeInstance( PNN ) {
GUI = 0;
RT = 0;
}
void AUSB::setSpecificAttribute( QString & , QString & ) {
}
void AUSB::saveSpecificAttribute( QTextStream & ) {
}
QWidget * AUSB::edit( QWidget * parent ) {
GUI = new USBEdit( parent );
GUI->showData( Data );
return GUI;
}
QString AUSB::acceptable( void ) {
return ( GUI ) ? GUI->acceptable( ) : QString();
}
void AUSB::commit( void ) {
if( GUI && GUI->commit( Data ) ) {
setModified( 1 );
}
}
-bool AUSB::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
@@ -1,46 +1,46 @@
#ifndef USB_H
#define USB_H
#include <netnode.h>
#include "usbdata.h"
#include "usbrun.h"
class USBNetNode;
class USBEdit;
class AUSB : public ANetNodeInstance {
public :
AUSB( USBNetNode * PNN );
+ 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 :
USBEdit * GUI;
USBData Data;
USBRun * RT;
};
#endif
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,62 +1,50 @@
#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")) {
}
/**
* Delete any interfaces that we own.
*/
VPNNetNode::~VPNNetNode(){
}
const QString VPNNetNode::nodeDescription(){
return tr("\
<p>Configure private IP connection.</p>\
<p>Defines Secure tunnels over non secure IP sessions</p>\
"
);
}
ANetNodeInstance * VPNNetNode::createInstance( void ) {
return new AVPN( this );
}
const char ** VPNNetNode::needs( void ) {
return VPNNeeds;
}
const char * VPNNetNode::provides( void ) {
return "connection";
}
-bool VPNNetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 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 ) {
PNN.append( new VPNNetNode() );
}
}
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
@@ -1,44 +1,36 @@
#ifndef VPN_NETNODE_H
#define VPN_NETNODE_H
#include "netnode.h"
class AVPN;
class VPNNetNode : public ANetNode{
Q_OBJECT
public:
VPNNetNode();
virtual ~VPNNetNode();
virtual const QString pixmapName()
{ return "Devices/vpn"; }
virtual const QString 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"
{
void create_plugin( QList<ANetNode> & PNN );
};
#endif
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
@@ -1,36 +1,30 @@
#include "vpnedit.h"
#include "vpn_NNI.h"
#include "vpn_NN.h"
AVPN::AVPN( VPNNetNode * PNN ) : ANetNodeInstance( PNN ) {
GUI = 0;
RT = 0;
}
void AVPN::setSpecificAttribute( QString & , QString & ) {
}
void AVPN::saveSpecificAttribute( QTextStream & ) {
}
QWidget * AVPN::edit( QWidget * parent ) {
GUI = new VPNEdit( parent );
GUI->showData( Data );
return GUI;
}
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
@@ -1,47 +1,43 @@
#ifndef VPN_H
#define VPN_H
#include <netnode.h>
#include "vpndata.h"
#include "vpnrun.h"
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;
VPNData Data;
VPNRun * RT;
};
#endif
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
@@ -1,85 +1,62 @@
#include "wlan_NN.h"
#include "wlan_NNI.h"
static const char * WLanNeeds[] =
{ 0
};
/**
* Constructor, find all of the possible interfaces
*/
WLanNetNode::WLanNetNode() : ANetNode(tr("WLan Device")) {
InstanceCount = 2;
}
/**
* Delete any interfaces that we own.
*/
WLanNetNode::~WLanNetNode(){
}
const QString WLanNetNode::nodeDescription(){
return tr("\
<p>Configure Wi/Fi or WLan network cards.</p>\
<p>Defines Wireless options for those cards</p>\
"
);
}
ANetNodeInstance * WLanNetNode::createInstance( void ) {
return new AWLan( this );
}
const char ** WLanNetNode::needs( void ) {
return WLanNeeds;
}
const char * WLanNetNode::provides( void ) {
return "device";
}
-bool WLanNetNode::generateProperFilesFor(
- ANetNodeInstance * ) {
- return 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();
}
}
void WLanNetNode::saveSpecificAttribute( QTextStream & TS ) {
TS << "interfacecount="
<< InstanceCount
<< endl;
}
extern "C" {
void create_plugin( QList<ANetNode> & PNN ) {
PNN.append( new WLanNetNode() );
}
}
diff --git a/noncore/settings/networksettings2/wlan/wlan_NN.h b/noncore/settings/networksettings2/wlan/wlan_NN.h
index b5ff3fd..c13c05c 100644
--- a/noncore/settings/networksettings2/wlan/wlan_NN.h
+++ b/noncore/settings/networksettings2/wlan/wlan_NN.h
@@ -1,53 +1,44 @@
#ifndef WLAN_NETNODE_H
#define WLAN_NETNODE_H
#include "netnode.h"
class AWLan;
class WLanNetNode : public ANetNode{
Q_OBJECT
public:
WLanNetNode();
virtual ~WLanNetNode();
virtual const QString pixmapName()
{ return "Devices/wlan"; }
virtual const QString 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
long InstanceCount;
};
extern "C"
{
void create_plugin( QList<ANetNode> & PNN );
};
#endif
diff --git a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp
index 61969f2..0e4fc4c 100644
--- a/noncore/settings/networksettings2/wlan/wlan_NNI.cpp
+++ b/noncore/settings/networksettings2/wlan/wlan_NNI.cpp
@@ -1,140 +1,151 @@
#include <unistd.h>
#include "wlanedit.h"
#include "wlan_NNI.h"
#include "wlan_NN.h"
AWLan::AWLan( WLanNetNode * PNN ) : ANetNodeInstance( PNN ) {
GUI = 0;
RT = 0;
Data.ESSID = "";
Data.NodeName = tr("<UseHostName>");
Data.Mode = 0;
Data.SpecificAP = 0;
Data.APMac = "";
Data.Encrypted = 0;
Data.AcceptNonEncrypted = 0;
Data.Key[0] = "";
Data.Key[1] = "";
Data.Key[2] = "";
Data.Key[3] = "";
}
void AWLan::setSpecificAttribute( QString & A, QString & V ) {
if( A == "essid" ) {
Data.ESSID = V;
} else if( A == "nodename" ) {
Data.NodeName = V;
} else if( A == "mode" ) {
Data.Mode = V.toShort();
} else if( A == "specificap" ) {
Data.SpecificAP = (V=="yes");
} else if( A == "apmac" ) {
Data.APMac = V;
} else if( A == "encrypted" ) {
Data.Encrypted = (V=="yes");
} else if( A == "acceptnonencrypted" ) {
Data.AcceptNonEncrypted = (V=="yes");
} else if( A == "key0" ) {
Data.Key[0] = V;
} else if( A == "key1" ) {
Data.Key[1] = V;
} else if( A == "key2" ) {
Data.Key[2] = V;
} else if( A == "key3" ) {
Data.Key[3] = V;
}
}
void AWLan::saveSpecificAttribute( QTextStream & S ) {
S << "essid=" << quote( Data.ESSID ) << endl;
S << "nodename=" << quote( Data.NodeName ) << endl;
S << "mode=" << Data.Mode << endl;
S << "specificap="
<< ((Data.SpecificAP) ? "yes" : "no")
<< endl;
S << "apmac=" << Data.APMac << endl;
S << "encrypted="
<< ((Data.Encrypted) ? "yes" : "no")
<< endl;
S << "acceptnonencrypted="
<< ((Data.AcceptNonEncrypted) ? "yes" : "no")
<< endl;
for( int i = 0 ;i < 4 ; i ++ ) {
S << "key" << i << "=" << Data.Key[i] << endl;
}
}
QWidget * AWLan::edit( QWidget * parent ) {
GUI = new WLanEdit( parent, this );
GUI->showData( Data );
return GUI;
}
QString AWLan::acceptable( void ) {
return ( GUI ) ? GUI->acceptable( ) : QString();
}
void AWLan::commit( void ) {
if( GUI && GUI->commit( Data ) )
setModified( 1 );
}
-bool AWLan::generateDataForCommonFile(
- SystemFile & 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
@@ -1,47 +1,47 @@
#ifndef WLAN_H
#define WLAN_H
#include <netnode.h>
#include "wlandata.h"
#include "wlanrun.h"
class WLanNetNode;
class WLanEdit;
class AWLan : public ANetNodeInstance {
public :
AWLan( WLanNetNode * PNN );
+ 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;
WLanData Data;
WLanRun * RT;
};
#endif