File indexing completed on 2024-04-21 04:00:06

0001 /*
0002     SPDX-FileCopyrightText: 2012-2019 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #ifndef NETWORKMANAGERQT_SETTING_H
0008 #define NETWORKMANAGERQT_SETTING_H
0009 
0010 #include <networkmanagerqt/networkmanagerqt_export.h>
0011 
0012 #include "generictypes.h"
0013 
0014 #undef signals
0015 #include <libnm/NetworkManager.h>
0016 #define signals Q_SIGNALS
0017 
0018 #include <QSharedPointer>
0019 #include <QStringList>
0020 #include <QVariantMap>
0021 
0022 namespace NetworkManager
0023 {
0024 class SettingPrivate;
0025 
0026 /**
0027  * Base class for all kinds of setting
0028  */
0029 class NETWORKMANAGERQT_EXPORT Setting
0030 {
0031 public:
0032     typedef QSharedPointer<Setting> Ptr;
0033     typedef QList<Ptr> List;
0034     enum SettingType {
0035         Adsl,
0036         Cdma,
0037         Gsm,
0038         Infiniband,
0039         Ipv4,
0040         Ipv6,
0041         Ppp,
0042         Pppoe,
0043         Security8021x,
0044         Serial,
0045         Vpn,
0046         Wired,
0047         Wireless,
0048         WirelessSecurity,
0049         Bluetooth,
0050         OlpcMesh,
0051         Vlan,
0052         Wimax,
0053         Bond,
0054         Bridge,
0055         BridgePort,
0056         Team,
0057         Generic,
0058         Tun,
0059         Vxlan,
0060         IpTunnel,
0061         Proxy,
0062         User,
0063         OvsBridge,
0064         OvsInterface,
0065         OvsPatch,
0066         OvsPort,
0067         Match,
0068         Tc,
0069         TeamPort,
0070         Macsec,
0071         Dcb,
0072         WireGuard,
0073     };
0074 
0075     enum SecretFlagType {
0076         None = 0,
0077         AgentOwned = 0x01,
0078         NotSaved = 0x02,
0079         NotRequired = 0x04,
0080     };
0081     Q_DECLARE_FLAGS(SecretFlags, SecretFlagType)
0082 
0083     enum MacAddressRandomization {
0084         MacAddressRandomizationDefault = 0,
0085         MacAddressRandomizationNever,
0086         MacAddressRandomizationAlways,
0087     };
0088 
0089     static QString typeAsString(SettingType type);
0090     static SettingType typeFromString(const QString &type);
0091 
0092     explicit Setting(SettingType type);
0093     explicit Setting(const Ptr &setting);
0094     virtual ~Setting();
0095 
0096     /**
0097      * @brief Must be reimplemented, default implementation does nothing
0098      */
0099     virtual void fromMap(const QVariantMap &map);
0100 
0101     /**
0102      * @brief Must be reimplemented, default implementationd does nothing
0103      */
0104     virtual QVariantMap toMap() const;
0105 
0106     virtual void secretsFromMap(const QVariantMap &map);
0107 
0108     /**
0109      * @brief secretsFromStringMap is a convenience function
0110      * to set the secrets from a map of strings.
0111      * @param map to extract secrets from
0112      */
0113     virtual void secretsFromStringMap(const NMStringMap &map);
0114 
0115     virtual QVariantMap secretsToMap() const;
0116 
0117     /**
0118      * @brief secretsToStringMap is a convenience function
0119      * to get the secrets to map of strings.
0120      * @return string map with current secrets
0121      */
0122     virtual NMStringMap secretsToStringMap() const;
0123 
0124     virtual QStringList needSecrets(bool requestNew = false) const;
0125 
0126     /**
0127      * @brief Must be reimplemented, default implementationd does nothing
0128      */
0129     virtual QString name() const;
0130 
0131     void setInitialized(bool initialized);
0132 
0133     bool isNull() const;
0134 
0135     void setType(SettingType type);
0136     SettingType type() const;
0137 
0138 protected:
0139     SettingPrivate *d_ptr;
0140 
0141 private:
0142     Q_DECLARE_PRIVATE(Setting)
0143 };
0144 Q_DECLARE_OPERATORS_FOR_FLAGS(Setting::SecretFlags)
0145 
0146 NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const Setting &setting);
0147 
0148 }
0149 
0150 #endif // NETWORKMANAGERQT_SETTING_H