Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index bb37f10..3b17548 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -8,25 +8,25 @@ | |||
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 | ||
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/Settings/NS2.conf", | 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 | Log(( "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 |
29 | NetworkSettingsData::~NetworkSettingsData( void ) { | 29 | NetworkSettingsData::~NetworkSettingsData( void ) { |
30 | delete NSResources; | 30 | delete NSResources; |
31 | } | 31 | } |
32 | 32 | ||
@@ -70,29 +70,29 @@ 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 ); | 78 | S = S.mid( 9, S.length()-9 ); |
79 | S = deQuote(S); | 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 | Log( ( "Node %s : %p\n", S.latin1(), NN ) ); |
83 | } else { | 83 | } else { |
84 | // try to find instance | 84 | // try to find instance |
85 | NNI = NSResources->createNodeInstance( S ); | 85 | NNI = NSResources->createNodeInstance( S ); |
86 | fprintf( stderr, "NodeInstance %s : %p\n", S.latin1(), NNI ); | 86 | Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI )); |
87 | } | 87 | } |
88 | 88 | ||
89 | if( NN == 0 && NNI == 0 ) { | 89 | if( NN == 0 && NNI == 0 ) { |
90 | LeftOvers.append( Line ); | 90 | LeftOvers.append( Line ); |
91 | } | 91 | } |
92 | 92 | ||
93 | do { | 93 | do { |
94 | S = Line = TS.readLine(); | 94 | S = Line = TS.readLine(); |
95 | 95 | ||
96 | if( NN || NNI ) { | 96 | if( NN || NNI ) { |
97 | if( S.isEmpty() ) { | 97 | if( S.isEmpty() ) { |
98 | // empty line | 98 | // empty line |
@@ -142,25 +142,25 @@ void NetworkSettingsData::loadSettings( void ) { | |||
142 | 142 | ||
143 | } | 143 | } |
144 | 144 | ||
145 | QString NetworkSettingsData::saveSettings( void ) { | 145 | QString NetworkSettingsData::saveSettings( void ) { |
146 | QString ErrS = ""; | 146 | QString ErrS = ""; |
147 | 147 | ||
148 | if( ! isModified() ) | 148 | if( ! isModified() ) |
149 | return ErrS; | 149 | return ErrS; |
150 | 150 | ||
151 | QString S; | 151 | QString S; |
152 | QFile F( CfgFile + ".bup" ); | 152 | QFile F( CfgFile + ".bup" ); |
153 | 153 | ||
154 | printf( "Saving settings to %s\n", CfgFile.latin1() ); | 154 | Log( ( "Saving settings to %s\n", CfgFile.latin1() )); |
155 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { | 155 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { |
156 | ErrS = qApp->translate( "NetworkSettings", | 156 | ErrS = qApp->translate( "NetworkSettings", |
157 | "<p>Could not save setup to \"%1\" !</p>" ). | 157 | "<p>Could not save setup to \"%1\" !</p>" ). |
158 | arg(CfgFile); | 158 | arg(CfgFile); |
159 | // problem | 159 | // problem |
160 | return ErrS; | 160 | return ErrS; |
161 | } | 161 | } |
162 | 162 | ||
163 | QTextStream TS( &F ); | 163 | QTextStream TS( &F ); |
164 | 164 | ||
165 | // save leftovers | 165 | // save leftovers |
166 | for ( QStringList::Iterator it = LeftOvers.begin(); | 166 | for ( QStringList::Iterator it = LeftOvers.begin(); |
@@ -220,25 +220,25 @@ QString NetworkSettingsData::saveSettings( void ) { | |||
220 | 220 | ||
221 | QString NetworkSettingsData::generateSettings( bool ForceReq ) { | 221 | QString NetworkSettingsData::generateSettings( bool ForceReq ) { |
222 | bool ForceIt; | 222 | bool ForceIt; |
223 | QString S = ""; | 223 | QString S = ""; |
224 | 224 | ||
225 | // include own force flag | 225 | // include own force flag |
226 | ForceIt = (Force) ? 1 : ForceReq; | 226 | ForceIt = (Force) ? 1 : ForceReq; |
227 | 227 | ||
228 | if( ! ForceIt && ! isModified() ) | 228 | if( ! ForceIt && ! isModified() ) |
229 | return S; | 229 | return S; |
230 | 230 | ||
231 | // regenerate system files | 231 | // regenerate system files |
232 | fprintf( stderr, "Generating settings from %s\n", CfgFile.latin1() ); | 232 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); |
233 | 233 | ||
234 | { Name2SystemFile_t & SFM = NSResources->systemFiles(); | 234 | { Name2SystemFile_t & SFM = NSResources->systemFiles(); |
235 | Name2Connection_t & M = NSResources->connections(); | 235 | Name2Connection_t & M = NSResources->connections(); |
236 | NodeCollection * NC; | 236 | NodeCollection * NC; |
237 | ANetNodeInstance * NNI; | 237 | ANetNodeInstance * NNI; |
238 | SystemFile * SF; | 238 | SystemFile * SF; |
239 | AsDevice * CurDev; | 239 | AsDevice * CurDev; |
240 | ANetNode * CurDevNN; | 240 | ANetNode * CurDevNN; |
241 | bool needToRegenerate = ForceIt; | 241 | bool needToRegenerate = ForceIt; |
242 | 242 | ||
243 | // | 243 | // |
244 | // check if we need to generate at least one of the system files | 244 | // check if we need to generate at least one of the system files |
@@ -272,32 +272,24 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { | |||
272 | break; | 272 | break; |
273 | } | 273 | } |
274 | } | 274 | } |
275 | } | 275 | } |
276 | if( needToRegenerate ) | 276 | if( needToRegenerate ) |
277 | break; | 277 | break; |
278 | } | 278 | } |
279 | if( needToRegenerate ) | 279 | if( needToRegenerate ) |
280 | break; | 280 | break; |
281 | } | 281 | } |
282 | } | 282 | } |
283 | 283 | ||
284 | // we cannot renumber with a FORCE request since | ||
285 | // we probably are NOT going to save the config | ||
286 | // e.g. when using --regen option | ||
287 | if( ! ForceReq && needToRegenerate ) { | ||
288 | NSResources->renumberConnections(); | ||
289 | setModified(1); | ||
290 | } | ||
291 | |||
292 | // | 284 | // |
293 | // generate files proper to each netnodeinstance | 285 | // generate files proper to each netnodeinstance |
294 | // | 286 | // |
295 | { Name2Instance_t & NNIs = NSResources->netNodeInstances(); | 287 | { Name2Instance_t & NNIs = NSResources->netNodeInstances(); |
296 | 288 | ||
297 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); | 289 | for( QDictIterator<ANetNodeInstance> NNIIt(NNIs); |
298 | NNIIt.current(); | 290 | NNIIt.current(); |
299 | ++NNIIt | 291 | ++NNIIt |
300 | ){ | 292 | ){ |
301 | // for all nodes find those that are modified | 293 | // for all nodes find those that are modified |
302 | NNI = NNIIt.current(); | 294 | NNI = NNIIt.current(); |
303 | 295 | ||
@@ -312,25 +304,25 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { | |||
312 | } | 304 | } |
313 | } | 305 | } |
314 | } | 306 | } |
315 | 307 | ||
316 | // | 308 | // |
317 | // generate all system files | 309 | // generate all system files |
318 | // | 310 | // |
319 | for( QDictIterator<SystemFile> sfit(SFM); | 311 | for( QDictIterator<SystemFile> sfit(SFM); |
320 | sfit.current(); | 312 | sfit.current(); |
321 | ++sfit ) { | 313 | ++sfit ) { |
322 | SF = sfit.current(); | 314 | SF = sfit.current(); |
323 | 315 | ||
324 | fprintf( stderr, "Generating %s\n", SF->name().latin1() ); | 316 | Log( ( "Generating %s\n", SF->name().latin1() )); |
325 | SF->open(); | 317 | SF->open(); |
326 | 318 | ||
327 | do { // so we can break; | 319 | do { // so we can break; |
328 | 320 | ||
329 | // global presection for this system file | 321 | // global presection for this system file |
330 | if( SF->preSection() ) { | 322 | if( SF->preSection() ) { |
331 | S = qApp->translate( "NetworkSettings", | 323 | S = qApp->translate( "NetworkSettings", |
332 | "<p>Error in preSection for file \"%1\"</p>" ). | 324 | "<p>Error in preSection for file \"%1\"</p>" ). |
333 | arg( SF->name() ); | 325 | arg( SF->name() ); |
334 | return S; | 326 | return S; |
335 | } | 327 | } |
336 | 328 | ||
@@ -396,47 +388,46 @@ QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interfa | |||
396 | Name2Connection_t & M = NSResources->connections(); | 388 | Name2Connection_t & M = NSResources->connections(); |
397 | 389 | ||
398 | // for all connections | 390 | // for all connections |
399 | for( QDictIterator<NodeCollection> it(M); | 391 | for( QDictIterator<NodeCollection> it(M); |
400 | it.current(); | 392 | it.current(); |
401 | ++it ) { | 393 | ++it ) { |
402 | NC = it.current(); | 394 | NC = it.current(); |
403 | // check if this profile handles the requested interface | 395 | // check if this profile handles the requested interface |
404 | if( NC->handlesInterface( Interface ) && // if different Intf. | 396 | if( NC->handlesInterface( Interface ) && // if different Intf. |
405 | NC->state() != Disabled && // if not enabled | 397 | NC->state() != Disabled && // if not enabled |
406 | NC->state() != IsUp // if already used | 398 | NC->state() != IsUp // if already used |
407 | ) { | 399 | ) { |
408 | fprintf( stderr, "Append %s for %s\n", NC->name().latin1(), Interface); | 400 | Log( ( "Append %s for %s\n", NC->name().latin1(), Interface)); |
409 | PossibleConnections.append( NC ); | 401 | PossibleConnections.append( NC ); |
410 | } | 402 | } |
411 | } | 403 | } |
412 | return PossibleConnections; | 404 | return PossibleConnections; |
413 | } | 405 | } |
414 | 406 | ||
415 | 407 | ||
416 | /* | 408 | /* |
417 | Called by the system to see if interface can be brought UP | 409 | Called by the system to see if interface can be brought UP |
418 | 410 | ||
419 | if allowed, echo Interface-allowed else Interface-disallowed | 411 | if allowed, echo Interface-allowed else Interface-disallowed |
420 | */ | 412 | */ |
421 | 413 | ||
422 | bool NetworkSettingsData::canStart( const char * Interface ) { | 414 | bool NetworkSettingsData::canStart( const char * Interface ) { |
423 | // load situation | 415 | // load situation |
424 | NodeCollection * NC = 0; | 416 | NodeCollection * NC = 0; |
425 | QList<NodeCollection> PossibleConnections; | 417 | QList<NodeCollection> PossibleConnections; |
426 | 418 | ||
427 | PossibleConnections = collectPossible( Interface ); | 419 | PossibleConnections = collectPossible( Interface ); |
428 | 420 | ||
429 | fprintf( stderr, "Possiblilies %d\n", | 421 | Log( ( "Possiblilies %d\n", PossibleConnections.count() )); |
430 | PossibleConnections.count() ); | ||
431 | switch( PossibleConnections.count() ) { | 422 | switch( PossibleConnections.count() ) { |
432 | case 0 : // no connections | 423 | case 0 : // no connections |
433 | break; | 424 | break; |
434 | case 1 : // one connection | 425 | case 1 : // one connection |
435 | NC = PossibleConnections.first(); | 426 | NC = PossibleConnections.first(); |
436 | break; | 427 | break; |
437 | default : // need to ask user ? | 428 | default : // need to ask user ? |
438 | return 1; | 429 | return 1; |
439 | } | 430 | } |
440 | 431 | ||
441 | if( NC ) { | 432 | if( NC ) { |
442 | switch( NC->state() ) { | 433 | switch( NC->state() ) { |