-rw-r--r-- | noncore/settings/networksettings/interfaces/interface.cpp | 46 | ||||
-rw-r--r-- | noncore/settings/networksettings/interfaces/interface.h | 1 |
2 files changed, 42 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 @@ | |||
5 | 5 | ||
6 | #include "interface.h" | 6 | #include "interface.h" |
7 | 7 | ||
8 | #include <opie2/odebug.h> | 8 | #include <opie2/odebug.h> |
9 | #include <opie2/oprocess.h> | ||
10 | #include <opie2/owait.h> | ||
9 | 11 | ||
12 | #include <qpe/global.h> | ||
13 | |||
14 | #include <qapplication.h> | ||
10 | #include <qdatetime.h> | 15 | #include <qdatetime.h> |
11 | #include <qfile.h> | 16 | #include <qfile.h> |
12 | #include <qdir.h> | 17 | #include <qdir.h> |
13 | #include <qfileinfo.h> | 18 | #include <qfileinfo.h> |
14 | #include <qtextstream.h> | 19 | #include <qtextstream.h> |
15 | 20 | ||
16 | #define IFCONFIG "/sbin/ifconfig" | 21 | #define IFCONFIG "/sbin/ifconfig" |
22 | #define IF_UP "/sbin/ifup" | ||
23 | #define IF_DOWN "/sbin/ifdown" | ||
17 | #define DHCP_INFO_DIR "/etc/dhcpc" | 24 | #define DHCP_INFO_DIR "/etc/dhcpc" |
18 | 25 | ||
19 | #include <stdio.h> | 26 | #include <stdio.h> |
20 | #include <stdlib.h> | 27 | #include <stdlib.h> |
@@ -65,8 +72,31 @@ void Interface::setModuleOwner(Module *owner){ | |||
65 | emit(updateInterface(this)); | 72 | emit(updateInterface(this)); |
66 | }; | 73 | }; |
67 | 74 | ||
68 | 75 | ||
76 | bool Interface::callProcess( const QStringList& names ) { | ||
77 | Opie::Ui::OWait *owait = new Opie::Ui::OWait(); | ||
78 | Global::statusMessage( tr( "Restarting interface" ) ); | ||
79 | |||
80 | owait->show(); | ||
81 | qApp->processEvents(); | ||
82 | |||
83 | Opie::Core::OProcess restart; | ||
84 | restart << names; | ||
85 | if ( !restart.start(Opie::Core::OProcess::Block, | ||
86 | Opie::Core::OProcess::NoCommunication ) ) { | ||
87 | owarn << "unable to spawn command" << names << oendl; | ||
88 | return false; | ||
89 | } | ||
90 | owait->hide(); | ||
91 | delete owait; | ||
92 | |||
93 | if ( restart.normalExit() || restart.exitStatus() != 0 ) | ||
94 | return false; | ||
95 | |||
96 | return true; | ||
97 | } | ||
98 | |||
69 | /** | 99 | /** |
70 | * Try to start the interface. | 100 | * Try to start the interface. |
71 | */ | 101 | */ |
72 | void Interface::start(){ | 102 | void Interface::start(){ |
@@ -75,11 +105,13 @@ void Interface::start(){ | |||
75 | emit (updateMessage("Unable to start interface,\n already started")); | 105 | emit (updateMessage("Unable to start interface,\n already started")); |
76 | return; | 106 | return; |
77 | } | 107 | } |
78 | 108 | ||
79 | int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(this->name()).latin1()); | 109 | /* prepare command and call it */ |
80 | // See if it was successful... | 110 | QStringList lst; |
81 | if(ret != 0){ | 111 | lst << IF_UP; |
112 | lst << name(); | ||
113 | if ( !callProcess(lst) ) { | ||
82 | emit (updateMessage("Starting interface failed")); | 114 | emit (updateMessage("Starting interface failed")); |
83 | return; | 115 | return; |
84 | } | 116 | } |
85 | 117 | ||
@@ -97,10 +129,14 @@ void Interface::stop(){ | |||
97 | emit (updateMessage("Unable to stop interface,\n already stopped")); | 129 | emit (updateMessage("Unable to stop interface,\n already stopped")); |
98 | return; | 130 | return; |
99 | } | 131 | } |
100 | 132 | ||
101 | int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(this->name()).latin1()); | 133 | QStringList lst; |
102 | if(ret != 0){ | 134 | lst << IF_DOWN; |
135 | lst << name(); | ||
136 | |||
137 | /* prepare command and call it */ | ||
138 | if( !callProcess( lst ) ){ | ||
103 | emit (updateMessage("Stopping interface failed")); | 139 | emit (updateMessage("Stopping interface failed")); |
104 | return; | 140 | return; |
105 | } | 141 | } |
106 | 142 | ||
diff --git a/noncore/settings/networksettings/interfaces/interface.h b/noncore/settings/networksettings/interfaces/interface.h index 83ab088..e9ab0c2 100644 --- a/noncore/settings/networksettings/interfaces/interface.h +++ b/noncore/settings/networksettings/interfaces/interface.h | |||
@@ -54,8 +54,9 @@ public: | |||
54 | virtual void stop(); | 54 | virtual void stop(); |
55 | virtual void restart(); | 55 | virtual void restart(); |
56 | 56 | ||
57 | protected: | 57 | protected: |
58 | bool callProcess( const QStringList& name ); | ||
58 | // Interface information | 59 | // Interface information |
59 | QString hardwareName; | 60 | QString hardwareName; |
60 | Module *moduleOwner; | 61 | Module *moduleOwner; |
61 | bool status; | 62 | bool status; |