feat(mainwindow): Optimize code logic.

Description: 优化代码逻辑

Log: 优化代码逻辑
This commit is contained in:
mammonsama666 2020-12-11 14:53:20 +08:00
parent 80dfbc214c
commit 9d7e067798
3 changed files with 24 additions and 9 deletions

View File

@ -75,7 +75,8 @@ IFace* BackThread::execGetIface()
QString iname = lastStr.left(index2);
QString istateStr = lastStr.mid(index2).trimmed();
if (type == "ethernet") {
//只要存在一个有线设备已连接,就不再扫描其他有线设备状态,避免有线被误断开
if (type == "ethernet" && iface->lstate != 0) {
// if type is wired network
iface->lname = iname;
@ -434,5 +435,6 @@ void BackThread::disConnLanOrWifi(QString type)
kylin_network_set_con_down(strSlist.toUtf8().data());
}
}
emit btFinish();
pclose(p_file);
}

View File

@ -494,10 +494,16 @@ void MainWindow::initNetwork()
BackThread *m_bt = new BackThread();
IFace *m_iface = m_bt->execGetIface();
m_bt->disConnLanOrWifi("ethernet");
sleep(1);
m_bt->disConnLanOrWifi("ethernet");
sleep(1);
//写成信号监听自动执行,避免阻塞主线程
disconnect_time = 1;
connect (m_bt, &BackThread::btFinish, this, [ = ](){
disconnect_time ++;
if (disconnect_time <= 3) {
m_bt->disConnLanOrWifi("ethernet");
} else {
m_bt->disconnect();
}
});
m_bt->disConnLanOrWifi("ethernet");
delete m_iface;
@ -918,10 +924,16 @@ void MainWindow::onDeleteLan()
{
deleteLanTimer->stop();
BackThread *btn_bt = new BackThread();
btn_bt->disConnLanOrWifi("ethernet");
sleep(1);
btn_bt->disConnLanOrWifi("ethernet");
sleep(1);
//写成信号监听自动执行,避免阻塞主线程
disconnect_time = 1;
connect (btn_bt, &BackThread::btFinish, this, [ = ](){
disconnect_time ++;
if (disconnect_time <= 3) {
btn_bt->disConnLanOrWifi("ethernet");
} else {
btn_bt->disconnect();
}
});
btn_bt->disConnLanOrWifi("ethernet");
btn_bt->deleteLater();

View File

@ -268,6 +268,7 @@ private:
int currentIconIndex;
int activeWifiSignalLv;
int disconnect_time = 0;
long int start_rcv_rates = 0; //保存开始时的流量计数
long int end_rcv_rates = 0; //保存结束时的流量计数