author | benmeyer <benmeyer> | 2002-12-11 22:08:02 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-12-11 22:08:02 (UTC) |
commit | 6523ee46d49203d11f34a3dbbf966a318cef7def (patch) (unidiff) | |
tree | 2a51a44e1fb114c3f4d8f3965d5106c8930fba16 /noncore/net/networksetup/wlan/wlanimp.cpp | |
parent | c5737bbbe357ea7481a9f6a406ef81bbeba0d541 (diff) | |
download | opie-6523ee46d49203d11f34a3dbbf966a318cef7def.zip opie-6523ee46d49203d11f34a3dbbf966a318cef7def.tar.gz opie-6523ee46d49203d11f34a3dbbf966a318cef7def.tar.bz2 |
New cleaner layout
Diffstat (limited to 'noncore/net/networksetup/wlan/wlanimp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/networksetup/wlan/wlanimp.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/noncore/net/networksetup/wlan/wlanimp.cpp b/noncore/net/networksetup/wlan/wlanimp.cpp index 6a56358..ef7329e 100644 --- a/noncore/net/networksetup/wlan/wlanimp.cpp +++ b/noncore/net/networksetup/wlan/wlanimp.cpp | |||
@@ -1,24 +1,26 @@ | |||
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 <qspinbox.h> | 10 | #include <qspinbox.h> |
10 | #include <qradiobutton.h> | 11 | #include <qradiobutton.h> |
11 | #include <qcheckbox.h> | 12 | #include <qcheckbox.h> |
12 | #include <qtabwidget.h> | 13 | #include <qtabwidget.h> |
14 | #include <qcombobox.h> | ||
13 | 15 | ||
14 | /* system() */ | 16 | /* system() */ |
15 | #include <stdlib.h> | 17 | #include <stdlib.h> |
16 | 18 | ||
17 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" | 19 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" |
18 | 20 | ||
19 | /** | 21 | /** |
20 | * Constructor, read in the wireless.opts file for parsing later. | 22 | * Constructor, read in the wireless.opts file for parsing later. |
21 | */ | 23 | */ |
22 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { | 24 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { |
23 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); | 25 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); |
24 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); | 26 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); |
@@ -30,24 +32,31 @@ WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, W | |||
30 | QTextStream stream( &file ); | 32 | QTextStream stream( &file ); |
31 | QString line = ""; | 33 | QString line = ""; |
32 | while ( !stream.eof() ) { | 34 | while ( !stream.eof() ) { |
33 | line += stream.readLine(); | 35 | line += stream.readLine(); |
34 | line += "\n"; | 36 | line += "\n"; |
35 | } | 37 | } |
36 | file.close(); | 38 | file.close(); |
37 | settingsFileText = QStringList::split("\n", line, true); | 39 | settingsFileText = QStringList::split("\n", line, true); |
38 | parseSettingFile(); | 40 | parseSettingFile(); |
39 | } | 41 | } |
40 | else | 42 | else |
41 | qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); | 43 | qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1()); |
44 | connect(networkType, SIGNAL(activated(int)), this, SLOT(typeChanged(int))); | ||
45 | |||
46 | } | ||
47 | |||
48 | void WLANImp::typeChanged(int mod){ | ||
49 | networkChannel->setEnabled(mod); | ||
50 | channelLabel->setEnabled(mod); | ||
42 | } | 51 | } |
43 | 52 | ||
44 | /** | 53 | /** |
45 | * Change the profile for both wireless settings and network settings. | 54 | * Change the profile for both wireless settings and network settings. |
46 | */ | 55 | */ |
47 | void WLANImp::setProfile(const QString &profile){ | 56 | void WLANImp::setProfile(const QString &profile){ |
48 | interfaceSetup->setProfile(profile); | 57 | interfaceSetup->setProfile(profile); |
49 | parseSettingFile(); | 58 | parseSettingFile(); |
50 | } | 59 | } |
51 | 60 | ||
52 | /** | 61 | /** |
53 | * 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,41 +71,37 @@ void WLANImp::parseSettingFile(){ | |||
62 | // See if we found our scheme to write or the sceme couldn't be found | 71 | // See if we found our scheme to write or the sceme couldn't be found |
63 | if((foundCase && line.contains("esac")) || | 72 | if((foundCase && line.contains("esac")) || |
64 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) | 73 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) |
65 | found = true; | 74 | found = true; |
66 | 75 | ||
67 | if(line.contains(";;")) | 76 | if(line.contains(";;")) |
68 | found = false; | 77 | found = false; |
69 | if(found){ | 78 | if(found){ |
70 | // write out scheme | 79 | // write out scheme |
71 | if(line.contains("ESSID=")){ | 80 | if(line.contains("ESSID=")){ |
72 | QString id = line.mid(line.find("ESSID=")+6, line.length()); | 81 | QString id = line.mid(line.find("ESSID=")+6, line.length()); |
73 | if(id == "any"){ | 82 | if(id == "any"){ |
74 | essNon->setChecked(true); | 83 | essAny->setChecked(false); |
75 | essSpecific->setChecked(false); | ||
76 | }else{ | 84 | }else{ |
77 | essSpecific->setChecked(true); | 85 | essAny->setChecked(true); |
78 | essSpecificLineEdit->setText(id); | 86 | essSpecificLineEdit->setText(id); |
79 | essNon->setChecked(false); | ||
80 | } | 87 | } |
81 | } | 88 | } |
82 | if(line.contains("MODE=")){ | 89 | if(line.contains("MODE=")){ |
83 | QString mode = line.mid(line.find("MODE=")+5, line.length()); | 90 | QString mode = line.mid(line.find("MODE=")+5, line.length()); |
84 | if(mode == "Managed"){ | 91 | if(mode == "Managed"){ |
85 | network802->setChecked( false ); | 92 | networkType->setCurrentItem(0); |
86 | networkInfrastructure->setChecked( true ); | ||
87 | } | 93 | } |
88 | else{ | 94 | else{ |
89 | network802->setChecked( true ); | 95 | networkType->setCurrentItem(0); |
90 | networkInfrastructure->setChecked( false ); | ||
91 | } | 96 | } |
92 | } | 97 | } |
93 | if(line.contains("KEY0=")) | 98 | if(line.contains("KEY0=")) |
94 | keyLineEdit0->setText(line.mid(5, line.length())); | 99 | keyLineEdit0->setText(line.mid(5, line.length())); |
95 | if(line.contains("KEY1=")) | 100 | if(line.contains("KEY1=")) |
96 | keyLineEdit1->setText(line.mid(5, line.length())); | 101 | keyLineEdit1->setText(line.mid(5, line.length())); |
97 | if(line.contains("KEY2=")) | 102 | if(line.contains("KEY2=")) |
98 | keyLineEdit2->setText(line.mid(5, line.length())); | 103 | keyLineEdit2->setText(line.mid(5, line.length())); |
99 | if(line.contains("KEY3=")) | 104 | if(line.contains("KEY3=")) |
100 | keyLineEdit3->setText(line.mid(5, line.length())); | 105 | keyLineEdit3->setText(line.mid(5, line.length())); |
101 | 106 | ||
102 | if(line.contains("KEY=")){ | 107 | if(line.contains("KEY=")){ |
@@ -145,78 +150,90 @@ void WLANImp::changeAndSaveSettingFile(){ | |||
145 | QString line = (*it).simplifyWhiteSpace(); | 150 | QString line = (*it).simplifyWhiteSpace(); |
146 | if(line.contains("case")) | 151 | if(line.contains("case")) |
147 | foundCase = true; | 152 | foundCase = true; |
148 | // See if we found our scheme to write or the sceme couldn't be found | 153 | // See if we found our scheme to write or the sceme couldn't be found |
149 | if((foundCase && line.contains("esac") && !found) || | 154 | if((foundCase && line.contains("esac") && !found) || |
150 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ | 155 | (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ |
151 | // write out scheme | 156 | // write out scheme |
152 | found = true; | 157 | found = true; |
153 | output = false; | 158 | output = false; |
154 | 159 | ||
155 | if(!line.contains("esac")) | 160 | if(!line.contains("esac")) |
156 | stream << line << "\n"; | 161 | stream << line << "\n"; |
157 | 162 | if(!essAny->isChecked() == true){ | |
158 | stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n'; | 163 | stream << "\tESSID=any\n"; |
159 | stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "ad-hoc") << '\n'; | 164 | stream << "\tMODE=Managed\n"; |
160 | 165 | stream << "\tCHANNEL=6\n"; | |
166 | } | ||
167 | else{ | ||
168 | stream << "\tESSID=" << essSpecificLineEdit->text() << '\n'; | ||
169 | stream << "\tMODE=" << ( networkType->currentItem() == 0 ? "Managed" : "ad-hoc") << '\n'; | ||
170 | stream << "\tCHANNEL=" << networkChannel->value() << "\n"; | ||
171 | } | ||
172 | |||
161 | stream << "\tKEY0=" << keyLineEdit0->text() << "\n"; | 173 | stream << "\tKEY0=" << keyLineEdit0->text() << "\n"; |
162 | stream << "\tKEY1=" << keyLineEdit1->text() << "\n"; | 174 | stream << "\tKEY1=" << keyLineEdit1->text() << "\n"; |
163 | stream << "\tKEY2=" << keyLineEdit2->text() << "\n"; | 175 | stream << "\tKEY2=" << keyLineEdit2->text() << "\n"; |
164 | stream << "\tKEY3=" << keyLineEdit3->text() << "\n"; | 176 | stream << "\tKEY3=" << keyLineEdit3->text() << "\n"; |
165 | 177 | ||
166 | if(wepEnabled->isChecked()){ | 178 | if(wepEnabled->isChecked()){ |
167 | stream << "\tKEY=\""; | 179 | stream << "\tKEY=\""; |
168 | if(keyRadio0->isChecked()) stream << keyLineEdit0->text(); | 180 | if(keyRadio0->isChecked()) stream << keyLineEdit0->text(); |
169 | if(keyRadio1->isChecked()) stream << keyLineEdit1->text(); | 181 | if(keyRadio1->isChecked()) stream << keyLineEdit1->text(); |
170 | if(keyRadio2->isChecked()) stream << keyLineEdit2->text(); | 182 | if(keyRadio2->isChecked()) stream << keyLineEdit2->text(); |
171 | if(keyRadio3->isChecked()) stream << keyLineEdit3->text(); | 183 | if(keyRadio3->isChecked()) stream << keyLineEdit3->text(); |
172 | if(authOpen->isChecked()) | 184 | if(authOpen->isChecked()) |
173 | stream << " open"; | 185 | stream << " open"; |
174 | else | 186 | else |
175 | stream << " restricted"; | 187 | stream << " restricted"; |
176 | stream << "\"\n"; | 188 | stream << "\"\n"; |
177 | } | 189 | } |
178 | stream << "\tCHANNEL=" << networkChannel->value() << "\n"; | ||
179 | stream << "\tRATE=auto\n"; | 190 | stream << "\tRATE=auto\n"; |
180 | if(line.contains("esac")) | 191 | if(line.contains("esac")) |
181 | stream << line << "\n"; | 192 | stream << line << "\n"; |
182 | } | 193 | } |
183 | if(line.contains(";;")) | 194 | if(line.contains(";;")) |
184 | output = true; | 195 | output = true; |
185 | if(output && (*it).length() ) | 196 | if(output && (*it).length() ) |
186 | stream << (*it) << '\n'; | 197 | stream << (*it) << '\n'; |
187 | } | 198 | } |
188 | file.close(); | 199 | file.close(); |
189 | } | 200 | } |
190 | 201 | ||
191 | /** | 202 | /** |
192 | * Check to see if the current config is valid | 203 | * Check to see if the current config is valid |
193 | * Save wireless.opts, save interfaces | 204 | * Save wireless.opts, save interfaces |
194 | */ | 205 | */ |
195 | void WLANImp::accept(){ | 206 | void WLANImp::accept(){ |
196 | if(wepEnabled->isChecked()){ | 207 | if(wepEnabled->isChecked()){ |
197 | if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ) | 208 | if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ) |
198 | { | 209 | { |
199 | QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok); | 210 | QMessageBox::information(this, "Error", "Please enter a key for WEP.", QMessageBox::Ok); |
200 | return; | 211 | return; |
201 | } | 212 | } |
202 | } | 213 | } |
203 | 214 | ||
215 | if(essSpecificLineEdit->text().isEmpty()){ | ||
216 | QMessageBox::information(this, "Error", "Please enter a ESS-ID.", QMessageBox::Ok); | ||
217 | return; | ||
218 | } | ||
219 | |||
204 | // Ok settings are good here, save | 220 | // Ok settings are good here, save |
205 | changeAndSaveSettingFile(); | 221 | changeAndSaveSettingFile(); |
206 | 222 | ||
207 | // Try to save the interfaces settings. | 223 | // Try to save the interfaces settings. |
208 | if(!interfaceSetup->saveChanges()) | 224 | if(!interfaceSetup->saveChanges()) |
209 | return; | 225 | return; |
210 | 226 | ||
227 | return; | ||
211 | // Restart the device now that the settings have changed | 228 | // Restart the device now that the settings have changed |
212 | QString initpath; | 229 | QString initpath; |
213 | if( QDir("/etc/rc.d/init.d").exists() ) | 230 | if( QDir("/etc/rc.d/init.d").exists() ) |
214 | initpath = "/etc/rc.d/init.d"; | 231 | initpath = "/etc/rc.d/init.d"; |
215 | else if( QDir("/etc/init.d").exists() ) | 232 | else if( QDir("/etc/init.d").exists() ) |
216 | initpath = "/etc/init.d"; | 233 | initpath = "/etc/init.d"; |
217 | if( initpath ) | 234 | if( initpath ) |
218 | system(QString("%1/pcmcia stop").arg(initpath)); | 235 | system(QString("%1/pcmcia stop").arg(initpath)); |
219 | if( initpath ) | 236 | if( initpath ) |
220 | system(QString("%1/pcmcia start").arg(initpath)); | 237 | system(QString("%1/pcmcia start").arg(initpath)); |
221 | 238 | ||
222 | // Close out the dialog | 239 | // Close out the dialog |