From ddf74e12b46138c98e8ce579805e984bd090d2aa Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Fri, 14 Apr 2023 11:05:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E7=95=8C=E9=9D=A2=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=9C=AA=E6=89=98=E7=AE=A1=E6=97=A0=E7=BA=BF=E7=BD=91?= =?UTF-8?q?=E5=8D=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/wlanconnect/wlanconnect.cpp | 2 +- src/frontend/tab-pages/tabpage.cpp | 4 +++- src/frontend/tab-pages/wlanpage.cpp | 30 +++++++++++++++++++++++++++-- src/frontend/tab-pages/wlanpage.h | 1 + 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/plugins/wlanconnect/wlanconnect.cpp b/plugins/wlanconnect/wlanconnect.cpp index 0e2402c5..5ce2f20c 100644 --- a/plugins/wlanconnect/wlanconnect.cpp +++ b/plugins/wlanconnect/wlanconnect.cpp @@ -991,7 +991,7 @@ void WlanConnect::removeDeviceFrame(QString devName) while ((layoutItem = item->lanItemFrame->layout()->takeAt(0)) != NULL) { delete layoutItem->widget(); delete layoutItem; - item = nullptr; + layoutItem = nullptr; } item->itemMap.clear(); } diff --git a/src/frontend/tab-pages/tabpage.cpp b/src/frontend/tab-pages/tabpage.cpp index 03d4f92c..8544d2a4 100644 --- a/src/frontend/tab-pages/tabpage.cpp +++ b/src/frontend/tab-pages/tabpage.cpp @@ -434,7 +434,9 @@ void getDeviceEnableState(int type, QMap &map) if (!wirelessDevList.isEmpty()) { for (int i = 0; i < wirelessDevList.size(); ++i) { QString devName = wirelessDevList.at(i); - map.insert(devName, kdr->getDeviceManaged(devName)); + if (kdr->getDeviceManaged(devName)) { + map.insert(devName, kdr->getDeviceManaged(devName)); + } } } } diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 2aa4ecab..20a2c220 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -70,6 +70,7 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent) connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceRemove, this, &WlanPage::onDeviceRemove); connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceNameUpdate, this, &WlanPage::onDeviceNameUpdate); + connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceManagedChange, this, &WlanPage::onDeviceManagedChanged); connect(m_netDeviceResource, &KyNetworkDeviceResourse::stateChanged, this, &WlanPage::onWlanStateChanged); connect(m_wirelessConnectOpreation, &KyWirelessConnectOperation::activateConnectionError, this, &WlanPage::activateFailed); @@ -241,6 +242,17 @@ void WlanPage::initDevice() m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, m_devList); m_currentDevice = getDefaultDeviceName(WIRELESS); + + if (m_devList.count() == 0) { + return; + } + for (int index = m_devList.count() - 1; index >= 0; --index) { + if (!m_netDeviceResource->getDeviceManaged(m_devList.at(index))) { + //删除未托管网卡 + qDebug() << LOG_FLAG << "delete unmanaged device" << m_devList.at(index); + m_devList.removeOne(m_devList.at(index)); + } + } return; } @@ -703,7 +715,7 @@ void WlanPage::addDeviceToCombox(QString deviceName) m_deviceFrame->hide(); m_currentDevice = deviceName; setDefaultDevice(WIRELESS, m_currentDevice); - } else if (m_deviceComboBox->count() == 0) { + } else if (m_deviceComboBox->count() == 0 && m_currentDevice != deviceName) { m_deviceComboBox->addItem(m_currentDevice); m_deviceComboBox->addItem(deviceName); m_deviceFrame->show(); @@ -762,7 +774,7 @@ void WlanPage::deleteDeviceFromCombox(QString deviceName) m_currentDevice = m_devList.at(0); setDefaultDevice(WIRELESS, m_currentDevice); } else { - int index = m_deviceComboBox->findData(deviceName); + int index = m_deviceComboBox->findText(deviceName); if (-1 != index) { m_deviceComboBox->removeItem(index); m_currentDevice = m_deviceComboBox->currentText(); @@ -856,6 +868,20 @@ void WlanPage::onWlanStateChanged(NetworkManager::Device::State newstate, Networ Q_EMIT wirelessSwitchBtnChanged(getSwitchBtnState()); } +void WlanPage::onDeviceManagedChanged(QString deviceName, bool managed) +{ + if (managed && !m_devList.contains(deviceName)) { + //添加新增托管网卡 + onDeviceAdd(deviceName, NetworkManager::Device::Type::Wifi); + qDebug() << LOG_FLAG << "add managed device" << deviceName; + } + if (!managed && m_devList.contains(deviceName)) { + //删除未托管网卡 + onDeviceRemove(deviceName); + qDebug() << LOG_FLAG << "delete unmanaged device" << deviceName; + } +} + void WlanPage::sendApStateChangeSignal(QString uuid, QString ssid, QString deviceName, diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index 31257368..d3606881 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -129,6 +129,7 @@ private Q_SLOTS: void onRefreshIconTimer(); void onWlanStateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason); + void onDeviceManagedChanged(QString deviceName, bool managed); protected: bool eventFilter(QObject *watched, QEvent *event);