summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/nsdata.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp152
1 files changed, 85 insertions, 67 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 ) {
95 FORMAT : 95 FORMAT :
96 96
97 [NETNODETYPE] 97 [NETNODETYPE]
98 Entries ... 98 Entries ...
99 <EMPTYLINE> 99 <EMPTYLINE>
100 [connection] 100 [connection]
101 Name=Name 101 Name=Name
102 Node=Name 102 Node=Name
103 <EMPTYLINE> 103 <EMPTYLINE>
104 */ 104 */
105 while( ! TS.atEnd() ) { 105 while( ! TS.atEnd() ) {
106 S = Line = TS.readLine(); 106 S = Line = TS.readLine();
107 107
108 if ( S.isEmpty() || S[0] != '[' ) 108 if ( S.isEmpty() || S[0] != '[' )
109 continue; 109 continue;
110 110
111 S = S.mid( 1, S.length()-2 ); 111 S = S.mid( 1, S.length()-2 );
112 112
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);
127 // try to find netnode 128 // try to find netnode
128 NN = NSResources->findNetNode( S ); 129 NN = NSResources->findNetNode( S );
129 } else { 130 } else {
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 );
136 } 137 do {
138 Line = TS.readLine();
139 // store even delimiter
140 LeftOvers.append( Line );
141 } while ( ! Line.isEmpty() );
142
143 //next section
144 continue;
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 ) { 151 if( S.isEmpty() ) {
142 if( S.isEmpty() ) { 152 // empty line
143 // empty line 153 break;
144 break; 154 }
145 } 155 idx = S.find( '=' );
146 idx = S.find( '=' ); 156 if( idx > 0 ) {
147 if( idx > 0 ) { 157 Attr = S.left( idx );
148 Attr = S.left( idx ); 158 Value = S.mid( idx+1, S.length() );
149 Value = S.mid( idx+1, S.length() ); 159 } else {
150 } else { 160 Value="";
151 Value=""; 161 Attr = S;
152 Attr = S; 162 }
153 }
154 163
155 Value.stripWhiteSpace(); 164 Value.stripWhiteSpace();
156 Attr.stripWhiteSpace(); 165 Attr.stripWhiteSpace();
157 Attr.lower(); 166 Attr.lower();
158 // dequote Attr 167 // dequote Attr
159 Value = deQuote(Value); 168 Value = deQuote(Value);
160 169
161 if( NN ) { 170 if( NN ) {
162 // set the attribute 171 // set the attribute
163 NN->setAttribute( Attr, Value ); 172 NN->setAttribute( Attr, Value );
164 } else {
165 // set the attribute
166 NNI->setAttribute( Attr, Value );
167 }
168 } else { 173 } else {
169 LeftOvers.append( Line ); 174 // set the attribute
170 // add empty line too as delimiter 175 NNI->setAttribute( Attr, Value );
171 if( S.isEmpty() ) {
172 // empty line
173 break;
174 }
175 } 176 }
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
190 } while( 0 ); 192 } while( 0 );
191 193
192} 194}
193 195
194QString NetworkSettingsData::saveSettings( void ) { 196QString NetworkSettingsData::saveSettings( void ) {
195 QString ErrS = ""; 197 QString ErrS = "";
196 198
197 if( ! isModified() ) 199 if( ! isModified() )
198 return ErrS; 200 return ErrS;
199 201
200 QString S; 202 QString S;
201 QFile F( CfgFile + ".bup" ); 203 QFile F( CfgFile + ".bup" );
202 204
203 Log( ( "Saving settings to %s\n", CfgFile.latin1() )); 205 Log( ( "Saving settings to %s\n", CfgFile.latin1() ));
204 if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { 206 if( ! F.open( IO_WriteOnly | IO_Truncate ) ) {
205 ErrS = qApp->translate( "NetworkSettings", 207 ErrS = qApp->translate( "NetworkSettings",
206 "<p>Could not save setup to \"%1\" !</p>" ). 208 "<p>Could not save setup to \"%1\" !</p>" ).
207 arg(CfgFile); 209 arg(CfgFile);
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
229 // save leftovers
230 for ( QStringList::Iterator it = LeftOvers.begin();
231 it != LeftOvers.end(); ++it ) {
232 TS << (*it) << endl;
233 }
234
235 // save all netnode instances
236 { ANetNodeInstance * NNI;
237 for( QDictIterator<ANetNodeInstance> nit(
238 NSResources->netNodeInstances());
239 nit.current();
240 ++nit ) {
241 // header
242 NNI = nit.current();
243 TS << '['
244 << QString(NNI->nodeClass()->name())
245 << ']'
246 << endl;
247 NNI->saveAttributes( TS );
248 TS << endl;
249 }
250 }
251
252 // good connections
233 { Name2Connection_t & M = NSResources->connections(); 253 { Name2Connection_t & M = NSResources->connections();
234 ANetNodeInstance * NNI;
235 254
236 // for all connections 255 // for all connections
237 for( QDictIterator<NodeCollection> it(M); 256 for( QDictIterator<NodeCollection> it(M);
238 it.current(); 257 it.current();
239 ++it ) { 258 ++it ) {
240 // all nodes in those connections 259 TS << "[connection]" << endl;
241 for( QListIterator<ANetNodeInstance> nit(*(it.current())); 260 it.current()->save(TS);
242 nit.current(); 261 }
243 ++nit ) { 262 }
244 // header
245 NNI = nit.current();
246 TS << '['
247 << QString(NNI->nodeClass()->name())
248 << ']'
249 << endl;
250 NNI->saveAttributes( TS );
251 TS << endl;
252 }
253 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(".");
260 D.rename( CfgFile + ".bup", CfgFile ); 277 D.rename( CfgFile + ".bup", CfgFile );
261 278
262 // 279 //
263 // proper files AND system files regenerated 280 // proper files AND system files regenerated
264 // 281 //
265 282
266 283
267 for( QDictIterator<NodeCollection> it(NSResources->connections()); 284 for( QDictIterator<NodeCollection> it(NSResources->connections());
268 it.current(); 285 it.current();
269 ++it ) { 286 ++it ) {
270 it.current()->setModified( 0 ); 287 it.current()->setModified( 0 );
271 } 288 }
272 289
273 return ErrS; 290 return ErrS;
274} 291}
275 292
276QString NetworkSettingsData::generateSettings( void ) { 293QString NetworkSettingsData::generateSettings( void ) {
277 QString S = ""; 294 QString S = "";
278 Name2SystemFile_t & SFM = NSResources->systemFiles(); 295 Name2SystemFile_t & SFM = NSResources->systemFiles();
279 Name2Connection_t & M = NSResources->connections(); 296 Name2Connection_t & M = NSResources->connections();
280 NodeCollection * NC; 297 NodeCollection * NC;
281 ANetNodeInstance * NNI; 298 ANetNodeInstance * NNI;
282 ANetNodeInstance * FirstWithData; 299 ANetNodeInstance * FirstWithData;
283 RuntimeInfo * CurDev; 300 RuntimeInfo * CurDev;
284 ANetNode * NN, * CurDevNN = 0; 301 ANetNode * NN, * CurDevNN = 0;
285 long NoOfDevs; 302 long NoOfDevs;
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; 312 bool FirstItem = 1;
296 bool FirstItem = 1; 313 bool Generated = 0;
297 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
306 Generated = 0; 324 Generated = 0;
307 FirstItem = 1; 325 FirstItem = 1;
308 // iterate over NNI's of this class 326 // iterate over NNI's of this class
309 for( QDictIterator<ANetNodeInstance> nniit( 327 for( QDictIterator<ANetNodeInstance> nniit(
310 NSResources->netNodeInstances() ); 328 NSResources->netNodeInstances() );
311 nniit.current(); 329 nniit.current();
312 ++nniit ) { 330 ++nniit ) {
313 if( nniit.current()->nodeClass() != CurDevNN ) 331 if( nniit.current()->nodeClass() != CurDevNN )
314 // different class 332 // different class
315 continue; 333 continue;
316 334
317 // open proper file 335 // open proper file
318 { SystemFile SF( (*it) ); 336 { SystemFile SF( (*it) );
319 337
320 if( ! CurDevNN->openFile( SF, nniit.current()) ) { 338 if( ! CurDevNN->openFile( SF, nniit.current()) ) {
321 // cannot open 339 // cannot open
322 S = qApp->translate( "NetworkSettings", 340 S = qApp->translate( "NetworkSettings",
323 "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). 341 "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ).
@@ -374,78 +392,78 @@ QString NetworkSettingsData::generateSettings( void ) {
374 if( CurDevNN->generatePostamble( SF ) == 2 ) { 392 if( CurDevNN->generatePostamble( SF ) == 2 ) {
375 S = qApp->translate( "NetworkSettings", 393 S = qApp->translate( "NetworkSettings",
376 "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). 394 "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ).
377 arg( (*it) ). 395 arg( (*it) ).
378 arg( CurDevNN->name() ); 396 arg( CurDevNN->name() );
379 return S; 397 return S;
380 } 398 }
381 } // no postamble 399 } // no postamble
382 } 400 }
383 } 401 }
384 } 402 }
385 } 403 }
386 404
387 // 405 //
388 // generate all registered files 406 // generate all registered files
389 // 407 //
390 for( QDictIterator<SystemFile> sfit(SFM); 408 for( QDictIterator<SystemFile> sfit(SFM);
391 sfit.current(); 409 sfit.current();
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 ) {
408 nniit.current()->setDone(0); 426 nniit.current()->setDone(0);
409 } 427 }
410 428
411 for( QDictIterator<NodeCollection> ncit(M); 429 for( QDictIterator<NodeCollection> ncit(M);
412 ncit.current(); 430 ncit.current();
413 ++ncit ) { 431 ++ncit ) {
414 ncit.current()->setDone(0); 432 ncit.current()->setDone(0);
415 } 433 }
416 434
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(
434 NSResources->netNodeInstances() ); 452 NSResources->netNodeInstances() );
435 ! needToGenerate && nniit.current(); 453 ! needToGenerate && nniit.current();
436 ++nniit ) { 454 ++nniit ) {
437 if( nniit.current()->nodeClass() == NN ) { 455 if( nniit.current()->nodeClass() == NN ) {
438 // yes 456 // yes
439 Log(("Node %s has data\n", 457 Log(("Node %s has data\n",
440 nniit.current()->name() )); 458 nniit.current()->name() ));
441 needToGenerate = 1; 459 needToGenerate = 1;
442 break; 460 break;
443 } 461 }
444 } 462 }
445 } 463 }
446 } 464 }
447 465
448 if( ! needToGenerate ) { 466 if( ! needToGenerate ) {
449 // no instances found that might need to write data 467 // no instances found that might need to write data
450 // in this systemfile 468 // in this systemfile
451 Log(("No nodes for systemfile %s\n", SF->name().latin1() )); 469 Log(("No nodes for systemfile %s\n", SF->name().latin1() ));