summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/nsdata.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp
index 13979ce..64b83f7 100644
--- a/noncore/settings/networksettings2/nsdata.cpp
+++ b/noncore/settings/networksettings2/nsdata.cpp
@@ -6,25 +6,25 @@
#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/NETCONFIG",
+ CfgFile.sprintf( "%s/Settings/NS2.conf",
NSResources->currentUser().HomeDir.latin1() );
fprintf( stderr, "Cfg from %s\n", CfgFile.latin1() );
// load settings
Force = 0;
IsModified = 0;
loadSettings();
}
// saving is done by caller
NetworkSettingsData::~NetworkSettingsData( void ) {
delete NSResources;
@@ -66,72 +66,79 @@ void NetworkSettingsData::loadSettings( void ) {
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-1 );
- fprintf( stderr, "Node %s\n", S.latin1() );
+ S = S.mid( 9, S.length()-9 );
+ S = deQuote(S);
// try to find netnode
NN = NSResources->findNetNode( S );
+ fprintf( stderr, "Node %s : %p\n", S.latin1(), NN );
} else {
// try to find instance
NNI = NSResources->createNodeInstance( S );
+ fprintf( stderr, "NodeInstance %s : %p\n", S.latin1(), NNI );
+ }
+
+ if( NN == 0 && NNI == 0 ) {
+ LeftOvers.append( Line );
}
do {
- S = TS.readLine();
+ 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
- NNI->setAttribute( Attr, Value );
+ 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 );
}
@@ -157,45 +164,49 @@ QString NetworkSettingsData::saveSettings( void ) {
// 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 "
- << it.current()->NetNode->name()
+ << 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 << '[' <<NNI->nodeClass()->nodeName() << ']' << endl;
+ 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 );
@@ -286,25 +297,25 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) {
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()->nodeName()) ;
+ arg(NNI->nodeClass()->name()) ;
return S;
}
}
}
}
//
// generate all system files
//
for( QDictIterator<SystemFile> sfit(SFM);
sfit.current();
++sfit ) {
@@ -381,30 +392,29 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) {
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
- fprintf( stderr, "check %s\n", NC->name().latin1() );
if( NC->handlesInterface( Interface ) && // if different Intf.
NC->state() != Disabled && // if not enabled
NC->state() != IsUp // if already used
) {
- fprintf( stderr, "Append %s\n", NC->name().latin1() );
+ fprintf( stderr, "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
*/
@@ -477,103 +487,96 @@ QString NetworkSettingsData::generateSystemFileNode(
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 preDeviceSection for file \"%1\" and nodetype \"%2\"</p>" ).
arg( SF.name() ).
- arg( CurDevNN->nodeName() );
+ arg( CurDevNN->name() );
return S;
}
if( CurDevNN->hasDataFor( SF.name() ) ) {
if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in node Device part for file \"%1\" and node \"%2\"</p>" ).
arg( SF.name() ).
- arg( CurDevNN->nodeName() );
+ arg( CurDevNN->name() );
return S;
}
}
- if( CurDev )
- fprintf( stderr, "Cur %s\n", CurDevNN->nodeName().latin1() );
- else
- fprintf( stderr, "Cur NO\n" );
-
// 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();
- fprintf( stderr, "%s\n", Dev->netNode()->nodeName().latin1() );
if( CurDev ) {
if( CurDevNN != Dev->netNode()->nodeClass() ) {
// other device type -> later
- fprintf( stderr, "Other Dev type\n" );
continue;
}
} else {
if( Dev ) {
// other
continue;
}
}
// generate 'entry'
if( SF.preNodeSection( DevNNI, DevInstNr ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in preNodeSection for file \"%1\" and node \"%2\"</p>" ).
arg( SF.name() ).
- arg( CurDevNN->nodeName() );
+ 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()->nodeName() );
+ arg( NNI->nodeClass()->name() );
return S;
}
}
}
if( SF.postNodeSection( DevNNI, DevInstNr ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in postNodeSection for file \"%1\" and node \"%2\"</p>" ).
arg( SF.name() ).
- arg( CurDevNN->nodeName() );
+ arg( CurDevNN->name() );
return S;
}
SF << endl;
}
if( SF.postDeviceSection( CurDevNN ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in postDeviceSection for file \"%1\" and node \"%2\"</p>" ).
arg( SF.name() ).
- arg( CurDevNN->nodeName() );
+ arg( CurDevNN->name() );
return S;
}
return S;
}