Merge branch '2309-0721' into 'yhkylin/v101'

fix(托盘): 开启热点后 WiFi列表内容未移除问题(bug181187)

See merge request kylinos-src/kylin-nm!235
This commit is contained in:
赵世旭 2023-07-28 08:48:56 +00:00
commit 6e07f5dabb
4 changed files with 51 additions and 27 deletions

View File

@ -457,8 +457,8 @@ NetworkManager::Connection::Ptr KyNetworkResourceManager::getConnect(const QStri
int index = 0; int index = 0;
NetworkManager::Connection::Ptr connectPtr = nullptr; NetworkManager::Connection::Ptr connectPtr = nullptr;
qDebug() <<"[KyNetworkResourceManager]" << "get connect with uuid" << connectUuid;
if (connectUuid.isEmpty()) { if (connectUuid.isEmpty()) {
qWarning() << "[KyNetworkResourceManager]" << "get connect with uuid is empty";
return nullptr; return nullptr;
} }

View File

@ -416,18 +416,20 @@ void KyWirelessNetResource::onWifiNetworkAdded(QString devIfaceName, QString ssi
void KyWirelessNetResource::onWifiNetworkRemoved(QString devIfaceName, QString ssid) void KyWirelessNetResource::onWifiNetworkRemoved(QString devIfaceName, QString ssid)
{ {
if (m_WifiNetworkList.contains(devIfaceName)) { if (!m_WifiNetworkList.contains(devIfaceName)) {
int index = 0; return;
for ( ; index < m_WifiNetworkList.value(devIfaceName).size(); index++) { }
for (int index = 0; index < m_WifiNetworkList.value(devIfaceName).size(); ++index) {
if (m_WifiNetworkList[devIfaceName].at(index).m_NetSsid == ssid) { if (m_WifiNetworkList[devIfaceName].at(index).m_NetSsid == ssid) {
m_WifiNetworkList[devIfaceName].removeAt(index); m_WifiNetworkList[devIfaceName].removeAt(index);
}
}
//remove后为空则删除 //remove后为空则删除
if (m_WifiNetworkList.value(devIfaceName).isEmpty()) { if (m_WifiNetworkList.value(devIfaceName).isEmpty()) {
m_WifiNetworkList.remove(devIfaceName); m_WifiNetworkList.remove(devIfaceName);
} }
Q_EMIT wifiNetworkRemove(devIfaceName,ssid); Q_EMIT wifiNetworkRemove(devIfaceName,ssid);
break;
}
} }
} }
@ -846,8 +848,31 @@ void KyWirelessNetResource::onConnectionUpdate(QString uuid)
return; return;
} }
m_WifiNetworkList.clear();
kyWirelessNetItemListInit(); QString ssid, dev;
getSsidByUuid(uuid, ssid);
getDeviceByUuid(uuid, dev);
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;
}
QList<KyWirelessNetItem> list = m_WifiNetworkList.value(dev);
for (int i = 0; i < list.count(); ++i) {
if (uuid == list.at(i).m_connectUuid) {
list.removeAt(i);
break;
}
}
list.append(KyWirelessNetItem(netPtr));
m_WifiNetworkList.insert(dev, list);
Q_EMIT wifiNetworkUpdate(); Q_EMIT wifiNetworkUpdate();
} }

View File

