Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index eb63e02..b4d9aaa 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -1,42 +1,44 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <qpe/qpeapplication.h> | 2 | #include <qpe/qpeapplication.h> |
3 | #include <qtextstream.h> | 3 | #include <qtextstream.h> |
4 | #include <qdir.h> | 4 | #include <qdir.h> |
5 | #include <qfile.h> | 5 | #include <qfile.h> |
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 | ||
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", getenv("HOME") ); | 18 | CfgFile.sprintf( "%s/NETCONFIG", |
19 | NSResources->currentUser().HomeDir.latin1() ); | ||
20 | fprintf( stderr, "Cfg from %s\n", CfgFile.latin1() ); | ||
19 | 21 | ||
20 | // load settings | 22 | // load settings |
21 | Force = 0; | 23 | Force = 0; |
22 | IsModified = 0; | 24 | IsModified = 0; |
23 | loadSettings(); | 25 | loadSettings(); |
24 | } | 26 | } |
25 | 27 | ||
26 | // saving is done by caller | 28 | // saving is done by caller |
27 | NetworkSettingsData::~NetworkSettingsData( void ) { | 29 | NetworkSettingsData::~NetworkSettingsData( void ) { |
28 | delete NSResources; | 30 | delete NSResources; |
29 | } | 31 | } |
30 | 32 | ||
31 | void NetworkSettingsData::loadSettings( void ) { | 33 | void NetworkSettingsData::loadSettings( void ) { |
32 | QString S; | 34 | QString S; |
33 | ANetNodeInstance* NNI; | 35 | ANetNodeInstance* NNI; |
34 | QString Attr, Value; | 36 | QString Attr, Value; |
35 | long idx; | 37 | long idx; |
36 | 38 | ||
37 | QFile F( CfgFile ); | 39 | QFile F( CfgFile ); |
38 | QTextStream TS( &F ); | 40 | QTextStream TS( &F ); |
39 | 41 | ||
40 | do { | 42 | do { |
41 | 43 | ||
42 | if( ! F.open(IO_ReadOnly) ) | 44 | if( ! F.open(IO_ReadOnly) ) |
@@ -332,111 +334,113 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) { | |||
332 | arg( SF->name() ); | 334 | arg( SF->name() ); |
333 | return S; | 335 | return S; |
334 | } | 336 | } |
335 | 337 | ||
336 | } while( 0 ); | 338 | } while( 0 ); |
337 | SF->close(); | 339 | SF->close(); |
338 | } | 340 | } |
339 | } | 341 | } |
340 | Force = 0; | 342 | Force = 0; |
341 | return S; | 343 | return S; |
342 | } | 344 | } |
343 | 345 | ||
344 | QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { | 346 | QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) { |
345 | // collect connections that can work on top of this interface | 347 | // collect connections that can work on top of this interface |
346 | NodeCollection * NC; | 348 | NodeCollection * NC; |
347 | QList<NodeCollection> PossibleConnections; | 349 | QList<NodeCollection> PossibleConnections; |
348 | Name2Connection_t & M = NSResources->connections(); | 350 | Name2Connection_t & M = NSResources->connections(); |
349 | 351 | ||
350 | // for all connections | 352 | // for all connections |
351 | for( QDictIterator<NodeCollection> it(M); | 353 | for( QDictIterator<NodeCollection> it(M); |
352 | it.current(); | 354 | it.current(); |
353 | ++it ) { | 355 | ++it ) { |
354 | NC = it.current(); | 356 | NC = it.current(); |
355 | // check if this profile handles the requested interface | 357 | // check if this profile handles the requested interface |
358 | fprintf( stderr, "check %s\n", NC->name().latin1() ); | ||
356 | if( NC->handlesInterface( Interface ) && // if different Intf. | 359 | if( NC->handlesInterface( Interface ) && // if different Intf. |
357 | NC->state() != Disabled && // if not enabled | 360 | NC->state() != Disabled && // if not enabled |
358 | NC->state() != IsUp // if already used | 361 | NC->state() != IsUp // if already used |
359 | ) { | 362 | ) { |
363 | fprintf( stderr, "Append %s\n", NC->name().latin1() ); | ||
360 | PossibleConnections.append( NC ); | 364 | PossibleConnections.append( NC ); |
361 | } | 365 | } |
362 | } | 366 | } |
363 | return PossibleConnections; | 367 | return PossibleConnections; |
364 | } | 368 | } |
365 | 369 | ||
366 | 370 | ||
367 | /* | 371 | /* |
368 | Called by the system to see if interface can be brought UP | 372 | Called by the system to see if interface can be brought UP |
369 | 373 | ||
370 | if allowed, echo Interface-allowed else Interface-disallowed | 374 | if allowed, echo Interface-allowed else Interface-disallowed |
371 | */ | 375 | */ |
372 | 376 | ||
373 | void NetworkSettingsData::canStart( const char * Interface ) { | 377 | bool NetworkSettingsData::canStart( const char * Interface ) { |
374 | // load situation | 378 | // load situation |
375 | NodeCollection * NC = 0; | 379 | NodeCollection * NC = 0; |
376 | QList<NodeCollection> PossibleConnections; | 380 | QList<NodeCollection> PossibleConnections; |
377 | 381 | ||
378 | PossibleConnections = collectPossible( Interface ); | 382 | PossibleConnections = collectPossible( Interface ); |
379 | 383 | ||
384 | fprintf( stderr, "Possiblilies %d\n", | ||
385 | PossibleConnections.count() ); | ||
380 | switch( PossibleConnections.count() ) { | 386 | switch( PossibleConnections.count() ) { |
381 | case 0 : // no connections | 387 | case 0 : // no connections |
382 | break; | 388 | break; |
383 | case 1 : // one connection | 389 | case 1 : // one connection |
384 | NC = PossibleConnections.first(); | 390 | NC = PossibleConnections.first(); |
385 | break; | 391 | break; |
386 | default : // need to ask user ? | 392 | default : // need to ask user ? |
387 | // are we connected to a server | 393 | return 1; |
388 | // system( "su %d networksettings2 --prompt %s\n", | ||
389 | // "", Interface ); | ||
390 | break; | ||
391 | } | 394 | } |
392 | 395 | ||
393 | if( NC ) { | 396 | if( NC ) { |
394 | switch( NC->state() ) { | 397 | switch( NC->state() ) { |
395 | case Unchecked : | 398 | case Unchecked : |
396 | case Unknown : | 399 | case Unknown : |
397 | case Unavailable : | 400 | case Unavailable : |
398 | case Disabled : | 401 | case Disabled : |
399 | // this profile does not allow interface to be UP | 402 | // this profile does not allow interface to be UP |
400 | // -> try others | 403 | // -> try others |
401 | break; | 404 | break; |
402 | case Off : | 405 | case Off : |
403 | // try to UP the device | 406 | // try to UP the device |
404 | if( ! NC->setState( Activate ) ) { | 407 | if( ! NC->setState( Activate ) ) { |
405 | // cannot bring device Online -> try other alters | 408 | // cannot bring device Online -> try other alters |
406 | break; | 409 | break; |
407 | } | 410 | } |
408 | // FT | 411 | // FT |
409 | case Available : | 412 | case Available : |
410 | case IsUp : // also called for 'ifdown' | 413 | case IsUp : // also called for 'ifdown' |
411 | // device is ready -> done | 414 | // device is ready -> done |
412 | printf( "%s-c%d-allowed\n", Interface, NC->number() ); | 415 | printf( "%s-c%d-allowed\n", Interface, NC->number() ); |
413 | return; | 416 | return 0; |
414 | } | 417 | } |
415 | } else { | 418 | } |
419 | |||
416 | // if we come here no alternatives are possible | 420 | // if we come here no alternatives are possible |
417 | printf( "%s-cnn-disallowed\n", Interface ); | 421 | printf( "%s-cnn-disallowed\n", Interface ); |
418 | } | 422 | return 0; |
419 | } | 423 | } |
420 | 424 | ||
421 | /* | 425 | /* |
422 | Called by the system to regenerate config files | 426 | Called by the system to regenerate config files |
423 | */ | 427 | */ |
424 | 428 | ||
425 | bool NetworkSettingsData::regenerate( void ) { | 429 | bool NetworkSettingsData::regenerate( void ) { |
426 | QString S; | 430 | QString S; |
427 | // load situation | 431 | // load situation |
428 | S = generateSettings( TRUE ); | 432 | S = generateSettings( TRUE ); |
429 | if( ! S.isEmpty() ) { | 433 | if( ! S.isEmpty() ) { |
430 | fprintf( stdout, "%s\n", S.latin1() ); | 434 | fprintf( stdout, "%s\n", S.latin1() ); |
431 | return 1; | 435 | return 1; |
432 | } | 436 | } |
433 | return 0; | 437 | return 0; |
434 | } | 438 | } |
435 | 439 | ||
436 | QString NetworkSettingsData::generateSystemFileNode( | 440 | QString NetworkSettingsData::generateSystemFileNode( |
437 | SystemFile &SF, | 441 | SystemFile &SF, |
438 | AsDevice * CurDev, | 442 | AsDevice * CurDev, |
439 | ANetNodeInstance * DevNNI, | 443 | ANetNodeInstance * DevNNI, |
440 | long DevInstNr ) { | 444 | long DevInstNr ) { |
441 | 445 | ||
442 | QString S=""; | 446 | QString S=""; |