summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/wlan/wlanimp.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/wlan/wlanimp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/wlan/wlanimp.cpp96
1 files changed, 48 insertions, 48 deletions
diff --git a/noncore/settings/networksettings/wlan/wlanimp.cpp b/noncore/settings/networksettings/wlan/wlanimp.cpp
index 719be1b..95f4abe 100644
--- a/noncore/settings/networksettings/wlan/wlanimp.cpp
+++ b/noncore/settings/networksettings/wlan/wlanimp.cpp
@@ -10,24 +10,24 @@
10#include <qspinbox.h> 10#include <qspinbox.h>
11#include <qradiobutton.h> 11#include <qradiobutton.h>
12#include <qcheckbox.h> 12#include <qcheckbox.h>
13#include <qtabwidget.h> 13#include <qtabwidget.h>
14#include <qcombobox.h> 14#include <qcombobox.h>
15 15
16#ifdef QWS 16#ifdef QWS
17 #include <opie/oprocess.h> 17 #include <opie2/oprocess.h>
18#else 18#else
19 #define OProcess KProcess 19 #define OProcess KProcess
20 #include <kprocess.h> 20 #include <kprocess.h>
21#endif 21#endif
22 22
23#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" 23#define WIRELESS_OPTS "/etc/pcmcia/wireless.opts"
24 24
25/** 25/**
26 * Constructor, read in the wireless.opts file for parsing later. 26 * Constructor, read in the wireless.opts file for parsing later.
27 */ 27 */
28WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") { 28WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl):WLAN(parent, name, modal, fl), currentProfile("*") {
29 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i); 29 interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i);
30 tabWidget->insertTab(interfaceSetup, "TCP/IP"); 30 tabWidget->insertTab(interfaceSetup, "TCP/IP");
31 31
32 // Read in the config file. 32 // Read in the config file.
33 QString wlanFile = WIRELESS_OPTS; 33 QString wlanFile = WIRELESS_OPTS;
@@ -52,153 +52,153 @@ void WLANImp::typeChanged(int mod){
52 networkChannel->setEnabled(mod); 52 networkChannel->setEnabled(mod);
53 channelLabel->setEnabled(mod); 53 channelLabel->setEnabled(mod);
54} 54}
55 55
56/** 56/**
57 * Change the profile for both wireless settings and network settings. 57 * Change the profile for both wireless settings and network settings.
58 */ 58 */
59void WLANImp::setProfile(const QString &profile){ 59void WLANImp::setProfile(const QString &profile){
60 interfaceSetup->setProfile(profile); 60 interfaceSetup->setProfile(profile);
61 parseSettingFile(); 61 parseSettingFile();
62} 62}
63 63
64/** 64/**
65 * Parses the settings file that was read in and gets any setting from it. 65 * Parses the settings file that was read in and gets any setting from it.
66 */ 66 */
67void WLANImp::parseSettingFile(){ 67void WLANImp::parseSettingFile(){
68 bool foundCase = false; 68 bool foundCase = false;
69 bool found = false; 69 bool found = false;
70 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { 70 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
71 QString line = (*it).simplifyWhiteSpace(); 71 QString line = (*it).simplifyWhiteSpace();
72 if(line.contains("case")) 72 if(line.contains("case"))
73 foundCase = true; 73 foundCase = true;
74 // See if we found our scheme to write or the sceme couldn't be found 74 // See if we found our scheme to write or the sceme couldn't be found
75 if((foundCase && line.contains("esac")) || 75 if((foundCase && line.contains("esac")) ||
76 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')) 76 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#'))
77 found = true; 77 found = true;
78 78
79 if(line.contains(";;")) 79 if(line.contains(";;"))
80 found = false; 80 found = false;
81 if(found){ 81 if(found){
82 // write out scheme 82 // write out scheme
83 if(line.contains("ESSID=")){ 83 if(line.contains("ESSID=")){
84 QString id = line.mid(line.find("ESSID=")+6, line.length()); 84 QString id = line.mid(line.find("ESSID=")+6, line.length());
85 if(id == "any"){ 85 if(id == "any"){
86 essAny->setChecked(false); 86 essAny->setChecked(false);
87 }else{ 87 }else{
88 essAny->setChecked(true); 88 essAny->setChecked(true);
89 essSpecificLineEdit->setText(id); 89 essSpecificLineEdit->setText(id);
90 } 90 }
91 } 91 }
92 if(line.contains("MODE=")){ 92 if(line.contains("MODE=")){
93 QString mode = line.mid(line.find("MODE=")+5, line.length()); 93 QString mode = line.mid(line.find("MODE=")+5, line.length());
94 if(mode == "Managed"){ 94 if(mode == "Managed"){
95 networkType->setCurrentItem(0); 95 networkType->setCurrentItem(0);
96 channelLabel->setEnabled(false); 96 channelLabel->setEnabled(false);
97 networkChannel->setEnabled(false); 97 networkChannel->setEnabled(false);
98 } 98 }
99 else{ 99 else{
100 networkType->setCurrentItem(1); 100 networkType->setCurrentItem(1);
101 networkChannel->setEnabled(true); 101 networkChannel->setEnabled(true);
102 channelLabel->setEnabled(true); 102 channelLabel->setEnabled(true);
103 } 103 }
104 } 104 }
105 if(line.contains("#KEY0=")) 105 if(line.contains("#KEY0="))
106 keyLineEdit0->setText(line.mid(6, line.length())); 106 keyLineEdit0->setText(line.mid(6, line.length()));
107 if(line.contains("#KEY1=")) 107 if(line.contains("#KEY1="))
108 keyLineEdit1->setText(line.mid(6, line.length())); 108 keyLineEdit1->setText(line.mid(6, line.length()));
109 if(line.contains("#KEY2=")) 109 if(line.contains("#KEY2="))
110 keyLineEdit2->setText(line.mid(6, line.length())); 110 keyLineEdit2->setText(line.mid(6, line.length()));
111 if(line.contains("#KEY3=")) 111 if(line.contains("#KEY3="))
112 keyLineEdit3->setText(line.mid(6, line.length())); 112 keyLineEdit3->setText(line.mid(6, line.length()));
113 113
114 if(line.contains("KEY=")){ 114 if(line.contains("KEY=")){
115 wepEnabled->setChecked(true); 115 wepEnabled->setChecked(true);
116 QString key; 116 QString key;
117 if(line.right(5) == (" open")){ 117 if(line.right(5) == (" open")){
118 key = line.mid(4, line.length()-5); 118 key = line.mid(4, line.length()-5);
119 authOpen->setChecked(true); 119 authOpen->setChecked(true);
120 authShared->setChecked(false); 120 authShared->setChecked(false);
121 } 121 }
122 else{ 122 else{
123 authOpen->setChecked(false); 123 authOpen->setChecked(false);
124 authShared->setChecked(true); 124 authShared->setChecked(true);
125 key = line.mid(4, line.length()); 125 key = line.mid(4, line.length());
126 } 126 }
127 if(key == keyLineEdit0->text()) keyRadio0->setChecked(true); 127 if(key == keyLineEdit0->text()) keyRadio0->setChecked(true);
128 if(key == keyLineEdit1->text()) keyRadio1->setChecked(true); 128 if(key == keyLineEdit1->text()) keyRadio1->setChecked(true);
129 if(key == keyLineEdit2->text()) keyRadio2->setChecked(true); 129 if(key == keyLineEdit2->text()) keyRadio2->setChecked(true);
130 if(key == keyLineEdit3->text()) keyRadio3->setChecked(true); 130 if(key == keyLineEdit3->text()) keyRadio3->setChecked(true);
131 } 131 }
132 if(line.contains("CHANNEL=")){ 132 if(line.contains("CHANNEL=")){
133 networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt()); 133 networkChannel->setValue(line.mid(line.find("CHANNEL=")+8, line.length()).toInt());
134 } 134 }
135 } 135 }
136 } 136 }
137} 137}
138 138
139/** 139/**
140 * Saves settings to the wireless.opts file using the current profile 140 * Saves settings to the wireless.opts file using the current profile
141 */ 141 */
142void WLANImp::changeAndSaveSettingFile(){ 142void WLANImp::changeAndSaveSettingFile(){
143 QString wlanFile = WIRELESS_OPTS; 143 QString wlanFile = WIRELESS_OPTS;
144 QFile::remove(wlanFile); 144 QFile::remove(wlanFile);
145 QFile file(wlanFile); 145 QFile file(wlanFile);
146 146
147 if (!file.open(IO_ReadWrite)){ 147 if (!file.open(IO_ReadWrite)){
148 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1()); 148 qDebug(QString("WLANImp::changeAndSaveSettingFile(): Can't open file: %1 for writing.").arg(wlanFile).latin1());
149 return; 149 return;
150 } 150 }
151 151
152 QTextStream stream( &file ); 152 QTextStream stream( &file );
153 bool foundCase = false; 153 bool foundCase = false;
154 bool found = false; 154 bool found = false;
155 bool output = true; 155 bool output = true;
156 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) { 156 for ( QStringList::Iterator it = settingsFileText.begin(); it != settingsFileText.end(); ++it ) {
157 QString line = (*it).simplifyWhiteSpace(); 157 QString line = (*it).simplifyWhiteSpace();
158 if(line.contains("case")) 158 if(line.contains("case"))
159 foundCase = true; 159 foundCase = true;
160 // See if we found our scheme to write or the sceme couldn't be found 160 // See if we found our scheme to write or the sceme couldn't be found
161 if((foundCase && line.contains("esac") && !found) || 161 if((foundCase && line.contains("esac") && !found) ||
162 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){ 162 (foundCase && line.left(currentProfile.length()+7) == currentProfile + ",*,*,*)" && line.at(0) != '#')){
163 // write out scheme 163 // write out scheme
164 found = true; 164 found = true;
165 output = false; 165 output = false;
166 166
167 if(!line.contains("esac")) 167 if(!line.contains("esac"))
168 stream << line << "\n"; 168 stream << line << "\n";
169 if(!essAny->isChecked() == true){ 169 if(!essAny->isChecked() == true){
170 stream << "\tESSID=any\n"; 170 stream << "\tESSID=any\n";
171 stream << "\tMODE=Managed\n"; 171 stream << "\tMODE=Managed\n";
172 } 172 }
173 else{ 173 else{
174 stream << "\tESSID=" << essSpecificLineEdit->text() << '\n'; 174 stream << "\tESSID=" << essSpecificLineEdit->text() << '\n';
175 stream << "\tMODE=" << ( networkType->currentItem() == 0 ? "Managed" : "ad-hoc") << '\n'; 175 stream << "\tMODE=" << ( networkType->currentItem() == 0 ? "Managed" : "ad-hoc") << '\n';
176 stream << "\tCHANNEL=" << networkChannel->value() << "\n"; 176 stream << "\tCHANNEL=" << networkChannel->value() << "\n";
177 } 177 }
178 178
179 stream << "\t#KEY0=" << keyLineEdit0->text() << "\n"; 179 stream << "\t#KEY0=" << keyLineEdit0->text() << "\n";
180 stream << "\t#KEY1=" << keyLineEdit1->text() << "\n"; 180 stream << "\t#KEY1=" << keyLineEdit1->text() << "\n";
181 stream << "\t#KEY2=" << keyLineEdit2->text() << "\n"; 181 stream << "\t#KEY2=" << keyLineEdit2->text() << "\n";
182 stream << "\t#KEY3=" << keyLineEdit3->text() << "\n"; 182 stream << "\t#KEY3=" << keyLineEdit3->text() << "\n";
183 183
184 if(wepEnabled->isChecked()){ 184 if(wepEnabled->isChecked()){
185 stream << "\tKEY=\""; 185 stream << "\tKEY=\"";
186 if(keyRadio0->isChecked()) stream << keyLineEdit0->text(); 186 if(keyRadio0->isChecked()) stream << keyLineEdit0->text();
187 if(keyRadio1->isChecked()) stream << keyLineEdit1->text(); 187 if(keyRadio1->isChecked()) stream << keyLineEdit1->text();
188 if(keyRadio2->isChecked()) stream << keyLineEdit2->text(); 188 if(keyRadio2->isChecked()) stream << keyLineEdit2->text();
189 if(keyRadio3->isChecked()) stream << keyLineEdit3->text(); 189 if(keyRadio3->isChecked()) stream << keyLineEdit3->text();
190 if(authOpen->isChecked()) 190 if(authOpen->isChecked())
191 stream << " open"; 191 stream << " open";
192 else 192 else
193 stream << " restricted"; 193 stream << " restricted";
194 stream << "\"\n"; 194 stream << "\"\n";
195 } 195 }
196 stream << "\tRATE=auto\n"; 196 stream << "\tRATE=auto\n";
197 if(line.contains("esac")) 197 if(line.contains("esac"))
198 stream << line << "\n"; 198 stream << line << "\n";
199 } 199 }
200 if(line.contains(";;")) 200 if(line.contains(";;"))
201 output = true; 201 output = true;
202 if(output && (*it).length() ) 202 if(output && (*it).length() )
203 stream << (*it) << '\n'; 203 stream << (*it) << '\n';
204 } 204 }
@@ -212,22 +212,22 @@ void WLANImp::changeAndSaveSettingFile(){
212void WLANImp::accept(){ 212void WLANImp::accept(){
213 if(wepEnabled->isChecked()){ 213 if(wepEnabled->isChecked()){
214 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ){ 214 if(keyLineEdit0->text().isEmpty() && keyLineEdit1->text().isEmpty() && keyLineEdit2->text().isEmpty() && keyLineEdit3->text().isEmpty() ){
215 QMessageBox::information(this, "Error", "Please enter a key for WEP.", QMessageBox::Ok); 215 QMessageBox::information(this, "Error", "Please enter a key for WEP.", QMessageBox::Ok);
216 return; 216 return;
217 } 217 }
218 } 218 }
219 219
220 if(essAny->isChecked() && essSpecificLineEdit->text().isEmpty()){ 220 if(essAny->isChecked() && essSpecificLineEdit->text().isEmpty()){
221 QMessageBox::information(this, "Error", "Please enter a SSID.", QMessageBox::Ok); 221 QMessageBox::information(this, "Error", "Please enter a SSID.", QMessageBox::Ok);
222 return; 222 return;
223 } 223 }
224 224
225 // Ok settings are good here, save 225 // Ok settings are good here, save
226 changeAndSaveSettingFile(); 226 changeAndSaveSettingFile();
227 227
228 // Try to save the interfaces settings. 228 // Try to save the interfaces settings.
229 if(!interfaceSetup->saveChanges()) 229 if(!interfaceSetup->saveChanges())
230 return; 230 return;
231 231
232 OProcess insert; 232 OProcess insert;
233 insert << "sh"; 233 insert << "sh";