ui/WifiManager: inherit from QObject instead of QWidget (#23523)
parent
785180d234
commit
75be1223f8
|
@ -99,14 +99,12 @@ void Networking::wrongPassword(const QString &ssid) {
|
|||
}
|
||||
}
|
||||
|
||||
void Networking::showEvent(QShowEvent* event) {
|
||||
// Wait to refresh to avoid delay when showing Networking widget
|
||||
QTimer::singleShot(300, this, [=]() {
|
||||
if (this->isVisible()) {
|
||||
wifi->refreshNetworks();
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
void Networking::showEvent(QShowEvent *event) {
|
||||
wifi->start();
|
||||
}
|
||||
|
||||
void Networking::hideEvent(QHideEvent *event) {
|
||||
wifi->stop();
|
||||
}
|
||||
|
||||
// AdvancedNetworking functions
|
||||
|
|
|
@ -65,6 +65,7 @@ private:
|
|||
|
||||
protected:
|
||||
void showEvent(QShowEvent* event) override;
|
||||
void hideEvent(QHideEvent* event) override;
|
||||
|
||||
public slots:
|
||||
void refresh();
|
||||
|
|
|
@ -29,7 +29,7 @@ bool compare_by_strength(const Network &a, const Network &b) {
|
|||
return a.strength > b.strength;
|
||||
}
|
||||
|
||||
WifiManager::WifiManager(QWidget* parent) : QWidget(parent) {
|
||||
WifiManager::WifiManager(QObject *parent) : QObject(parent) {
|
||||
qDBusRegisterMetaType<Connection>();
|
||||
qDBusRegisterMetaType<IpConfig>();
|
||||
connecting_to_network = "";
|
||||
|
@ -47,13 +47,7 @@ WifiManager::WifiManager(QWidget* parent) : QWidget(parent) {
|
|||
bus.connect(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "DeviceAdded", this, SLOT(deviceAdded(QDBusObjectPath)));
|
||||
}
|
||||
|
||||
QTimer* timer = new QTimer(this);
|
||||
QObject::connect(timer, &QTimer::timeout, this, [=]() {
|
||||
if (!adapter.isEmpty() && this->isVisible()) {
|
||||
requestScan();
|
||||
}
|
||||
});
|
||||
timer->start(5000);
|
||||
timer.callOnTimeout(this, &WifiManager::requestScan);
|
||||
}
|
||||
|
||||
void WifiManager::setup() {
|
||||
|
@ -74,10 +68,18 @@ void WifiManager::setup() {
|
|||
requestScan();
|
||||
}
|
||||
|
||||
void WifiManager::start() {
|
||||
timer.start(5000);
|
||||
refreshNetworks();
|
||||
}
|
||||
|
||||
void WifiManager::stop() {
|
||||
timer.stop();
|
||||
}
|
||||
|
||||
void WifiManager::refreshNetworks() {
|
||||
if (adapter.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (adapter.isEmpty() || !timer.isActive()) return;
|
||||
|
||||
seenNetworks.clear();
|
||||
ipv4_address = get_ipv4_address();
|
||||
|
||||
|
@ -107,6 +109,7 @@ void WifiManager::refreshNetworks() {
|
|||
Network network = {ssid, strength, ctype, security};
|
||||
seenNetworks[ssid] = network;
|
||||
}
|
||||
emit refreshSignal();
|
||||
}
|
||||
|
||||
QString WifiManager::get_ipv4_address() {
|
||||
|
@ -315,21 +318,14 @@ void WifiManager::stateChange(unsigned int new_state, unsigned int previous_stat
|
|||
emit wrongPassword(connecting_to_network);
|
||||
} else if (new_state == NM_DEVICE_STATE_ACTIVATED) {
|
||||
connecting_to_network = "";
|
||||
if (this->isVisible()) {
|
||||
refreshNetworks();
|
||||
emit refreshSignal();
|
||||
}
|
||||
refreshNetworks();
|
||||
}
|
||||
}
|
||||
|
||||
// https://developer.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.Device.Wireless.html
|
||||
void WifiManager::propertyChange(const QString &interface, const QVariantMap &props, const QStringList &invalidated_props) {
|
||||
if (interface == NM_DBUS_INTERFACE_DEVICE_WIRELESS && props.contains("LastScan")) {
|
||||
if (this->isVisible() || firstScan) {
|
||||
refreshNetworks();
|
||||
emit refreshSignal();
|
||||
firstScan = false;
|
||||
}
|
||||
refreshNetworks();
|
||||
} else if (interface == NM_DBUS_INTERFACE_DEVICE_WIRELESS && props.contains("ActiveAccessPoint")) {
|
||||
const QDBusObjectPath &path = props.value("ActiveAccessPoint").value<QDBusObjectPath>();
|
||||
activeAp = path.path();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <QtDBus>
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
|
||||
#include "selfdrive/ui/qt/offroad/networkmanager.h"
|
||||
|
||||
|
@ -33,12 +33,13 @@ struct Network {
|
|||
};
|
||||
bool compare_by_strength(const Network &a, const Network &b);
|
||||
|
||||
class WifiManager : public QWidget {
|
||||
class WifiManager : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WifiManager(QWidget* parent);
|
||||
|
||||
explicit WifiManager(QObject* parent);
|
||||
void start();
|
||||
void stop();
|
||||
void requestScan();
|
||||
QMap<QString, Network> seenNetworks;
|
||||
QMap<QDBusObjectPath, QString> knownConnections;
|
||||
|
@ -67,13 +68,13 @@ public:
|
|||
|
||||
private:
|
||||
QString adapter; // Path to network manager wifi-device
|
||||
QTimer timer;
|
||||
QDBusConnection bus = QDBusConnection::systemBus();
|
||||
unsigned int raw_adapter_state; // Connection status https://developer.gnome.org/NetworkManager/1.26/nm-dbus-types.html#NMDeviceState
|
||||
QString connecting_to_network;
|
||||
QString tethering_ssid;
|
||||
const QString defaultTetheringPassword = "swagswagcomma";
|
||||
|
||||
bool firstScan = true;
|
||||
QString getAdapter(const uint = NM_DEVICE_TYPE_WIFI);
|
||||
uint getAdapterType(const QDBusObjectPath &path);
|
||||
bool isWirelessAdapter(const QDBusObjectPath &path);
|
||||
|
|
Loading…
Reference in New Issue