summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp2.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/noncore/settings/networksettings/wlan/wlanimp2.cpp b/noncore/settings/networksettings/wlan/wlanimp2.cpp
index 01c9668..73afc92 100644
--- a/noncore/settings/networksettings/wlan/wlanimp2.cpp
+++ b/noncore/settings/networksettings/wlan/wlanimp2.cpp
@@ -1,266 +1,268 @@
1#include "wlanimp2.h" 1#include "wlanimp2.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#ifdef QWS 16#ifdef QWS
17 #include <opie/oprocess.h> 17 #include <opie/oprocess.h>
18#else 18#else
19 #define OProcess KProcess 19 #define OProcess KProcess
20 #include <kprocess.h> 20 #include <kprocess.h>
21#endif 21#endif
22 22
23#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" 23#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts"
24#define PREUP "/etc/netwrok/if-pre-up.d/wireless-tools" 24#define PREUP "/etc/netwrok/if-pre-up.d/wireless-tools"
25 25
26/** 26/**
27 * Constructor, read in the wireless.opts file for parsing later. 27 * Constructor, read in the wireless.opts file for parsing later.
28 */ 28 */
29WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), currentProfile("*"), interface(i) { 29WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), currentProfile("*"), interface(i) {
30 interfaces = new Interfaces; 30 interfaces = new Interfaces;
31 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); 31 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces);
32 tabWidget->insertTab(interfaceSetup, "TCP/IP"); 32 tabWidget->insertTab(interfaceSetup, "TCP/IP");
33 33
34 // Check sanity - the existance of the wireless-tools if-pre-up script 34 // Check sanity - the existance of the wireless-tools if-pre-up script
35 QFile file(QString(PREUP)); 35 QFile file(QString(PREUP));
36 if (file.exists()) { 36 if (file.exists()) {
37 qWarning(QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools")); 37 qWarning(QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools"));
38 } 38 }
39} 39}
40 40
41WLANImp::~WLANImp() { 41WLANImp::~WLANImp() {
42 delete interfaces; 42 delete interfaces;
43} 43}
44 44
45/** 45/**
46 * Change the profile for both wireless settings and network settings. 46 * Change the profile for both wireless settings and network settings.
47 */ 47 */
48void WLANImp::setProfile(const QString &profile){ 48void WLANImp::setProfile(const QString &profile){
49 interfaceSetup->setProfile(profile); 49 interfaceSetup->setProfile(profile);
50 parseOpts(); 50 parseOpts();
51} 51}
52 52
53void WLANImp::parseOpts() { 53void WLANImp::parseOpts() {
54 bool error; 54 bool error;
55 QString opt; 55 QString opt;
56 56
57 if (! interfaces->isInterfaceSet()) 57 if (! interfaces->isInterfaceSet())
58 return; 58 return;
59 59
60 60
61 opt = interfaces->getInterfaceOption("wireless_essid", error); 61 opt = interfaces->getInterfaceOption("wireless_essid", error);
62 if(opt == "any" || opt == "off" || opt.isNull()){ 62 if(opt == "any" || opt == "off" || opt.isNull()){
63 essid->setEditText("any"); 63 essid->setEditText("any");
64 } else { 64 } else {
65 essid->setEditText(opt); 65 essid->setEditText(opt);
66 } 66 }
67 67
68 opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace(); 68 opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace();
69 if (opt == "Auto") { 69 if (opt == "Auto") {
70 mode->setCurrentItem(0); 70 mode->setCurrentItem(0);
71 } else if (opt == "Ad-Hoc") { 71 } else if (opt == "Ad-Hoc") {
72 mode->setCurrentItem(2); 72 mode->setCurrentItem(2);
73 } else { 73 } else {
74 // Managed/Infrastructure mode 74 // Managed/Infrastructure mode
75 mode->setCurrentItem(1); 75 mode->setCurrentItem(1);
76 } 76 }
77 77
78 opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace(); 78 opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace();
79 if (! opt.isNull()) { 79 if (! opt.isNull()) {
80 specifyAp->setChecked(true); 80 specifyAp->setChecked(true);
81 macEdit->setText(opt); 81 macEdit->setText(opt);
82 } 82 }
83 83
84 opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace(); 84 opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace();
85 if (! opt.isNull()) { 85 if (! opt.isNull()) {
86 specifyChan->setChecked(true); 86 specifyChan->setChecked(true);
87 networkChannel->setValue(opt.toInt()); 87 networkChannel->setValue(opt.toInt());
88 } 88 }
89 89
90 opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace(); 90 opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace();
91 if (opt.isNull()) 91 if (opt.isNull())
92 opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace(); 92 opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace();
93 parseKeyStr(opt); 93 parseKeyStr(opt);
94} 94}
95 95
96void WLANImp::parseKeyStr(QString keystr) { 96void WLANImp::parseKeyStr(QString keystr) {
97 int loc = 0; 97 int loc = 0;
98 int index = 1; 98 int index = 1;
99 QString key; 99 QString key;
100 QStringList keys = QStringList::split(QRegExp("\\s+"), keystr); 100 QStringList keys = QStringList::split(QRegExp("\\s+"), keystr);
101 int enc = -1; // encryption state 101 int enc = -1; // encryption state
102 102
103 for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { 103 for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) {
104 if ((*it).left(3) == "off") { 104 if ((*it).left(3) == "off") {
105 // encryption disabled 105 // encryption disabled
106 enc = 0; 106 enc = 0;
107 } else if ((*it).left(2) == "on") { 107 } else if ((*it).left(2) == "on") {
108 // encryption enabled 108 // encryption enabled
109 enc = 1; 109 enc = 1;
110 } else if ((*it).left(4) == "open") { 110 } else if ((*it).left(4) == "open") {
111 // open mode, accept non encrypted packets 111 // open mode, accept non encrypted packets
112 acceptNonEnc->setChecked(true); 112 acceptNonEnc->setChecked(true);
113 } else if ((*it).left(10) == "restricted") { 113 } else if ((*it).left(10) == "restricted") {
114 // restricted mode, only accept encrypted packets 114 // restricted mode, only accept encrypted packets
115 rejectNonEnc->setChecked(true); 115 rejectNonEnc->setChecked(true);
116 } else if ((*it).left(3) == "key") { 116 } else if ((*it).left(3) == "key") {
117 // new set of options 117 // new set of options
118 } else if ((*it).left(1) == "[") { 118 } else if ((*it).left(1) == "[") {
119 index = (*it).mid(1, 1).toInt(); 119 index = (*it).mid(1, 1).toInt();
120 // switch current key to index 120 // switch current key to index
121 switch (index) { 121 switch (index) {
122 case 1: 122 case 1:
123 keyRadio0->setChecked(true); 123 keyRadio0->setChecked(true);
124 break; 124 break;
125 case 2: 125 case 2:
126 keyRadio1->setChecked(true); 126 keyRadio1->setChecked(true);
127 break; 127 break;
128 case 3: 128 case 3:
129 keyRadio2->setChecked(true); 129 keyRadio2->setChecked(true);
130 break; 130 break;
131 case 4: 131 case 4:
132 keyRadio3->setChecked(true); 132 keyRadio3->setChecked(true);
133 break; 133 break;
134 } 134 }
135 } else { 135 } else {
136 // key 136 // key
137 key = (*it); 137 key = (*it);
138 } 138 }
139 if (! key.isNull()) { 139 if (! key.isNull()) {
140 if (enc == -1) 140 if (enc == -1)
141 enc = 1; 141 enc = 1;
142 QStringList::Iterator next = ++it; 142 QStringList::Iterator next = ++it;
143 if (it == keys.end()) { 143 if (it == keys.end()) {
144 break; 144 break;
145 } 145 }
146 if ((*(next)).left(1) == "[") { 146 if ((*(next)).left(1) == "[") {
147 // set key at index 147 // set key at index
148 index = (*(next)).mid(1, 1).toInt(); 148 index = (*(next)).mid(1, 1).toInt();
149 } else { 149 } else {
150 index = 1; 150 index = 1;
151 } 151 }
152 switch (index) { 152 switch (index) {
153 case 1: 153 case 1:
154 keyLineEdit0->setText(key); 154 keyLineEdit0->setText(key);
155 break; 155 break;
156 case 2: 156 case 2:
157 keyLineEdit1->setText(key); 157 keyLineEdit1->setText(key);
158 break; 158 break;
159 case 3: 159 case 3:
160 keyLineEdit2->setText(key); 160 keyLineEdit2->setText(key);
161 break; 161 break;
162 case 4: 162 case 4:
163 keyLineEdit3->setText(key); 163 keyLineEdit3->setText(key);
164 break; 164 break;
165 } 165 }
166 key = QString::null; 166 key = QString::null;
167 } 167 }
168 } 168 }
169 if (enc == 1) { 169 if (enc == 1) {
170 wepEnabled->setChecked(true); 170 wepEnabled->setChecked(true);
171 } else { 171 } else {
172 wepEnabled->setChecked(false); 172 wepEnabled->setChecked(false);
173 } 173 }
174} 174}
175 175
176/** 176/**
177 * Check to see if the current config is valid 177 * Check to see if the current config is valid
178 * Save interfaces 178 * Save interfaces
179 */ 179 */
180void WLANImp::accept() { 180void WLANImp::accept() {
181 if (wepEnabled->isChecked()) { 181 if (wepEnabled->isChecked()) {
182 if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) || 182 if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) ||
183 (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) || 183 (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) ||
184 (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) || 184 (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) ||
185 (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) { 185 (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) {
186 QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok); 186 QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok);
187 return; 187 return;
188 } 188 }
189 } 189 }
190 190
191 if (essid->currentText().isEmpty()) { 191 if (essid->currentText().isEmpty()) {
192 QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok); 192 QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok);
193 return; 193 return;
194 } 194 }
195 195
196 if (specifyAp->isChecked() && macEdit->text().isEmpty()) { 196 if (specifyAp->isChecked() && macEdit->text().isEmpty()) {
197 QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok); 197 QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok);
198 return; 198 return;
199 } 199 }
200 200
201 // Try to save the interfaces settings. 201 // Try to save the interfaces settings.
202 writeOpts(); 202 writeOpts();
203 203
204 // Close out the dialog 204 // Close out the dialog
205 QDialog::accept(); 205 QDialog::accept();
206} 206}
207 207
208void WLANImp::writeOpts() { 208void WLANImp::writeOpts() {
209 bool error = false; 209 bool error = false;
210 210
211 interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); 211 interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText());
212 interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); 212 interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText());
213 213
214 if (specifyAp->isChecked()) { 214 if (specifyAp->isChecked()) {
215 interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); 215 interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text());
216 } else { 216 } else {
217 interfaces->removeInterfaceOption(QString("wireless_ap")); 217 interfaces->removeInterfaceOption(QString("wireless_ap"));
218 } 218 }
219 219
220 if (specifyChan->isChecked()) { 220 if (specifyChan->isChecked()) {
221 interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); 221 interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text());
222 } else { 222 } else {
223 interfaces->removeInterfaceOption(QString("wireless_channel")); 223 interfaces->removeInterfaceOption(QString("wireless_channel"));
224 } 224 }
225 225
226 if (wepEnabled->isChecked()) { 226 if (wepEnabled->isChecked()) {
227 QStringList keyList; 227 QStringList keyList;
228 228
229 if (! keyLineEdit0->text().isNull()) { 229 if (! keyLineEdit0->text().isNull()) {
230 keyList += keyLineEdit0->text(); 230 keyList += keyLineEdit0->text();
231 keyList += "[1]"; 231 keyList += "[1]";
232 } else if (! keyLineEdit1->text().isNull()) { 232 } else if (! keyLineEdit1->text().isNull()) {
233 keyList += keyLineEdit1->text(); 233 keyList += keyLineEdit1->text();
234 keyList += "[2]"; 234 keyList += "[2]";
235 } else if (! keyLineEdit2->text().isNull()) { 235 } else if (! keyLineEdit2->text().isNull()) {
236 keyList += keyLineEdit2->text(); 236 keyList += keyLineEdit2->text();
237 keyList += "[3]"; 237 keyList += "[3]";
238 } else if (! keyLineEdit3->text().isNull()) { 238 } else if (! keyLineEdit3->text().isNull()) {
239 keyList += keyLineEdit3->text(); 239 keyList += keyLineEdit3->text();
240 keyList += "[4]"; 240 keyList += "[4]";
241 } 241 }
242 if (acceptNonEnc->isChecked()) { 242 if (acceptNonEnc->isChecked()) {
243 keyList += "open"; 243 keyList += "open";
244 } else { 244 } else {
245 keyList += "restricted"; 245 keyList += "restricted";
246 } 246 }
247 247
248 keyList += "key"; 248 keyList += "key";
249 if (keyRadio0->isChecked()) { 249 if (keyRadio0->isChecked()) {
250 keyList += "[1]"; 250 keyList += "[1]";
251 } else if (keyRadio1->isChecked()) { 251 } else if (keyRadio1->isChecked()) {
252 keyList += "[2]"; 252 keyList += "[2]";
253 } else if (keyRadio2->isChecked()) { 253 } else if (keyRadio2->isChecked()) {
254 keyList += "[3]"; 254 keyList += "[3]";
255 } else if (keyRadio3->isChecked()) { 255 } else if (keyRadio3->isChecked()) {
256 keyList += "[4]"; 256 keyList += "[4]";
257 } 257 }
258 interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); 258 interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" ")));
259 } else { 259 } else {
260 interfaces->removeInterfaceOption(QString("wireless_key")); 260 interfaces->removeInterfaceOption(QString("wireless_key"));
261 } 261 }
262 interfaces->removeInterfaceOption(QString("wireless_enc")); 262 interfaces->removeInterfaceOption(QString("wireless_enc"));
263 263
264 if(!interfaceSetup->saveChanges()) 264 if(!interfaceSetup->saveChanges())
265 return; 265 return;
266
267 QDialog::accept();
266} 268}