Commit 3db1ea15 authored by Raine Makelainen's avatar Raine Makelainen

[nemo-systemsettings] Add autoConnect property for VpnConnection. Contributes to JB#41460

parent 1fc9cd50
<?xml version="1.0"?>
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="net.connman.Service">
<method name="GetProperties">
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
<arg name="properties" type="a{sv}" direction="out"/>
</method>
<method name="SetProperty">
<arg name="name" type="s" direction="in"/>
<arg name="value" type="v" direction="in"/>
</method>
<method name="ClearProperty">
<arg name="name" type="s" direction="in"/>
</method>
<method name="Connect"/>
<method name="Disconnect"/>
<method name="Remove"/>
<method name="MoveBefore">
<arg name="service" type="o" direction="in"/>
</method>
<method name="MoveAfter">
<arg name="service" type="o" direction="in"/>
</method>
<method name="ResetCounters"/>
<signal name="PropertyChanged">
<arg name="name" type="s"/>
<arg name="value" type="v"/>
</signal>
<property name="State" type="s" access="read"/>
<property name="Error" type="s" access="read"/>
<property name="AutoConnect" type="b" access="readwrite"/>
</interface>
</node>
......@@ -12,6 +12,7 @@ PKGCONFIG += ssu-sysinfo nemodbus
system(qdbusxml2cpp -p mceiface.h:mceiface.cpp mce.xml)
system(qdbusxml2cpp -c ConnmanVpnProxy -p connmanvpnproxy ../dbus/net.connman.vpn.xml -i qdbusxml2cpp_dbus_types.h)
system(qdbusxml2cpp -c ConnmanVpnConnectionProxy -p connmanvpnconnectionproxy ../dbus/net.connman.vpn.Connection.xml -i qdbusxml2cpp_dbus_types.h)
system(qdbusxml2cpp -c ConnmanServiceProxy -p connmanserviceproxy ../dbus/net.connman.service.xml -i qdbusxml2cpp_dbus_types.h)
SOURCES += \
languagemodel.cpp \
......@@ -24,6 +25,7 @@ SOURCES += \
aboutsettings.cpp \
certificatemodel.cpp \
vpnmodel.cpp \
connmanserviceproxy.cpp \
connmanvpnproxy.cpp \
connmanvpnconnectionproxy.cpp \
developermodesettings.cpp \
......@@ -49,6 +51,7 @@ PUBLIC_HEADERS = \
aboutsettings.h \
certificatemodel.h \
vpnmodel.h \
connmanserviceproxy.h \
connmanvpnproxy.h \
connmanvpnconnectionproxy.h \
developermodesettings.h \
......
......@@ -32,15 +32,27 @@
#include "vpnmodel.h"
#include "logging_p.h"
#include "connmanvpnconnectionproxy.h"
#include "connmanserviceproxy.h"
#include <QCryptographicHash>
#include <QDBusPendingCallWatcher>
#include <QDBusServiceWatcher>
#include <QRegularExpression>
#include <nemo-dbus/dbus.h>
namespace {
const QString defaultDomain(QStringLiteral("merproject.org"));
const auto connmanService = QStringLiteral("net.connman");
const auto connmanVpnService = QStringLiteral("net.connman.vpn");
const auto autoConnectKey = QStringLiteral("AutoConnect");
QString vpnServicePath(QString connectionPath)
{
return QString("/net/connman/service/vpn_%1").arg(connectionPath.section("/", 5));
}
// Conversion to/from DBus/QML
QHash<QString, QList<QPair<QVariant, QVariant> > > propertyConversions()
......@@ -374,7 +386,7 @@ QVariantMap VpnModel::CredentialsRepository::decodeCredentials(const QByteArray
VpnModel::VpnModel(QObject *parent)
: ObjectListModel(parent, true, false)
, connmanVpn_("net.connman.vpn", "/", QDBusConnection::systemBus(), this)
, connmanVpn_(connmanVpnService, "/", QDBusConnection::systemBus(), this)
, tokenFiles_("/home/nemo/.local/share/system/vpn")
, credentials_("/home/nemo/.local/share/system/vpn-data")
, bestState_(VpnModel::Idle)
......@@ -413,10 +425,17 @@ VpnModel::VpnModel(QObject *parent)
connections_.erase(it);
delete proxy;
}
auto vpnServiceIterator = vpnServices_.find(path);
if (vpnServiceIterator != vpnServices_.end()) {
ConnmanServiceProxy *proxy(*vpnServiceIterator);
vpnServices_.erase(vpnServiceIterator);
delete proxy;
}
});
// If connman-vpn restarts, we need to discard and re-read the state
QDBusServiceWatcher *watcher = new QDBusServiceWatcher("net.connman.vpn", QDBusConnection::systemBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this);
QDBusServiceWatcher *watcher = new QDBusServiceWatcher(connmanVpnService, QDBusConnection::systemBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this);
connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, [this](const QString &) {
for (int i = 0, n = count(); i < n; ++i) {
get(i)->deleteLater();
......@@ -424,6 +443,7 @@ VpnModel::VpnModel(QObject *parent)
clear();
setPopulated(false);
qDeleteAll(connections_);
qDeleteAll(vpnServices_);
});
connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, [this](const QString &) {
fetchVpnList();
......@@ -795,16 +815,50 @@ VpnConnection *VpnModel::newConnection(const QString &path)
VpnConnection *conn = new VpnConnection(path);
appendItem(conn);
// Create a proxy for this connection
ConnmanVpnConnectionProxy *proxy = new ConnmanVpnConnectionProxy("net.connman.vpn", path, QDBusConnection::systemBus(), nullptr);
// Create a vpn and a connman service proxies for this connection
ConnmanVpnConnectionProxy *proxy = new ConnmanVpnConnectionProxy(connmanVpnService, path, QDBusConnection::systemBus(), nullptr);
ConnmanServiceProxy *serviceProxy = new ConnmanServiceProxy(connmanService, vpnServicePath(path), QDBusConnection::systemBus(), nullptr);
connections_.insert(path, proxy);
vpnServices_.insert(path, serviceProxy);
QDBusPendingCall servicePropertiesCall = serviceProxy->GetProperties();
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(servicePropertiesCall, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, conn, path](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<> reply = *watcher;
if (reply.isFinished() && reply.isValid()) {
QDBusMessage message = reply.reply();
QVariantMap properties = NemoDBus::demarshallArgument<QVariantMap>(message.arguments().value(0));
bool autoConnect = properties.value(autoConnectKey).toBool();
properties.clear();
properties.insert(autoConnectKey, autoConnect);
qCInfo(lcVpnLog) << "Initial VPN service properties:" << properties << path << conn->name();
updateConnection(conn, propertiesToQml(properties));
} else {
qCDebug(lcVpnLog) << "Error :" << path << ":" << reply.error().message();
}
watcher->deleteLater();
});
connect(proxy, &ConnmanVpnConnectionProxy::PropertyChanged, this, [this, conn](const QString &name, const QDBusVariant &value) {
ConnmanVpnConnectionProxy *proxy = qobject_cast<ConnmanVpnConnectionProxy *>(sender());
QVariantMap properties;
qCInfo(lcVpnLog) << "VPN connection property changed:" << name << value.variant() << proxy->path() << conn->name();
properties.insert(name, value.variant());
updateConnection(conn, propertiesToQml(properties));
});
connect(serviceProxy, &ConnmanServiceProxy::PropertyChanged, this, [this, conn](const QString &name, const QDBusVariant &value) {
ConnmanServiceProxy *proxy = qobject_cast<ConnmanServiceProxy *>(sender());
qCInfo(lcVpnLog) << "VPN service property changed:" << name << value.variant() << proxy->path() << conn->name();
if (name == autoConnectKey) {
QVariantMap properties;
properties.insert(name, value.variant());
updateConnection(conn, propertiesToQml(properties));
}
});
return conn;
}
......@@ -1101,6 +1155,11 @@ VpnConnection::VpnConnection(const QString &path)
, path_(path)
, state_(static_cast<int>(VpnModel::Disconnect))
, type_("openvpn")
, autoConnect_(false)
, automaticUpDown_(false)
, storeCredentials_(false)
, immutable_(false)
, index_(-1)
{
}
......@@ -34,22 +34,21 @@
#define VPNMODEL_H
#include "connmanvpnproxy.h"
#include "connmanvpnconnectionproxy.h"
#include <systemsettingsglobal.h>
#include <objectlistmodel.h>
#include <QDir>
#include <QVariantMap>
class ConnmanServiceProxy;
class ConnmanVpnConnectionProxy;
class SYSTEMSETTINGS_EXPORT VpnConnection;
class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
{
Q_OBJECT
Q_ENUMS(ConnectionState)
Q_PROPERTY(int bestState READ bestState NOTIFY bestStateChanged)
......@@ -61,6 +60,7 @@ public:
Ready,
Disconnect,
};
Q_ENUM(ConnectionState)
explicit VpnModel(QObject *parent = 0);
virtual ~VpnModel();
......@@ -142,6 +142,7 @@ private:
ConnmanVpnProxy connmanVpn_;
QHash<QString, ConnmanVpnConnectionProxy *> connections_;
QHash<QString, ConnmanServiceProxy *> vpnServices_;
TokenFileRepository tokenFiles_;
CredentialsRepository credentials_;
ConnectionState bestState_;
......@@ -155,6 +156,7 @@ class SYSTEMSETTINGS_EXPORT VpnConnection : public QObject
Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged)
Q_PROPERTY(QString networks READ networks WRITE setNetworks NOTIFY networksChanged)
Q_PROPERTY(bool autoConnect READ autoConnect WRITE setAutoConnect NOTIFY autoConnectChanged)
Q_PROPERTY(bool automaticUpDown READ automaticUpDown WRITE setAutomaticUpDown NOTIFY automaticUpDownChanged)
Q_PROPERTY(bool storeCredentials READ storeCredentials WRITE setStoreCredentials NOTIFY storeCredentialsChanged)
Q_PROPERTY(int state READ state WRITE setState NOTIFY stateChanged)
......@@ -185,6 +187,9 @@ public:
QString networks() const { return networks_; }
void setNetworks(const QString &networks) { updateMember(&VpnConnection::networks_, networks, &VpnConnection::networksChanged); }
bool autoConnect() const { return autoConnect_; }
void setAutoConnect(bool autoConnect) { updateMember(&VpnConnection::autoConnect_, autoConnect, &VpnConnection::autoConnectChanged); }
bool automaticUpDown() const { return automaticUpDown_; }
void setAutomaticUpDown(bool automaticUpDown) { updateMember(&VpnConnection::automaticUpDown_, automaticUpDown, &VpnConnection::automaticUpDownChanged); }
......@@ -228,6 +233,7 @@ signals:
void hostChanged();
void domainChanged();
void networksChanged();
void autoConnectChanged();
void automaticUpDownChanged();
void storeCredentialsChanged();
void immutableChanged();
......@@ -257,6 +263,7 @@ private:
QString host_;
QString domain_;
QString networks_;
bool autoConnect_;
bool automaticUpDown_;
bool storeCredentials_;
bool immutable_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment