From ad1ca9917e205b9f32b3b749547f04df0606a211 Mon Sep 17 00:00:00 2001 From: renpeijia Date: Wed, 17 Nov 2021 15:34:38 +0800 Subject: [PATCH 1/3] fix: solve the problem of thread blocking. bug link:http://172.17.50.104/biz/bug-view-90268.html http://172.17.50.104/biz/bug-view-86473.html http://172.17.50.104/biz/bug-view-81153.html --- .../kylinactiveconnectresource.cpp | 55 +++++++++++++------ .../kylinnetworkdeviceresource.cpp | 18 ++++-- .../kylinnetworkresourcemanager.cpp | 16 +++++- .../kylinnetworkresourcemanager.h | 4 ++ .../kywirelessconnectoperation.cpp | 6 +- .../kywirelessconnectoperation.h | 1 + .../dbus-interface/kywirelessnetresource.cpp | 43 ++++++++++----- .../dbus-interface/kywirelessnetresource.h | 5 +- src/frontend/list-items/lanlistitem.cpp | 2 + src/frontend/list-items/wlanlistitem.cpp | 3 + src/frontend/tab-pages/wlanpage.cpp | 23 ++++---- src/frontend/tools/switchbutton.cpp | 27 ++++++--- src/frontend/tools/switchbutton.h | 2 + src/main.cpp | 10 ++++ src/src.pro | 3 + src/threaddriver.h | 25 +++++++++ 16 files changed, 183 insertions(+), 60 deletions(-) create mode 100644 src/threaddriver.h diff --git a/src/backend/dbus-interface/kylinactiveconnectresource.cpp b/src/backend/dbus-interface/kylinactiveconnectresource.cpp index 39b9f2c2..2a3a6633 100644 --- a/src/backend/dbus-interface/kylinactiveconnectresource.cpp +++ b/src/backend/dbus-interface/kylinactiveconnectresource.cpp @@ -14,11 +14,11 @@ KyActiveConnectResourse::KyActiveConnectResourse(QObject *parent) : QObject(pare m_networkdevice = new KyNetworkDeviceResourse(); connect(m_networkResourceInstance, &KyNetworkResourceManager::activeConnectionRemove, - this, &KyActiveConnectResourse::activeConnectRemove); + this, &KyActiveConnectResourse::activeConnectRemove); connect(m_networkResourceInstance, &KyNetworkResourceManager::activeConnectStateChangeReason, - this, &KyActiveConnectResourse::stateChangeReason); + this, &KyActiveConnectResourse::stateChangeReason); connect(m_networkResourceInstance, &KyNetworkResourceManager::vpnActiveConnectStateChangeReason, - this, &KyActiveConnectResourse::vpnConnectChangeReason); + this, &KyActiveConnectResourse::vpnConnectChangeReason); } KyActiveConnectResourse::~KyActiveConnectResourse() @@ -74,6 +74,11 @@ KyConnectItem *KyActiveConnectResourse::getActiveConnectionByUuid(QString connec } QStringList interfaces = activeConnectPtr->devices(); + if (interfaces.isEmpty()) { + qWarning()<< LOG_FLAG << "get active connection device failed."; + return nullptr; + } + QString ifaceUni = interfaces.at(0); NetworkManager::Device:: Ptr devicePtr = m_networkResourceInstance->findDeviceUni(ifaceUni); @@ -159,7 +164,7 @@ void KyActiveConnectResourse::getActiveConnectionList(QString deviceName, activeConnectItem->m_ifaceName = deviceName; activeConnectItem->m_itemType = connectionType; activeConnectItemList << activeConnectItem; - activeConnectItem->dumpInfo(); + //activeConnectItem->dumpInfo(); } activeConnectPtr = nullptr; @@ -257,7 +262,10 @@ void KyActiveConnectResourse::getActiveConnectIpInfo( qWarning()<< "[KyActiveConnectResourse]" <<"it can not find connect "<< connectUuid; return; } + getActiveConnectIp(activeConnectPtr, ipv4Address, ipv6Address); + + return; } void KyActiveConnectResourse::getActiveConnectIp( @@ -301,15 +309,18 @@ void KyActiveConnectResourse::getActiveConnectDnsInfo( { NetworkManager::ActiveConnection::Ptr activeConnectPtr = m_networkResourceInstance->getActiveConnect(connectUuid); - if (activeConnectPtr.isNull()) { qWarning()<< "[KyActiveConnectResourse]" <<"it can not find connect "<< connectUuid; return; } + getActiveConnectDns(activeConnectPtr, ipv4Dns, ipv6Dns); + + return; } -void KyActiveConnectResourse::getActiveConnectDns(NetworkManager::ActiveConnection::Ptr activeConnectPtr, +void KyActiveConnectResourse::getActiveConnectDns( + NetworkManager::ActiveConnection::Ptr activeConnectPtr, QList &ipv4Dns, QList &ipv6Dns) { @@ -565,23 +576,28 @@ void KyActiveConnectResourse::getApActivateConnect(QList &apC QString KyActiveConnectResourse::getDeviceOfActivateConnect(QString conUuid) { - QString deviceName = ""; + QString deviceName = ""; - NetworkManager::ActiveConnection::Ptr activeConnectPtr = + NetworkManager::ActiveConnection::Ptr activeConnectPtr = m_networkResourceInstance->getActiveConnect(conUuid); - if (nullptr == activeConnectPtr) { - qWarning()<< "[KyActiveConnectResourse]" <<"it can not find connect "<< conUuid; - return deviceName; - } + if (nullptr == activeConnectPtr) { + qWarning()<< "[KyActiveConnectResourse]" <<"it can not find connect "<< conUuid; + return deviceName; + } - QStringList interfaces = activeConnectPtr->devices(); - QString ifaceUni = interfaces.at(0); - NetworkManager::Device:: Ptr devicePtr = + QStringList interfaces = activeConnectPtr->devices(); + if (interfaces.isEmpty()) { + qWarning()<< LOG_FLAG << "get device of active connection failed."; + return deviceName; + } + + QString ifaceUni = interfaces.at(0); + NetworkManager::Device:: Ptr devicePtr = m_networkResourceInstance->findDeviceUni(ifaceUni); - deviceName = devicePtr->interfaceName(); + deviceName = devicePtr->interfaceName(); - return deviceName; + return deviceName; } bool KyActiveConnectResourse::connectionIsVirtual(QString uuid) @@ -595,6 +611,11 @@ bool KyActiveConnectResourse::connectionIsVirtual(QString uuid) } QStringList interfaces = activeConnectPtr->devices(); + if (interfaces.isEmpty()) { + qWarning()<< LOG_FLAG << "active connection get device failed."; + return false; + } + QString ifaceUni = interfaces.at(0); NetworkManager::Device:: Ptr devicePtr = m_networkResourceInstance->findDeviceUni(ifaceUni); diff --git a/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp b/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp index debff1c9..4724ea56 100644 --- a/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp +++ b/src/backend/dbus-interface/kylinnetworkdeviceresource.cpp @@ -13,13 +13,19 @@ KyNetworkDeviceResourse::KyNetworkDeviceResourse(QObject *parent) : QObject(pare initDeviceMap(); - connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceAdd, this, &KyNetworkDeviceResourse::onDeviceAdd); - connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceRemove, this, &KyNetworkDeviceResourse::onDeviceRemove); - connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceUpdate, this, &KyNetworkDeviceResourse::onDeviceUpdate); + connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceAdd, + this, &KyNetworkDeviceResourse::onDeviceAdd, Qt::ConnectionType::DirectConnection); + connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceRemove, + this, &KyNetworkDeviceResourse::onDeviceRemove, Qt::ConnectionType::DirectConnection); + connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceUpdate, + this, &KyNetworkDeviceResourse::onDeviceUpdate, Qt::ConnectionType::DirectConnection); - connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceCarrierChanage, this, &KyNetworkDeviceResourse::carrierChanage); - connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceBitRateChanage, this, &KyNetworkDeviceResourse::deviceBitRateChanage); - connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceMacAddressChanaged, this, &KyNetworkDeviceResourse::deviceMacAddressChanaged); + connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceCarrierChanage, + this, &KyNetworkDeviceResourse::carrierChanage); + connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceBitRateChanage, + this, &KyNetworkDeviceResourse::deviceBitRateChanage); + connect(m_networkResourceInstance, &KyNetworkResourceManager::deviceMacAddressChanaged, + this, &KyNetworkDeviceResourse::deviceMacAddressChanaged); } diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp index d97b5a4e..3d98283b 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.cpp @@ -17,6 +17,8 @@ */ #include "kylinnetworkresourcemanager.h" +#include + #define SIGNAL_DELAY 80000 #define EMIT_DELAY 10000 @@ -41,6 +43,14 @@ void KyNetworkResourceManager::Release() } KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(parent) +{ + qRegisterMetaType("NetworkManager::ActiveConnection::State"); + qRegisterMetaType("NetworkManager::Connectivity"); + qRegisterMetaType("NetworkManager::ActiveConnection::Reason"); + qRegisterMetaType("NetworkManager::Device::Type"); +} + +void KyNetworkResourceManager::onInitNetwork() { insertActiveConnections(); insertConnections(); @@ -64,7 +74,7 @@ KyNetworkResourceManager::KyNetworkResourceManager(QObject *parent) : QObject(pa connect(NetworkManager::notifier(), &NetworkManager::Notifier::serviceDisappeared, this, &KyNetworkResourceManager::clearConnections); qDebug() <<"[KyNetworkResourceManager]" - << "active connections:" << m_activeConns.size() + << "active connections:" << m_activeConns.size() << "connections:" << m_connections.size() << "network device:" << m_devices.size(); } @@ -924,6 +934,10 @@ void KyNetworkResourceManager::removeConnection(QString const & uuid) } } +void KyNetworkResourceManager::setWirelessNetworkEnabled(bool enabled) +{ + NetworkManager::setWirelessEnabled(enabled); +} void KyNetworkResourceManager::connectionDump() { diff --git a/src/backend/dbus-interface/kylinnetworkresourcemanager.h b/src/backend/dbus-interface/kylinnetworkresourcemanager.h index f80dbbd0..efb0c12a 100644 --- a/src/backend/dbus-interface/kylinnetworkresourcemanager.h +++ b/src/backend/dbus-interface/kylinnetworkresourcemanager.h @@ -136,6 +136,10 @@ signals: void connectivityChanged(NetworkManager::Connectivity connectivity); +public slots: + void onInitNetwork(); + void setWirelessNetworkEnabled(bool enabled); + private slots: //connection void onConnectionUpdated(); diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.cpp b/src/backend/dbus-interface/kywirelessconnectoperation.cpp index 4edb0bec..28e37cd2 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.cpp +++ b/src/backend/dbus-interface/kywirelessconnectoperation.cpp @@ -103,6 +103,8 @@ KyWirelessConnectOperation::KyWirelessConnectOperation(QObject *parent) : KyConn { connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiEnabledChanged, this, &KyWirelessConnectOperation::wifiEnabledChanged); + connect(this, &KyWirelessConnectOperation::enabledWirelessNetwork, + m_networkResourceInstance, &KyNetworkResourceManager::setWirelessNetworkEnabled, Qt::ConnectionType::QueuedConnection); } KyWirelessConnectOperation::~KyWirelessConnectOperation() @@ -696,7 +698,9 @@ void KyWirelessConnectOperation::addAndActiveWirelessEnterPriseTtlsConnect(KyEap //无线网络开关设置 void KyWirelessConnectOperation::setWirelessEnabled(bool enabled) { - NetworkManager::setWirelessEnabled(enabled); + emit enabledWirelessNetwork(enabled); + + return; } bool KyWirelessConnectOperation::getWirelessEnabled() diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.h b/src/backend/dbus-interface/kywirelessconnectoperation.h index 1663fc2b..c45a6ba8 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.h +++ b/src/backend/dbus-interface/kywirelessconnectoperation.h @@ -129,6 +129,7 @@ private: signals: void wifiEnabledChanged(bool); + void enabledWirelessNetwork(bool enabled); void addAndActivateConnectionError(QString errorMessage); private: diff --git a/src/backend/dbus-interface/kywirelessnetresource.cpp b/src/backend/dbus-interface/kywirelessnetresource.cpp index 054eff90..63013f18 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.cpp +++ b/src/backend/dbus-interface/kywirelessnetresource.cpp @@ -18,27 +18,36 @@ static void wifiListSort(QList &list) KyWirelessNetResource::KyWirelessNetResource(QObject *parent) : QObject(parent) { - qDebug()<<"KyWirelessNetResource"; + qDebug()<< LOG_FLAG <<"KyWirelessNetResource"; + + qRegisterMetaType("KyWirelessNetItem&"); + m_networkResourceInstance = KyNetworkResourceManager::getInstance(); - m_connectResource = new KyConnectResourse(this); m_operation = new KyWirelessConnectOperation(this); + m_networkDevice = new KyNetworkDeviceResourse(this); kyWirelessNetItemListInit(); //TODO:connect device signal - connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkAdded, this, &KyWirelessNetResource::onWifiNetworkAdded); - connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkRemoved, this, &KyWirelessNetResource::onWifiNetworkRemoved); - connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkPropertyChange, this, &KyWirelessNetResource::onWifiNetworkPropertyChange); - connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkDeviceDisappear, this, &KyWirelessNetResource::onWifiNetworkDeviceDisappear); + connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkAdded, + this, &KyWirelessNetResource::onWifiNetworkAdded, Qt::ConnectionType::DirectConnection); + connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkRemoved, + this, &KyWirelessNetResource::onWifiNetworkRemoved, Qt::ConnectionType::DirectConnection); + connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkPropertyChange, + this, &KyWirelessNetResource::onWifiNetworkPropertyChange, Qt::ConnectionType::DirectConnection); + connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkDeviceDisappear, + this, &KyWirelessNetResource::onWifiNetworkDeviceDisappear, Qt::ConnectionType::DirectConnection); - connect(m_connectResource, &KyConnectResourse::connectionAdd, this, &KyWirelessNetResource::onConnectionAdd); - connect(m_connectResource, &KyConnectResourse::connectionRemove, this, &KyWirelessNetResource::onConnectionRemove); - connect(m_connectResource, &KyConnectResourse::connectionUpdate, this, &KyWirelessNetResource::onConnectionUpdate); - - connect(m_device, &KyNetworkDeviceResourse::deviceAdd, this, &KyWirelessNetResource::onDeviceAdd); - connect(m_device, &KyNetworkDeviceResourse::deviceRemove, this, &KyWirelessNetResource::onDeviceRemove); - connect(m_device, &KyNetworkDeviceResourse::deviceNameUpdate, this, &KyWirelessNetResource::onDeviceNameUpdate); + connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionAdd, + this, &KyWirelessNetResource::onConnectionAdd, Qt::ConnectionType::DirectConnection); + connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionRemove, + this, &KyWirelessNetResource::onConnectionRemove, Qt::ConnectionType::DirectConnection); + connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionUpdate, + this, &KyWirelessNetResource::onConnectionUpdate, Qt::ConnectionType::DirectConnection); + connect(m_networkDevice, &KyNetworkDeviceResourse::deviceAdd, this, &KyWirelessNetResource::onDeviceAdd); + connect(m_networkDevice, &KyNetworkDeviceResourse::deviceRemove, this, &KyWirelessNetResource::onDeviceRemove); + connect(m_networkDevice, &KyNetworkDeviceResourse::deviceNameUpdate, this, &KyWirelessNetResource::onDeviceNameUpdate); } KyWirelessNetResource::~KyWirelessNetResource() @@ -167,6 +176,10 @@ QString KyWirelessNetResource::getActiveConnectSsidByDevice(QString deviceName) } QStringList interfaces = activeConnectionPtr->devices(); + if(interfaces.isEmpty()) { + qWarning()<< LOG_FLAG <<"get active device failed."; + continue; + } QString ifaceUni = interfaces.at(0); NetworkManager::Device:: Ptr devicePtr = m_networkResourceInstance->findDeviceUni(ifaceUni); @@ -233,6 +246,10 @@ QString KyWirelessNetResource::getDeviceIFace(NetworkManager::ActiveConnection:: wirelessNetResourcessid = wireless_sett->ssid(); QStringList interfaces = actConn->devices(); + if (interfaces.isEmpty()) { + return ""; + } + QString ifaceUni = interfaces.at(0); NetworkManager::Device:: Ptr devicePtr = m_networkResourceInstance->findDeviceUni(ifaceUni); diff --git a/src/backend/dbus-interface/kywirelessnetresource.h b/src/backend/dbus-interface/kywirelessnetresource.h index d49c0dc2..c7ed1f0b 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.h +++ b/src/backend/dbus-interface/kywirelessnetresource.h @@ -21,7 +21,7 @@ public: //ui层调用接口 bool getWifiNetwork(const QString &devIfaceName, const QString &ssid, KyWirelessNetItem &wirelessNetResource); - bool getAllDeviceWifiNetwork(QMap > &map); + bool getAllDeviceWifiNetwork(QMap> &map); bool getDeviceWifiNetwork(QString devIfaceName, QList &wirelessNetResource); bool getEnterPriseInfoTls(QString &uuid, KyEapMethodTlsInfo &info); @@ -67,9 +67,8 @@ signals: private: KyNetworkResourceManager *m_networkResourceInstance = nullptr; - KyConnectResourse *m_connectResource = nullptr; KyWirelessConnectOperation *m_operation = nullptr; - KyNetworkDeviceResourse *m_device = nullptr; + KyNetworkDeviceResourse *m_networkDevice = nullptr; QMap > m_WifiNetworkList; }; diff --git a/src/frontend/list-items/lanlistitem.cpp b/src/frontend/list-items/lanlistitem.cpp index ebbea431..09e169bf 100644 --- a/src/frontend/list-items/lanlistitem.cpp +++ b/src/frontend/list-items/lanlistitem.cpp @@ -88,6 +88,7 @@ void LanListItem::onNetButtonClicked() m_connectOperation->activateWiredConnection(m_lanConnectItem.m_connectUuid, m_deviceName); qDebug() << LOG_FLAG << "it will activate connection" << m_lanConnectItem.m_connectName << ". it's device is" << m_deviceName; + m_netButton->startLoading(); } else { qDebug() << LOG_FLAG << m_deviceName << "is not carried, so can not activate connection"; this->showDesktopNotify(tr("Wired Device not carried")); @@ -131,6 +132,7 @@ void LanListItem::onMenuTriggered(QAction *action) m_connectOperation->deactivateWiredConnection(m_lanConnectItem.m_connectName, m_lanConnectItem.m_connectUuid); qDebug() << LOG_FLAG << "it will disconnect connection" << m_lanConnectItem.m_connectName << ". it's device is" << m_deviceName; + m_netButton->startLoading(); } return; } diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index f5a10bca..6f096146 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -374,6 +374,7 @@ void WlanListItem::onNetButtonClicked() m_wirelessConnectOperation->activeWirelessConnect(m_wlanDevice, m_wirelessNetItem.m_connectUuid); qDebug()<<"[WlanListItem] Has configuration, will be activated. ssid = " << m_wirelessNetItem.m_NetSsid << Q_FUNC_INFO << __LINE__; + m_netButton->startLoading(); return; } @@ -482,6 +483,7 @@ void WlanListItem::onConnectButtonClicked() m_wirelessConnectOperation->addAndActiveWirelessConnect(m_wlanDevice, settings, false); setExpanded(false); + m_netButton->startLoading(); return; } @@ -517,6 +519,7 @@ void WlanListItem::onMenuTriggered(QAction *action) m_wirelessConnectOperation->deActivateWirelessConnection(m_wlanDevice, m_wirelessNetItem.m_connectUuid); qDebug()<<"[WlanListItem] Clicked on connected wifi, it will be inactivated. ssid = " << m_wirelessNetItem.m_NetSsid << Q_FUNC_INFO << __LINE__; + m_netButton->startLoading(); } else if (action->text() == tr("Forget")) { m_wirelessConnectOperation->deleteWirelessConnect(m_wirelessNetItem.m_connectUuid); } diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index cb8c800f..a3ad8e6b 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -112,21 +112,22 @@ void WlanPage::onWlanSwithGsettingsChanged(const QString &key) */ void WlanPage::onWlanSwitchClicked() { - qDebug() <<"[WlanPage] On wlan switch button clicked! old state = " - << !m_netSwitch->getSwitchStatus() << Q_FUNC_INFO << __LINE__; - if (m_devList.isEmpty()) { - qDebug() << "[WlanPage] have no device to use " << Q_FUNC_INFO << __LINE__; showDesktopNotify(tr("No wireless network card detected")); //检测不到无线网卡不再触发click信号 m_netSwitch->setSwitchStatus(false); - //m_netSwitch->setEnabled(false); } else { bool switchEnable = m_netSwitch->getSwitchStatus(); if (m_wlanSwitchEnable != switchEnable) { qDebug()<< LOG_FLAG << "wlan switch state " << switchEnable; m_wirelessConnectOpreation->setWirelessEnabled(switchEnable); - //m_switchGsettings->set(WIRELESS_SWITCH, switchEnable); + if (!switchEnable) { + m_netSwitch->setEnabled(false); + m_activatedNetFrame->hide(); + m_activatedNetDivider->hide(); + m_inactivatedNetFrame->hide(); + m_deviceFrame->hide(); + } } } @@ -998,10 +999,10 @@ void WlanPage::onWifiEnabledChanged(bool isWifiOn) if (m_wlanSwitchEnable == isWifiOn) { return; } else { - //m_netSwitch->setSwitchStatus(isWifiOn); - //m_netSwitch->setEnabled(isWifiOn); + if (!m_netSwitch->getEnabled()) { + m_netSwitch->setEnabled(true); + } m_switchGsettings->set(WIRELESS_SWITCH, isWifiOn); -// emit this->wlanConnectChanged(); } return; @@ -1030,7 +1031,7 @@ void WlanPage::onRefreshIconTimer() if(!this->isVisible()) { return; } - qDebug() << "onRefreshIconTimer"; + //qDebug() << "onRefreshIconTimer"; if (m_expandedItem) { qDebug()<< LOG_FLAG << "Has expanded item and forbid refresh wifi strength" << Q_FUNC_INFO << __LINE__; @@ -1069,7 +1070,7 @@ void WlanPage::onRefreshIconTimer() continue; } - qDebug()<< LOG_FLAG << "row" << sortRow << "item ssid" << p_wlanItem->getSsid(); + //qDebug()<< LOG_FLAG << "row" << sortRow << "item ssid" << p_wlanItem->getSsid(); if (sortSsid == p_wlanItem->getSsid()) { // qDebug()<< LOG_FLAG << "sort wlan set signal strength." << Q_FUNC_INFO << __LINE__; p_wlanItem->setSignalStrength(sortItem.m_signalStrength); diff --git a/src/frontend/tools/switchbutton.cpp b/src/frontend/tools/switchbutton.cpp index 8a9881c1..7e54e475 100644 --- a/src/frontend/tools/switchbutton.cpp +++ b/src/frontend/tools/switchbutton.cpp @@ -34,7 +34,8 @@ SwitchButton::SwitchButton(QWidget *parent) : QWidget(parent) else { m_fCurrentValue = 4; } - connect(m_cTimer,SIGNAL(timeout()),this,SLOT(startAnimation())); + + connect(m_cTimer, SIGNAL(timeout()), this, SLOT(startAnimation())); } @@ -42,12 +43,15 @@ SwitchButton::SwitchButton(QWidget *parent) : QWidget(parent) void SwitchButton::setSwitchStatus(bool check) { if (!m_enabled) return; + if(check == true) { m_bIsOn = 1; } else { m_bIsOn = 0; } + emit this->switchStatusChanged(); + m_cTimer->start(); //开始播放动画 } @@ -61,9 +65,15 @@ bool SwitchButton::getSwitchStatus() void SwitchButton::setEnabled(bool enabled) { m_enabled = enabled; + update(); + + return; } - +bool SwitchButton::getEnabled() +{ + return m_enabled; +} /* 播放按钮开启关闭动画 */ void SwitchButton::startAnimation() { //滑动按钮动作播放 int pos = 4; @@ -74,7 +84,6 @@ void SwitchButton::startAnimation() { //滑动按钮动作播放 m_fCurrentValue = size - pos; m_cTimer->stop(); } - } else { m_fCurrentValue --; if(m_fCurrentValue <= pos) { //到达最小值,停止继续前进 @@ -88,14 +97,12 @@ void SwitchButton::startAnimation() { //滑动按钮动作播放 /* 按钮按下处理 */ void SwitchButton::mousePressEvent(QMouseEvent *event) { Q_UNUSED(event); -// if (!m_enabled) -// return QWidget::mousePressEvent(event); + if (m_enabled) { m_bIsOn = !m_bIsOn; + Q_EMIT clicked(m_bIsOn); } - Q_EMIT clicked(m_bIsOn); - return QWidget::mousePressEvent(event); } @@ -122,7 +129,11 @@ void SwitchButton::paintEvent(QPaintEvent *event) { } painter.restore(); painter.save(); - painter.setBrush(Qt::white); + if (!m_enabled) { + painter.setBrush(Qt::darkGray); + } else { + painter.setBrush(Qt::white); + } painter.drawEllipse(m_fCurrentValue,4, 16, 16); painter.restore(); } diff --git a/src/frontend/tools/switchbutton.h b/src/frontend/tools/switchbutton.h index 70ac2d33..1662c310 100644 --- a/src/frontend/tools/switchbutton.h +++ b/src/frontend/tools/switchbutton.h @@ -31,6 +31,7 @@ public: void setSwitchStatus(bool check); bool getSwitchStatus(); void setEnabled(bool enabled); + bool getEnabled(); private: int m_bIsOn = 1; @@ -45,6 +46,7 @@ private: Q_SIGNALS: void clicked(int check); void switchStatusChanged(); + private Q_SLOTS: void startAnimation(); diff --git a/src/main.cpp b/src/main.cpp index 6c34052a..40bfef2a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,8 @@ #include "xatom-helper.h" #endif +#include "threaddriver.h" + #define LOG_IDENT "ukui_kylin_nm" void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) @@ -97,6 +99,14 @@ int main(int argc, char *argv[]) QApplication::setQuitOnLastWindowClosed(false); + ThreadDriver networkManagerDiver; + QThread thread; + KyNetworkResourceManager *p_networkResource = KyNetworkResourceManager::getInstance(); + p_networkResource->moveToThread(&thread); + QObject::connect(&networkManagerDiver, SIGNAL(initSignal()), p_networkResource, SLOT(onInitNetwork())); + thread.start(); + networkManagerDiver.emitSignal(); + // Internationalization QString locale = QLocale::system().name(); QTranslator trans_global; diff --git a/src/src.pro b/src/src.pro index eb6419ed..109a25f4 100644 --- a/src/src.pro +++ b/src/src.pro @@ -66,3 +66,6 @@ unix { DISTFILES += \ org.ukui.kylin-nm.switch.gschema.xml + +HEADERS += \ + threaddriver.h diff --git a/src/threaddriver.h b/src/threaddriver.h new file mode 100644 index 00000000..0cc30ffd --- /dev/null +++ b/src/threaddriver.h @@ -0,0 +1,25 @@ +#ifndef THREADDRIVER_H +#define THREADDRIVER_H + + +#include +#include +#include +#include + +class ThreadDriver:public QObject +{ + Q_OBJECT +public: + ThreadDriver(QObject* parent=0):QObject(parent){} + +public slots: + void emitSignal() { + emit initSignal(); + } + +signals: + void initSignal(); +}; + +#endif // THREADDRIVER_H From 1e845d537d38bf51a6b2a0a0e2e0cd407c6f12f5 Mon Sep 17 00:00:00 2001 From: renpeijia Date: Fri, 19 Nov 2021 19:56:46 +0800 Subject: [PATCH 2/3] modify:change the trigger method of thread --- src/main.cpp | 6 +----- src/src.pro | 3 --- src/threaddriver.h | 25 ------------------------- 3 files changed, 1 insertion(+), 33 deletions(-) delete mode 100644 src/threaddriver.h diff --git a/src/main.cpp b/src/main.cpp index 40bfef2a..41a85703 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,8 +29,6 @@ #include "xatom-helper.h" #endif -#include "threaddriver.h" - #define LOG_IDENT "ukui_kylin_nm" void messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) @@ -99,13 +97,11 @@ int main(int argc, char *argv[]) QApplication::setQuitOnLastWindowClosed(false); - ThreadDriver networkManagerDiver; QThread thread; KyNetworkResourceManager *p_networkResource = KyNetworkResourceManager::getInstance(); p_networkResource->moveToThread(&thread); - QObject::connect(&networkManagerDiver, SIGNAL(initSignal()), p_networkResource, SLOT(onInitNetwork())); + QObject::connect(&thread, SIGNAL(started()), p_networkResource, SLOT(onInitNetwork())); thread.start(); - networkManagerDiver.emitSignal(); // Internationalization QString locale = QLocale::system().name(); diff --git a/src/src.pro b/src/src.pro index 109a25f4..eb6419ed 100644 --- a/src/src.pro +++ b/src/src.pro @@ -66,6 +66,3 @@ unix { DISTFILES += \ org.ukui.kylin-nm.switch.gschema.xml - -HEADERS += \ - threaddriver.h diff --git a/src/threaddriver.h b/src/threaddriver.h deleted file mode 100644 index 0cc30ffd..00000000 --- a/src/threaddriver.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef THREADDRIVER_H -#define THREADDRIVER_H - - -#include -#include -#include -#include - -class ThreadDriver:public QObject -{ - Q_OBJECT -public: - ThreadDriver(QObject* parent=0):QObject(parent){} - -public slots: - void emitSignal() { - emit initSignal(); - } - -signals: - void initSignal(); -}; - -#endif // THREADDRIVER_H From 67c7ce891a1b27d433a0efca8e255cd9c79531bd Mon Sep 17 00:00:00 2001 From: renpeijia Date: Thu, 25 Nov 2021 11:20:54 +0800 Subject: [PATCH 3/3] fix:resolve core, when click wireless connection. --- src/backend/dbus-interface/kylinconnectresource.cpp | 6 +++--- src/backend/dbus-interface/kywirelessnetresource.cpp | 6 +++--- src/frontend/tab-pages/lanpage.cpp | 12 ++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/backend/dbus-interface/kylinconnectresource.cpp b/src/backend/dbus-interface/kylinconnectresource.cpp index ae0f83ca..d2294b4a 100644 --- a/src/backend/dbus-interface/kylinconnectresource.cpp +++ b/src/backend/dbus-interface/kylinconnectresource.cpp @@ -83,7 +83,7 @@ KyConnectItem * KyConnectResourse::getConnectionItemByUuid(QString connectUuid) KyConnectItem *connectItem = getConnectionItem(connectPtr); if (nullptr != connectItem) { - connectItem->dumpInfo(); + //connectItem->dumpInfo(); return connectItem; } @@ -115,7 +115,7 @@ KyConnectItem * KyConnectResourse::getConnectionItemByUuid(QString connectUuid, KyConnectItem *connectItem = getConnectionItem(connectPtr); if (nullptr != connectItem) { - connectItem->dumpInfo(); + //connectItem->dumpInfo(); return connectItem; } @@ -169,7 +169,7 @@ void KyConnectResourse::getConnectionList(QString deviceName, if (nullptr != connectItem) { // connectItem->m_itemType = connectionType; connectItemList << connectItem; - connectItem->dumpInfo(); + //connectItem->dumpInfo(); } connectPtr = nullptr; diff --git a/src/backend/dbus-interface/kywirelessnetresource.cpp b/src/backend/dbus-interface/kywirelessnetresource.cpp index 672d36f2..3989f7f2 100644 --- a/src/backend/dbus-interface/kywirelessnetresource.cpp +++ b/src/backend/dbus-interface/kywirelessnetresource.cpp @@ -39,11 +39,11 @@ KyWirelessNetResource::KyWirelessNetResource(QObject *parent) this, &KyWirelessNetResource::onWifiNetworkDeviceDisappear, Qt::ConnectionType::DirectConnection); connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionAdd, - this, &KyWirelessNetResource::onConnectionAdd, Qt::ConnectionType::DirectConnection); + this, &KyWirelessNetResource::onConnectionAdd); connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionRemove, - this, &KyWirelessNetResource::onConnectionRemove, Qt::ConnectionType::DirectConnection); + this, &KyWirelessNetResource::onConnectionRemove); connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionUpdate, - this, &KyWirelessNetResource::onConnectionUpdate, Qt::ConnectionType::DirectConnection); + this, &KyWirelessNetResource::onConnectionUpdate); connect(m_networkDevice, &KyNetworkDeviceResourse::deviceAdd, this, &KyWirelessNetResource::onDeviceAdd); connect(m_networkDevice, &KyNetworkDeviceResourse::deviceRemove, this, &KyWirelessNetResource::onDeviceRemove); diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index 8f308ad6..801602e3 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -381,6 +381,9 @@ void LanPage::constructConnectionArea() KyConnectItem *p_deactiveConnectionItem = deactivedList.at(index); qDebug()<<"[LanPage] construct connection area add deactive item"<m_connectName; QListWidgetItem *p_listWidgetItem = addNewItem(p_deactiveConnectionItem, m_inactivatedLanListWidget); + if (m_inactiveConnectionMap.contains(p_deactiveConnectionItem->m_connectUuid)) { + qDebug()<m_connectUuid; + } m_inactiveConnectionMap.insert(p_deactiveConnectionItem->m_connectUuid, p_listWidgetItem); delete p_deactiveConnectionItem; @@ -471,6 +474,9 @@ void LanPage::onAddConnection(QString uuid) //新增一个有线 if (p_newItem->m_ifaceName == m_currentDeviceName || p_newItem->m_ifaceName == "") { qDebug()<<"[LanPage] Add a new connection, name:"<m_connectName; QListWidgetItem *p_listWidgetItem = insertNewItem(p_newItem, m_inactivatedLanListWidget); + if (m_inactiveConnectionMap.contains(p_newItem->m_connectUuid)) { + qDebug()<m_connectUuid; + } m_inactiveConnectionMap.insert(p_newItem->m_connectUuid, p_listWidgetItem); } @@ -965,6 +971,9 @@ void LanPage::updateConnectionProperty(KyConnectItem *p_connectItem) //只要名字改变就要删除,重新插入,主要是为了排序 deleteConnectionMapItem(m_inactiveConnectionMap, m_inactivatedLanListWidget, newUuid); QListWidgetItem *p_sortListWidgetItem = insertNewItem(p_connectItem, m_inactivatedLanListWidget); + if (m_inactiveConnectionMap.contains(newUuid)) { + qDebug()<m_connectPath != p_lanItem->getConnectionPath()) { p_lanItem->updateConnectionPath(p_connectItem->m_connectPath); @@ -975,6 +984,9 @@ void LanPage::updateConnectionProperty(KyConnectItem *p_connectItem) if (p_connectItem->m_ifaceName == m_currentDeviceName || p_connectItem->m_ifaceName.isEmpty()) { QListWidgetItem *p_listWidgetItem = insertNewItem(p_connectItem, m_inactivatedLanListWidget); + if (m_inactiveConnectionMap.contains(newUuid)) { + qDebug()<