重写initInfobyssid

This commit is contained in:
jzxc95 2023-09-05 15:41:10 +08:00 committed by zhangyuanyuan1
parent 45c1d17acb
commit b3c74a6d1b
5 changed files with 81 additions and 35 deletions

View File

@ -18,6 +18,7 @@
* *
*/ */
#include "kywirelessnetitem.h" #include "kywirelessnetitem.h"
#include "kylinactiveconnectresource.h"
#include <NetworkManagerQt/Connection> #include <NetworkManagerQt/Connection>
#include "kylinutil.h" #include "kylinutil.h"
@ -149,38 +150,7 @@ void KyWirelessNetItem::init(NetworkManager::WirelessNetwork::Ptr net)
} }
} }
} }
initInfoBySsid(); updatewirelessItemConnectInfo(*this);
}
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<NetworkManager::WirelessSetting>();
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;
} }
int KyWirelessNetItem::getCategory(QString uni) int KyWirelessNetItem::getCategory(QString uni)
@ -218,3 +188,73 @@ void KyWirelessNetItem::setKySecuType(QString strSecuType)
m_kySecuType = NONE; 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<NetworkManager::WirelessSetting>();
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的则用WIFIadhoc
*/
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;
}
}

View File

@ -32,9 +32,12 @@ public:
KyWirelessNetItem() {;} KyWirelessNetItem() {;}
~KyWirelessNetItem(); ~KyWirelessNetItem();
QString getDevice() {
return m_device;
}
private: private:
void init(NetworkManager::WirelessNetwork::Ptr net); void init(NetworkManager::WirelessNetwork::Ptr net);
void initInfoBySsid();
public: public:
QString m_NetSsid; QString m_NetSsid;
@ -62,4 +65,6 @@ private:
}; };
void updatewirelessItemConnectInfo(KyWirelessNetItem& item);
#endif // KYWIRELESSNETITEM_H #endif // KYWIRELESSNETITEM_H

View File

@ -252,6 +252,7 @@ bool KyWirelessNetResource::getActiveWirelessNetItem(QString deviceName, KyWirel
for (int index = 0; index < m_WifiNetworkList[deviceName].size(); index ++) { for (int index = 0; index < m_WifiNetworkList[deviceName].size(); index ++) {
if (m_WifiNetworkList[deviceName].at(index).m_NetSsid == ssid) { if (m_WifiNetworkList[deviceName].at(index).m_NetSsid == ssid) {
wirelessNetItem = m_WifiNetworkList[deviceName].at(index); wirelessNetItem = m_WifiNetworkList[deviceName].at(index);
updatewirelessItemConnectInfo(wirelessNetItem);
qDebug()<< LOG_FLAG << "getWifiNetwork success"; qDebug()<< LOG_FLAG << "getWifiNetwork success";
return true; return true;
} }

View File

@ -501,7 +501,7 @@ void WlanListItem::onNetButtonClicked()
} else { } else {
qDebug() << "KeyMgmt not support now " << type; qDebug() << "KeyMgmt not support now " << type;
} }
//qDebug() << "!!!!" << m_wirelessNetItem.m_kySecuType << kySecuType;
//有配置或者无密码的wifi直接连接 //有配置或者无密码的wifi直接连接
if (m_wirelessNetItem.m_isConfigured) { if (m_wirelessNetItem.m_isConfigured) {
if (m_wirelessNetItem.m_kySecuType == kySecuType || if (m_wirelessNetItem.m_kySecuType == kySecuType ||

View File

@ -985,7 +985,7 @@ void WlanPage::updateActivatedArea(QString uuid, QString ssid, QString devName)
m_inactivatedNetListWidget, ssid); m_inactivatedNetListWidget, ssid);
KyWirelessNetItem wirelessNetItem; KyWirelessNetItem wirelessNetItem;
bool ret = m_wirelessNetResource->getWifiNetwork(devName, ssid, wirelessNetItem); bool ret = m_wirelessNetResource->getActiveWirelessNetItem(devName, wirelessNetItem);
if (!ret) { if (!ret) {
qWarning()<<"[WlanPage] get wireless item failed, when update activated connection area."; qWarning()<<"[WlanPage] get wireless item failed, when update activated connection area.";
return; return;