From c66e13275bffb47b9acb65034598cd61e6eee89f Mon Sep 17 00:00:00 2001 From: chenlelin Date: Wed, 2 Jun 2021 11:36:53 +0800 Subject: [PATCH] Fix bug can not trigger wifi scan after turn on wifi switch --- debian/changelog | 2 +- src/ksimplenm.cpp | 2 - src/kylin-dbus-interface.cpp | 8 +++- src/main.cpp | 2 +- src/mainwindow.cpp | 87 +++++++++++++++++++++--------------- src/mainwindow.h | 7 ++- 6 files changed, 65 insertions(+), 43 deletions(-) diff --git a/debian/changelog b/debian/changelog index 090c83e9..37c14d37 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -kylin-nm (3.0.1-1kylin47) v101; urgency=medium +kylin-nm (3.0.1-1kylin47hw1) v101.hw; urgency=medium * BUG号:#57475 #56581 * 需求号:无 diff --git a/src/ksimplenm.cpp b/src/ksimplenm.cpp index 21760911..8ea46820 100644 --- a/src/ksimplenm.cpp +++ b/src/ksimplenm.cpp @@ -83,7 +83,6 @@ void KSimpleNM::execGetWifiList(const QString& wname, const bool &isHuaweiPc) return; } isExecutingGetWifiList = true; - qDebug()<< __FUNCTION__<<__LINE__; shellOutputWifi = ""; QString cmd; //将ssid放置在最后一列以防ssid存在中文或特殊字符导致其后面的列不对齐 @@ -137,7 +136,6 @@ void KSimpleNM::finishedProcessWifi(int msg) QStringList slist = shellOutputWifi.split("\n"); emit getWifiListFinished(slist); isExecutingGetWifiList = false; - qDebug()<< __FUNCTION__<<__LINE__; } void KSimpleNM::finishedProcessConn(int msg) { diff --git a/src/kylin-dbus-interface.cpp b/src/kylin-dbus-interface.cpp index 4068ed45..c5ecad62 100644 --- a/src/kylin-dbus-interface.cpp +++ b/src/kylin-dbus-interface.cpp @@ -1720,7 +1720,11 @@ void KylinDBus::onAutoConnect() { //syslog(LOG_DEBUG, "Receive a auto-connect signal to reconnect wifi"); qDebug() << Q_FUNC_INFO << "Receive a auto-connect signal to reconnect wifi"; - mw->toReconnectWifi(); + if (!mw->isRadioWifiTurningOn) { + mw->toReconnectWifi(); + } else { + qDebug() << Q_FUNC_INFO << "but need waiting turn on wifi switch, will not reconnect wifi"; + } } //有线网属性变化时,执行该函数。由于可能在短时间收到几条相同属性变化信息,所以在短时间内,执行一次 @@ -1960,7 +1964,7 @@ void KylinDBus::requestScanWifi() QDBusConnection::systemBus() ); QMap my_map; my_map = {}; - interface.call("RequestScan", my_map); //get accesspoint for each wifi + interface.call("RequestScan", my_map); } //显示桌面通知 diff --git a/src/main.cpp b/src/main.cpp index 0900d16e..7253bd90 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QApplication a(argc, argv); - qInstallMessageHandler(messageOutput); + //qInstallMessageHandler(messageOutput); openlog(LOG_IDENT, LOG_NDELAY | LOG_NOWAIT | LOG_PID, LOG_USER); qDebug()<<"Kylin Network Manager Is Already Launched"; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 356b1da1..37e1abfa 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -561,6 +561,7 @@ void MainWindow::initTimer() numberForWifiScan = 0; QObject::connect(this, SIGNAL(loadWifiListAfterScan()), this, SLOT(onLoadWifiListAfterScan())); QObject::connect(this, SIGNAL(refreshWifiListAfterScan()), this, SLOT(onRefreshWifiListAfterScan())); + QObject::connect(this, SIGNAL(requestReconnecWifi()), this, SLOT(onRequestReconnecWifi())); checkWifiListChanged = new QTimer(this); checkWifiListChanged->setTimerType(Qt::PreciseTimer); QObject::connect(checkWifiListChanged, SIGNAL(timeout()), this, SLOT(onRequestScanAccesspoint())); @@ -1206,6 +1207,7 @@ void MainWindow::onBtnWifiClicked(int flag) if (is_fly_mode_on == 0) { //on_btnWifiList_clicked(); is_stop_check_net_state = 1; + isRadioWifiTurningOn = true; objKyDBus->setWifiCardState(true); objKyDBus->setWifiSwitchState(true); @@ -1225,6 +1227,7 @@ void MainWindow::onBtnWifiClicked(int flag) if (is_fly_mode_on == 0) { //on_btnWifiList_clicked(); is_stop_check_net_state = 1; + isRadioWifiTurningOn = true; lbTopWifiList->show(); btnAddNet->show(); @@ -1336,7 +1339,6 @@ void MainWindow::on_btnWifiList_clicked() { is_stop_check_net_state = 1; current_wifi_list_state = LOAD_WIFI_LIST; - qDebug()<<__FUNCTION__<< __LINE__<is_btnWifiList_clicked = 1; this->is_btnLanList_clicked = 0; end_rcv_rates = 0; @@ -1372,12 +1374,14 @@ void MainWindow::on_btnWifiList_clicked() btnWireless->setSwitchStatus(true); lbTopWifiList->show(); btnAddNet->show(); - this->startLoading(); if (isHuaWeiPC) { - QtConcurrent::run([=](){ + QtConcurrent::run([=]() { + isScaningWifi = true; objKyDBus->requestScanWifi(); //要求后台扫描AP sleep(2); + isScaningWifi = false; + qDebug() << "scan finished, will load wifi list"; emit loadWifiListAfterScan(); }); } else { @@ -1442,8 +1446,8 @@ void MainWindow::on_btnWifiList_clicked() void MainWindow::onLoadWifiListAfterScan() { current_wifi_list_state = LOAD_WIFI_LIST; - qDebug()<<__FUNCTION__<< __LINE__<ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); //加载wifi列表 + objKyDBus->getWirelessCardName(); } void MainWindow::on_wifi_changed() @@ -1746,7 +1750,6 @@ void MainWindow::onRequestRevalueUpdateWifi() { is_stop_check_net_state = 1; current_wifi_list_state = LOAD_WIFI_LIST; - qDebug()<<__FUNCTION__<< __LINE__< targetWifiStructList = connectableWifiPriorityList(slist); if (!targetWifiStructList.isEmpty()) { - qDebug()<< __FUNCTION__<<__LINE__<<"current_wifi_list_state="<ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); + if (isHuaWeiPC) { +// QtConcurrent::run([=]() { +// if (is_btnWifiList_clicked) { +// sleep(4); +// objKyDBus->requestScanWifi(); //要求后台扫描AP +// emit loadWifiListAfterScan(); +// } +// }); + + QtConcurrent::run([=]() { + sleep(1); + isRadioWifiTurningOn = false; + qDebug()<<"debug: already turn on the switch of wifi network"; + //syslog(LOG_DEBUG, "Already turn on the switch of wifi network"); + }); } else { //on_btnWifiList_clicked(); + current_wifi_list_state = LOAD_WIFI_LIST; + if (is_btnWifiList_clicked) { + this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); + } + objKyDBus->getWirelessCardName(); + qDebug()<<"debug: already turn on the switch of wifi network"; + //syslog(LOG_DEBUG, "Already turn on the switch of wifi network"); } - - objKyDBus->getWirelessCardName(); - qDebug()<<"debug: already turn on the switch of wifi network"; - //syslog(LOG_DEBUG, "Already turn on the switch of wifi network"); } void MainWindow::disWifiDone() { @@ -3567,24 +3583,14 @@ void MainWindow::on_btnHotspotState() //执行wifi的重新连接 void MainWindow::toReconnectWifi() { - qDebug()<<__FUNCTION__<<__LINE__<<"canReconnectWifiTimeInterval="<ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); + if (isHuaWeiPC) { + QtConcurrent::run([=](){ + objKyDBus->requestScanWifi(); //要求后台扫描AP + sleep(2); + emit refreshWifiListAfterScan(); + }); + } else { + current_wifi_list_state = REFRESH_WIFI; + syslog(LOG_DEBUG, "[%s++%d] state[%d]", __FUNCTION__, __LINE__, current_wifi_list_state); + this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); + } } /* get primary screen changed */ @@ -4331,10 +4348,10 @@ void MainWindow::rfkillEnableWifiDone() if (is_btnWifiList_clicked) { this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC); } else { -// on_btnWifiList_clicked(); + //on_btnWifiList_clicked(); } objKyDBus->getWirelessCardName(); - qDebug()<<"debug: already turn on the switch of wifi network"; - //syslog(LOG_DEBUG, "Already turn on the switch of wifi network"); + qDebug()<<"debug: already turn on the switch of wifi network by keyboard button"; + //syslog(LOG_DEBUG, "Already turn on the switch of wifi network by keyboard button"); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 55245065..5663312a 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -183,10 +183,12 @@ public: bool isToSetWifiValue = true; //本次执行是否进行赋值 bool isReconnectingWifi = false; //是否正在执行wifi的回连 bool isReconnectingLan = false; //是否正在执行lan的回连 + bool isScaningWifi = false; //是否正在进行扫描 int addNumberForWifi = 0; //短时间内收到关于wifi连接信号的次数 bool isHuaWeiPC; bool isHandlingWiredCableOn = false; - bool canReconnectWifiTimeInterval = true; + bool ifCanReconnectWifiNow = true; + bool isRadioWifiTurningOn = false; //是否正在打开wifi开关 QVector dbus_wifiList; //其他组件通过dbus接口获取到的wifi列表,第一个元素一定为已连接wifi,若没有已连接wifi则显示为-- void requestRefreshWifiList(); //申请刷新wifi列表 @@ -233,6 +235,7 @@ public slots: void onRequestRefreshWifiList(); void onRefreshWifiListAfterScan(); void onLoadWifiListAfterScan(); + void onRequestReconnecWifi(); //flag =0或1为普通点击、2为收到打开信息、3为收到关闭信息、4为无线网卡插入、5为无线网卡拔出 void onBtnWifiClicked(int flag = 0); @@ -242,7 +245,6 @@ public slots: void checkIfConnectedWifiExist(); void toReconnectWifi(); - void timeIntervalToConnectWifi(); void rfkillDisableWifiDone(); void rfkillEnableWifiDone(); @@ -424,6 +426,7 @@ signals: void wiredConnectionAdded(); void wiredConnectionRemoved(); void actWiredConnectionChanged(); + void requestReconnecWifi(); }; #endif // MAINWINDOW_H