Changeset View
Changeset View
Standalone View
Standalone View
libs/editor/settings/wifisecurity.cpp
Show All 38 Lines | 33 | { | |||
---|---|---|---|---|---|
39 | m_ui->psk->setPasswordOptionsEnabled(true); | 39 | m_ui->psk->setPasswordOptionsEnabled(true); | ||
40 | m_ui->wepKey->setPasswordOptionsEnabled(true); | 40 | m_ui->wepKey->setPasswordOptionsEnabled(true); | ||
41 | 41 | | |||
42 | m_8021xWidget = new Security8021x(setting8021x, true, this); // Dynamic WEP | 42 | m_8021xWidget = new Security8021x(setting8021x, true, this); // Dynamic WEP | ||
43 | m_WPA2Widget = new Security8021x(setting8021x, true, this); // WPA(2) Enterprise | 43 | m_WPA2Widget = new Security8021x(setting8021x, true, this); // WPA(2) Enterprise | ||
44 | m_ui->stackedWidget->insertWidget(3, m_8021xWidget); | 44 | m_ui->stackedWidget->insertWidget(3, m_8021xWidget); | ||
45 | m_ui->stackedWidget->insertWidget(5, m_WPA2Widget); | 45 | m_ui->stackedWidget->insertWidget(5, m_WPA2Widget); | ||
46 | 46 | | |||
47 | // WPA3 Personal is available in NM 1.16+ | ||||
48 | if (!NetworkManager::checkVersion(1, 16, 0)) { | ||||
49 | m_ui->securityCombo->removeItem(7); | ||||
50 | } | ||||
51 | | ||||
47 | connect(m_ui->securityCombo, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::securityChanged); | 52 | connect(m_ui->securityCombo, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::securityChanged); | ||
48 | connect(m_ui->wepIndex, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::setWepKey); | 53 | connect(m_ui->wepIndex, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &WifiSecurity::setWepKey); | ||
49 | 54 | | |||
50 | // Connect for setting check | 55 | // Connect for setting check | ||
51 | watchChangedSetting(); | 56 | watchChangedSetting(); | ||
52 | 57 | | |||
53 | // Connect for validity check | 58 | // Connect for validity check | ||
54 | connect(m_ui->wepKey, &PasswordField::textChanged, this, &WifiSecurity::slotWidgetChanged); | 59 | connect(m_ui->wepKey, &PasswordField::textChanged, this, &WifiSecurity::slotWidgetChanged); | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 98 | { | |||
99 | } else if (securityIndex == WepPassphrase) { // WEP Passphrase | 104 | } else if (securityIndex == WepPassphrase) { // WEP Passphrase | ||
100 | return NetworkManager::wepKeyIsValid(m_ui->wepKey->text(), NetworkManager::WirelessSecuritySetting::Passphrase) || | 105 | return NetworkManager::wepKeyIsValid(m_ui->wepKey->text(), NetworkManager::WirelessSecuritySetting::Passphrase) || | ||
101 | m_ui->wepKey->passwordOption() == PasswordField::AlwaysAsk;; | 106 | m_ui->wepKey->passwordOption() == PasswordField::AlwaysAsk;; | ||
102 | }else if (securityIndex == Leap) { // LEAP | 107 | }else if (securityIndex == Leap) { // LEAP | ||
103 | return !m_ui->leapUsername->text().isEmpty() && | 108 | return !m_ui->leapUsername->text().isEmpty() && | ||
104 | (!m_ui->leapPassword->text().isEmpty() || m_ui->leapPassword->passwordOption() == PasswordField::AlwaysAsk); | 109 | (!m_ui->leapPassword->text().isEmpty() || m_ui->leapPassword->passwordOption() == PasswordField::AlwaysAsk); | ||
105 | } else if (securityIndex == WpaPsk) { // WPA | 110 | } else if (securityIndex == WpaPsk) { // WPA | ||
106 | return NetworkManager::wpaPskIsValid(m_ui->psk->text()) || | 111 | return NetworkManager::wpaPskIsValid(m_ui->psk->text()) || | ||
107 | m_ui->psk->passwordOption() == PasswordField::AlwaysAsk;; | 112 | m_ui->psk->passwordOption() == PasswordField::AlwaysAsk; | ||
108 | } else if (securityIndex == DynamicWep) { | 113 | } else if (securityIndex == DynamicWep) { | ||
109 | return m_8021xWidget->isValid(); | 114 | return m_8021xWidget->isValid(); | ||
110 | } else if (securityIndex == WpaEap) { | 115 | } else if (securityIndex == WpaEap) { | ||
111 | return m_WPA2Widget->isValid(); | 116 | return m_WPA2Widget->isValid(); | ||
117 | } else if (securityIndex == SAE) { | ||||
118 | return !m_ui->psk->text().isEmpty() || m_ui->psk->passwordOption() == PasswordField::AlwaysAsk; | ||||
meven: It is very similar with `securityIndex == WpaPsk) { // WPA` if `NetworkManager::wpaPskIsValid… | |||||
112 | } | 119 | } | ||
113 | 120 | | |||
114 | return true; | 121 | return true; | ||
115 | } | 122 | } | ||
116 | 123 | | |||
117 | void WifiSecurity::loadConfig(const NetworkManager::Setting::Ptr &setting) | 124 | void WifiSecurity::loadConfig(const NetworkManager::Setting::Ptr &setting) | ||
118 | { | 125 | { | ||
119 | NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity = setting.staticCast<NetworkManager::WirelessSecuritySetting>(); | 126 | NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity = setting.staticCast<NetworkManager::WirelessSecuritySetting>(); | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 173 | } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaPsk) { | |||
171 | } else if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::AgentOwned)) { | 178 | } else if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::AgentOwned)) { | ||
172 | m_ui->psk->setPasswordOption(PasswordField::StoreForUser); | 179 | m_ui->psk->setPasswordOption(PasswordField::StoreForUser); | ||
173 | } else { | 180 | } else { | ||
174 | m_ui->psk->setPasswordOption(PasswordField::AlwaysAsk); | 181 | m_ui->psk->setPasswordOption(PasswordField::AlwaysAsk); | ||
175 | } | 182 | } | ||
176 | } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaEap) { | 183 | } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaEap) { | ||
177 | m_ui->securityCombo->setCurrentIndex(WpaEap); // WPA2 Enterprise | 184 | m_ui->securityCombo->setCurrentIndex(WpaEap); // WPA2 Enterprise | ||
178 | // done in the widget | 185 | // done in the widget | ||
186 | } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::SAE) { | ||||
187 | m_ui->securityCombo->setCurrentIndex(SAE); // WPA3 | ||||
188 | | ||||
189 | if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::None)) { | ||||
190 | m_ui->psk->setPasswordOption(PasswordField::StoreForAllUsers); | ||||
191 | } else if (wifiSecurity->pskFlags().testFlag(NetworkManager::Setting::AgentOwned)) { | ||||
192 | m_ui->psk->setPasswordOption(PasswordField::StoreForUser); | ||||
193 | } else { | ||||
194 | m_ui->psk->setPasswordOption(PasswordField::AlwaysAsk); | ||||
195 | } | ||||
179 | } | 196 | } | ||
180 | 197 | | |||
181 | if (keyMgmt != NetworkManager::WirelessSecuritySetting::Ieee8021x && | 198 | if (keyMgmt != NetworkManager::WirelessSecuritySetting::Ieee8021x && | ||
182 | keyMgmt != NetworkManager::WirelessSecuritySetting::WpaEap) { | 199 | keyMgmt != NetworkManager::WirelessSecuritySetting::WpaEap) { | ||
183 | loadSecrets(setting); | 200 | loadSecrets(setting); | ||
184 | } | 201 | } | ||
185 | } | 202 | } | ||
186 | 203 | | |||
Show All 20 Lines | 222 | if (keyMgmt == NetworkManager::WirelessSecuritySetting::Wep) { | |||
207 | const int keyIndex = static_cast<int>(m_wifiSecurity->wepTxKeyindex()); | 224 | const int keyIndex = static_cast<int>(m_wifiSecurity->wepTxKeyindex()); | ||
208 | setWepKey(keyIndex); | 225 | setWepKey(keyIndex); | ||
209 | } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x | 226 | } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::Ieee8021x | ||
210 | && authAlg == NetworkManager::WirelessSecuritySetting::Leap) { | 227 | && authAlg == NetworkManager::WirelessSecuritySetting::Leap) { | ||
211 | const QString leapPassword = wifiSecurity->leapPassword(); | 228 | const QString leapPassword = wifiSecurity->leapPassword(); | ||
212 | if (!leapPassword.isEmpty()) { | 229 | if (!leapPassword.isEmpty()) { | ||
213 | m_ui->leapPassword->setText(leapPassword); | 230 | m_ui->leapPassword->setText(leapPassword); | ||
214 | } | 231 | } | ||
215 | } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaPsk) { | 232 | } else if (keyMgmt == NetworkManager::WirelessSecuritySetting::WpaPsk || keyMgmt == NetworkManager::WirelessSecuritySetting::SAE) { | ||
216 | const QString psk = wifiSecurity->psk(); | 233 | const QString psk = wifiSecurity->psk(); | ||
217 | if (!psk.isEmpty()) { | 234 | if (!psk.isEmpty()) { | ||
218 | m_ui->psk->setText(psk); | 235 | m_ui->psk->setText(psk); | ||
219 | } | 236 | } | ||
220 | } | 237 | } | ||
221 | } | 238 | } | ||
222 | } | 239 | } | ||
223 | } | 240 | } | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 301 | if (m_ui->psk->passwordOption() == PasswordField::StoreForAllUsers) { | |||
285 | wifiSecurity.setPskFlags(NetworkManager::Setting::None); | 302 | wifiSecurity.setPskFlags(NetworkManager::Setting::None); | ||
286 | } else if (m_ui->psk->passwordOption() == PasswordField::StoreForUser) { | 303 | } else if (m_ui->psk->passwordOption() == PasswordField::StoreForUser) { | ||
287 | wifiSecurity.setPskFlags(NetworkManager::Setting::AgentOwned); | 304 | wifiSecurity.setPskFlags(NetworkManager::Setting::AgentOwned); | ||
288 | } else { | 305 | } else { | ||
289 | wifiSecurity.setPskFlags(NetworkManager::Setting::NotSaved); | 306 | wifiSecurity.setPskFlags(NetworkManager::Setting::NotSaved); | ||
290 | } | 307 | } | ||
291 | } else if (securityIndex == WpaEap) { // WPA2 Enterprise | 308 | } else if (securityIndex == WpaEap) { // WPA2 Enterprise | ||
292 | wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap); | 309 | wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap); | ||
310 | } else if (securityIndex == SAE) { // WPA3 Personal | ||||
311 | wifiSecurity.setKeyMgmt(NetworkManager::WirelessSecuritySetting::SAE); | ||||
312 | wifiSecurity.setPsk(m_ui->psk->text()); | ||||
313 | | ||||
314 | if (m_ui->psk->passwordOption() == PasswordField::StoreForAllUsers) { | ||||
315 | wifiSecurity.setPskFlags(NetworkManager::Setting::None); | ||||
316 | } else if (m_ui->psk->passwordOption() == PasswordField::StoreForUser) { | ||||
317 | wifiSecurity.setPskFlags(NetworkManager::Setting::AgentOwned); | ||||
318 | } else { | ||||
319 | wifiSecurity.setPskFlags(NetworkManager::Setting::NotSaved); | ||||
320 | } | ||||
293 | } | 321 | } | ||
294 | 322 | | |||
295 | return wifiSecurity.toMap(); | 323 | return wifiSecurity.toMap(); | ||
296 | } | 324 | } | ||
297 | 325 | | |||
298 | QVariantMap WifiSecurity::setting8021x() const | 326 | QVariantMap WifiSecurity::setting8021x() const | ||
299 | { | 327 | { | ||
300 | if (m_ui->securityCombo->currentIndex() == DynamicWep) { // Dynamic WEP | 328 | if (m_ui->securityCombo->currentIndex() == DynamicWep) { // Dynamic WEP | ||
Show All 33 Lines | 361 | case NetworkManager::WirelessSecurityType::Wpa2Psk: | |||
334 | m_ui->securityCombo->setCurrentIndex(WpaPsk); | 362 | m_ui->securityCombo->setCurrentIndex(WpaPsk); | ||
335 | break; | 363 | break; | ||
336 | case NetworkManager::WirelessSecurityType::WpaEap: | 364 | case NetworkManager::WirelessSecurityType::WpaEap: | ||
337 | m_ui->securityCombo->setCurrentIndex(WpaEap); | 365 | m_ui->securityCombo->setCurrentIndex(WpaEap); | ||
338 | break; | 366 | break; | ||
339 | case NetworkManager::WirelessSecurityType::Wpa2Eap: | 367 | case NetworkManager::WirelessSecurityType::Wpa2Eap: | ||
340 | m_ui->securityCombo->setCurrentIndex(WpaEap); | 368 | m_ui->securityCombo->setCurrentIndex(WpaEap); | ||
341 | break; | 369 | break; | ||
370 | case NetworkManager::WirelessSecurityType::SAE: | ||||
371 | m_ui->securityCombo->setCurrentIndex(SAE); | ||||
372 | break; | ||||
342 | default: | 373 | default: | ||
343 | m_ui->securityCombo->setCurrentIndex(None); | 374 | m_ui->securityCombo->setCurrentIndex(None); | ||
344 | } | 375 | } | ||
345 | 376 | | |||
346 | return; | 377 | return; | ||
347 | } | 378 | } | ||
348 | } | 379 | } | ||
349 | } | 380 | } | ||
Show All 14 Lines | 394 | } else if (keyIndex == 2) { | |||
364 | m_ui->wepKey->setText(m_wifiSecurity->wepKey2()); | 395 | m_ui->wepKey->setText(m_wifiSecurity->wepKey2()); | ||
365 | } else if (keyIndex == 3) { | 396 | } else if (keyIndex == 3) { | ||
366 | m_ui->wepKey->setText(m_wifiSecurity->wepKey3()); | 397 | m_ui->wepKey->setText(m_wifiSecurity->wepKey3()); | ||
367 | } | 398 | } | ||
368 | } | 399 | } | ||
369 | 400 | | |||
370 | void WifiSecurity::securityChanged(int index) | 401 | void WifiSecurity::securityChanged(int index) | ||
371 | { | 402 | { | ||
372 | if (index == 0) { | 403 | if (index == 0) { // None | ||
It would be nice to convert use SecurityTypeIndex enum instead of hardcoded values. And then change WifiSecurity::securityChanged(int) to WifiSecurity::securityChanged(SecurityTypeIndex) if possible. meven: It would be nice to convert use SecurityTypeIndex enum instead of hardcoded values.
It seems to… | |||||
373 | m_ui->stackedWidget->setCurrentIndex(0); | 404 | m_ui->stackedWidget->setCurrentIndex(0); | ||
374 | } else if (index == 1 || index == 2) { | 405 | } else if (index == 1 || index == 2) { // WEP | ||
375 | m_ui->stackedWidget->setCurrentIndex(1); | 406 | m_ui->stackedWidget->setCurrentIndex(1); | ||
376 | } else { | 407 | } else if (index == 3) { // LEAP | ||
377 | m_ui->stackedWidget->setCurrentIndex(index-1); | 408 | m_ui->stackedWidget->setCurrentIndex(2); | ||
409 | } else if (index == 4) { // Dynamic WEP | ||||
410 | m_ui->stackedWidget->setCurrentIndex(3); | ||||
411 | } else if (index == 5) { // WPA/WPA2 Personal | ||||
412 | m_ui->stackedWidget->setCurrentIndex(4); | ||||
413 | } else if (index == 6) { // WPA/WPA2 Enterprise | ||||
414 | m_ui->stackedWidget->setCurrentIndex(5); | ||||
415 | } else if (index == 7) { // WPA3 Personal | ||||
With an enum this could be merged easily with the WPA/WPA2 Enterprise index == 5 case. meven: With an enum this could be merged easily with the WPA/WPA2 Enterprise index == 5 case. | |||||
416 | m_ui->stackedWidget->setCurrentIndex(4); | ||||
378 | } | 417 | } | ||
379 | 418 | | |||
380 | KAcceleratorManager::manage(m_ui->stackedWidget->currentWidget()); | 419 | KAcceleratorManager::manage(m_ui->stackedWidget->currentWidget()); | ||
381 | } | 420 | } |
It is very similar with securityIndex == WpaPsk) { // WPA if NetworkManager::wpaPskIsValid(m_ui->psk->text()) could be used instead of !m_ui->psk->text().isEmpty() we could use a single if block for both.
As a side note this if block could become a switch(securityIndex)