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