Merge branch '0530-cll' into 'main'

Optimize process after turn on wifi switch

See merge request kylin-desktop/kylin-nm!8
This commit is contained in:
Xiaoshuo Shi 2021-06-03 09:53:30 +00:00
commit b71893f5d6
5 changed files with 122 additions and 72 deletions

View File

@ -184,6 +184,35 @@ void BackThread::execEnWifi()
}
}
void BackThread::rfKillexecEnWifi()
{
char *chr1 = "nmcli radio wifi on";
Utils::m_system(chr1);
emit enWifiDoneByRfkill();
emit btFinishByRfkill();
// char *chr1 = "nmcli radio wifi on";
// Utils::m_system(chr1);
// emit btFinish();
// KylinDBus objBackThreadDBus;
// while (1) {
// if (execGetIface()->wstate != 2) {
// while (1) {
// if (objBackThreadDBus.getAccessPointsNumber() > 0) {
// // objBackThreadDBus.getAccessPointsNumber()>0 standard can get wireless accesspoints now
// emit enWifiDoneByRfkill();
// emit btFinishByRfkill();
// break;
// }
// sleep(2);
// }
// break;
// }
// sleep(1);
// }
}
//turn off the switch of wireless network
void BackThread::execDisWifi()
{
@ -199,6 +228,20 @@ void BackThread::execDisWifi()
}
}
void BackThread::rfkillExecDisWifi()
{
char *chr = "nmcli radio wifi off";
Utils::m_system(chr);
while (1) {
if (execGetIface()->wstate == 2) {
emit disWifiDoneByRfkill();
emit btFinishByRfkill();
break;
}
sleep(1);
}
}
//to connect wired network
void BackThread::execConnLan(QString connName, QString ifname, QString connectType)
{

View File

@ -57,7 +57,9 @@ public slots:
void execEnNet();
void execDisNet();
void execEnWifi();
void rfKillexecEnWifi();
void execDisWifi();
void rfkillExecDisWifi();
void execConnLan(QString connName, QString ifname, QString connectType);
void execConnWifi(QString connName, QString connIfName);
void execReconnWIfi(QString uuid);
@ -81,11 +83,14 @@ signals:
void enNetDone();
void disNetDone();
void enWifiDone();
void enWifiDoneByRfkill();
void disWifiDone();
void disWifiDoneByRfkill();
void connDone(int connFlag);
void btFinish();
void btFinishByRfkill();
};
#endif // BACKTHREAD_H

View File

