File indexing completed on 2024-04-14 03:57:41

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