-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathhandler.h
172 lines (144 loc) · 6.56 KB
/
handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
SPDX-FileCopyrightText: 2013-2014 Jan Grulich <[email protected]>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#ifndef PLASMA_NM_HANDLER_H
#define PLASMA_NM_HANDLER_H
#include "plasmanm_internal_export.h"
#include <QDBusInterface>
#include <QDBusPendingCallWatcher>
#include <QPointer>
#include <QTimer>
#include <qqmlregistration.h>
#include <ModemManagerQt/GenericTypes>
#include <NetworkManagerQt/Connection>
#include <NetworkManagerQt/ConnectionSettings>
#include <NetworkManagerQt/Settings>
#include <NetworkManagerQt/Utils>
#include <QCoroCore>
class PLASMANM_INTERNAL_EXPORT Handler : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
explicit Handler(QObject *parent = nullptr);
~Handler() override;
Q_PROPERTY(bool hotspotSupported READ hotspotSupported NOTIFY hotspotSupportedChanged)
// Not scientifically correct, but a good estimation of whether a scanning is currently in progress.
Q_PROPERTY(bool scanning READ isScanning NOTIFY scanningChanged)
public:
bool hotspotSupported() const
{
return m_hotspotSupported;
}
bool isScanning() const
{
return m_ongoingScansCount != 0;
}
void addConnection(NMConnection *connection);
public Q_SLOTS:
/**
* Activates given connection
* @connection - d-bus path of the connection you want to activate
* @device - d-bus path of the device where the connection should be activated
* @specificParameter - d-bus path of the specific object you want to use for this activation, i.e access point
*/
void activateConnection(const QString &connection, const QString &device, const QString &specificParameter);
/**
* Adds and activates a new wireless connection
* @device - d-bus path of the wireless device where the connection should be activated
* @specificParameter - d-bus path of the accesspoint you want to connect to
* @password - pre-filled password which should be used for the new wireless connection
* @autoConnect - boolean value whether this connection should be activated automatically when it's available
*
* Works automatically for wireless connections with WEP/WPA security, for wireless connections with WPA/WPA
* it will open the connection editor for advanced configuration.
* */
void addAndActivateConnection(const QString &device, const QString &specificParameter, const QString &password = QString());
/**
* Request a code that includes the credentials to a said wifi connection
* Here's some information on how this information is created, it's generally used to put in QR codes to share.
* https://github.com/zxing/zxing/wiki/Barcode-Contents#wi-fi-network-config-android-ios-11
*
* @param connectionPath the d-bus path to the connection we want to read
* @param ssid the name of the network being displayed
* @param securityType the authentication protocol used for this specific ssid
* @param connectionName the name of the connection
* @see wifiCodeReceived
*/
void requestWifiCode(const QString &connectionPath,
const QString &ssid,
/*NetworkManager::WirelessSecurityType*/ int securityType);
/**
* Adds a new connection
* @map - NMVariantMapMap with connection settings
*/
QCoro::Task<void> addConnection(const NMVariantMapMap &map);
/**
* Deactivates given connection
* @connection - d-bus path of the connection you want to deactivate
* @device - d-bus path of the connection where the connection is activated
*/
void deactivateConnection(const QString &connection, const QString &device);
/**
* Disconnects all connections
*/
void disconnectAll();
void enableAirplaneMode(bool enable);
void enableNetworking(bool enable);
void enableWireless(bool enable);
void enableWwan(bool enable);
/**
* Removes given connection
* @connection - d-bus path of the connection you want to edit
*/
void removeConnection(const QString &connection);
/**
* Updates given connection
* @connection - connection which should be updated
* @map - NMVariantMapMap with new connection settings
*/
QCoro::Task<void> updateConnection(NetworkManager::Connection::Ptr connection, const NMVariantMapMap &map);
void requestScan(const QString &interface = QString());
void createHotspot();
void stopHotspot();
private Q_SLOTS:
void secretAgentError(const QString &connectionPath, const QString &message);
void primaryConnectionTypeChanged(NetworkManager::ConnectionSettings::ConnectionType type);
void unlockRequiredChanged(MMModemLock modemLock);
void slotRequestWifiCode(QDBusPendingCallWatcher *watcher);
Q_SIGNALS:
void connectionActivationFailed(const QString &connectionPath, const QString &message);
void hotspotCreated();
void hotspotDisabled();
void hotspotSupportedChanged(bool hotspotSupported);
void scanningChanged();
void wifiCodeReceived(const QString &data, const QString &ssid);
private:
QCoro::Task<void> addAndActivateConnectionDBus(const NMVariantMapMap &map, const QString &device, const QString &specificObject);
QCoro::Task<void> activateConnectionInternal(const QString &connection, const QString &device, const QString &specificParameter);
QCoro::Task<void> addAndActivateConnectionInternal(const QString &device, const QString &specificParameter, const QString &password = QString());
QCoro::Task<void> deactivateConnectionInternal(const QString &connection, const QString &device);
QCoro::Task<void> removeConnectionInternal(const QString &connection);
QCoro::Task<void> requestScanInternal(const QString &interface = QString());
QCoro::Task<void> createHotspotInternal();
bool m_hotspotSupported;
bool m_tmpWirelessEnabled;
bool m_tmpWwanEnabled;
QString m_tmpConnectionPath;
QString m_tmpConnectionUuid;
QString m_tmpDevicePath;
QString m_tmpSpecificPath;
QMap<QString, bool> m_bluetoothAdapters;
QMap<QString, QTimer *> m_wirelessScanRetryTimer;
short m_ongoingScansCount = 0;
QCoro::Task<void> enableBluetooth(bool enable);
void scanRequestFailed(const QString &interface);
bool checkRequestScanRateLimit(const NetworkManager::WirelessDevice::Ptr &wifiDevice);
bool checkHotspotSupported();
void scheduleRequestScan(const QString &interface, int timeout);
void incrementScansCount();
void decrementScansCount();
QPointer<QDBusPendingCallWatcher> m_requestWifiCodeWatcher;
};
#endif // PLASMA_NM_HANDLER_H