summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/nsdata.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/nsdata.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/nsdata.cpp25
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
@@ -1,44 +1,44 @@
#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/Settings/NS2.conf",
NSResources->currentUser().HomeDir.latin1() );
- fprintf( stderr, "Cfg from %s\n", CfgFile.latin1() );
+ Log(( "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 Line, S;
QString Attr, Value;
long idx;
QFile F( CfgFile );
QTextStream TS( &F );
do {
if( ! F.open(IO_ReadOnly) )
break;
@@ -58,53 +58,53 @@ void NetworkSettingsData::loadSettings( void ) {
while( ! TS.atEnd() ) {
S = Line = TS.readLine();
if ( S.isEmpty() || S[0] != '[' )
continue;
S = S.mid( 1, S.length()-2 );
if( ! NSResources ) {
continue;
}
if( S == "connection" ) {
// load connections -> collections of nodes
NodeCollection * NC = new NodeCollection( TS );
NSResources->addConnection( NC );
} else {
ANetNode * NN = 0;
ANetNodeInstance* NNI = 0;
if( S.startsWith( "nodetype " ) ) {
S = S.mid( 9, S.length()-9 );
S = deQuote(S);
// try to find netnode
NN = NSResources->findNetNode( S );
- fprintf( stderr, "Node %s : %p\n", S.latin1(), NN );
+ Log( ( "Node %s : %p\n", S.latin1(), NN ) );
} else {
// try to find instance
NNI = NSResources->createNodeInstance( S );
- fprintf( stderr, "NodeInstance %s : %p\n", S.latin1(), NNI );
+ Log( ( "NodeInstance %s : %p\n", S.latin1(), NNI ));
}
if( NN == 0 && NNI == 0 ) {
LeftOvers.append( Line );
}
do {
S = Line = TS.readLine();
if( NN || NNI ) {
if( S.isEmpty() ) {
// empty line
break;
}
idx = S.find( '=' );
if( idx > 0 ) {
Attr = S.left( idx );
Value = S.mid( idx+1, S.length() );
} else {
Value="";
Attr = S;
}
Value.stripWhiteSpace();
@@ -130,49 +130,49 @@ void NetworkSettingsData::loadSettings( void ) {
}
} while( 1 );
if( NNI ) {
// loading from file -> exists
NNI->setNew( FALSE );
NSResources->addNodeInstance( NNI );
}
}
}
} while( 0 );
}
QString NetworkSettingsData::saveSettings( void ) {
QString ErrS = "";
if( ! isModified() )
return ErrS;
QString S;
QFile F( CfgFile + ".bup" );
- printf( "Saving settings to %s\n", CfgFile.latin1() );
+ Log( ( "Saving settings to %s\n", CfgFile.latin1() ));
if( ! F.open( IO_WriteOnly | IO_Truncate ) ) {
ErrS = qApp->translate( "NetworkSettings",
"<p>Could not save setup to \"%1\" !</p>" ).
arg(CfgFile);
// problem
return ErrS;
}
QTextStream TS( &F );
// save leftovers
for ( QStringList::Iterator it = LeftOvers.begin();
it != LeftOvers.end(); ++it ) {
TS << (*it) << endl;
}
// save global configs
for( QDictIterator<NetNode_t> it( NSResources->netNodes() );
it.current();
++it ) {
TS << "[nodetype "
<< quote( QString( it.current()->NetNode->name() ) )
<< "]"
<< endl;
@@ -208,49 +208,49 @@ QString NetworkSettingsData::saveSettings( void ) {
}
QDir D(".");
D.rename( CfgFile + ".bup", CfgFile );
//
// proper files AND system files regenerated
//
setModified( 0 );
return ErrS;
}
QString NetworkSettingsData::generateSettings( bool ForceReq ) {
bool ForceIt;
QString S = "";
// include own force flag
ForceIt = (Force) ? 1 : ForceReq;
if( ! ForceIt && ! isModified() )
return S;
// regenerate system files
- fprintf( stderr, "Generating settings from %s\n", CfgFile.latin1() );
+ Log( ( "Generating settings from %s\n", CfgFile.latin1() ));
{ Name2SystemFile_t & SFM = NSResources->systemFiles();
Name2Connection_t & M = NSResources->connections();
NodeCollection * NC;
ANetNodeInstance * NNI;
SystemFile * SF;
AsDevice * CurDev;
ANetNode * CurDevNN;
bool needToRegenerate = ForceIt;
//
// check if we need to generate at least one of the system files
//
if( ! ForceIt ) {
for( QDictIterator<SystemFile> sfit(SFM);
sfit.current();
++sfit ) {
SF = sfit.current();
// check if there are nodes that are modified and require
// data for this system file
// for all connections
for( QDictIterator<NodeCollection> ncit(M);
@@ -260,89 +260,81 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) {
if( NC->isModified() ) {
// does this connection 'touch' this system file ?
for( QListIterator<ANetNodeInstance> cncit(*NC);
cncit.current();
++cncit ) {
NNI = cncit.current();
if( ( NNI->nodeClass()->hasDataFor( SF->name() ) ||
NNI->hasDataFor( SF->name() )
) &&
NNI->isModified() ) {
needToRegenerate = 1;
break;
}
}
}
if( needToRegenerate )
break;
}
if( needToRegenerate )
break;
}
}
- // we cannot renumber with a FORCE request since
- // we probably are NOT going to save the config
- // e.g. when using --regen option
- if( ! ForceReq && needToRegenerate ) {
- NSResources->renumberConnections();
- setModified(1);
- }
-
//
// generate files proper to each netnodeinstance
//
{ Name2Instance_t & NNIs = NSResources->netNodeInstances();
for( QDictIterator<ANetNodeInstance> NNIIt(NNIs);
NNIIt.current();
++NNIIt
){
// for all nodes find those that are modified
NNI = NNIIt.current();
if( ForceIt || NNI->isModified() ) {
if( NNI->nodeClass()->generateProperFilesFor( NNI ) ) {
// problem generating
S = qApp->translate( "NetworkSettings",
"<p>Cannot generate files proper to \"%1\"</p>" ).
arg(NNI->nodeClass()->name()) ;
return S;
}
}
}
}
//
// generate all system files
//
for( QDictIterator<SystemFile> sfit(SFM);
sfit.current();
++sfit ) {
SF = sfit.current();
- fprintf( stderr, "Generating %s\n", SF->name().latin1() );
+ Log( ( "Generating %s\n", SF->name().latin1() ));
SF->open();
do { // so we can break;
// global presection for this system file
if( SF->preSection() ) {
S = qApp->translate( "NetworkSettings",
"<p>Error in preSection for file \"%1\"</p>" ).
arg( SF->name() );
return S;
}
// find all netnodes and figure out if
// for that node there are instances
for( QDictIterator<NetNode_t> nnit(
NSResources->netNodes() );
nnit.current();
++nnit ) {
CurDevNN = nnit.current()->NetNode;
// are there instances for this netnode ?
NNI = 0;
for( QDictIterator<ANetNodeInstance> nniit(
@@ -384,71 +376,70 @@ QString NetworkSettingsData::generateSettings( bool ForceReq ) {
} 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
if( NC->handlesInterface( Interface ) && // if different Intf.
NC->state() != Disabled && // if not enabled
NC->state() != IsUp // if already used
) {
- fprintf( stderr, "Append %s for %s\n", NC->name().latin1(), Interface);
+ Log( ( "Append %s for %s\n", NC->name().latin1(), Interface));
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
*/
bool NetworkSettingsData::canStart( const char * Interface ) {
// load situation
NodeCollection * NC = 0;
QList<NodeCollection> PossibleConnections;
PossibleConnections = collectPossible( Interface );
- fprintf( stderr, "Possiblilies %d\n",
- PossibleConnections.count() );
+ Log( ( "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 ?
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;