author | kergoth <kergoth> | 2003-03-27 21:01:33 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2003-03-27 21:01:33 (UTC) |
commit | f196ea87989e6f51463a5beb5a37139d6e019a74 (patch) (unidiff) | |
tree | 16fc44e33be1e678c736db4f660784df79b5fc00 | |
parent | bff145f5cced95c742deefcd607932a9f3728dd3 (diff) | |
download | opie-f196ea87989e6f51463a5beb5a37139d6e019a74.zip opie-f196ea87989e6f51463a5beb5a37139d6e019a74.tar.gz opie-f196ea87989e6f51463a5beb5a37139d6e019a74.tar.bz2 |
Switch from 1) calling /etc/init.d/pcmcia to calling cardctl eject, cardctl insert..
and 2) OProcess instead of system()
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanimp.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/noncore/settings/networksettings/wlan/wlanimp.cpp b/noncore/settings/networksettings/wlan/wlanimp.cpp index 1782c22..db03266 100644 --- a/noncore/settings/networksettings/wlan/wlanimp.cpp +++ b/noncore/settings/networksettings/wlan/wlanimp.cpp | |||
@@ -1,65 +1,66 @@ | |||
1 | #include "wlanimp.h" | 1 | #include "wlanimp.h" |
2 | #include "interfacesetupimp.h" | 2 | #include "interfacesetupimp.h" |
3 | 3 | ||
4 | #include <qfile.h> | 4 | #include <qfile.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <qtextstream.h> | 6 | #include <qtextstream.h> |
7 | #include <qmessagebox.h> | 7 | #include <qmessagebox.h> |
8 | #include <qlineedit.h> | 8 | #include <qlineedit.h> |
9 | #include <qlabel.h> | 9 | #include <qlabel.h> |
10 | #include <qspinbox.h> | 10 | #include <qspinbox.h> |
11 | #include <qradiobutton.h> | 11 | #include <qradiobutton.h> |
12 | #include <qcheckbox.h> | 12 | #include <qcheckbox.h> |
13 | #include <qtabwidget.h> | 13 | #include <qtabwidget.h> |
14 | #include <qcombobox.h> | 14 | #include <qcombobox.h> |
15 | 15 | ||
16 | /* system() */ | 16 | /* system() */ |
17 | #include <stdlib.h> | 17 | //#include <stdlib.h> |
18 | #include <opie/oprocess.h> | ||
18 | 19 | ||
19 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" | 20 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" |
20 | 21 | ||
21 | /** | 22 | /** |
22 | * Constructor, read in the wireless.opts file for parsing later. | 23 | * Constructor, read in the wireless.opts file for parsing later. |
23 | */ | 24 | */ |
24 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { | 25 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { |
25 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); | 26 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); |
26 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); | 27 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); |
27 | 28 | ||
28 | // Read in the config file. | 29 | // Read in the config file. |
29 | QString wlanFile = WIRELESS_OPTS; | 30 | QString wlanFile = WIRELESS_OPTS; |
30 | QFile file(wlanFile); | 31 | QFile file(wlanFile); |
31 | if (file.open(IO_ReadOnly)){ | 32 | if (file.open(IO_ReadOnly)){ |
32 | QTextStream stream( &file ); | 33 | QTextStream stream( &file ); |
33 | QString line = ""; | 34 | QString line = ""; |
34 | while ( !stream.eof() ) { | 35 | while ( !stream.eof() ) { |
35 | line += stream.readLine(); | 36 | line += stream.readLine(); |
36 | line += "\n"; | 37 | line += "\n"; |
37 | } | 38 | } |
38 | file.close(); | 39 | file.close(); |
39 | settingsFileText = QStringList::split("\n", line, true); | 40 | settingsFileText = QStringList::split("\n", line, true); |
40 | parseSettingFile(); | 41 | parseSettingFile(); |
41 | } | 42 | } |
42 | else | 43 | else |
43 | qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); | 44 | qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); |
44 | connect(networkType, SIGNAL(activated(int)), this, SLOT(typeChanged(int))); | 45 | connect(networkType, SIGNAL(activated(int)), this, SLOT(typeChanged(int))); |
45 | } | 46 | } |
46 | 47 | ||
47 | void WLANImp::typeChanged(int mod){ | 48 | void WLANImp::typeChanged(int mod){ |
48 | networkChannel->setEnabled(mod); | 49 | networkChannel->setEnabled(mod); |
49 | channelLabel->setEnabled(mod); | 50 | channelLabel->setEnabled(mod); |
50 | } | 51 | } |
51 | 52 | ||
52 | /** | 53 | /** |
53 | * Change the profile for both wireless settings and network settings. | 54 | * Change the profile for both wireless settings and network settings. |
54 | */ | 55 | */ |
55 | void WLANImp::setProfile(const QString &profile){ | 56 | void WLANImp::setProfile(const QString &profile){ |
56 | interfaceSetup->setProfile(profile); | 57 | interfaceSetup->setProfile(profile); |
57 | parseSettingFile(); | 58 | parseSettingFile(); |
58 | } | 59 | } |
59 | 60 | ||
60 | /** | 61 | /** |
61 | * Parses the settings file that was read in and gets any setting from it. | 62 | * Parses the settings file that was read in and gets any setting from it. |
62 | */ | 63 | */ |
63 | void WLANImp::parseSettingFile(){ | 64 | void WLANImp::parseSettingFile(){ |
64 | bool foundCase = false; | 65 | bool foundCase = false; |
65 | bool found = false; | 66 | bool found = false; |
@@ -180,68 +181,68 @@ void WLANImp::changeAndSaveSettingFile(){ | |||
180 | if(wepEnabled->isChecked()){ | 181 | if(wepEnabled->isChecked()){ |
181 | stream << "\tKEY=\""; | 182 | stream << "\tKEY=\""; |
182 | if(keyRadio0->isChecked()) stream << keyLineEdit0->text(); | 183 | if(keyRadio0->isChecked()) stream << keyLineEdit0->text(); |
183 | if(keyRadio1->isChecked()) stream << keyLineEdit1->text(); | 184 | if(keyRadio1->isChecked()) stream << keyLineEdit1->text(); |
184 | if(keyRadio2->isChecked()) stream << keyLineEdit2->text(); | 185 | if(keyRadio2->isChecked()) stream << keyLineEdit2->text(); |
185 | if(keyRadio3->isChecked()) stream << keyLineEdit3->text(); | 186 | if(keyRadio3->isChecked()) stream << keyLineEdit3->text(); |
186 | if(authOpen->isChecked()) | 187 | if(authOpen->isChecked()) |
187 | stream << " open"; | 188 | stream << " open"; |
188 | else | 189 | else |
189 | stream << " restricted"; | 190 | stream << " restricted"; |
190 | stream << "\"\n"; | 191 | stream << "\"\n"; |
191 | } | 192 | } |
192 | stream << "\tRATE=auto\n"; | 193 | stream << "\tRATE=auto\n"; |
193 | if(line.contains("esac")) | 194 | if(line.contains("esac")) |
194 | stream << line << "\n"; | 195 | stream << line << "\n"; |
195 | } | 196 | } |
196 | if(line.contains(";;")) | 197 | if(line.contains(";;")) |
197 | output = true; | 198 | output = true; |
198 | if(output && (*it).length() ) | 199 | if(output && (*it).length() ) |
199 | stream << (*it) << '\n'; | 200 | stream << (*it) << '\n'; |
200 | } | 201 | } |
201 | file.close(); | 202 | file.close(); |
202 | } | 203 | } |
203 | 204 | ||
204 | /** | 205 | /** |
205 | * Check to see if the current config is valid | 206 | * Check to see if the current config is valid |
206 | * Save wireless.opts, save interfaces | 207 | * Save wireless.opts, save interfaces |
207 | */ | 208 | */ |
208 | void WLANImp::accept(){ | 209 | void WLANImp::accept(){ |
209 | if(wepEnabled->isChecked()){ | 210 | if(wepEnabled->isChecked()){ |
210 | if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ){ | 211 | if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ){ |
211 | QMessageBox::information(this, "Error", "Please enter a key for WEP.", QMessageBox::Ok); | 212 | QMessageBox::information(this, "Error", "Please enter a key for WEP.", QMessageBox::Ok); |
212 | return; | 213 | return; |
213 | } | 214 | } |
214 | } | 215 | } |
215 | 216 | ||
216 | if(essAny->isChecked() && essSpecificLineEdit->text().isEmpty()){ | 217 | if(essAny->isChecked() && essSpecificLineEdit->text().isEmpty()){ |
217 | QMessageBox::information(this, "Error", "Please enter a ESS-ID.", QMessageBox::Ok); | 218 | QMessageBox::information(this, "Error", "Please enter a ESS-ID.", QMessageBox::Ok); |
218 | return; | 219 | return; |
219 | } | 220 | } |
220 | 221 | ||
221 | // Ok settings are good here, save | 222 | // Ok settings are good here, save |
222 | changeAndSaveSettingFile(); | 223 | changeAndSaveSettingFile(); |
223 | 224 | ||
224 | // Try to save the interfaces settings. | 225 | // Try to save the interfaces settings. |
225 | if(!interfaceSetup->saveChanges()) | 226 | if(!interfaceSetup->saveChanges()) |
226 | return; | 227 | return; |
227 | 228 | ||
228 | // Restart the device now that the settings have changed | 229 | OProcess insert; |
229 | QString initpath; | 230 | // OProcess eject; |
230 | if( QDir("/etc/rc.d/init.d").exists() ) | ||
231 | initpath = "/etc/rc.d/init.d"; | ||
232 | else if( QDir("/etc/init.d").exists() ) | ||
233 | initpath = "/etc/init.d"; | ||
234 | 231 | ||
235 | // It would be kinda cool if we didn't have to do this and could just to ifup/down | 232 | insert << "sh -c \"cardctl insert && cardctl eject\""; |
236 | 233 | // eject << "cardctl eject"; | |
237 | if( initpath ) | 234 | |
238 | system(QString("%1/pcmcia stop").arg(initpath)); | 235 | // if (!eject.start(OProcess::Block, OProcess::NoCommunication) ) { |
239 | if( initpath ) | 236 | // qWarning("could not start cardctl eject"); |
240 | system(QString("%1/pcmcia start").arg(initpath)); | 237 | // } |
238 | |||
239 | if (!insert.start(OProcess::DontCare, OProcess::NoCommunication) ) { | ||
240 | qWarning("could not start cardctl insert"); | ||
241 | } | ||
241 | 242 | ||
242 | // Close out the dialog | 243 | // Close out the dialog |
243 | QDialog::accept(); | 244 | QDialog::accept(); |
244 | } | 245 | } |
245 | 246 | ||
246 | // wlanimp.cpp | 247 | // wlanimp.cpp |
247 | 248 | ||