Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 698a941..d76353a 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp @@ -95,229 +95,247 @@ void NetworkSettingsData::loadSettings( void ) { 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 ); + bool Dangling; + NodeCollection * NC = new NodeCollection( TS, Dangling ); + NSResources->addConnection( NC, Dangling ); } 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 ); } else { // try to find instance NNI = NSResources->createNodeInstance( S ); } if( NN == 0 && NNI == 0 ) { LeftOvers.append( Line ); + do { + Line = TS.readLine(); + // store even delimiter + LeftOvers.append( Line ); + } while ( ! Line.isEmpty() ); + + //next section + continue; } + // read entries of this section 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 Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); NNI->setNew( FALSE ); NSResources->addNodeInstance( NNI ); } + if( NN ) { Log( ( "Node %s : %p\n", NN->name(), NN ) ); } } } } 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() ); + for( QDictIterator<ANetNode> it( NSResources->netNodes() ); it.current(); ++it ) { TS << "[nodetype " - << quote( QString( it.current()->NetNode->name() ) ) + << quote( QString( it.current()->name() ) ) << "]" << endl; - it.current()->NetNode->saveAttributes( TS ); + it.current()->saveAttributes( TS ); TS << endl; } - { Name2Connection_t & M = NSResources->connections(); - ANetNodeInstance * NNI; + // save leftovers + for ( QStringList::Iterator it = LeftOvers.begin(); + it != LeftOvers.end(); ++it ) { + TS << (*it) << endl; + } - // for all connections - for( QDictIterator<NodeCollection> it(M); - it.current(); - ++it ) { - // all nodes in those connections - for( QListIterator<ANetNodeInstance> nit(*(it.current())); + // save all netnode instances + { ANetNodeInstance * NNI; + for( QDictIterator<ANetNodeInstance> nit( + NSResources->netNodeInstances()); nit.current(); ++nit ) { // header NNI = nit.current(); TS << '[' << QString(NNI->nodeClass()->name()) << ']' << endl; NNI->saveAttributes( TS ); TS << endl; } + } + // good connections + { Name2Connection_t & M = NSResources->connections(); + + // for all connections + for( QDictIterator<NodeCollection> it(M); + it.current(); + ++it ) { + TS << "[connection]" << endl; + it.current()->save(TS); + } + } + + // save dangling connections + { Name2Connection_t & M = NSResources->danglingConnections(); + + // for all connections + for( QDictIterator<NodeCollection> it(M); + it.current(); + ++it ) { TS << "[connection]" << endl; it.current()->save(TS); } } QDir D("."); D.rename( CfgFile + ".bup", CfgFile ); // // proper files AND system files regenerated // for( QDictIterator<NodeCollection> it(NSResources->connections()); it.current(); ++it ) { it.current()->setModified( 0 ); } return ErrS; } QString NetworkSettingsData::generateSettings( void ) { QString S = ""; Name2SystemFile_t & SFM = NSResources->systemFiles(); Name2Connection_t & M = NSResources->connections(); NodeCollection * NC; ANetNodeInstance * NNI; ANetNodeInstance * FirstWithData; RuntimeInfo * CurDev; ANetNode * NN, * CurDevNN = 0; long NoOfDevs; long DevCtStart; bool needToGenerate; // regenerate system files Log( ( "Generating settings from %s\n", CfgFile.latin1() )); - for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); + for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); nnit.current(); ++nnit ) { - { QStringList SL; bool FirstItem = 1; bool Generated = 0; - CurDevNN = nnit.current()->NetNode; + CurDevNN = nnit.current(); + + { QStringList SL; SL = CurDevNN->properFiles(); for ( QStringList::Iterator it = SL.begin(); it != SL.end(); ++it ) { Generated = 0; FirstItem = 1; // iterate over NNI's of this class for( QDictIterator<ANetNodeInstance> nniit( NSResources->netNodeInstances() ); nniit.current(); ++nniit ) { if( nniit.current()->nodeClass() != CurDevNN ) // different class continue; // open proper file { SystemFile SF( (*it) ); if( ! CurDevNN->openFile( SF, nniit.current()) ) { // cannot open S = qApp->translate( "NetworkSettings", "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). @@ -374,78 +392,78 @@ QString NetworkSettingsData::generateSettings( void ) { if( CurDevNN->generatePostamble( SF ) == 2 ) { S = qApp->translate( "NetworkSettings", "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). arg( (*it) ). arg( CurDevNN->name() ); return S; } } // no postamble } } } } // // generate all registered files // for( QDictIterator<SystemFile> sfit(SFM); sfit.current(); ++sfit ) { SystemFile * SF; SF = sfit.current(); // reset all - for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); + for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); nnit.current(); ++nnit ) { - nnit.current()->NetNode->setDone(0); + nnit.current()->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 system file %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() ); + for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); ! needToGenerate && nnit.current(); ++nnit ) { - NN = nnit.current()->NetNode; + NN = nnit.current(); if( NN->hasDataForFile( *SF ) ) { // 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; } } } } if( ! needToGenerate ) { // no instances found that might need to write data // in this systemfile Log(("No nodes for systemfile %s\n", SF->name().latin1() )); |