From 1ef4794d5f10d44041c84c7b08e1209428314616 Mon Sep 17 00:00:00 2001 From: liuxinhao Date: Fri, 18 Oct 2024 15:00:05 +0800 Subject: [PATCH] fix(Network): fix a bug in the logic of the network plugin's handing of the configure mac attribute update slot function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复网络插件处理配置Mac属性更改槽函数逻辑错误 - 调整代码中所有使用PermanentHardwareAddress属性的位置,获取不到尝试取当前硬件地址 --- .../src/plugin/connection-itemwidget.cpp | 6 ++++ .../device-available-connection-widget.cpp | 32 ++++++++++++------- plugins/network/src/utils.cpp | 9 ++++-- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/plugins/network/src/plugin/connection-itemwidget.cpp b/plugins/network/src/plugin/connection-itemwidget.cpp index df5dbc3c..1f9a78e1 100644 --- a/plugins/network/src/plugin/connection-itemwidget.cpp +++ b/plugins/network/src/plugin/connection-itemwidget.cpp @@ -357,7 +357,13 @@ void ConnectionItemWidget::updateConnection() QString devicePath = m_connectionInfo.devicePath; auto device = findNetworkInterface(devicePath); WiredDevice::Ptr wiredDevice = qobject_cast(device); + QString hardwareAddress = wiredDevice->permanentHardwareAddress(); + if (hardwareAddress.isEmpty()) + { + hardwareAddress = wiredDevice->hardwareAddress(); + } + // 检查绑定的设备信息是否改变 if (!mac.isEmpty() && (mac != hardwareAddress)) diff --git a/plugins/network/src/plugin/device-available-connection-widget.cpp b/plugins/network/src/plugin/device-available-connection-widget.cpp index adf14007..064ad0e6 100644 --- a/plugins/network/src/plugin/device-available-connection-widget.cpp +++ b/plugins/network/src/plugin/device-available-connection-widget.cpp @@ -201,13 +201,7 @@ void DeviceAvailableConnectionWidget::createConnection() } void DeviceAvailableConnectionWidget::updateConnection(const QString &connectionPath, const QString &mac) -{ - ConnectionItemWidget *connectionItem = findConnectionItemByPath(connectionPath); - if (connectionItem == nullptr) - { - return; - } - +{ // 判断配置是否应该出现在该设备下,应判断两个属性permanentHardwareAddress,hardwareAddress // 部分手机共享网络permanentHardwareAddress属性为空 QString deviceMac = m_wiredDevice->permanentHardwareAddress(); @@ -216,15 +210,29 @@ void DeviceAvailableConnectionWidget::updateConnection(const QString &connection deviceMac = m_wiredDevice->hardwareAddress(); } + ConnectionItemWidget *connectionItem = findConnectionItemByPath(connectionPath); + if (deviceMac == mac) { - auto connection = findConnection(connectionPath); - onAddConnection(connection); + // 配置Mac等于设备Mac,更新或新增该配置 + if( connectionItem ) + { + updateConnectionItemStatus(connectionItem); + } + else + { + auto connection = findConnection(connectionPath); + onAddConnection(connection); + } } - else + else { - removeConnectionItem(connectionItem); - connectionItem->deleteLater(); + //配置mac不等于设备Mac,删除该配置 + if( connectionItem ) + { + removeConnectionItem(connectionItem); + connectionItem->deleteLater(); + } } } diff --git a/plugins/network/src/utils.cpp b/plugins/network/src/utils.cpp index 13732973..bd53512f 100644 --- a/plugins/network/src/utils.cpp +++ b/plugins/network/src/utils.cpp @@ -236,7 +236,12 @@ NetworkManager::Connection::List NetworkUtils::getAvailableWiredConnections(cons else { auto wiredDevice = device->as(); - QString permanentHardwareAddress = wiredDevice->permanentHardwareAddress(); + + QString deviceHardwareAddress = wiredDevice->permanentHardwareAddress(); + if( deviceHardwareAddress.isEmpty() ) + { + deviceHardwareAddress = wiredDevice->hardwareAddress(); + } auto allConnections = listConnections(); for (auto connection : allConnections) @@ -250,7 +255,7 @@ NetworkManager::Connection::List NetworkUtils::getAvailableWiredConnections(cons // 匹配配置以及设备中的Mac地址是否匹配 WiredSetting::Ptr wiredSetting = settings->setting(Setting::SettingType::Wired).dynamicCast(); QString mac = wiredSetting->macAddress().toHex(':').toUpper(); - if ( !mac.isEmpty() && mac != permanentHardwareAddress ) + if ( !mac.isEmpty() && mac != deviceHardwareAddress ) { continue; } -- Gitee