File indexing completed on 2025-03-16 12:58:27
0001 /* 0002 SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "vpnplugin.h" 0008 0009 #include "manager_p.h" 0010 #include "vpnplugininterface.h" 0011 0012 class NetworkManager::VpnPluginPrivate 0013 { 0014 public: 0015 VpnPluginPrivate(const QString &path); 0016 0017 VpnConnection::State state; 0018 OrgFreedesktopNetworkManagerVPNPluginInterface iface; 0019 }; 0020 0021 NetworkManager::VpnPluginPrivate::VpnPluginPrivate(const QString &path) 0022 #ifdef NMQT_STATIC 0023 : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) 0024 #else 0025 : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) 0026 #endif 0027 { 0028 } 0029 0030 NetworkManager::VpnPlugin::VpnPlugin(const QString &path, QObject *parent) 0031 : QObject(parent) 0032 , d_ptr(new VpnPluginPrivate(path)) 0033 { 0034 Q_D(VpnPlugin); 0035 d->state = (NetworkManager::VpnConnection::State)d->iface.state(); 0036 0037 QObject::connect(&d->iface, SIGNAL(Config(QVariantMap)), this, SLOT(setConfig(QVariantMap))); 0038 QObject::connect(&d->iface, SIGNAL(Failure(uint)), this, SLOT(setFailure(QString))); 0039 QObject::connect(&d->iface, SIGNAL(Ip4Config(QVariantMap)), this, SLOT(setIp4Config(QVariantMap))); 0040 QObject::connect(&d->iface, SIGNAL(Ip6Config(QVariantMap)), this, SLOT(setIp6Config(QVariantMap))); 0041 // QObject::connect(&d->iface, SIGNAL(LoginBanner(QString)), 0042 // this, SLOT(onLoginBanner(QString))); 0043 QObject::connect(&d->iface, SIGNAL(StateChanged(uint)), this, SLOT(onStateChanged(uint))); 0044 } 0045 0046 NetworkManager::VpnPlugin::~VpnPlugin() 0047 { 0048 delete d_ptr; 0049 } 0050 0051 void NetworkManager::VpnPlugin::connect(const NMVariantMapMap &connection) 0052 { 0053 Q_D(VpnPlugin); 0054 0055 QDBusPendingReply<> reply = d->iface.Connect(connection); 0056 } 0057 0058 void NetworkManager::VpnPlugin::disconnect() 0059 { 0060 Q_D(VpnPlugin); 0061 0062 QDBusPendingReply<> reply = d->iface.Disconnect(); 0063 } 0064 0065 QString NetworkManager::VpnPlugin::needSecrets(const NMVariantMapMap &connection) 0066 { 0067 Q_D(VpnPlugin); 0068 0069 QDBusPendingReply<QString> reply = d->iface.NeedSecrets(connection); 0070 0071 return reply.value(); 0072 } 0073 0074 void NetworkManager::VpnPlugin::setConfig(const QVariantMap &configuration) 0075 { 0076 Q_D(VpnPlugin); 0077 0078 QDBusPendingReply<QString> reply = d->iface.SetConfig(configuration); 0079 0080 Q_EMIT configChanged(configuration); 0081 } 0082 0083 void NetworkManager::VpnPlugin::setFailure(const QString &reason) 0084 { 0085 Q_D(VpnPlugin); 0086 0087 QDBusPendingReply<QString> reply = d->iface.SetFailure(reason); 0088 0089 // TODO 0090 // Q_EMIT failureChanged(reason); 0091 } 0092 0093 void NetworkManager::VpnPlugin::setIp4Config(const QVariantMap &config) 0094 { 0095 Q_D(VpnPlugin); 0096 0097 QDBusPendingReply<> reply = d->iface.SetIp4Config(config); 0098 0099 Q_EMIT ip4ConfigChanged(config); 0100 } 0101 0102 void NetworkManager::VpnPlugin::setIp6Config(const QVariantMap &config) 0103 { 0104 Q_D(VpnPlugin); 0105 0106 QDBusPendingReply<> reply = d->iface.SetIp6Config(config); 0107 0108 Q_EMIT ip6ConfigChanged(config); 0109 } 0110 0111 void NetworkManager::VpnPlugin::onStateChanged(uint state) 0112 { 0113 Q_D(VpnPlugin); 0114 0115 d->state = (VpnConnection::State)state; 0116 0117 Q_EMIT stateChanged(d->state); 0118 } 0119 0120 #include "moc_vpnplugin.cpp"