Optimize code

This commit is contained in:
chenlelin 2021-01-10 09:32:59 +08:00
parent aa05ae1d2c
commit 63e25aa409
2 changed files with 22 additions and 22 deletions

View File

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

View File

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