@ -104,10 +104,7 @@ NetworkMode::NetworkMode(QObject *parent)
{ {
qRegisterMetaType<NetworkManager::Device::State>("NetworkManager::Device::State"); qRegisterMetaType<NetworkManager::Device::State>("NetworkManager::Device::State");
qRegisterMetaType<NetworkManager::Device::StateChangeReason>("NetworkManager::Device::StateChangeReason"); qRegisterMetaType<NetworkManager::Device::StateChangeReason>("NetworkManager::Device::StateChangeReason");
m_deviceResource = new KyNetworkDeviceResourse(this);
m_activatedConnectResource = new KyActiveConnectResourse(this); m_activatedConnectResource = new KyActiveConnectResourse(this);
m_connectResource = new KyConnectResourse(this);
m_wirelessNetResource = new KyWirelessNetResource(this);
connect(m_activatedConnectResource, &KyActiveConnectResourse::stateChangeReason, connect(m_activatedConnectResource, &KyActiveConnectResourse::stateChangeReason,
this, &NetworkMode::onConnectionStateChanged); this, &NetworkMode::onConnectionStateChanged);
} }
@ -116,7 +113,8 @@ void NetworkMode::initWiredNetworkMode()
{ {
qDebug()<< LOG_FLAG << "initWiredNetworkMode"; qDebug()<< LOG_FLAG << "initWiredNetworkMode";
QStringList wiredDevList; QStringList wiredDevList;
m_deviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDevList); KyNetworkDeviceResourse deviceResource;
deviceResource.getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDevList);
if (wiredDevList.isEmpty()) { if (wiredDevList.isEmpty()) {
return; return;
} }
@ -148,14 +146,16 @@ void NetworkMode::initWirelessNetworkMode()
{ {
qDebug()<< LOG_FLAG << "initWirelessNetworkMode"; qDebug()<< LOG_FLAG << "initWirelessNetworkMode";
QStringList wirelessDevList; QStringList wirelessDevList;
m_deviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, wirelessDevList); KyNetworkDeviceResourse deviceResource;
deviceResource.getNetworkDeviceList(NetworkManager::Device::Type::Wifi, wirelessDevList);
if (wirelessDevList.isEmpty()) { if (wirelessDevList.isEmpty()) {
return; return;
} }
for (auto devName : wirelessDevList) { for (auto devName : wirelessDevList) {
KyWirelessNetItem wirelessNetItem; KyWirelessNetItem wirelessNetItem;
bool ret = m_wirelessNetResource->getActiveWirelessNetItem(devName, wirelessNetItem); KyWirelessNetResource wirelessNetResource;
bool ret = wirelessNetResource.getActiveWirelessNetItem(devName, wirelessNetItem);
if (ret == true) { if (ret == true) {
int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(wirelessNetItem.m_connectUuid); int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(wirelessNetItem.m_connectUuid);
@ -205,9 +205,10 @@ void NetworkMode::onConnectionStateChanged(QString uuid,
QString ssid = ""; QString ssid = "";
int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(uuid); int configType = NetworkModeConfig::getInstance()->getNetworkModeConfig(uuid);
KyConnectResourse connectResource;
//有线网络连接 //有线网络连接
if (m_connectResource->isWiredConnection(uuid)) { if (connectResource.isWiredConnection(uuid)) {
KyConnectItem *p_newItem = nullptr; KyConnectItem *p_newItem = nullptr;
p_newItem = m_activatedConnectResource->getActiveConnectionByUuid(uuid); p_newItem = m_activatedConnectResource->getActiveConnectionByUuid(uuid);
if (nullptr == p_newItem) { if (nullptr == p_newItem) {
@ -229,9 +230,10 @@ void NetworkMode::onConnectionStateChanged(QString uuid,
} }
} }
//无线网络连接 //无线网络连接
if (m_connectResource->isWirelessConnection(uuid)) { if (connectResource.isWirelessConnection(uuid)) {
m_wirelessNetResource->getSsidByUuid(uuid, ssid); KyWirelessNetResource wirelessNetResource;
m_wirelessNetResource->getDeviceByUuid(uuid, deviceName); wirelessNetResource.getSsidByUuid(uuid, ssid);
wirelessNetResource.getDeviceByUuid(uuid, deviceName);
if (ssid.isEmpty()) { if (ssid.isEmpty()) {
//忘记此网络 //忘记此网络
qDebug()<< LOG_FLAG << "forgrt wireless connect:" << uuid <<", call break_networkConnect"; qDebug()<< LOG_FLAG << "forgrt wireless connect:" << uuid <<", call break_networkConnect";

View File

@ -64,10 +64,7 @@ public:
void initWirelessNetworkMode(); void initWirelessNetworkMode();
private: private:
KyNetworkDeviceResourse *m_deviceResource = nullptr;
KyActiveConnectResourse *m_activatedConnectResource = nullptr; KyActiveConnectResourse *m_activatedConnectResource = nullptr;
KyConnectResourse * m_connectResource = nullptr;
KyWirelessNetResource *m_wirelessNetResource = nullptr;
void setFirstConnectNetworkMode(QString uuid, QString deviceName, QString ssid); void setFirstConnectNetworkMode(QString uuid, QString deviceName, QString ssid);
private Q_SLOTS: private Q_SLOTS: