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