From 36c796eddd154b77d5136fbedae6dcc46f7ec1d1 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Thu, 20 May 2021 17:23:18 +0800 Subject: [PATCH 1/2] Optimze code. --- src/mainwindow.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d23d8e0e..87027ab4 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1771,9 +1771,14 @@ void MainWindow::getWifiListDone(QStringList slist) int current_try_time = 0; canReconnectWifiTimeInterval = false; //若使用配置文件连接失败且还有可以回连的wifi,继续尝试回连下一个 + QStringList tried_list; for (current_try_time; current_try_time < targetWifiStructList.length(); current_try_time++) { is_stop_check_net_state = 1; QString wifiSsid = objKyDBus->getWifiSsid(targetWifiStructList.at(current_try_time).objectPath); + if (tried_list.contains(wifiSsid)) { + //如果已有同名AP尝试过重连了,就不再尝试此AP,以防多个同名AP连续尝试连接均失败 + continue; + } emit this->startReconnectWifi(wifiSsid); QString modifyCmd = "nmcli connection modify \""+ wifiSsid + "\" " + "802-11-wireless.bssid " + targetWifiStructList.at(current_try_time).bssid; int mdf_res = system(modifyCmd.toUtf8().data()); @@ -1793,6 +1798,7 @@ void MainWindow::getWifiListDone(QStringList slist) objKyDBus->showDesktopNotify(txt); this->stopLoading(); is_stop_check_net_state = 0; + tried_list.append(wifiSsid); } isReconnectingWifi = false; timeIntervalToConnectWifi(); From 34b5853220842734d45bef89f9b8d9a522ce1d28 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Fri, 21 May 2021 14:34:24 +0800 Subject: [PATCH 2/2] Fix: kylin-nm crashed on Pc with no ethernet device & wifi list can not be shown on v10sp1. --- src/backthread.cpp | 2 +- src/mainwindow.cpp | 60 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/backthread.cpp b/src/backthread.cpp index 599bb106..80e48958 100644 --- a/src/backthread.cpp +++ b/src/backthread.cpp @@ -212,7 +212,7 @@ void BackThread::execConnLan(QString connName, QString ifname, QString connectTy bool isWiredCableAlready = objBackThreadDBus.getWiredCableStateByIfname(ifname); - if (connectType == "bluetooth") { + if (connectType == "bluetooth" || ifname == "") { isWiredCableAlready = true; //对于蓝牙类型的网络不需要接入网线就可以连接 mycmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection up '" + connName + "'"; } else { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 87027ab4..a03f93a1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1584,7 +1584,10 @@ void MainWindow::getLanListDone(QStringList slist) macInterface = macLan; } } else { - mIfName = objKyDBus->multiWiredIfName.at(0); //使用默认的网络接口 + if (objKyDBus->multiWiredIfName.length() > 0) + mIfName = objKyDBus->multiWiredIfName.at(0); //使用默认的网络接口 + else + mIfName = ""; macInterface = objKyDBus->dbusMacDefault; //使用默认的MAC地址 } @@ -2235,7 +2238,12 @@ QVector MainWindow::connectableWifiPriorityList(const QStrin QString line = tmp.at(iter); QString wifiname = line.mid(indexName).trimmed(); QString wifibssid = line.mid(indexBSsid, indexPath-indexBSsid).trimmed(); - QString wifiObjectPath = line.mid(indexPath,indexCate-indexPath).trimmed(); + QString wifiObjectPath; + if (indexCate) { + wifiObjectPath = line.mid(indexPath,indexCate-indexPath).trimmed(); + } else { + wifiObjectPath = line.mid(indexPath,indexName-indexPath).trimmed(); + } QString wifiAutoConnection = "no"; QString wifiPriority; @@ -2427,7 +2435,12 @@ void MainWindow::loadWifiListDone(QStringList slist) QString line = slist.at(i); QString wbssid = line.mid(indexBSsid, 17).trimmed(); int Path = line.indexOf("/org/"); - QString wDbusPath = line.mid(Path, indexCate-indexPath).trimmed(); + QString wDbusPath; + if (indexCate >= 0) { + wDbusPath = line.mid(Path,indexCate-Path).trimmed(); + } else { + wDbusPath = line.mid(Path,indexName-Path).trimmed(); + } QDBusInterface interface("org.freedesktop.NetworkManager", wDbusPath, "org.freedesktop.DBus.Properties", @@ -2454,9 +2467,18 @@ void MainWindow::loadWifiListDone(QStringList slist) QString wsecu = line.mid(indexSecu, indexFreq - indexSecu).trimmed(); QString wbssid = line.mid(indexBSsid, 17).trimmed(); QString wfreq = line.mid(indexFreq, 4).trimmed(); - QString wcate = line.mid(indexCate, 1).trimmed(); + QString wcate; + if (indexCate >= 0) + wcate = line.mid(indexCate, 1).trimmed(); + else + wcate = QString::number(0); int Path = line.indexOf("/org/"); - QString wDbusPath = line.mid(Path, indexCate-indexPath).trimmed(); + QString wDbusPath; + if (indexCate >= 0) { + wDbusPath = line.mid(Path,indexCate-Path).trimmed(); + } else { + wDbusPath = line.mid(Path,indexName-Path).trimmed(); + } QDBusInterface interface("org.freedesktop.NetworkManager", wDbusPath, "org.freedesktop.DBus.Properties", @@ -2490,7 +2512,12 @@ void MainWindow::loadWifiListDone(QStringList slist) for (int k = i; k < slist.size(); k ++) { QString tmpLine = slist.at(k); int Path = tmpLine.indexOf("/org/"); - QString m_DbusPath = slist.at(k).mid(Path, indexCate-indexPath).trimmed(); + QString m_DbusPath; + if (indexCate >= 0) { + m_DbusPath = line.mid(Path,indexCate-Path).trimmed(); + } else { + m_DbusPath = line.mid(Path,indexName-Path).trimmed(); + } QDBusInterface m_interface("org.freedesktop.NetworkManager", m_DbusPath, "org.freedesktop.DBus.Properties", @@ -2525,7 +2552,12 @@ void MainWindow::loadWifiListDone(QStringList slist) }); connect(ccf, SIGNAL(selectedOneWifiForm(QString,int)), this, SLOT(oneTopWifiFormSelected(QString,int))); connect(ccf, SIGNAL(requestHandleWifiDisconn()), this, SLOT(handleWifiDisconn())); - QString path = line.mid(indexPath, indexCate-indexPath).trimmed(); + QString path; + if (indexCate >= 0) { + path = line.mid(indexPath, indexCate - indexPath).trimmed(); + } else { + path = line.mid(indexPath, indexName - indexPath).trimmed(); + } QString m_name; if (path != "" && !path.isEmpty()) m_name= this->objKyDBus->getWifiSsid(path); if (m_name.isEmpty() || m_name == "") { @@ -2586,7 +2618,12 @@ void MainWindow::loadWifiListDone(QStringList slist) OneConnForm *ocf = new OneConnForm(wifiListWidget, this, confForm, ksnm); connect(ocf, SIGNAL(selectedOneWifiForm(QString,int)), this, SLOT(oneWifiFormSelected(QString,int))); - QString path = line.mid(indexPath,indexCate-indexPath).trimmed(); + QString path; + if (indexCate >= 0) { + path = line.mid(indexPath, indexCate - indexPath).trimmed(); + } else { + path = line.mid(indexPath, indexName - indexPath).trimmed(); + } QString m_name; if (path != "" && !path.isEmpty()) m_name= this->objKyDBus->getWifiSsid(path); if (m_name.isEmpty() || m_name == "") { @@ -2748,7 +2785,12 @@ void MainWindow::updateWifiListDone(QStringList slist) QString wbssid = line.mid(indexBSsid, 17).trimmed(); QString wname = line.mid(indexName).trimmed(); QString wfreq = line.mid(indexFreq, 4).trimmed(); - QString wpath = line.mid(indexPath, indexCate - indexPath).trimmed(); + QString wpath; + if (indexCate) { + wpath = line.mid(indexPath, indexCate - indexPath).trimmed(); + } else { + wpath = line.mid(indexPath, indexName - indexPath).trimmed(); + } QString wcate = line.mid(indexCate, 1).trimmed(); if(wname == "" || wname == "--"){continue;}