File indexing completed on 2024-05-12 05:36:30

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