Diffstat (limited to 'noncore/settings/networksettings2/networksettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings.cpp | 434 |
1 files changed, 14 insertions, 420 deletions
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index ffe130c..f72fa8e 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp @@ -8,10 +8,6 @@ #include <qmessagebox.h> #include <qlabel.h> #include <qiconview.h> -#include <qtextstream.h> -#include <qdir.h> -#include <qfile.h> -#include <qfileinfo.h> #include <qtimer.h> #include <qpe/qpeapplication.h> #include <qtoolbutton.h> @@ -21,359 +17,6 @@ #include "netnode.h" #include "editconnection.h" -static QString CfgFile; - -NetworkSettingsData::NetworkSettingsData( void ) { - // init global resources structure - new TheNSResources(); - - CfgFile.sprintf( "%s/NETCONFIG", getenv("HOME") ); - - // load settings - Force = 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; - } - - if( S == "connection" ) { - // load connections -> collections of nodes - NodeCollection * NC = new NodeCollection( TS ); - if ( NC->count() == 0 ) { - if( QMessageBox::warning( - 0, - qApp->translate( "NetworkSettings2", "Invalid connection" ), - qApp->translate( "NetworkSettings2", - "<p>Connection %1 contains unrecognized nodes and cannot be loaded</p>" ).arg(NC->name()), - qApp->translate( "NetworkSettings2", - "Remove node"), - qApp->translate( "NetworkSettings2", - "Exit program") ) == 1 ) { - exit( 0 ); - } - delete NC; - } else - NSResources->addConnection( NC ); - } else { - // load nodes - NNI = NSResources->createNodeInstance( S ); - if( ! NNI ) { - printf( "SKIPPING %s\n", S.latin1() ); - } - - do { - S = TS.readLine(); - if( S.isEmpty() ) { - // empty line - break; - } - // node found ? - if( NNI ) { - idx = S.find( '=' ); - if( idx > 0 ) { - Attr = S.left( idx ); - Value = S.mid( idx+1, S.length() ); - } else { - Value=""; - Attr = S; - } - - Value.stripWhiteSpace(); - Attr.stripWhiteSpace(); - Attr.lower(); - // dequote Attr - Value = deQuote(Value); - - // set the attribute - NNI->setAttribute( Attr, Value ); - } - - } 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() ); - 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 ); - { Name2Connection_t & M = NSResources->connections(); - ANetNodeInstance * NNI; - - // for all connections - for( QDictIterator<NodeCollection> it(M); - it.current(); - ++it ) { - // all nodes in those connections - for( QListIterator<ANetNodeInstance> nit(*(it.current())); - nit.current(); - ++nit ) { - // header - NNI = nit.current(); - TS << '[' <<NNI->netNode()->nodeName() << ']' << endl; - NNI->saveAttributes( TS ); - TS << endl; - } - - TS << "[connection]" << endl; - it.current()->save(TS); - } - } - - 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 - printf( "Generating settings from %s\n", CfgFile.latin1() ); - - { Name2SystemFile_t & SFM = NSResources->systemFiles(); - Name2Connection_t & M = NSResources->connections(); - NodeCollection * NC; - ANetNodeInstance * NNI; - SystemFile * SF; - 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); - ncit.current(); - ++ncit ) { - NC = ncit.current(); - - if( NC->isModified() ) { - // does this connection 'touch' this system file ? - for( QListIterator<ANetNodeInstance> cncit(*NC); - cncit.current(); - ++cncit ) { - NNI = cncit.current(); - if( NNI->netNode()->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(); - ANetNodeInstance * NNI; - - 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->netNode()->generateProperFilesFor( NNI ) ) { - // problem generating - S = qApp->translate( "NetworkSettings", - "<p>Cannot generate files proper to %1</p>" ). - arg(NNI->netNode()->nodeName()) ; - return S; - } - } - } - } - - // - // generate system files - // - for( QDictIterator<SystemFile> sfit(SFM); - sfit.current(); - ++sfit ) { - SF = sfit.current(); - - // - // regenerate current file - // - printf( "Generating %s\n", SF->name().latin1() ); - SF->open(); - - do { // so we can break; - - if( SF->preSection() ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in preSection for file %1</p>" ). - arg( SF->name() ); - return S; - } - - for( QDictIterator<NodeCollection> ncit(M); - ncit.current(); - ++ncit ) { - NC = ncit.current(); - - // get the netnode that serves as the device for this - // connection - AsDevice * Dev = NC->device(); - - // generate 'entry' for every possible device this profile handles - - for( QListIterator<ANetNodeInstance> cncit(*NC); - cncit.current(); - ++cncit ) { - NNI = cncit.current(); - for( int i = 0; i < Dev->count(); i ++ ) { - if( NNI->netNode()->hasDataFor( SF->name() ) ) { - if( SF->preNodeSection( NNI, i ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in preNodeSection for file %1 and node %2</p>" ). - arg( SF->name() ). - arg( NNI->netNode()->nodeName() ); - return S; - } - - if( NNI->netNode()->generateDataForCommonFile(*SF,i,NNI) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in node part for file %1 and node %2</p>" ). - arg( SF->name() ). - arg( NNI->netNode()->nodeName() ); - return S; - } - - if( SF->postNodeSection( NNI, i ) ) { - S = qApp->translate( "NetworkSettings", - "<p>Error in postNodeSection for file %1 and node %2</p>" ). - arg( SF->name() ). - arg( NNI->netNode()->nodeName() ); - return S; - } - } - } - } - *SF << endl; - } - - 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; -} - -// -// GUI part -// - NetworkSettings::NetworkSettings( QWidget *parent, const char *name, WFlags fl ) : NetworkSettingsGUI(parent,name,fl), @@ -420,6 +63,10 @@ NetworkSettings::NetworkSettings( QWidget *parent, UpdateTimer->start( 5000 ); connect( UpdateTimer, SIGNAL( timeout() ), this, SLOT( SLOT_RefreshStates() ) ); + + /* Add QCopChannel */ + connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), + this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); } NetworkSettings::~NetworkSettings() { @@ -753,68 +400,15 @@ void NetworkSettings::SLOT_Connect( void ) { // we do not update the GUI but wait for the REAL upping of the device } -/* - Called by the system to see if interface can be brought UP - - if allowed, echo Interface-allowed else Interface-disallowed -*/ - -void NetworkSettings::canStart( const char * Interface ) { - // load situation - NetworkSettingsData NSD; - - { Name2Connection_t & M = NSResources->connections(); - NodeCollection * NC; - - // 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 ) ) { - 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 'down' - // device is ready -> done - printf( "%s-c%d-allowed\n", - Interface, NC->number() ); - return; - } - } - } - } - // if we come here no alternatives are possible - printf( "%s-cnn-disallowed\n", Interface ); -} - -/* - Called by the system to regenerate config files -*/ - -bool NetworkSettings::regenerate( void ) { - QString S; - // load situation - NetworkSettingsData NSD; +void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { + QDataStream stream( data, IO_ReadOnly ); - S = NSD.generateSettings( TRUE ); - if( ! S.isEmpty() ) { - fprintf( stdout, "%s\n", S.latin1() ); - return 1; - } - return 0; + if( msg == "raise" ) { + raise(); + return; + } /* if ( msg == "someMessage(int,int,int)" ) { + int a,b,c; + stream >> a >> b >> c; + ... + } */ } |