Fix bug can not show correct wifi list after connect a hidden wifi which be connected before

This commit is contained in:
chenlelin 2020-12-31 20:54:55 +08:00
parent 2d42e4029e
commit 22aa73d67e
4 changed files with 43 additions and 7 deletions

View File

@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT += core gui x11extras dbus KWindowSystem svg concurrent
QT += core gui x11extras dbus KWindowSystem svg concurrent concurrent
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

View File

@ -1281,6 +1281,7 @@ void MainWindow::on_btnWifiList_clicked()
}
if (iface->wstate != 2) {
qDebug()<<"debug: WiFi的开关已经打开";
btnWireless->setSwitchStatus(true);
lbTopWifiList->show();
btnAddNet->show();
@ -1288,6 +1289,7 @@ void MainWindow::on_btnWifiList_clicked()
this->startLoading();
this->ksnm->execGetWifiList();
} else {
qDebug()<<"debug: WiFi的开关已经关闭";
btnWireless->setSwitchStatus(false);
delete topWifiListWidget; //清空top列表
createTopWifiUI(); //创建顶部无线网item
@ -1564,10 +1566,12 @@ void MainWindow::getWifiListDone(QStringList slist)
}
if (is_update_wifi_list == 0) {
qDebug() << "加载无线列表";
loadWifiListDone(slist);
is_init_wifi_list = 0;
} else {
updateWifiListDone(slist);
//updateWifiListDone(slist);
qDebug() << "更新无线列表";
is_update_wifi_list = 0;
}
oldWifiSlist = slist;
@ -1576,6 +1580,12 @@ void MainWindow::getWifiListDone(QStringList slist)
// 加载wifi列表
void MainWindow::loadWifiListDone(QStringList slist)
{
qDebug() << " ";
foreach (QString sss, slist) {
qDebug() << "列表是: "<< sss;
}
qDebug() << " ";
delete topWifiListWidget; //清空top列表
createTopWifiUI(); //创建topWifiListWidget

View File

@ -28,6 +28,8 @@
#include <stdlib.h>
#include <QDir>
#include <QtConcurrent>
#include <QFuture>
DlgHideWifiWpa::DlgHideWifiWpa(int type, MainWindow *mainWindow, QWidget *parent) :
isUsed(type),
@ -276,6 +278,8 @@ void DlgHideWifiWpa::on_btnCancel_clicked()
void DlgHideWifiWpa::on_btnConnect_clicked()
{
mw->is_stop_check_net_state = 1;
QThread *t = new QThread();
connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
connect(t, SIGNAL(started()), this, SLOT(slotStartLoading()));
@ -308,10 +312,10 @@ void DlgHideWifiWpa::on_btnConnect_clicked()
if(text.indexOf("Scanning not allowed") != -1){x = 1;} else { x = 0;}
} while(x == 1);
QTimer::singleShot(5*1000, this, SLOT(on_execSecConn() ));
QTimer::singleShot(8*1000, this, SLOT(on_execSecConn() ));
} else {
bt->execConnWifi(wifiName);
QTimer::singleShot(6*1000, this, SLOT(emitSignal() ));
QTimer::singleShot(4*1000, this, SLOT(emitSignal() ));
}
this->close();
}
@ -353,14 +357,35 @@ void DlgHideWifiWpa::on_execSecConn()
QString str = "nmcli device wifi connect " + strWifiname + " password " + strWifiPassword;
int status = system(str.toUtf8().data());
if (status != 0){ syslog(LOG_ERR, "execute 'nmcli device wifi connect' in function 'on_execSecConn' failed");}
QTimer::singleShot(3*1000, this, SLOT(emitSignal() ));
QTimer::singleShot(7*1000, this, SLOT(emitSignal() ));
}
void DlgHideWifiWpa::emitSignal()
{
emit reSetWifiList();
mw->stopLoading();
emit this->stopSignal();
QFuture < void > future = QtConcurrent::run([=](){
int xx = 1;
int nn = 0;
do {
BackThread *bt = new BackThread();
IFace *iface = bt->execGetIface();
sleep(1);
nn += 1;
if (nn == 8) {
xx = 0;
} else {
if (iface->wstate != 2) {
emit reSetWifiList();
mw->stopLoading();
xx = 0;
}
}
delete iface;
bt->deleteLater();
} while(xx == 1);
});
}
void DlgHideWifiWpa::paintEvent(QPaintEvent *event)

View File

@ -61,6 +61,7 @@ private slots:
signals:
void reSetWifiList();
void stopSignal();
void stopSignalAgain();
private:
Ui::DlgHideWifiWpa *ui;