Commit e1f125e9 authored by flypig's avatar flypig

[systemsettings] Update VpnModel to use libconnman-qt VPN API. Contributes to JB#45378

Functionality from VpnModel has now been moved into libconnman-qt
VpnCoreModel. This updates VpnModel to use this libconnman-qt VPN API,
by extending VpnCoreModel, rather than interacting with connman directly
through its dbus interface.
parent 19a8d7e8
#include <QPair>
#include <QList>
#include <QDBusMetaType>
typedef QPair<QDBusObjectPath, QVariantMap> PathProperties;
typedef QList<PathProperties> PathPropertiesArray;
......@@ -10,9 +10,6 @@ PKGCONFIG += profile mlite5 mce timed-qt5 libshadowutils blkid libcrypto nemomod
PKGCONFIG += ssu-sysinfo nemodbus packagekitqt5
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)
languagemodel.cpp \
......@@ -26,9 +23,6 @@ SOURCES += \
aboutsettings.cpp \
certificatemodel.cpp \
vpnmodel.cpp \
connmanserviceproxy.cpp \
connmanvpnproxy.cpp \
connmanvpnconnectionproxy.cpp \
developermodesettings.cpp \
batterystatus.cpp \
diskusage.cpp \
......@@ -54,9 +48,6 @@ PUBLIC_HEADERS = \
aboutsettings.h \
certificatemodel.h \
vpnmodel.h \
connmanserviceproxy.h \
connmanvpnproxy.h \
connmanvpnconnectionproxy.h \
developermodesettings.h \
batterystatus.h \
udisks2block_p.h \
......@@ -72,7 +63,6 @@ PUBLIC_HEADERS = \
qdbusxml2cpp_dbus_types.h \
localeconfig.h \
batterystatus_p.h \
logging_p.h \
This diff is collapsed.
* Copyright (C) 2016 Jolla Ltd.
* Contact: Matt Vogt <>
* Copyright (c) 2016 - 2019 Jolla Ltd.
* Copyright (c) 2019 Open Mobile Platform LLC.
* You may use this file under the terms of the BSD license as follows:
......@@ -33,20 +33,15 @@
#ifndef VPNMODEL_H
#define VPNMODEL_H
#include "connmanvpnproxy.h"
#include <systemsettingsglobal.h>
#include <objectlistmodel.h>
#include <QObject>
#include <QSet>
#include <QDir>
#include <QVariantMap>
class ConnmanServiceProxy;
class ConnmanVpnConnectionProxy;
#include <vpnconnection.h>
#include <vpncoremodel.h>
#include <systemsettingsglobal.h>
class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
class SYSTEMSETTINGS_EXPORT VpnModel : public VpnCoreModel
......@@ -55,24 +50,22 @@ class SYSTEMSETTINGS_EXPORT VpnModel : public ObjectListModel
Q_PROPERTY(bool orderByConnected READ orderByConnected WRITE setOrderByConnected NOTIFY orderByConnectedChanged)
enum ConnectionState {
VpnModel(QObject* parent = nullptr);
~VpnModel() override;
enum ItemRoles {
ConnectedRole = VpnCoreModel::VpnRole + 1
explicit VpnModel(QObject *parent = 0);
virtual ~VpnModel();
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role) const override;
int bestState() const;
bool autoConnect() const;
bool orderByConnected() const;
void setOrderByConnected(bool orderByConnected);
Q_INVOKABLE static bool isDefaultDomain(const QString &domain);
Q_INVOKABLE void createConnection(const QVariantMap &properties);
Q_INVOKABLE void modifyConnection(const QString &path, const QVariantMap &properties);
Q_INVOKABLE void deleteConnection(const QString &path);
......@@ -90,7 +83,7 @@ public:
Q_INVOKABLE QVariantMap processProvisioningFile(const QString &path, const QString &type);
VpnConnection *connection(const QString &path) const;
Q_INVOKABLE VpnConnection *get(int index) const;
void bestStateChanged();
......@@ -99,18 +92,23 @@ signals:
void orderByConnectedChanged();
void fetchVpnList();
VpnConnection *newConnection(const QString &path);
void updateConnection(VpnConnection *conn, const QVariantMap &properties);
QVariantMap processOpenVpnProvisioningFile(QFile &provisioningFile);
bool domainInUse(const QString &domain) const;
QString createDefaultDomain() const;
bool isDefaultDomain(const QString &domain) const;
void reorderConnection(VpnConnection * conn);
virtual void orderConnections(QVector<VpnConnection*> &connections) override;
bool compareConnections(const VpnConnection *i, const VpnConnection *j);
QVariantMap processOpenVpnProvisioningFile(QFile &provisioningFile);
private Q_SLOTS:
void connectionAdded(const QString &path);
void connectionRemoved(const QString &path);
void connectionsClearingAll();
void connectionsRefreshed();
void updatedConnectionPosition();
void connectedChanged();
void stateChanged();
class CredentialsRepository
......@@ -132,144 +130,13 @@ private:
QDir baseDir_;
ConnmanVpnProxy connmanVpn_;
QHash<QString, ConnmanVpnConnectionProxy *> connections_;
QHash<QString, ConnmanServiceProxy *> vpnServices_;
QSet<QString> defaultDomains_;
CredentialsRepository credentials_;
QString provisioningOutputPath_;
ConnectionState bestState_;
VpnConnection::ConnectionState bestState_;
// True if there's one VPN that has autoConnect true
bool autoConnect_;
bool orderByConnected_;
QString provisioningOutputPath_;
QHash<int, QByteArray> roles;
class SYSTEMSETTINGS_EXPORT VpnConnection : public QObject
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(bool autoConnect READ autoConnect WRITE setAutoConnect NOTIFY autoConnectChanged)
Q_PROPERTY(bool storeCredentials READ storeCredentials WRITE setStoreCredentials NOTIFY storeCredentialsChanged)
Q_PROPERTY(int state READ state WRITE setState NOTIFY stateChanged)
Q_PROPERTY(QString 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)
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
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); }
bool autoConnect() const { return autoConnect_; }
void setAutoConnect(bool autoConnect) { updateMember(&VpnConnection::autoConnect_, autoConnect, &VpnConnection::autoConnectChanged); }
bool storeCredentials() const { return storeCredentials_; }
void setStoreCredentials(bool storeCredentials) { updateMember(&VpnConnection::storeCredentials_, storeCredentials, &VpnConnection::storeCredentialsChanged); }
int state() const { return state_; }
void setState(int state) { updateMember(&VpnConnection::state_, state, &VpnConnection::stateChanged); }
QString type() const { return type_; }
void setType(const QString &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); }
int connected() const { return state_ == VpnModel::Ready; }
void nameChanged();
void stateChanged();
void typeChanged();
void hostChanged();
void domainChanged();
void networksChanged();
void autoConnectChanged();
void storeCredentialsChanged();
void immutableChanged();
void indexChanged();
void iPv4Changed();
void iPv6Changed();
void nameserversChanged();
void userRoutesChanged();
void serverRoutesChanged();
void providerPropertiesChanged();
void connectedChanged();
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_;
QString type_;
QString host_;
QString domain_;
QString networks_;
bool autoConnect_;
bool storeCredentials_;
bool immutable_;
int index_;
QVariantMap ipv4_;
QVariantMap ipv6_;
QStringList nameservers_;
QVariantList userRoutes_;
QVariantList serverRoutes_;
QVariantMap providerProperties_;
#endif // VPNMODEL_H
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