mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix(network): 解决连接不冲突的有线连接,任务栏图标状态不刷新
因为IP冲突检测存在一些不准确的状态,做了状态延迟刷新。现调整算法按 计数来减轻误差 Bug: https://pms.uniontech.com/zentao/bug-view-91516.html Log: 解决IP冲突时切换时,图标状态不刷新 Change-Id: I87f6f526dcbfc0148c2d0a5b639123dc8bb66677
This commit is contained in:
parent
30c8251882
commit
6495a484da
@ -44,6 +44,7 @@ NetworkItem::NetworkItem(QWidget *parent)
|
||||
, m_networkInter(new DbusNetwork("com.deepin.daemon.Network", "/com/deepin/daemon/Network", QDBusConnection::sessionBus(), this))
|
||||
, m_detectConflictTimer(new QTimer(this))
|
||||
, m_ipConflict(false)
|
||||
, m_ipConflictChecking(false)
|
||||
{
|
||||
refreshIconTimer->setInterval(100);
|
||||
|
||||
@ -525,8 +526,6 @@ bool NetworkItem::eventFilter(QObject *obj, QEvent *event)
|
||||
// 主动检测,如果冲突会触发IPConflict信号
|
||||
if (obj == this) {
|
||||
if (event->type() == QEvent::Enter) {
|
||||
if (m_detectConflictTimer->isActive())
|
||||
m_detectConflictTimer->stop();
|
||||
onDetectConflict();
|
||||
}
|
||||
}
|
||||
@ -596,6 +595,8 @@ void NetworkItem::onThemeTypeChanged(DGuiApplicationHelper::ColorType themeType)
|
||||
*/
|
||||
void NetworkItem::ipConflict(const QString &ip, const QString &mac)
|
||||
{
|
||||
static int conflictCount = 0;
|
||||
static int removeCount = 0;
|
||||
QStringList ipList = currentIpList();
|
||||
|
||||
//判断缓存冲突列表中的IP是否在本机IP列表中
|
||||
@ -613,26 +614,41 @@ void NetworkItem::ipConflict(const QString &ip, const QString &mac)
|
||||
// 自检为空,则解除ip冲突状态或者冲突列表为空时,更新状态
|
||||
m_conflictMap.remove(ip);
|
||||
|
||||
if (m_conflictMap.isEmpty()) {
|
||||
conflictCount = 0;
|
||||
}
|
||||
|
||||
if (m_conflictMap.isEmpty() && m_ipConflict) {
|
||||
// 确认1次解除
|
||||
if (removeCount++ < 1) {
|
||||
onDetectConflict();
|
||||
return;
|
||||
}
|
||||
|
||||
// 当mac为空且map也为空时,立即更新状态会导致文字显示由'ip地址冲突'变为'已连接网络但无法访问互联网'
|
||||
// 因为加了次数判断
|
||||
static int emptyNums = 0;
|
||||
++emptyNums;
|
||||
if (emptyNums >= 3) {
|
||||
m_ipConflict = false;
|
||||
m_detectConflictTimer->stop();
|
||||
updateSelf();
|
||||
emptyNums = 0;
|
||||
m_conflictMap.clear();
|
||||
}
|
||||
m_ipConflict = false;
|
||||
m_ipConflictChecking = false;
|
||||
m_detectConflictTimer->stop();
|
||||
updateSelf();
|
||||
m_conflictMap.clear();
|
||||
removeCount = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 缓存冲突ip和mac地址
|
||||
m_conflictMap.insert(ip, mac);
|
||||
removeCount = 0;
|
||||
|
||||
if (m_conflictMap.size()) {
|
||||
if (m_conflictMap.size() && !m_ipConflict) {
|
||||
// 确认2次
|
||||
if (conflictCount++ < 2) {
|
||||
onDetectConflict();
|
||||
return;
|
||||
}
|
||||
|
||||
conflictCount = 0;
|
||||
m_ipConflict = true;
|
||||
updateSelf();
|
||||
|
||||
@ -648,23 +664,30 @@ void NetworkItem::ipConflict(const QString &ip, const QString &mac)
|
||||
void NetworkItem::onSendIpConflictDect(int index)
|
||||
{
|
||||
QTimer::singleShot(500, this, [ = ]() mutable {
|
||||
if (index - 1 > currentIpList().size())
|
||||
if (index - 1 > currentIpList().size()) {
|
||||
m_ipConflictChecking = false;
|
||||
return;
|
||||
}
|
||||
|
||||
m_networkInter->RequestIPConflictCheck(currentIpList().at(index), "");
|
||||
|
||||
++index;
|
||||
if (currentIpList().size() > index)
|
||||
if (currentIpList().size() > index) {
|
||||
emit sendIpConflictDect(index);
|
||||
} else {
|
||||
m_ipConflictChecking = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void NetworkItem::onDetectConflict()
|
||||
{
|
||||
// ip冲突时发起主动检测,如果解除则更新状态
|
||||
if (currentIpList().size() <= 0)
|
||||
if (currentIpList().size() <= 0 || m_ipConflictChecking) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_ipConflictChecking = true;
|
||||
onSendIpConflictDect();
|
||||
}
|
||||
|
||||
|
@ -141,6 +141,7 @@ private:
|
||||
QMap<QString, QString> m_conflictMap; // 缓存有线和无线冲突的ip列表
|
||||
QTimer *m_detectConflictTimer; // 定时器自检,当其他主机主动解除ip冲突,我方需要更新网络状态
|
||||
bool m_ipConflict; // ip冲突的标识
|
||||
bool m_ipConflictChecking; // 标记是否正在检测中
|
||||
};
|
||||
|
||||
#endif // NETWORKITEM_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user