Skip to content

Commit

Permalink
[libconnman-qt] Clear all vpn connections upon connman stop (restart)…
Browse files Browse the repository at this point in the history
…. Fixes JB#48087

VpnManager emits connectionsCleared when all connections have been removed.
  • Loading branch information
rainemak committed Nov 27, 2019
1 parent f3ba989 commit 16ca1f9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
14 changes: 9 additions & 5 deletions libconnman-qt/vpnmanager.cpp
Expand Up @@ -110,20 +110,24 @@ void VpnManagerPrivate::init()

emit q->connectionRemoved(path);
emit q->connectionsChanged();

if (m_items.isEmpty()) {
emit q->connectionsCleared();
}
});

// If connman-vpn restarts, we need to discard and re-read the state
QDBusServiceWatcher *watcher = new QDBusServiceWatcher(connmanVpnService, QDBusConnection::systemBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, q);
VpnManager::connect(watcher, &QDBusServiceWatcher::serviceUnregistered, q, [this](const QString &) {
Q_Q(VpnManager);

emit q->connectionsClearingAll();

for (int i = 0, n = m_items.size(); i < n; ++i) {
m_items.at(i)->deleteLater();
}
emit beginConnectionsReset();
qDeleteAll(m_items);
m_items.clear();
emit endConnectionsReset();
setPopulated(false);

emit q->connectionsCleared();
});
VpnManager::connect(watcher, &QDBusServiceWatcher::serviceRegistered, q, [this](const QString &) {
fetchVpnList();
Expand Down
2 changes: 1 addition & 1 deletion libconnman-qt/vpnmanager.h
Expand Up @@ -90,8 +90,8 @@ class VpnManager : public QObject
void connectionsChanged();
void connectionAdded(const QString &path);
void connectionRemoved(const QString &path);
void connectionsClearingAll();
void connectionsRefreshed();
void connectionsCleared();
void populatedChanged();

private:
Expand Down
10 changes: 9 additions & 1 deletion libconnman-qt/vpnmanager_p.h
Expand Up @@ -37,8 +37,9 @@

#include "vpnmanager.h"

class VpnManagerPrivate
class VpnManagerPrivate : public QObject
{
Q_OBJECT
Q_DECLARE_PUBLIC(VpnManager)

public:
Expand All @@ -47,6 +48,13 @@ class VpnManagerPrivate
void fetchVpnList();
void setPopulated(bool populated);

static VpnManagerPrivate *get(VpnManager *manager) { return manager->d_func(); }
static const VpnManagerPrivate *get(const VpnManager *manager) { return manager->d_func(); }

Q_SIGNALS:
void beginConnectionsReset();
void endConnectionsReset();

public:
NetConnmanVpnManagerInterface m_connmanVpn;
QVector<VpnConnection*> m_items;
Expand Down
11 changes: 11 additions & 0 deletions libconnman-qt/vpnmodel.cpp
Expand Up @@ -37,6 +37,8 @@
#include "vpnmodel.h"
#include "vpnmodel_p.h"

#include "vpnmanager_p.h"

const QHash<int, QByteArray> VpnModelPrivate::m_roles({{VpnModel::VpnRole, "vpnService"}});

// ==========================================================================
Expand All @@ -60,6 +62,15 @@ void VpnModelPrivate::init()
VpnModel::connect(m_manager, &VpnManager::connectionsChanged, q, &VpnModel::connectionsChanged);
VpnModel::connect(m_manager, &VpnManager::populatedChanged, q, &VpnModel::populatedChanged);

VpnModel::connect(VpnManagerPrivate::get(m_manager), &VpnManagerPrivate::beginConnectionsReset, q, [q, this]() {
q->beginResetModel();
m_connections.clear();
});

VpnModel::connect(VpnManagerPrivate::get(m_manager), &VpnManagerPrivate::endConnectionsReset, q, [q]() {
q->endResetModel();
});

q->connectionsChanged();
}

Expand Down

0 comments on commit 16ca1f9

Please sign in to comment.