@ -1709,10 +1709,10 @@ void KylinDBus::onAutoConnect()
{
//syslog(LOG_DEBUG, "Receive a auto-connect signal to reconnect wifi");
qDebug() << Q_FUNC_INFO << "Receive a auto-connect signal to reconnect wifi";
if (!mw->isRadioWifiTurningOn) {
if (!mw->isRadioWifiTurningOn && !mw->isScaningWifi) {
mw->toReconnectWifi();
} else {
qDebug() << Q_FUNC_INFO << "but need waiting turn on wifi switch, will not reconnect wifi";
qDebug() << Q_FUNC_INFO << "but need waiting turn on wifi switch or finish scan, will not reconnect wifi";
}
}

View File

@ -20,7 +20,7 @@
#include <QIcon>
#define FRAMESPEED 60 //帧与帧之间的间隔时间(ms)
#define ALLTIME 40*1000 //等待动画持续总时间
#define ALLTIME 10*1000 //等待动画持续总时间
//加载动画控件'loadingGif'
LoadingDiv::LoadingDiv(QWidget *parent) : QWidget(parent)

View File

@ -1208,7 +1208,6 @@ void MainWindow::onBtnWifiClicked(int flag)
if (is_fly_mode_on == 0) {
//on_btnWifiList_clicked();
is_stop_check_net_state = 1;
isRadioWifiTurningOn = true;
objKyDBus->setWifiCardState(true);
objKyDBus->setWifiSwitchState(true);
@ -1228,7 +1227,6 @@ void MainWindow::onBtnWifiClicked(int flag)
if (is_fly_mode_on == 0) {
//on_btnWifiList_clicked();
is_stop_check_net_state = 1;
isRadioWifiTurningOn = true;
lbTopWifiList->show();
btnAddNet->show();
@ -1378,10 +1376,8 @@ void MainWindow::on_btnWifiList_clicked()
this->startLoading();
if (isHuaWeiPC) {
QtConcurrent::run([=]() {
isScaningWifi = true;
objKyDBus->requestScanWifi(); //要求后台扫描AP
sleep(2);
isScaningWifi = false;
qDebug() << "scan finished, will load wifi list";
emit loadWifiListAfterScan();
});
@ -3500,20 +3496,7 @@ void MainWindow::disNetDone()
void MainWindow::enWifiDone()
{
if (isHuaWeiPC) {
// QtConcurrent::run([=]() {
// if (is_btnWifiList_clicked) {
// sleep(4);
// objKyDBus->requestScanWifi(); //要求后台扫描AP
// emit loadWifiListAfterScan();
// }
// });
QtConcurrent::run([=]() {
sleep(1);
isRadioWifiTurningOn = false;
qDebug()<<"debug: already turn on the switch of wifi network";
//syslog(LOG_DEBUG, "Already turn on the switch of wifi network");
});
//这里先不做什么因为onRfkillStatusChanged这个函数也在处理wifi开关
} else {
//on_btnWifiList_clicked();
current_wifi_list_state = LOAD_WIFI_LIST;
@ -3527,13 +3510,15 @@ void MainWindow::enWifiDone()
}
void MainWindow::disWifiDone()
{
disWifiDoneChangeUI();
qDebug()<<"debug: already turn off the switch of wifi network";
//syslog(LOG_DEBUG, "Already turn off the switch of wifi network");
this->stopLoading();
is_stop_check_net_state = 0;
if (isHuaWeiPC) {
//这里先不做什么因为onRfkillStatusChanged这个函数也在处理wifi开关
} else {
disWifiDoneChangeUI();
this->stopLoading();
is_stop_check_net_state = 0;
qDebug()<<"debug: already turn on the switch of wifi network";
//syslog(LOG_DEBUG, "Already turn on the switch of wifi network");
}
}
void MainWindow::disWifiStateKeep()
{
@ -4301,48 +4286,51 @@ void MainWindow::priScreenChanged(int x, int y, int width, int height)
// 通过kds的dbus发现rfkill状态变化
void MainWindow::onRfkillStatusChanged()
{
QDBusReply<int> reply = kdsDbus->call("getCurrentWlanMode");
if (reply.isValid()){
int current = reply.value();
if (isHuaWeiPC) {
QDBusReply<int> reply = kdsDbus->call("getCurrentWlanMode");
if (reply.isValid()){
int current = reply.value();
if (current == -1){
qWarning("Error Occur When Get Current WlanMode");
//syslog(LOG_DEBUG, "Error Occur When Get Current WlanMode");
return;
}
if (!current) {
is_stop_check_net_state = 1;
lbTopWifiList->hide();
btnAddNet->hide();
objKyDBus->setWifiSwitchState(false);
QThread *t = new QThread();
BackThread *bt = new BackThread();
bt->moveToThread(t);
btnWireless->setSwitchStatus(false);//此处逻辑应为关闭开关故应将true改为false
connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
connect(t, SIGNAL(started()), bt, SLOT(execDisWifi()));
connect(bt, SIGNAL(disWifiDone()), this, SLOT(rfkillDisableWifiDone()));
connect(bt, SIGNAL(btFinish()), t, SLOT(quit()));
t->start();
this->startLoading();
} else {
if (is_fly_mode_on == 0) {
on_btnWifiList_clicked();
if (current == -1){
qWarning("Error Occur When Get Current WlanMode");
//syslog(LOG_DEBUG, "Error Occur When Get Current WlanMode");
return;
}
if (!current) {
is_stop_check_net_state = 1;
objKyDBus->setWifiCardState(true);
objKyDBus->setWifiSwitchState(true);
lbTopWifiList->hide();
btnAddNet->hide();
objKyDBus->setWifiSwitchState(false);
QThread *t = new QThread();
BackThread *bt = new BackThread();
bt->moveToThread(t);
QThread *rfkill_t = new QThread();
BackThread *rfkill_bt = new BackThread();
rfkill_bt->moveToThread(rfkill_t);
btnWireless->setSwitchStatus(true);
connect(t, SIGNAL(finished()), t, SLOT(deleteLater()));
connect(t, SIGNAL(started()), bt, SLOT(execEnWifi()));
connect(bt, SIGNAL(enWifiDone()), this, SLOT(rfkillEnableWifiDone()));
connect(bt, SIGNAL(btFinish()), t, SLOT(quit()));
t->start();
connect(rfkill_t, SIGNAL(finished()), rfkill_t, SLOT(deleteLater()));
connect(rfkill_t, SIGNAL(started()), rfkill_bt, SLOT(rfkillExecDisWifi()));
connect(rfkill_bt, SIGNAL(disWifiDoneByRfkill()), this, SLOT(rfkillDisableWifiDone()));
connect(rfkill_bt, SIGNAL(btFinishByRfkill()), rfkill_t, SLOT(quit()));
rfkill_t->start();
this->startLoading();
} else {
if (is_fly_mode_on == 0) {
on_btnWifiList_clicked();
is_stop_check_net_state = 1;
isRadioWifiTurningOn = true;
objKyDBus->setWifiCardState(true);
objKyDBus->setWifiSwitchState(true);
QThread *rfkill_t = new QThread();
BackThread *rfkill_bt = new BackThread();
rfkill_bt->moveToThread(rfkill_t);
btnWireless->setSwitchStatus(true);
connect(rfkill_t, SIGNAL(finished()), rfkill_t, SLOT(deleteLater()));
connect(rfkill_t, SIGNAL(started()), rfkill_bt, SLOT(rfKillexecEnWifi()));
connect(rfkill_bt, SIGNAL(enWifiDoneByRfkill()), this, SLOT(rfkillEnableWifiDone()));
connect(rfkill_bt, SIGNAL(btFinishByRfkill()), rfkill_t, SLOT(quit()));
rfkill_t->start();
this->startLoading();
}
}
}
}
@ -4350,11 +4338,12 @@ void MainWindow::onRfkillStatusChanged()
void MainWindow::rfkillDisableWifiDone()
{
//wifi开关关闭
if (is_btnWifiList_clicked)
disWifiDoneChangeUI();
qDebug()<<"debug: already turn off the switch of wifi network by keyboard button";
//syslog(LOG_DEBUG, "Already turn off the switch of wifi network by keyboard button");
qDebug()<<"debug: already turn off the switch of wifi network detected by kds policy";
//syslog(LOG_DEBUG, "Already turn off the switch of wifi network detected by kds policy");
this->stopLoading();
is_stop_check_net_state = 0;
@ -4362,14 +4351,27 @@ void MainWindow::rfkillDisableWifiDone()
void MainWindow::rfkillEnableWifiDone()
{
//wifi开关打开
isRadioWifiTurningOn = false;
current_wifi_list_state = LOAD_WIFI_LIST;
if (is_btnWifiList_clicked) {
this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC);
QtConcurrent::run([=]() {
isScaningWifi = true;
objKyDBus->requestScanWifi(); //要求后台扫描AP
//sleep(1);
isScaningWifi = false;
qDebug() << Q_FUNC_INFO << "scan finished, will exec reconnect wifi";
//emit loadWifiListAfterScan();
emit requestReconnecWifi();
//this->ksnm->execGetWifiList(this->wcardname, this->isHuaWeiPC);
objKyDBus->getWirelessCardName();
qDebug()<<"debug: already turn on the switch of wifi network detected by kds policy";
//syslog(LOG_DEBUG, "Already turn on the switch of wifi network detected by kds policy");
});
} else {
//on_btnWifiList_clicked();
}
objKyDBus->getWirelessCardName();
qDebug()<<"debug: already turn on the switch of wifi network by keyboard button";
//syslog(LOG_DEBUG, "Already turn on the switch of wifi network by keyboard button");
}