diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d7785b02..74f25dc5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1714,13 +1714,13 @@ void MainWindow::getWifiListDone(QStringList slist) } //若slist为空,则使用上一次获取到的列表 -// if (slist.size() == 1 && slist.at(0) == "") { -// if (oldWifiSlist.size() == 1 && oldWifiSlist.at(0) == "") { -// return; -// } else { -// slist = oldWifiSlist; -// } -// } + //if (slist.size() == 1 && slist.at(0) == "") { + // if (oldWifiSlist.size() == 1 && oldWifiSlist.at(0) == "") { + // return; + // } else { + // slist = oldWifiSlist; + // } + //} if (isHuaWeiPC) { if (slist.size() >= 2) { @@ -1734,7 +1734,7 @@ void MainWindow::getWifiListDone(QStringList slist) if (!targetWifiList.isEmpty()) { if (!isWifiReconnecting) { isWifiReconnecting = true; //保证对于连续发出的重连信号,只处理第一个 - QFuture < void > future1 = QtConcurrent::run([=]() { + QtConcurrent::run([=]() { QString wifiSsid = objKyDBus->getWifiSsid(targetWifiList.at(0)); QString modityCmd = "nmcli connection modify \""+ wifiSsid + "\" " + "802-11-wireless.bssid " + targetWifiList.at(1); system(modityCmd.toUtf8().data()); @@ -1803,7 +1803,8 @@ void MainWindow::getConnListDone(QStringList slist) } } -//进行wifi列表优化选择 +//进行wifi列表优化选择,分为2.4G和5G进行选择,先每种频率形成一个列表 +//同一个列表中同名wifi只有一个,再按信号强度由大到小合并列表 void MainWindow::wifiListOptimize(QStringList& slist) { //这个函数可能会把已经连接的那个wifi给筛选出去 @@ -1860,9 +1861,9 @@ void MainWindow::wifiListOptimize(QStringList& slist) targetList<isWifiConfExist(wifiname) && canReconnectWifiList.contains(wifiname)) { //两格以上有配置的5Gwifi中选择信号最佳的 - target << wifiObjectPath <isWifiConfExist(wifiname) && canReconnectWifiList.contains(wifiname)) { + QString tmpPath = "/tmp/kylin-nm-lanprop-" + QDir::home().dirName(); + QString getInfoCmd = "nmcli connection show '" + wifiname + "' > " + tmpPath; + Utils::m_system(getInfoCmd.toUtf8().data()); + QFile file(tmpPath); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + syslog(LOG_ERR, "Can't open the file /tmp/kylin-nm-lanprop in function connectableWifiPriorityList!"); + qDebug()<<"Can't open the file /tmp/kylin-nm-lanprop in function connectableWifiPriorityList!"; + } + QString txt = file.readAll(); + QStringList txtLine = txt.split("\n"); + file.close(); + foreach (QString line, txtLine) { + if (line.startsWith("connection.autoconnect:")) { + wifiAutoConnection = line.mid(25).trimmed(); //connection.autoconnect:有23个字符 + } + if (line.startsWith("connection.autoconnect-priority:")) { + wifiPriority = line.mid(34).trimmed(); //connection.autoconnect-priority:有32个字符 + } + } + + //可以自动回连,则加入列表 + if (wifiAutoConnection == "是" || wifiAutoConnection == "yes") { + selectedWifiList << wifiObjectPath << wifibssid << wifiPriority; + } + } + } + + //再按照wifiPriority进行排序,先简单的选出最高优先级的wifi进行连接 + QStringList targetWifiList; + int maxPos; + int maxPriority = -999; + //选找到最高优先级的那个wifi的位置 + if (selectedWifiList.size() > 1) { + for (int i=0; i+2 < selectedWifiList.size(); i=i+2) { + QString strPriority = selectedWifiList.at(i+2); + int priority = strPriority.toInt(); + if (priority >= maxPriority) { + maxPos = i; + maxPriority = priority; + } + } + } + //将最高优先级的那个wifi信息放入列表中 + targetWifiList.append(selectedWifiList.at(maxPos)); + targetWifiList.append(selectedWifiList.at(maxPos+1)); + targetWifiList.append(selectedWifiList.at(maxPos+2)); + //剩下的暂时不排序,按照原来顺序放入列表中 + if (selectedWifiList.size() > 1) { + for (int i=0; i+2 < selectedWifiList.size(); i=i+2) { + if (i != maxPos) { + targetWifiList.append(selectedWifiList.at(i)); + targetWifiList.append(selectedWifiList.at(i+1)); + targetWifiList.append(selectedWifiList.at(i+2)); + } } } ocf->deleteLater(); - return target; + return targetWifiList; } // 加载wifi列表