Diffstat (limited to 'noncore/settings/networksettings/interfaces/interface.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/interfaces/interface.cpp | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/noncore/settings/networksettings/interfaces/interface.cpp b/noncore/settings/networksettings/interfaces/interface.cpp index 46f3e19..44c0264 100644 --- a/noncore/settings/networksettings/interfaces/interface.cpp +++ b/noncore/settings/networksettings/interfaces/interface.cpp @@ -5,16 +5,23 @@ #include "interface.h" #include <opie2/odebug.h> +#include <opie2/oprocess.h> +#include <opie2/owait.h> +#include <qpe/global.h> + +#include <qapplication.h> #include <qdatetime.h> #include <qfile.h> #include <qdir.h> #include <qfileinfo.h> #include <qtextstream.h> #define IFCONFIG "/sbin/ifconfig" +#define IF_UP "/sbin/ifup" +#define IF_DOWN "/sbin/ifdown" #define DHCP_INFO_DIR "/etc/dhcpc" #include <stdio.h> #include <stdlib.h> @@ -65,8 +72,31 @@ void Interface::setModuleOwner(Module *owner){ emit(updateInterface(this)); }; +bool Interface::callProcess( const QStringList& names ) { + Opie::Ui::OWait *owait = new Opie::Ui::OWait(); + Global::statusMessage( tr( "Restarting interface" ) ); + + owait->show(); + qApp->processEvents(); + + Opie::Core::OProcess restart; + restart << names; + if ( !restart.start(Opie::Core::OProcess::Block, + Opie::Core::OProcess::NoCommunication ) ) { + owarn << "unable to spawn command" << names << oendl; + return false; + } + owait->hide(); + delete owait; + + if ( restart.normalExit() || restart.exitStatus() != 0 ) + return false; + + return true; +} + /** * Try to start the interface. */ void Interface::start(){ @@ -75,11 +105,13 @@ void Interface::start(){ emit (updateMessage("Unable to start interface,\n already started")); return; } - int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); - // See if it was successful... - if(ret != 0){ + /* prepare command and call it */ + QStringList lst; + lst << IF_UP; + lst << name(); + if ( !callProcess(lst) ) { emit (updateMessage("Starting interface failed")); return; } @@ -97,10 +129,14 @@ void Interface::stop(){ emit (updateMessage("Unable to stop interface,\n already stopped")); return; } - int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); - if(ret != 0){ + QStringList lst; + lst << IF_DOWN; + lst << name(); + + /* prepare command and call it */ + if( !callProcess( lst ) ){ emit (updateMessage("Stopping interface failed")); return; } |