summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/nsdata.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp22
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,66 +1,68 @@
#include <stdlib.h>
#include <qpe/qpeapplication.h>
#include <qtextstream.h>
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
#include "nsdata.h"
#include <asdevice.h>
#include <resources.h>
static QString CfgFile;
NetworkSettingsData::NetworkSettingsData( void ) {
// init global resources structure
new TheNSResources();
- CfgFile.sprintf( "%s/NETCONFIG", getenv("HOME") );
+ CfgFile.sprintf( "%s/NETCONFIG",
+ NSResources->currentUser().HomeDir.latin1() );
+ fprintf( stderr, "Cfg from %s\n", CfgFile.latin1() );
// load settings
Force = 0;
IsModified = 0;
loadSettings();
}
// saving is done by caller
NetworkSettingsData::~NetworkSettingsData( void ) {
delete NSResources;
}
void NetworkSettingsData::loadSettings( void ) {
QString S;
ANetNodeInstance* NNI;
QString Attr, Value;
long idx;
QFile F( CfgFile );
QTextStream TS( &F );
do {
if( ! F.open(IO_ReadOnly) )
break;
/* load the file ->
FORMAT :
[NETNODETYPE]
Entries ...
<EMPTYLINE>
[connection]
Name=Name
Node=Name
<EMPTYLINE>
*/
while( ! TS.atEnd() ) {
S = TS.readLine();
if ( S.isEmpty() || S[0] != '[' )
continue;
S = S.mid( 1, S.length()-2 );
if( ! NSResources ) {
continue;
@@ -308,159 +310,161 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) {
}
if( ! NNI )
// no instances -> next netnode type
continue;
// has this node data for this system file ?
if( (CurDev = NNI->runtime()->asDevice() ) ) {
// generate start for this nodetype for all possible devices of this type
for( int i = 0; i < CurDevNN->instanceCount(); i ++ ) {
S = generateSystemFileNode( *SF, CurDev, NNI, i );
if( ! S.isEmpty() )
return S;
}
} else {
S = generateSystemFileNode( *SF, 0, NNI, -1 );
if( ! S.isEmpty() )
return S;
}
}
if( SF->postSection() ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in postSection for file \"%1\"</p>" ).
arg( SF->name() );
return S;
}
} while( 0 );
SF->close();
}
}
Force = 0;
return S;
}
QList<NodeCollection> NetworkSettingsData::collectPossible( const char * Interface ) {
// collect connections that can work on top of this interface
NodeCollection * NC;
QList<NodeCollection> PossibleConnections;
Name2Connection_t & M = NSResources->connections();
// for all connections
for( QDictIterator<NodeCollection> it(M);
it.current();
++it ) {
NC = it.current();
// check if this profile handles the requested interface
+ fprintf( stderr, "check %s\n", NC->name().latin1() );
if( NC->handlesInterface( Interface ) && // if different Intf.
NC->state() != Disabled && // if not enabled
NC->state() != IsUp // if already used
) {
+ fprintf( stderr, "Append %s\n", NC->name().latin1() );
PossibleConnections.append( NC );
}
}
return PossibleConnections;
}
/*
Called by the system to see if interface can be brought UP
if allowed, echo Interface-allowed else Interface-disallowed
*/
-void NetworkSettingsData::canStart( const char * Interface ) {
+bool NetworkSettingsData::canStart( const char * Interface ) {
// load situation
NodeCollection * NC = 0;
QList<NodeCollection> PossibleConnections;
PossibleConnections = collectPossible( Interface );
+ fprintf( stderr, "Possiblilies %d\n",
+ PossibleConnections.count() );
switch( PossibleConnections.count() ) {
case 0 : // no connections
break;
case 1 : // one connection
NC = PossibleConnections.first();
break;
default : // need to ask user ?
- // are we connected to a server
- // system( "su %d networksettings2 --prompt %s\n",
- // "", Interface );
- break;
+ return 1;
}
if( NC ) {
switch( NC->state() ) {
case Unchecked :
case Unknown :
case Unavailable :
case Disabled :
// this profile does not allow interface to be UP
// -> try others
break;
case Off :
// try to UP the device
if( ! NC->setState( Activate ) ) {
// cannot bring device Online -> try other alters
break;
}
// FT
case Available :
case IsUp : // also called for 'ifdown'
// device is ready -> done
printf( "%s-c%d-allowed\n", Interface, NC->number() );
- return;
+ return 0;
}
- } else {
+ }
+
// if we come here no alternatives are possible
printf( "%s-cnn-disallowed\n", Interface );
- }
+ return 0;
}
/*
Called by the system to regenerate config files
*/
bool NetworkSettingsData::regenerate( void ) {
QString S;
// load situation
S = generateSettings( TRUE );
if( ! S.isEmpty() ) {
fprintf( stdout, "%s\n", S.latin1() );
return 1;
}
return 0;
}
QString NetworkSettingsData::generateSystemFileNode(
SystemFile &SF,
AsDevice * CurDev,
ANetNodeInstance * DevNNI,
long DevInstNr ) {
QString S="";
ANetNode * CurDevNN = DevNNI->nodeClass();
Name2Connection_t & M = NSResources->connections();
if( SF.preDeviceSection( CurDevNN ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in preDeviceSection for file \"%1\" and nodetype \"%2\"</p>" ).
arg( SF.name() ).
arg( CurDevNN->nodeName() );
return S;
}
if( CurDevNN->hasDataFor( SF.name() ) ) {
if( CurDevNN->generateDeviceDataForCommonFile( SF, DevInstNr ) ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in node Device part for file \"%1\" and node \"%2\"</p>" ).
arg( SF.name() ).
arg( CurDevNN->nodeName() );
return S;
}
}
if( CurDev )
fprintf( stderr, "Cur %s\n", CurDevNN->nodeName().latin1() );
else