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

View File

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

View File

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

View File

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

View File

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