Skip to content

Commit

Permalink
[systemsettings-vpn] Disconnect VPN when removed from the model. Fixe…
Browse files Browse the repository at this point in the history
…s JB#41636
  • Loading branch information
rainemak committed Apr 13, 2018
1 parent 5a1b8b6 commit edc0077
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/vpnmodel.cpp
Expand Up @@ -487,21 +487,31 @@ void VpnModel::modifyConnection(const QString &path, const QVariantMap &properti
void VpnModel::deleteConnection(const QString &path)
{
if (VpnConnection *conn = connection(path)) {
Q_UNUSED(conn)

QDBusPendingCall call = connmanVpn_.Remove(QDBusObjectPath(path));

QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, path](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<void> reply = *watcher;
watcher->deleteLater();

if (reply.isError()) {
qCWarning(lcVpnLog) << "Unable to delete Connman VPN connection:" << path << ":" << reply.error().message();
} else {
qCWarning(lcVpnLog) << "Deleted connection:" << path;
if (conn->state() == VpnModel::Ready || conn->state() == VpnModel::Configuration) {
auto it = connections_.find(path);
if (it != connections_.end()) {
ConnmanVpnConnectionProxy *proxy(*it);
QDBusPendingCall call = proxy->Disconnect();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, path](QDBusPendingCallWatcher *watcher) {
watcher->deleteLater();
// Regardless of reply status let's remove it.
deleteConnection(path);
});
}
});
} else {
QDBusPendingCall call = connmanVpn_.Remove(QDBusObjectPath(path));
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, path](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<void> reply = *watcher;
watcher->deleteLater();
if (reply.isError()) {
qCWarning(lcVpnLog) << "Unable to delete Connman VPN connection:" << path << ":" << reply.error().message();
} else {
qCWarning(lcVpnLog) << "Deleted connection:" << path;
}
});
}
} else {
qCWarning(lcVpnLog) << "Unable to delete unknown connection:" << path;
}
Expand Down

0 comments on commit edc0077

Please sign in to comment.