Optimize the code to get WiFi list
This commit is contained in:
parent
c5f5969e7e
commit
5e48c76dcf
|
@ -36,11 +36,16 @@ KSimpleNM::KSimpleNM(QObject *parent) : QObject(parent)
|
||||||
//获取有线网络列表数据
|
//获取有线网络列表数据
|
||||||
void KSimpleNM::execGetLanList()
|
void KSimpleNM::execGetLanList()
|
||||||
{
|
{
|
||||||
if (isExecutingGetWifiList) {
|
if (isExecutingGetWifiList || isExecutingGetLanList) {
|
||||||
syslog(LOG_DEBUG, "It is running getting wifi list when getting lan list");
|
syslog(LOG_DEBUG, "It is running getting wifi or lan list when getting lan list");
|
||||||
qDebug()<<"debug: it is running getting wifi list when getting lan list";
|
qDebug()<<"debug: it is running getting wifi or lan list when getting lan list";
|
||||||
isUseOldLanSlist = true;
|
isUseOldLanSlist = true;
|
||||||
|
QStringList slistmEmpty;
|
||||||
|
slistmEmpty.append("Empty");
|
||||||
|
emit getLanListFinished(slistmEmpty);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isExecutingGetLanList = true;
|
isExecutingGetLanList = true;
|
||||||
shellOutput = "";
|
shellOutput = "";
|
||||||
type = 0;
|
type = 0;
|
||||||
|
@ -53,6 +58,16 @@ void KSimpleNM::execGetLanList()
|
||||||
//获取无线网络列表数据
|
//获取无线网络列表数据
|
||||||
void KSimpleNM::execGetWifiList()
|
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;
|
isExecutingGetWifiList = true;
|
||||||
shellOutput = "";
|
shellOutput = "";
|
||||||
type = 1;
|
type = 1;
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
bool isExecutingGetLanList = false; //是否正在执行获取有线网列表
|
bool isExecutingGetLanList = false; //是否正在执行获取有线网列表
|
||||||
bool isExecutingGetWifiList = false; //是否正在执行获取无线网列表
|
bool isExecutingGetWifiList = false; //是否正在执行获取无线网列表
|
||||||
bool isUseOldLanSlist = false; //是否应该要用上一次获取的有线列表
|
bool isUseOldLanSlist = false; //是否应该要用上一次获取的有线列表
|
||||||
|
bool isUseOldWifiSlist = false; //是否应该要用上一次获取的有线列表
|
||||||
|
|
||||||
void execGetLanList();
|
void execGetLanList();
|
||||||
void execGetWifiList();
|
void execGetWifiList();
|
||||||
|
|
|
@ -111,6 +111,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
|
|
||||||
KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
|
KWindowEffects::enableBlurBehind(this->winId(), true, QRegion(path.toFillPolygon().toPolygon()));
|
||||||
|
|
||||||
|
hasWifiConnected = false;
|
||||||
// QDBusConnection systemBus = QDBusConnection::systemBus();
|
// QDBusConnection systemBus = QDBusConnection::systemBus();
|
||||||
// if (!systemBus.registerService("com.kylin.NetworkManager.qt.systemdbus")){
|
// if (!systemBus.registerService("com.kylin.NetworkManager.qt.systemdbus")){
|
||||||
// qCritical() << "QDbus register service failed reason:" << systemBus.lastError();
|
// 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()) {
|
if (checkLanOn()) {
|
||||||
QThread *t = new QThread();
|
QThread *t = new QThread();
|
||||||
|
@ -1265,6 +1266,7 @@ void MainWindow::on_btnWifiList_clicked()
|
||||||
btnWireless->setSwitchStatus(true);
|
btnWireless->setSwitchStatus(true);
|
||||||
lbTopWifiList->show();
|
lbTopWifiList->show();
|
||||||
btnAddNet->show();
|
btnAddNet->show();
|
||||||
|
hasWifiConnected = true;
|
||||||
|
|
||||||
this->startLoading();
|
this->startLoading();
|
||||||
this->ksnm->execGetWifiList();
|
this->ksnm->execGetWifiList();
|
||||||
|
@ -1291,6 +1293,7 @@ void MainWindow::on_btnWifiList_clicked()
|
||||||
ccf->setAct(true);
|
ccf->setAct(true);
|
||||||
ccf->move(L_VERTICAL_LINE_TO_ITEM, 0);
|
ccf->move(L_VERTICAL_LINE_TO_ITEM, 0);
|
||||||
ccf->show();
|
ccf->show();
|
||||||
|
is_stop_check_net_state = 0;
|
||||||
} else {
|
} else {
|
||||||
qDebug()<<"debug: WiFi的开关已经关闭";
|
qDebug()<<"debug: WiFi的开关已经关闭";
|
||||||
btnWireless->setSwitchStatus(false);
|
btnWireless->setSwitchStatus(false);
|
||||||
|
@ -1559,6 +1562,18 @@ void MainWindow::getWifiListDone(QStringList slist)
|
||||||
{
|
{
|
||||||
qDebug()<<"debug: oldWifiSlist.size()="<<oldWifiSlist.size()<<" slist.size()="<<slist.size();
|
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为空,则使用上一次获取到的列表
|
//若slist为空,则使用上一次获取到的列表
|
||||||
if (slist.size() == 1 && slist.at(0) == "") {
|
if (slist.size() == 1 && slist.at(0) == "") {
|
||||||
if (oldWifiSlist.size() == 1 && oldWifiSlist.at(0) == "") {
|
if (oldWifiSlist.size() == 1 && oldWifiSlist.at(0) == "") {
|
||||||
|
@ -1764,6 +1779,13 @@ void MainWindow::loadWifiListDone(QStringList slist)
|
||||||
// 更新wifi列表
|
// 更新wifi列表
|
||||||
void MainWindow::updateWifiListDone(QStringList slist)
|
void MainWindow::updateWifiListDone(QStringList slist)
|
||||||
{
|
{
|
||||||
|
if (hasWifiConnected) {
|
||||||
|
lbLoadDown->show();
|
||||||
|
lbLoadUp->show();
|
||||||
|
lbLoadDownImg->show();
|
||||||
|
lbLoadUpImg->show();
|
||||||
|
}
|
||||||
|
|
||||||
if (this->ksnm->isExecutingGetLanList){ return;}
|
if (this->ksnm->isExecutingGetLanList){ return;}
|
||||||
|
|
||||||
//获取表头信息
|
//获取表头信息
|
||||||
|
|
|
@ -282,10 +282,12 @@ private:
|
||||||
long int end_tx_rates = 0; //保存结束时的流量计数
|
long int end_tx_rates = 0; //保存结束时的流量计数
|
||||||
QString actWifissid = "--"; //当前连接wifi的ssid
|
QString actWifissid = "--"; //当前连接wifi的ssid
|
||||||
|
|
||||||
|
bool hasWifiConnected;//当前是否有wifi连接
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void iconActivated(QSystemTrayIcon::ActivationReason reason);
|
void iconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||||
|
|
||||||
void on_btnNet_clicked();
|
void onBtnNetClicked();
|
||||||
// void on_btnWifiList_clicked();
|
// void on_btnWifiList_clicked();
|
||||||
void onBtnNetListClicked(int flag=0);
|
void onBtnNetListClicked(int flag=0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue