From b3c74a6d1bf9edba978f6c86f2fd88fd23f34df8 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Tue, 5 Sep 2023 15:41:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99initInfobyssid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dbus-interface/kywirelessnetitem.cpp | 104 ++++++++++++------ .../dbus-interface/kywirelessnetitem.h | 7 +- .../dbus-interface/kywirelessnetresource.cpp | 1 + src/frontend/list-items/wlanlistitem.cpp | 2 +- src/frontend/tab-pages/wlanpage.cpp | 2 +- 5 files changed, 81 insertions(+), 35 deletions(-) diff --git a/src/backend/dbus-interface/kywirelessnetitem.cpp b/src/backend/dbus-interface/kywirelessnetitem.cpp index ac86d45a..d0ef888d 100644 --- a/src/backend/dbus-interface/kywirelessnetitem.cpp +++ b/src/backend/dbus-interface/kywirelessnetitem.cpp @@ -18,6 +18,7 @@ * */ #include "kywirelessnetitem.h" +#include "kylinactiveconnectresource.h" #include #include "kylinutil.h" @@ -149,38 +150,7 @@ void KyWirelessNetItem::init(NetworkManager::WirelessNetwork::Ptr net) } } } - initInfoBySsid(); -} - -void KyWirelessNetItem::initInfoBySsid() -{ - for (auto const & conn : m_networkResourceInstance->m_connections) { - NetworkManager::ConnectionSettings::Ptr settings = conn->settings(); - if (settings->connectionType() != NetworkManager::ConnectionSettings::Wireless) { - continue; - } - - NetworkManager::WirelessSetting::Ptr wifi_sett - = settings->setting(NetworkManager::Setting::Wireless).dynamicCast(); - QString devName = m_networkResourceInstance->findDeviceUni(m_device)->interfaceName(); - QByteArray rawSsid = wifi_sett->ssid(); - QString wifiSsid = getSsidFromByteArray(rawSsid); - if (wifiSsid == m_NetSsid - && (settings->interfaceName().compare(devName) == 0 || settings->interfaceName().isEmpty())) { - m_connectUuid = settings->uuid(); - m_connName = conn->name(); - m_connDbusPath = conn->path(); - m_isConfigured = true; - /* - * 如果有激活的链接,则取激活的链接,没有则取最后一个,因为一个热点可以创建多个链接 - */ - if (nullptr != m_networkResourceInstance->getActiveConnect(m_connectUuid)) { - break; - } - } - } - - return; + updatewirelessItemConnectInfo(*this); } int KyWirelessNetItem::getCategory(QString uni) @@ -218,3 +188,73 @@ void KyWirelessNetItem::setKySecuType(QString strSecuType) m_kySecuType = NONE; } } + +void updatewirelessItemConnectInfo(KyWirelessNetItem& item) +{ + KyNetworkResourceManager *networkResourceInstance = KyNetworkResourceManager::getInstance(); + + bool findHotspot = false; + bool findInfrastructure = false; + + KyWirelessNetItem hotspotItem; + KyWirelessNetItem connectItem; + + for (auto const & conn : networkResourceInstance->m_connections) { + NetworkManager::ConnectionSettings::Ptr settings = conn->settings(); + if (settings->connectionType() != NetworkManager::ConnectionSettings::Wireless) { + continue; + } + + NetworkManager::WirelessSetting::Ptr wifi_sett + = settings->setting(NetworkManager::Setting::Wireless).dynamicCast(); + QString devName = networkResourceInstance->findDeviceUni(item.getDevice())->interfaceName(); + QByteArray rawSsid = wifi_sett->ssid(); + QString wifiSsid = getSsidFromByteArray(rawSsid); + if (wifiSsid == item.m_NetSsid + && (settings->interfaceName().compare(devName) == 0 || settings->interfaceName().isEmpty())) { + /* + * 如果有激活的链接,则取激活的链接,没有则取最后一个,因为一个热点可以创建多个链接, 有WIFI的则用WIFI,否则用adhoc + */ + KyActiveConnectResourse actResource; + KyConnectItem * kyItem = actResource.getActiveConnectionByUuid(settings->uuid(), devName); + if (nullptr != kyItem) { + item.m_connectUuid = settings->uuid(); + item.m_connName = conn->name(); + item.m_connDbusPath = conn->path(); + item.m_isConfigured = true; + return; + } + + if (wifi_sett->mode() != NetworkManager::WirelessSetting::NetworkMode::Infrastructure) { + hotspotItem.m_connectUuid = settings->uuid(); + hotspotItem.m_connName = conn->name(); + hotspotItem.m_connDbusPath = conn->path(); + hotspotItem.m_isConfigured = true; + findHotspot = true; + } else { + connectItem.m_connectUuid = settings->uuid(); + connectItem.m_connName = conn->name(); + connectItem.m_connDbusPath = conn->path(); + connectItem.m_isConfigured = true; + findInfrastructure = true; + } + } + } + + if (findInfrastructure) { + item.m_connectUuid = connectItem.m_connectUuid; + item.m_connName = connectItem.m_connName; + item.m_connDbusPath = connectItem.m_connDbusPath; + item.m_isConfigured = connectItem.m_isConfigured; + } else if (findHotspot) { + item.m_connectUuid = hotspotItem.m_connectUuid; + item.m_connName = hotspotItem.m_connName; + item.m_connDbusPath = hotspotItem.m_connDbusPath; + item.m_isConfigured = hotspotItem.m_isConfigured; + } else { + item.m_connectUuid.clear(); + item.m_connName.clear(); + item.m_connDbusPath.clear(); + item.m_isConfigured = false; + } +} diff --git a/src/backend/dbus-interface/kywirelessnetitem.h b/src/backend/dbus-interface/kywirelessnetitem.h index 533e6ca6..9533e6b4 100644 --- a/src/backend/dbus-interface/kywirelessnetitem.h +++ b/src/backend/dbus-interface/kywirelessnetitem.h @@ -32,9 +32,12 @@ public: KyWirelessNetItem() {;} ~KyWirelessNetItem(); + QString getDevice() { + return m_device; + } + private: void init(NetworkManager::WirelessNetwork::Ptr net); - void initInfoBySsid(); public: QString m_NetSsid; @@ -62,4 +65,6 @@ private: }; +void updatewirelessItemConnectInfo(KyWirelessNetItem& item); + #endif // KYWIRELESSNETITEM_H diff --git a/src/backend/dbus-interface/kywirelessnetresource.cpp b/src/backend/dbus-interface/kywirelessnetresource.cpp index b855d73a..63dfd555 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.cpp +++ b/src/backend/dbus-interface/kywirelessnetresource.cpp @@ -252,6 +252,7 @@ bool KyWirelessNetResource::getActiveWirelessNetItem(QString deviceName, KyWirel for (int index = 0; index < m_WifiNetworkList[deviceName].size(); index ++) { if (m_WifiNetworkList[deviceName].at(index).m_NetSsid == ssid) { wirelessNetItem = m_WifiNetworkList[deviceName].at(index); + updatewirelessItemConnectInfo(wirelessNetItem); qDebug()<< LOG_FLAG << "getWifiNetwork success"; return true; } diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index d5cc9651..e0b2cc33 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -501,7 +501,7 @@ void WlanListItem::onNetButtonClicked() } else { qDebug() << "KeyMgmt not support now " << type; } - //qDebug() << "!!!!" << m_wirelessNetItem.m_kySecuType << kySecuType; + //有配置或者无密码的wifi直接连接 if (m_wirelessNetItem.m_isConfigured) { if (m_wirelessNetItem.m_kySecuType == kySecuType || diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index d275f683..80042664 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -985,7 +985,7 @@ void WlanPage::updateActivatedArea(QString uuid, QString ssid, QString devName) m_inactivatedNetListWidget, ssid); KyWirelessNetItem wirelessNetItem; - bool ret = m_wirelessNetResource->getWifiNetwork(devName, ssid, wirelessNetItem); + bool ret = m_wirelessNetResource->getActiveWirelessNetItem(devName, wirelessNetItem); if (!ret) { qWarning()<<"[WlanPage] get wireless item failed, when update activated connection area."; return;