From 6b972e007dcf6f222d62ea1fa6352895b894934e Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Wed, 1 Sep 2021 17:59:50 +0800 Subject: [PATCH] hotpot connect && disconnect signal --- .../kywirelessconnectoperation.cpp | 53 ++++++++++++++++--- .../kywirelessconnectoperation.h | 1 + src/backend/dbusadaptor.h | 4 ++ src/frontend/new-mainwindow.cpp | 5 +- src/frontend/new-mainwindow.h | 4 +- src/frontend/tab-pages/wlanpage.cpp | 29 ++++++++++ src/frontend/tab-pages/wlanpage.h | 2 + 7 files changed, 90 insertions(+), 8 deletions(-) diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.cpp b/src/backend/dbus-interface/kywirelessconnectoperation.cpp index e3aa158c..eca4d5d7 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.cpp +++ b/src/backend/dbus-interface/kywirelessconnectoperation.cpp @@ -670,10 +670,10 @@ NetworkManager::ConnectionSettings::Ptr NetworkManager::WirelessSecuritySetting::Ptr wirelessSecuritySetting = connectionSettings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast(); - wirelessSecuritySetting->setInitialized(true); if (apPassword.isEmpty()) { - wirelessSecuritySetting->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaNone); + wirelessSecuritySetting->setInitialized(false); } else { + wirelessSecuritySetting->setInitialized(true); wirelessSecuritySetting->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk); wirelessSecuritySetting->setPsk(apPassword); } @@ -715,7 +715,7 @@ void KyWirelessConnectOperation::activeWirelessAp(const QString apUuid, const QS if (nullptr == connectPtr) { NetworkManager::Device::Ptr devicePtr = m_networkResourceInstance->findDeviceInterface(apDevice); if (devicePtr.isNull()) { - QString errorMsg ="active wifi ap failed," + apDevice + "is not existed"; + QString errorMsg ="Create hotpot faild. " + apDevice + " is not existed"; qWarning()<< errorMsg; emit addAndActivateConnectionError(errorMsg); return; @@ -730,15 +730,15 @@ void KyWirelessConnectOperation::activeWirelessAp(const QString apUuid, const QS watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(apConnectSettingPtr->toMap(), deviceIdentifier, specificObject), this}; connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) { if (watcher->isError() || !watcher->isValid()) { - QString errorMsg = "activation connection failed," + watcher->error().message(); + QString errorMsg = "Create hotpot faild. " + watcher->error().message(); qWarning() << errorMsg; emit addAndActivateConnectionError(errorMsg); } watcher->deleteLater(); }); } else { - updateWirelessApSetting(connectPtr, apName, apPassword, apDevice); - activateConnection(apUuid, apDevice); +// updateWirelessApSetting(connectPtr, apName, apPassword, apDevice); + activateApConnectionByUuid(apUuid, apDevice, connectPtr); } return; @@ -823,3 +823,44 @@ void KyWirelessConnectOperation::setIpv4AndIpv6Setting(NetworkManager::Connectio NetworkManager::Ipv6Setting::Ptr ipv6Setting = connSetting->setting(NetworkManager::Setting::Ipv6).dynamicCast(); ipv6SettingSet(ipv6Setting, connSettingInfo); } + +void KyWirelessConnectOperation::activateApConnectionByUuid(const QString apUuid, const QString apDevice, NetworkManager::Connection::Ptr connectPtr) +{ + QString connectPath = ""; + QString deviceIdentifier = ""; + QString connectName = ""; + QString specificObject = ""; + + qDebug()<<"it will activate hotpot connect"<path(); + connectName = connectPtr->name(); + + auto dev = m_networkResourceInstance->findDeviceInterface(apDevice); + if (!dev.isNull()) { + deviceIdentifier = dev->uni(); + } + + if (deviceIdentifier.isEmpty()) { + QString errorMessage = tr("Create hotpot faild.Device Identifier is empty, its name") + apDevice; + qWarning() << errorMessage; + Q_EMIT activateConnectionError(errorMessage); + return ; + } + + QDBusPendingCallWatcher * watcher; + watcher = new QDBusPendingCallWatcher{NetworkManager::activateConnection(connectPath, deviceIdentifier, specificObject), this}; + connect(watcher, &QDBusPendingCallWatcher::finished, [this, connectName, apDevice] (QDBusPendingCallWatcher * watcher) { + if (watcher->isError() || !watcher->isValid()) { + QString errorMessage = tr("Create hotpot faild. ") + watcher->error().message(); + qWarning()<activateConnectionError(errorMessage); + } else { + qWarning()<<"active wired connect complete."; + } + + watcher->deleteLater(); + }); + + return ; +} diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.h b/src/backend/dbus-interface/kywirelessconnectoperation.h index 432c6c73..82b98aee 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.h +++ b/src/backend/dbus-interface/kywirelessconnectoperation.h @@ -124,6 +124,7 @@ private: void updateWirelessSecu(NetworkManager::ConnectionSettings::Ptr connSettingPtr, const KyWirelessConnectSetting &connSettingInfo, bool bPwdChange = false); void setIpv4AndIpv6Setting(NetworkManager::ConnectionSettings::Ptr connSetting, const KyConnectSetting &connSettingInfo); void setWirelessSecuWpaXEap(NetworkManager::ConnectionSettings::Ptr connSettingPtr); + void activateApConnectionByUuid(const QString apUuid, const QString apDevice, NetworkManager::Connection::Ptr connectPtr); KyNetworkResourceManager *m_networkResourceInstance = nullptr; diff --git a/src/backend/dbusadaptor.h b/src/backend/dbusadaptor.h index 497eeb38..14b6cda1 100644 --- a/src/backend/dbusadaptor.h +++ b/src/backend/dbusadaptor.h @@ -94,6 +94,10 @@ Q_SIGNALS: // SIGNALS //设备插拔 void deviceStatusChanged(); void deviceNameChanged(QString oldName, QString newName); + //热点断开 + void hotPotDeactivated(QString devName, QString ssid); + //热点连接 + void hotPotActivated(QString devName, QString ssid); }; #endif diff --git a/src/frontend/new-mainwindow.cpp b/src/frontend/new-mainwindow.cpp index 36b70721..fb3a9b3a 100644 --- a/src/frontend/new-mainwindow.cpp +++ b/src/frontend/new-mainwindow.cpp @@ -146,13 +146,16 @@ void MainWindow::initDbusConnnect() connect(m_wlanWidget, &WlanPage::deviceNameChanged, this, &MainWindow::deviceNameChanged); connect(m_wlanWidget, &WlanPage::activateFailed, this, &MainWindow::activateFailed); - connect(m_wlanWidget, &WlanPage::deactivateFailed, this, &MainWindow::activateFailed); + connect(m_wlanWidget, &WlanPage::deactivateFailed, this, &MainWindow::deactivateFailed); connect(m_lanWidget, &LanPage::listUpdate, this, &MainWindow::listUpdate); connect(m_wlanWidget, &WlanPage::listUpdate, this, &MainWindow::listUpdate); connect(m_lanWidget, &LanPage::wiredActivating, this, &MainWindow::wiredActivating); connect(m_wlanWidget, &WlanPage::wirelessActivating, this, &MainWindow::wirelessActivating); + + connect(m_wlanWidget, &WlanPage::hotPotDeactivated, this, &MainWindow::hotPotDeactivated); + connect(m_wlanWidget, &WlanPage::hotPotActivated, this, &MainWindow::hotPotActivated); } /** diff --git a/src/frontend/new-mainwindow.h b/src/frontend/new-mainwindow.h index 7dd9dbbf..66ac6ac4 100644 --- a/src/frontend/new-mainwindow.h +++ b/src/frontend/new-mainwindow.h @@ -49,7 +49,9 @@ signals: void wirelessActivating(QString devName, QString ssid); void activateFailed(QString errorMessage); void deactivateFailed(QString errorMessage); - + //热点断开 + void hotPotDeactivated(QString devName, QString ssid); + void hotPotActivated(QString devName, QString ssid); public slots: protected: diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index fb1dd5b0..07c29100 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -358,6 +358,34 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec emit listUpdate(devName); } + if (state == NetworkManager::ActiveConnection::State::Deactivated) { + QList apConnectItemList; + m_apConnectResource->getApConnections(apConnectItemList); + if (!apConnectItemList.isEmpty()) { + foreach (auto item, apConnectItemList) { + if (item->m_connectUuid == uuid) { + qDebug() << "[WlanPage] hotpot Deactivated"; + emit hotPotDeactivated(item->m_ifaceName, ssid); + break; + } + } + } + } + + if (state == NetworkManager::ActiveConnection::State::Activated) { + QList apConnectItemList; + m_apConnectResource->getApConnections(apConnectItemList); + if (!apConnectItemList.isEmpty()) { + foreach (auto item, apConnectItemList) { + if (item->m_connectUuid == uuid) { + qDebug() << "[WlanPage] hotpot Deactivated"; + emit hotPotActivated(item->m_ifaceName, ssid); + break; + } + } + } + } + if (state == NetworkManager::ActiveConnection::State::Activated) { //onWlanRemoved(m_wlanDevice, ssid); m_activatedNetListWidget->clear(); @@ -472,6 +500,7 @@ void WlanPage::deactiveWirelessAp(const QString apName, const QString apPassword m_wirelessConnectOpreation->deactiveWirelessAp(apName, uuid); } else { qDebug() << "[WlanPage] deactiveWirelessAp can not find apName " << apName; + emit deactivateFailed("invalid info"); } } diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index 42809cf3..138f349b 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -31,6 +31,8 @@ public: signals: void oneItemExpanded(const QString &ssid); void wirelessActivating(QString devName, QString ssid); + void hotPotDeactivated(QString devName, QString ssid); + void hotPotActivated(QString devName, QString ssid); protected: bool eventFilter(QObject *watched, QEvent *event);