Skip to content

Commit 8e8e147

Browse files
ut003640deepin-bot[bot]
authored andcommitted
fix: Update taskbar signal strength icon in real-time when network strength changes
When the network signal strength changes, the taskbar icon should be updated accordingly. Log: Fix the issue where the taskbar signal strength icon does not update in real-time Influence: Taskbar signal strength display PMS: BUG-331547
1 parent d1a6268 commit 8e8e147

File tree

5 files changed

+51
-0
lines changed

5 files changed

+51
-0
lines changed

net-view/window/netstatus.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ void NetStatus::onStrengthLevelChanged()
456456
if (item && item->status() != NetType::CS_UnConnected) {
457457
updateStatus();
458458
}
459+
updateNetworkIcon();
459460
}
460461

461462
void NetStatus::updateVpnAndProxyStatus()

src/impl/networkmanager/accesspointproxynm.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ bool AccessPointProxyNM::isWlan6() const
114114
return false;
115115
}
116116

117+
void AccessPointProxyNM::updateStrengthFromActiveAp(int strength)
118+
{
119+
if (strength == m_strength)
120+
return;
121+
122+
m_strength = strength;
123+
Q_EMIT strengthChanged(m_strength);
124+
}
125+
117126
void AccessPointProxyNM::initState()
118127
{
119128
// 获取当前网络的连接状态

src/impl/networkmanager/accesspointproxynm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class AccessPointProxyNM : public AccessPointProxy
3939
ConnectionStatus status() const override;
4040
bool hidden() const override;
4141
bool isWlan6() const override;
42+
void updateStrengthFromActiveAp(int strength);
4243

4344
private:
4445
void initState();

src/impl/networkmanager/devicemanagerrealize.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,36 @@ WirelessDeviceManagerRealize::WirelessDeviceManagerRealize(NetworkManager::Wirel
614614
NetworkManager::WirelessNetwork::List networks = m_device->networks();
615615
for (NetworkManager::WirelessNetwork::Ptr network : networks)
616616
addNetwork(network);
617+
618+
auto updateActiveApStrength = [this](const NetworkManager::AccessPoint::Ptr &activeAp) {
619+
if (activeAp.isNull())
620+
return;
621+
for (AccessPointInfo *apInfo : m_accessPointInfos) {
622+
if (apInfo && apInfo->proxy() && apInfo->proxy()->contains(activeAp->uni())) {
623+
apInfo->proxy()->updateStrengthFromActiveAp(activeAp->signalStrength());
624+
break;
625+
}
626+
}
627+
};
628+
629+
// referenceAccessPoint 信号强度变化不及时,需要监听 activeAccessPointChanged 信号
630+
auto changeActiveAp = [this, updateActiveApStrength] {
631+
if (m_activeApStrengthConn)
632+
disconnect(m_activeApStrengthConn);
633+
NetworkManager::AccessPoint::Ptr activeAp = m_device->activeAccessPoint();
634+
if (activeAp.isNull())
635+
return;
636+
637+
updateActiveApStrength(activeAp);
638+
m_activeApStrengthConn = connect(activeAp.data(), &NetworkManager::AccessPoint::signalStrengthChanged, this, [updateActiveApStrength, activeAp] {
639+
updateActiveApStrength(activeAp);
640+
}, Qt::UniqueConnection);
641+
};
642+
643+
connect(device.data(), &NetworkManager::WirelessDevice::activeAccessPointChanged, this, [changeActiveAp] {
644+
changeActiveAp();
645+
});
646+
changeActiveAp();
617647
}
618648

619649
WirelessDeviceManagerRealize::~WirelessDeviceManagerRealize()
@@ -1144,11 +1174,19 @@ void WirelessDeviceManagerRealize::addNetwork(const NetworkManager::WirelessNetw
11441174
AccessPointInfo *apInfo = new AccessPointInfo(m_device, network);
11451175
m_accessPointInfos << apInfo;
11461176

1177+
NetworkManager::AccessPoint::Ptr activeAp = m_device->activeAccessPoint();
1178+
if (!activeAp.isNull() && apInfo->proxy()->contains(activeAp->uni()))
1179+
apInfo->proxy()->updateStrengthFromActiveAp(activeAp->signalStrength());
1180+
11471181
Q_EMIT networkAdded({ apInfo->accessPoint() });
11481182
} else {
11491183
// 已经存在该无线网络,只需要更新内部的数据即可
11501184
AccessPointInfo *apInfo = *itApInfo;
11511185
apInfo->proxy()->updateNetwork(network);
1186+
1187+
NetworkManager::AccessPoint::Ptr activeAp = m_device->activeAccessPoint();
1188+
if (!activeAp.isNull() && apInfo->proxy()->contains(activeAp->uni()))
1189+
apInfo->proxy()->updateStrengthFromActiveAp(activeAp->signalStrength());
11521190
}
11531191
}
11541192

src/impl/networkmanager/devicemanagerrealize.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <NetworkManagerQt/WirelessDevice>
1212
#include <NetworkManagerQt/WirelessSecuritySetting>
1313

14+
#include <QMetaObject>
1415
#include <QDBusReply>
1516

1617
namespace NetworkManager {
@@ -153,6 +154,7 @@ private Q_SLOTS:
153154
bool m_hotspotEnabled;
154155
ProcesserInterface *m_netProcesser;
155156
bool m_available;
157+
QMetaObject::Connection m_activeApStrengthConn;
156158
};
157159

158160
}

0 commit comments

Comments
 (0)