Fix bug show abnormal wired network list after launch compter

This commit is contained in:
chenlelin 2021-01-04 18:37:44 +08:00
parent fb73b4a4b6
commit 3cea31eb75
1 changed files with 42 additions and 4 deletions

View File

@ -405,7 +405,9 @@ void MainWindow::getInitLanSlist()
FILE * p_file = NULL; FILE * p_file = NULL;
p_file = popen("export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli -f type,device,name connection show", "r"); //p_file = popen("export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli -f type,device,name connection show", "r");
//nmcli -f type,uuid,name connection show
p_file = popen("export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli -f type,uuid,name connection show", "r");
if (!p_file) { if (!p_file) {
syslog(LOG_ERR, "Error occurred when popen cmd 'nmcli connection show'"); syslog(LOG_ERR, "Error occurred when popen cmd 'nmcli connection show'");
qDebug()<<"Error occurred when popen cmd 'nmcli connection show"; qDebug()<<"Error occurred when popen cmd 'nmcli connection show";
@ -421,6 +423,14 @@ void MainWindow::getInitLanSlist()
oldLanSlist.append(strSlist); oldLanSlist.append(strSlist);
} }
} }
qDebug() << " ";
foreach (QString sss, oldLanSlist) {
qDebug() << "AAAAA the oldLanSlist is:"<<sss;
//syslog(LOG_DEBUG, "AAAAA the oldLanSlist is: %s",sss.toUtf8().data());
}
qDebug() << " ";
pclose(p_file); pclose(p_file);
} }
@ -1360,17 +1370,29 @@ void MainWindow::on_btnWifiList_clicked()
// 获取lan列表回调 // 获取lan列表回调
void MainWindow::getLanListDone(QStringList slist) void MainWindow::getLanListDone(QStringList slist)
{ {
qDebug() << " ";
qDebug() <<slist;
qDebug() << " ";
foreach (QString sss, slist) {
qDebug() << "AAAAA the slist is:"<<sss;
//syslog(LOG_DEBUG, "AAAAA the slist is: %s",sss.toUtf8().data());
}
qDebug() << " ";
//要求使用上一次获取到的列表 //要求使用上一次获取到的列表
if (this->ksnm->isUseOldLanSlist) { if (this->ksnm->isUseOldLanSlist) {
slist = oldLanSlist; slist = oldLanSlist;
this->ksnm->isUseOldLanSlist = false; this->ksnm->isUseOldLanSlist = false;
} }
syslog(LOG_DEBUG, "AAAAAAAAAAAAAAAAAAAAAAA");
//若slist为空则也使用上一次获取到的列表 //若slist为空则也使用上一次获取到的列表
if (slist.size() == 1 && slist.at(0) == "") { if (slist.size() == 1 && slist.at(0) == "") {
if (oldLanSlist.size() == 1 && oldLanSlist.at(0) == "") { if (oldLanSlist.size() == 1 && oldLanSlist.at(0) == "") {
syslog(LOG_DEBUG, "AAAAAAAAAAAAAAAAAAAAAAB");
return; return;
} else { } else {
syslog(LOG_DEBUG, "AAAAAAAAAAAAAAAAAAAAAAC");
slist = oldLanSlist; slist = oldLanSlist;
} }
} }
@ -1391,6 +1413,7 @@ void MainWindow::getLanListDone(QStringList slist)
// 若当前lan name为"--"设置OneConnForm // 若当前lan name为"--"设置OneConnForm
if (currConnNames.size() == 0) { if (currConnNames.size() == 0) {
syslog(LOG_DEBUG, "AAAAAAAAAAAAAAAAAAAAAAD");
OneLancForm *ccf = new OneLancForm(topLanListWidget, this, confForm, ksnm); OneLancForm *ccf = new OneLancForm(topLanListWidget, this, confForm, ksnm);
ccf->setName(tr("Not connected"), "--", "--");//"当前未连接任何 以太网" ccf->setName(tr("Not connected"), "--", "--");//"当前未连接任何 以太网"
ccf->setIcon(false); ccf->setIcon(false);
@ -1408,13 +1431,24 @@ void MainWindow::getLanListDone(QStringList slist)
ccf->setLine(false); ccf->setLine(false);
currTopLanItem = 1; currTopLanItem = 1;
} else { } else {
syslog(LOG_DEBUG, "AAAAAAAAAAAAAAAAAAAAAAE");
int i = 0; int i = 0;
do { do {
syslog(LOG_DEBUG, "AAAAAAAAAAAAAAAAAAAAAAF");
actLanSsidName.append(currConnNames.at(i)); //网络名称 actLanSsidName.append(currConnNames.at(i)); //网络名称
actLanUuidName.append(currConnNames.at(i+1)); //网络唯一ID actLanUuidName.append(currConnNames.at(i+1)); //网络唯一ID
i += 2; i += 2;
} while(i<currConnNames.size()); } while(i<currConnNames.size());
currTopLanItem = actLanSsidName.size(); currTopLanItem = actLanSsidName.size();
syslog(LOG_DEBUG, "AAAAAAAAAAAAAAAAAAAAAAG");
foreach (QString ssid, actLanSsidName) {
syslog(LOG_DEBUG, "AAAAA the ssid is: %s",ssid.toUtf8().data());
}
foreach (QString uuid, actLanUuidName) {
syslog(LOG_DEBUG, "AAAAA the uuid is: %s",uuid.toUtf8().data());
}
} }
// 填充可用网络列表 // 填充可用网络列表
@ -1439,7 +1473,7 @@ void MainWindow::getLanListDone(QStringList slist)
bool isActiveNet = false; //是否是活动的连接 bool isActiveNet = false; //是否是活动的连接
//仅仅对有线网络进行添加列表处理 //仅仅对有线网络进行添加列表处理
if (ltype != "802-11-wireless" && ltype != "wifi" && ltype != "" && ltype != "--") { if (ltype != "802-11-wireless" && ltype != "wifi" && ltype != "bridge" && ltype != "" && ltype != "--") {
objKyDBus->getLanIpDNS(nuuid, true); //使用UUID获取有线网的ip和dns信息 objKyDBus->getLanIpDNS(nuuid, true); //使用UUID获取有线网的ip和dns信息
QString macLan = getMacByUuid(nuuid); //有线网对应的mac地址 QString macLan = getMacByUuid(nuuid); //有线网对应的mac地址
@ -1450,8 +1484,8 @@ void MainWindow::getLanListDone(QStringList slist)
macInterface = objKyDBus->getLanMAC(objKyDBus->dbusIfName); //有限网卡对应的mac地址 macInterface = objKyDBus->getLanMAC(objKyDBus->dbusIfName); //有限网卡对应的mac地址
if (macLan!="" && macLan!="--" && macLan != macInterface) { if (macLan!="" && macLan!="--" && macLan != macInterface) {
//continue; //有线网的permenant mac地址与网卡的地址不同则不在列表中显示 continue; //有线网的permenant mac地址与网卡的地址不同则不在列表中显示
macInterface = macLan; //macInterface = macLan;
} }
} else { } else {
mIfName = objKyDBus->multiWiredIfName.at(0); //使用默认的网络接口 mIfName = objKyDBus->multiWiredIfName.at(0); //使用默认的网络接口
@ -1461,7 +1495,11 @@ void MainWindow::getLanListDone(QStringList slist)
//**********************创建已经连接的有线网item********************// //**********************创建已经连接的有线网item********************//
if (currConnNames.size() != 0) {//证明有已经连接的有线网络 if (currConnNames.size() != 0) {//证明有已经连接的有线网络
for (int kk=0; kk<actLanSsidName.size(); kk++) { for (int kk=0; kk<actLanSsidName.size(); kk++) {
syslog(LOG_DEBUG, "AAAAAAAAAAAAAAAAAAAAAAH");
syslog(LOG_DEBUG, "AAAAA the name is: %s",nname.toUtf8().data());
syslog(LOG_DEBUG, "AAAAA the nuid is: %s",nuuid.toUtf8().data());
if (nname == actLanSsidName.at(kk) && nuuid == actLanUuidName.at(kk)) { if (nname == actLanSsidName.at(kk) && nuuid == actLanUuidName.at(kk)) {
syslog(LOG_DEBUG, "AAAAAAAAAAAAAAAAAAAAAAI");
topLanListWidget->resize(topLanListWidget->width(), topLanListWidget->height() + H_NORMAL_ITEM*kk); topLanListWidget->resize(topLanListWidget->width(), topLanListWidget->height() + H_NORMAL_ITEM*kk);
isActiveNet = true; //名为nname的网络是已经连接的有线网络 isActiveNet = true; //名为nname的网络是已经连接的有线网络
ifLanConnected = true; ifLanConnected = true;