Fix bug window of kylin-nm chocked when connect or disconnect wifi

This commit is contained in:
chenlelin 2021-04-26 11:36:11 +08:00
parent 36081fff60
commit d06ae50117
7 changed files with 36 additions and 46 deletions

View File

@ -569,15 +569,12 @@ QString BackThread::execChkLanWidth(QString ethName)
//disconnected spare ethernet or wifi //disconnected spare ethernet or wifi
void BackThread::disConnSparedNetSlot(QString type) void BackThread::disConnSparedNetSlot(QString type)
{ {
sleep(1);
if (type == "wifi") { if (type == "wifi") {
//disConnLanOrWifi("wifi"); //disConnLanOrWifi("wifi");
} else if(type == "ethernet") { } else if(type == "ethernet") {
sleep(1);
disConnLanOrWifi("ethernet"); disConnLanOrWifi("ethernet");
} }
emit disFinish();
emit ttFinish();
} }
//disconnected ethernet or wifi according to network type //disconnected ethernet or wifi according to network type

View File

@ -86,8 +86,6 @@ signals:
void connDone(int connFlag); void connDone(int connFlag);
void btFinish(); void btFinish();
void disFinish();
void ttFinish();
}; };
#endif // BACKTHREAD_H #endif // BACKTHREAD_H

View File

