From 45835db3d925c378f51e4ef5e4b45d560cb28046 Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Wed, 16 Dec 2020 15:50:57 +0800 Subject: [PATCH] feat(wifi-freq): Add freq label to each wifi. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description: 给所有的wifi添加频率标签 Log: 给所有的wifi添加频率标签 --- src/mainwindow.cpp | 27 +++++++++++++++++---- src/oneconnform.cpp | 59 +++++++++++++++++++++++++++++---------------- src/oneconnform.h | 7 +++++- src/oneconnform.ui | 19 +-------------- 4 files changed, 67 insertions(+), 45 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d4f6be1b..c9942274 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1591,7 +1591,7 @@ void MainWindow::loadWifiListDone(QStringList slist) for (int i = 1, j = 0; i < slist.size(); i ++) { QString line = slist.at(i); QString wsignal = line.mid(0, indexSecu).trimmed(); - QString wsecu = line.mid(indexSecu, indexName - indexSecu).trimmed(); + QString wsecu = line.mid(indexSecu, indexFreq - indexSecu).trimmed(); QString wname = line.mid(indexName).trimmed(); QString wfreq = line.mid(indexFreq, 4).trimmed(); bool isContinue = false; @@ -1612,6 +1612,14 @@ void MainWindow::loadWifiListDone(QStringList slist) } } } + int freqState = 0; + if (max_freq < 3000) { + //只有2.4GHZ + freqState = 1; + } else if (min_freq >= 5000) { + //只有5GHZ + freqState = 2; + } if (wname != "" && wname != "--") { // 当前连接的wifi if (wname == actWifiName) { @@ -1622,7 +1630,7 @@ void MainWindow::loadWifiListDone(QStringList slist) ccf->setSignal(wsignal, wsecu); activeWifiSignalLv = wsignal.toInt(); objKyDBus->getWifiMac(wname); - ccf->setWifiInfo(wsecu, wsignal, objKyDBus->dbusWifiMac, ((max_freq > 5000) && (min_freq < 3000))); + ccf->setWifiInfo(wsecu, wsignal, objKyDBus->dbusWifiMac, freqState); ccf->setConnedString(1, tr("NetOn,"), wsecu);//"已连接" ccf->isConnected = true; ifWLanConnected = true; @@ -1644,7 +1652,7 @@ void MainWindow::loadWifiListDone(QStringList slist) ocf->setLine(true); ocf->setSignal(wsignal, wsecu); objKyDBus->getWifiMac(wname); - ocf->setWifiInfo(wsecu, wsignal, objKyDBus->dbusWifiMac, ((max_freq > 5000) && (min_freq < 3000))); + ocf->setWifiInfo(wsecu, wsignal, objKyDBus->dbusWifiMac, freqState); ocf->setConnedString(0, tr("Disconnected"), wsecu); ocf->move(L_VERTICAL_LINE_TO_ITEM, j * H_NORMAL_ITEM); ocf->setSelected(false, false); @@ -1753,7 +1761,7 @@ void MainWindow::updateWifiListDone(QStringList slist) for(int i = 1; i < slist.size(); i++){ QString line = slist.at(i); QString wsignal = line.mid(0, indexSecu).trimmed(); - QString wsecu = line.mid(indexSecu, indexName - indexSecu).trimmed(); + QString wsecu = line.mid(indexSecu, indexFreq - indexSecu).trimmed(); QString wname = line.mid(indexName).trimmed(); QString wfreq = line.mid(indexFreq, 4).trimmed(); @@ -1778,6 +1786,15 @@ void MainWindow::updateWifiListDone(QStringList slist) } } + int freqState = 0; + if (max_freq < 3000) { + //只有2.4GHZ + freqState = 1; + } else if (min_freq >= 5000) { + //只有5GHZ + freqState = 2; + } + wnames.append(wname); for (int j=1; j < oldWifiSlist.size(); j++) { @@ -1807,7 +1824,7 @@ void MainWindow::updateWifiListDone(QStringList slist) addItem->setLine(false); addItem->setSignal(wsignal, wsecu); objKyDBus->getWifiMac(wname); - addItem->setWifiInfo(wsecu, wsignal, objKyDBus->dbusWifiMac, ((max_freq > 5000) && (min_freq < 3000))); + addItem->setWifiInfo(wsecu, wsignal, objKyDBus->dbusWifiMac, freqState); addItem->setConnedString(0, tr("Disconnected"), wsecu);//"未连接" addItem->move(L_VERTICAL_LINE_TO_ITEM, posY); addItem->setSelected(false, false); diff --git a/src/oneconnform.cpp b/src/oneconnform.cpp index 7dc2b1a4..597eaeef 100644 --- a/src/oneconnform.cpp +++ b/src/oneconnform.cpp @@ -136,9 +136,18 @@ OneConnForm::OneConnForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf connect(mw, SIGNAL(waitWifiStop()), this, SLOT(stopWaiting())); connType = ""; - - ui->fiveGlabel->hide(); - ui->fiveGlabel->setStyleSheet("QLabel{background-color: palette(button); border-radius: 4px;}"); + lbNameLyt = new QHBoxLayout(ui->lbName); + lbFreq = new QLabel(ui->lbName); + lbFreq->setAlignment(Qt::AlignCenter); + lbFreq->setEnabled(false); + lbFreq->setStyleSheet("QLabel{border: 1px solid rgba(0, 0, 0, 0.5); background: transparent; color: rgba(0, 0, 0, 0.5); border-radius: 4px; font-size: 12px;}"); + lbNameText = new QLabel(ui->lbName); + lbNameLyt->setContentsMargins(0, 0, 0, 0); + lbNameLyt->setSpacing(4); + lbNameLyt->addWidget(lbNameText); + lbNameLyt->addWidget(lbFreq); + lbNameLyt->addStretch(); + ui->lbName->setLayout(lbNameLyt); } OneConnForm::~OneConnForm() @@ -345,18 +354,18 @@ void OneConnForm::setConnedString(bool showLable, QString str, QString str1) void OneConnForm::setName(QString name) { - ui->lbName->setText(name); + lbNameText->setText(name); wifiName = name; } void OneConnForm::setSpecialName(QString name) { - ui->lbName->setText(tr("Connect to Hidden Wi-Fi Network")); //连接到隐藏的 Wi-Fi 网络 + lbNameText->setText(tr("Connect to Hidden Wi-Fi Network")); //连接到隐藏的 Wi-Fi 网络 wifiName = name; } QString OneConnForm::getName() { - return ui->lbName->text(); + return lbNameText->text(); } void OneConnForm::setRate(QString rate) @@ -426,10 +435,18 @@ void OneConnForm::setSignal(QString lv, QString secu) } } -void OneConnForm::setWifiInfo(QString str1, QString str2, QString str3, bool is_double_freq) +void OneConnForm::setWifiInfo(QString str1, QString str2, QString str3, int freq) { - if (is_double_freq) { - ui->fiveGlabel->show(); + //freq 0:含2.4G和5G, 1:只有2.4G, 2:只有5G + if (freq == 1) { + //freq ~ 2.4G + lbFreq->setText("2.4G"); + } else if (freq == 2) { + //freq ~ 5G + lbFreq->setText("5G"); + } else { + //freq ~ 5G&2.4G + lbFreq->setText("2.4/5G"); } if (str1 == "--" || str1 == ""){ str1 = tr("None"); }; @@ -446,25 +463,25 @@ void OneConnForm::setWifiInfo(QString str1, QString str2, QString str3, bool is_ void OneConnForm::slotConnWifi() { this->startWaiting(true); - emit sigConnWifi(ui->lbName->text()); + emit sigConnWifi(lbNameText->text()); } void OneConnForm::slotConnWifiPWD() { this->startWaiting(true); - emit sigConnWifiPWD(ui->lbName->text(), ui->lePassword->text(), connType); + emit sigConnWifiPWD(lbNameText->text(), ui->lePassword->text(), connType); } //点击后断开wifi网络 void OneConnForm::on_btnDisConn_clicked() { - syslog(LOG_DEBUG, "DisConnect button about wifi net is clicked, current wifi name is %s .", ui->lbName->text().toUtf8().data()); - qDebug()<<"DisConnect button about wifi net is clicked, current wifi name is "<lbName->text(); + syslog(LOG_DEBUG, "DisConnect button about wifi net is clicked, current wifi name is %s .", lbNameText->text().toUtf8().data()); + qDebug()<<"DisConnect button about wifi net is clicked, current wifi name is "<text(); this->startWaiting(false); mw->is_stop_check_net_state = 1; mw->on_btnHotspotState(); - kylin_network_set_con_down(ui->lbName->text().toUtf8().data()); + kylin_network_set_con_down(lbNameText->text().toUtf8().data()); disconnect(this, SIGNAL(selectedOneWifiForm(QString,int)), mw, SLOT(oneWifiFormSelected(QString,int))); emit disconnActiveWifi(); } @@ -521,7 +538,7 @@ void OneConnForm::toConnectWirelessNetwork() return; } if (ui->lbConned->text() == "--" || ui->lbConned->text() == " ") { - if (!isWifiConfExist(ui->lbName->text())) { + if (!isWifiConfExist(lbNameText->text())) { //没有配置文件,使用有密码的wifi连接 on_btnConnPWD_clicked(); return; @@ -654,7 +671,7 @@ void OneConnForm::on_btnInfo_clicked() } BackThread *bt = new BackThread(); - QString connProp = bt->getConnProp(ui->lbName->text()); + QString connProp = bt->getConnProp(lbNameText->text()); QStringList propList = connProp.split("|"); QString v4method, addr, mask, gateway, dns; foreach (QString line, propList) { @@ -676,7 +693,7 @@ void OneConnForm::on_btnInfo_clicked() } // qDebug()<<"v4method:"<setProp(ui->lbName->text(), "--", v4method, addr, mask, gateway, dns, this->isActive, true); + cf->setProp(lbNameText->text(), "--", v4method, addr, mask, gateway, dns, this->isActive, true); cf->move(primaryGeometry.width() / 2 - cf->width() / 2, primaryGeometry.height() / 2 - cf->height() / 2); cf->exec(); cf->raise(); @@ -690,14 +707,14 @@ void OneConnForm::slotConnWifiResult(int connFlag) qDebug()<<"Function slotConnWifiResult receives a number: "<lbName->text() + " wifi-sec.psk-flags 2"; + QString strConntype = "nmcli connection modify " + lbNameText->text() + " wifi-sec.psk-flags 2"; system(strConntype.toUtf8().data()); } connType = ""; if (connFlag == 2 || connFlag == 4) { mw->currSelNetName = ""; - emit selectedOneWifiForm(ui->lbName->text(), H_WIFI_ITEM_SMALL_EXTEND); + emit selectedOneWifiForm(lbNameText->text(), H_WIFI_ITEM_SMALL_EXTEND); resize(W_ITEM, H_ITEM_MIDDLE); ui->wbg->hide(); @@ -732,12 +749,12 @@ void OneConnForm::slotConnWifiResult(int connFlag) if (connFlag == 1) { // 使用配置文件连接失败,需要删除该配置文件 QString txt(tr("Conn Wifi Failed"));//"连接 Wifi 失败" - syslog(LOG_DEBUG, "Try to connect wifi named %s, but failed, will delete it's configuration file", ui->lbName->text().toUtf8().data()); + syslog(LOG_DEBUG, "Try to connect wifi named %s, but failed, will delete it's configuration file", lbNameText->text().toUtf8().data()); KylinDBus kylindbus; kylindbus.showDesktopNotify(txt); //QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection delete '" + ui->lbName->text() + "';notify-send '" + txt + "...' -t 3800"; - QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection delete '" + ui->lbName->text() + "'"; + QString cmd = "export LANG='en_US.UTF-8';export LANGUAGE='en_US';nmcli connection delete '" + lbNameText->text() + "'"; int status = system(cmd.toUtf8().data()); if (status != 0) { syslog(LOG_ERR, "execute 'nmcli connection delete' in function 'slotConnWifiResult' failed"); diff --git a/src/oneconnform.h b/src/oneconnform.h index ccf1a140..a33947ca 100644 --- a/src/oneconnform.h +++ b/src/oneconnform.h @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "confform.h" #include "backthread.h" @@ -68,7 +70,7 @@ public: QString getName(); void setRate(QString rate); void setLine(bool isShow); - void setWifiInfo(QString str1, QString str2, QString str3, bool is_double_freq); + void setWifiInfo(QString str1, QString str2, QString str3, int freq); void setSelected(bool isSelected, bool isCurrName); void setHideItem(bool isHideItem, bool isShowHideBtn); @@ -131,6 +133,9 @@ private: bool hasPwd; QString leQssLow, leQssHigh; + QLabel * lbFreq = nullptr; + QLabel * lbNameText = nullptr; + QHBoxLayout * lbNameLyt = nullptr; signals: void selectedOneWifiForm(QString wifiName, int extendLength); diff --git a/src/oneconnform.ui b/src/oneconnform.ui index 0ab736cf..ea23a959 100644 --- a/src/oneconnform.ui +++ b/src/oneconnform.ui @@ -18,7 +18,7 @@ 63 8 - 190 + 200 20 @@ -259,22 +259,6 @@ - - - - 255 - 17 - 50 - 20 - - - - 2.4/5G - - - Qt::AlignCenter - - wbg_3 wbg_2 lbName @@ -289,7 +273,6 @@ btnHideConn lbWaiting lbWaitingIcon - fiveGlabel