summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/networksetup/wlan/wlan.ui199
-rw-r--r--noncore/net/networksetup/wlan/wlanimp.cpp385
-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.cpp385
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp.h13
6 files changed, 526 insertions, 668 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
@@ -11,7 +11,7 @@
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>
@@ -179,7 +179,7 @@
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" >
@@ -200,6 +200,10 @@
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>
@@ -257,7 +261,7 @@
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>
@@ -266,7 +270,69 @@
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>
@@ -367,109 +433,7 @@
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>
@@ -490,18 +454,7 @@
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>
@@ -534,12 +487,6 @@
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>
@@ -556,8 +503,6 @@
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>
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,11 +1,6 @@
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>
@@ -14,234 +9,224 @@
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;
58 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
59 QString line = (*it).simplifyWhiteSpace();
60 if(line.contains("case"))
61 foundCase = true;
62 // See if we found our scheme to write or the sceme couldn't be found
63 if((foundCase && line.contains("esac")) ||
64 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#'))
65 found = true;
66
67 if(line.contains(";;"))
68 found = false;
69 if(found){
70 // write out scheme
71 if(line.contains("ESSID=")){
72 QString id = line.mid(line.find("ESSID=")+6, line.length());
73 if(id == "any"){
46 essNon->setChecked( true ); 74 essNon->setChecked( true );
75 essSpecific->setChecked(false);
47 } else { 76 } else {
48 essSpecific->setChecked( true ); 77 essSpecific->setChecked( true );
49 essSpecificLineEdit->setText( ssid ); 78 essSpecificLineEdit->setText(id);
79 essNon->setChecked(false);
50 } 80 }
51 QString mode = config->readEntry( "Mode", "Managed" ); 81 }
52 if( mode == "adhoc" ) { 82 if(line.contains("MODE=")){
53 network802->setChecked( true ); 83 QString mode = line.mid(line.find("MODE=")+5, line.length());
54 } else { 84 if(mode == "Managed"){
85 network802->setChecked( false );
55 networkInfrastructure->setChecked( true ); 86 networkInfrastructure->setChecked( true );
56 } 87 }
57 networkChannel->setValue( config->readNumEntry( "CHANNEL", 1 ) ); 88 else{
58// config->readEntry( "RATE", "auto" ); 89 network802->setChecked( true );
59 config->readEntry( "dot11PrivacyInvoked" ) == "true" ? wepEnabled->setChecked( true ) : wepEnabled->setChecked( false ); 90 networkInfrastructure->setChecked( false );
60 config->readEntry( "AuthType", "opensystem" ); 91 }
61 config->readEntry( "PRIV_KEY128", "false" ) == "false" ? key40->setChecked( true ) : key128->setChecked( true ); 92 }
62 int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); 93 if(line.contains("KEY=")){
63 switch( defaultkey ){ 94 line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false);
64 case 0: 95 int s = line.find("KEY=");
65 keyRadio0->setChecked( true ); 96 line = line.mid(s+4, line.length());
66 break; 97 // Find first Key
67 case 1: 98 s = line.find("[1]");
68 keyRadio1->setChecked( true ); 99 if(s != -1){
69 break; 100 keyLineEdit0->setText(line.mid(0, s));
70 case 2: 101 line = line.mid(s+3, line.length());
71 keyRadio2->setChecked( true ); 102 }
72 break; 103 s = line.find("[2]");
73 case 3: 104 if(s != -1){
74 keyRadio3->setChecked( true ); 105 keyLineEdit1->setText(line.mid(0, s));
75 break; 106 line = line.mid(s+3, line.length());
76 } 107 }
77 keyLineEdit0->setText(config->readEntry( "dot11WEPDefaultKey0" )); 108 s = line.find("[3]");
78 keyLineEdit1->setText(config->readEntry( "dot11WEPDefaultKey1" )); 109 if(s != -1){
79 keyLineEdit2->setText(config->readEntry( "dot11WEPDefaultKey2" )); 110 keyLineEdit2->setText(line.mid(0, s));
80 keyLineEdit3->setText(config->readEntry( "dot11WEPDefaultKey3" )); 111 line = line.mid(s+3, line.length());
81 return; 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 }
134 }
82} 135}
83
84bool WLANImp::writeConfig()
85{
86 qWarning( "WLANImp::writeConfig() called." );
87 config->setGroup( "Properties" );
88 if( essNon->isChecked() ) {
89 config->writeEntry( "SSID", "any" );
90 } else {
91 config->writeEntry( "SSID", essSpecificLineEdit->text() );
92 }
93 if( networkInfrastructure->isChecked() ){
94 config->writeEntry( "Mode", "Managed" );
95 } else if( network802->isChecked() ){
96 config->writeEntry( "Mode", "adhoc" );
97 }
98 config->writeEntry( "CHANNEL", networkChannel->value() );
99// config->readEntry( "RATE", "auto" );
100 wepEnabled->isChecked() ? config->writeEntry( "dot11PrivacyInvoked", "true" ) : config->writeEntry( "dot11PrivacyInvoked", "false" );
101 authOpen->isChecked() ? config->writeEntry( "AuthType", "opensystem" ) : config->writeEntry( "AuthType", "sharedkey" );
102 key40->isChecked() ? config->writeEntry( "PRIV_KEY128", "false" ) : config->writeEntry( "PRIV_KEY128", "true" );
103 if( keyRadio0->isChecked() ){
104 config->writeEntry( "dot11WEPDefaultKeyID", 0 );
105 } else if( keyRadio1->isChecked() ){
106 config->writeEntry( "dot11WEPDefaultKeyID", 1 );
107 } else if( keyRadio2->isChecked() ){
108 config->writeEntry( "dot11WEPDefaultKeyID", 2 );
109 } else if( keyRadio3->isChecked() ){
110 config->writeEntry( "dot11WEPDefaultKeyID", 3 );
111 }
112 config->writeEntry( "dot11WEPDefaultKey0", keyLineEdit0->text() );
113 config->writeEntry( "dot11WEPDefaultKey1", keyLineEdit1->text() );
114 config->writeEntry( "dot11WEPDefaultKey2", keyLineEdit2->text() );
115 config->writeEntry( "dot11WEPDefaultKey3", keyLineEdit3->text() );
116 return writeWirelessOpts( );
117} 136}
118 137
119/** 138/**
139 * Saves settings to the wireless.opts file using the current profile
120 */ 140 */
121void WLANImp::accept() 141void WLANImp::changeAndSaveSettingFile(){
122{ 142 QString wlanFile = WIRELESS_OPTS;
123 if ( writeConfig() ){ 143 QFile::remove(wlanFile);
124 if(interfaceSetup->saveChanges()) 144 QFile file(wlanFile);
125 QDialog::accept();
126 }
127}
128 145
129bool WLANImp::writeWirelessOpts( QString scheme ) 146 if (!file.open(IO_ReadWrite)){
130{ 147 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1());
131 qWarning( "WLANImp::writeWirelessOpts entered." ); 148 return;
132 QString prev = "/etc/pcmcia/wireless.opts"; 149 }
133 QFile prevFile(prev);
134 if ( !prevFile.open( IO_ReadOnly ) )
135 return false;
136 150
137 QString tmp = "/etc/pcmcia/wireless.opts-qpe-new"; 151 QTextStream stream( &file );
138 QFile tmpFile(tmp); 152 bool foundCase = false;
139 if ( !tmpFile.open( IO_WriteOnly ) ) 153 bool found = false;
140 return false; 154 bool output = true;
155 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
156 QString line = (*it).simplifyWhiteSpace();
157 if(line.contains("case"))
158 foundCase = true;
159 // See if we found our scheme to write or the sceme couldn't be found
160 if((foundCase && line.contains("esac") && !found) ||
161 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){
162 // write out scheme
163 found = true;
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";
189 }
190 if(line.contains(";;"))
191 output = true;
192 if(output)
193 stream << (*it) << '\n';
194 }
195 file.close();
196}
141 197
142 bool retval = true; 198/**
199 * Check to see if the current config is valid
200 * Save wireless.opts, save interfaces
201 */
202void WLANImp::accept(){
203 if(wepEnabled->isChecked()){
204 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() )
205 QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok);
206 return;
207 }
143 208
144 QTextStream in( &prevFile ); 209 // Ok settings are good here, save
145 QTextStream out( &tmpFile ); 210 changeAndSaveSettingFile();
146 211
147 config->setGroup("Properties"); 212 // Try to save the interfaces settings.
213 if(!interfaceSetup->saveChanges())
214 return;
148 215
149 QString line; 216 // Restart the device now that the settings have changed
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
223 prevFile.close();
224 tmpFile.close();
225 QString initpath; 217 QString initpath;
226 //system("cardctl suspend"); 218 if( QDir("/etc/rc.d/init.d").exists() )
227 if( QDir("/etc/rc.d/init.d").exists() ){
228 initpath = "/etc/rc.d/init.d"; 219 initpath = "/etc/rc.d/init.d";
229 } else if( QDir("/etc/init.d").exists() ){ 220 else if( QDir("/etc/init.d").exists() )
230 initpath = "/etc/init.d"; 221 initpath = "/etc/init.d";
231 }
232 if( initpath ) 222 if( initpath )
233 system(QString("%1/pcmcia stop").arg(initpath)); 223 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 ) 224 if( initpath )
244 system(QString("%1/pcmcia start").arg(initpath)); 225 system(QString("%1/pcmcia start").arg(initpath));
245 226
246 return retval; 227 // Close out the dialog
228 QDialog::accept();
247} 229}
230
231// wlanimp.cpp
232
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
@@ -2,6 +2,7 @@
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;
@@ -12,20 +13,18 @@ class WLANImp : public WLAN {
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 = "*" );
25 bool writeWlanngOpts( QString scheme = "*" );
26 Config* config;
27 InterfaceSetupImp *interfaceSetup;
28 24
25 InterfaceSetupImp *interfaceSetup;
26 QStringList settingsFileText;
27 QString currentProfile;
29}; 28};
30 29
31#endif 30#endif
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
@@ -11,7 +11,7 @@
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>
@@ -179,7 +179,7 @@
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" >
@@ -200,6 +200,10 @@
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>
@@ -257,7 +261,7 @@
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>
@@ -266,7 +270,69 @@
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>
@@ -367,109 +433,7 @@
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>
@@ -490,18 +454,7 @@
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>
@@ -534,12 +487,6 @@
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>
@@ -556,8 +503,6 @@
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>
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,11 +1,6 @@
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>
@@ -14,234 +9,224 @@
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;
58 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
59 QString line = (*it).simplifyWhiteSpace();
60 if(line.contains("case"))
61 foundCase = true;
62 // See if we found our scheme to write or the sceme couldn't be found
63 if((foundCase && line.contains("esac")) ||
64 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#'))
65 found = true;
66
67 if(line.contains(";;"))
68 found = false;
69 if(found){
70 // write out scheme
71 if(line.contains("ESSID=")){
72 QString id = line.mid(line.find("ESSID=")+6, line.length());
73 if(id == "any"){
46 essNon->setChecked( true ); 74 essNon->setChecked( true );
75 essSpecific->setChecked(false);
47 } else { 76 } else {
48 essSpecific->setChecked( true ); 77 essSpecific->setChecked( true );
49 essSpecificLineEdit->setText( ssid ); 78 essSpecificLineEdit->setText(id);
79 essNon->setChecked(false);
50 } 80 }
51 QString mode = config->readEntry( "Mode", "Managed" ); 81 }
52 if( mode == "adhoc" ) { 82 if(line.contains("MODE=")){
53 network802->setChecked( true ); 83 QString mode = line.mid(line.find("MODE=")+5, line.length());
54 } else { 84 if(mode == "Managed"){
85 network802->setChecked( false );
55 networkInfrastructure->setChecked( true ); 86 networkInfrastructure->setChecked( true );
56 } 87 }
57 networkChannel->setValue( config->readNumEntry( "CHANNEL", 1 ) ); 88 else{
58// config->readEntry( "RATE", "auto" ); 89 network802->setChecked( true );
59 config->readEntry( "dot11PrivacyInvoked" ) == "true" ? wepEnabled->setChecked( true ) : wepEnabled->setChecked( false ); 90 networkInfrastructure->setChecked( false );
60 config->readEntry( "AuthType", "opensystem" ); 91 }
61 config->readEntry( "PRIV_KEY128", "false" ) == "false" ? key40->setChecked( true ) : key128->setChecked( true ); 92 }
62 int defaultkey = config->readNumEntry( "dot11WEPDefaultKeyID", 0 ); 93 if(line.contains("KEY=")){
63 switch( defaultkey ){ 94 line.at(0) != '#' ? wepEnabled->setChecked(true) : wepEnabled->setChecked(false);
64 case 0: 95 int s = line.find("KEY=");
65 keyRadio0->setChecked( true ); 96 line = line.mid(s+4, line.length());
66 break; 97 // Find first Key
67 case 1: 98 s = line.find("[1]");
68 keyRadio1->setChecked( true ); 99 if(s != -1){
69 break; 100 keyLineEdit0->setText(line.mid(0, s));
70 case 2: 101 line = line.mid(s+3, line.length());
71 keyRadio2->setChecked( true ); 102 }
72 break; 103 s = line.find("[2]");
73 case 3: 104 if(s != -1){
74 keyRadio3->setChecked( true ); 105 keyLineEdit1->setText(line.mid(0, s));
75 break; 106 line = line.mid(s+3, line.length());
76 } 107 }
77 keyLineEdit0->setText(config->readEntry( "dot11WEPDefaultKey0" )); 108 s = line.find("[3]");
78 keyLineEdit1->setText(config->readEntry( "dot11WEPDefaultKey1" )); 109 if(s != -1){
79 keyLineEdit2->setText(config->readEntry( "dot11WEPDefaultKey2" )); 110 keyLineEdit2->setText(line.mid(0, s));
80 keyLineEdit3->setText(config->readEntry( "dot11WEPDefaultKey3" )); 111 line = line.mid(s+3, line.length());
81 return; 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 }
134 }
82} 135}
83
84bool WLANImp::writeConfig()
85{
86 qWarning( "WLANImp::writeConfig() called." );
87 config->setGroup( "Properties" );
88 if( essNon->isChecked() ) {
89 config->writeEntry( "SSID", "any" );
90 } else {
91 config->writeEntry( "SSID", essSpecificLineEdit->text() );
92 }
93 if( networkInfrastructure->isChecked() ){
94 config->writeEntry( "Mode", "Managed" );
95 } else if( network802->isChecked() ){
96 config->writeEntry( "Mode", "adhoc" );
97 }
98 config->writeEntry( "CHANNEL", networkChannel->value() );
99// config->readEntry( "RATE", "auto" );
100 wepEnabled->isChecked() ? config->writeEntry( "dot11PrivacyInvoked", "true" ) : config->writeEntry( "dot11PrivacyInvoked", "false" );
101 authOpen->isChecked() ? config->writeEntry( "AuthType", "opensystem" ) : config->writeEntry( "AuthType", "sharedkey" );
102 key40->isChecked() ? config->writeEntry( "PRIV_KEY128", "false" ) : config->writeEntry( "PRIV_KEY128", "true" );
103 if( keyRadio0->isChecked() ){
104 config->writeEntry( "dot11WEPDefaultKeyID", 0 );
105 } else if( keyRadio1->isChecked() ){
106 config->writeEntry( "dot11WEPDefaultKeyID", 1 );
107 } else if( keyRadio2->isChecked() ){
108 config->writeEntry( "dot11WEPDefaultKeyID", 2 );
109 } else if( keyRadio3->isChecked() ){
110 config->writeEntry( "dot11WEPDefaultKeyID", 3 );
111 }
112 config->writeEntry( "dot11WEPDefaultKey0", keyLineEdit0->text() );
113 config->writeEntry( "dot11WEPDefaultKey1", keyLineEdit1->text() );
114 config->writeEntry( "dot11WEPDefaultKey2", keyLineEdit2->text() );
115 config->writeEntry( "dot11WEPDefaultKey3", keyLineEdit3->text() );
116 return writeWirelessOpts( );
117} 136}
118 137
119/** 138/**
139 * Saves settings to the wireless.opts file using the current profile
120 */ 140 */
121void WLANImp::accept() 141void WLANImp::changeAndSaveSettingFile(){
122{ 142 QString wlanFile = WIRELESS_OPTS;
123 if ( writeConfig() ){ 143 QFile::remove(wlanFile);
124 if(interfaceSetup->saveChanges()) 144 QFile file(wlanFile);
125 QDialog::accept();
126 }
127}
128 145
129bool WLANImp::writeWirelessOpts( QString scheme ) 146 if (!file.open(IO_ReadWrite)){
130{ 147 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1());
131 qWarning( "WLANImp::writeWirelessOpts entered." ); 148 return;
132 QString prev = "/etc/pcmcia/wireless.opts"; 149 }
133 QFile prevFile(prev);
134 if ( !prevFile.open( IO_ReadOnly ) )
135 return false;
136 150
137 QString tmp = "/etc/pcmcia/wireless.opts-qpe-new"; 151 QTextStream stream( &file );
138 QFile tmpFile(tmp); 152 bool foundCase = false;
139 if ( !tmpFile.open( IO_WriteOnly ) ) 153 bool found = false;
140 return false; 154 bool output = true;
155 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
156 QString line = (*it).simplifyWhiteSpace();
157 if(line.contains("case"))
158 foundCase = true;
159 // See if we found our scheme to write or the sceme couldn't be found
160 if((foundCase && line.contains("esac") && !found) ||
161 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){
162 // write out scheme
163 found = true;
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";
189 }
190 if(line.contains(";;"))
191 output = true;
192 if(output)
193 stream << (*it) << '\n';
194 }
195 file.close();
196}
141 197
142 bool retval = true; 198/**
199 * Check to see if the current config is valid
200 * Save wireless.opts, save interfaces
201 */
202void WLANImp::accept(){
203 if(wepEnabled->isChecked()){
204 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() )
205 QMessageBox::information(this, "", "Please enter a key for WEP.", QMessageBox::Ok);
206 return;
207 }
143 208
144 QTextStream in( &prevFile ); 209 // Ok settings are good here, save
145 QTextStream out( &tmpFile ); 210 changeAndSaveSettingFile();
146 211
147 config->setGroup("Properties"); 212 // Try to save the interfaces settings.
213 if(!interfaceSetup->saveChanges())
214 return;
148 215
149 QString line; 216 // Restart the device now that the settings have changed
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
223 prevFile.close();
224 tmpFile.close();
225 QString initpath; 217 QString initpath;
226 //system("cardctl suspend"); 218 if( QDir("/etc/rc.d/init.d").exists() )
227 if( QDir("/etc/rc.d/init.d").exists() ){
228 initpath = "/etc/rc.d/init.d"; 219 initpath = "/etc/rc.d/init.d";
229 } else if( QDir("/etc/init.d").exists() ){ 220 else if( QDir("/etc/init.d").exists() )
230 initpath = "/etc/init.d"; 221 initpath = "/etc/init.d";
231 }
232 if( initpath ) 222 if( initpath )
233 system(QString("%1/pcmcia stop").arg(initpath)); 223 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 ) 224 if( initpath )
244 system(QString("%1/pcmcia start").arg(initpath)); 225 system(QString("%1/pcmcia start").arg(initpath));
245 226
246 return retval; 227 // Close out the dialog
228 QDialog::accept();
247} 229}
230
231// wlanimp.cpp
232
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
@@ -2,6 +2,7 @@
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;
@@ -12,20 +13,18 @@ class WLANImp : public WLAN {
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 = "*" );
25 bool writeWlanngOpts( QString scheme = "*" );
26 Config* config;
27 InterfaceSetupImp *interfaceSetup;
28 24
25 InterfaceSetupImp *interfaceSetup;
26 QStringList settingsFileText;
27 QString currentProfile;
29}; 28};
30 29
31#endif 30#endif