| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2008, 2009 Will Stephenson <[email protected]> |
| 3 | SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza <[email protected]> |
| 4 | SPDX-FileCopyrightText: 2013 Jan Grulich <[email protected]> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 7 | */ |
| 8 | |
| 9 | #ifndef NETWORKMANAGERQT_SETTINGS_CONNECTION_H |
| 10 | #define NETWORKMANAGERQT_SETTINGS_CONNECTION_H |
| 11 | |
| 12 | #include "connectionsettings.h" |
| 13 | #include "generictypes.h" |
| 14 | #include <networkmanagerqt/networkmanagerqt_export.h> |
| 15 | |
| 16 | #include <QDBusPendingReply> |
| 17 | #include <QObject> |
| 18 | #include <QSharedPointer> |
| 19 | |
| 20 | namespace NetworkManager |
| 21 | { |
| 22 | class ConnectionPrivate; |
| 23 | |
| 24 | /*! |
| 25 | * \class NetworkManager::Connection |
| 26 | * \inheaderfile NetworkManagerQt/Connection |
| 27 | * \inmodule NetworkManagerQt |
| 28 | * |
| 29 | * \brief This class represents a single network connection configuration. |
| 30 | */ |
| 31 | class NETWORKMANAGERQT_EXPORT Connection : public QObject |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | public: |
| 35 | /*! |
| 36 | * \typedef NetworkManager::Connection::Ptr |
| 37 | */ |
| 38 | typedef QSharedPointer<Connection> Ptr; |
| 39 | /*! |
| 40 | * \typedef NetworkManager::Connection::List |
| 41 | */ |
| 42 | typedef QList<Ptr> List; |
| 43 | |
| 44 | /*! |
| 45 | * Constructs a connection object for the given path |
| 46 | */ |
| 47 | explicit Connection(const QString &path, QObject *parent = nullptr); |
| 48 | ~Connection() override; |
| 49 | |
| 50 | /*! |
| 51 | * Returns if this connection is valid |
| 52 | */ |
| 53 | bool isValid() const; |
| 54 | |
| 55 | /*! |
| 56 | * Returns the unique identifier of this connection |
| 57 | */ |
| 58 | QString uuid() const; |
| 59 | |
| 60 | /*! |
| 61 | * Returns the path (DBus) of this connection |
| 62 | */ |
| 63 | QString path() const; |
| 64 | |
| 65 | /*! |
| 66 | * Returns the name of this connection |
| 67 | */ |
| 68 | QString name() const; |
| 69 | /*! |
| 70 | * If set, indicates that the in-memory state of the |
| 71 | * connection does not match the on-disk state. This flag |
| 72 | * will be set when updateUnsaved() is called or when any |
| 73 | * connection details change, and cleared when the connection |
| 74 | * is saved to disk via save() or from internal operations. |
| 75 | * |
| 76 | * \since 0.9.9.0 |
| 77 | */ |
| 78 | bool isUnsaved() const; |
| 79 | /*! |
| 80 | * Returns the settings of this connection |
| 81 | */ |
| 82 | ConnectionSettings::Ptr settings(); |
| 83 | |
| 84 | /*! |
| 85 | * Retrieves this connections's secrets (passwords and / or encryption keys). |
| 86 | * |
| 87 | * \a setting the setting identifier. |
| 88 | */ |
| 89 | QDBusPendingReply<NMVariantMapMap> secrets(const QString &setting); |
| 90 | |
| 91 | /*! |
| 92 | * Update the connection with new \a settings and properties, replacing all previous settings and properties. |
| 93 | * Secrets may be part of the update request, and will be either stored in persistent storage or given to a Secret Agent for storage, |
| 94 | * depending on the request. |
| 95 | */ |
| 96 | QDBusPendingReply<> update(const NMVariantMapMap &settings); |
| 97 | /*! |
| 98 | * Update the connection with new \a settings and properties (replacing |
| 99 | * all previous settings and properties) but do not immediately save |
| 100 | * the connection to disk. Secrets may be part of the update request |
| 101 | * and may sent to a Secret Agent for storage, depending on the |
| 102 | * flags associated with each secret. |
| 103 | * |
| 104 | * Use the save() method to save these changes to disk. Note |
| 105 | * that unsaved changes will be lost if the connection is |
| 106 | * reloaded from disk (either automatically on file change or |
| 107 | * due to an explicit reloadConnections() call). |
| 108 | * |
| 109 | * \since 0.9.9.0 |
| 110 | */ |
| 111 | QDBusPendingReply<> updateUnsaved(const NMVariantMapMap &settings); |
| 112 | |
| 113 | /*! |
| 114 | * Saves a "dirty" connection (that had previously been |
| 115 | * updated with updateUnsaved()) to persistent storage. |
| 116 | * |
| 117 | * \since 0.9.9.0 |
| 118 | */ |
| 119 | QDBusPendingReply<> save(); |
| 120 | |
| 121 | /*! |
| 122 | * Clear the secrets belonging to this network connection profile. |
| 123 | * \since 5.8.0 |
| 124 | */ |
| 125 | QDBusPendingReply<> clearSecrets(); |
| 126 | |
| 127 | /*! |
| 128 | * Removes the connection from NetworkManager database, |
| 129 | * this operation does not ask for confirmation but |
| 130 | * a policykit rule might prevent it from being removed |
| 131 | * without the proper password. |
| 132 | */ |
| 133 | QDBusPendingReply<> remove(); |
| 134 | |
| 135 | Q_SIGNALS: |
| 136 | /*! |
| 137 | * Emitted when the connection settings changes |
| 138 | */ |
| 139 | void updated(); |
| 140 | |
| 141 | /*! |
| 142 | * Emitted when the connection was removed |
| 143 | * |
| 144 | * \a path connections's path. |
| 145 | */ |
| 146 | void removed(const QString &path); |
| 147 | /*! |
| 148 | * Emitted when the connection unsaved state changes |
| 149 | */ |
| 150 | void unsavedChanged(bool unsaved); |
| 151 | |
| 152 | private: |
| 153 | Q_DECLARE_PRIVATE(Connection) |
| 154 | |
| 155 | ConnectionPrivate *const d_ptr; |
| 156 | }; |
| 157 | |
| 158 | } |
| 159 | #endif // CONNECTION_H |
| 160 | |