From 63e25aa4098ea3702b4da170f6e77c779def64c9 Mon Sep 17 00:00:00 2001 From: chenlelin Date: Sun, 10 Jan 2021 09:32:59 +0800 Subject: [PATCH] Optimize code --- src/ksimplenm.cpp | 36 ++++++++++++++++++------------------ src/ksimplenm.h | 8 ++++---- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ksimplenm.cpp b/src/ksimplenm.cpp index da624af4..79933212 100644 --- a/src/ksimplenm.cpp +++ b/src/ksimplenm.cpp @@ -27,25 +27,25 @@ KSimpleNM::KSimpleNM(QObject *parent) : QObject(parent) { - runProcessWifi = new QProcess(this); - connect(runProcessWifi, &QProcess::readyRead, this, &KSimpleNM::readProcessWifi); - connect(runProcessWifi, SIGNAL(finished(int)), this, SLOT(finishedProcessWifi(int))); - runProcessLan = new QProcess(this); connect(runProcessLan, &QProcess::readyRead, this, &KSimpleNM::readProcessLan); connect(runProcessLan, SIGNAL(finished(int)), this, SLOT(finishedProcessLan(int))); + + runProcessWifi = new QProcess(this); + connect(runProcessWifi, &QProcess::readyRead, this, &KSimpleNM::readProcessWifi); + connect(runProcessWifi, SIGNAL(finished(int)), this, SLOT(finishedProcessWifi(int))); } KSimpleNM::~KSimpleNM() { - delete runProcessWifi; delete runProcessLan; + delete runProcessWifi; } //获取有线网络列表数据 void KSimpleNM::execGetLanList() { - if (isExecutingGetLanList) { + if (isExecutingGetLanList || isExecutingGetWifiList) { syslog(LOG_DEBUG, "It is running getting lan list when getting lan list"); qDebug()<<"debug: it is running getting lan list when getting lan list"; isUseOldLanSlist = true; @@ -63,7 +63,7 @@ void KSimpleNM::execGetLanList() //获取无线网络列表数据 void KSimpleNM::execGetWifiList() { - if (isExecutingGetWifiList) { + if (isExecutingGetWifiList || isExecutingGetLanList) { syslog(LOG_DEBUG, "It is running getting wifi list when getting wifi list"); qDebug()<<"debug: it is running getting wifi list when getting wifi list"; isUseOldWifiSlist = true; @@ -79,27 +79,27 @@ void KSimpleNM::execGetWifiList() } //读取获取到的结果 -void KSimpleNM::readProcessWifi() -{ - QString output = runProcessWifi->readAll(); - shellOutputWifi += output; -} void KSimpleNM::readProcessLan() { QString output = runProcessLan->readAll(); shellOutputLan += output; } +void KSimpleNM::readProcessWifi() +{ + QString output = runProcessWifi->readAll(); + shellOutputWifi += output; +} //读取完所有列表数据后发信号,将数据发往mainwindow用于显示网络列表 -void KSimpleNM::finishedProcessWifi(int msg) -{ - QStringList slist = shellOutputWifi.split("\n"); - emit getWifiListFinished(slist); - isExecutingGetWifiList = false; -} void KSimpleNM::finishedProcessLan(int msg) { QStringList slist = shellOutputLan.split("\n"); emit getLanListFinished(slist); isExecutingGetLanList = false; } +void KSimpleNM::finishedProcessWifi(int msg) +{ + QStringList slist = shellOutputWifi.split("\n"); + emit getWifiListFinished(slist); + isExecutingGetWifiList = false; +} diff --git a/src/ksimplenm.h b/src/ksimplenm.h index 464e27d6..d8c15a29 100644 --- a/src/ksimplenm.h +++ b/src/ksimplenm.h @@ -32,10 +32,10 @@ public: explicit KSimpleNM(QObject *parent = nullptr); ~KSimpleNM(); - QProcess *runProcessWifi; QProcess *runProcessLan; - QString shellOutputWifi; + QProcess *runProcessWifi; QString shellOutputLan; + QString shellOutputWifi; bool isExecutingGetLanList = false; //是否正在执行获取有线网列表 bool isExecutingGetWifiList = false; //是否正在执行获取无线网列表 @@ -50,10 +50,10 @@ signals: void getWifiListFinished(QStringList slist); public slots: - void readProcessWifi(); void readProcessLan(); - void finishedProcessWifi(int msg); + void readProcessWifi(); void finishedProcessLan(int msg); + void finishedProcessWifi(int msg); }; #endif // KSIMPLENM_H