From 5190d5e838ac530adad36daa408a883218641a4d Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Tue, 5 Sep 2023 17:56:07 +0800 Subject: [PATCH] fix(wlan): modify onConnectionUpdate method and add signal(bug#190099) --- plugins/wlanconnect/wlanconnect.cpp | 16 +++++-- .../dbus-interface/kywirelessnetresource.cpp | 45 +++++++++++++------ .../dbus-interface/kywirelessnetresource.h | 1 + src/frontend/tab-pages/wlanpage.cpp | 8 ++++ src/frontend/tab-pages/wlanpage.h | 1 + 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/plugins/wlanconnect/wlanconnect.cpp b/plugins/wlanconnect/wlanconnect.cpp index 7a05c009..e1b01309 100644 --- a/plugins/wlanconnect/wlanconnect.cpp +++ b/plugins/wlanconnect/wlanconnect.cpp @@ -605,7 +605,6 @@ void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QS if (!deviceFrameMap.contains(deviceName)) { return; } - for (int i = 0; i < deviceFrameMap[deviceName]->itemMap.size(); ++i) { if (deviceFrameMap[deviceName]->itemMap.contains(ssid)) { item = deviceFrameMap[deviceName]->itemMap[ssid]; if (status == ACTIVATED || status == ACTIVATING) { @@ -621,9 +620,20 @@ void WlanConnect::onActiveConnectionChanged(QString deviceName, QString ssid, QS deviceFrameMap[deviceName]->uuid.clear(); //todo 断开后排序 现在等下次更新列表 自动排序 } - break; + } else { + if (uuid == deviceFrameMap[deviceName]->uuid) { + QMap::iterator itemIter; + for (itemIter = deviceFrameMap[deviceName]->itemMap.begin(); itemIter != deviceFrameMap[deviceName]->itemMap.end(); itemIter++) { + if (itemIter.value()->uuid == uuid ) { + item = itemIter.value(); + if (status == DEACTIVATED) { + itemIter.value()->uuid.clear(); + } + break; + } + } + } } - } } if (nullptr != item) { diff --git a/src/backend/dbus-interface/kywirelessnetresource.cpp b/src/backend/dbus-interface/kywirelessnetresource.cpp index 63dfd555..6196d55c 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.cpp +++ b/src/backend/dbus-interface/kywirelessnetresource.cpp @@ -863,25 +863,44 @@ void KyWirelessNetResource::onConnectionUpdate(QString uuid) getSsidByUuid(uuid, ssid); getDeviceByUuid(uuid, dev); - NetworkManager::Device::Ptr devicePtr = m_networkResourceInstance->findDeviceInterface(dev); - if (devicePtr.isNull() || !m_WifiNetworkList.contains(dev)) { - return; + if (!dev.isEmpty()) { + NetworkManager::Device::Ptr devicePtr = m_networkResourceInstance->findDeviceInterface(dev); + if (devicePtr.isNull() || !m_WifiNetworkList.contains(dev)) { + return; + } } - NetworkManager::WirelessNetwork::Ptr netPtr = m_networkResourceInstance->findWifiNetwork(ssid, devicePtr->uni()); - if (netPtr.isNull()) { - return; - } + QMap >::iterator iter; + for (iter = m_WifiNetworkList.begin(); iter != m_WifiNetworkList.end(); ++iter) { + QList::iterator itemIter; + for (itemIter = iter.value().begin(); itemIter != iter.value().end(); ++itemIter) { + //判断是否有其他wifi配置 更新WIFI-bd 的connect相关变量 emit update + if (uuid == itemIter->m_connectUuid) { + if (itemIter->m_NetSsid != ssid || + (iter.key() != dev && !dev.isEmpty())) { + updatewirelessItemConnectInfo(*itemIter); + Q_EMIT connectionUpdate(iter.key(), itemIter->m_NetSsid); - QList list = m_WifiNetworkList.value(dev); - for (int i = 0; i < list.count(); ++i) { - if (uuid == list.at(i).m_connectUuid) { - list.removeAt(i); + //判断netptr是否为空 空返回 + //否则 更新ssid 的connect相关变量 emit update ssid + NetworkManager::Device::Ptr devicePtr = m_networkResourceInstance->findDeviceInterface(dev); + NetworkManager::WirelessNetwork::Ptr netPtr = m_networkResourceInstance->findWifiNetwork(ssid, devicePtr->uni()); + if (netPtr.isNull()) { + qDebug() << LOG_FLAG << ssid << "netPtr is Null"; + return; + } + } + } + //更新WIFI 的connect相关变量 emit update to ui + if (ssid == itemIter->m_NetSsid) { + if (iter.key() == dev || dev.isEmpty()) { + updatewirelessItemConnectInfo(*itemIter); + Q_EMIT connectionUpdate(dev, itemIter->m_NetSsid); + } + } break; } } - list.append(KyWirelessNetItem(netPtr)); - m_WifiNetworkList.insert(dev, list); Q_EMIT wifiNetworkUpdate(); } diff --git a/src/backend/dbus-interface/kywirelessnetresource.h b/src/backend/dbus-interface/kywirelessnetresource.h index ac1e5f5b..07ea5cce 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.h +++ b/src/backend/dbus-interface/kywirelessnetresource.h @@ -84,6 +84,7 @@ Q_SIGNALS: void secuTypeChange(QString, QString, QString); void connectionRemove(QString, QString, QString); void connectionAdd(QString, QString); + void connectionUpdate(QString, QString); void wifiNetworkUpdate(); void wifiNetworkAdd(QString, KyWirelessNetItem&); void wifiNetworkRemove(QString, QString); diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 80042664..fdc0ecfb 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -62,6 +62,7 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent) connect(m_wirelessNetResource, &KyWirelessNetResource::connectionAdd, this, &WlanPage::onConnectionAdd); connect(m_wirelessNetResource, &KyWirelessNetResource::connectionRemove, this, &WlanPage::onConnectionRemove); + connect(m_wirelessNetResource, &KyWirelessNetResource::connectionUpdate, this, &WlanPage::onConnectionUpdate); connect(m_activatedConnectResource, &KyActiveConnectResourse::stateChangeReason, this, &WlanPage::onConnectionStateChanged); @@ -687,6 +688,13 @@ void WlanPage::onConnectionRemove(QString deviceName, QString ssid, QString path return; } +void WlanPage::onConnectionUpdate(QString deviceName, QString ssid) +{ + if (deviceName == m_currentDevice || deviceName.isEmpty()) { + updateWlanListItem(ssid); + } +} + void WlanPage::onSecurityTypeChange(QString devName, QString ssid, QString secuType) { QListWidgetItem *p_listWidgetItem = nullptr; diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index a2563bf4..41d55246 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -119,6 +119,7 @@ private Q_SLOTS: void onConnectionAdd(QString deviceName, QString ssid); void onConnectionRemove(QString deviceName, QString ssid, QString path); + void onConnectionUpdate(QString deviceName, QString ssid); void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType); void onDeviceRemove(QString deviceName);