Changeset View
Changeset View
Standalone View
Standalone View
libs/handler.cpp
Show First 20 Lines • Show All 159 Lines • ▼ Show 20 Line(s) | 159 | #endif | |||
---|---|---|---|---|---|
160 | 160 | | |||
161 | QDBusPendingReply<QDBusObjectPath> reply = NetworkManager::activateConnection(connection, device, specificObject); | 161 | QDBusPendingReply<QDBusObjectPath> reply = NetworkManager::activateConnection(connection, device, specificObject); | ||
162 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | 162 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); | ||
163 | watcher->setProperty("action", Handler::ActivateConnection); | 163 | watcher->setProperty("action", Handler::ActivateConnection); | ||
164 | watcher->setProperty("connection", con->name()); | 164 | watcher->setProperty("connection", con->name()); | ||
165 | connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); | 165 | connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished); | ||
166 | } | 166 | } | ||
167 | 167 | | |||
168 | QString Handler::wifiCode(const QString& connectionPath, const QString& specificObject) const | ||||
169 | { | ||||
170 | NetworkManager::AccessPoint::Ptr ap; | ||||
jgrulich: I actually thought that instead of all this logic, where you search for wireless device, AP and… | |||||
171 | NetworkManager::WirelessDevice::Ptr wifiDev; | ||||
172 | for (const NetworkManager::Device::Ptr &dev : NetworkManager::networkInterfaces()) { | ||||
173 | if (dev->type() == NetworkManager::Device::Wifi) { | ||||
174 | wifiDev = dev.objectCast<NetworkManager::WirelessDevice>(); | ||||
175 | ap = wifiDev->findAccessPoint(specificObject); | ||||
176 | if (ap) { | ||||
177 | break; | ||||
178 | } | ||||
179 | } | ||||
180 | } | ||||
181 | | ||||
182 | if (!ap) { | ||||
183 | return {}; | ||||
184 | } | ||||
185 | | ||||
186 | // https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11 | ||||
187 | | ||||
188 | const NetworkManager::WirelessSecurityType securityType = NetworkManager::findBestWirelessSecurity(wifiDev->wirelessCapabilities(), true, (ap->mode() == NetworkManager::AccessPoint::Adhoc), ap->capabilities(), ap->wpaFlags(), ap->rsnFlags()); | ||||
Each item in the model already exposes SecurityType so you don't need to search for the AP and find security type it uses. jgrulich: Each item in the model already exposes **SecurityType** so you don't need to search for the AP… | |||||
189 | QString ret = QStringLiteral("WIFI:"); | ||||
190 | if (securityType != NetworkManager::NoneSecurity) { | ||||
191 | switch (securityType) { | ||||
192 | case NetworkManager::NoneSecurity: | ||||
193 | break; | ||||
194 | case NetworkManager::StaticWep: | ||||
195 | case NetworkManager::DynamicWep: | ||||
196 | ret += "T:WEP;"; | ||||
197 | break; | ||||
198 | case NetworkManager::WpaPsk: | ||||
199 | case NetworkManager::Wpa2Psk: | ||||
200 | ret += "T:WPA;"; | ||||
201 | break; | ||||
202 | default: | ||||
203 | case NetworkManager::WpaEap: | ||||
204 | case NetworkManager::Wpa2Eap: | ||||
205 | case NetworkManager::Leap: | ||||
206 | return {}; | ||||
207 | } | ||||
208 | } | ||||
209 | ret += QStringLiteral("S:") + ap->ssid() + QLatin1Char(';'); | ||||
210 | | ||||
211 | NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(connectionPath); | ||||
212 | const auto key = QStringLiteral("802-11-wireless-security"); | ||||
Networks using WPA2-EAP or DynamicWEP don't have secrets stored as 802-11-wireless-security, these are under 802-1-x. Anyway, I think we should maybe filter these out, you will most likely won't be sharing them anyway. You can do that in the applet already, check predictableWirelessPassword property. jgrulich: Networks using WPA2-EAP or DynamicWEP don't have secrets stored as **802-11-wireless-security**… | |||||
213 | auto reply = connection->secrets(key); | ||||
214 | | ||||
215 | const auto secret = reply.argumentAt<0>()[key]; | ||||
216 | QString pass; | ||||
217 | switch (securityType) { | ||||
218 | case NetworkManager::NoneSecurity: | ||||
219 | break; | ||||
220 | case NetworkManager::WpaPsk: | ||||
221 | case NetworkManager::Wpa2Psk: | ||||
222 | pass = secret["psk"].toString(); | ||||
223 | break; | ||||
224 | default: | ||||
225 | return {}; | ||||
226 | } | ||||
227 | if (!pass.isEmpty()) | ||||
228 | ret += QStringLiteral("P:") + pass; | ||||
229 | | ||||
230 | KNotification *notification = new KNotification("WifiQR", KNotification::CloseOnTimeout); | ||||
broulik: What does this do? | |||||
apol: Yeah forgot to remove it. | |||||
231 | notification->setComponentName("networkmanagement"); | ||||
232 | notification->setTitle(connection->name()); | ||||
233 | | ||||
234 | return ret; | ||||
235 | } | ||||
236 | | ||||
168 | void Handler::addAndActivateConnection(const QString& device, const QString& specificObject, const QString& password) | 237 | void Handler::addAndActivateConnection(const QString& device, const QString& specificObject, const QString& password) | ||
169 | { | 238 | { | ||
170 | NetworkManager::AccessPoint::Ptr ap; | 239 | NetworkManager::AccessPoint::Ptr ap; | ||
171 | NetworkManager::WirelessDevice::Ptr wifiDev; | 240 | NetworkManager::WirelessDevice::Ptr wifiDev; | ||
172 | for (const NetworkManager::Device::Ptr &dev : NetworkManager::networkInterfaces()) { | 241 | for (const NetworkManager::Device::Ptr &dev : NetworkManager::networkInterfaces()) { | ||
173 | if (dev->type() == NetworkManager::Device::Wifi) { | 242 | if (dev->type() == NetworkManager::Device::Wifi) { | ||
174 | wifiDev = dev.objectCast<NetworkManager::WirelessDevice>(); | 243 | wifiDev = dev.objectCast<NetworkManager::WirelessDevice>(); | ||
175 | ap = wifiDev->findAccessPoint(specificObject); | 244 | ap = wifiDev->findAccessPoint(specificObject); | ||
▲ Show 20 Lines • Show All 411 Lines • Show Last 20 Lines |
I actually thought that instead of all this logic, where you search for wireless device, AP and then to get the security type, you will pass those information from the applet, instead of the specificObject. Even ssid is exposed from the model so you can just pass ssid as an argument and security type as another one and almost all this code below can go away.