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& ssid, int _securityType) const | ||||
169 | { | ||||
170 | NetworkManager::WirelessSecurityType securityType = static_cast<NetworkManager::WirelessSecurityType>(_securityType); | ||||
jgrulich: I actually thought that instead of all this logic, where you search for wireless device, AP and… | |||||
171 | | ||||
172 | QString ret = QStringLiteral("WIFI:S:") + ssid + QLatin1Char(';'); | ||||
173 | if (securityType != NetworkManager::NoneSecurity) { | ||||
174 | switch (securityType) { | ||||
175 | case NetworkManager::NoneSecurity: | ||||
176 | break; | ||||
177 | case NetworkManager::StaticWep: | ||||
178 | ret += "T:WEP;"; | ||||
179 | break; | ||||
180 | case NetworkManager::WpaPsk: | ||||
181 | case NetworkManager::Wpa2Psk: | ||||
182 | ret += "T:WPA;"; | ||||
183 | break; | ||||
184 | default: | ||||
185 | case NetworkManager::DynamicWep: | ||||
186 | case NetworkManager::WpaEap: | ||||
187 | case NetworkManager::Wpa2Eap: | ||||
188 | case NetworkManager::Leap: | ||||
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 | return {}; | ||||
190 | } | ||||
191 | } | ||||
192 | | ||||
193 | NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(connectionPath); | ||||
194 | if(!connection) | ||||
195 | return {}; | ||||
196 | | ||||
197 | const auto key = QStringLiteral("802-11-wireless-security"); | ||||
198 | auto reply = connection->secrets(key); | ||||
199 | | ||||
200 | const auto secret = reply.argumentAt<0>()[key]; | ||||
201 | QString pass; | ||||
202 | switch (securityType) { | ||||
203 | case NetworkManager::NoneSecurity: | ||||
204 | break; | ||||
205 | case NetworkManager::WpaPsk: | ||||
206 | case NetworkManager::Wpa2Psk: | ||||
207 | pass = secret["psk"].toString(); | ||||
208 | break; | ||||
209 | default: | ||||
210 | return {}; | ||||
211 | } | ||||
212 | if (!pass.isEmpty()) | ||||
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 | ret += QStringLiteral("P:") + pass + QLatin1Char(';'); | ||||
214 | | ||||
215 | return ret + QLatin1Char(';'); | ||||
216 | } | ||||
217 | | ||||
168 | void Handler::addAndActivateConnection(const QString& device, const QString& specificObject, const QString& password) | 218 | void Handler::addAndActivateConnection(const QString& device, const QString& specificObject, const QString& password) | ||
169 | { | 219 | { | ||
170 | NetworkManager::AccessPoint::Ptr ap; | 220 | NetworkManager::AccessPoint::Ptr ap; | ||
171 | NetworkManager::WirelessDevice::Ptr wifiDev; | 221 | NetworkManager::WirelessDevice::Ptr wifiDev; | ||
172 | for (const NetworkManager::Device::Ptr &dev : NetworkManager::networkInterfaces()) { | 222 | for (const NetworkManager::Device::Ptr &dev : NetworkManager::networkInterfaces()) { | ||
173 | if (dev->type() == NetworkManager::Device::Wifi) { | 223 | if (dev->type() == NetworkManager::Device::Wifi) { | ||
174 | wifiDev = dev.objectCast<NetworkManager::WirelessDevice>(); | 224 | wifiDev = dev.objectCast<NetworkManager::WirelessDevice>(); | ||
175 | ap = wifiDev->findAccessPoint(specificObject); | 225 | ap = wifiDev->findAccessPoint(specificObject); | ||
176 | if (ap) { | 226 | if (ap) { | ||
177 | break; | 227 | break; | ||
178 | } | 228 | } | ||
179 | } | 229 | } | ||
180 | } | 230 | } | ||
broulik: What does this do? | |||||
apol: Yeah forgot to remove it. | |||||
181 | 231 | | |||
182 | if (!ap) { | 232 | if (!ap) { | ||
183 | return; | 233 | return; | ||
184 | } | 234 | } | ||
185 | 235 | | |||
186 | NetworkManager::ConnectionSettings::Ptr settings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless)); | 236 | NetworkManager::ConnectionSettings::Ptr settings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless)); | ||
187 | settings->setId(ap->ssid()); | 237 | settings->setId(ap->ssid()); | ||
188 | settings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); | 238 | settings->setUuid(NetworkManager::ConnectionSettings::createNewUuid()); | ||
▲ Show 20 Lines • Show All 398 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.