Merge pull request #137 from mammonsama666/0517-dev

fix bugs
This commit is contained in:
chenlelin 2021-05-17 19:14:48 +08:00 committed by GitHub
commit 6f2886c858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 51 deletions

View File

@ -950,10 +950,10 @@ void MainWindow::getActiveInfoAndSetTrayIcon()
setTrayLoading(true);
}
} else if (actWifiName != "--") {
} else if (actWifiName != "--" && activeWifiSignalLv != 0) {
setTrayIconOfWifi(activeWifiSignalLv);
emit this->actWifiSignalLvChanaged(activeWifiSignalLv);
} else {
} else if (actWifiName == "--") {
setTrayIcon(iconLanOffline);
}
}
@ -1634,7 +1634,6 @@ void MainWindow::getLanListDone(QStringList slist)
} else {
ccfAct->setLine(false); //最后一个item不显示下划线
}
if (!objKyDBus->dbusLanIpv4.isEmpty()) {
if (!objKyDBus->dbusActiveLanIpv4.isEmpty() && objKyDBus->dbusActiveLanIpv4 != objKyDBus->dbusLanIpv4) {
// qDebug() << Q_FUNC_INFO << __LINE__ << objKyDBus->dbusActiveLanIpv4 << objKyDBus->dbusLanIpv4;
@ -1651,6 +1650,16 @@ void MainWindow::getLanListDone(QStringList slist)
objKyDBus->reConnectWiredNet(nuuid);
emit this->configurationChanged();
}
actLanUuid = nuuid;
actLanIpv4Method = "manual";
} else {
//已连接WiFi未改变但IP获取方式改变重连之
if (actLanUuid == nuuid && actLanIpv4Method == "manual") {
objKyDBus->reConnectWiredNet(nuuid);
emit this->configurationChanged();
}
actLanUuid = nuuid;
actLanIpv4Method = "auto";
}
currSelNetName = "";
@ -1749,16 +1758,20 @@ void MainWindow::getWifiListDone(QStringList slist)
}
if (current_wifi_list_state == RECONNECT_WIFI) {
qDebug()<<"======优选后的列表为======";
foreach (QString line, slist) {
qDebug()<<line;
}
qDebug()<<"========================";
QVector<structWifiProperty> targetWifiStructList = connectableWifiPriorityList(slist);
if (!targetWifiStructList.isEmpty()) {
if (!isReconnectingWifi) {
isReconnectingWifi = true; //保证对于连续发出的重连信号,只处理第一个
QtConcurrent::run([=]() {
QString wifiSsid = objKyDBus->getWifiSsid(targetWifiStructList.at(0).objectPath);
QString modityCmd = "nmcli connection modify \""+ wifiSsid + "\" " + "802-11-wireless.bssid " + targetWifiStructList.at(0).bssid;
qDebug()<<"Will modify configuration for "<<wifiSsid<<"; cmd = "<<modityCmd;
int res = system(modityCmd.toUtf8().data());
qDebug()<<"Modifination finished, res = "<<res;
QString modifyCmd = "nmcli connection modify \""+ wifiSsid + "\" " + "802-11-wireless.bssid " + targetWifiStructList.at(0).bssid;
int res = system(modifyCmd.toUtf8().data());
qDebug()<<"Modification finished, cmd = "<<modifyCmd<<". res = "<<res;
// QString reconnectWifiCmd = "nmcli connection up \"" + wifiSsid + "\"";
// system(reconnectWifiCmd.toUtf8().data());
canReconnectWifiTimeInterval = false;
@ -2023,7 +2036,7 @@ void MainWindow::wifiListOptimize(QStringList& slist)
if (slist.size() < 2) return ;
QString headLine = slist.at(0);
int indexSignal, indexSecu, indexFreq, indexBSsid, indexName, indexPath;
int indexSignal, indexSecu, indexFreq, indexBSsid, indexName, indexPath, indexCate;
headLine = headLine.trimmed();
bool isChineseExist = headLine.contains(QRegExp("[\\x4e00-\\x9fa5]+"));
if (isChineseExist) {
@ -2032,6 +2045,7 @@ void MainWindow::wifiListOptimize(QStringList& slist)
indexFreq = headLine.indexOf("频率") + 4;
indexBSsid = headLine.indexOf("BSSID") + 6;
indexPath = headLine.indexOf("DBUS-PATH");
indexCate = headLine.indexOf("CATEGORY");
indexName = headLine.lastIndexOf("SSID");
} else {
indexSignal = headLine.indexOf("SIGNAL");
@ -2039,69 +2053,71 @@ void MainWindow::wifiListOptimize(QStringList& slist)
indexFreq = headLine.indexOf("FREQ");
indexBSsid = headLine.indexOf("BSSID");
indexPath = headLine.indexOf("DBUS-PATH");
indexCate = headLine.indexOf("CATEGORY");
indexName = headLine.lastIndexOf("SSID");
}
QStringList targetList; //slist优化同名同频AP中只留信号最强
QStringList targetList; //slist优化同名同频同类别(category)AP中只留信号最强
targetList<<slist.at(0); //把第一行加进去
hasStarWifiInfo = "";
hasStarWifiName = "";
// hasStarWifiInfo = "";
// hasStarWifiName = "";
for (int ii = 1;ii < slist.size();ii++) {
if ((ii+1) == slist.size()) {
break;
}
QString currentWifiInfo = slist.at(ii);
bool ifContinue = false;
bool isConnected = false;
QString conName = currentWifiInfo.mid(indexName).trimmed();
int conSignal = currentWifiInfo.mid(indexSignal,3).trimmed().toInt();
// int conSignal = currentWifiInfo.mid(indexSignal,3).trimmed().toInt();
int conFreq = currentWifiInfo.mid(indexFreq,4).trimmed().toInt();
int conCate = currentWifiInfo.mid(indexCate,1).trimmed().toInt();
if ("*" == currentWifiInfo.mid(0,indexSignal).trimmed()) {
hasStarWifiInfo = currentWifiInfo;
hasStarWifiName = conName;
// hasStarWifiInfo = currentWifiInfo;
// hasStarWifiName = conName;
isConnected = true;
}
for (int jj=1;jj<slist.size();jj++) {
for (int jj=1;jj<ii;jj++) {//仅与排在它前面的wifi比较即可
QString compareWifiInfo = slist.at(jj);
QString name = compareWifiInfo.mid(indexName).trimmed();
int signal = compareWifiInfo.mid(indexSignal,3).trimmed().toInt();
// int signal = compareWifiInfo.mid(indexSignal,3).trimmed().toInt();
int freq = compareWifiInfo.mid(indexFreq,4).trimmed().toInt();
int category = compareWifiInfo.mid(indexCate,1).trimmed().toInt();
if (conName == name) {
if (conFreq < 5000 && freq < 5000) {
if(conSignal < signal){
ifContinue = true;
break;
}
if (conFreq < 5000 && freq < 5000 && conCate == category) {
//若前面有同频同category的同名wifi它的信号一定比此wifi强
ifContinue = true;
break;
}
if (conFreq >= 5000 && freq >= 5000) {
if (conSignal < signal) {
ifContinue = true;
break;
}
if (conFreq >= 5000 && freq >= 5000 && conCate == category) {
ifContinue = true;
break;
}
}
}
if (ifContinue) continue;
if (ifContinue && !isConnected) continue;
targetList << currentWifiInfo;
}
//上面的选网方法容易把存在同名wifi的情况下把已经连接的那个wifi给去掉
//在这种情况下把连接的wifi信息加回去
int changePosition = 100000;
for (int kk=1;kk<targetList.size();kk++) {
QString wifiInfo = slist.at(kk);
QString wifiName = wifiInfo.mid(indexName).trimmed();
if (hasStarWifiName == wifiName) {
changePosition = kk;
break;
}
}
// //上面的选网方法容易把存在同名wifi的情况下把已经连接的那个wifi给去掉
// //在这种情况下把连接的wifi信息加回去
// int changePosition = 100000;
// for (int kk=1;kk<targetList.size();kk++) {
// QString wifiInfo = slist.at(kk);
// QString wifiName = wifiInfo.mid(indexName).trimmed();
// if (hasStarWifiName == wifiName) {
// changePosition = kk;
// break;
// }
// }
if (changePosition < 100000) {
//证明确实有已经连接的wifi被去掉了
targetList.replace(changePosition, hasStarWifiInfo);
}
// if (changePosition < 100000) {
// //证明确实有已经连接的wifi被去掉了
// targetList.replace(changePosition, hasStarWifiInfo);
// }
slist = targetList;
}
@ -2206,12 +2222,12 @@ QVector<structWifiProperty> MainWindow::connectableWifiPriorityList(const QStrin
QString wifiname = line.mid(indexName).trimmed();
QString wifibssid = line.mid(indexBSsid, indexPath-indexBSsid).trimmed();
QString wifiObjectPath = line.mid(indexPath,indexCate-indexPath).trimmed();
QString wifiAutoConnection;
QString wifiAutoConnection = "no";
QString wifiPriority;
if (ocf->isWifiConfExist(wifiname) && canReconnectWifiList.contains(wifiname)) {
QString tmpPath = "/tmp/kylin-nm-lanprop-" + QDir::home().dirName();
QString getInfoCmd = "nmcli connection show '" + wifiname + "' > " + tmpPath;
QString getInfoCmd = "nmcli -f connection.autoconnect,connection.autoconnect-priority connection show '" + wifiname + "' > " + tmpPath;
Utils::m_system(getInfoCmd.toUtf8().data());
QFile file(tmpPath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {

View File

@ -318,6 +318,8 @@ private:
bool m_isWifiConnected = false; //专用于处理dbus获取的WiFi状态用于对比每次刷新后的WiFi连接状态变化
QString lastAddedConn = "";
QString oldActLanName = ""; //上一次获取的已连接有线网名称
QString actLanUuid = ""; //当前连接的有线网uuid
QString actLanIpv4Method = ""; //当前连接的有线网的ip获取方式
int oldDbusActLanDNS = 0; //上一次获取的已连接有线网的DNS代号
void wifiListOptimize(QStringList& slist); //只保留同名同频信号最优AP
QVector<QStringList> repetitionFilter(QVector<QStringList>);
@ -351,8 +353,8 @@ private:
QString actWifiSsid = "--"; //当前连接wifi的ssid
QStringList actWifiBssidList; //当前连接wifi的bssid
QString actWifiUuid = "--"; //当前连接wifi的uuid
QString hasStarWifiInfo; //nmcli命令获取的wifi列表中已经连接的wifi in-use熟悉会有一个*
QString hasStarWifiName;
// QString hasStarWifiInfo; //nmcli命令获取的wifi列表中已经连接的wifi in-use熟悉会有一个*
// QString hasStarWifiName;
bool hasWifiConnected;//当前是否有wifi连接
QDBusInterface *mDbusXrandInter;
@ -411,7 +413,7 @@ signals:
void refreshWifiListAfterScan();
void carrierDownHandle();
void waitLanStop();
void configurationChanged();
void configurationChanged(); //通知控制面板更新IP的信号
void reConnectWifi(const QString& uuid);
void actWifiSignalLvChanaged(const int& currentLevel);
void getWifiListFinished();

View File

@ -130,7 +130,8 @@ WpaWifiDialog::~WpaWifiDialog()
void WpaWifiDialog::initUI() {
mainWidget = new QWidget(this);
mainLyt = new QVBoxLayout(mainWidget);
mainWidget->setFixedSize(360, 590);
mainWidget->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_PEAP);
this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_PEAP);
titleFrame = new QFrame(mainWidget); //标题栏
titleFrame->setFixedHeight(48);
@ -222,7 +223,7 @@ void WpaWifiDialog::initUI() {
userFrame->setLayout(userLyt);
pwdFrame = new QFrame(); //密码
pwdFrame->setFixedHeight(96);
pwdFrame->setFixedHeight(72);
pwdLyt = new QVBoxLayout(pwdFrame);
pwdLyt->setContentsMargins(0, 0, 0, 0);
pwdLyt->setSpacing(0);
@ -878,15 +879,23 @@ void WpaWifiDialog::eapTypeChange()
mainLyt->addWidget(m_UserCertificateFrame);
mainLyt->addWidget(m_UserPrivateKeyFrame);
mainLyt->addWidget(m_pwd4PrivateKeyPWDFrame);
mainWidget->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_TLP);
this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_TLP);
break;
case EapType::LEAP:
// Todo
mainWidget->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_ELSE);
this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_ELSE);
break;
case EapType::PWD:
// Todo
mainWidget->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_ELSE);
this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_ELSE);
break;
case EapType::FAST:
// Todo
mainWidget->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_ELSE);
this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_ELSE);
break;
case EapType::TTLS:
// Todo
@ -899,12 +908,16 @@ void WpaWifiDialog::eapTypeChange()
mainLyt->addWidget(userFrame);
mainLyt->addWidget(pwdFrame);
*/
mainWidget->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_ELSE);
this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_ELSE);
break;
case EapType::PEAP:
// 需要抽离的
mainLyt->addWidget(innerFrame);
mainLyt->addWidget(userFrame);
mainLyt->addWidget(pwdFrame);
mainWidget->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_PEAP);
this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_PEAP);
break;
default: // TLS
mainLyt->addWidget(m_identityFrame);
@ -913,6 +926,8 @@ void WpaWifiDialog::eapTypeChange()
mainLyt->addWidget(m_UserCertificateFrame);
mainLyt->addWidget(m_UserPrivateKeyFrame);
mainLyt->addWidget(m_pwd4PrivateKeyPWDFrame);
mainWidget->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_TLP);
this->setFixedSize(WINDOW_WIDTH, WINDOW_HEIGHT_TLP);
break;
}

View File

@ -38,6 +38,11 @@
#include <QModelIndex>
#include <QList>
#define WINDOW_WIDTH 360
#define WINDOW_HEIGHT_PEAP 540
#define WINDOW_HEIGHT_TLP 670
#define WINDOW_HEIGHT_ELSE 360
class MainWindow;
typedef QList<QObject*> QObjectList;

View File

@ -13,13 +13,13 @@
<property name="minimumSize">
<size>
<width>360</width>
<height>660</height>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>360</width>
<height>660</height>
<height>680</height>
</size>
</property>
<property name="windowTitle">