File indexing completed on 2024-03-24 15:41:33

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_SETTINGS_H
0010 #define NETWORKMANAGERQT_SETTINGS_H
0011 
0012 #include <networkmanagerqt/networkmanagerqt_export.h>
0013 
0014 #include "connection.h"
0015 #include "generictypes.h"
0016 #include "manager.h"
0017 #include <QObject>
0018 
0019 #include <QString>
0020 
0021 namespace NetworkManager
0022 {
0023 /**
0024  * This class manages provides access to connections and notify about new ones
0025  */
0026 class NETWORKMANAGERQT_EXPORT SettingsNotifier : public QObject
0027 {
0028     Q_OBJECT
0029 Q_SIGNALS:
0030     /**
0031      * Emitted when the settings are modifiable by user
0032      * @param canModify @p true if the user can modify the settings
0033      */
0034     void canModifyChanged(bool canModify);
0035     /**
0036      * Emitted when the hostname has changed
0037      * @param hostname new hostname
0038      */
0039     void hostnameChanged(const QString &hostname);
0040     /**
0041      * Emitted when a new connection is added
0042      *
0043      * \note This signal is not emitted when the Network Manager
0044      * daemon starts, if you are interested in keeping an
0045      * updated listing of connections you must also watch for
0046      * NetworkManager::Notifier::serviceAppeared() and
0047      * NetworkManager::Notifier::serviceDisappeared() signals
0048      */
0049     void connectionAdded(const QString &path);
0050     /**
0051      * Emitted when a new connection is removed
0052      *
0053      * \note This signal is not emitted when the Network Manager
0054      * daemon starts, if you are interested in keeping an
0055      * updated listing of connections you must also watch for
0056      * NetworkManager::Notifier::serviceAppeared() and
0057      * NetworkManager::Notifier::serviceDisappeared() signals
0058      */
0059     void connectionRemoved(const QString &path);
0060 };
0061 /**
0062  * Retrieves the list of connections.
0063  */
0064 NETWORKMANAGERQT_EXPORT NetworkManager::Connection::List listConnections();
0065 
0066 /**
0067  * Retrieves the connection for the given path, returns null if not found
0068  */
0069 NETWORKMANAGERQT_EXPORT NetworkManager::Connection::Ptr findConnection(const QString &path);
0070 
0071 /**
0072  * Add new connection and save it to disk. This operation does not start
0073  * the network connection unless (1) device is idle and able to connect to
0074  * the network described by the new connection, and (2) the connection
0075  * is allowed to be started automatically.
0076  * Once the connection has been added, you will get a notification through
0077  * SettingsNotifier::connectionAddComplete()
0078  *
0079  * @returns Uuid of the new connection that was just added.
0080  *
0081  * @since 0.9.9.0
0082  */
0083 NETWORKMANAGERQT_EXPORT QDBusPendingReply<QDBusObjectPath> addConnection(const NMVariantMapMap &settings);
0084 
0085 /**
0086  * Add new connection but do not save it to disk immediately.  This
0087  * operation does not start the network connection unless (1) device is
0088  * idle and able to connect to the network described by the new connection,
0089  * and (2) the connection is allowed to be started automatically.
0090  *
0091  * Use the 'Save' method on the connection to save these changes
0092  * to disk. Note that unsaved changes will be lost if the
0093  * connection is reloaded from disk (either automatically on file
0094  * change or due to an explicit ReloadConnections call).
0095  *
0096  * Once the connection has been added, you will get a notification through
0097  * SettingsNotifier::connectionAddComplete()
0098  *
0099  * @returns Uuid of the new connection that was just added.
0100  *
0101  * @since 0.9.9.0
0102  */
0103 NETWORKMANAGERQT_EXPORT QDBusPendingReply<QDBusObjectPath> addConnectionUnsaved(const NMVariantMapMap &settings);
0104 
0105 /**
0106  * Retrieves the connection for the given @p uuid, returns null if not found
0107  */
0108 NETWORKMANAGERQT_EXPORT NetworkManager::Connection::Ptr findConnectionByUuid(const QString &uuid);
0109 
0110 /**
0111  * Loads or reloads the indicated connections from disk. You
0112  * should call this after making changes directly to an on-disk
0113  * connection file to make sure that NetworkManager sees the
0114  * changes. (If "monitor-connection-files" in NetworkManager.conf
0115  * is "true", then this will have no real effect, but is
0116  * harmless.) As with AddConnection(), this operation does not
0117  * necessarily start the network connection.
0118  *
0119  * @returns  Success or failure of the operation as a whole. True if
0120  *           NetworkManager at least tried to load the indicated
0121  *           connections, even if it did not succeed. False if an error
0122  *           occurred before trying to load the connections (eg,
0123  *           permission denied).
0124  *
0125  * @returns  Paths of connection files that could not be loaded.
0126  *
0127  * @since 0.9.9.0
0128  */
0129 NETWORKMANAGERQT_EXPORT QDBusPendingReply<bool, QStringList> loadConnections(const QStringList &filenames);
0130 
0131 /**
0132  * Tells NetworkManager to reload all connection files from disk,
0133  * including noticing any added or deleted connection files. By
0134  * default, connections are re-read automatically any time they
0135  * change, so you only need to use this command if you have set
0136  * "monitor-connection-files=false" in NetworkManager.conf.
0137  *
0138  * @returns Success or failure.
0139  *
0140  * @since 0.9.9.0
0141  */
0142 NETWORKMANAGERQT_EXPORT QDBusPendingReply<bool> reloadConnections();
0143 
0144 /**
0145  * Configure the following hostname
0146  */
0147 NETWORKMANAGERQT_EXPORT void saveHostname(const QString &hostname);
0148 
0149 /**
0150  * Returns @p true if the user can modify the settings
0151  */
0152 NETWORKMANAGERQT_EXPORT bool canModify();
0153 
0154 /**
0155  * Returns hostname of the machine
0156  */
0157 NETWORKMANAGERQT_EXPORT QString hostname();
0158 
0159 /**
0160  * Notifier object for connecting signals
0161  */
0162 NETWORKMANAGERQT_EXPORT SettingsNotifier *settingsNotifier();
0163 }
0164 
0165 #endif