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