Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into upgrade-2.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rainemak committed Oct 1, 2018
2 parents 068e559 + eaffeda commit e907fb6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion rpm/nemo-qml-plugin-systemsettings.spec
@@ -1,6 +1,6 @@
Name: nemo-qml-plugin-systemsettings
Summary: System settings plugin for Nemo Mobile
Version: 0.3.0
Version: 0.4
Release: 1
Group: System/Libraries
License: BSD
Expand Down
48 changes: 23 additions & 25 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 All @@ -488,6 +480,7 @@ void VpnModel::deleteConnection(const QString &path)
if (conn->state() == VpnModel::Ready || conn->state() == VpnModel::Configuration) {
ConnmanServiceProxy* proxy = vpnServices_.value(path);
if (proxy) {
proxy->SetProperty(autoConnectKey, QDBusVariant(false));
QDBusPendingCall call = proxy->Disconnect();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, path](QDBusPendingCallWatcher *watcher) {
Expand Down Expand Up @@ -572,8 +565,6 @@ void VpnModel::activateConnection(const QString &path)

ConnmanServiceProxy* proxy = vpnServices_.value(path);
if (proxy) {
// TODO: Maybe possible to remove after Sailfish OS 2.2.1 release.
proxy->SetProperty(autoConnectKey, QDBusVariant(true));
QDBusPendingCall call = proxy->Connect();
qCDebug(lcVpnLog) << "Connect to vpn" << path;

Expand All @@ -596,7 +587,6 @@ void VpnModel::deactivateConnection(const QString &path)
qCInfo(lcVpnLog) << "Disconnect" << path;
ConnmanServiceProxy* proxy = vpnServices_.value(path);
if (proxy) {
proxy->SetProperty(autoConnectKey, QDBusVariant(false));
QDBusPendingCall call = proxy->Disconnect();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, path](QDBusPendingCallWatcher *watcher) {
Expand Down Expand Up @@ -811,6 +801,14 @@ VpnConnection *VpnModel::newConnection(const QString &path)
}
});

connect(conn, &VpnConnection::autoConnectChanged, conn, [this, conn]() {
qCInfo(lcVpnLog) << "VPN autoconnect changed:" << conn->name() << conn->autoConnect();
ConnmanServiceProxy* proxy = vpnServices_.value(conn->path());
if (proxy) {
proxy->SetProperty(autoConnectKey, QDBusVariant(conn->autoConnect()));
}
});

return conn;
}

Expand Down

0 comments on commit e907fb6

Please sign in to comment.