summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/nsdata.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp88
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
@@ -113,14 +113,15 @@ void NetworkSettingsData::loadSettings( void ) {
113 if( ! NSResources ) { 113 if( ! NSResources ) {
114 continue; 114 continue;
115 } 115 }
116 116
117 if( S == "connection" ) { 117 if( S == "connection" ) {
118 // load connections -> collections of nodes 118 // load connections -> collections of nodes
119 NodeCollection * NC = new NodeCollection( TS ); 119 bool Dangling;
120 NSResources->addConnection( NC ); 120 NodeCollection * NC = new NodeCollection( TS, Dangling );
121 NSResources->addConnection( NC, Dangling );
121 } else { 122 } else {
122 ANetNode * NN = 0; 123 ANetNode * NN = 0;
123 ANetNodeInstance* NNI = 0; 124 ANetNodeInstance* NNI = 0;
124 if( S.startsWith( "nodetype " ) ) { 125 if( S.startsWith( "nodetype " ) ) {
125 S = S.mid( 9, S.length()-9 ); 126 S = S.mid( 9, S.length()-9 );
126 S = deQuote(S); 127 S = deQuote(S);
@@ -130,18 +131,26 @@ void NetworkSettingsData::loadSettings( void ) {
130 // try to find instance 131 // try to find instance
131 NNI = NSResources->createNodeInstance( S ); 132 NNI = NSResources->createNodeInstance( S );
132 } 133 }
133 134
134 if( NN == 0 && NNI == 0 ) { 135 if( NN == 0 && NNI == 0 ) {
135 LeftOvers.append( Line ); 136 LeftOvers.append( Line );
137 do {
138 Line = TS.readLine();
139 // store even delimiter
140 LeftOvers.append( Line );
141 } while ( ! Line.isEmpty() );
142
143 //next section
144 continue;
136 } 145 }
137 146
147 // read entries of this section
138 do { 148 do {
139 S = Line = TS.readLine(); 149 S = Line = TS.readLine();
140 150
141 if( NN || NNI ) {
142 if( S.isEmpty() ) { 151 if( S.isEmpty() ) {
143 // empty line 152 // empty line
144 break; 153 break;
145 } 154 }
146 idx = S.find( '=' ); 155 idx = S.find( '=' );
147 if( idx > 0 ) { 156 if( idx > 0 ) {
@@ -162,28 +171,21 @@ void NetworkSettingsData::loadSettings( void ) {
162 // set the attribute 171 // set the attribute
163 NN->setAttribute( Attr, Value ); 172 NN->setAttribute( Attr, Value );
164 } else { 173 } else {
165 // set the attribute 174 // set the attribute
166 NNI->setAttribute( Attr, Value ); 175 NNI->setAttribute( Attr, Value );
167 } 176 }
168 } else {
169 LeftOvers.append( Line );
170 // add empty line too as delimiter
171 if( S.isEmpty() ) {
172 // empty line
173 break;
174 }
175 }
176 } while( 1 ); 177 } while( 1 );
177 178
178 if( NNI ) { 179 if( NNI ) {
179 // loading from file -> exists 180 // loading from file -> exists
180 Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); 181 Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI ));
181 NNI->setNew( FALSE ); 182 NNI->setNew( FALSE );
182 NSResources->addNodeInstance( NNI ); 183 NSResources->addNodeInstance( NNI );
183 } 184 }
185
184 if( NN ) { 186 if( NN ) {
185 Log( ( "Node %s : %p\n", NN->name(), NN ) ); 187 Log( ( "Node %s : %p\n", NN->name(), NN ) );
186 } 188 }
187 } 189 }
188 } 190 }
189 191
@@ -208,52 +210,67 @@ QString NetworkSettingsData::saveSettings( void ) {
208 // problem 210 // problem
209 return ErrS; 211 return ErrS;
210 } 212 }
211 213
212 QTextStream TS( &F ); 214 QTextStream TS( &F );
213 215
214 // save leftovers
215 for ( QStringList::Iterator it = LeftOvers.begin();
216 it != LeftOvers.end(); ++it ) {
217 TS << (*it) << endl;
218 }
219
220 // save global configs 216 // save global configs
221 for( QDictIterator<NetNode_t> it( NSResources->netNodes() ); 217 for( QDictIterator<ANetNode> it( NSResources->netNodes() );
222 it.current(); 218 it.current();
223 ++it ) { 219 ++it ) {
224 TS << "[nodetype " 220 TS << "[nodetype "
225 << quote( QString( it.current()->NetNode->name() ) ) 221 << quote( QString( it.current()->name() ) )
226 << "]" 222 << "]"
227 << endl; 223 << endl;
228 224
229 it.current()->NetNode->saveAttributes( TS ); 225 it.current()->saveAttributes( TS );
230 TS << endl; 226 TS << endl;
231 } 227 }
232 228
233 { Name2Connection_t & M = NSResources->connections(); 229 // save leftovers
234 ANetNodeInstance * NNI; 230 for ( QStringList::Iterator it = LeftOvers.begin();
231 it != LeftOvers.end(); ++it ) {
232 TS << (*it) << endl;
233 }
235 234
236 // for all connections 235 // save all netnode instances
237 for( QDictIterator<NodeCollection> it(M); 236 { ANetNodeInstance * NNI;
238 it.current(); 237 for( QDictIterator<ANetNodeInstance> nit(
239 ++it ) { 238 NSResources->netNodeInstances());
240 // all nodes in those connections
241 for( QListIterator<ANetNodeInstance> nit(*(it.current()));
242 nit.current(); 239 nit.current();
243 ++nit ) { 240 ++nit ) {
244 // header 241 // header
245 NNI = nit.current(); 242 NNI = nit.current();
246 TS << '[' 243 TS << '['
247 << QString(NNI->nodeClass()->name()) 244 << QString(NNI->nodeClass()->name())
248 << ']' 245 << ']'
249 << endl; 246 << endl;
250 NNI->saveAttributes( TS ); 247 NNI->saveAttributes( TS );
251 TS << endl; 248 TS << endl;
252 } 249 }
250 }
253 251
252 // good connections
253 { Name2Connection_t & M = NSResources->connections();
254
255 // for all connections
256 for( QDictIterator<NodeCollection> it(M);
257 it.current();
258 ++it ) {
259 TS << "[connection]" << endl;
260 it.current()->save(TS);
261 }
262 }
263
264 // save dangling connections
265 { Name2Connection_t & M = NSResources->danglingConnections();
266
267 // for all connections
268 for( QDictIterator<NodeCollection> it(M);
269 it.current();
270 ++it ) {
254 TS << "[connection]" << endl; 271 TS << "[connection]" << endl;
255 it.current()->save(TS); 272 it.current()->save(TS);
256 } 273 }
257 } 274 }
258 275
259 QDir D("."); 276 QDir D(".");
@@ -286,20 +303,21 @@ QString NetworkSettingsData::generateSettings( void ) {
286 long DevCtStart; 303 long DevCtStart;
287 bool needToGenerate; 304 bool needToGenerate;
288 305
289 // regenerate system files 306 // regenerate system files
290 Log( ( "Generating settings from %s\n", CfgFile.latin1() )); 307 Log( ( "Generating settings from %s\n", CfgFile.latin1() ));
291 308
292 for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); 309 for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
293 nnit.current(); 310 nnit.current();
294 ++nnit ) { 311 ++nnit ) {
295 { QStringList SL;
296 bool FirstItem = 1; 312 bool FirstItem = 1;
297 bool Generated = 0; 313 bool Generated = 0;
298 314
299 CurDevNN = nnit.current()->NetNode; 315 CurDevNN = nnit.current();
316
317 { QStringList SL;
300 SL = CurDevNN->properFiles(); 318 SL = CurDevNN->properFiles();
301 319
302 for ( QStringList::Iterator it = SL.begin(); 320 for ( QStringList::Iterator it = SL.begin();
303 it != SL.end(); 321 it != SL.end();
304 ++it ) { 322 ++it ) {
305 323
@@ -392,16 +410,16 @@ QString NetworkSettingsData::generateSettings( void ) {
392 ++sfit ) { 410 ++sfit ) {
393 SystemFile * SF; 411 SystemFile * SF;
394 412
395 SF = sfit.current(); 413 SF = sfit.current();
396 414
397 // reset all 415 // reset all
398 for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); 416 for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
399 nnit.current(); 417 nnit.current();
400 ++nnit ) { 418 ++nnit ) {
401 nnit.current()->NetNode->setDone(0); 419 nnit.current()->setDone(0);
402 } 420 }
403 421
404 for( QDictIterator<ANetNodeInstance> nniit( 422 for( QDictIterator<ANetNodeInstance> nniit(
405 NSResources->netNodeInstances() ); 423 NSResources->netNodeInstances() );
406 nniit.current(); 424 nniit.current();
407 ++nniit ) { 425 ++nniit ) {
@@ -417,17 +435,17 @@ QString NetworkSettingsData::generateSettings( void ) {
417 Log( ( "Generating system file %s\n", SF->name().latin1() )); 435 Log( ( "Generating system file %s\n", SF->name().latin1() ));
418 436
419 needToGenerate = 0; 437 needToGenerate = 0;
420 438
421 // are there netnodes that have instances and need 439 // are there netnodes that have instances and need
422 // to write data in this system file ? 440 // to write data in this system file ?
423 for( QDictIterator<NetNode_t> nnit( NSResources->netNodes() ); 441 for( QDictIterator<ANetNode> nnit( NSResources->netNodes() );
424 ! needToGenerate && nnit.current(); 442 ! needToGenerate && nnit.current();
425 ++nnit ) { 443 ++nnit ) {
426 444
427 NN = nnit.current()->NetNode; 445 NN = nnit.current();
428 446
429 if( NN->hasDataForFile( *SF ) ) { 447 if( NN->hasDataForFile( *SF ) ) {
430 // netnode can have data 448 // netnode can have data
431 449
432 // are there instances of this node ? 450 // are there instances of this node ?
433 for( QDictIterator<ANetNodeInstance> nniit( 451 for( QDictIterator<ANetNodeInstance> nniit(