From 5e48c76dcf81a95f1632ddccdbb16f660d1b4fde Mon Sep 17 00:00:00 2001 From: chenlelin Date: Sat, 9 Jan 2021 19:15:35 +0800 Subject: [PATCH] Optimize the code to get WiFi list --- src/ksimplenm.cpp | 21 ++++++++++++++++++--- src/ksimplenm.h | 1 + src/mainwindow.cpp | 24 +++++++++++++++++++++++- src/mainwindow.h | 4 +++- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/ksimplenm.cpp b/src/ksimplenm.cpp index 70bd547a..565bb5d3 100644 --- a/src/ksimplenm.cpp +++ b/src/ksimplenm.cpp @@ -36,11 +36,16 @@ KSimpleNM::KSimpleNM(QObject *parent) : QObject(parent) //获取有线网络列表数据 void KSimpleNM::execGetLanList() { - if (isExecutingGetWifiList) { - syslog(LOG_DEBUG, "It is running getting wifi list when getting lan list"); - qDebug()<<"debug: it is running getting wifi list when getting lan list"; + if (isExecutingGetWifiList || isExecutingGetLanList) { + syslog(LOG_DEBUG, "It is running getting wifi or lan list when getting lan list"); + qDebug()<<"debug: it is running getting wifi or lan list when getting lan list"; isUseOldLanSlist = true; + QStringList slistmEmpty; + slistmEmpty.append("Empty"); + emit getLanListFinished(slistmEmpty); + return; } + isExecutingGetLanList = true; shellOutput = ""; type = 0; @@ -53,6 +58,16 @@ void KSimpleNM::execGetLanList() //获取无线网络列表数据 void KSimpleNM::execGetWifiList() { + if (isExecutingGetWifiList || isExecutingGetLanList) { + syslog(LOG_DEBUG, "It is running getting wifi or lan list when getting wifi list"); + qDebug()<<"debug: it is running getting wifi or lan list when getting wifi list"; + isUseOldWifiSlist = true; + QStringList slistmEmpty; + slistmEmpty.append("Empty"); + emit getWifiListFinished(slistmEmpty); + return; + } + isExecutingGetWifiList = true; shellOutput = ""; type = 1; diff --git a/src/ksimplenm.h b/src/ksimplenm.h index 77022510..3a7d5ac8 100644 --- a/src/ksimplenm.h +++ b/src/ksimplenm.h @@ -37,6 +37,7 @@ public: bool isExecutingGetLanList = false; //是否正在执行获取有线网列表 bool isExecutingGetWifiList = false; //是否正在执行获取无线网列表 bool isUseOldLanSlist = false; //是否应该要用上一次获取的有线列表 + bool isUseOldWifiSlist = false; //是否应该要用上一次获取的有线列表 void execGetLanList(); void execGetWifiList(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bfb9937e..cf422147 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -111,6 +111,7 @@ MainWindow::MainWindow(QWidget *parent) : KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon())); + hasWifiConnected = false; // QDBusConnection systemBus = QDBusConnection::systemBus(); // if (!systemBus.registerService("com.kylin.NetworkManager.qt.systemdbus")){ // qCritical() << "QDbus register service failed reason:" << systemBus.lastError(); @@ -1056,7 +1057,7 @@ bool MainWindow::checkWlOn() /////////////////////////////////////////////////////////////////////////////// //有线网与无线网按钮响应 -void MainWindow::on_btnNet_clicked() +void MainWindow::onBtnNetClicked() { if (checkLanOn()) { QThread *t = new QThread(); @@ -1265,6 +1266,7 @@ void MainWindow::on_btnWifiList_clicked() btnWireless->setSwitchStatus(true); lbTopWifiList->show(); btnAddNet->show(); + hasWifiConnected = true; this->startLoading(); this->ksnm->execGetWifiList(); @@ -1291,6 +1293,7 @@ void MainWindow::on_btnWifiList_clicked() ccf->setAct(true); ccf->move(L_VERTICAL_LINE_TO_ITEM, 0); ccf->show(); + is_stop_check_net_state = 0; } else { qDebug()<<"debug: WiFi的开关已经关闭"; btnWireless->setSwitchStatus(false); @@ -1559,6 +1562,18 @@ void MainWindow::getWifiListDone(QStringList slist) { qDebug()<<"debug: oldWifiSlist.size()="<ksnm->isUseOldWifiSlist) { + slist = oldWifiSlist; + this->ksnm->isUseOldWifiSlist = false; + } + //若slist为空,则使用上一次获取到的列表 if (slist.size() == 1 && slist.at(0) == "") { if (oldWifiSlist.size() == 1 && oldWifiSlist.at(0) == "") { @@ -1764,6 +1779,13 @@ void MainWindow::loadWifiListDone(QStringList slist) // 更新wifi列表 void MainWindow::updateWifiListDone(QStringList slist) { + if (hasWifiConnected) { + lbLoadDown->show(); + lbLoadUp->show(); + lbLoadDownImg->show(); + lbLoadUpImg->show(); + } + if (this->ksnm->isExecutingGetLanList){ return;} //获取表头信息 diff --git a/src/mainwindow.h b/src/mainwindow.h index 74ea7902..9d7a160f 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -282,10 +282,12 @@ private: long int end_tx_rates = 0; //保存结束时的流量计数 QString actWifissid = "--"; //当前连接wifi的ssid + bool hasWifiConnected;//当前是否有wifi连接 + private slots: void iconActivated(QSystemTrayIcon::ActivationReason reason); - void on_btnNet_clicked(); + void onBtnNetClicked(); // void on_btnWifiList_clicked(); void onBtnNetListClicked(int flag=0);