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.cpp49
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
@@ -6,25 +6,25 @@
6#include <qfileinfo.h> 6#include <qfileinfo.h>
7 7
8#include "nsdata.h" 8#include "nsdata.h"
9#include <asdevice.h> 9#include <asdevice.h>
10#include <resources.h> 10#include <resources.h>
11 11
12static QString CfgFile; 12static QString CfgFile;
13 13
14NetworkSettingsData::NetworkSettingsData( void ) { 14NetworkSettingsData::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}
27 27
28// saving is done by caller 28// saving is done by caller
29NetworkSettingsData::~NetworkSettingsData( void ) { 29NetworkSettingsData::~NetworkSettingsData( void ) {
30 delete NSResources; 30 delete NSResources;
@@ -66,72 +66,79 @@ void NetworkSettingsData::loadSettings( void ) {
66 if( ! NSResources ) { 66 if( ! NSResources ) {
67 continue; 67 continue;
68 } 68 }
69 69
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 ) {
97 Attr = S.left( idx ); 103 Attr = S.left( idx );
98 Value = S.mid( idx+1, S.length() ); 104 Value = S.mid( idx+1, S.length() );
99 } else { 105 } else {
100 Value=""; 106 Value="";
101 Attr = S; 107 Attr = S;
102 } 108 }
103 109
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
134 } while( 0 ); 141 } while( 0 );
135 142
136} 143}
137 144
@@ -157,45 +164,49 @@ QString NetworkSettingsData::saveSettings( void ) {
157 164
158 // save leftovers 165 // save leftovers
159 for ( QStringList::Iterator it = LeftOvers.begin(); 166 for ( QStringList::Iterator it = LeftOvers.begin();
160 it != LeftOvers.end(); ++it ) { 167 it != LeftOvers.end(); ++it ) {
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 }
198 209
199 QDir D("."); 210 QDir D(".");
200 D.rename( CfgFile + ".bup", CfgFile ); 211 D.rename( CfgFile + ".bup", CfgFile );
201 212
@@ -286,25 +297,25 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) {
286 for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); 297 for( QDictIterator<ANetNodeInstance> NNIIt(NNIs);
287 NNIIt.current(); 298 NNIIt.current();
288 ++NNIIt 299 ++NNIIt
289 ){ 300 ){
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
307 // 318 //
308 for( QDictIterator<SystemFile> sfit(SFM); 319 for( QDictIterator<SystemFile> sfit(SFM);
309 sfit.current(); 320 sfit.current();
310 ++sfit ) { 321 ++sfit ) {
@@ -381,30 +392,29 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) {
381QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { 392QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) {
382 // collect connections that can work on top of this interface 393 // collect connections that can work on top of this interface
383 NodeCollection * NC; 394 NodeCollection * NC;
384 QList<NodeCollection> PossibleConnections; 395 QList<NodeCollection> PossibleConnections;
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/*
407 Called by the system to see if interface can be brought UP 417 Called by the system to see if interface can be brought UP
408 418
409 if allowed, echo Interface-allowed else Interface-disallowed 419 if allowed, echo Interface-allowed else Interface-disallowed
410*/ 420*/
@@ -477,103 +487,96 @@ QString NetworkSettingsData::generateSystemFileNode(
477 AsDevice * CurDev, 487 AsDevice * CurDev,
478 ANetNodeInstance * DevNNI, 488 ANetNodeInstance * DevNNI,
479 long DevInstNr ) { 489 long DevInstNr ) {
480 490
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}