File indexing completed on 2023-11-26 08:54:34

0001 /*
0002     SPDX-FileCopyrightText: 2008-2010 Sebastian K├╝gler <sebas@kde.org>
0003     SPDX-FileCopyrightText: 2013-2014 Jan Grulich <jgrulich@redhat.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #ifndef PLASMA_NM_UIUTILS_H
0009 #define PLASMA_NM_UIUTILS_H
0010 
0011 #include <NetworkManagerQt/AccessPoint>
0012 #include <NetworkManagerQt/BluetoothDevice>
0013 #include <NetworkManagerQt/Device>
0014 #include <NetworkManagerQt/ModemDevice>
0015 #include <NetworkManagerQt/Utils>
0016 #include <NetworkManagerQt/VpnConnection>
0017 #include <NetworkManagerQt/VpnSetting>
0018 #include <NetworkManagerQt/WiredDevice>
0019 #include <NetworkManagerQt/WirelessDevice>
0020 #include <NetworkManagerQt/WirelessSetting>
0021 
0022 #include <ModemManager/ModemManager.h>
0023 #include <ModemManagerQt/Modem>
0024 
0025 class Q_DECL_EXPORT UiUtils
0026 {
0027 public:
0028     enum SortedConnectionType {
0029         Wired,
0030         Wireless,
0031         Gsm,
0032         Cdma,
0033         Pppoe,
0034         Adsl,
0035         Infiniband,
0036         OLPCMesh,
0037         Bluetooth,
0038         Wireguard,
0039         Vpn,
0040         Vlan,
0041         Bridge,
0042         Bond,
0043         Team,
0044         Unknown,
0045     };
0046 
0047     /*
0048      * @return sorted connection type used to prioritize specific connection types
0049      */
0050     static SortedConnectionType connectionTypeToSortedType(NetworkManager::ConnectionSettings::ConnectionType type);
0051 
0052     /*
0053      * @return whether given connection type is supported
0054      * Currently ignored connection types: Bond, Bridge, Generic, Infiniband, Team, Vlan, Tun
0055      */
0056     static bool isConnectionTypeSupported(NetworkManager::ConnectionSettings::ConnectionType type);
0057 
0058     /**
0059      * @return true if the connection is virtual.
0060      * @param type Type of the network connection
0061      */
0062     static bool isConnectionTypeVirtual(NetworkManager::ConnectionSettings::ConnectionType type);
0063 
0064     /**
0065      * @return a human-readable description for the network interface type for use as label
0066      * @param type the type of the network interface
0067      */
0068     static QString interfaceTypeLabel(const NetworkManager::Device::Type type, const NetworkManager::Device::Ptr iface);
0069 
0070     /**
0071      * @return a human-readable name for a given network interface according to the configured
0072      * naming style
0073      * @param type type of the network interface
0074      * @param interfaceName name of the network interface (eg eth0)
0075      */
0076     static QString prettyInterfaceName(NetworkManager::Device::Type type, const QString &interfaceName);
0077 
0078     /**
0079      * @return a human-readable description of the connection state of a given network interface
0080      * @param state The connection state
0081      */
0082     static QString connectionStateToString(NetworkManager::Device::State state, const QString &connectionName = QString());
0083 
0084     static QString vpnConnectionStateToString(NetworkManager::VpnConnection::State state);
0085 
0086     static QString iconAndTitleForConnectionSettingsType(NetworkManager::ConnectionSettings::ConnectionType type, QString &title);
0087     /**
0088      * @return a human-readable description of operation mode.
0089      * @param mode the operation mode
0090      */
0091     static QString operationModeToString(NetworkManager::WirelessDevice::OperationMode mode);
0092 
0093     /**
0094      * @return string list with a human-readable description of wpa flags.
0095      * @param flags the wpa flags
0096      */
0097     static QStringList wpaFlagsToStringList(NetworkManager::AccessPoint::WpaFlags flags);
0098 
0099     /**
0100      * @return localized string showing a human-readable connection speed. 1000 is used as base.
0101      * @param bitrate bitrate of the connection per second
0102      */
0103     static QString connectionSpeed(double bitrate);
0104 
0105     /**
0106      * @param band The band of a wireless network. The value corresponds to the type enum in Knm::WirelessSetting::EnumBand
0107      * @return A string representation
0108      */
0109     static QString wirelessBandToString(NetworkManager::WirelessSetting::FrequencyBand band);
0110 
0111     /**
0112      * @param frequency The frequency of a wireless network access point in MHz
0113      * @return A string representation
0114      */
0115     static QString wirelessFrequencyToString(uint frequency);
0116 
0117     /**
0118      * Check whether we're running in a live image session.
0119      */
0120     static bool isLiveImage();
0121 
0122     /**
0123      * Setup default permissions for a new connection.
0124      *
0125      * This determines whether we should use system connections or user
0126      * connections by default and sets the default permissions accordingly.
0127      * System connections are preferred if either the preference for that is
0128      * set, KWallet is not enabled or we're running in a live image. However, if
0129      * we do not have permissions to create system connections, we fall back to
0130      * user connections.
0131      *
0132      * @param settings The connection settings to setup.
0133      * @param liveSession Whether we are running a session from a live disk image.
0134      */
0135     static void setConnectionDefaultPermissions(NetworkManager::ConnectionSettings::Ptr &settings);
0136 
0137     static QString convertAllowedModeToString(ModemManager::Modem::ModemModes mode);
0138     static QString convertAccessTechnologyToString(ModemManager::Modem::AccessTechnologies tech);
0139     static QString convertLockReasonToString(MMModemLock reason);
0140     static NetworkManager::ModemDevice::Capability modemSubType(NetworkManager::ModemDevice::Capabilities modemCaps);
0141     static QString labelFromWirelessSecurity(NetworkManager::WirelessSecurityType type);
0142 
0143     static QString formatDateRelative(const QDateTime &lastUsed);
0144     static QString formatLastUsedDateRelative(const QDateTime &lastUsed);
0145 };
0146 #endif // UIUTILS_H