Optimize the code to get WiFi list

This commit is contained in:
chenlelin 2021-01-09 19:15:35 +08:00
parent c5f5969e7e
commit 5e48c76dcf
4 changed files with 45 additions and 5 deletions

View File

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

View File

@ -37,6 +37,7 @@ public:
bool isExecutingGetLanList = false; //是否正在执行获取有线网列表
bool isExecutingGetWifiList = false; //是否正在执行获取无线网列表
bool isUseOldLanSlist = false; //是否应该要用上一次获取的有线列表
bool isUseOldWifiSlist = false; //是否应该要用上一次获取的有线列表
void execGetLanList();
void execGetWifiList();

View File

@ -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()="<<oldWifiSlist.size()<<" slist.size()="<<slist.size();
//qDebug()<<"0 ";
//foreach (QString str, slist) {
// qDebug()<<str;
//}
//qDebug()<<"0 ";
//要求使用上一次获取到的列表
if (this->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;}
//获取表头信息

View File

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