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

0001 /*
0002     SPDX-FileCopyrightText: 2008, 2009 Will Stephenson <wstephenson@kde.org>
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_SETTINGS_CONNECTION_H
0010 #define NETWORKMANAGERQT_SETTINGS_CONNECTION_H
0011 
0012 #include "connectionsettings.h"
0013 #include "generictypes.h"
0014 #include <networkmanagerqt/networkmanagerqt_export.h>
0015 
0016 #include <QDBusPendingReply>
0017 #include <QObject>
0018 #include <QSharedPointer>
0019 
0020 class QDBusPendingCallWatcher;
0021 
0022 namespace NetworkManager
0023 {
0024 class ConnectionPrivate;
0025 
0026 /**
0027  * This class represents a single network connection configuration.
0028  */
0029 class NETWORKMANAGERQT_EXPORT Connection : public QObject
0030 {
0031     Q_OBJECT
0032 public:
0033     typedef QSharedPointer<Connection> Ptr;
0034     typedef QList<Ptr> List;
0035 
0036     /**
0037      * Constructs a connection object for the given path
0038      */
0039     explicit Connection(const QString &path, QObject *parent = nullptr);
0040     ~Connection() override;
0041 
0042     /**
0043      * Returns if this connection is valid
0044      */
0045     bool isValid() const;
0046 
0047     /**
0048      * Returns the unique identifier of this connection
0049      */
0050     QString uuid() const;
0051 
0052     /**
0053      * Returns the path (DBus) of this connection
0054      */
0055     QString path() const;
0056 
0057     /**
0058      * Returns the name of this connection
0059      */
0060     QString name() const;
0061     /**
0062      * If set, indicates that the in-memory state of the
0063      * connection does not match the on-disk state. This flag
0064      * will be set when updateUnsaved() is called or when any
0065      * connection details change, and cleared when the connection
0066      * is saved to disk via save() or from internal operations.
0067      *
0068      * @since 0.9.9.0
0069      */
0070     bool isUnsaved() const;
0071     /**
0072      * Returns the settings of this connection
0073      */
0074     ConnectionSettings::Ptr settings();
0075 
0076     /**
0077      * Retrieves this connections's secrets (passwords and / or encryption keys).
0078      *
0079      * @param setting the setting identifier.
0080      */
0081     QDBusPendingReply<NMVariantMapMap> secrets(const QString &setting);
0082 
0083     /**
0084      * Update the connection with new @p settings and properties, replacing all previous settings and properties.
0085      * Secrets may be part of the update request, and will be either stored in persistent storage or given to a Secret Agent for storage,
0086      * depending on the request.
0087      */
0088     QDBusPendingReply<> update(const NMVariantMapMap &settings);
0089     /**
0090      * Update the connection with new @p settings and properties (replacing
0091      * all previous settings and properties) but do not immediately save
0092      * the connection to disk. Secrets may be part of the update request
0093      * and may sent to a Secret Agent for storage, depending on the
0094      * flags associated with each secret.
0095      *
0096      * Use the save() method to save these changes to disk. Note
0097      * that unsaved changes will be lost if the connection is
0098      * reloaded from disk (either automatically on file change or
0099      * due to an explicit reloadConnections() call).
0100      *
0101      * @since 0.9.9.0
0102      */
0103     QDBusPendingReply<> updateUnsaved(const NMVariantMapMap &settings);
0104 
0105     /**
0106      * Saves a "dirty" connection (that had previously been
0107      * updated with updateUnsaved()) to persistent storage.
0108      *
0109      * @since 0.9.9.0
0110      */
0111     QDBusPendingReply<> save();
0112 
0113     /**
0114      * Clear the secrets belonging to this network connection profile.
0115      * @since 5.8.0
0116      */
0117     QDBusPendingReply<> clearSecrets();
0118 
0119     /**
0120      * Removes the connection from NetworkManager database,
0121      * this operation does not ask for confirmation but
0122      * a policykit rule might prevent it from being removed
0123      * without the proper password.
0124      */
0125     QDBusPendingReply<> remove();
0126 
0127 Q_SIGNALS:
0128     /**
0129      * Emitted when the connection settings changes
0130      */
0131     void updated();
0132 
0133     /**
0134      * Emitted when the connection was removed
0135      * @param path connections's path.
0136      */
0137     void removed(const QString &path);
0138     /**
0139      * Emitted when the connection unsaved state changes
0140      */
0141     void unsavedChanged(bool unsaved);
0142 
0143 private:
0144     Q_DECLARE_PRIVATE(Connection)
0145 
0146     ConnectionPrivate *const d_ptr;
0147 };
0148 
0149 }
0150 #endif // CONNECTION_H