@ -1578,6 +1578,9 @@ void KylinDBus::toGetWifiList()
//网络连接变化时,如有新增或减少的网络,发信号通知更新主界面 //网络连接变化时,如有新增或减少的网络,发信号通知更新主界面
void KylinDBus::onPropertiesChanged(QVariantMap qvm) void KylinDBus::onPropertiesChanged(QVariantMap qvm)
{ {
if (mw->is_stop_check_net_state) {
return;
}
for(QString keyStr : qvm.keys()) { for(QString keyStr : qvm.keys()) {
//有关已连接网络变化的信号 //有关已连接网络变化的信号
if (keyStr == "ActiveConnections") { if (keyStr == "ActiveConnections") {
@ -1709,6 +1712,9 @@ void KylinDBus::onLanIpPropertiesChanged()
//无线网的Ip属性变化时的响应函数 //无线网的Ip属性变化时的响应函数
void KylinDBus::onWifiIpPropertiesChanged() { void KylinDBus::onWifiIpPropertiesChanged() {
if (mw->is_stop_check_net_state) {
return;
}
emit this->updateWirelessList(); emit this->updateWirelessList();
} }

View File

@ -2064,7 +2064,7 @@ QList<structWifiProperty> MainWindow::connectableWifiPriorityList(const QStringL
if (selectedWifiListStruct.size() > 1) { if (selectedWifiListStruct.size() > 1) {
devListSort(&selectedWifiListStruct); devListSort(&selectedWifiListStruct);
foreach (structWifiProperty wifiPriorityAfterSort, selectedWifiListStruct) { foreach (structWifiProperty wifiPriorityAfterSort, selectedWifiListStruct) {
qDebug() << "-----------------------> 排序后" << wifiPriorityAfterSort.priority; qDebug() << wifiPriorityAfterSort.bssid << " 的自动连接优先级是 " << wifiPriorityAfterSort.priority;
} }
} }
ocf->deleteLater(); ocf->deleteLater();
@ -2339,9 +2339,9 @@ void MainWindow::loadWifiListDone(QStringList slist)
ocf->show(); ocf->show();
if (actWifiBssidList.contains(wbssid) && wifiActState == 1) { if (actWifiBssidList.contains(wbssid) && wifiActState == 1) {
ocf->startWaiting(true); ocf->startWifiWaiting(true);
} else if (actWifiId == wname && wifiActState == 1) { } else if (actWifiId == wname && wifiActState == 1) {
ocf->startWaiting(true); ocf->startWifiWaiting(true);
} }
j ++; j ++;
@ -3060,16 +3060,11 @@ void MainWindow::activeLanDisconn()
void MainWindow::activeWifiDisconn() void MainWindow::activeWifiDisconn()
{ {
hasWifiConnected = false; hasWifiConnected = false;
currSelNetName = "";
QThread *tt = new QThread(); this->ksnm->execGetWifiList(this->wcardname);
BackThread *btt = new BackThread(); QtConcurrent::run([=]() {
btt->moveToThread(tt); activeStartLoading();
connect(tt, SIGNAL(finished()), tt, SLOT(deleteLater())); });
connect(tt, SIGNAL(started()), this, SLOT(activeStartLoading()));
connect(this, SIGNAL(disConnSparedNet(QString)), btt, SLOT(disConnSparedNetSlot(QString)));
connect(btt, SIGNAL(disFinish()), this, SLOT(activeGetWifiList()));
connect(btt, SIGNAL(ttFinish()), tt, SLOT(quit()));
tt->start();
} }
void MainWindow::activeStartLoading() void MainWindow::activeStartLoading()
{ {
@ -3077,13 +3072,8 @@ void MainWindow::activeStartLoading()
QString txt(tr("Wi-Fi is disconnected")); QString txt(tr("Wi-Fi is disconnected"));
objKyDBus->showDesktopNotify(txt); objKyDBus->showDesktopNotify(txt);
currSelNetName = ""; setTrayLoading(false);
emit this->disConnSparedNet("wifi"); getActiveInfoAndSetTrayIcon();
}
void MainWindow::activeGetWifiList()
{
emit this->waitWifiStop();
this->ksnm->execGetWifiList(this->wcardname);
} }
//网络开关处理,打开与关闭网络 //网络开关处理,打开与关闭网络

View File

@ -371,7 +371,6 @@ private slots:
void activeLanDisconn(); void activeLanDisconn();
void activeWifiDisconn(); void activeWifiDisconn();
void activeStartLoading(); void activeStartLoading();
void activeGetWifiList();
void onRequestScanAccesspoint(); void onRequestScanAccesspoint();
void toScanWifi(bool isShow); void toScanWifi(bool isShow);
void on_setNetSpeed(); void on_setNetSpeed();
@ -401,7 +400,6 @@ private slots:
signals: signals:
void disConnSparedNet(QString type); void disConnSparedNet(QString type);
void waitWifiStop();
void waitLanStop(); void waitLanStop();
void reConnectWifi(const QString& uuid); void reConnectWifi(const QString& uuid);
void actWifiSignalLvChanaged(const int& currentLevel); void actWifiSignalLvChanaged(const int& currentLevel);

View File

@ -155,7 +155,6 @@ OneConnForm::OneConnForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf
this->waitTimer = new QTimer(this); this->waitTimer = new QTimer(this);
connect(waitTimer, SIGNAL(timeout()), this, SLOT(waitAnimStep())); connect(waitTimer, SIGNAL(timeout()), this, SLOT(waitAnimStep()));
connect(mw, SIGNAL(waitWifiStop()), this, SLOT(stopWaiting()));
connect(mw, &MainWindow::reConnectWifi, this, [ = ](const QString& uuid) { connect(mw, &MainWindow::reConnectWifi, this, [ = ](const QString& uuid) {
if (isActive) { if (isActive) {
QThread *t = new QThread(); QThread *t = new QThread();
@ -520,12 +519,12 @@ void OneConnForm::setWifiInfo(QString str1, QString str2, QString str3, int freq
void OneConnForm::slotConnWifi() void OneConnForm::slotConnWifi()
{ {
this->startWaiting(true); this->startWifiWaiting(true);
emit sigConnWifi(wifiName, wifiIfName); emit sigConnWifi(wifiName, wifiIfName);
} }
void OneConnForm::slotConnWifiPWD() void OneConnForm::slotConnWifiPWD()
{ {
this->startWaiting(true); this->startWifiWaiting(true);
emit sigConnWifiPWD(wifiName, ui->lePassword->text(), connType); emit sigConnWifiPWD(wifiName, ui->lePassword->text(), connType);
} }
@ -542,10 +541,10 @@ void OneConnForm::on_btnDisConn_clicked()
mw->canReconnectWifiList.removeOne(wifiName); mw->canReconnectWifiList.removeOne(wifiName);
} }
this->startWaiting(false); this->startWifiWaiting(false);
mw->is_stop_check_net_state = 1; mw->is_stop_check_net_state = 1;
mw->on_btnHotspotState(); //mw->on_btnHotspotState();
//kylin_network_set_con_down(wifiName.toUtf8().data()); //kylin_network_set_con_down(wifiName.toUtf8().data());
kylin_network_set_con_down(wifiUuid.toUtf8().data()); kylin_network_set_con_down(wifiUuid.toUtf8().data());
disconnect(this, SIGNAL(selectedOneWifiForm(QString,int)), mw, SLOT(oneTopWifiFormSelected(QString,int))); disconnect(this, SIGNAL(selectedOneWifiForm(QString,int)), mw, SLOT(oneTopWifiFormSelected(QString,int)));
@ -685,13 +684,13 @@ void OneConnForm::toConnectWirelessNetwork()
bt->moveToThread(t); bt->moveToThread(t);
connect(t, SIGNAL(finished()), t, SLOT(deleteLater())); connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
connect(t, &QThread::started, this, [ = ]() { connect(t, &QThread::started, this, [ = ]() {
this->startWaiting(true); this->startWifiWaiting(true);
QString cmdStr = "nmcli connection up '" + wifiName + "' passwd-file " + homePath +"/.config/" + wifiName + ".psk"; QString cmdStr = "nmcli connection up '" + wifiName + "' passwd-file " + homePath +"/.config/" + wifiName + ".psk";
emit this->sigConnWifiPsk(cmdStr); emit this->sigConnWifiPsk(cmdStr);
}); });
connect(this, SIGNAL(sigConnWifiPsk(QString)), bt, SLOT(execConnWifiPsk(QString))); connect(this, SIGNAL(sigConnWifiPsk(QString)), bt, SLOT(execConnWifiPsk(QString)));
connect(bt, &BackThread::connDone, this, [ = ](int res) { connect(bt, &BackThread::connDone, this, [ = ](int res) {
this->stopWaiting(); this->stopWifiWaiting(true);
mw->is_stop_check_net_state = 0; mw->is_stop_check_net_state = 0;
if (res) { if (res) {
QFile::remove(QString("%1/.config/%2.psk").arg(homePath).arg(wifiName).toUtf8()); QFile::remove(QString("%1/.config/%2.psk").arg(homePath).arg(wifiName).toUtf8());
@ -743,13 +742,13 @@ void OneConnForm::on_btnConnPWD_clicked()
bt->moveToThread(t); bt->moveToThread(t);
connect(t, SIGNAL(finished()), t, SLOT(deleteLater())); connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
connect(t, &QThread::started, this, [ = ]() { connect(t, &QThread::started, this, [ = ]() {
this->startWaiting(true); this->startWifiWaiting(true);
QString cmdStr = "nmcli connection up '" + wifiName + "' passwd-file " + homePath +"/.config/" + wifiName + ".psk"; QString cmdStr = "nmcli connection up '" + wifiName + "' passwd-file " + homePath +"/.config/" + wifiName + ".psk";
emit this->sigConnWifiPsk(cmdStr); emit this->sigConnWifiPsk(cmdStr);
}); });
connect(this, SIGNAL(sigConnWifiPsk(QString)), bt, SLOT(execConnWifiPsk(QString))); connect(this, SIGNAL(sigConnWifiPsk(QString)), bt, SLOT(execConnWifiPsk(QString)));
connect(bt, &BackThread::connDone, this, [ = ](int res) { connect(bt, &BackThread::connDone, this, [ = ](int res) {
this->stopWaiting(); this->stopWifiWaiting(true);
mw->is_stop_check_net_state = 0; mw->is_stop_check_net_state = 0;
if (res) { if (res) {
QFile::remove(QString("%1/.config/%2.psk").arg(homePath).arg(wifiName).toUtf8()); QFile::remove(QString("%1/.config/%2.psk").arg(homePath).arg(wifiName).toUtf8());
@ -994,7 +993,7 @@ void OneConnForm::slotConnWifiResult(int connFlag)
// 设置全局变量当前连接Wifi的信号强度 // 设置全局变量当前连接Wifi的信号强度
currentActWifiSignalLv = signalLv; currentActWifiSignalLv = signalLv;
this->stopWaiting(); this->stopWifiWaiting(true);
mw->is_stop_check_net_state = 0; mw->is_stop_check_net_state = 0;
} }
@ -1020,13 +1019,13 @@ void OneConnForm::waitAnimStep()
syslog(LOG_ERR, "execute 'kill -9 $(pidof nmcli)' in function 'waitAnimStep' failed"); syslog(LOG_ERR, "execute 'kill -9 $(pidof nmcli)' in function 'waitAnimStep' failed");
} }
this->stopWaiting(); //动画超出时间限制,强制停止动画 this->stopWifiWaiting(true); //动画超出时间限制,强制停止动画
mw->is_stop_check_net_state = 0; mw->is_stop_check_net_state = 0;
} }
} }
void OneConnForm::startWaiting(bool isToConnect) void OneConnForm::startWifiWaiting(bool isToConnect)
{ {
this->isWaiting = true; this->isWaiting = true;
if (isToConnect) { if (isToConnect) {
@ -1046,7 +1045,7 @@ void OneConnForm::startWaiting(bool isToConnect)
mw->setTrayLoading(true); mw->setTrayLoading(true);
} }
void OneConnForm::stopWaiting() void OneConnForm::stopWifiWaiting(bool isUpdateTrayIcon)
{ {
ui->lbWaitingIcon->move(380, 20); ui->lbWaitingIcon->move(380, 20);
ui->btnCancel->hide(); ui->btnCancel->hide();
@ -1055,8 +1054,10 @@ void OneConnForm::stopWaiting()
ui->lbWaiting->hide(); ui->lbWaiting->hide();
ui->lbWaitingIcon->hide(); ui->lbWaitingIcon->hide();
mw->setTrayLoading(false); if (isUpdateTrayIcon) {
mw->getActiveInfoAndSetTrayIcon(); mw->setTrayLoading(false);
mw->getActiveInfoAndSetTrayIcon();
}
} }
void OneConnForm::on_btnCancel_clicked() void OneConnForm::on_btnCancel_clicked()
@ -1075,7 +1076,7 @@ void OneConnForm::on_btnCancel_clicked()
QString currentConnectWifiUuid = wifiSsidAndUuid.at(0); QString currentConnectWifiUuid = wifiSsidAndUuid.at(0);
kylin_network_set_con_down(currentConnectWifiUuid.toUtf8().data()); kylin_network_set_con_down(currentConnectWifiUuid.toUtf8().data());
} }
this->stopWaiting(); this->stopWifiWaiting(true);
} }
int OneConnForm::getPskFlag() int OneConnForm::getPskFlag()

View File

@ -98,8 +98,8 @@ public:
public slots: public slots:
void waitAnimStep(); void waitAnimStep();
void startWaiting(bool isToConnect); void startWifiWaiting(bool isToConnect);
void stopWaiting(); void stopWifiWaiting(bool isUpdateTrayIcon);
void onBtnPropertyClicked(); void onBtnPropertyClicked();
protected: protected: