Diffstat (limited to 'noncore/settings/networksettings2/networksettings2') (more/less context) (ignore whitespace changes)
16 files changed, 1743 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/networksettings2/GUIUtils.cpp b/noncore/settings/networksettings2/networksettings2/GUIUtils.cpp new file mode 100644 index 0000000..a98c303 --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/GUIUtils.cpp @@ -0,0 +1,27 @@ +#include <qstringlist.h> +#include "GUIUtils.h" + +bool validIP( const QString & S ) { + + QStringList SL = QStringList::split( '.', S, TRUE ); + if( SL.count() != 4 ) + return 0; + + for( int i = 0; i < 4 ; i ++ ) { + if( SL[i].isEmpty() ) + return 0; + } + + short x = SL[0].toShort(); + + if( x < 1 || x > 255 ) + return 0; + + for( int i = 1; i < 4 ; i ++ ) { + x = SL[i].toShort(); + if( x < 0 || x > 255 ) + return 0; + } + return 1; + +} diff --git a/noncore/settings/networksettings2/networksettings2/GUIUtils.h b/noncore/settings/networksettings2/networksettings2/GUIUtils.h new file mode 100644 index 0000000..23290a9 --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/GUIUtils.h @@ -0,0 +1,36 @@ +#ifndef __GUIUTILS_H +#define __GUIUTILS_H + +#include <qstring.h> + +// if TEXT capable widget has changed +#define TXTM( Data, Wdg, FL ) \ + if( Wdg->text() != Data ) { \ + FL = 1; \ + Data = Wdg->text(); \ + } + +// if IsChecked capable widget has changed +#define CBM(Data,Wdg,FL) \ + if( Wdg->isChecked() != Data) { \ + FL = 1; \ + Data = Wdg->isChecked(); \ + } + +// if Value capable widget has changed +#define SBM(Data,Wdg,FL) \ + if( Wdg->value() != Data) { \ + FL = 1; \ + Data = Wdg->value(); \ + } + +// if currentItem capable widget has changed +#define CIM(Data,Wdg,FL) \ + if( Wdg->currentItem() != Data) { \ + FL = 1; \ + Data = Wdg->currentItem(); \ + } + +extern bool validIP( const QString & S ); + +#endif diff --git a/noncore/settings/networksettings2/networksettings2/asconnection.h b/noncore/settings/networksettings2/networksettings2/asconnection.h new file mode 100644 index 0000000..1ed7e74 --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/asconnection.h @@ -0,0 +1,18 @@ +#ifndef ASCONNECTION_H +#define ASCONNECTION_H + +#include <resources.h> + +// pure virtual (component oriented) interface of any +// plugin that offers a connection +class AsConnection : public RuntimeInfo { + +public : + + AsConnection( ANetNodeInstance * NNI ) : + RuntimeInfo( NNI ) { + } + +}; + +#endif diff --git a/noncore/settings/networksettings2/networksettings2/asdevice.h b/noncore/settings/networksettings2/networksettings2/asdevice.h new file mode 100644 index 0000000..058fc4c --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/asdevice.h @@ -0,0 +1,37 @@ +#ifndef ASDEVICE_H +#define ASDEVICE_H + +#include "system.h" +#include "netnode.h" + +// pure virtual (component oriented) interface of any +// plugin that offers a device +class AsDevice : public RuntimeInfo { + +public : + + AsDevice( ANetNodeInstance * NNI ) : + RuntimeInfo( NNI ) { + AssignedInterface = 0; + } + + // return the interface assigned to this device + // e.g eth0, wlan, ... + InterfaceInfo * assignedInterface( void ) + { return AssignedInterface; } + virtual void assignInterface( InterfaceInfo * NI ) + { AssignedInterface = NI; } + + // number of device to configure for this Device type + virtual long count( void ) + { return 1; } + // generate NIC name of device number ... + virtual QString genNic( long NicNr ) = 0; + +private : + + InterfaceInfo * AssignedInterface; + +}; + +#endif diff --git a/noncore/settings/networksettings2/networksettings2/asfullsetup.h b/noncore/settings/networksettings2/networksettings2/asfullsetup.h new file mode 100644 index 0000000..e358a83 --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/asfullsetup.h @@ -0,0 +1,20 @@ +#ifndef ASFULLSETUP_H +#define ASFULLSETUP_H + +#include <netnode.h> + +// pure virtual (component oriented) interface of any +// plugin that offers a full setup +class AsFullSetup : public RuntimeInfo { + +public : + + AsFullSetup( ANetNodeInstance * NNI ) : + RuntimeInfo( NNI ) { + } + + virtual const QString & description( void ) = 0; + +}; + +#endif diff --git a/noncore/settings/networksettings2/networksettings2/asline.h b/noncore/settings/networksettings2/networksettings2/asline.h new file mode 100644 index 0000000..6bd93ec --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/asline.h @@ -0,0 +1,18 @@ +#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 ) { + } + +}; + +#endif diff --git a/noncore/settings/networksettings2/networksettings2/config.in b/noncore/settings/networksettings2/networksettings2/config.in new file mode 100644 index 0000000..4f1dd5b --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/config.in @@ -0,0 +1,4 @@ + config NS2MAIN + boolean + default "y" if NS2 + depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && NS2 diff --git a/noncore/settings/networksettings2/networksettings2/netnode.cpp b/noncore/settings/networksettings2/networksettings2/netnode.cpp new file mode 100644 index 0000000..a5b572b --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/netnode.cpp @@ -0,0 +1,278 @@ +#include <qpe/qpeapplication.h> +#include <time.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[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; +} + +// +// +// +// +// + +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->nodeName() ); + setNodeName( N ); +} + +void ANetNodeInstance::setAttribute( QString & Attr, QString & Value ){ + if( Attr == "name" ) { + NodeName = Value; + } else { + setSpecificAttribute( Attr, Value ); + } +} + +void ANetNodeInstance::saveAttributes( QTextStream & TS ) { + TS << "name=" << quote( NodeName ) << endl; + saveSpecificAttribute( TS ); +} + +ANetNodeInstance * ANetNodeInstance::nextNode( void ) { + return connection()->findNext( this ); +} + +// +// +// +// +// + +long NodeCollection::MaxNr = -1; + +NodeCollection::NodeCollection( void ) : QList<ANetNodeInstance>() { + IsModified = 0; + Index = -1; + Name=""; + IsNew = 1; + CurrentState = Unchecked; +} + +NodeCollection::NodeCollection( QTextStream & TS ) : + QList<ANetNodeInstance>() { + long idx; + bool InError = 0; + QString S, A, N; + IsModified = 0; + Index = -1; + Name=""; + IsNew = 0; + CurrentState = Unchecked; + + do { + S = TS.readLine(); + if( S.isEmpty() ) { + if( InError ) { + // remove all nodes + clear(); + } + // empty line + break; + } + + idx = S.find('='); + S.stripWhiteSpace(); + A = S.left( idx ); + A.lower(); + N = S.mid( idx+1, S.length() ); + N.stripWhiteSpace(); + N = deQuote( N ); + + if( A == "name" ) { + Name = N; + } else if( A == "number" ) { + setNumber( N.toLong() ); + } else if( A == "node" ) { + ANetNodeInstance * NNI = NSResources->findNodeInstance( N ); + if( NNI && ! InError ) { + append( NSResources->findNodeInstance( N ) ); + } else { + // could not find a node type -> collection invalid + InError = 1; + } + } + } while( 1 ); +} + + +NodeCollection::~NodeCollection( void ) { +} + +const QString & NodeCollection::description( void ) { + ANetNodeInstance * NNI = getToplevel(); + return (NNI) ? NNI->runtime()->asFullSetup()->description() : Name; +} + +void NodeCollection::append( ANetNodeInstance * NNI ) { + NNI->setConnection( this ); + QList<ANetNodeInstance>::append( NNI ); +} + +void NodeCollection::save( QTextStream & TS ) { + + TS << "name=" << quote( Name ) << endl; + TS << "number=" << number() << endl; + ANetNodeInstance * NNI; + for( QListIterator<ANetNodeInstance> it(*this); + it.current(); + ++it ) { + NNI = it.current(); + TS << "node=" << quote( NNI->nodeName() ) << 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->netNode()->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 NNI1->nodeName().compare( NNI2->nodeName() ); +} + +static char * State2PixmapTbl[] = { + "NULL", // Unchecked : no pixmap + "check", // Unknown + "delete", // unavailable + "disabled", // disabled + "off", // off + "disconnected", // available + "connected" // up +}; + +QPixmap NodeCollection::devicePixmap( void ) { + return NSResources->getPixmap( + device()->netNode()->pixmapName()+"-large" ); +} + +QPixmap 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 ); + } +} + +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 new file mode 100644 index 0000000..0ecd64e --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/netnode.h @@ -0,0 +1,361 @@ +#ifndef NETNODE_H +#define NETNODE_H + +#include <qtextstream.h> +#include <qlist.h> +#include <qpixmap.h> +#include <qobject.h> +#include <time.h> + +// difference feature interfaces +class AsDevice; +class AsLine; +class AsConnection; +class AsFullSetup; + +// needed for plugin creation function +#include <qlist.h> + +class ANetNode; +class ANetNodeInstance; +class NodeCollection; +class QTextStream; +class RuntimeInfo; +class InterfaceInfo; + +extern QString & deQuote( QString & X ); +extern QString quote( QString X ); + +#include "systemfile.h" + +typedef enum State { + // if we have not yet detected the state of the device + Unchecked = 0, + // if we cannot determine the state + Unknown = 1, + // if connection cannot be established e.g. because + // the hardware is not available + Unavailable = 2, + // if the connection cannot be establishec but NOT + // because it is physically impossible but because + // it has been disabled for FUNCTIONAL reasons + Disabled = 3, + // if connection is available to is currently down + // i.e. the corresponding hardware is not activated + Off = 4, + // if connection is available to be used (i.e. the + // devices if fully ready to be used + Available = 5, + // if connection is being used + IsUp = 6 +} State_t; + +typedef enum Action { + // to make the device unavailable functionally + Disable = 0, + // to make the device available functionally + Enable = 1, + // bring the hardware up + Activate = 2, + // bring the hardware down + Deactivate = 3, + // bring the connection up + Up = 4, + // bring the connection down + Down = 5 +} Action_t; + +class ANetNode : public QObject{ + +public: + + typedef QArray<ANetNode *> NetNodeList; + + ANetNode(){}; + virtual ~ANetNode(){}; + + // pixmap needed for this NetNode + virtual const QString pixmapName() = 0; + + // name of this NetNode + virtual const QString nodeName() = 0; + + // description for this NetNode + virtual const QString nodeDescription() = 0; + + // create a blank instance of a net node + virtual ANetNodeInstance * createInstance( void ) = 0; + + // return feature this NetNode provides + virtual const char * provides( void ) = 0; + virtual const char ** needs( void ) = 0; + + // generate files specific for this node (if any) + virtual bool generateProperFilesFor( ANetNodeInstance * NNI ) = 0; + // return TRUE if this node has data to be inserted in systemfile + // with name S + virtual bool hasDataFor( const QString & S ) = 0; + // generate data specific for the system file S + // called only IF data was needed + virtual bool generateDataForCommonFile( + SystemFile & SF, long DevNr, ANetNodeInstance * NNI ) = 0; + + // does this Node provide a Connection + bool isToplevel( void ) + { return strcmp( provides(), "fullsetup") == 0 ; } + + // compiled references to 'needed' NetNodes -> needs list + void setAlternatives( NetNodeList * Alt ) + { Alternatives = Alt; } + NetNodeList & alternatives( void ) + { return *Alternatives; } + +protected : + + NetNodeList * Alternatives; + +private : +}; + +class ANetNodeInstance : public QObject { + +public: + + ANetNodeInstance( ANetNode * NN ) : QObject() + { IsModified=0; NodeType = NN; IsNew = TRUE; } + virtual ~ANetNodeInstance( void ) { } + + virtual RuntimeInfo * runtime( void ) = 0; + + void setConnection( NodeCollection * NC ) + { Connection = NC; } + NodeCollection * connection( void ) + { return Connection; } + + // create edit widget under parent + virtual QWidget * edit( QWidget * parent ) = 0; + // is given data acceptable + virtual QString acceptable( void ) = 0; + + // return data was modified + void setModified( bool M ) + { IsModified = M; } + bool isModified( void ) + { return IsModified; } + + // get data from GUI and store in node + virtual void commit( void ) = 0; + + // get next node + ANetNodeInstance * nextNode(); + // return NetNode this is an instance of + ANetNode * netNode( void ) + { return NodeType; } + + // intialize am instance of a net node + void initialize( void ); + + // set the value of an attribute + void setAttribute( QString & Attr, QString & Value ) ; + void saveAttributes( QTextStream & TS ) ; + + // return true if node isntance is NEW and not loaded + void setNew( bool IsN ) + { IsNew = IsN; } + bool isNew( void ) + { return IsNew; } + + // return logical name of this instance + QString & nodeName( void ) + { return NodeName; } + void setNodeName( const QString & S ) + { NodeName = S; } + // return description for this instance + QString & description( void ) + { return Description; } + void setDescription( const QString & S ) + { Description = S; } + + // pixmap for this instance -> from NetNode + const QString pixmapName( void ) + { return NodeType->pixmapName(); } + + const char * provides( void ) + { return NodeType->provides(); } + + const char ** needs( void ) + { return NodeType->needs(); } + + // returns node specific data -> only useful for 'buddy' + virtual void * data( void ) = 0; + +protected : + + virtual void setSpecificAttribute( QString & , QString & ) = 0; + virtual void saveSpecificAttribute( QTextStream & ) = 0; + + ANetNode * NodeType; + // connection to which this node belongs to + NodeCollection * Connection; + QString NodeName; + QString Description; + bool IsModified; + bool IsNew; + + static long InstanceCounter; +}; + +class RuntimeInfo : public QObject { + + Q_OBJECT + +public : + + RuntimeInfo( ANetNodeInstance * TheNNI ) + { NNI = TheNNI; } + + // downcast + AsDevice * asDevice( void ) + { return (AsDevice *)this; } + AsConnection * asConnection( void ) + { return (AsConnection *)this; } + AsLine * asLine( void ) + { return (AsLine *)this; } + AsFullSetup * asFullSetup( void ) + { return (AsFullSetup *)this; } + + // does this node handles this interface e.g.eth0 + // recurse deeper if this node cannot answer that question + virtual bool handlesInterface( const QString & ) + { return 0; } + virtual InterfaceInfo * assignedInterface( void ); + virtual AsDevice * device( void ); + + ANetNodeInstance * netNode() + { return NNI; } + NodeCollection * connection() + { return NNI->connection(); } + + virtual void detectState( NodeCollection * NC ) = 0; + virtual bool setState( NodeCollection * NC, Action_t A ) = 0; + virtual bool canSetState( State_t Curr, Action_t A ) = 0; + +signals : + + // sent by device if state changes + void stateChanged( State_t S, ANetNodeInstance * NNI ); + +protected : + + // connection this runtime info belongs to + ANetNodeInstance * NNI; +}; + +class NodeCollection : public QList<ANetNodeInstance> { + +public : + + NodeCollection( void ); + NodeCollection( QTextStream & TS ); + ~NodeCollection( void ); + + int number( void ) + { return Number; } + void setNumber( int i ) + { Number = i; if( MaxNr < i ) MaxNr = i; } + bool isNew( void ) + { return IsNew; } + void setNew( bool N ) + { IsNew = N ; } + bool isModified( void ) + { return IsModified; } + void setModified( bool N ) + { IsModified = N ; } + + bool handlesInterface( const QString & S ) { + return getToplevel()->runtime()->handlesInterface( S ); + } + + InterfaceInfo * assignedInterface( void ) { + return getToplevel()->runtime()->assignedInterface(); + } + + AsDevice * device() { + return getToplevel()->runtime()->device(); + } + + State_t state( bool Update = 0 ) + { if( CurrentState == Unchecked || Update ) { + // need to get current state + getToplevel()->runtime()->detectState( this ); + } + return CurrentState; + } + + // get the ixmap for this device + QPixmap devicePixmap( void ); + QPixmap statePixmap( State_t S ); + QPixmap statePixmap( bool Update = 0 ) + { return statePixmap( state(Update) ); } + QString stateName( State_t ); + QString stateName( bool Update = 0 ) + { return stateName( state(Update) ); } + + bool setState( Action_t A ) + { return getToplevel()->runtime()->setState( this, A ); } + bool canSetState( Action_t A ) + { return getToplevel()->runtime()->canSetState( CurrentState, A ); } + + void save( QTextStream & TS ); + + void append( ANetNodeInstance * NNI ); + + // makes sure that all items in the connection point to + // that connectoin + void reassign( void ); + + ANetNodeInstance * getToplevel( void ); + ANetNodeInstance * findNext( ANetNodeInstance * NNI ); + ANetNodeInstance * findByName( const QString & S ); + + const QString & name() + { return Name; } + + const QString & description( void ); + + void setName( const QString & N) + { Name = N; } + + State_t currentState( void ) + { return CurrentState; } + void setCurrentState( State_t S ) + { CurrentState = S; } + + long maxConnectionNumber( void ) + { return MaxNr; } + + static void resetMaxNr( void ) + { MaxNr = -1; } + +private : + + int compareItems ( QCollection::Item item1, + QCollection::Item item2 ); + + static long MaxNr; + long Number; + + // state of this connection + State_t CurrentState; + + QString Name; + // true if this collection was just created (and not + // loaded from file + bool IsNew; + // index in listbox + int Index; + bool IsModified; + +}; + +#endif diff --git a/noncore/settings/networksettings2/networksettings2/networksettings2.pro b/noncore/settings/networksettings2/networksettings2/networksettings2.pro new file mode 100644 index 0000000..c9945ff --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/networksettings2.pro @@ -0,0 +1,26 @@ +TEMPLATE = lib +CONFIG += qt warn_on release +#CONFIG += qt warn_on debug +DESTDIR = $(OPIEDIR)/lib$(PROJMAK) +HEADERS = netnode.h \ + resources.h \ + system.h \ + asline.h \ + GUIUtils.h \ + asconnection.h \ + asfullsetup.h \ + systemfile.h \ + asdevice.h +SOURCES = netnode.cpp \ + GUIUtils.cpp \ + system.cpp \ + systemfile.cpp \ + resources.cpp +INCLUDEPATH += $(OPIEDIR)/include ../networksettings2 +DEPENDPATH += $(OPIEDIR)/include +LIBS += -lqpe -lopie +INTERFACES = +TARGET = networksettings2 +VERSION = 1.0.0 + +include ( $(OPIEDIR)/include.pro ) diff --git a/noncore/settings/networksettings2/networksettings2/resources.cpp b/noncore/settings/networksettings2/networksettings2/resources.cpp new file mode 100644 index 0000000..ff6e457 --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/resources.cpp @@ -0,0 +1,236 @@ +#include <qpixmap.h> +#include <qpe/qlibrary.h> +#include <qpe/qpeapplication.h> +#include <qdir.h> +#include <qtopia/resource.h> + +#include "netnode.h" +#include "resources.h" + +#define PLUGINDIR "plugins/networksettings2" +#define ICONDIR "/pics/networksettings2/" + +// single resources instance +TheNSResources * _NSResources = 0; + +TheNSResources::TheNSResources( void ) : NodeTypeNameMap(), + ConnectionsMap() { + + _NSResources = this; + + // load available netnodes + findAvailableNetNodes(QPEApplication::qpeDir() + PLUGINDIR ); + + // compile provides and needs lists + { const char ** NeedsRun; + QDictIterator<NetNode_t> OuterIt( AllNodeTypes ); + bool Done; + + for ( ; OuterIt.current(); ++OuterIt ) { + // find needs list + ANetNode::NetNodeList * NNLP = new ANetNode::NetNodeList; + ANetNode::NetNodeList & NNL = *(NNLP); + + // must iterate this way to avoid duplication pointers + for ( QDictIterator<NetNode_t> InnerIt( AllNodeTypes ); + InnerIt.current(); ++InnerIt ) { + if( InnerIt.current() == OuterIt.current() ) + // avoid recursive + continue; + + const char * Provides = InnerIt.current()->NetNode->provides(); + NeedsRun = OuterIt.current()->NetNode->needs(); + for( ; *NeedsRun; NeedsRun ++ ) { + if( strcmp( Provides, *NeedsRun ) == 0 ) { + // inner provides what outer needs + NNL.resize( NNL.size() + 1 ); + NNL[NNL.size()-1] = InnerIt.current()->NetNode; + Done = 1; // break from 2 loops + break; + } + } + } + OuterIt.current()->NetNode->setAlternatives( NNLP ); + } + } + + // define Node types to Description map + NodeTypeNameMap.insert( "device", tr( "Network Device" ) ); + NodeTypeNameMap.insert( "line", tr( "Character device" ) ); + NodeTypeNameMap.insert( "connection", tr( "IP Connection" ) ); + NodeTypeNameMap.insert( "fullsetup", tr( "Connection Profile" ) ); + + NodeTypeDescriptionMap.insert( "device", + tr( "<p>Devices that can handle IP packets</p>" ) ); + NodeTypeDescriptionMap.insert( "line", + tr( "<p>Devices that can handle single bytes</p>" ) ); + NodeTypeDescriptionMap.insert( "connection", + tr( "<p>Nodes that provide working IP connections</p>" ) ); + NodeTypeDescriptionMap.insert( "fullsetup", + tr( "<p>Fully configured connection profile</p>" ) ); + + // define system files + addSystemFile( new SystemFile( "interfaces", "./interfaces" ) ); + + // get access to the system + TheSystem = new System(); +} + +TheNSResources::~TheNSResources( void ) { + delete TheSystem; +} + +/** + * Load all modules that are found in the path + * @param path a directory that is scaned for any plugins that can be loaded + * and attempts to load them + */ +void TheNSResources::findAvailableNetNodes(const QString &path){ + + QDir d(path); + if(!d.exists()) + return; + + QString lang = ::getenv("LANG"); + + // Don't want sym links + d.setFilter( QDir::Files | QDir::NoSymLinks ); + const QFileInfoList *list = d.entryInfoList(); + QFileInfoListIterator it( *list ); + QFileInfo *fi; + + while ( (fi=it.current()) ) { + + if( fi->fileName().contains(".so")){ + /* if loaded install translation */ + if( loadNetNode(path + "/" + fi->fileName()) ) { + QTranslator *trans = new QTranslator(qApp); + QString fn = QPEApplication::qpeDir()+ + "/i18n/"+lang+"/"+ + fi->fileName().left( fi->fileName().find(".") )+ + ".qm"; + + if( trans->load( fn ) ) + qApp->installTranslator( trans ); + else + delete trans; + } + } + ++it; + } +} + +/** + * Attempt to load a function and resolve a function. + * @param pluginFileName - the name of the file in which to attempt to load + * @param resolveString - function pointer to resolve + * @return true of loading is successful + */ +bool TheNSResources::loadNetNode( + const QString &pluginFileName, const QString &resolveString){ + + QLibrary *lib = new QLibrary(pluginFileName); + void * res = lib->resolve(resolveString); + if( ! res ){ +#ifdef DEBUG + qDebug("loadNetNode: Warning: %s is not a plugin", pluginFileName.latin1()); +#endif + delete lib; + return 0; + } + + GetNetNodeListFt_t getNetNodeList = (GetNetNodeListFt_t)res; + + // Try to get an object. + QList<ANetNode> PNN; + + getNetNodeList( PNN ); + if( PNN.isEmpty() ) { +#ifdef DEBUG + qDebug("loadNetNode: Couldn't get node list, but did load library!"); +#endif + 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->nodeName(), NN ); + } + + return 1; +} + +QPixmap TheNSResources::getPixmap( const QString & QS ) { + return Resource::loadPixmap( QString("networksettings2")+QS ); +} + +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->nodeName() ) == 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->nodeName() ); + } + 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 ); + } +} diff --git a/noncore/settings/networksettings2/networksettings2/resources.h b/noncore/settings/networksettings2/networksettings2/resources.h new file mode 100644 index 0000000..cfa0b7a --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/resources.h @@ -0,0 +1,105 @@ +#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; + +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( ); + + System & system() + { return *TheSystem; } + + QPixmap getPixmap( const QString & Name ); + + Name2NetNode_t & netNodes( void ) + { return AllNodeTypes; } + bool netNodeExists( const QString & X ) + { return AllNodeTypes.find(X)!=0; } + + Name2SystemFile_t & systemFiles( void ) + { return SystemFiles; } + void addSystemFile( SystemFile * SF ) + { SystemFiles.insert( SF->name(), SF ); } + + ANetNodeInstance * createNodeInstance( const QString & S ) + { ANetNodeInstance * NNI = 0; + NetNode_t * NNT = AllNodeTypes[S]; + if( NNT ) { + NNI = NNT->NetNode->createInstance(); + NNI->initialize(); + } + return NNI; + } + + Name2Instance_t & netNodeInstances( void ) + { return AllNodes; } + void addNodeInstance( ANetNodeInstance * I ) + { AllNodes.insert( I->nodeName(), 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 renumberConnections( void ); + void addConnection( NodeCollection * NC ); + void removeConnection( const QString & N ); + NodeCollection * findConnection( const QString & N ); + Name2Connection_t & connections( void ) + { return ConnectionsMap; } + +private : + + 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; +}; + +extern TheNSResources * _NSResources; +#define NSResources _NSResources + +#endif diff --git a/noncore/settings/networksettings2/networksettings2/system.cpp b/noncore/settings/networksettings2/networksettings2/system.cpp new file mode 100644 index 0000000..99f642e --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/system.cpp @@ -0,0 +1,318 @@ +#include <stdlib.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <qfile.h> +#include <qtextstream.h> +#include <net/if.h> +#include <net/if_arp.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <sys/ioctl.h> +#include <sys/socket.h> + +#include "resources.h" +#include "system.h" + +#define PROCNETDEV "/proc/net/dev" + +static char Dig2Hex[] = { + '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F' +}; + +// get HIGH nibble of byte +#define HN(x) Dig2Hex[(((x)&0xf0)>>4)] +// get LOW nibble of byte +#define LN(x) Dig2Hex[((x)&0x0f)] + +System::System( void ) : ProbedInterfaces() { + probeInterfaces(); +} + +System::~System( void ) { + if( ProcDevNet ) + delete ProcDevNet; +} + +int System::execute( const QString & S ) { + QString MyS = S; + int rv; + + if( S.isEmpty() ) { + // loophole to start shell + return 8888; + } + if( getenv("USER") != "root" ) { + // use SUDO + MyS.prepend( "sudo " ); + } + + fprintf( stderr, "Executing %s\n", MyS.latin1() ); + + rv = system( MyS.latin1() ) ; + switch( rv ) { + case -1 : + // cannot fork + return 1; + case 127 : + // cannot start shell + return 2; + default : + if( WEXITSTATUS(rv) != 0 ) { + // error in command + return 3; + } + } + // all is fine + return 0; +} + +void System::refreshStatistics( InterfaceInfo & I ) { + if( ! ProcDevNet ) { + return; + } + // cannot seek on dev + ProcDevNet->close(); + ProcDevNet->open( IO_ReadOnly ); + + QString line; + QTextStream procTs(ProcDevNet); + QStringList SL; + int loc = -1; + int version; + + procTs.readLine(); + line = procTs.readLine(); + // get version + if( line.find("compressed") ) + version = 3; + else if( line.find( "bytes" ) ) + version = 2; + else + version = 1; + while((line = procTs.readLine().simplifyWhiteSpace()) != QString::null) { + if( (loc = line.find(":") ) == -1) { + 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 + fprintf( stderr, "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 ) { + fprintf( stderr, "%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 + fprintf( stderr, "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 = ""; + } + } +} diff --git a/noncore/settings/networksettings2/networksettings2/system.h b/noncore/settings/networksettings2/networksettings2/system.h new file mode 100644 index 0000000..f89fe5d --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/system.h @@ -0,0 +1,76 @@ +#ifndef __SYSTEM__H +#define __SYSTEM__H + +// for hardware types +#include <net/if_arp.h> +#include <qdict.h> + +class ANetNodeInstance; +class QFile; + +class InterfaceInfo { + +public : + + InterfaceInfo() : + Name(), + MACAddress(), + BCastAddress(), + Netmask(), + DstAddress() { + } + + ANetNodeInstance * assignedNode() + { return NetNode; } + + void assignNode( ANetNodeInstance * NNI ) + { NetNode = NNI; } + + ANetNodeInstance * NetNode; // netnode taking care of me + QString Name; // name of interface + int CardType; // type of card + QString MACAddress; // MAC address + QString Address; // IP Address + QString BCastAddress; // Broadcast Address + QString Netmask; // Netmask + QString DstAddress; // Peer address (if P-t-P) + bool IsUp; // interface is UP + bool HasMulticast; // Supports Multicast + bool IsPointToPoint; // IsPointToPoint card + + QString RcvBytes; + QString SndBytes; + QString RcvErrors; + QString SndErrors; + QString RcvDropped; + QString SndDropped; + QString Collisions; +}; + +class System { + +public : + + System( void ); + ~System( void ); + + QDict<InterfaceInfo> & interfaces( void ) + { return ProbedInterfaces; } + InterfaceInfo * interface( const QString& N ) + { return ProbedInterfaces[N]; } + + int execute( const QString & S ); + // refresh stats for this interface + void refreshStatistics( InterfaceInfo & ); + + // reloads interfaces + void probeInterfaces( void ); + +private : + + QDict<InterfaceInfo> ProbedInterfaces; + QFile * ProcDevNet; + +}; + +#endif diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.cpp b/noncore/settings/networksettings2/networksettings2/systemfile.cpp new file mode 100644 index 0000000..7249976 --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/systemfile.cpp @@ -0,0 +1,144 @@ +#include <stdio.h> +#include <qpe/qpeapplication.h> +#include <qfileinfo.h> +#include <qmessagebox.h> +#include <qfile.h> +#include <qtextstream.h> + +#include "resources.h" +#include "systemfile.h" + +#define TEMPLATEDIR "networktemplates/" +QString TemplDir; + +SystemFile::SystemFile( const QString & N, const QString & P ){ + Name = N; + Path = P; + F = 0; + // get template info + { QString S; + QFileInfo FI; + + // find location of templates + TemplDir = QPEApplication::qpeDir() + "etc/" + TEMPLATEDIR; + FI.setFile( TemplDir ); + if( ! FI.isDir() ) { + // try current dir + TemplDir = "./" TEMPLATEDIR; + FI.setFile( TemplDir ); + if( ! FI.isDir() ) { + hasPreSection = + hasPostSection = + hasPreNodeSection = + hasPostNodeSection = 0; + 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() ); + } +} + +SystemFile::~SystemFile( void ) { + if( F ) + delete F; +} + +bool SystemFile::open( void ) { + if( F ) { + F->close(); + delete F; + } + + F = new QFile( Path + "bup" ); + if( ! F->open( IO_WriteOnly ) ) { + return 0; + } + setDevice( F ); + return 1; +} + +bool SystemFile::close( void ) { + if( ! F ) { + return 1 ; + } + + QString OldP = Path + "bup"; + + F->close(); + delete F; + F = 0; + + return ( rename( OldP.latin1(), Path.latin1() ) >= 0 ); +} + +bool SystemFile::preSection( void ) { + if( hasPreSection ) { + QFile Fl( TemplDir + Name + "/presection" ); + if( ! Fl.open( IO_ReadOnly ) ) + return 1; // error + // copy file to this file + F->writeBlock( Fl.readAll() ); + } + return 0; +} + +bool SystemFile::postSection( void ) { + if( hasPostSection ) { + QFile Fl( TemplDir + Name + "/postsection" ); + if( ! Fl.open( IO_ReadOnly ) ) + return 1; // error + // copy file to this file + F->writeBlock( Fl.readAll() ); + } + return 0; +} + +bool SystemFile::preNodeSection( ANetNodeInstance * NNI, long ) { + if( hasPreNodeSection ) { + QFile Fl( TemplDir + Name + "/prenodesectoin" ); + if( ! Fl.open( IO_ReadOnly ) ) + return 1; // error + QTextStream TX( &Fl ); + QString Out; + QString S = TX.readLine(); + while( ! TX.eof() ) { + Out = S. + arg(NNI->netNode()->nodeName()); + (*this) << Out << endl; + S = TX.readLine(); + } + } + return 0; +} + +bool SystemFile::postNodeSection( ANetNodeInstance * NNI, long DevNr ) { + if( hasPostNodeSection ) { + QFile Fl( TemplDir + Name + "/postnodesectoin" ); + if( ! Fl.open( IO_ReadOnly ) ) + return 1; // error + QTextStream TX( &Fl ); + QString Out; + QString S = TX.readLine(); + while( ! TX.eof() ) { + Out = S. + arg(NNI->nodeName()); + (*this) << Out << endl; + S = TX.readLine(); + } + } + return 0; +} + diff --git a/noncore/settings/networksettings2/networksettings2/systemfile.h b/noncore/settings/networksettings2/networksettings2/systemfile.h new file mode 100644 index 0000000..8b6bcb9 --- a/dev/null +++ b/noncore/settings/networksettings2/networksettings2/systemfile.h @@ -0,0 +1,39 @@ +#ifndef __SYSTEMFILE__H +#define __SYSTEMFILE__H + +#include <qstring.h> +#include <qtextstream.h> + +class QFile; +class ANetNodeInstance; + +class SystemFile : public QTextStream { + +public : + + SystemFile( const QString & Name, const QString & Path ); + ~SystemFile( void ); + + const QString & name( void ) + { return Name; } + + bool open( void ); + bool close( void ); + + bool preSection( void ); + bool postSection( void ); + bool preNodeSection( ANetNodeInstance * NNI, long DevNr ); + bool postNodeSection( ANetNodeInstance * NNI, long DevNr ); + +private : + + QString Name; + QString Path; + QFile * F; + bool hasPreSection; + bool hasPreNodeSection; + bool hasPostSection; + bool hasPostNodeSection; + +}; +#endif |