summaryrefslogtreecommitdiff
authorbenmeyer <benmeyer>2002-11-04 16:50:27 (UTC)
committer benmeyer <benmeyer>2002-11-04 16:50:27 (UTC)
commitb8d6cf8848e68ab1089d7b94281fa205a13c766f (patch) (unidiff)
tree0e1ad7879401752385a8ca0c9fb733d28e0748b9
parenta59b7fd669c53ece7d4eb56eb5b69d8b5f298048 (diff)
downloadopie-b8d6cf8848e68ab1089d7b94281fa205a13c766f.zip
opie-b8d6cf8848e68ab1089d7b94281fa205a13c766f.tar.gz
opie-b8d6cf8848e68ab1089d7b94281fa205a13c766f.tar.bz2
Removed the Config class. Now parses wireless.opts file directly
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/wlan/wlan.ui199
-rw-r--r--noncore/net/networksetup/wlan/wlanimp.cpp415
-rw-r--r--noncore/net/networksetup/wlan/wlanimp.h13
-rw-r--r--noncore/settings/networksettings/wlan/wlan.ui199
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp.cpp415
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp.h13
6 files changed, 556 insertions, 698 deletions
diff --git a/noncore/net/networksetup/wlan/wlan.ui b/noncore/net/networksetup/wlan/wlan.ui
index 9f33559..1b29a3e 100644
--- a/noncore/net/networksetup/wlan/wlan.ui
+++ b/noncore/net/networksetup/wlan/wlan.ui
@@ -10,9 +10,9 @@
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>250</width> 14 <width>238</width>
15 <height>286</height> 15 <height>286</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
@@ -178,9 +178,9 @@
178 <cstring>network802</cstring> 178 <cstring>network802</cstring>
179 </property> 179 </property>
180 <property stdset="1"> 180 <property stdset="1">
181 <name>text</name> 181 <name>text</name>
182 <string>802.11 Ad-Hoc</string> 182 <string>Ad-Hoc</string>
183 </property> 183 </property>
184 </widget> 184 </widget>
185 <widget row="2" column="1" > 185 <widget row="2" column="1" >
186 <class>QSpinBox</class> 186 <class>QSpinBox</class>
@@ -199,8 +199,12 @@
199 <property stdset="1"> 199 <property stdset="1">
200 <name>minValue</name> 200 <name>minValue</name>
201 <number>1</number> 201 <number>1</number>
202 </property> 202 </property>
203 <property stdset="1">
204 <name>value</name>
205 <number>6</number>
206 </property>
203 </widget> 207 </widget>
204 <spacer row="2" column="2" > 208 <spacer row="2" column="2" >
205 <property> 209 <property>
206 <name>name</name> 210 <name>name</name>
@@ -256,18 +260,80 @@
256 <attribute> 260 <attribute>
257 <name>title</name> 261 <name>title</name>
258 <string>Wep</string> 262 <string>Wep</string>
259 </attribute> 263 </attribute>
260 <grid> 264 <vbox>
261 <property stdset="1"> 265 <property stdset="1">
262 <name>margin</name> 266 <name>margin</name>
263 <number>11</number> 267 <number>11</number>
264 </property> 268 </property>
265 <property stdset="1"> 269 <property stdset="1">
266 <name>spacing</name> 270 <name>spacing</name>
267 <number>6</number> 271 <number>6</number>
268 </property> 272 </property>
269 <widget row="2" column="0" rowspan="1" colspan="2" > 273 <widget>
274 <class>QCheckBox</class>
275 <property stdset="1">
276 <name>name</name>
277 <cstring>wepEnabled</cstring>
278 </property>
279 <property stdset="1">
280 <name>text</name>
281 <string>Enable Wep</string>
282 </property>
283 </widget>
284 <widget>
285 <class>QButtonGroup</class>
286 <property stdset="1">
287 <name>name</name>
288 <cstring>ButtonGroup43</cstring>
289 </property>
290 <property stdset="1">
291 <name>enabled</name>
292 <bool>false</bool>
293 </property>
294 <property stdset="1">
295 <name>title</name>
296 <string>Authentication Type</string>
297 </property>
298 <hbox>
299 <property stdset="1">
300 <name>margin</name>
301 <number>11</number>
302 </property>
303 <property stdset="1">
304 <name>spacing</name>
305 <number>6</number>
306 </property>
307 <widget>
308 <class>QRadioButton</class>
309 <property stdset="1">
310 <name>name</name>
311 <cstring>authOpen</cstring>
312 </property>
313 <property stdset="1">
314 <name>text</name>
315 <string>Open System</string>
316 </property>
317 <property stdset="1">
318 <name>checked</name>
319 <bool>true</bool>
320 </property>
321 </widget>
322 <widget>
323 <class>QRadioButton</class>
324 <property stdset="1">
325 <name>name</name>
326 <cstring>authShared</cstring>
327 </property>
328 <property stdset="1">
329 <name>text</name>
330 <string>Shared Key</string>
331 </property>
332 </widget>
333 </hbox>
334 </widget>
335 <widget>
270 <class>QButtonGroup</class> 336 <class>QButtonGroup</class>
271 <property stdset="1"> 337 <property stdset="1">
272 <name>name</name> 338 <name>name</name>
273 <cstring>ButtonGroup44</cstring> 339 <cstring>ButtonGroup44</cstring>
@@ -366,111 +432,9 @@
366 </property> 432 </property>
367 </widget> 433 </widget>
368 </grid> 434 </grid>
369 </widget> 435 </widget>
370 <widget row="1" column="0" > 436 <spacer>
371 <class>QButtonGroup</class>
372 <property stdset="1">
373 <name>name</name>
374 <cstring>ButtonGroup42</cstring>
375 </property>
376 <property stdset="1">
377 <name>enabled</name>
378 <bool>false</bool>
379 </property>
380 <property stdset="1">
381 <name>title</name>
382 <string>Key Length</string>
383 </property>
384 <vbox>
385 <property stdset="1">
386 <name>margin</name>
387 <number>11</number>
388 </property>
389 <property stdset="1">
390 <name>spacing</name>
391 <number>6</number>
392 </property>
393 <widget>
394 <class>QRadioButton</class>
395 <property stdset="1">
396 <name>name</name>
397 <cstring>key40</cstring>
398 </property>
399 <property stdset="1">
400 <name>text</name>
401 <string>40 Bits</string>
402 </property>
403 <property stdset="1">
404 <name>checked</name>
405 <bool>true</bool>
406 </property>
407 </widget>
408 <widget>
409 <class>QRadioButton</class>
410 <property stdset="1">
411 <name>name</name>
412 <cstring>key128</cstring>
413 </property>
414 <property stdset="1">
415 <name>text</name>
416 <string>128 Bits</string>
417 </property>
418 </widget>
419 </vbox>
420 </widget>
421 <widget row="1" column="1" >
422 <class>QButtonGroup</class>
423 <property stdset="1">
424 <name>name</name>
425 <cstring>ButtonGroup43</cstring>
426 </property>
427 <property stdset="1">
428 <name>enabled</name>
429 <bool>false</bool>
430 </property>
431 <property stdset="1">
432 <name>title</name>
433 <string>Authentication Type</string>
434 </property>
435 <vbox>
436 <property stdset="1">
437 <name>margin</name>
438 <number>11</number>
439 </property>
440 <property stdset="1">
441 <name>spacing</name>
442 <number>6</number>
443 </property>
444 <widget>
445 <class>QRadioButton</class>
446 <property stdset="1">
447 <name>name</name>
448 <cstring>authOpen</cstring>
449 </property>
450 <property stdset="1">
451 <name>text</name>
452 <string>Open System</string>
453 </property>
454 <property stdset="1">
455 <name>checked</name>
456 <bool>true</bool>
457 </property>
458 </widget>
459 <widget>
460 <class>QRadioButton</class>
461 <property stdset="1">
462 <name>name</name>
463 <cstring>authShared</cstring>
464 </property>
465 <property stdset="1">
466 <name>text</name>
467 <string>Shared Key</string>
468 </property>
469 </widget>
470 </vbox>
471 </widget>
472 <spacer row="3" column="1" >
473 <property> 437 <property>
474 <name>name</name> 438 <name>name</name>
475 <cstring>Spacer30</cstring> 439 <cstring>Spacer30</cstring>
476 </property> 440 </property>
@@ -489,20 +453,9 @@
489 <height>20</height> 453 <height>20</height>
490 </size> 454 </size>
491 </property> 455 </property>
492 </spacer> 456 </spacer>
493 <widget row="0" column="0" rowspan="1" colspan="2" > 457 </vbox>
494 <class>QCheckBox</class>
495 <property stdset="1">
496 <name>name</name>
497 <cstring>wepEnabled</cstring>
498 </property>
499 <property stdset="1">
500 <name>text</name>
501 <string>Enable Wep</string>
502 </property>
503 </widget>
504 </grid>
505 </widget> 458 </widget>
506 </widget> 459 </widget>
507 </vbox> 460 </vbox>
508</widget> 461</widget>
@@ -533,14 +486,8 @@
533 </connection> 486 </connection>
534 <connection> 487 <connection>
535 <sender>wepEnabled</sender> 488 <sender>wepEnabled</sender>
536 <signal>toggled(bool)</signal> 489 <signal>toggled(bool)</signal>
537 <receiver>ButtonGroup42</receiver>
538 <slot>setEnabled(bool)</slot>
539 </connection>
540 <connection>
541 <sender>wepEnabled</sender>
542 <signal>toggled(bool)</signal>
543 <receiver>ButtonGroup43</receiver> 490 <receiver>ButtonGroup43</receiver>
544 <slot>setEnabled(bool)</slot> 491 <slot>setEnabled(bool)</slot>
545 </connection> 492 </connection>
546 <connection> 493 <connection>
@@ -555,10 +502,8 @@
555 <tabstop>essNon</tabstop> 502 <tabstop>essNon</tabstop>
556 <tabstop>essSpecificLineEdit</tabstop> 503 <tabstop>essSpecificLineEdit</tabstop>
557 <tabstop>networkInfrastructure</tabstop> 504 <tabstop>networkInfrastructure</tabstop>
558 <tabstop>networkChannel</tabstop> 505 <tabstop>networkChannel</tabstop>
559 <tabstop>key40</tabstop>
560 <tabstop>key128</tabstop>
561 <tabstop>authOpen</tabstop> 506 <tabstop>authOpen</tabstop>
562 <tabstop>authShared</tabstop> 507 <tabstop>authShared</tabstop>
563 <tabstop>keyRadio0</tabstop> 508 <tabstop>keyRadio0</tabstop>
564 <tabstop>keyLineEdit0</tabstop> 509 <tabstop>keyLineEdit0</tabstop>
diff --git a/noncore/net/networksetup/wlan/wlanimp.cpp b/noncore/net/networksetup/wlan/wlanimp.cpp
index 01d7e36..689eae2 100644
--- a/noncore/net/networksetup/wlan/wlanimp.cpp
+++ b/noncore/net/networksetup/wlan/wlanimp.cpp
@@ -1,247 +1,232 @@
1#include "wlanimp.h" 1#include "wlanimp.h"
2#include "interfacesetupimp.h"
2 3
3/* Config class */
4#include <qpe/config.h>
5/* Global namespace */
6#include <qpe/global.h>
7/* system() */
8#include <stdlib.h>
9#include <qfile.h> 4#include <qfile.h>
10#include <qdir.h> 5#include <qdir.h>
11#include <qtextstream.h> 6#include <qtextstream.h>
12#include <qmessagebox.h> 7#include <qmessagebox.h>
13#include <qlineedit.h> 8#include <qlineedit.h>
14#include <qspinbox.h> 9#include <qspinbox.h>
15#include <qradiobutton.h> 10#include <qradiobutton.h>
16#include <qcheckbox.h> 11#include <qcheckbox.h>
17#include <qregexp.h>
18#include <qpe/config.h>
19#include <qtabwidget.h> 12#include <qtabwidget.h>
20#include "interfacesetupimp.h"
21 13
22WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl){ 14/* system() */
23 config = new Config("wireless"); 15#include <stdlib.h>
24 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i);//, Qt::WDestructiveClose);
25 //configure->setProfile(currentProfile);
26 tabWidget->insertTab(interfaceSetup, "TCP/IP");
27 16
28 readConfig(); 17#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts"
29 18
30} 19/**
20 * Constructor, read in the wireless.opts file for parsing later.
21 */
22WLANImp::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);
24 tabWidget->insertTab(interfaceSetup, "TCP/IP");
31 25
32WLANImp::~WLANImp( ){ 26 // Read in the config file.
33 delete config; 27 QString wlanFile = WIRELESS_OPTS;
28 QFile file(wlanFile);
29 if (file.open(IO_ReadOnly)){
30 QTextStream stream( &file );
31 QString line = "";
32 while ( !stream.eof() ) {
33 line += stream.readLine();
34 line += "\n";
35 }
36 file.close();
37 settingsFileText = QStringList::split("\n", line, true);
38 parseSettingFile();
39 }
40 else
41 qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1());
34} 42}
35 43
44/**
45 * Change the profile for both wireless settings and network settings.
46 */
36void WLANImp::setProfile(QString &profile){ 47void WLANImp::setProfile(QString &profile){
37 interfaceSetup->setProfile(profile); 48 interfaceSetup->setProfile(profile);
49 parseSettingFile();
38} 50}
39 51
40void WLANImp::readConfig() 52/**
41{ 53 * Parses the settings file that was read in and gets any setting from it.
42 qWarning( "WLANImp::readConfig() called." ); 54 */
43 config->setGroup( "Properties" ); 55void WLANImp::parseSettingFile(){
44 QString ssid = config->readEntry( "SSID", "any" ); 56 bool foundCase = false;
45 if( ssid == "any" || ssid == "ANY" ){ 57 bool found = false;
46 essNon->setChecked( true ); 58 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
47 } else { 59 QString line = (*it).simplifyWhiteSpace();
48 essSpecific->setChecked( true ); 60 if(line.contains("case"))
49 essSpecificLineEdit->setText( ssid ); 61 foundCase = true;
50 } 62 // See if we found our scheme to write or the sceme couldn't be found
51 QString mode = config->readEntry( "Mode", "Managed" ); 63 if((foundCase && line.contains("esac")) ||
52 if( mode == "adhoc" ) { 64 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#'))
53 network802->setChecked( true ); 65 found = true;
54 } else { 66
55 networkInfrastructure->setChecked( true ); 67 if(line.contains(";;"))
56 } 68 found = false;
57 networkChannel->setValue( config->readNumEntry( "CHANNEL", 1 ) ); 69 if(found){
58// config->readEntry( "RATE", "auto" ); 70 // write out scheme
59 config->readEntry( "dot11PrivacyInvoked" ) == "true" ? wepEnabled->setChecked( true ) : wepEnabled->setChecked( false ); 71 if(line.contains("ESSID=")){
60 config->readEntry( "AuthType", "opensystem" ); 72 QString id = line.mid(line.find("ESSID=")+6, line.length());
61 config->readEntry( "PRIV_KEY128", "false" ) == "false" ? key40->setChecked( true ) : key128->setChecked( true ); 73 if(id == "any"){
62 int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); 74 essNon->setChecked(true);
63 switch( defaultkey ){ 75 essSpecific->setChecked(false);
64 case 0: 76 }else{
65 keyRadio0->setChecked( true ); 77 essSpecific->setChecked(true);
66 break; 78 essSpecificLineEdit->setText(id);
67 case 1: 79 essNon->setChecked(false);
68 keyRadio1->setChecked( true ); 80 }
69 break; 81 }
70 case 2: 82 if(line.contains("MODE=")){
71 keyRadio2->setChecked( true ); 83 QString mode = line.mid(line.find("MODE=")+5, line.length());
72 break; 84 if(mode == "Managed"){
73 case 3: 85 network802->setChecked( false );
74 keyRadio3->setChecked( true ); 86 networkInfrastructure->setChecked( true );
75 break; 87 }
88 else{
89 network802->setChecked( true );
90 networkInfrastructure->setChecked( false );
91 }
92 }
93 if(line.contains("KEY=")){
94 line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false);
95 int s = line.find("KEY=");
96 line = line.mid(s+4, line.length());
97 // Find first Key
98 s = line.find("[1]");
99 if(s != -1){
100 keyLineEdit0->setText(line.mid(0, s));
101 line = line.mid(s+3, line.length());
102 }
103 s = line.find("[2]");
104 if(s != -1){
105 keyLineEdit1->setText(line.mid(0, s));
106 line = line.mid(s+3, line.length());
107 }
108 s = line.find("[3]");
109 if(s != -1){
110 keyLineEdit2->setText(line.mid(0, s));
111 line = line.mid(s+3, line.length());
112 }
113 s = line.find("[4]");
114 if(s != -1){
115 keyLineEdit3->setText(line.mid(0, s));
116 line = line.mid(s+3, line.length());
117 }
118 if(line.contains("key [1]")) keyRadio0->setChecked(true);
119 if(line.contains("key [2]")) keyRadio1->setChecked(true);
120 if(line.contains("key [3]")) keyRadio2->setChecked(true);
121 if(line.contains("key [4]")) keyRadio3->setChecked(true);
122 if(line.contains("open")){
123 authOpen->setChecked(true);
124 authShared->setChecked(false);
125 }
126 else{
127 authOpen->setChecked(false);
128 authShared->setChecked(true);
129 }
130 }
131 if(line.contains("CHANNEL=")){
132 networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt());
133 }
76 } 134 }
77 keyLineEdit0->setText(config->readEntry( "dot11WEPDefaultKey0" )); 135 }
78 keyLineEdit1->setText(config->readEntry( "dot11WEPDefaultKey1" ));
79 keyLineEdit2->setText(config->readEntry( "dot11WEPDefaultKey2" ));
80 keyLineEdit3->setText(config->readEntry( "dot11WEPDefaultKey3" ));
81 return;
82} 136}
83 137
84bool WLANImp::writeConfig() 138/**
85{ 139 * Saves settings to the wireless.opts file using the current profile
86 qWarning( "WLANImp::writeConfig() called." ); 140 */
87 config->setGroup( "Properties" ); 141void WLANImp::changeAndSaveSettingFile(){
88 if( essNon->isChecked() ) { 142 QString wlanFile = WIRELESS_OPTS;
89 config->writeEntry( "SSID", "any" ); 143 QFile::remove(wlanFile);
90 } else { 144 QFile file(wlanFile);
91 config->writeEntry( "SSID", essSpecificLineEdit->text() ); 145
92 } 146 if (!file.open(IO_ReadWrite)){
93 if( networkInfrastructure->isChecked() ){ 147 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1());
94 config->writeEntry( "Mode", "Managed" ); 148 return;
95 } else if( network802->isChecked() ){ 149 }
96 config->writeEntry( "Mode", "adhoc" ); 150
97 } 151 QTextStream stream( &file );
98 config->writeEntry( "CHANNEL", networkChannel->value() ); 152 bool foundCase = false;
99// config->readEntry( "RATE", "auto" ); 153 bool found = false;
100 wepEnabled->isChecked() ? config->writeEntry( "dot11PrivacyInvoked", "true" ) : config->writeEntry( "dot11PrivacyInvoked", "false" ); 154 bool output = true;
101 authOpen->isChecked() ? config->writeEntry( "AuthType", "opensystem" ) : config->writeEntry( "AuthType", "sharedkey" ); 155 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
102 key40->isChecked() ? config->writeEntry( "PRIV_KEY128", "false" ) : config->writeEntry( "PRIV_KEY128", "true" ); 156 QString line = (*it).simplifyWhiteSpace();
103 if( keyRadio0->isChecked() ){ 157 if(line.contains("case"))
104 config->writeEntry( "dot11WEPDefaultKeyID", 0 ); 158 foundCase = true;
105 } else if( keyRadio1->isChecked() ){ 159 // See if we found our scheme to write or the sceme couldn't be found
106 config->writeEntry( "dot11WEPDefaultKeyID", 1 ); 160 if((foundCase && line.contains("esac") && !found) ||
107 } else if( keyRadio2->isChecked() ){ 161 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){
108 config->writeEntry( "dot11WEPDefaultKeyID", 2 ); 162 // write out scheme
109 } else if( keyRadio3->isChecked() ){ 163 found = true;
110 config->writeEntry( "dot11WEPDefaultKeyID", 3 ); 164 output = false;
165
166 if(!line.contains("esac"))
167 stream << line << "\n";
168
169 stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n';
170 stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "AdHoc") << '\n';
171 if(!wepEnabled->isChecked())
172 stream << "#";
173 stream << "\tKEY=";
174 stream << keyLineEdit0->text() << " [1]";
175 stream << keyLineEdit1->text() << " [2]";
176 stream << keyLineEdit2->text() << " [3]";
177 stream << keyLineEdit3->text() << " [4]";
178 stream << " key [";
179 if(keyRadio0->isChecked()) stream << "1]";
180 if(keyRadio1->isChecked()) stream << "2]";
181 if(keyRadio2->isChecked()) stream << "3]";
182 if(keyRadio3->isChecked()) stream << "4]";
183 if(authOpen->isChecked()) stream << " open";
184 stream << "\n";
185 stream << "\tCHANNEL=" << networkChannel->value() << "\n";
186 stream << "\tRATE=auto\n";
187 if(line.contains("esac"))
188 stream << line << "\n";
111 } 189 }
112 config->writeEntry( "dot11WEPDefaultKey0", keyLineEdit0->text() ); 190 if(line.contains(";;"))
113 config->writeEntry( "dot11WEPDefaultKey1", keyLineEdit1->text() ); 191 output = true;
114 config->writeEntry( "dot11WEPDefaultKey2", keyLineEdit2->text() ); 192 if(output)
115 config->writeEntry( "dot11WEPDefaultKey3", keyLineEdit3->text() ); 193 stream << (*it) << '\n';
116 return writeWirelessOpts( ); 194 }
195 file.close();
117} 196}
118 197
119/** 198/**
199 * Check to see if the current config is valid
200 * Save wireless.opts, save interfaces
120 */ 201 */
121void WLANImp::accept() 202void WLANImp::accept(){
122{ 203 if(wepEnabled->isChecked()){
123 if ( writeConfig() ){ 204 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() )
124 if(interfaceSetup->saveChanges()) 205 QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok);
125 QDialog::accept(); 206 return;
126 } 207 }
208
209 // Ok settings are good here, save
210 changeAndSaveSettingFile();
211
212 // Try to save the interfaces settings.
213 if(!interfaceSetup->saveChanges())
214 return;
215
216 // Restart the device now that the settings have changed
217 QString initpath;
218 if( QDir("/etc/rc.d/init.d").exists() )
219 initpath = "/etc/rc.d/init.d";
220 else if( QDir("/etc/init.d").exists() )
221 initpath = "/etc/init.d";
222 if( initpath )
223 system(QString("%1/pcmcia stop").arg(initpath));
224 if( initpath )
225 system(QString("%1/pcmcia start").arg(initpath));
226
227 // Close out the dialog
228 QDialog::accept();
127} 229}
128 230
129bool WLANImp::writeWirelessOpts( QString scheme ) 231// wlanimp.cpp
130{
131 qWarning( "WLANImp::writeWirelessOpts entered." );
132 QString prev = "/etc/pcmcia/wireless.opts";
133 QFile prevFile(prev);
134 if ( !prevFile.open( IO_ReadOnly ) )
135 return false;
136
137 QString tmp = "/etc/pcmcia/wireless.opts-qpe-new";
138 QFile tmpFile(tmp);
139 if ( !tmpFile.open( IO_WriteOnly ) )
140 return false;
141
142 bool retval = true;
143
144 QTextStream in( &prevFile );
145 QTextStream out( &tmpFile );
146
147 config->setGroup("Properties");
148
149 QString line;
150 bool found=false;
151 bool done=false;
152 while ( !in.atEnd() ) {
153 QString line = in.readLine();
154 QString wline = line.simplifyWhiteSpace();
155 if ( !done ) {
156 if ( found ) {
157 // skip existing entry for this scheme, and write our own.
158 if ( wline == ";;" ) {
159 found = false;
160 continue;
161 } else {
162 continue;
163 }
164 } else {
165 if ( wline.left(scheme.length()+7) == scheme + ",*,*,*)" ) {
166 found=true;
167 continue; // skip this line
168 } else if ( wline == "esac" || wline == "*,*,*,*)" ) {
169 // end - add new entry
170 // Not all fields have a GUI, but all are supported
171 // in the letwork configuration files.
172 static const char* txtfields[] = {
173 0
174 };
175 QString readmode = config->readEntry( "Mode", "Managed" );
176 QString mode;
177 if( readmode == "Managed" ){
178 mode = readmode;
179 } else if( readmode == "adhoc" ){
180 mode = "Ad-Hoc";
181 }
182 QString key;
183 if( wepEnabled->isChecked() ){
184 int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 );
185 switch( defaultkey ){
186 case 0:
187 key += keyLineEdit0->text();
188 break;
189 case 1:
190 key += keyLineEdit1->text();
191 break;
192 case 2:
193 key += keyLineEdit2->text();
194 break;
195 case 3:
196 key += keyLineEdit3->text();
197 break;
198 }
199 if( config->readEntry( "AuthType", "opensystem" ) == "opensystem")
200 key += " open";
201 }
202 out << scheme << ",*,*,*)" << "\n"
203 << " ESSID=" << Global::shellQuote( config->readEntry( "SSID", "any" ) ) << "\n"
204 << " MODE=" << mode << "\n"
205 << " KEY=" << Global::shellQuote( key ) << "\n"
206 << " RATE=" << "auto" << "\n"
207 ;
208 if( mode != "Managed" )
209 out << " CHANNEL=" << config->readNumEntry( "CHANNEL", 1 ) << "\n";
210 const char** f = txtfields;
211 while (*f) {
212 out << " " << *f << "=" << config->readEntry(*f,"") << "\n";
213 ++f;
214 }
215 out << " ;;\n";
216 done = true;
217 }
218 }
219 }
220 out << line << "\n";
221 }
222 232
223 prevFile.close();
224 tmpFile.close();
225 QString initpath;
226 //system("cardctl suspend");
227 if( QDir("/etc/rc.d/init.d").exists() ){
228 initpath = "/etc/rc.d/init.d";
229 } else if( QDir("/etc/init.d").exists() ){
230 initpath = "/etc/init.d";
231 }
232 if( initpath )
233 system(QString("%1/pcmcia stop").arg(initpath));
234
235 if( system( "mv " + tmp + " " + prev ) )
236 retval = false;
237//#ifdef USE_SCHEMES
238// if ( retval )
239 //SchemeChanger::changeScheme(scheme);
240//#endif
241
242 //system("cardctl resume");
243 if( initpath )
244 system(QString("%1/pcmcia start").arg(initpath));
245
246 return retval;
247}
diff --git a/noncore/net/networksetup/wlan/wlanimp.h b/noncore/net/networksetup/wlan/wlanimp.h
index faa1674..f88e550 100644
--- a/noncore/net/networksetup/wlan/wlanimp.h
+++ b/noncore/net/networksetup/wlan/wlanimp.h
@@ -1,8 +1,9 @@
1#ifndef WLANIMP_H 1#ifndef WLANIMP_H
2#define WLANIMP_H 2#define WLANIMP_H
3 3
4#include "wlan.h" 4#include "wlan.h"
5#include <qstringlist.h>
5 6
6class InterfaceSetupImp; 7class InterfaceSetupImp;
7class Interface; 8class Interface;
8class Config; 9class Config;
@@ -11,22 +12,20 @@ class WLANImp : public WLAN {
11 Q_OBJECT 12 Q_OBJECT
12 13
13public: 14public:
14 WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); 15 WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 );
15 ~WLANImp( );
16 void setProfile(QString &profile); 16 void setProfile(QString &profile);
17 17
18protected: 18protected:
19 void accept(); 19 void accept();
20 20
21private: 21private:
22 void readConfig(); 22 void parseSettingFile();
23 bool writeConfig(); 23 void changeAndSaveSettingFile();
24 bool writeWirelessOpts( QString scheme = "*" ); 24
25 bool writeWlanngOpts( QString scheme = "*" );
26 Config* config;
27 InterfaceSetupImp *interfaceSetup; 25 InterfaceSetupImp *interfaceSetup;
28 26 QStringList settingsFileText;
27 QString currentProfile;
29}; 28};
30 29
31#endif 30#endif
32 31
diff --git a/noncore/settings/networksettings/wlan/wlan.ui b/noncore/settings/networksettings/wlan/wlan.ui
index 9f33559..1b29a3e 100644
--- a/noncore/settings/networksettings/wlan/wlan.ui
+++ b/noncore/settings/networksettings/wlan/wlan.ui
@@ -10,9 +10,9 @@
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>250</width> 14 <width>238</width>
15 <height>286</height> 15 <height>286</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
@@ -178,9 +178,9 @@
178 <cstring>network802</cstring> 178 <cstring>network802</cstring>
179 </property> 179 </property>
180 <property stdset="1"> 180 <property stdset="1">
181 <name>text</name> 181 <name>text</name>
182 <string>802.11 Ad-Hoc</string> 182 <string>Ad-Hoc</string>
183 </property> 183 </property>
184 </widget> 184 </widget>
185 <widget row="2" column="1" > 185 <widget row="2" column="1" >
186 <class>QSpinBox</class> 186 <class>QSpinBox</class>
@@ -199,8 +199,12 @@
199 <property stdset="1"> 199 <property stdset="1">
200 <name>minValue</name> 200 <name>minValue</name>
201 <number>1</number> 201 <number>1</number>
202 </property> 202 </property>
203 <property stdset="1">
204 <name>value</name>
205 <number>6</number>
206 </property>
203 </widget> 207 </widget>
204 <spacer row="2" column="2" > 208 <spacer row="2" column="2" >
205 <property> 209 <property>
206 <name>name</name> 210 <name>name</name>
@@ -256,18 +260,80 @@
256 <attribute> 260 <attribute>
257 <name>title</name> 261 <name>title</name>
258 <string>Wep</string> 262 <string>Wep</string>
259 </attribute> 263 </attribute>
260 <grid> 264 <vbox>
261 <property stdset="1"> 265 <property stdset="1">
262 <name>margin</name> 266 <name>margin</name>
263 <number>11</number> 267 <number>11</number>
264 </property> 268 </property>
265 <property stdset="1"> 269 <property stdset="1">
266 <name>spacing</name> 270 <name>spacing</name>
267 <number>6</number> 271 <number>6</number>
268 </property> 272 </property>
269 <widget row="2" column="0" rowspan="1" colspan="2" > 273 <widget>
274 <class>QCheckBox</class>
275 <property stdset="1">
276 <name>name</name>
277 <cstring>wepEnabled</cstring>
278 </property>
279 <property stdset="1">
280 <name>text</name>
281 <string>Enable Wep</string>
282 </property>
283 </widget>
284 <widget>
285 <class>QButtonGroup</class>
286 <property stdset="1">
287 <name>name</name>
288 <cstring>ButtonGroup43</cstring>
289 </property>
290 <property stdset="1">
291 <name>enabled</name>
292 <bool>false</bool>
293 </property>
294 <property stdset="1">
295 <name>title</name>
296 <string>Authentication Type</string>
297 </property>
298 <hbox>
299 <property stdset="1">
300 <name>margin</name>
301 <number>11</number>
302 </property>
303 <property stdset="1">
304 <name>spacing</name>
305 <number>6</number>
306 </property>
307 <widget>
308 <class>QRadioButton</class>
309 <property stdset="1">
310 <name>name</name>
311 <cstring>authOpen</cstring>
312 </property>
313 <property stdset="1">
314 <name>text</name>
315 <string>Open System</string>
316 </property>
317 <property stdset="1">
318 <name>checked</name>
319 <bool>true</bool>
320 </property>
321 </widget>
322 <widget>
323 <class>QRadioButton</class>
324 <property stdset="1">
325 <name>name</name>
326 <cstring>authShared</cstring>
327 </property>
328 <property stdset="1">
329 <name>text</name>
330 <string>Shared Key</string>
331 </property>
332 </widget>
333 </hbox>
334 </widget>
335 <widget>
270 <class>QButtonGroup</class> 336 <class>QButtonGroup</class>
271 <property stdset="1"> 337 <property stdset="1">
272 <name>name</name> 338 <name>name</name>
273 <cstring>ButtonGroup44</cstring> 339 <cstring>ButtonGroup44</cstring>
@@ -366,111 +432,9 @@
366 </property> 432 </property>
367 </widget> 433 </widget>
368 </grid> 434 </grid>
369 </widget> 435 </widget>
370 <widget row="1" column="0" > 436 <spacer>
371 <class>QButtonGroup</class>
372 <property stdset="1">
373 <name>name</name>
374 <cstring>ButtonGroup42</cstring>
375 </property>
376 <property stdset="1">
377 <name>enabled</name>
378 <bool>false</bool>
379 </property>
380 <property stdset="1">
381 <name>title</name>
382 <string>Key Length</string>
383 </property>
384 <vbox>
385 <property stdset="1">
386 <name>margin</name>
387 <number>11</number>
388 </property>
389 <property stdset="1">
390 <name>spacing</name>
391 <number>6</number>
392 </property>
393 <widget>
394 <class>QRadioButton</class>
395 <property stdset="1">
396 <name>name</name>
397 <cstring>key40</cstring>
398 </property>
399 <property stdset="1">
400 <name>text</name>
401 <string>40 Bits</string>
402 </property>
403 <property stdset="1">
404 <name>checked</name>
405 <bool>true</bool>
406 </property>
407 </widget>
408 <widget>
409 <class>QRadioButton</class>
410 <property stdset="1">
411 <name>name</name>
412 <cstring>key128</cstring>
413 </property>
414 <property stdset="1">
415 <name>text</name>
416 <string>128 Bits</string>
417 </property>
418 </widget>
419 </vbox>
420 </widget>
421 <widget row="1" column="1" >
422 <class>QButtonGroup</class>
423 <property stdset="1">
424 <name>name</name>
425 <cstring>ButtonGroup43</cstring>
426 </property>
427 <property stdset="1">
428 <name>enabled</name>
429 <bool>false</bool>
430 </property>
431 <property stdset="1">
432 <name>title</name>
433 <string>Authentication Type</string>
434 </property>
435 <vbox>
436 <property stdset="1">
437 <name>margin</name>
438 <number>11</number>
439 </property>
440 <property stdset="1">
441 <name>spacing</name>
442 <number>6</number>
443 </property>
444 <widget>
445 <class>QRadioButton</class>
446 <property stdset="1">
447 <name>name</name>
448 <cstring>authOpen</cstring>
449 </property>
450 <property stdset="1">
451 <name>text</name>
452 <string>Open System</string>
453 </property>
454 <property stdset="1">
455 <name>checked</name>
456 <bool>true</bool>
457 </property>
458 </widget>
459 <widget>
460 <class>QRadioButton</class>
461 <property stdset="1">
462 <name>name</name>
463 <cstring>authShared</cstring>
464 </property>
465 <property stdset="1">
466 <name>text</name>
467 <string>Shared Key</string>
468 </property>
469 </widget>
470 </vbox>
471 </widget>
472 <spacer row="3" column="1" >
473 <property> 437 <property>
474 <name>name</name> 438 <name>name</name>
475 <cstring>Spacer30</cstring> 439 <cstring>Spacer30</cstring>
476 </property> 440 </property>
@@ -489,20 +453,9 @@
489 <height>20</height> 453 <height>20</height>
490 </size> 454 </size>
491 </property> 455 </property>
492 </spacer> 456 </spacer>
493 <widget row="0" column="0" rowspan="1" colspan="2" > 457 </vbox>
494 <class>QCheckBox</class>
495 <property stdset="1">
496 <name>name</name>
497 <cstring>wepEnabled</cstring>
498 </property>
499 <property stdset="1">
500 <name>text</name>
501 <string>Enable Wep</string>
502 </property>
503 </widget>
504 </grid>
505 </widget> 458 </widget>
506 </widget> 459 </widget>
507 </vbox> 460 </vbox>
508</widget> 461</widget>
@@ -533,14 +486,8 @@
533 </connection> 486 </connection>
534 <connection> 487 <connection>
535 <sender>wepEnabled</sender> 488 <sender>wepEnabled</sender>
536 <signal>toggled(bool)</signal> 489 <signal>toggled(bool)</signal>
537 <receiver>ButtonGroup42</receiver>
538 <slot>setEnabled(bool)</slot>
539 </connection>
540 <connection>
541 <sender>wepEnabled</sender>
542 <signal>toggled(bool)</signal>
543 <receiver>ButtonGroup43</receiver> 490 <receiver>ButtonGroup43</receiver>
544 <slot>setEnabled(bool)</slot> 491 <slot>setEnabled(bool)</slot>
545 </connection> 492 </connection>
546 <connection> 493 <connection>
@@ -555,10 +502,8 @@
555 <tabstop>essNon</tabstop> 502 <tabstop>essNon</tabstop>
556 <tabstop>essSpecificLineEdit</tabstop> 503 <tabstop>essSpecificLineEdit</tabstop>
557 <tabstop>networkInfrastructure</tabstop> 504 <tabstop>networkInfrastructure</tabstop>
558 <tabstop>networkChannel</tabstop> 505 <tabstop>networkChannel</tabstop>
559 <tabstop>key40</tabstop>
560 <tabstop>key128</tabstop>
561 <tabstop>authOpen</tabstop> 506 <tabstop>authOpen</tabstop>
562 <tabstop>authShared</tabstop> 507 <tabstop>authShared</tabstop>
563 <tabstop>keyRadio0</tabstop> 508 <tabstop>keyRadio0</tabstop>
564 <tabstop>keyLineEdit0</tabstop> 509 <tabstop>keyLineEdit0</tabstop>
diff --git a/noncore/settings/networksettings/wlan/wlanimp.cpp b/noncore/settings/networksettings/wlan/wlanimp.cpp
index 01d7e36..689eae2 100644
--- a/noncore/settings/networksettings/wlan/wlanimp.cpp
+++ b/noncore/settings/networksettings/wlan/wlanimp.cpp
@@ -1,247 +1,232 @@
1#include "wlanimp.h" 1#include "wlanimp.h"
2#include "interfacesetupimp.h"
2 3
3/* Config class */
4#include <qpe/config.h>
5/* Global namespace */
6#include <qpe/global.h>
7/* system() */
8#include <stdlib.h>
9#include <qfile.h> 4#include <qfile.h>
10#include <qdir.h> 5#include <qdir.h>
11#include <qtextstream.h> 6#include <qtextstream.h>
12#include <qmessagebox.h> 7#include <qmessagebox.h>
13#include <qlineedit.h> 8#include <qlineedit.h>
14#include <qspinbox.h> 9#include <qspinbox.h>
15#include <qradiobutton.h> 10#include <qradiobutton.h>
16#include <qcheckbox.h> 11#include <qcheckbox.h>
17#include <qregexp.h>
18#include <qpe/config.h>
19#include <qtabwidget.h> 12#include <qtabwidget.h>
20#include "interfacesetupimp.h"
21 13
22WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl){ 14/* system() */
23 config = new Config("wireless"); 15#include <stdlib.h>
24 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i);//, Qt::WDestructiveClose);
25 //configure->setProfile(currentProfile);
26 tabWidget->insertTab(interfaceSetup, "TCP/IP");
27 16
28 readConfig(); 17#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts"
29 18
30} 19/**
20 * Constructor, read in the wireless.opts file for parsing later.
21 */
22WLANImp::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);
24 tabWidget->insertTab(interfaceSetup, "TCP/IP");
31 25
32WLANImp::~WLANImp( ){ 26 // Read in the config file.
33 delete config; 27 QString wlanFile = WIRELESS_OPTS;
28 QFile file(wlanFile);
29 if (file.open(IO_ReadOnly)){
30 QTextStream stream( &file );
31 QString line = "";
32 while ( !stream.eof() ) {
33 line += stream.readLine();
34 line += "\n";
35 }
36 file.close();
37 settingsFileText = QStringList::split("\n", line, true);
38 parseSettingFile();
39 }
40 else
41 qDebug(QString("WLANImp: Can't open file: %1 for reading.").arg(wlanFile).latin1());
34} 42}
35 43
44/**
45 * Change the profile for both wireless settings and network settings.
46 */
36void WLANImp::setProfile(QString &profile){ 47void WLANImp::setProfile(QString &profile){
37 interfaceSetup->setProfile(profile); 48 interfaceSetup->setProfile(profile);
49 parseSettingFile();
38} 50}
39 51
40void WLANImp::readConfig() 52/**
41{ 53 * Parses the settings file that was read in and gets any setting from it.
42 qWarning( "WLANImp::readConfig() called." ); 54 */
43 config->setGroup( "Properties" ); 55void WLANImp::parseSettingFile(){
44 QString ssid = config->readEntry( "SSID", "any" ); 56 bool foundCase = false;
45 if( ssid == "any" || ssid == "ANY" ){ 57 bool found = false;
46 essNon->setChecked( true ); 58 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
47 } else { 59 QString line = (*it).simplifyWhiteSpace();
48 essSpecific->setChecked( true ); 60 if(line.contains("case"))
49 essSpecificLineEdit->setText( ssid ); 61 foundCase = true;
50 } 62 // See if we found our scheme to write or the sceme couldn't be found
51 QString mode = config->readEntry( "Mode", "Managed" ); 63 if((foundCase && line.contains("esac")) ||
52 if( mode == "adhoc" ) { 64 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#'))
53 network802->setChecked( true ); 65 found = true;
54 } else { 66
55 networkInfrastructure->setChecked( true ); 67 if(line.contains(";;"))
56 } 68 found = false;
57 networkChannel->setValue( config->readNumEntry( "CHANNEL", 1 ) ); 69 if(found){
58// config->readEntry( "RATE", "auto" ); 70 // write out scheme
59 config->readEntry( "dot11PrivacyInvoked" ) == "true" ? wepEnabled->setChecked( true ) : wepEnabled->setChecked( false ); 71 if(line.contains("ESSID=")){
60 config->readEntry( "AuthType", "opensystem" ); 72 QString id = line.mid(line.find("ESSID=")+6, line.length());
61 config->readEntry( "PRIV_KEY128", "false" ) == "false" ? key40->setChecked( true ) : key128->setChecked( true ); 73 if(id == "any"){
62 int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); 74 essNon->setChecked(true);
63 switch( defaultkey ){ 75 essSpecific->setChecked(false);
64 case 0: 76 }else{
65 keyRadio0->setChecked( true ); 77 essSpecific->setChecked(true);
66 break; 78 essSpecificLineEdit->setText(id);
67 case 1: 79 essNon->setChecked(false);
68 keyRadio1->setChecked( true ); 80 }
69 break; 81 }
70 case 2: 82 if(line.contains("MODE=")){
71 keyRadio2->setChecked( true ); 83 QString mode = line.mid(line.find("MODE=")+5, line.length());
72 break; 84 if(mode == "Managed"){
73 case 3: 85 network802->setChecked( false );
74 keyRadio3->setChecked( true ); 86 networkInfrastructure->setChecked( true );
75 break; 87 }
88 else{
89 network802->setChecked( true );
90 networkInfrastructure->setChecked( false );
91 }
92 }
93 if(line.contains("KEY=")){
94 line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false);
95 int s = line.find("KEY=");
96 line = line.mid(s+4, line.length());
97 // Find first Key
98 s = line.find("[1]");
99 if(s != -1){
100 keyLineEdit0->setText(line.mid(0, s));
101 line = line.mid(s+3, line.length());
102 }
103 s = line.find("[2]");
104 if(s != -1){
105 keyLineEdit1->setText(line.mid(0, s));
106 line = line.mid(s+3, line.length());
107 }
108 s = line.find("[3]");
109 if(s != -1){
110 keyLineEdit2->setText(line.mid(0, s));
111 line = line.mid(s+3, line.length());
112 }
113 s = line.find("[4]");
114 if(s != -1){
115 keyLineEdit3->setText(line.mid(0, s));
116 line = line.mid(s+3, line.length());
117 }
118 if(line.contains("key [1]")) keyRadio0->setChecked(true);
119 if(line.contains("key [2]")) keyRadio1->setChecked(true);
120 if(line.contains("key [3]")) keyRadio2->setChecked(true);
121 if(line.contains("key [4]")) keyRadio3->setChecked(true);
122 if(line.contains("open")){
123 authOpen->setChecked(true);
124 authShared->setChecked(false);
125 }
126 else{
127 authOpen->setChecked(false);
128 authShared->setChecked(true);
129 }
130 }
131 if(line.contains("CHANNEL=")){
132 networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt());
133 }
76 } 134 }
77 keyLineEdit0->setText(config->readEntry( "dot11WEPDefaultKey0" )); 135 }
78 keyLineEdit1->setText(config->readEntry( "dot11WEPDefaultKey1" ));
79 keyLineEdit2->setText(config->readEntry( "dot11WEPDefaultKey2" ));
80 keyLineEdit3->setText(config->readEntry( "dot11WEPDefaultKey3" ));
81 return;
82} 136}
83 137
84bool WLANImp::writeConfig() 138/**
85{ 139 * Saves settings to the wireless.opts file using the current profile
86 qWarning( "WLANImp::writeConfig() called." ); 140 */
87 config->setGroup( "Properties" ); 141void WLANImp::changeAndSaveSettingFile(){
88 if( essNon->isChecked() ) { 142 QString wlanFile = WIRELESS_OPTS;
89 config->writeEntry( "SSID", "any" ); 143 QFile::remove(wlanFile);
90 } else { 144 QFile file(wlanFile);
91 config->writeEntry( "SSID", essSpecificLineEdit->text() ); 145
92 } 146 if (!file.open(IO_ReadWrite)){
93 if( networkInfrastructure->isChecked() ){ 147 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1());
94 config->writeEntry( "Mode", "Managed" ); 148 return;
95 } else if( network802->isChecked() ){ 149 }
96 config->writeEntry( "Mode", "adhoc" ); 150
97 } 151 QTextStream stream( &file );
98 config->writeEntry( "CHANNEL", networkChannel->value() ); 152 bool foundCase = false;
99// config->readEntry( "RATE", "auto" ); 153 bool found = false;
100 wepEnabled->isChecked() ? config->writeEntry( "dot11PrivacyInvoked", "true" ) : config->writeEntry( "dot11PrivacyInvoked", "false" ); 154 bool output = true;
101 authOpen->isChecked() ? config->writeEntry( "AuthType", "opensystem" ) : config->writeEntry( "AuthType", "sharedkey" ); 155 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
102 key40->isChecked() ? config->writeEntry( "PRIV_KEY128", "false" ) : config->writeEntry( "PRIV_KEY128", "true" ); 156 QString line = (*it).simplifyWhiteSpace();
103 if( keyRadio0->isChecked() ){ 157 if(line.contains("case"))
104 config->writeEntry( "dot11WEPDefaultKeyID", 0 ); 158 foundCase = true;
105 } else if( keyRadio1->isChecked() ){ 159 // See if we found our scheme to write or the sceme couldn't be found
106 config->writeEntry( "dot11WEPDefaultKeyID", 1 ); 160 if((foundCase && line.contains("esac") && !found) ||
107 } else if( keyRadio2->isChecked() ){ 161 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){
108 config->writeEntry( "dot11WEPDefaultKeyID", 2 ); 162 // write out scheme
109 } else if( keyRadio3->isChecked() ){ 163 found = true;
110 config->writeEntry( "dot11WEPDefaultKeyID", 3 ); 164 output = false;
165
166 if(!line.contains("esac"))
167 stream << line << "\n";
168
169 stream << "\tESSID=" << (essNon->isChecked() == true ? QString("any") : essSpecificLineEdit->text()) << '\n';
170 stream << "\tMODE=" << (networkInfrastructure->isChecked() == true ? "Managed" : "AdHoc") << '\n';
171 if(!wepEnabled->isChecked())
172 stream << "#";
173 stream << "\tKEY=";
174 stream << keyLineEdit0->text() << " [1]";
175 stream << keyLineEdit1->text() << " [2]";
176 stream << keyLineEdit2->text() << " [3]";
177 stream << keyLineEdit3->text() << " [4]";
178 stream << " key [";
179 if(keyRadio0->isChecked()) stream << "1]";
180 if(keyRadio1->isChecked()) stream << "2]";
181 if(keyRadio2->isChecked()) stream << "3]";
182 if(keyRadio3->isChecked()) stream << "4]";
183 if(authOpen->isChecked()) stream << " open";
184 stream << "\n";
185 stream << "\tCHANNEL=" << networkChannel->value() << "\n";
186 stream << "\tRATE=auto\n";
187 if(line.contains("esac"))
188 stream << line << "\n";
111 } 189 }
112 config->writeEntry( "dot11WEPDefaultKey0", keyLineEdit0->text() ); 190 if(line.contains(";;"))
113 config->writeEntry( "dot11WEPDefaultKey1", keyLineEdit1->text() ); 191 output = true;
114 config->writeEntry( "dot11WEPDefaultKey2", keyLineEdit2->text() ); 192 if(output)
115 config->writeEntry( "dot11WEPDefaultKey3", keyLineEdit3->text() ); 193 stream << (*it) << '\n';
116 return writeWirelessOpts( ); 194 }
195 file.close();
117} 196}
118 197
119/** 198/**
199 * Check to see if the current config is valid
200 * Save wireless.opts, save interfaces
120 */ 201 */
121void WLANImp::accept() 202void WLANImp::accept(){
122{ 203 if(wepEnabled->isChecked()){
123 if ( writeConfig() ){ 204 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() )
124 if(interfaceSetup->saveChanges()) 205 QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok);
125 QDialog::accept(); 206 return;
126 } 207 }
208
209 // Ok settings are good here, save
210 changeAndSaveSettingFile();
211
212 // Try to save the interfaces settings.
213 if(!interfaceSetup->saveChanges())
214 return;
215
216 // Restart the device now that the settings have changed
217 QString initpath;
218 if( QDir("/etc/rc.d/init.d").exists() )
219 initpath = "/etc/rc.d/init.d";
220 else if( QDir("/etc/init.d").exists() )
221 initpath = "/etc/init.d";
222 if( initpath )
223 system(QString("%1/pcmcia stop").arg(initpath));
224 if( initpath )
225 system(QString("%1/pcmcia start").arg(initpath));
226
227 // Close out the dialog
228 QDialog::accept();
127} 229}
128 230
129bool WLANImp::writeWirelessOpts( QString scheme ) 231// wlanimp.cpp
130{
131 qWarning( "WLANImp::writeWirelessOpts entered." );
132 QString prev = "/etc/pcmcia/wireless.opts";
133 QFile prevFile(prev);
134 if ( !prevFile.open( IO_ReadOnly ) )
135 return false;
136
137 QString tmp = "/etc/pcmcia/wireless.opts-qpe-new";
138 QFile tmpFile(tmp);
139 if ( !tmpFile.open( IO_WriteOnly ) )
140 return false;
141
142 bool retval = true;
143
144 QTextStream in( &prevFile );
145 QTextStream out( &tmpFile );
146
147 config->setGroup("Properties");
148
149 QString line;
150 bool found=false;
151 bool done=false;
152 while ( !in.atEnd() ) {
153 QString line = in.readLine();
154 QString wline = line.simplifyWhiteSpace();
155 if ( !done ) {
156 if ( found ) {
157 // skip existing entry for this scheme, and write our own.
158 if ( wline == ";;" ) {
159 found = false;
160 continue;
161 } else {
162 continue;
163 }
164 } else {
165 if ( wline.left(scheme.length()+7) == scheme + ",*,*,*)" ) {
166 found=true;
167 continue; // skip this line
168 } else if ( wline == "esac" || wline == "*,*,*,*)" ) {
169 // end - add new entry
170 // Not all fields have a GUI, but all are supported
171 // in the letwork configuration files.
172 static const char* txtfields[] = {
173 0
174 };
175 QString readmode = config->readEntry( "Mode", "Managed" );
176 QString mode;
177 if( readmode == "Managed" ){
178 mode = readmode;
179 } else if( readmode == "adhoc" ){
180 mode = "Ad-Hoc";
181 }
182 QString key;
183 if( wepEnabled->isChecked() ){
184 int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 );
185 switch( defaultkey ){
186 case 0:
187 key += keyLineEdit0->text();
188 break;
189 case 1:
190 key += keyLineEdit1->text();
191 break;
192 case 2:
193 key += keyLineEdit2->text();
194 break;
195 case 3:
196 key += keyLineEdit3->text();
197 break;
198 }
199 if( config->readEntry( "AuthType", "opensystem" ) == "opensystem")
200 key += " open";
201 }
202 out << scheme << ",*,*,*)" << "\n"
203 << " ESSID=" << Global::shellQuote( config->readEntry( "SSID", "any" ) ) << "\n"
204 << " MODE=" << mode << "\n"
205 << " KEY=" << Global::shellQuote( key ) << "\n"
206 << " RATE=" << "auto" << "\n"
207 ;
208 if( mode != "Managed" )
209 out << " CHANNEL=" << config->readNumEntry( "CHANNEL", 1 ) << "\n";
210 const char** f = txtfields;
211 while (*f) {
212 out << " " << *f << "=" << config->readEntry(*f,"") << "\n";
213 ++f;
214 }
215 out << " ;;\n";
216 done = true;
217 }
218 }
219 }
220 out << line << "\n";
221 }
222 232
223 prevFile.close();
224 tmpFile.close();
225 QString initpath;
226 //system("cardctl suspend");
227 if( QDir("/etc/rc.d/init.d").exists() ){
228 initpath = "/etc/rc.d/init.d";
229 } else if( QDir("/etc/init.d").exists() ){
230 initpath = "/etc/init.d";
231 }
232 if( initpath )
233 system(QString("%1/pcmcia stop").arg(initpath));
234
235 if( system( "mv " + tmp + " " + prev ) )
236 retval = false;
237//#ifdef USE_SCHEMES
238// if ( retval )
239 //SchemeChanger::changeScheme(scheme);
240//#endif
241
242 //system("cardctl resume");
243 if( initpath )
244 system(QString("%1/pcmcia start").arg(initpath));
245
246 return retval;
247}
diff --git a/noncore/settings/networksettings/wlan/wlanimp.h b/noncore/settings/networksettings/wlan/wlanimp.h
index faa1674..f88e550 100644
--- a/noncore/settings/networksettings/wlan/wlanimp.h
+++ b/noncore/settings/networksettings/wlan/wlanimp.h
@@ -1,8 +1,9 @@
1#ifndef WLANIMP_H 1#ifndef WLANIMP_H
2#define WLANIMP_H 2#define WLANIMP_H
3 3
4#include "wlan.h" 4#include "wlan.h"
5#include <qstringlist.h>
5 6
6class InterfaceSetupImp; 7class InterfaceSetupImp;
7class Interface; 8class Interface;
8class Config; 9class Config;
@@ -11,22 +12,20 @@ class WLANImp : public WLAN {
11 Q_OBJECT 12 Q_OBJECT
12 13
13public: 14public:
14 WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); 15 WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 );
15 ~WLANImp( );
16 void setProfile(QString &profile); 16 void setProfile(QString &profile);
17 17
18protected: 18protected:
19 void accept(); 19 void accept();
20 20
21private: 21private:
22 void readConfig(); 22 void parseSettingFile();
23 bool writeConfig(); 23 void changeAndSaveSettingFile();
24 bool writeWirelessOpts( QString scheme = "*" ); 24
25 bool writeWlanngOpts( QString scheme = "*" );
26 Config* config;
27 InterfaceSetupImp *interfaceSetup; 25 InterfaceSetupImp *interfaceSetup;
28 26 QStringList settingsFileText;
27 QString currentProfile;
29}; 28};
30 29
31#endif 30#endif
32 31