Skip to content

Commit

Permalink
Merge branch 'jb43090-vpn-modify' into 'upgrade-2.2.1'
Browse files Browse the repository at this point in the history
[settings-system] Make VPN model modifyConnection only to set properties. Contributes to JB#43090

See merge request mer-core/nemo-qml-plugin-systemsettings!83
  • Loading branch information
rainemak committed Oct 1, 2018
2 parents 9e09bbd + 69124cc commit 7788cc3
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions src/vpnmodel.cpp
Expand Up @@ -428,13 +428,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 @@ -453,28 +453,19 @@ 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();

if (canStoreCredentials != couldStoreCredentials) {
if (canStoreCredentials ) {
credentials_.storeCredentials(location, QVariantMap());
} else {
credentials_.removeCredentials(location);
}
}
credentials_.removeCredentials(location);
}
});
}
} else {
qCWarning(lcVpnLog) << "Unable to update unknown VPN connection:" << path;
}
Expand Down

0 comments on commit 7788cc3

Please sign in to comment.