From d1d8c7781e1463b015bce737b4e1aa072df485b7 Mon Sep 17 00:00:00 2001 From: jzxc95 <907297917@qq.com> Date: Fri, 3 Sep 2021 15:48:19 +0800 Subject: [PATCH] delay connect hotspot --- .../dbus-interface/kywirelessconnectoperation.cpp | 14 ++++++++++++-- .../dbus-interface/kywirelessconnectoperation.h | 3 ++- src/backend/dbusadaptor.cpp | 15 +++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.cpp b/src/backend/dbus-interface/kywirelessconnectoperation.cpp index 2d136490..cd973a60 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.cpp +++ b/src/backend/dbus-interface/kywirelessconnectoperation.cpp @@ -741,7 +741,9 @@ void KyWirelessConnectOperation::activeWirelessAp(const QString apUuid, const QS }); } else { updateWirelessApSetting(connectPtr, apName, apPassword, apDevice); - activateApConnectionByUuid(apUuid, apDevice, connectPtr); + QTimer::singleShot(500, this, [=](){ + activateApConnectionByUuid(apUuid, apDevice); + }); } return; @@ -827,7 +829,7 @@ void KyWirelessConnectOperation::setIpv4AndIpv6Setting(NetworkManager::Connectio ipv6SettingSet(ipv6Setting, connSettingInfo); } -void KyWirelessConnectOperation::activateApConnectionByUuid(const QString apUuid, const QString apDevice, NetworkManager::Connection::Ptr connectPtr) +void KyWirelessConnectOperation::activateApConnectionByUuid(const QString apUuid, const QString apDevice) { QString connectPath = ""; QString deviceIdentifier = ""; @@ -836,6 +838,14 @@ void KyWirelessConnectOperation::activateApConnectionByUuid(const QString apUuid qDebug()<<"it will activate hotspot connect"<getConnect(apUuid); + if (connectPtr.isNull()) + { + QString errorMessage = tr("Create hotspot faild.UUID is empty, its name") + apUuid; + qWarning() << errorMessage; + Q_EMIT activateConnectionError(errorMessage); + return; + } connectPath = connectPtr->path(); connectName = connectPtr->name(); diff --git a/src/backend/dbus-interface/kywirelessconnectoperation.h b/src/backend/dbus-interface/kywirelessconnectoperation.h index 82b98aee..df3c1f3a 100644 --- a/src/backend/dbus-interface/kywirelessconnectoperation.h +++ b/src/backend/dbus-interface/kywirelessconnectoperation.h @@ -3,6 +3,7 @@ #include #include +#include #include "kyenterpricesettinginfo.h" #include "kylinconnectoperation.h" #include "kyenterpricesettinginfo.h" @@ -124,7 +125,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); + void activateApConnectionByUuid(const QString apUuid, const QString apDevice); KyNetworkResourceManager *m_networkResourceInstance = nullptr; diff --git a/src/backend/dbusadaptor.cpp b/src/backend/dbusadaptor.cpp index 75d2fed3..2821f506 100644 --- a/src/backend/dbusadaptor.cpp +++ b/src/backend/dbusadaptor.cpp @@ -21,11 +21,6 @@ const QByteArray GSETTINGS_SCHEMA_KYLIN_NM = "org.ukui.kylin-nm.switch"; const QString KEY_WIRELESS_SWITCH = "wirelessswitch"; const QString KEY_WIRED_SWITCH = "wiredswitch"; -enum KyDeviceType{ - WIRED = 0, - WIRELESS, -}; - void saveDeviceEnableState(QString deviceName, bool enable) { QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); @@ -44,7 +39,7 @@ void getDeviceEnableState(int type, QMap &map) if (!QFile::exists(CONFIG_FILE_PATH)) { return; } - if (type != 0 && type != 1) { + if (type != WIRED && type != WIRELESS) { qDebug() << "getDeviceEnableState but wrong type"; return; } @@ -57,7 +52,7 @@ void getDeviceEnableState(int type, QMap &map) QSettings * m_settings = new QSettings(CONFIG_FILE_PATH, QSettings::IniFormat); m_settings->beginGroup("CARDEABLE"); - if (type == 0) { + if (type == WIRED) { kdr->getNetworkDeviceList(NetworkManager::Device::Type::Ethernet, wiredDevList); if (!wiredDevList.isEmpty()) { for (int i = 0; i < wiredDevList.size(); ++i) { @@ -65,7 +60,7 @@ void getDeviceEnableState(int type, QMap &map) map.insert(wiredDevList.at(i), enable); } } - } else if (type == 1) { + } else if (type == WIRELESS) { kdr->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, wirelessDevList); if (!wirelessDevList.isEmpty()) { for (int i = 0; i < wirelessDevList.size(); ++i) { @@ -247,9 +242,9 @@ QString DbusAdaptor::getDefaultWirelessDevice() //连接 根据网卡类型 参数1 0:lan 1:wlan 参数3 为ssid/uuid void DbusAdaptor::activateConnect(int type, QString devName, QString ssid) { - if (type == 0) { + if (type == WIRED) { parent()->activateWired(devName,ssid); - } else if (type == 1) { + } else if (type == WIRELESS) { parent()->activateWireless(devName,ssid); } else { qDebug() << "[DbusAdaptor] activateConnect type is invalid";