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.cpp67
1 files changed, 51 insertions, 16 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp
index b4d9aaa..13979ce 100644
--- a/noncore/settings/networksettings2/nsdata.cpp
+++ b/noncore/settings/networksettings2/nsdata.cpp
@@ -28,14 +28,13 @@ NetworkSettingsData::NetworkSettingsData( void ) {
// saving is done by caller
NetworkSettingsData::~NetworkSettingsData( void ) {
delete NSResources;
}
void NetworkSettingsData::loadSettings( void ) {
- QString S;
- ANetNodeInstance* NNI;
+ QString Line, S;
QString Attr, Value;
long idx;
QFile F( CfgFile );
QTextStream TS( &F );
@@ -54,13 +53,13 @@ void NetworkSettingsData::loadSettings( void ) {
[connection]
Name=Name
Node=Name
<EMPTYLINE>
*/
while( ! TS.atEnd() ) {
- S = TS.readLine();
+ S = Line = TS.readLine();
if ( S.isEmpty() || S[0] != '[' )
continue;
S = S.mid( 1, S.length()-2 );
@@ -70,26 +69,32 @@ void NetworkSettingsData::loadSettings( void ) {
if( S == "connection" ) {
// load connections -> collections of nodes
NodeCollection * NC = new NodeCollection( TS );
NSResources->addConnection( NC );
} else {
- // load nodes
- NNI = NSResources->createNodeInstance( S );
- if( ! NNI ) {
- printf( "SKIPPING %s\n", S.latin1() );
+ 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() );
+ // try to find netnode
+ NN = NSResources->findNetNode( S );
+ } else {
+ // try to find instance
+ NNI = NSResources->createNodeInstance( S );
}
do {
S = TS.readLine();
- if( S.isEmpty() ) {
- // empty line
- break;
- }
- // node found ?
- if( NNI ) {
+
+ 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="";
@@ -99,16 +104,27 @@ void NetworkSettingsData::loadSettings( void ) {
Value.stripWhiteSpace();
Attr.stripWhiteSpace();
Attr.lower();
// dequote Attr
Value = deQuote(Value);
- // set the attribute
- NNI->setAttribute( Attr, Value );
+ if( NN ) {
+ // set the attribute
+ NNI->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 );
}
@@ -135,12 +151,31 @@ QString NetworkSettingsData::saveSettings( void ) {
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 "
+ << it.current()->NetNode->name()
+ << "]"
+ << endl;
+
+ it.current()->NetNode->saveAttributes( TS );
+ }
+
{ Name2Connection_t & M = NSResources->connections();
ANetNodeInstance * NNI;
// for all connections
for( QDictIterator<NodeCollection> it(M);
it.current();