Skip to content

Commit

Permalink
[settings-system] Make VPN model modifyConnection only to set propert…
Browse files Browse the repository at this point in the history
…ies. Contributes to JB#43090
  • Loading branch information
rainemak committed Oct 1, 2018
1 parent e091ed1 commit c921b60
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/vpnmodel.cpp
Expand Up @@ -429,13 +429,13 @@ void VpnModel::createConnection(const QVariantMap &createProperties)

void VpnModel::modifyConnection(const QString &path, const QVariantMap &properties)
{
if (VpnConnection *conn = connection(path)) {
auto it = connections_.find(path);
if (it != connections_.end()) {
// ConnmanVpnConnectionProxy provides the SetProperty interface to modify a connection,
// but as far as I can tell, the only way to cause Connman to store the configuration to
// disk is to create a new connection... Work around this by removing the existing
// connection and recreating it with the updated properties.
qCWarning(lcVpnLog) << "Removing VPN connection for modification:" << conn->path();
deleteConnection(conn->path());
qCWarning(lcVpnLog) << "Updating VPN connection for modification:" << path;

// Remove properties that connman doesn't know about
QVariantMap updatedProperties(properties);
Expand All @@ -454,29 +454,21 @@ void VpnModel::modifyConnection(const QString &path, const QVariantMap &properti
const bool couldStoreCredentials(credentials_.credentialsExist(location));
const bool canStoreCredentials(properties.value(QString("storeCredentials")).toBool());

QDBusPendingCall call = connmanVpn_.Create(propertiesToDBus(updatedProperties));

QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, conn, location, canStoreCredentials, couldStoreCredentials](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<QDBusObjectPath> reply = *watcher;
watcher->deleteLater();
ConnmanVpnConnectionProxy *proxy(*it);
QVariantMap dbusProps = propertiesToDBus(updatedProperties);
for (QMap<QString, QVariant>::const_iterator i = dbusProps.constBegin(); i != dbusProps.constEnd(); ++i) {
proxy->SetProperty(i.key(), QDBusVariant(i.value()));
}

if (reply.isError()) {
qCWarning(lcVpnLog) << "Unable to recreate Connman VPN connection:" << reply.error().message();
if (canStoreCredentials != couldStoreCredentials) {
if (canStoreCredentials) {
credentials_.storeCredentials(location, QVariantMap());
} else {
const QDBusObjectPath &objectPath(reply.value());
qCWarning(lcVpnLog) << "Modified VPN connection:" << objectPath.path();
credentials_.removeCredentials(location);
}
}

if (canStoreCredentials != couldStoreCredentials) {
if (canStoreCredentials) {
credentials_.storeCredentials(location, QVariantMap());
} else {
credentials_.removeCredentials(location);

}
}
}
});
} else {
qCWarning(lcVpnLog) << "Unable to update unknown VPN connection:" << path;
}
Expand Down

0 comments on commit c921b60

Please sign in to comment.