mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-04 04:52:09 +08:00
dont init wifi widget if there is no adapter
old-commit-hash: 3d2fec6c9ad7e682404ff1481d11df43c1c03bf4
This commit is contained in:
@@ -21,7 +21,12 @@ void clearLayout(QLayout* layout) {
|
||||
}
|
||||
|
||||
WifiUI::WifiUI(QWidget *parent, int page_length) : QWidget(parent), networks_per_page(page_length) {
|
||||
wifi = new WifiManager;
|
||||
try {
|
||||
wifi = new WifiManager;
|
||||
} catch (std::exception &e) {
|
||||
return;
|
||||
}
|
||||
|
||||
QObject::connect(wifi, SIGNAL(wrongPassword(QString)), this, SLOT(wrongPassword(QString)));
|
||||
|
||||
QVBoxLayout * top_layout = new QVBoxLayout;
|
||||
@@ -33,7 +38,7 @@ WifiUI::WifiUI(QWidget *parent, int page_length) : QWidget(parent), networks_per
|
||||
QVBoxLayout* networkLayout = new QVBoxLayout;
|
||||
QHBoxLayout *tethering_field = new QHBoxLayout;
|
||||
tethering_field->addWidget(new QLabel("Enable Tethering"));
|
||||
|
||||
|
||||
Toggle* toggle_switch = new Toggle(this);
|
||||
toggle_switch->setFixedSize(150, 100);
|
||||
tethering_field->addWidget(toggle_switch);
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
explicit WifiUI(QWidget *parent = 0, int page_length = 5);
|
||||
|
||||
private:
|
||||
WifiManager* wifi;
|
||||
WifiManager* wifi = nullptr;
|
||||
const int networks_per_page;
|
||||
|
||||
QStackedWidget *swidget;
|
||||
|
||||
@@ -61,17 +61,20 @@ WifiManager::WifiManager() {
|
||||
qDBusRegisterMetaType<IpConfig>();
|
||||
connecting_to_network = "";
|
||||
adapter = get_adapter();
|
||||
has_adapter = adapter != "";
|
||||
if (has_adapter) {
|
||||
QDBusInterface nm(nm_service, adapter, device_iface, bus);
|
||||
bus.connect(nm_service, adapter, device_iface, "StateChanged", this, SLOT(change(unsigned int, unsigned int, unsigned int)));
|
||||
|
||||
QDBusInterface device_props(nm_service, adapter, props_iface, bus);
|
||||
QDBusMessage response = device_props.call("Get", device_iface, "State");
|
||||
raw_adapter_state = get_response<uint>(response);
|
||||
change(raw_adapter_state, 0, 0);
|
||||
|
||||
bool has_adapter = adapter != "";
|
||||
if (!has_adapter){
|
||||
throw std::runtime_error("Error connecting to panda");
|
||||
}
|
||||
|
||||
QDBusInterface nm(nm_service, adapter, device_iface, bus);
|
||||
bus.connect(nm_service, adapter, device_iface, "StateChanged", this, SLOT(change(unsigned int, unsigned int, unsigned int)));
|
||||
|
||||
QDBusInterface device_props(nm_service, adapter, props_iface, bus);
|
||||
QDBusMessage response = device_props.call("Get", device_iface, "State");
|
||||
raw_adapter_state = get_response<uint>(response);
|
||||
change(raw_adapter_state, 0, 0);
|
||||
|
||||
// Compute tethering ssid as "Weedle" + first 4 characters of a dongle id
|
||||
tethering_ssid = "weedle";
|
||||
std::string bytes = Params().get("DongleId");
|
||||
@@ -81,8 +84,6 @@ WifiManager::WifiManager() {
|
||||
}
|
||||
|
||||
void WifiManager::refreshNetworks() {
|
||||
if (!has_adapter) return;
|
||||
|
||||
bus = QDBusConnection::systemBus();
|
||||
seen_networks.clear();
|
||||
seen_ssids.clear();
|
||||
@@ -142,7 +143,7 @@ SecurityType WifiManager::getSecurityType(QString path) {
|
||||
|
||||
// obtained by looking at flags of networks in the office as reported by an Android phone
|
||||
const int supports_wpa = NM_802_11_AP_SEC_PAIR_WEP40 | NM_802_11_AP_SEC_PAIR_WEP104 | NM_802_11_AP_SEC_GROUP_WEP40 | NM_802_11_AP_SEC_GROUP_WEP104 | NM_802_11_AP_SEC_KEY_MGMT_PSK;
|
||||
|
||||
|
||||
if (sflag == 0) {
|
||||
return SecurityType::OPEN;
|
||||
} else if ((sflag & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_props & supports_wpa) && !(wpa_props & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
|
||||
@@ -249,8 +250,6 @@ void WifiManager::clear_connections(QString ssid) {
|
||||
}
|
||||
|
||||
void WifiManager::request_scan() {
|
||||
if (!has_adapter) return;
|
||||
|
||||
QDBusInterface nm(nm_service, adapter, wireless_device_iface, bus);
|
||||
nm.call("RequestScan", QVariantMap());
|
||||
}
|
||||
@@ -326,7 +325,7 @@ void WifiManager::disconnect() {
|
||||
}
|
||||
}
|
||||
|
||||
//Functions for tethering
|
||||
//Functions for tethering
|
||||
|
||||
void WifiManager::enableTethering() {
|
||||
disconnect();
|
||||
|
||||
@@ -30,7 +30,6 @@ class WifiManager : public QWidget {
|
||||
public:
|
||||
explicit WifiManager();
|
||||
|
||||
bool has_adapter;
|
||||
void request_scan();
|
||||
QVector<Network> seen_networks;
|
||||
|
||||
@@ -39,7 +38,7 @@ public:
|
||||
void connect(Network ssid, QString password);
|
||||
void connect(Network ssid, QString username, QString password);
|
||||
// Tethering functions
|
||||
|
||||
|
||||
void enableTethering();
|
||||
void disableTethering();
|
||||
bool tetheringEnabled();
|
||||
|
||||
Reference in New Issue
Block a user