hotpot connect && disconnect signal

This commit is contained in:
jzxc95 2021-09-01 17:59:50 +08:00
parent 22bf3af64b
commit 6b972e007d
7 changed files with 90 additions and 8 deletions

View File

@ -670,10 +670,10 @@ NetworkManager::ConnectionSettings::Ptr
NetworkManager::WirelessSecuritySetting::Ptr wirelessSecuritySetting
= connectionSettings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
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<NetworkManager::Ipv6Setting>();
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"<<apUuid;
connectPath = connectPtr->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()<<errorMessage;
emit this->activateConnectionError(errorMessage);
} else {
qWarning()<<"active wired connect complete.";
}
watcher->deleteLater();
});
return ;
}

View File

@ -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;

View File

@ -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

View File

@ -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);
}
/**

View File

@ -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:

View File

@ -358,6 +358,34 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec
emit listUpdate(devName);
}
if (state == NetworkManager::ActiveConnection::State::Deactivated) {
QList<KyApConnectItem *> 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<KyApConnectItem *> 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");
}
}

View File

@ -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);