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.cpp327
1 files changed, 138 insertions, 189 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp
index 6541596..eb63e02 100644
--- a/noncore/settings/networksettings2/nsdata.cpp
+++ b/noncore/settings/networksettings2/nsdata.cpp
@@ -84,452 +84,296 @@ void NetworkSettingsData::loadSettings( void ) {
84 break; 84 break;
85 } 85 }
86 // node found ? 86 // node found ?
87 if( NNI ) { 87 if( NNI ) {
88 idx = S.find( '=' ); 88 idx = S.find( '=' );
89 if( idx > 0 ) { 89 if( idx > 0 ) {
90 Attr = S.left( idx ); 90 Attr = S.left( idx );
91 Value = S.mid( idx+1, S.length() ); 91 Value = S.mid( idx+1, S.length() );
92 } else { 92 } else {
93 Value=""; 93 Value="";
94 Attr = S; 94 Attr = S;
95 } 95 }
96 96
97 Value.stripWhiteSpace(); 97 Value.stripWhiteSpace();
98 Attr.stripWhiteSpace(); 98 Attr.stripWhiteSpace();
99 Attr.lower(); 99 Attr.lower();
100 // dequote Attr 100 // dequote Attr
101 Value = deQuote(Value); 101 Value = deQuote(Value);
102 102
103 // set the attribute 103 // set the attribute
104 NNI->setAttribute( Attr, Value ); 104 NNI->setAttribute( Attr, Value );
105 } 105 }
106 106
107 } while( 1 ); 107 } while( 1 );
108 if( NNI ) { 108 if( NNI ) {
109 // loading from file -> exists 109 // loading from file -> exists
110 NNI->setNew( FALSE ); 110 NNI->setNew( FALSE );
111 NSResources->addNodeInstance( NNI ); 111 NSResources->addNodeInstance( NNI );
112 } 112 }
113 } 113 }
114 } 114 }
115 115
116 } while( 0 ); 116 } while( 0 );
117 117
118} 118}
119 119
120QString NetworkSettingsData::saveSettings( void ) { 120QString NetworkSettingsData::saveSettings( void ) {
121 QString ErrS = ""; 121 QString ErrS = "";
122 122
123 if( ! isModified() ) 123 if( ! isModified() )
124 return ErrS; 124 return ErrS;
125 125
126 QString S; 126 QString S;
127 QFile F( CfgFile + ".bup" ); 127 QFile F( CfgFile + ".bup" );
128 128
129 printf( "Saving settings to %s\n", CfgFile.latin1() ); 129 printf( "Saving settings to %s\n", CfgFile.latin1() );
130 if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { 130 if( ! F.open( IO_WriteOnly | IO_Truncate ) ) {
131 ErrS = qApp->translate( "NetworkSettings", 131 ErrS = qApp->translate( "NetworkSettings",
132 "<p>Could not save setup to %1 !</p>" ). 132 "<p>Could not save setup to \"%1\" !</p>" ).
133 arg(CfgFile); 133 arg(CfgFile);
134 // problem 134 // problem
135 return ErrS; 135 return ErrS;
136 } 136 }
137 137
138 QTextStream TS( &F ); 138 QTextStream TS( &F );
139 { Name2Connection_t & M = NSResources->connections(); 139 { Name2Connection_t & M = NSResources->connections();
140 ANetNodeInstance * NNI; 140 ANetNodeInstance * NNI;
141 141
142 // for all connections 142 // for all connections
143 for( QDictIterator<NodeCollection> it(M); 143 for( QDictIterator<NodeCollection> it(M);
144 it.current(); 144 it.current();
145 ++it ) { 145 ++it ) {
146 // all nodes in those connections 146 // all nodes in those connections
147 for( QListIterator<ANetNodeInstance> nit(*(it.current())); 147 for( QListIterator<ANetNodeInstance> nit(*(it.current()));
148 nit.current(); 148 nit.current();
149 ++nit ) { 149 ++nit ) {
150 // header 150 // header
151 NNI = nit.current(); 151 NNI = nit.current();
152 TS << '[' <<NNI->netNode()->nodeName() << ']' << endl; 152 TS << '[' <<NNI->nodeClass()->nodeName() << ']' << endl;
153 NNI->saveAttributes( TS ); 153 NNI->saveAttributes( TS );
154 TS << endl; 154 TS << endl;
155 } 155 }
156 156
157 TS << "[connection]" << endl; 157 TS << "[connection]" << endl;
158 it.current()->save(TS); 158 it.current()->save(TS);
159 } 159 }
160 } 160 }
161 161
162 QDir D("."); 162 QDir D(".");
163 D.rename( CfgFile + ".bup", CfgFile ); 163 D.rename( CfgFile + ".bup", CfgFile );
164 164
165 // 165 //
166 // proper files AND system files regenerated 166 // proper files AND system files regenerated
167 // 167 //
168 168
169 setModified( 0 ); 169 setModified( 0 );
170 return ErrS; 170 return ErrS;
171} 171}
172 172
173QString NetworkSettingsData::generateSettings( bool ForceReq ) { 173QString NetworkSettingsData::generateSettings( bool ForceReq ) {
174 bool ForceIt; 174 bool ForceIt;
175 QString S = ""; 175 QString S = "";
176 176
177 // include own force flag 177 // include own force flag
178 ForceIt = (Force) ? 1 : ForceReq; 178 ForceIt = (Force) ? 1 : ForceReq;
179 179
180 if( ! ForceIt && ! isModified() ) 180 if( ! ForceIt && ! isModified() )
181 return S; 181 return S;
182 182
183 // regenerate system files 183 // regenerate system files
184 printf( "Generating settings from %s\n", CfgFile.latin1() ); 184 fprintf( stderr, "Generating settings from %s\n", CfgFile.latin1() );
185 185
186 { Name2SystemFile_t & SFM = NSResources->systemFiles(); 186 { Name2SystemFile_t & SFM = NSResources->systemFiles();
187 Name2Connection_t & M = NSResources->connections(); 187 Name2Connection_t & M = NSResources->connections();
188 NodeCollection * NC; 188 NodeCollection * NC;
189 ANetNodeInstance * NNI; 189 ANetNodeInstance * NNI;
190 SystemFile * SF; 190 SystemFile * SF;
191 AsDevice * CurDev; 191 AsDevice * CurDev;
192 ANetNode * CurDevNN;
192 bool needToRegenerate = ForceIt; 193 bool needToRegenerate = ForceIt;
193 194
194 // 195 //
195 // check if we need to generate at least one of the system files 196 // check if we need to generate at least one of the system files
196 // 197 //
197 if( ! ForceIt ) { 198 if( ! ForceIt ) {
198 for( QDictIterator<SystemFile> sfit(SFM); 199 for( QDictIterator<SystemFile> sfit(SFM);
199 sfit.current(); 200 sfit.current();
200 ++sfit ) { 201 ++sfit ) {
201 SF = sfit.current(); 202 SF = sfit.current();
202 203
203 // check if there are nodes that are modified and require 204 // check if there are nodes that are modified and require
204 // data for this system file 205 // data for this system file
205 206
206 // for all connections 207 // for all connections
207 for( QDictIterator<NodeCollection> ncit(M); 208 for( QDictIterator<NodeCollection> ncit(M);
208 ncit.current(); 209 ncit.current();
209 ++ncit ) { 210 ++ncit ) {
210 NC = ncit.current(); 211 NC = ncit.current();
211 212
212 if( NC->isModified() ) { 213 if( NC->isModified() ) {
213 // does this connection 'touch' this system file ? 214 // does this connection 'touch' this system file ?
214 for( QListIterator<ANetNodeInstance> cncit(*NC); 215 for( QListIterator<ANetNodeInstance> cncit(*NC);
215 cncit.current(); 216 cncit.current();
216 ++cncit ) { 217 ++cncit ) {
217 NNI = cncit.current(); 218 NNI = cncit.current();
218 if( ( NNI->netNode()->hasDataFor( SF->name(), 1 ) || 219 if( ( NNI->nodeClass()->hasDataFor( SF->name() ) ||
219 NNI->netNode()->hasDataFor( SF->name(), 0 ) 220 NNI->hasDataFor( SF->name() )
220 ) && 221 ) &&
221 NNI->isModified() ) { 222 NNI->isModified() ) {
222 needToRegenerate = 1; 223 needToRegenerate = 1;
223 break; 224 break;
224 } 225 }
225 } 226 }
226 } 227 }
227 if( needToRegenerate ) 228 if( needToRegenerate )
228 break; 229 break;
229 } 230 }
230 if( needToRegenerate ) 231 if( needToRegenerate )
231 break; 232 break;
232 } 233 }
233 } 234 }
234 235
235 // we cannot renumber with a FORCE request since 236 // we cannot renumber with a FORCE request since
236 // we probably are NOT going to save the config 237 // we probably are NOT going to save the config
237 // e.g. when using --regen option 238 // e.g. when using --regen option
238 if( ! ForceReq && needToRegenerate ) { 239 if( ! ForceReq && needToRegenerate ) {
239 NSResources->renumberConnections(); 240 NSResources->renumberConnections();
240 setModified(1); 241 setModified(1);
241 } 242 }
242 243
243 // 244 //
244 // generate files proper to each netnodeinstance 245 // generate files proper to each netnodeinstance
245 // 246 //
246 { Name2Instance_t & NNIs = NSResources->netNodeInstances(); 247 { Name2Instance_t & NNIs = NSResources->netNodeInstances();
247 248
248 for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); 249 for( QDictIterator<ANetNodeInstance> NNIIt(NNIs);
249 NNIIt.current(); 250 NNIIt.current();
250 ++NNIIt 251 ++NNIIt
251 ){ 252 ){
252 // for all nodes find those that are modified 253 // for all nodes find those that are modified
253 NNI = NNIIt.current(); 254 NNI = NNIIt.current();
254 255
255 if( ForceIt || NNI->isModified() ) { 256 if( ForceIt || NNI->isModified() ) {
256 if( ! NNI->netNode()->generateProperFilesFor( NNI ) ) { 257 if( ! NNI->nodeClass()->generateProperFilesFor( NNI ) ) {
257 // problem generating 258 // problem generating
258 S = qApp->translate( "NetworkSettings", 259 S = qApp->translate( "NetworkSettings",
259 "<p>Cannot generate files proper to %1</p>" ). 260 "<p>Cannot generate files proper to \"%1\"</p>" ).
260 arg(NNI->netNode()->nodeName()) ; 261 arg(NNI->nodeClass()->nodeName()) ;
261 return S; 262 return S;
262 } 263 }
263 } 264 }
264 } 265 }
265 } 266 }
266 267
267 // 268 //
268 // generate all system files 269 // generate all system files
269 // 270 //
270 for( QDictIterator<SystemFile> sfit(SFM); 271 for( QDictIterator<SystemFile> sfit(SFM);
271 sfit.current(); 272 sfit.current();
272 ++sfit ) { 273 ++sfit ) {
273 SF = sfit.current(); 274 SF = sfit.current();
274 275
275 printf( "Generating %s\n", SF->name().latin1() ); 276 fprintf( stderr, "Generating %s\n", SF->name().latin1() );
276 SF->open(); 277 SF->open();
277 278
278 do { // so we can break; 279 do { // so we can break;
279 280
280 // global presection for this system file 281 // global presection for this system file
281 if( SF->preSection() ) { 282 if( SF->preSection() ) {
282 S = qApp->translate( "NetworkSettings", 283 S = qApp->translate( "NetworkSettings",
283 "<p>Error in preSection for file %1</p>" ). 284 "<p>Error in preSection for file \"%1\"</p>" ).
284 arg( SF->name() ); 285 arg( SF->name() );
285 return S; 286 return S;
286 } 287 }
287 288
288 // find all netnodes and figure out if 289 // find all netnodes and figure out if
289 // for that node there are instances 290 // for that node there are instances
290 for( QDictIterator<NetNode_t> nnit( 291 for( QDictIterator<NetNode_t> nnit(
291 NSResources->netNodes() ); 292 NSResources->netNodes() );
292 nnit.current(); 293 nnit.current();
293 ++nnit ) { 294 ++nnit ) {
294 ANetNode * NN; 295
295 296 CurDevNN = nnit.current()->NetNode;
296 NN = nnit.current()->NetNode; 297
297 298 // are there instances for this netnode ?
298 // are there instances ? 299 NNI = 0;
299 NNI = 0; 300 for( QDictIterator<ANetNodeInstance> nniit(
300 for( QDictIterator<ANetNodeInstance> nniit( 301 NSResources->netNodeInstances() );
301 NSResources->netNodeInstances() ); 302 nniit.current();
302 nniit.current(); 303 ++nniit ) {
303 ++nniit ) { 304 if( nniit.current()->nodeClass() == CurDevNN ) {
304 if( nniit.current()->netNode() == NN ) { 305 NNI = nniit.current();
305 NNI = nniit.current(); 306 break;
306 break;
307 }
308 } 307 }
308 }
309 309
310 if( ! NNI ) 310 if( ! NNI )
311 // no instances 311 // no instances -> next netnode type
312 continue; 312 continue;
313 313
314 // has this node data for this system file ? 314 // has this node data for this system file ?
315 if( (CurDev = NNI->runtime()->asDevice() ) ) { 315 if( (CurDev = NNI->runtime()->asDevice() ) ) {
316 // generate start for this nodetype for all possible devices of this type 316 // generate start for this nodetype for all possible devices of this type
317 for( int i = 0; i < CurDev->count(); i ++ ) { 317 for( int i = 0; i < CurDevNN->instanceCount(); i ++ ) {
318 if( SF->preDeviceSection( NNI, i ) ) { 318 S = generateSystemFileNode( *SF, CurDev, NNI, i );
319 S = qApp->translate( "NetworkSettings", 319 if( ! S.isEmpty() )
320 "<p>Error in preDeviceSection for file %1 and node %2</p>" ).
321 arg( SF->name() ).
322 arg( NN->nodeName() );
323 return S;
324 }
325
326 if( ! NN->hasDataFor( SF->name(), 1 ) ) {
327 if( NN->generateDeviceDataForCommonFile( *SF, i, NNI ) ) {
328 S = qApp->translate( "NetworkSettings",
329 "<p>Error in node part for file %1 and node %2</p>" ).
330 arg( SF->name() ).
331 arg( NN->nodeName() );
332 return S;
333 }
334 }
335 }
336 } else {
337 // just request this once
338 if( SF->preDeviceSection( NNI, -1 ) ) {
339 S = qApp->translate( "NetworkSettings",
340 "<p>Error in preDeviceSection for file %1 and node %2</p>" ).
341 arg( SF->name() ).
342 arg( NN->nodeName() );
343 return S;
344 }
345
346 if( ! NN->hasDataFor( SF->name(), 1 ) ) {
347 if( NN->generateDeviceDataForCommonFile( *SF, -1, NNI ) ) {
348 S = qApp->translate( "NetworkSettings",
349 "<p>Error in node part for file %1 and node %2</p>" ).
350 arg( SF->name() ).
351 arg( NN->nodeName() );
352 return S;
353 }
354 }
355 }
356
357 // now generate profile specific data for all
358 // connections working on a device of the current
359 // netnode type
360 for( QDictIterator<NodeCollection> ncit(M);
361 ncit.current();
362 ++ncit ) {
363 NC = ncit.current();
364
365 NNI = NC->getToplevel();
366
367 // no output needed
368 if( ! NNI->netNode()->hasDataFor( SF->name(), 0 ) )
369 continue;
370
371 // get the netnode that serves as the device for this
372 // connection
373 AsDevice * Dev = NC->device();
374
375 if( CurDev ) {
376 if( CurDev != Dev ) {
377 // other device -> later
378 continue;
379 }
380
381 // generate 'entry' for every combination of device and profile
382 // each node delegates to deeper level
383 for( int i = 0; i < CurDev->count(); i ++ ) {
384 if( SF->preNodeSection( NNI, i ) ) {
385 S = qApp->translate( "NetworkSettings",
386 "<p>Error in preNodeSection for file %1 and node %2</p>" ).
387 arg( SF->name() ).
388 arg( NNI->netNode()->nodeName() );
389 return S;
390 }
391
392 // ask all nodes in connection
393
394 for( QListIterator<ANetNodeInstance> cncit(*NC);
395 cncit.current();
396 ++cncit ) {
397 NNI = cncit.current();
398
399 if( NNI->netNode()->hasDataFor( SF->name(), 0 ) ) {
400 if( NNI->netNode()->generateDataForCommonFile(*SF,i,NNI) ) {
401 S = qApp->translate( "NetworkSettings",
402 "<p>Error in node part for file %1 and node %2</p>" ).
403 arg( SF->name() ).
404 arg( NNI->netNode()->nodeName() );
405 return S;
406 }
407 }
408 }
409
410 if( SF->postNodeSection( NNI, i ) ) {
411 S = qApp->translate( "NetworkSettings",
412 "<p>Error in postNodeSection for file %1 and node %2</p>" ).
413 arg( SF->name() ).
414 arg( NNI->netNode()->nodeName() );
415 return S;
416 }
417 }
418
419 } else {
420 if( Dev ) {
421 // other
422 continue;
423 }
424
425 // one entry to generate
426 if( SF->preNodeSection( NNI, -1 ) ) {
427 S = qApp->translate( "NetworkSettings",
428 "<p>Error in preNodeSection for file %1 and node %2</p>" ).
429 arg( SF->name() ).
430 arg( NNI->netNode()->nodeName() );
431 return S;
432 }
433
434 if( NNI->netNode()->generateDataForCommonFile(*SF,-1,NNI) ) {
435 S = qApp->translate( "NetworkSettings",
436 "<p>Error in node part for file %1 and node %2</p>" ).
437 arg( SF->name() ).
438 arg( NNI->netNode()->nodeName() );
439 return S;
440 }
441
442 if( SF->postNodeSection( NNI, -1 ) ) {
443 S = qApp->translate( "NetworkSettings",
444 "<p>Error in postNodeSection for file %1 and node %2</p>" ).
445 arg( SF->name() ).
446 arg( NNI->netNode()->nodeName() );
447 return S;
448 }
449 }
450
451 // generated some data
452 if( SF->postNodeSection( NNI, -1 ) ) {
453 S = qApp->translate( "NetworkSettings",
454 "<p>Error in postNodeSection for file %1 and node %2</p>" ).
455 arg( SF->name() ).
456 arg( NNI->netNode()->nodeName() );
457 return S;
458 }
459 *SF << endl;
460 }
461
462 if( CurDev ) {
463 // generate 'entry' for every combination of device and profile
464 // each node delegates to deeper level
465 for( int i = 0; i < CurDev->count(); i ++ ) {
466 if( SF->postDeviceSection( NNI, i ) ) {
467 S = qApp->translate( "NetworkSettings",
468 "<p>Error in postDeviceSection for file %1 and node %2</p>" ).
469 arg( SF->name() ).
470 arg( NNI->netNode()->nodeName() );
471 return S; 320 return S;
472 }
473 } 321 }
474 } else { 322 } else {
475 if( SF->postDeviceSection( NNI, -1 ) ) { 323 S = generateSystemFileNode( *SF, 0, NNI, -1 );
476 S = qApp->translate( "NetworkSettings", 324 if( ! S.isEmpty() )
477 "<p>Error in postDeviceSection for file %1 and node %2</p>" ).
478 arg( SF->name() ).
479 arg( NNI->netNode()->nodeName() );
480 return S; 325 return S;
481 }
482 } 326 }
483 } 327 }
484 328
485 if( SF->postSection() ) { 329 if( SF->postSection() ) {
486 S = qApp->translate( "NetworkSettings", 330 S = qApp->translate( "NetworkSettings",
487 "<p>Error in postSection for file %1</p>" ). 331 "<p>Error in postSection for file \"%1\"</p>" ).
488 arg( SF->name() ); 332 arg( SF->name() );
489 return S; 333 return S;
490 } 334 }
491 335
492 } while( 0 ); 336 } while( 0 );
493 SF->close(); 337 SF->close();
494 } 338 }
495 } 339 }
496 Force = 0; 340 Force = 0;
497 return S; 341 return S;
498} 342}
499 343
500QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { 344QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) {
501 // collect connections that can work on top of this interface 345 // collect connections that can work on top of this interface
502 NodeCollection * NC; 346 NodeCollection * NC;
503 QList<NodeCollection> PossibleConnections; 347 QList<NodeCollection> PossibleConnections;
504 Name2Connection_t & M = NSResources->connections(); 348 Name2Connection_t & M = NSResources->connections();
505 349
506 // for all connections 350 // for all connections
507 for( QDictIterator<NodeCollection> it(M); 351 for( QDictIterator<NodeCollection> it(M);
508 it.current(); 352 it.current();
509 ++it ) { 353 ++it ) {
510 NC = it.current(); 354 NC = it.current();
511 // check if this profile handles the requested interface 355 // check if this profile handles the requested interface
512 if( NC->handlesInterface( Interface ) && // if different Intf. 356 if( NC->handlesInterface( Interface ) && // if different Intf.
513 NC->state() != Disabled && // if not enabled 357 NC->state() != Disabled && // if not enabled
514 NC->state() != IsUp // if already used 358 NC->state() != IsUp // if already used
515 ) { 359 ) {
516 PossibleConnections.append( NC ); 360 PossibleConnections.append( NC );
517 } 361 }
518 } 362 }
519 return PossibleConnections; 363 return PossibleConnections;
520} 364}
521 365
522 366
523/* 367/*
524 Called by the system to see if interface can be brought UP 368 Called by the system to see if interface can be brought UP
525 369
526 if allowed, echo Interface-allowed else Interface-disallowed 370 if allowed, echo Interface-allowed else Interface-disallowed
527*/ 371*/
528 372
529void NetworkSettingsData::canStart( const char * Interface ) { 373void NetworkSettingsData::canStart( const char * Interface ) {
530 // load situation 374 // load situation
531 NodeCollection * NC = 0; 375 NodeCollection * NC = 0;
532 QList<NodeCollection> PossibleConnections; 376 QList<NodeCollection> PossibleConnections;
533 377
534 PossibleConnections = collectPossible( Interface ); 378 PossibleConnections = collectPossible( Interface );
535 379
@@ -544,48 +388,153 @@ void NetworkSettingsData::canStart( const char * Interface ) {
544 // system( "su %d networksettings2 --prompt %s\n", 388 // system( "su %d networksettings2 --prompt %s\n",
545 // "", Interface ); 389 // "", Interface );
546 break; 390 break;
547 } 391 }
548 392
549 if( NC ) { 393 if( NC ) {
550 switch( NC->state() ) { 394 switch( NC->state() ) {
551 case Unchecked : 395 case Unchecked :
552 case Unknown : 396 case Unknown :
553 case Unavailable : 397 case Unavailable :
554 case Disabled : 398 case Disabled :
555 // this profile does not allow interface to be UP 399 // this profile does not allow interface to be UP
556 // -> try others 400 // -> try others
557 break; 401 break;
558 case Off : 402 case Off :
559 // try to UP the device 403 // try to UP the device
560 if( ! NC->setState( Activate ) ) { 404 if( ! NC->setState( Activate ) ) {
561 // cannot bring device Online -> try other alters 405 // cannot bring device Online -> try other alters
562 break; 406 break;
563 } 407 }
564 // FT 408 // FT
565 case Available : 409 case Available :
566 case IsUp : // also called for 'ifdown' 410 case IsUp : // also called for 'ifdown'
567 // device is ready -> done 411 // device is ready -> done
568 printf( "%s-c%d-allowed\n", Interface, NC->number() ); 412 printf( "%s-c%d-allowed\n", Interface, NC->number() );
569 return; 413 return;
570 } 414 }
571 } else { 415 } else {
572 // if we come here no alternatives are possible 416 // if we come here no alternatives are possible
573 printf( "%s-cnn-disallowed\n", Interface ); 417 printf( "%s-cnn-disallowed\n", Interface );
574 } 418 }
575} 419}
576 420
577/* 421/*
578 Called by the system to regenerate config files 422 Called by the system to regenerate config files
579*/ 423*/
580 424
581bool NetworkSettingsData::regenerate( void ) { 425bool NetworkSettingsData::regenerate( void ) {
582 QString S; 426 QString S;
583 // load situation 427 // load situation
584 S = generateSettings( TRUE ); 428 S = generateSettings( TRUE );
585 if( ! S.isEmpty() ) { 429 if( ! S.isEmpty() ) {
586 fprintf( stdout, "%s\n", S.latin1() ); 430 fprintf( stdout, "%s\n", S.latin1() );
587 return 1; 431 return 1;
588 } 432 }
589 return 0; 433 return 0;
590} 434}
591 435
436QString NetworkSettingsData::generateSystemFileNode(
437 SystemFile &SF,
438 AsDevice * CurDev,
439 ANetNodeInstance * DevNNI,
440 long DevInstNr ) {
441
442 QString S="";
443 ANetNode * CurDevNN = DevNNI->nodeClass();
444 Name2Connection_t & M = NSResources->connections();
445
446 if( SF.preDeviceSection( CurDevNN ) ) {
447 S = qApp->translate( "NetworkSettings",
448 "<p>Error in preDeviceSection for file \"%1\" and nodetype \"%2\"</p>" ).
449 arg( SF.name() ).
450 arg( CurDevNN->nodeName() );
451 return S;
452 }
453
454 if( CurDevNN->hasDataFor( SF.name() ) ) {
455 if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) {
456 S = qApp->translate( "NetworkSettings",
457 "<p>Error in node Device part for file \"%1\" and node \"%2\"</p>" ).
458 arg( SF.name() ).
459 arg( CurDevNN->nodeName() );
460 return S;
461 }
462 }
463
464 if( CurDev )
465 fprintf( stderr, "Cur %s\n", CurDevNN->nodeName().latin1() );
466 else
467 fprintf( stderr, "Cur NO\n" );
468
469 // now generate profile specific data for all
470 // connections working on a device of the current
471 // netnode type
472 for( QDictIterator<NodeCollection> ncit(M);
473 ncit.current();
474 ++ncit ) {
475 NodeCollection * NC = ncit.current();
476
477 // currenly only those connections that work on
478 // the current device (or on no device if no current)
479 AsDevice * Dev = NC->device();
480
481 fprintf( stderr, "%s\n", Dev->netNode()->nodeName().latin1() );
482 if( CurDev ) {
483 if( CurDevNN != Dev->netNode()->nodeClass() ) {
484 // other device type -> later
485 fprintf( stderr, "Other Dev type\n" );
486 continue;
487 }
488 } else {
489 if( Dev ) {
490 // other
491 continue;
492 }
493 }
494
495 // generate 'entry'
496 if( SF.preNodeSection( DevNNI, DevInstNr ) ) {
497 S = qApp->translate( "NetworkSettings",
498 "<p>Error in preNodeSection for file \"%1\" and node \"%2\"</p>" ).
499 arg( SF.name() ).
500 arg( CurDevNN->nodeName() );
501 return S;
502 }
503
504 // ask all nodes in connection
505 for( QListIterator<ANetNodeInstance> cncit(*NC);
506 cncit.current();
507 ++cncit ) {
508 ANetNodeInstance * NNI = cncit.current();
509
510 if( NNI->hasDataFor( SF.name() ) ) {
511 if( NNI->generateDataForCommonFile(SF,DevInstNr) ) {
512 S = qApp->translate( "NetworkSettings",
513 "<p>Error in node part for file \"%1\" and node \"%2\"</p>" ).
514 arg( SF.name() ).
515 arg( NNI->nodeClass()->nodeName() );
516 return S;
517 }
518 }
519 }
520
521 if( SF.postNodeSection( DevNNI, DevInstNr ) ) {
522 S = qApp->translate( "NetworkSettings",
523 "<p>Error in postNodeSection for file \"%1\" and node \"%2\"</p>" ).
524 arg( SF.name() ).
525 arg( CurDevNN->nodeName() );
526 return S;
527 }
528 SF << endl;
529 }
530
531 if( SF.postDeviceSection( CurDevNN ) ) {
532 S = qApp->translate( "NetworkSettings",
533 "<p>Error in postDeviceSection for file \"%1\" and node \"%2\"</p>" ).
534 arg( SF.name() ).
535 arg( CurDevNN->nodeName() );
536 return S;
537 }
538
539 return S;
540}