This commit is contained in:
king 2021-11-02 13:53:54 +08:00
parent 4b653b389c
commit 9d7f4fb70f
4 changed files with 81 additions and 15 deletions

View File

@ -582,3 +582,72 @@ QString KyActiveConnectResourse::getDeviceOfActivateConnect(QString conUuid)
return deviceName;
}
bool KyActiveConnectResourse::wiredConnectIsActived()
{
int index = 0;
NetworkManager::ActiveConnection::List activeConnectList;
activeConnectList.clear();
activeConnectList = m_networkResourceInstance->getActiveConnectList();
if (activeConnectList.empty()) {
qWarning()<<"[KyActiveConnectResourse]"
<<"get active connect failed, the active connect list is empty";
return false;
}
NetworkManager::ActiveConnection::Ptr activeConnectPtr = nullptr;
for (index = 0; index < activeConnectList.size(); index++) {
activeConnectPtr = activeConnectList.at(index);
if (activeConnectPtr.isNull()) {
continue;
}
if (NetworkManager::ConnectionSettings::ConnectionType::Wired
!= activeConnectPtr->type()) {
continue;
}
if (activeConnectPtr->state() == NetworkManager::ActiveConnection::State::Activated) {
return true;
}
}
return false;
}
bool KyActiveConnectResourse::wirelessConnectIsActived()
{
int index = 0;
NetworkManager::ActiveConnection::List activeConnectList;
activeConnectList.clear();
activeConnectList = m_networkResourceInstance->getActiveConnectList();
if (activeConnectList.empty()) {
qWarning()<<"[KyActiveConnectResourse]"
<<"get active connect failed, the active connect list is empty";
return false;
}
NetworkManager::ActiveConnection::Ptr activeConnectPtr = nullptr;
for (index = 0; index < activeConnectList.size(); index++) {
activeConnectPtr = activeConnectList.at(index);
if (activeConnectPtr.isNull()) {
continue;
}
if (NetworkManager::ConnectionSettings::ConnectionType::Wireless
!= activeConnectPtr->type()) {
continue;
}
if (activeConnectPtr->state() == NetworkManager::ActiveConnection::State::Activated) {
return true;
}
}
return false;
}

View File

@ -39,6 +39,9 @@ public:
QString getDeviceOfActivateConnect(QString conUuid);
bool wiredConnectIsActived();
bool wirelessConnectIsActived();
private:
void getActiveConnectIp(NetworkManager::ActiveConnection::Ptr activeConnectPtr,
QString &ipv4Address,

View File

@ -820,6 +820,7 @@ void LanPage::onConnectionStateChange(QString uuid,
NetworkManager::ActiveConnection::State state,
NetworkManager::ActiveConnection::Reason reason)
{
emit this->lanConnectChanged(state);
//lanpage函数内持续监听连接状态的变化并记录供其他函数调用获取状态
if (!m_connectResourse->isWiredConnection(uuid)) {
qDebug() << "[LanPage] connection state change signal but not wired";
@ -868,8 +869,6 @@ void LanPage::onConnectionStateChange(QString uuid,
p_newItem = nullptr;
}
emit this->lanConnectChanged(state);
return;
}
@ -1123,14 +1122,9 @@ void LanPage::showDetailPage(QString devName, QString uuid)
bool LanPage::lanIsConnected()
{
if (m_activeConnectionMap.isEmpty()) {
return false;
} else {
QString connectionUuid= m_activeConnectionMap.firstKey();
if (connectionUuid == EMPTY_CONNECT_UUID) {
return false;
}
}
if (m_activeResourse->wiredConnectIsActived()) {
return true;
} else {
return false;
}
}

View File

@ -829,6 +829,8 @@ void WlanPage::onConnectionStateChanged(QString uuid,
NetworkManager::ActiveConnection::State state,
NetworkManager::ActiveConnection::Reason reason)
{
emit this->wlanConnectChanged(state);
QString devName, ssid;
m_wirelessNetResource->getSsidByUuid(uuid, ssid);
m_wirelessNetResource->getDeviceByUuid(uuid, devName);
@ -882,7 +884,6 @@ void WlanPage::onConnectionStateChanged(QString uuid,
updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Activating);
}
}
emit this->wlanConnectChanged(state);
return;
}
@ -1267,12 +1268,11 @@ void WlanPage::showDetailPage(QString devName, QString ssid)
bool WlanPage::wlanIsConnected()
{
if (m_activateConnectionItemMap.isEmpty()) {
return false;
} else if (m_activateConnectionItemMap.contains(EMPTY_SSID)) {
if (m_activatedConnectResource->wirelessConnectIsActived()) {
return true;
} else {
return false;
}
return true;
}
void WlanPage::setWirelessSwitchEnable(bool enable)