NetworkManagerQt

vpnconnection.cpp
1/*
2 SPDX-FileCopyrightText: 2011 Ilia Kats <ilia-kats@gmx.net>
3 SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "connection.h"
9#include "device.h"
10#include "nmdebug.h"
11#include "settings.h"
12#include "vpnconnection_p.h"
13
14NetworkManager::VpnConnectionPrivate::VpnConnectionPrivate(const QString &path, VpnConnection *q)
15 : ActiveConnectionPrivate(path, q)
16#ifdef NMQT_STATIC
17 , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus())
18#else
19 , iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus())
20#endif
21 , q_ptr(q)
22{
23}
24
25NetworkManager::VpnConnection::State NetworkManager::VpnConnectionPrivate::convertVpnConnectionState(uint state)
26{
27 return static_cast<NetworkManager::VpnConnection::State>(state);
28}
29
30NetworkManager::VpnConnection::StateChangeReason NetworkManager::VpnConnectionPrivate::convertVpnConnectionStateReason(uint reason)
31{
32 return static_cast<NetworkManager::VpnConnection::StateChangeReason>(reason);
33}
34
36 : ActiveConnection(*new VpnConnectionPrivate(path, this), parent)
37{
39
40 QDBusConnection::systemBus().connect(NetworkManagerPrivate::DBUS_SERVICE,
41 d->path,
42 NetworkManagerPrivate::FDO_DBUS_PROPERTIES,
43 QLatin1String("PropertiesChanged"),
44 d,
45 SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList)));
46 connect(&d->iface, &OrgFreedesktopNetworkManagerVPNConnectionInterface::VpnStateChanged, d, &VpnConnectionPrivate::vpnStateChanged);
47
48 // We need to get ActiveConnection's properties, because by default every ActiveConnection
49 // is basically a VpnConnection
50 QVariantMap initialProperties =
51 NetworkManagerPrivate::retrieveInitialProperties(OrgFreedesktopNetworkManagerConnectionActiveInterface::staticInterfaceName(), path);
52 if (!initialProperties.isEmpty()) {
53 d->propertiesChanged(initialProperties);
54 }
55
56 // Try to retrieve VPN specific properties if this is a VPN connection
57 if (vpn()) {
58 // Get all VpnConnection's properties at once
59 QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path);
60 if (!initialProperties.isEmpty()) {
61 d->propertiesChanged(initialProperties);
62 }
63 }
64}
65
69
71{
72 Q_D(const VpnConnection);
73 // return d->banner; // FIXME NM doesn't Q_EMIT the Banner property change
74 return d->iface.banner();
75}
76
82
83void NetworkManager::VpnConnectionPrivate::dbusPropertiesChanged(const QString &interfaceName,
84 const QVariantMap &properties,
85 const QStringList &invalidatedProperties)
86{
87 Q_UNUSED(invalidatedProperties);
88
89 if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.VPN.Connection")) {
90 propertiesChanged(properties);
91 } else {
92 ActiveConnectionPrivate::propertiesChanged(properties);
93 }
94}
95
96void NetworkManager::VpnConnectionPrivate::propertyChanged(const QString &property, const QVariant &value)
97{
98 Q_Q(VpnConnection);
99
100 if (property == QLatin1String("Banner")) {
101 banner = value.toString();
102 Q_EMIT q->bannerChanged(banner);
103 } else if (property == QLatin1String("VpnState")) {
104 // Do not notify about changed VpnState twice, because there is also signal VpnStateChanged() from NetworkManager
105 state = NetworkManager::VpnConnectionPrivate::convertVpnConnectionState(value.toUInt());
106 // NetworkManager::VpnConnection::StateChangeReason reason =
107 // NetworkManager::VpnConnectionPrivate::convertVpnConnectionStateReason(properties.key("Reason").toUInt()); Q_EMIT stateChanged(d->state, reason);
108 } else {
109 ActiveConnectionPrivate::propertyChanged(property, value);
110 }
111}
112
113void NetworkManager::VpnConnectionPrivate::vpnStateChanged(uint newState, uint reason)
114{
115 Q_Q(VpnConnection);
116 Q_UNUSED(reason);
117
118 state = NetworkManager::VpnConnectionPrivate::convertVpnConnectionState(newState);
119 NetworkManager::VpnConnection::StateChangeReason stateChangeReason = NetworkManager::VpnConnectionPrivate::convertVpnConnectionStateReason(reason);
120 Q_EMIT q->stateChanged(state, stateChangeReason);
121}
122
123NetworkManager::VpnConnection::operator VpnConnection *()
124{
126 if (d->vpn) {
127 return this;
128 } else {
129 return nullptr;
130 }
131}
132
133#include "moc_vpnconnection.cpp"
134#include "moc_vpnconnection_p.cpp"
bool vpn() const
Whether this is a VPN connection.
QString path() const
Return path of the connection object.
An active VPN connection.
~VpnConnection() override
Destroys a VpnConnection object.
VpnConnection(const QString &path, QObject *parent=nullptr)
Creates a new VpnConnection object.
State
Enum describing the possible VPN connection states.
NetworkManager::VpnConnection::State state() const
returns the current state
QString banner() const
Return the current login banner.
QString path(const QString &relativePath)
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection systemBus()
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString toString() const const
uint toUInt(bool *ok) const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.