File indexing completed on 2024-04-21 15:06:30

0001 /*
0002     SPDX-FileCopyrightText: 2011 Ilia Kats <ilia-kats@gmx.net>
0003     SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza <lamarque@kde.org>
0004     SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef NETWORKMANAGERQT_VPNCONNECTION_H
0010 #define NETWORKMANAGERQT_VPNCONNECTION_H
0011 
0012 #include <networkmanagerqt/networkmanagerqt_export.h>
0013 
0014 #include "activeconnection.h"
0015 
0016 #include <QDBusObjectPath>
0017 #include <QObject>
0018 
0019 namespace NetworkManager
0020 {
0021 class Device;
0022 class VpnConnectionPrivate;
0023 
0024 /**
0025  * An active VPN connection
0026  */
0027 class NETWORKMANAGERQT_EXPORT VpnConnection : public ActiveConnection
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     typedef QSharedPointer<VpnConnection> Ptr;
0033     typedef QList<Ptr> List;
0034     /**
0035      * Enum describing the possible VPN connection states
0036      */
0037     enum State {
0038         Unknown = 0, /**< The state of the VPN connection is unknown. */
0039         Prepare, /**< The VPN connection is preparing to connect. */
0040         NeedAuth, /**< The VPN connection needs authorization credentials. */
0041         Connecting, /**< The VPN connection is being established. */
0042         GettingIpConfig, /**< The VPN connection is getting an IP address. */
0043         Activated, /**< The VPN connection is active. */
0044         Failed, /**< The VPN connection failed. */
0045         Disconnected, /**< The VPN connection is disconnected. */
0046     };
0047     Q_ENUM(State)
0048 
0049     enum StateChangeReason {
0050         UnknownReason = 0, /**< The reason for the VPN connection state change is unknown.*/
0051         NoneReason, /**< No reason was given for the VPN connection state change. */
0052         UserDisconnectedReason, /**< The VPN connection changed state because the user disconnected it. */
0053         DeviceDisconnectedReason, /**< The VPN connection changed state because the device it was using was disconnected. */
0054         ServiceStoppedReason, /**< The service providing the VPN connection was stopped. */
0055         IpConfigInvalidReason, /**< The IP config of the VPN connection was invalid. */
0056         ConnectTimeoutReason, /**< The connection attempt to the VPN service timed out. */
0057         ServiceStartTimeoutReason, /**< A timeout occurred while starting the service providing the VPN connection. */
0058         ServiceStartFailedReason, /**< Starting the service starting the service providing the VPN connection failed. */
0059         NoSecretsReason, /**< Necessary secrets for the VPN connection were not provided. */
0060         LoginFailedReason, /**< Authentication to the VPN server failed. */
0061         ConnectionRemovedReason, /**< The connection was deleted from settings. */
0062     };
0063     Q_ENUM(StateChangeReason)
0064 
0065     /**
0066      * Creates a new VpnConnection object.
0067      *
0068      * @param path the DBus path of the device
0069      */
0070     explicit VpnConnection(const QString &path, QObject *parent = nullptr);
0071     /**
0072      * Destroys a VpnConnection object.
0073      */
0074     ~VpnConnection() override;
0075     /**
0076      * Return the current login banner
0077      */
0078     QString banner() const;
0079     /**
0080      * returns the current state
0081      */
0082     NetworkManager::VpnConnection::State state() const;
0083     /**
0084      * operator for casting an ActiveConnection into a VpnConnection. Returns 0 if this
0085      * object is not a VPN connection. Introduced to make it possible to create a VpnConnection
0086      * object for every active connection, without creating an ActiveConnection object, checking
0087      * if it's a VPN connection, deleting the ActiveConnection and creating a VpnConnection
0088      */
0089     operator VpnConnection *();
0090 
0091 Q_SIGNALS:
0092     /**
0093      * This signal is emitted when the connection @p banner has changed
0094      */
0095     void bannerChanged(const QString &banner);
0096     /**
0097      * This signal is emitted when the VPN connection @p state has changed
0098      */
0099     void stateChanged(NetworkManager::VpnConnection::State state, NetworkManager::VpnConnection::StateChangeReason reason);
0100 
0101 private:
0102     Q_DECLARE_PRIVATE(VpnConnection)
0103 };
0104 
0105 } // namespace NetworkManager
0106 #endif // NETWORKMANAGERQT_VPNCONNECTION_H