Commit 07ad3865 authored by mvogt's avatar mvogt

[nemo-qml-plugin-systemsettings] Add model for VPN connections. Contributes to MER#1644

parent 612b7d5b
<?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.vpn.Connection">
<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="Connect2">
<arg name="dbus_sender" type="s" direction="in"/>
</method>
<method name="Disconnect"/>
<signal name="PropertyChanged">
<arg name="name" type="s"/>
<arg name="value" type="v"/>
</signal>
</interface>
</node>
<?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.vpn.Manager">
<method name="Create">
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
<arg name="properties" type="a{sv}" direction="in"/>
<arg name="path" type="o" direction="out"/>
</method>
<method name="Remove">
<arg name="identifier" type="o" direction="in"/>
</method>
<method name="GetConnections">
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="PathPropertiesArray"/>
<arg name="connections" type="a(oa{sv})" direction="out"/>
</method>
<method name="RegisterAgent">
<arg name="path" type="o" direction="in"/>
</method>
<method name="UnregisterAgent">
<arg name="path" type="o" direction="in"/>
</method>
<signal name="ConnectionAdded">
<annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
<arg name="identifier" type="o"/>
<arg name="properties" type="a{sv}"/>
</signal>
<signal name="ConnectionRemoved">
<arg name="identifier" type="o"/>
</signal>
</interface>
</node>
......@@ -19,6 +19,7 @@ BuildRequires: pkgconfig(usb-moded-qt5)
BuildRequires: pkgconfig(libshadowutils)
BuildRequires: pkgconfig(blkid)
BuildRequires: pkgconfig(libcrypto)
BuildRequires: pkgconfig(nemomodels-qt5)
%description
%{summary}.
......
......@@ -46,6 +46,12 @@
#include "diskusage.h"
#include "partitionmodel.h"
#include "certificatemodel.h"
#include "vpnmodel.h"
static QObject *vpnmodel_api_factory(QQmlEngine *, QJSEngine *)
{
return new VpnModel;
}
class SystemSettingsPlugin : public QQmlExtensionPlugin
{
......@@ -72,6 +78,7 @@ public:
qmlRegisterType<PartitionModel>(uri, 1, 0, "PartitionModel");
qmlRegisterType<DeveloperModeSettings>(uri, 1, 0, "DeveloperModeSettings");
qmlRegisterType<CertificateModel>(uri, 1, 0, "CertificateModel");
qmlRegisterSingletonType<VpnModel>(uri, 1, 0, "VpnModel", vpnmodel_api_factory);
qRegisterMetaType<DeveloperModeSettings::Status>("DeveloperModeSettings::Status");
qmlRegisterType<DiskUsage>(uri, 1, 0, "DiskUsage");
}
......
......@@ -2,11 +2,11 @@ TARGET = nemosystemsettings
PLUGIN_IMPORT_PATH = org/nemomobile/systemsettings
TEMPLATE = lib
CONFIG += qt plugin hide_symbols link_pkgconfig
CONFIG += qt plugin c++11 hide_symbols link_pkgconfig
QT += qml dbus network
QT -= gui
PKGCONFIG += profile usb-moded-qt5
PKGCONFIG += profile usb-moded-qt5 nemomodels-qt5
target.path = $$[QT_INSTALL_QML]/$$PLUGIN_IMPORT_PATH
INSTALLS += target
......
#ifndef QDBUSXML2CPP_DBUS_TYPES
#define QDBUSXML2CPP_DBUS_TYPES
#include <QPair>
#include <QList>
#include <QDBusMetaType>
typedef QPair<QDBusObjectPath, QVariantMap> PathProperties;
Q_DECLARE_METATYPE(PathProperties);
typedef QList<PathProperties> PathPropertiesArray;
Q_DECLARE_METATYPE(PathPropertiesArray);
#endif
......@@ -6,9 +6,11 @@ QT += qml dbus systeminfo
QT -= gui
CONFIG += c++11 hide_symbols link_pkgconfig
PKGCONFIG += profile mlite5 timed-qt5 libshadowutils blkid libcrypto
PKGCONFIG += profile mlite5 timed-qt5 libshadowutils blkid libcrypto nemomodels-qt5
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)
SOURCES += \
languagemodel.cpp \
......@@ -19,6 +21,9 @@ SOURCES += \
displaysettings.cpp \
aboutsettings.cpp \
certificatemodel.cpp \
vpnmodel.cpp \
connmanvpnproxy.cpp \
connmanvpnconnectionproxy.cpp \
developermodesettings.cpp \
diskusage.cpp \
diskusage_impl.cpp \
......@@ -35,6 +40,9 @@ PUBLIC_HEADERS = \
displaysettings.h \
aboutsettings.h \
certificatemodel.h \
vpnmodel.h \
connmanvpnproxy.h \
connmanvpnconnectionproxy.h \
developermodesettings.h \
diskusage.h \
partition.h \
......@@ -44,6 +52,7 @@ PUBLIC_HEADERS = \
HEADERS += \
$$PUBLIC_HEADERS \
qdbusxml2cpp_dbus_types.h \
diskusage_p.h \
partition_p.h \
partitionmanager_p.h
......@@ -63,6 +72,6 @@ QMAKE_PKGCONFIG_DESCRIPTION = System settings application development files
QMAKE_PKGCONFIG_LIBDIR = $$target.path
QMAKE_PKGCONFIG_INCDIR = $$develheaders.path
QMAKE_PKGCONFIG_DESTDIR = pkgconfig
QMAKE_PKGCONFIG_REQUIRES = Qt5Core Qt5DBus profile
QMAKE_PKGCONFIG_REQUIRES = Qt5Core Qt5DBus profile nemomodels-qt5
INSTALLS += target develheaders pkgconfig
This diff is collapsed.
/*
* Copyright (C) 2016 Jolla Ltd.
* Contact: Matt Vogt <matthew.vogt@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#ifndef VPNMODEL_H
#define VPNMODEL_H
#include "connmanvpnproxy.h"
#include "connmanvpnconnectionproxy.h"
#include <systemsettingsglobal.h>
#include <objectlistmodel.h>
#include <QVariantMap>
class SYSTEMSETTINGS_EXPORT VpnConnection;
class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
{
Q_OBJECT
Q_ENUMS(ConnectionState)
Q_ENUMS(ConnectionType)
public:
enum ConnectionState {
Idle,
Failure,
Configuration,
Ready,
Disconnect,
};
enum ConnectionType {
OpenVPN,
OpenConnect,
VPNC,
L2TP,
PPTP,
};
explicit VpnModel(QObject *parent = 0);
virtual ~VpnModel();
Q_INVOKABLE void createConnection(const QVariantMap &properties);
Q_INVOKABLE void modifyConnection(const QString &path, const QVariantMap &properties);
Q_INVOKABLE void deleteConnection(const QString &path);
Q_INVOKABLE void activateConnection(const QString &path);
Q_INVOKABLE void deactivateConnection(const QString &path);
Q_INVOKABLE QVariantMap connectionSettings(const QString &path);
private:
void fetchVpnList();
VpnConnection *connection(const QString &path) const;
VpnConnection *newConnection(const QString &path);
void updateConnection(VpnConnection *conn, const QVariantMap &properties);
ConnmanVpnProxy connmanVpn_;
QHash<QString, ConnmanVpnConnectionProxy *> connections_;
};
class SYSTEMSETTINGS_EXPORT VpnConnection : public QObject
{
Q_OBJECT
Q_PROPERTY(QString path READ path CONSTANT)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
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(int state READ state WRITE setState NOTIFY stateChanged)
Q_PROPERTY(int type READ type WRITE setType NOTIFY typeChanged)
Q_PROPERTY(bool immutable READ immutable WRITE setImmutable NOTIFY immutableChanged)
Q_PROPERTY(int index READ index WRITE setIndex NOTIFY indexChanged)
Q_PROPERTY(QVariantMap iPv4 READ iPv4 WRITE setIPv4 NOTIFY iPv4Changed)
Q_PROPERTY(QVariantMap iPv6 READ iPv6 WRITE setIPv6 NOTIFY iPv6Changed)
Q_PROPERTY(QStringList nameservers READ nameservers WRITE setNameservers NOTIFY nameserversChanged)
Q_PROPERTY(QVariantList userRoutes READ userRoutes WRITE setUserRoutes NOTIFY userRoutesChanged)
Q_PROPERTY(QVariantList serverRoutes READ serverRoutes WRITE setServerRoutes NOTIFY serverRoutesChanged)
Q_PROPERTY(QVariantMap providerProperties READ providerProperties WRITE setProviderProperties NOTIFY providerPropertiesChanged)
public:
VpnConnection(const QString &path);
QString path() const { return path_; }
QString name() const { return name_; }
void setName(const QString &name) { updateMember(&VpnConnection::name_, name, &VpnConnection::nameChanged); }
QString host() const { return host_; }
void setHost(const QString &host) { updateMember(&VpnConnection::host_, host, &VpnConnection::hostChanged); }
QString domain() const { return domain_; }
void setDomain(const QString &domain) { updateMember(&VpnConnection::domain_, domain, &VpnConnection::domainChanged); }
QString networks() const { return networks_; }
void setNetworks(const QString &networks) { updateMember(&VpnConnection::networks_, networks, &VpnConnection::networksChanged); }
int state() const { return state_; }
void setState(int state) { updateMember(&VpnConnection::state_, state, &VpnConnection::stateChanged); }
int type() const { return type_; }
void setType(int type) { updateMember(&VpnConnection::type_, type, &VpnConnection::typeChanged); }
bool immutable() const { return immutable_; }
void setImmutable(bool immutable) { updateMember(&VpnConnection::immutable_, immutable, &VpnConnection::immutableChanged); }
int index() const { return index_; }
void setIndex(int index) { updateMember(&VpnConnection::index_, index, &VpnConnection::indexChanged); }
QVariantMap iPv4() const { return ipv4_; }
void setIPv4(const QVariantMap &ipv4) { updateMember(&VpnConnection::ipv4_, ipv4, &VpnConnection::iPv4Changed); }
QVariantMap iPv6() const { return ipv6_; }
void setIPv6(const QVariantMap &ipv6) { updateMember(&VpnConnection::ipv6_, ipv6, &VpnConnection::iPv6Changed); }
QStringList nameservers() const { return nameservers_; }
void setNameservers(const QStringList &nameservers) { updateMember(&VpnConnection::nameservers_, nameservers, &VpnConnection::nameserversChanged); }
QVariantList userRoutes() const { return userRoutes_; }
void setUserRoutes(const QVariantList &userRoutes) { updateMember(&VpnConnection::userRoutes_, userRoutes, &VpnConnection::userRoutesChanged); }
QVariantList serverRoutes() const { return serverRoutes_; }
void setServerRoutes(const QVariantList &serverRoutes) { updateMember(&VpnConnection::serverRoutes_, serverRoutes, &VpnConnection::serverRoutesChanged); }
QVariantMap providerProperties() const { return providerProperties_; }
void setProviderProperties(const QVariantMap providerProperties) { updateMember(&VpnConnection::providerProperties_, providerProperties, &VpnConnection::providerPropertiesChanged); }
signals:
void nameChanged();
void stateChanged();
void typeChanged();
void hostChanged();
void domainChanged();
void networksChanged();
void immutableChanged();
void indexChanged();
void iPv4Changed();
void iPv6Changed();
void nameserversChanged();
void userRoutesChanged();
void serverRoutesChanged();
void providerPropertiesChanged();
private:
template<typename T, typename V>
bool updateMember(T VpnConnection::*member, const V &value, void (VpnConnection::*func)()) {
if (this->*member != value) {
this->*member = value;
emit (this->*func)();
return true;
}
return false;
}
QString path_;
QString name_;
int state_;
int type_;
QString host_;
QString domain_;
QString networks_;
bool immutable_;
int index_;
QVariantMap ipv4_;
QVariantMap ipv6_;
QStringList nameservers_;
QVariantList userRoutes_;
QVariantList serverRoutes_;
QVariantMap providerProperties_;
};
Q_DECLARE_METATYPE(VpnModel::ConnectionState)
Q_DECLARE_METATYPE(VpnModel::ConnectionType)
#endif
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