File indexing completed on 2024-12-08 05:00:47
0001 /* 0002 SPDX-FileCopyrightText: 2013-2014 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 PLASMA_NM_HANDLER_H 0008 #define PLASMA_NM_HANDLER_H 0009 0010 #include "plasmanm_internal_export.h" 0011 0012 #include <QDBusInterface> 0013 #include <QDBusPendingCallWatcher> 0014 #include <QPointer> 0015 #include <QTimer> 0016 0017 #include <qqmlregistration.h> 0018 0019 #include <ModemManagerQt/GenericTypes> 0020 #include <NetworkManagerQt/Connection> 0021 #include <NetworkManagerQt/ConnectionSettings> 0022 #include <NetworkManagerQt/Settings> 0023 #include <NetworkManagerQt/Utils> 0024 0025 #include <QCoroCore> 0026 0027 class PLASMANM_INTERNAL_EXPORT Handler : public QObject 0028 { 0029 Q_OBJECT 0030 QML_ELEMENT 0031 0032 public: 0033 explicit Handler(QObject *parent = nullptr); 0034 ~Handler() override; 0035 0036 Q_PROPERTY(bool hotspotSupported READ hotspotSupported NOTIFY hotspotSupportedChanged) 0037 0038 // Not scientifically correct, but a good estimation of whether a scanning is currently in progress. 0039 Q_PROPERTY(bool scanning READ isScanning NOTIFY scanningChanged) 0040 0041 public: 0042 bool hotspotSupported() const 0043 { 0044 return m_hotspotSupported; 0045 } 0046 0047 bool isScanning() const 0048 { 0049 return m_ongoingScansCount != 0; 0050 } 0051 0052 void addConnection(NMConnection *connection); 0053 0054 public Q_SLOTS: 0055 /** 0056 * Activates given connection 0057 * @connection - d-bus path of the connection you want to activate 0058 * @device - d-bus path of the device where the connection should be activated 0059 * @specificParameter - d-bus path of the specific object you want to use for this activation, i.e access point 0060 */ 0061 void activateConnection(const QString &connection, const QString &device, const QString &specificParameter); 0062 /** 0063 * Adds and activates a new wireless connection 0064 * @device - d-bus path of the wireless device where the connection should be activated 0065 * @specificParameter - d-bus path of the accesspoint you want to connect to 0066 * @password - pre-filled password which should be used for the new wireless connection 0067 * @autoConnect - boolean value whether this connection should be activated automatically when it's available 0068 * 0069 * Works automatically for wireless connections with WEP/WPA security, for wireless connections with WPA/WPA 0070 * it will open the connection editor for advanced configuration. 0071 * */ 0072 void addAndActivateConnection(const QString &device, const QString &specificParameter, const QString &password = QString()); 0073 0074 /** 0075 * Request a code that includes the credentials to a said wifi connection 0076 * Here's some information on how this information is created, it's generally used to put in QR codes to share. 0077 * https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11 0078 * 0079 * @param connectionPath the d-bus path to the connection we want to read 0080 * @param ssid the name of the network being displayed 0081 * @param securityType the authentication protocol used for this specific ssid 0082 * @param connectionName the name of the connection 0083 * @see wifiCodeReceived 0084 */ 0085 void requestWifiCode(const QString &connectionPath, 0086 const QString &ssid, 0087 /*NetworkManager::WirelessSecurityType*/ int securityType); 0088 0089 /** 0090 * Adds a new connection 0091 * @map - NMVariantMapMap with connection settings 0092 */ 0093 QCoro::Task<void> addConnection(const NMVariantMapMap &map); 0094 0095 /** 0096 * Deactivates given connection 0097 * @connection - d-bus path of the connection you want to deactivate 0098 * @device - d-bus path of the connection where the connection is activated 0099 */ 0100 void deactivateConnection(const QString &connection, const QString &device); 0101 /** 0102 * Disconnects all connections 0103 */ 0104 void disconnectAll(); 0105 void enableAirplaneMode(bool enable); 0106 void enableNetworking(bool enable); 0107 void enableWireless(bool enable); 0108 0109 void enableWwan(bool enable); 0110 0111 /** 0112 * Removes given connection 0113 * @connection - d-bus path of the connection you want to edit 0114 */ 0115 void removeConnection(const QString &connection); 0116 /** 0117 * Updates given connection 0118 * @connection - connection which should be updated 0119 * @map - NMVariantMapMap with new connection settings 0120 */ 0121 QCoro::Task<void> updateConnection(NetworkManager::Connection::Ptr connection, const NMVariantMapMap &map); 0122 void requestScan(const QString &interface = QString()); 0123 0124 void createHotspot(); 0125 void stopHotspot(); 0126 0127 private Q_SLOTS: 0128 void secretAgentError(const QString &connectionPath, const QString &message); 0129 void primaryConnectionTypeChanged(NetworkManager::ConnectionSettings::ConnectionType type); 0130 void unlockRequiredChanged(MMModemLock modemLock); 0131 void slotRequestWifiCode(QDBusPendingCallWatcher *watcher); 0132 0133 Q_SIGNALS: 0134 void connectionActivationFailed(const QString &connectionPath, const QString &message); 0135 void hotspotCreated(); 0136 void hotspotDisabled(); 0137 void hotspotSupportedChanged(bool hotspotSupported); 0138 void scanningChanged(); 0139 void wifiCodeReceived(const QString &data, const QString &ssid); 0140 0141 private: 0142 QCoro::Task<void> addAndActivateConnectionDBus(const NMVariantMapMap &map, const QString &device, const QString &specificObject); 0143 QCoro::Task<void> activateConnectionInternal(const QString &connection, const QString &device, const QString &specificParameter); 0144 QCoro::Task<void> addAndActivateConnectionInternal(const QString &device, const QString &specificParameter, const QString &password = QString()); 0145 QCoro::Task<void> deactivateConnectionInternal(const QString &connection, const QString &device); 0146 QCoro::Task<void> removeConnectionInternal(const QString &connection); 0147 QCoro::Task<void> requestScanInternal(const QString &interface = QString()); 0148 QCoro::Task<void> createHotspotInternal(); 0149 0150 bool m_hotspotSupported; 0151 bool m_tmpWirelessEnabled; 0152 bool m_tmpWwanEnabled; 0153 QString m_tmpConnectionPath; 0154 QString m_tmpConnectionUuid; 0155 QString m_tmpDevicePath; 0156 QString m_tmpSpecificPath; 0157 QMap<QString, bool> m_bluetoothAdapters; 0158 QMap<QString, QTimer *> m_wirelessScanRetryTimer; 0159 short m_ongoingScansCount = 0; 0160 0161 QCoro::Task<void> enableBluetooth(bool enable); 0162 void scanRequestFailed(const QString &interface); 0163 bool checkRequestScanRateLimit(const NetworkManager::WirelessDevice::Ptr &wifiDevice); 0164 bool checkHotspotSupported(); 0165 void scheduleRequestScan(const QString &interface, int timeout); 0166 void incrementScansCount(); 0167 void decrementScansCount(); 0168 0169 QPointer<QDBusPendingCallWatcher> m_requestWifiCodeWatcher; 0170 }; 0171 0172 #endif // PLASMA_NM_HANDLER_H