1 | /* |
2 | SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | |
7 | #include "vpnplugin.h" |
8 | |
9 | #include "manager_p.h" |
10 | #include "vpnplugininterface.h" |
11 | |
12 | class NetworkManager::VpnPluginPrivate |
13 | { |
14 | public: |
15 | VpnPluginPrivate(const QString &path); |
16 | |
17 | VpnConnection::State state; |
18 | OrgFreedesktopNetworkManagerVPNPluginInterface iface; |
19 | }; |
20 | |
21 | NetworkManager::VpnPluginPrivate::VpnPluginPrivate(const QString &path) |
22 | #ifdef NMQT_STATIC |
23 | : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) |
24 | #else |
25 | : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) |
26 | #endif |
27 | { |
28 | } |
29 | |
30 | NetworkManager::VpnPlugin::VpnPlugin(const QString &path, QObject *parent) |
31 | : QObject(parent) |
32 | , d_ptr(new VpnPluginPrivate(path)) |
33 | { |
34 | Q_D(VpnPlugin); |
35 | d->state = (NetworkManager::VpnConnection::State)d->iface.state(); |
36 | |
37 | QObject::connect(sender: &d->iface, SIGNAL(Config(QVariantMap)), receiver: this, SLOT(setConfig(QVariantMap))); |
38 | QObject::connect(sender: &d->iface, SIGNAL(Failure(uint)), receiver: this, SLOT(setFailure(QString))); |
39 | QObject::connect(sender: &d->iface, SIGNAL(Ip4Config(QVariantMap)), receiver: this, SLOT(setIp4Config(QVariantMap))); |
40 | QObject::connect(sender: &d->iface, SIGNAL(Ip6Config(QVariantMap)), receiver: this, SLOT(setIp6Config(QVariantMap))); |
41 | // QObject::connect(&d->iface, SIGNAL(LoginBanner(QString)), |
42 | // this, SLOT(onLoginBanner(QString))); |
43 | QObject::connect(sender: &d->iface, SIGNAL(StateChanged(uint)), receiver: this, SLOT(onStateChanged(uint))); |
44 | } |
45 | |
46 | NetworkManager::VpnPlugin::~VpnPlugin() |
47 | { |
48 | delete d_ptr; |
49 | } |
50 | |
51 | void NetworkManager::VpnPlugin::connect(const NMVariantMapMap &connection) |
52 | { |
53 | Q_D(VpnPlugin); |
54 | |
55 | QDBusPendingReply<> reply = d->iface.Connect(connection); |
56 | } |
57 | |
58 | void NetworkManager::VpnPlugin::disconnect() |
59 | { |
60 | Q_D(VpnPlugin); |
61 | |
62 | QDBusPendingReply<> reply = d->iface.Disconnect(); |
63 | } |
64 | |
65 | QString NetworkManager::VpnPlugin::needSecrets(const NMVariantMapMap &connection) |
66 | { |
67 | Q_D(VpnPlugin); |
68 | |
69 | QDBusPendingReply<QString> reply = d->iface.NeedSecrets(settings: connection); |
70 | |
71 | return reply.value(); |
72 | } |
73 | |
74 | void NetworkManager::VpnPlugin::setConfig(const QVariantMap &configuration) |
75 | { |
76 | Q_D(VpnPlugin); |
77 | |
78 | QDBusPendingReply<QString> reply = d->iface.SetConfig(configuration); |
79 | |
80 | Q_EMIT configChanged(configuration); |
81 | } |
82 | |
83 | void NetworkManager::VpnPlugin::setFailure(const QString &reason) |
84 | { |
85 | Q_D(VpnPlugin); |
86 | |
87 | QDBusPendingReply<QString> reply = d->iface.SetFailure(reason); |
88 | |
89 | // TODO |
90 | // Q_EMIT failureChanged(reason); |
91 | } |
92 | |
93 | void NetworkManager::VpnPlugin::setIp4Config(const QVariantMap &config) |
94 | { |
95 | Q_D(VpnPlugin); |
96 | |
97 | QDBusPendingReply<> reply = d->iface.SetIp4Config(config); |
98 | |
99 | Q_EMIT ip4ConfigChanged(ip4config: config); |
100 | } |
101 | |
102 | void NetworkManager::VpnPlugin::setIp6Config(const QVariantMap &config) |
103 | { |
104 | Q_D(VpnPlugin); |
105 | |
106 | QDBusPendingReply<> reply = d->iface.SetIp6Config(config); |
107 | |
108 | Q_EMIT ip6ConfigChanged(ip6config: config); |
109 | } |
110 | |
111 | void NetworkManager::VpnPlugin::onStateChanged(uint state) |
112 | { |
113 | Q_D(VpnPlugin); |
114 | |
115 | d->state = (VpnConnection::State)state; |
116 | |
117 | Q_EMIT stateChanged(state: d->state); |
118 | } |
119 | |
120 | #include "moc_vpnplugin.cpp" |
121 | |