Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index 13979ce..64b83f7 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -10,17 +10,17 @@ | |||
10 | #include <resources.h> | 10 | #include <resources.h> |
11 | 11 | ||
12 | static QString CfgFile; | 12 | static QString CfgFile; |
13 | 13 | ||
14 | NetworkSettingsData::NetworkSettingsData( void ) { | 14 | NetworkSettingsData::NetworkSettingsData( void ) { |
15 | // init global resources structure | 15 | // init global resources structure |
16 | new TheNSResources(); | 16 | new TheNSResources(); |
17 | 17 | ||
18 | CfgFile.sprintf( "%s/NETCONFIG", | 18 | CfgFile.sprintf( "%s/Settings/NS2.conf", |
19 | NSResources->currentUser().HomeDir.latin1() ); | 19 | NSResources->currentUser().HomeDir.latin1() ); |
20 | fprintf( stderr, "Cfg from %s\n", CfgFile.latin1() ); | 20 | fprintf( stderr, "Cfg from %s\n", CfgFile.latin1() ); |
21 | 21 | ||
22 | // load settings | 22 | // load settings |
23 | Force = 0; | 23 | Force = 0; |
24 | IsModified = 0; | 24 | IsModified = 0; |
25 | loadSettings(); | 25 | loadSettings(); |
26 | } | 26 | } |
@@ -70,27 +70,33 @@ void NetworkSettingsData::loadSettings( void ) { | |||
70 | if( S == "connection" ) { | 70 | if( S == "connection" ) { |
71 | // load connections -> collections of nodes | 71 | // load connections -> collections of nodes |
72 | NodeCollection * NC = new NodeCollection( TS ); | 72 | NodeCollection * NC = new NodeCollection( TS ); |
73 | NSResources->addConnection( NC ); | 73 | NSResources->addConnection( NC ); |
74 | } else { | 74 | } else { |
75 | ANetNode * NN = 0; | 75 | ANetNode * NN = 0; |
76 | ANetNodeInstance* NNI = 0; | 76 | ANetNodeInstance* NNI = 0; |
77 | if( S.startsWith( "nodetype " ) ) { | 77 | if( S.startsWith( "nodetype " ) ) { |
78 | S = S.mid( 9, S.length()-9-1 ); | 78 | S = S.mid( 9, S.length()-9 ); |
79 | fprintf( stderr, "Node %s\n", S.latin1() ); | 79 | S = deQuote(S); |
80 | // try to find netnode | 80 | // try to find netnode |
81 | NN = NSResources->findNetNode( S ); | 81 | NN = NSResources->findNetNode( S ); |
82 | fprintf( stderr, "Node %s : %p\n", S.latin1(), NN ); | ||
82 | } else { | 83 | } else { |
83 | // try to find instance | 84 | // try to find instance |
84 | NNI = NSResources->createNodeInstance( S ); | 85 | NNI = NSResources->createNodeInstance( S ); |
86 | fprintf( stderr, "NodeInstance %s : %p\n", S.latin1(), NNI ); | ||
87 | } | ||
88 | |||
89 | if( NN == 0 && NNI == 0 ) { | ||
90 | LeftOvers.append( Line ); | ||
85 | } | 91 | } |
86 | 92 | ||
87 | do { | 93 | do { |
88 | S = TS.readLine(); | 94 | S = Line = TS.readLine(); |
89 | 95 | ||
90 | if( NN || NNI ) { | 96 | if( NN || NNI ) { |
91 | if( S.isEmpty() ) { | 97 | if( S.isEmpty() ) { |
92 | // empty line | 98 | // empty line |
93 | break; | 99 | break; |
94 | } | 100 | } |
95 | idx = S.find( '=' ); | 101 | idx = S.find( '=' ); |
96 | if( idx > 0 ) { | 102 | if( idx > 0 ) { |
@@ -104,30 +110,31 @@ void NetworkSettingsData::loadSettings( void ) { | |||
104 | Value.stripWhiteSpace(); | 110 | Value.stripWhiteSpace(); |
105 | Attr.stripWhiteSpace(); | 111 | Attr.stripWhiteSpace(); |
106 | Attr.lower(); | 112 | Attr.lower(); |
107 | // dequote Attr | 113 | // dequote Attr |
108 | Value = deQuote(Value); | 114 | Value = deQuote(Value); |
109 | 115 | ||
110 | if( NN ) { | 116 | if( NN ) { |
111 | // set the attribute | 117 | // set the attribute |
112 | NNI->setAttribute( Attr, Value ); | 118 | NN->setAttribute( Attr, Value ); |
113 | } else { | 119 | } else { |
114 | // set the attribute | 120 | // set the attribute |
115 | NNI->setAttribute( Attr, Value ); | 121 | NNI->setAttribute( Attr, Value ); |
116 | } | 122 | } |
117 | } else { | 123 | } else { |
118 | LeftOvers.append( Line ); | 124 | LeftOvers.append( Line ); |
119 | // add empty line too as delimiter | 125 | // add empty line too as delimiter |
120 | if( S.isEmpty() ) { | 126 | if( S.isEmpty() ) { |
121 | // empty line | 127 | // empty line |
122 | break; | 128 | break; |
123 | } | 129 | } |
124 | } | 130 | } |
125 | } while( 1 ); | 131 | } while( 1 ); |
132 | |||
126 | if( NNI ) { | 133 | if( NNI ) { |
127 | // loading from file -> exists | 134 | // loading from file -> exists |
128 | NNI->setNew( FALSE ); | 135 | NNI->setNew( FALSE ); |
129 | NSResources->addNodeInstance( NNI ); | 136 | NSResources->addNodeInstance( NNI ); |
130 | } | 137 | } |
131 | } | 138 | } |
132 | } | 139 | } |
133 | 140 | ||
@@ -161,37 +168,41 @@ QString NetworkSettingsData::saveSettings( void ) { | |||
161 | TS << (*it) << endl; | 168 | TS << (*it) << endl; |
162 | } | 169 | } |
163 | 170 | ||
164 | // save global configs | 171 | // save global configs |
165 | for( QDictIterator<NetNode_t> it( NSResources->netNodes() ); | 172 | for( QDictIterator<NetNode_t> it( NSResources->netNodes() ); |
166 | it.current(); | 173 | it.current(); |
167 | ++it ) { | 174 | ++it ) { |
168 | TS << "[nodetype " | 175 | TS << "[nodetype " |
169 | << it.current()->NetNode->name() | 176 | << quote( QString( it.current()->NetNode->name() ) ) |
170 | << "]" | 177 | << "]" |
171 | << endl; | 178 | << endl; |
172 | 179 | ||
173 | it.current()->NetNode->saveAttributes( TS ); | 180 | it.current()->NetNode->saveAttributes( TS ); |
181 | TS << endl; | ||
174 | } | 182 | } |
175 | 183 | ||
176 | { Name2Connection_t & M = NSResources->connections(); | 184 | { Name2Connection_t & M = NSResources->connections(); |
177 | ANetNodeInstance * NNI; | 185 | ANetNodeInstance * NNI; |
178 | 186 | ||
179 | // for all connections | 187 | // for all connections |
180 | for( QDictIterator<NodeCollection> it(M); | 188 | for( QDictIterator<NodeCollection> it(M); |
181 | it.current(); | 189 | it.current(); |
182 | ++it ) { | 190 | ++it ) { |
183 | // all nodes in those connections | 191 | // all nodes in those connections |
184 | for( QListIterator<ANetNodeInstance> nit(*(it.current())); | 192 | for( QListIterator<ANetNodeInstance> nit(*(it.current())); |
185 | nit.current(); | 193 | nit.current(); |
186 | ++nit ) { | 194 | ++nit ) { |
187 | // header | 195 | // header |
188 | NNI = nit.current(); | 196 | NNI = nit.current(); |
189 | TS << '[' <<NNI->nodeClass()->nodeName() << ']' << endl; | 197 | TS << '[' |
198 | << QString(NNI->nodeClass()->name()) | ||
199 | << ']' | ||
200 | << endl; | ||
190 | NNI->saveAttributes( TS ); | 201 | NNI->saveAttributes( TS ); |
191 | TS << endl; | 202 | TS << endl; |
192 | } | 203 | } |
193 | 204 | ||
194 | TS << "[connection]" << endl; | 205 | TS << "[connection]" << endl; |
195 | it.current()->save(TS); | 206 | it.current()->save(TS); |
196 | } | 207 | } |
197 | } | 208 | } |
@@ -290,17 +301,17 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { | |||
290 | // for all nodes find those that are modified | 301 | // for all nodes find those that are modified |
291 | NNI = NNIIt.current(); | 302 | NNI = NNIIt.current(); |
292 | 303 | ||
293 | if( ForceIt || NNI->isModified() ) { | 304 | if( ForceIt || NNI->isModified() ) { |
294 | if( ! NNI->nodeClass()->generateProperFilesFor( NNI ) ) { | 305 | if( ! NNI->nodeClass()->generateProperFilesFor( NNI ) ) { |
295 | // problem generating | 306 | // problem generating |
296 | S = qApp->translate( "NetworkSettings", | 307 | S = qApp->translate( "NetworkSettings", |
297 | "<p>Cannot generate files proper to \"%1\"</p>" ). | 308 | "<p>Cannot generate files proper to \"%1\"</p>" ). |
298 | arg(NNI->nodeClass()->nodeName()) ; | 309 | arg(NNI->nodeClass()->name()) ; |
299 | return S; | 310 | return S; |
300 | } | 311 | } |
301 | } | 312 | } |
302 | } | 313 | } |
303 | } | 314 | } |
304 | 315 | ||
305 | // | 316 | // |
306 | // generate all system files | 317 | // generate all system files |
@@ -385,22 +396,21 @@ QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interfa | |||
385 | Name2Connection_t & M = NSResources->connections(); | 396 | Name2Connection_t & M = NSResources->connections(); |
386 | 397 | ||
387 | // for all connections | 398 | // for all connections |
388 | for( QDictIterator<NodeCollection> it(M); | 399 | for( QDictIterator<NodeCollection> it(M); |
389 | it.current(); | 400 | it.current(); |
390 | ++it ) { | 401 | ++it ) { |
391 | NC = it.current(); | 402 | NC = it.current(); |
392 | // check if this profile handles the requested interface | 403 | // check if this profile handles the requested interface |
393 | fprintf( stderr, "check %s\n", NC->name().latin1() ); | ||
394 | if( NC->handlesInterface( Interface ) && // if different Intf. | 404 | if( NC->handlesInterface( Interface ) && // if different Intf. |
395 | NC->state() != Disabled && // if not enabled | 405 | NC->state() != Disabled && // if not enabled |
396 | NC->state() != IsUp // if already used | 406 | NC->state() != IsUp // if already used |
397 | ) { | 407 | ) { |
398 | fprintf( stderr, "Append %s\n", NC->name().latin1() ); | 408 | fprintf( stderr, "Append %s for %s\n", NC->name().latin1(), Interface); |
399 | PossibleConnections.append( NC ); | 409 | PossibleConnections.append( NC ); |
400 | } | 410 | } |
401 | } | 411 | } |
402 | return PossibleConnections; | 412 | return PossibleConnections; |
403 | } | 413 | } |
404 | 414 | ||
405 | 415 | ||
406 | /* | 416 | /* |
@@ -481,99 +491,92 @@ QString NetworkSettingsData::generateSystemFileNode( | |||
481 | QString S=""; | 491 | QString S=""; |
482 | ANetNode * CurDevNN = DevNNI->nodeClass(); | 492 | ANetNode * CurDevNN = DevNNI->nodeClass(); |
483 | Name2Connection_t & M = NSResources->connections(); | 493 | Name2Connection_t & M = NSResources->connections(); |
484 | 494 | ||
485 | if( SF.preDeviceSection( CurDevNN ) ) { | 495 | if( SF.preDeviceSection( CurDevNN ) ) { |
486 | S = qApp->translate( "NetworkSettings", | 496 | S = qApp->translate( "NetworkSettings", |
487 | "<p>Error in preDeviceSection for file \"%1\" and nodetype \"%2\"</p>" ). | 497 | "<p>Error in preDeviceSection for file \"%1\" and nodetype \"%2\"</p>" ). |
488 | arg( SF.name() ). | 498 | arg( SF.name() ). |
489 | arg( CurDevNN->nodeName() ); | 499 | arg( CurDevNN->name() ); |
490 | return S; | 500 | return S; |
491 | } | 501 | } |
492 | 502 | ||
493 | if( CurDevNN->hasDataFor( SF.name() ) ) { | 503 | if( CurDevNN->hasDataFor( SF.name() ) ) { |
494 | if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) { | 504 | if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) { |
495 | S = qApp->translate( "NetworkSettings", | 505 | S = qApp->translate( "NetworkSettings", |
496 | "<p>Error in node Device part for file \"%1\" and node \"%2\"</p>" ). | 506 | "<p>Error in node Device part for file \"%1\" and node \"%2\"</p>" ). |
497 | arg( SF.name() ). | 507 | arg( SF.name() ). |
498 | arg( CurDevNN->nodeName() ); | 508 | arg( CurDevNN->name() ); |
499 | return S; | 509 | return S; |
500 | } | 510 | } |
501 | } | 511 | } |
502 | 512 | ||
503 | if( CurDev ) | ||
504 | fprintf( stderr, "Cur %s\n", CurDevNN->nodeName().latin1() ); | ||
505 | else | ||
506 | fprintf( stderr, "Cur NO\n" ); | ||
507 | |||
508 | // now generate profile specific data for all | 513 | // now generate profile specific data for all |
509 | // connections working on a device of the current | 514 | // connections working on a device of the current |
510 | // netnode type | 515 | // netnode type |
511 | for( QDictIterator<NodeCollection> ncit(M); | 516 | for( QDictIterator<NodeCollection> ncit(M); |
512 | ncit.current(); | 517 | ncit.current(); |
513 | ++ncit ) { | 518 | ++ncit ) { |
514 | NodeCollection * NC = ncit.current(); | 519 | NodeCollection * NC = ncit.current(); |
515 | 520 | ||
516 | // currenly only those connections that work on | 521 | // currenly only those connections that work on |
517 | // the current device (or on no device if no current) | 522 | // the current device (or on no device if no current) |
518 | AsDevice * Dev = NC->device(); | 523 | AsDevice * Dev = NC->device(); |
519 | 524 | ||
520 | fprintf( stderr, "%s\n", Dev->netNode()->nodeName().latin1() ); | ||
521 | if( CurDev ) { | 525 | if( CurDev ) { |
522 | if( CurDevNN != Dev->netNode()->nodeClass() ) { | 526 | if( CurDevNN != Dev->netNode()->nodeClass() ) { |
523 | // other device type -> later | 527 | // other device type -> later |
524 | fprintf( stderr, "Other Dev type\n" ); | ||
525 | continue; | 528 | continue; |
526 | } | 529 | } |
527 | } else { | 530 | } else { |
528 | if( Dev ) { | 531 | if( Dev ) { |
529 | // other | 532 | // other |
530 | continue; | 533 | continue; |
531 | } | 534 | } |
532 | } | 535 | } |
533 | 536 | ||
534 | // generate 'entry' | 537 | // generate 'entry' |
535 | if( SF.preNodeSection( DevNNI, DevInstNr ) ) { | 538 | if( SF.preNodeSection( DevNNI, DevInstNr ) ) { |
536 | S = qApp->translate( "NetworkSettings", | 539 | S = qApp->translate( "NetworkSettings", |
537 | "<p>Error in preNodeSection for file \"%1\" and node \"%2\"</p>" ). | 540 | "<p>Error in preNodeSection for file \"%1\" and node \"%2\"</p>" ). |
538 | arg( SF.name() ). | 541 | arg( SF.name() ). |
539 | arg( CurDevNN->nodeName() ); | 542 | arg( CurDevNN->name() ); |
540 | return S; | 543 | return S; |
541 | } | 544 | } |
542 | 545 | ||
543 | // ask all nodes in connection | 546 | // ask all nodes in connection |
544 | for( QListIterator<ANetNodeInstance> cncit(*NC); | 547 | for( QListIterator<ANetNodeInstance> cncit(*NC); |
545 | cncit.current(); | 548 | cncit.current(); |
546 | ++cncit ) { | 549 | ++cncit ) { |
547 | ANetNodeInstance * NNI = cncit.current(); | 550 | ANetNodeInstance * NNI = cncit.current(); |
548 | 551 | ||
549 | if( NNI->hasDataFor( SF.name() ) ) { | 552 | if( NNI->hasDataFor( SF.name() ) ) { |
550 | if( NNI->generateDataForCommonFile(SF,DevInstNr) ) { | 553 | if( NNI->generateDataForCommonFile(SF,DevInstNr) ) { |
551 | S = qApp->translate( "NetworkSettings", | 554 | S = qApp->translate( "NetworkSettings", |
552 | "<p>Error in node part for file \"%1\" and node \"%2\"</p>" ). | 555 | "<p>Error in node part for file \"%1\" and node \"%2\"</p>" ). |
553 | arg( SF.name() ). | 556 | arg( SF.name() ). |
554 | arg( NNI->nodeClass()->nodeName() ); | 557 | arg( NNI->nodeClass()->name() ); |
555 | return S; | 558 | return S; |
556 | } | 559 | } |
557 | } | 560 | } |
558 | } | 561 | } |
559 | 562 | ||
560 | if( SF.postNodeSection( DevNNI, DevInstNr ) ) { | 563 | if( SF.postNodeSection( DevNNI, DevInstNr ) ) { |
561 | S = qApp->translate( "NetworkSettings", | 564 | S = qApp->translate( "NetworkSettings", |
562 | "<p>Error in postNodeSection for file \"%1\" and node \"%2\"</p>" ). | 565 | "<p>Error in postNodeSection for file \"%1\" and node \"%2\"</p>" ). |
563 | arg( SF.name() ). | 566 | arg( SF.name() ). |
564 | arg( CurDevNN->nodeName() ); | 567 | arg( CurDevNN->name() ); |
565 | return S; | 568 | return S; |
566 | } | 569 | } |
567 | SF << endl; | 570 | SF << endl; |
568 | } | 571 | } |
569 | 572 | ||
570 | if( SF.postDeviceSection( CurDevNN ) ) { | 573 | if( SF.postDeviceSection( CurDevNN ) ) { |
571 | S = qApp->translate( "NetworkSettings", | 574 | S = qApp->translate( "NetworkSettings", |
572 | "<p>Error in postDeviceSection for file \"%1\" and node \"%2\"</p>" ). | 575 | "<p>Error in postDeviceSection for file \"%1\" and node \"%2\"</p>" ). |
573 | arg( SF.name() ). | 576 | arg( SF.name() ). |
574 | arg( CurDevNN->nodeName() ); | 577 | arg( CurDevNN->name() ); |
575 | return S; | 578 | return S; |
576 | } | 579 | } |
577 | 580 | ||
578 | return S; | 581 | return S; |
579 | } | 582 | } |