diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp index f45cddc0..3e80ea59 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp @@ -306,7 +306,12 @@ void KyNetworkResourceManager::addWifiNetwork(NetworkManager::WirelessNetwork::P //device signals connect(net.data(), &NetworkManager::WirelessNetwork::signalStrengthChanged, this, &KyNetworkResourceManager::onUpdateWirelessNet); connect(net.data(), &NetworkManager::WirelessNetwork::referenceAccessPointChanged, this, &KyNetworkResourceManager::onUpdateWirelessNet); + connect(net.data(), &NetworkManager::WirelessNetwork::referenceAccessPointChanged, this, &KyNetworkResourceManager::onReferenceAccessPointChanged); connect(net.data(), &NetworkManager::WirelessNetwork::disappeared, this, &KyNetworkResourceManager::onUpdateWirelessNet); + connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::wpaFlagsChanged, this, &KyNetworkResourceManager::onWifiNetworkSecuChang, + Qt::UniqueConnection); + connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::rsnFlagsChanged, this, &KyNetworkResourceManager::onWifiNetworkSecuChang, + Qt::UniqueConnection); } void KyNetworkResourceManager::insertWifiNetworks() @@ -838,6 +843,31 @@ void KyNetworkResourceManager::onWifiNetworkDisappeared(QString const & ssid) return; } +void KyNetworkResourceManager::onReferenceAccessPointChanged() +{ + NetworkManager::WirelessNetwork *p_wirelessNet = + qobject_cast(sender()); + if (nullptr != p_wirelessNet) { + onAccessPointUpdate(p_wirelessNet); + } +} + +void KyNetworkResourceManager::onAccessPointUpdate(NetworkManager::WirelessNetwork * net) +{ + if (nullptr == net) { + return; + } + auto index = std::find(m_wifiNets.cbegin(), m_wifiNets.cend(), net); + if (m_wifiNets.cend() != index) { + if (!net->referenceAccessPoint().isNull()) { + connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::wpaFlagsChanged, this, &KyNetworkResourceManager::onWifiNetworkSecuChang, + Qt::UniqueConnection); + connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::rsnFlagsChanged, this, &KyNetworkResourceManager::onWifiNetworkSecuChang, + Qt::UniqueConnection); + } + } +} + void KyNetworkResourceManager::onUpdateWirelessNet() { NetworkManager::WirelessNetwork *p_wirelessNet = @@ -849,6 +879,13 @@ void KyNetworkResourceManager::onUpdateWirelessNet() return; } +void KyNetworkResourceManager::onWifiNetworkSecuChang() +{ + NetworkManager::AccessPoint *p_wirelessNet = + qobject_cast(sender()); + emit wifiNetworkSecuChange(p_wirelessNet); +} + void KyNetworkResourceManager::onDeviceAdded(QString const & uni) { qDebug()<< "onDeviceAdded"<referenceAccessPoint()->wpaFlags(); NetworkManager::AccessPoint::WpaFlags rsnFlag = net->referenceAccessPoint()->rsnFlags(); m_secuType = enumToQstring(cap, wpaFlag, rsnFlag); - if (m_secuType.indexOf(ENTERPRICE_TYPE) >= 0) { - m_kySecuType = WPA_AND_WPA2_ENTERPRISE; - } else if (m_secuType.indexOf(WPA3) >= 0) { - m_kySecuType = WPA3_PERSONAL; - } else if ( m_secuType.indexOf(WPA1_AND_WPA2) >= 0) { - m_kySecuType = WPA_AND_WPA2_PERSONAL; - } +// if (m_secuType.indexOf(ENTERPRICE_TYPE) >= 0) { +// m_kySecuType = WPA_AND_WPA2_ENTERPRISE; +// } else if (m_secuType.indexOf(WPA3) >= 0) { +// m_kySecuType = WPA3_PERSONAL; +// } else if ( m_secuType.indexOf(WPA1_AND_WPA2) >= 0) { +// m_kySecuType = WPA_AND_WPA2_PERSONAL; +// } + setKySecuType(m_secuType); m_bssid = net->referenceAccessPoint()->hardwareAddress(); m_device = net->device(); m_uni = net->referenceAccessPoint()->uni(); @@ -151,3 +152,16 @@ int KyWirelessNetItem::getCategory(QString uni) } } + +void KyWirelessNetItem::setKySecuType(QString strSecuType) +{ + if (strSecuType.indexOf(ENTERPRICE_TYPE) >= 0) { + m_kySecuType = WPA_AND_WPA2_ENTERPRISE; + } else if (strSecuType.indexOf(WPA3) >= 0) { + m_kySecuType = WPA3_PERSONAL; + } else if ( strSecuType.indexOf(WPA1_AND_WPA2) >= 0) { + m_kySecuType = WPA_AND_WPA2_PERSONAL; + } else { + m_kySecuType = NONE; + } +} diff --git a/src/backend/dbus-interface/kywirelessnetitem.h b/src/backend/dbus-interface/kywirelessnetitem.h index 0eb10690..36eecc76 100644 --- a/src/backend/dbus-interface/kywirelessnetitem.h +++ b/src/backend/dbus-interface/kywirelessnetitem.h @@ -55,6 +55,7 @@ public: uint m_channel; int getCategory(QString uni); + void setKySecuType(QString strSecuType); private: KyNetworkResourceManager *m_networkResourceInstance = nullptr; diff --git a/src/backend/dbus-interface/kywirelessnetresource.cpp b/src/backend/dbus-interface/kywirelessnetresource.cpp index ac3e3046..7ed1e8a0 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.cpp +++ b/src/backend/dbus-interface/kywirelessnetresource.cpp @@ -21,6 +21,9 @@ #include "kylinutil.h" #define LOG_FLAG "[KyWirelessNetResource]" +const QString ENTERPRICE_TYPE = "802.1X"; +const QString WPA1_AND_WPA2 = "WPA"; +const QString WPA3 = "WPA3"; static bool subWifiListSort(const KyWirelessNetItem info1, const KyWirelessNetItem info2) { @@ -63,6 +66,8 @@ KyWirelessNetResource::KyWirelessNetResource(QObject *parent) this, &KyWirelessNetResource::onWifiNetworkRemoved, Qt::ConnectionType::DirectConnection); connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkPropertyChange, this, &KyWirelessNetResource::onWifiNetworkPropertyChange, Qt::ConnectionType::DirectConnection); + connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkSecuChange, + this, &KyWirelessNetResource::onWifiNetworkSecuChange, Qt::ConnectionType::DirectConnection); connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkDeviceDisappear, this, &KyWirelessNetResource::onWifiNetworkDeviceDisappear, Qt::ConnectionType::DirectConnection); @@ -426,12 +431,39 @@ void KyWirelessNetResource::onWifiNetworkRemoved(QString devIfaceName, QString s } } +void KyWirelessNetResource::onWifiNetworkSecuChange(NetworkManager::AccessPoint *accessPointPtr) +{ + QString secuType = enumToQstring(accessPointPtr->capabilities(), + accessPointPtr->wpaFlags(), + accessPointPtr->rsnFlags()); + + + QMap >::iterator iter = m_WifiNetworkList.begin(); + while (iter != m_WifiNetworkList.end()) { + QList::iterator itemIter = iter.value().begin(); + while (itemIter != iter.value().end()) { + if (itemIter->m_NetSsid == accessPointPtr->ssid()) { + QString devName = iter.key(); + itemIter->m_secuType = secuType; + itemIter->setKySecuType(secuType); + //qDebug() << "!!!!" << itemIter->m_NetSsid << itemIter->m_secuType << itemIter->m_kySecuType; + emit secuTypeChange(devName, accessPointPtr->ssid(), secuType); + break; + } + itemIter++; + } + iter++; + } + +} + void KyWirelessNetResource::onWifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net) { if (nullptr == net) { return; } + qDebug() << "onWifiNetworkPropertyChange" << net->ssid(); NetworkManager::AccessPoint::Ptr accessPointPtr = net->referenceAccessPoint(); QByteArray rawSsid = accessPointPtr->rawSsid(); QString wifiSsid = getSsidFromByteArray(rawSsid); @@ -460,7 +492,10 @@ void KyWirelessNetResource::onWifiNetworkPropertyChange(NetworkManager::Wireless accessPointPtr->wpaFlags(), accessPointPtr->rsnFlags()); if (iter->m_secuType != secuType) { + //qDebug() << "!!!!secuTypeChange" << wifiSsid << iter->m_secuType << "change to " << secuType; iter->m_secuType = secuType; + iter->setKySecuType(secuType); + emit secuTypeChange(devIface, wifiSsid, secuType); } @@ -693,7 +728,7 @@ void KyWirelessNetResource::onConnectionRemove(QString path) for(auto var = map.cbegin(); var != map.cend(); var++) { QString devIfaceName = var.key(); QString ssid = var.value(); - emit connectionRemove(devIfaceName, ssid); + emit connectionRemove(devIfaceName, ssid, path); } } diff --git a/src/backend/dbus-interface/kywirelessnetresource.h b/src/backend/dbus-interface/kywirelessnetresource.h index 660b565f..8196fc65 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.h +++ b/src/backend/dbus-interface/kywirelessnetresource.h @@ -64,6 +64,7 @@ public slots: void onWifiNetworkAdded(QString, QString); void onWifiNetworkRemoved(QString, QString); void onWifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net); + void onWifiNetworkSecuChange(NetworkManager::AccessPoint *accessPointPtr); void onWifiNetworkDeviceDisappear(); void onConnectionAdd(QString uuid); @@ -78,7 +79,7 @@ signals: void signalStrengthChange(QString, QString, int); void bssidChange(QString, QString, QString); void secuTypeChange(QString, QString, QString); - void connectionRemove(QString, QString); + void connectionRemove(QString, QString, QString); void connectionAdd(QString, QString); void wifiNetworkUpdate(); void wifiNetworkAdd(QString, KyWirelessNetItem&); diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index 85191a10..56b83382 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -28,6 +28,10 @@ #define ENABLE_BUTTON_COLOR qApp->palette().highlight().color() #define UNABLE_BUTTON_COLOR qApp->palette().button().color() +const QString ENTERPRICE_TYPE = "802.1X"; +const QString WPA1_AND_WPA2 = "WPA"; +const QString WPA3 = "WPA3"; + WlanListItem::WlanListItem(KyWirelessNetItem &wirelessNetItem, QString device, bool isApMode, QWidget *parent) : WlanListItem(wirelessNetItem, device, parent) { @@ -84,6 +88,11 @@ QString WlanListItem::getUuid() return m_wirelessNetItem.m_connectUuid; } +QString WlanListItem::getPath() +{ + return m_wirelessNetItem.m_connDbusPath; +} + void WlanListItem::setSignalStrength(const int &signal) { m_wirelessNetItem.m_signalStrength = signal; @@ -467,7 +476,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) { @@ -512,7 +521,7 @@ void WlanListItem::updateWirelessNetSecurity(QString ssid, QString securityType) } qDebug() << LOG_FLAG << "Security changed! ssid = " << m_wirelessNetItem.m_NetSsid - << "; security = " << m_wirelessNetItem.m_secuType << "." <getUuid() == uuid) { + + if (p_wlanItem->getUuid() == uuid || uuid.isEmpty()) { + if (uuid.isEmpty() && p_wlanItem->getPath() != path) { + return; + } + deleteWirelessItemFormMap(m_activateConnectionItemMap, m_activatedNetListWidget, ssid); QListWidgetItem *p_activeListWidgetItem = addEmptyItem(m_activatedNetListWidget); m_activateConnectionItemMap.insert(EMPTY_SSID, p_activeListWidgetItem); @@ -1005,7 +1010,9 @@ void WlanPage::onConnectionStateChanged(QString uuid, if (devName.isEmpty()) { devName = m_currentDevice; } - updateWirelessNetArea(uuid, ssid, devName); + + updateWirelessNetArea(uuid, ssid, devName,""); + if (m_wirelessNetItemMap.contains(ssid)) { QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid); updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated); diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index c4ee3d38..11c47ba8 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -108,7 +108,7 @@ private slots: void onWlanRemoved(QString interface, QString ssid); void onConnectionAdd(QString deviceName, QString ssid); - void onConnectionRemove(QString deviceName, QString ssid); + void onConnectionRemove(QString deviceName, QString ssid, QString path); void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType); void onDeviceRemove(QString deviceName); @@ -167,7 +167,7 @@ private: void constructActivateConnectionArea(); void updateActivatedArea(QString uuid, QString ssid, QString devName); - void updateWirelessNetArea(QString uuid, QString ssid, QString devName); + void updateWirelessNetArea(QString uuid, QString ssid, QString devName, QString path); void addDeviceToCombox(QString deviceName); void deleteDeviceFromCombox(QString deviceName);