From ee1cb6c2caf1b4458e2dbf31fa1108497ee71fcf Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Fri, 14 May 2021 17:09:42 +0800 Subject: [PATCH 1/2] Fix:Frequence Label for connected wifi is incorrect. Link: http://172.17.66.192/biz/bug-view-50611.html --- src/mainwindow.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 656ede5a..4fdfe2b5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2461,7 +2461,7 @@ void MainWindow::loadWifiListDone(QStringList slist) int Path = tmpLine.indexOf("/org/"); QString m_DbusPath = slist.at(k).mid(Path, indexCate-indexPath).trimmed(); QDBusInterface m_interface("org.freedesktop.NetworkManager", - wDbusPath, + m_DbusPath, "org.freedesktop.DBus.Properties", QDBusConnection::systemBus() ); QDBusReply m_reply = m_interface.call("Get","org.freedesktop.NetworkManager.AccessPoint","Ssid"); @@ -2525,7 +2525,15 @@ void MainWindow::loadWifiListDone(QStringList slist) setTrayIconOfWifi(wsignal.toInt()); activeWifiSignalLv = wsignal.toInt(); //objKyDBus->getWifiMac(wname); - ccf->setWifiInfo(wsecu, wsignal, wbssid, freqState); + if (freqState == 0) { + //该WiFi含2.4G和5G的AP,需要判断当前连接的是那种类型 + if (wfreq.toInt() >= 5000) + ccf->setWifiInfo(wsecu, wsignal, wbssid, 2); + else + ccf->setWifiInfo(wsecu, wsignal, wbssid, 1); + } else { + ccf->setWifiInfo(wsecu, wsignal, wbssid, freqState); + } ccf->setConnedString(1, tr("NetOn,"), wsecu);//"已连接" ccf->isConnected = true; ifWLanConnected = true; From 14a5066b5a8c7625538f1210a290788d0f9ce3b3 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Fri, 14 May 2021 20:11:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20Wifi=20with=20Chinese=20in=20ssid=20?= =?UTF-8?q?will=20be=20added=20twice.=20=E4=BF=AE=E5=A4=8Dssid=E5=90=AB?= =?UTF-8?q?=E4=B8=AD=E6=96=87=E7=9A=84WiFi=E6=9B=B4=E6=96=B0=E6=97=B6?= =?UTF-8?q?=E4=BC=9A=E8=A2=AB=E8=AF=AF=E6=B7=BB=E5=8A=A0=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ksimplenm.cpp | 5 +-- src/mainwindow.cpp | 88 +++++++++++++++++++++------------------------- 2 files changed, 44 insertions(+), 49 deletions(-) diff --git a/src/ksimplenm.cpp b/src/ksimplenm.cpp index 0d61dfb5..f88af209 100644 --- a/src/ksimplenm.cpp +++ b/src/ksimplenm.cpp @@ -86,10 +86,11 @@ void KSimpleNM::execGetWifiList(const QString& wname) shellOutputWifi = ""; QString cmd; + //将ssid放置在最后一列以防ssid存在中文或特殊字符导致其后面的列不对齐 if (wname.isEmpty() || wname == "") { - cmd = "nmcli -f in-use,signal,security,freq,bssid,ssid,dbus-path,category device wifi"; + cmd = "nmcli -f in-use,signal,security,freq,bssid,dbus-path,category,ssid device wifi"; } else { - cmd = "nmcli -f in-use,signal,security,freq,bssid,ssid,dbus-path,category device wifi list ifname " + wname; + cmd = "nmcli -f in-use,signal,security,freq,bssid,dbus-path,category,ssid device wifi list ifname " + wname; } runProcessWifi->start(cmd); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4fdfe2b5..c87e8eae 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1757,7 +1757,9 @@ void MainWindow::getWifiListDone(QStringList slist) QtConcurrent::run([=]() { QString wifiSsid = objKyDBus->getWifiSsid(targetWifiStructList.at(0).objectPath); QString modityCmd = "nmcli connection modify \""+ wifiSsid + "\" " + "802-11-wireless.bssid " + targetWifiStructList.at(0).bssid; - system(modityCmd.toUtf8().data()); + qDebug()<<"Will modify configuration for "< 55 && conCate == 2){ p1.append(line); continue; @@ -2029,15 +2032,15 @@ void MainWindow::wifiListOptimize(QStringList& slist) indexSecu = headLine.indexOf("安全性"); indexFreq = headLine.indexOf("频率") + 4; indexBSsid = headLine.indexOf("BSSID") + 6; - indexName = indexBSsid + 19; indexPath = headLine.indexOf("DBUS-PATH"); + indexName = headLine.lastIndexOf("SSID"); } else { indexSignal = headLine.indexOf("SIGNAL"); indexSecu = headLine.indexOf("SECURITY"); indexFreq = headLine.indexOf("FREQ"); indexBSsid = headLine.indexOf("BSSID"); - indexName = indexBSsid + 19; indexPath = headLine.indexOf("DBUS-PATH"); + indexName = headLine.lastIndexOf("SSID"); } QStringList targetList; //slist优化,同名同频AP中只留信号最强 @@ -2051,7 +2054,7 @@ void MainWindow::wifiListOptimize(QStringList& slist) QString currentWifiInfo = slist.at(ii); bool ifContinue = false; - QString conName = currentWifiInfo.mid(indexName, indexPath - indexName).trimmed(); + QString conName = currentWifiInfo.mid(indexName).trimmed(); int conSignal = currentWifiInfo.mid(indexSignal,3).trimmed().toInt(); int conFreq = currentWifiInfo.mid(indexFreq,4).trimmed().toInt(); @@ -2062,7 +2065,7 @@ void MainWindow::wifiListOptimize(QStringList& slist) for (int jj=1;jj MainWindow::connectableWifiPriorityList(const QStrin indexSecu = headLine.indexOf("安全性"); indexFreq = headLine.indexOf("频率") + 4; indexBSsid = headLine.indexOf("BSSID") + 6; - indexName = indexBSsid + 19; indexPath = headLine.indexOf("DBUS-PATH"); indexCate = headLine.indexOf("CATEGORY"); + indexName = headLine.lastIndexOf("SSID"); } else { indexSignal = headLine.indexOf("SIGNAL"); indexSecu = headLine.indexOf("SECURITY"); indexFreq = headLine.indexOf("FREQ"); indexBSsid = headLine.indexOf("BSSID"); - indexName = indexBSsid + 19; indexPath = headLine.indexOf("DBUS-PATH"); indexCate = headLine.indexOf("CATEGORY"); + indexName = headLine.lastIndexOf("SSID"); } QStringList tmp = slist; for (int iter=1; iter MainWindow::connectableWifiPriorityList(const QStrin myWifiProStruct.bssid = wifibssid; myWifiProStruct.priority = wifiPriority.toInt(); selectedWifiListStruct.append(myWifiProStruct); - qDebug()<"<"<"<objKyDBus->getWifiSsid(QString("/org/freedesktop/NetworkManager/AccessPoint/%1").arg(path.mid(path.lastIndexOf("/") + 1))); + if (path != "" && !path.isEmpty()) m_name= this->objKyDBus->getWifiSsid(path); if (m_name.isEmpty() || m_name == "") { ccf->setWifiName(wname, wbssid, actWifiUuid, objKyDBus->dbusWiFiCardName, isHuaWeiPC); if (!canReconnectWifiList.contains(wname)) { @@ -2555,9 +2557,9 @@ 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).trimmed(); + QString path = line.mid(indexPath,indexCate-indexPath).trimmed(); QString m_name; - if (path != "" && !path.isEmpty()) m_name= this->objKyDBus->getWifiSsid(QString("/org/freedesktop/NetworkManager/AccessPoint/%1").arg(path.mid(path.lastIndexOf("/") + 1))); + if (path != "" && !path.isEmpty()) m_name= this->objKyDBus->getWifiSsid(path); if (m_name.isEmpty() || m_name == "") { ocf->setWifiName(wname, wbssid, actWifiUuid, objKyDBus->dbusWiFiCardName, isHuaWeiPC); } else { @@ -2640,15 +2642,10 @@ void MainWindow::updateWifiListDone(QStringList slist) //获取表头信息 QString lastHeadLine = oldWifiSlist.at(0); - int lastIndexName, lastIndexPath; + int lastIndexName; lastHeadLine = lastHeadLine.trimmed(); - bool isChineseInIt = lastHeadLine.contains(QRegExp("[\\x4e00-\\x9fa5]+")); - if (isChineseInIt) { - lastIndexName = lastHeadLine.indexOf("BSSID") + 6 + 19; - } else { - lastIndexName = lastHeadLine.indexOf("BSSID") + 19; - } - lastIndexPath = lastHeadLine.indexOf("DBUS-PATH"); +// bool isChineseInIt = lastHeadLine.contains(QRegExp("[\\x4e00-\\x9fa5]+")); + lastIndexName = lastHeadLine.lastIndexOf("SSID"); QString headLine = slist.at(0); int indexSecu, indexFreq, indexBSsid, indexName, indexPath, indexCate; @@ -2658,27 +2655,25 @@ void MainWindow::updateWifiListDone(QStringList slist) indexSecu = headLine.indexOf("安全性"); indexFreq = headLine.indexOf("频率") + 4; indexBSsid = headLine.indexOf("BSSID") + 6; - //indexName = headLine.indexOf("SSID") + 6; - indexName = indexBSsid + 19; indexPath = headLine.indexOf("DBUS-PATH"); - indexCate= headLine.indexOf("CATEGORY"); + indexCate = headLine.indexOf("CATEGORY"); + indexName = headLine.lastIndexOf("SSID"); } else { indexSecu = headLine.indexOf("SECURITY"); indexFreq = headLine.indexOf("FREQ"); indexBSsid = headLine.indexOf("BSSID"); - //indexName = headLine.indexOf("SSID"); - indexName = indexBSsid + 19; indexPath = headLine.indexOf("DBUS-PATH"); indexCate = headLine.indexOf("CATEGORY"); + indexName = headLine.lastIndexOf("SSID"); } //列表中去除已经减少的wifi for (int i=1; iobjKyDBus->getWifiSsid(QString("/org/freedesktop/NetworkManager/AccessPoint/%1").arg(slist.at(k).mid(slist.at(k).lastIndexOf("/") + 1).trimmed())); if (wname == m_name) { if (slist.at(k).mid(indexFreq, 4).trimmed().toInt() > max_freq) { @@ -2761,10 +2757,9 @@ void MainWindow::updateWifiListDone(QStringList slist) } wnames.append(wname); - for (int j=1; j < oldWifiSlist.size(); j++) { QString line = oldWifiSlist.at(j); - QString lastWname = line.mid(lastIndexName, lastIndexPath - lastIndexName).trimmed(); + QString lastWname = line.mid(lastIndexName).trimmed(); if (lastWname == wname){break;} //上一次的wifi列表已经有名为wname的wifi,则停止 if (j == oldWifiSlist.size()-1) { //到lastSlist最后一个都没找到,执行下面流程 QList wifiList = wifiListWidget->findChildren(); @@ -2783,9 +2778,8 @@ void MainWindow::updateWifiListDone(QStringList slist) wifiListWidget->resize(W_LIST_WIDGET, wifiListWidget->height() + H_NORMAL_ITEM); OneConnForm *addItem = new OneConnForm(wifiListWidget, this, confForm, ksnm); connect(addItem, SIGNAL(selectedOneWifiForm(QString,int)), this, SLOT(oneWifiFormSelected(QString,int))); - QString path = line.mid(indexPath).trimmed(); QString m_name; - if (path != "" && !path.isEmpty()) m_name= this->objKyDBus->getWifiSsid(QString("/org/freedesktop/NetworkManager/AccessPoint/%1").arg(path.mid(path.lastIndexOf("/") + 1))); + if (wpath != "" && !wpath.isEmpty()) m_name= this->objKyDBus->getWifiSsid(wpath); if (m_name.isEmpty() || m_name == "") { addItem->setWifiName(wname, wbssid, actWifiUuid, objKyDBus->dbusWiFiCardName, isHuaWeiPC); } else {