diff --git a/src/dbusadaptor.cpp b/src/dbusadaptor.cpp index 66d67a5e..c0653ea5 100644 --- a/src/dbusadaptor.cpp +++ b/src/dbusadaptor.cpp @@ -25,7 +25,13 @@ DbusAdaptor::DbusAdaptor(MainWindow *parent) : QDBusAbstractAdaptor(parent) { // constructor + qDBusRegisterMetaType>(); setAutoRelaySignals(true); + //setAutoRelaySignals(true)后会自动转发同名信号,因此不必再额外像如下代码一样写一个转发 +// connect(parent, &MainWindow::getWifiListFinished, this, [ = ]() { +// QDBusMessage msg = QDBusMessage::createSignal("/com/kylin/network", "com.kylin.network", "getWifiListFinished"); +// QDBusConnection::sessionBus().send(msg); +// }); } DbusAdaptor::~DbusAdaptor() @@ -41,3 +47,13 @@ void DbusAdaptor::showMainWindow() parent()->on_showWindowAction(); } +void DbusAdaptor::requestRefreshWifiList() +{ + parent()->requestRefreshWifiList(); +} + +QVector DbusAdaptor::getWifiList() +{ + return parent()->dbus_wifiList; +} + diff --git a/src/dbusadaptor.h b/src/dbusadaptor.h index 3c547575..093f6d08 100644 --- a/src/dbusadaptor.h +++ b/src/dbusadaptor.h @@ -14,13 +14,15 @@ #include #include +#include QT_BEGIN_NAMESPACE class QByteArray; -template class QList; +//template class QList; template class QMap; class QString; class QStringList; class QVariant; +template class QVector; QT_END_NAMESPACE /* @@ -36,6 +38,11 @@ class DbusAdaptor: public QDBusAbstractAdaptor Q_CLASSINFO("D-Bus Introspection", "" " \n" " \n" +" \n" +" \n" +" \n" +" \n" +" \n" " \n" "") public: @@ -48,7 +55,10 @@ public: public: // PROPERTIES public Q_SLOTS: // METHODS void showMainWindow(); + void requestRefreshWifiList(); + QVector getWifiList(); Q_SIGNALS: // SIGNALS + void getWifiListFinished(); }; #endif diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 304ee068..ae27afa3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2098,6 +2098,7 @@ void MainWindow::loadWifiListDone(QStringList slist) wifiListWidget->resize(W_LIST_WIDGET, H_WIFI_ITEM_BIG_EXTEND); scrollAreaw->setWidget(wifiListWidget); scrollAreaw->move(W_LEFT_AREA, Y_SCROLL_AREA); + dbus_wifiList.clear(); // 获取当前有线网的连接状态,正在连接wifiActState==1,已经连接wifiActState==2, 未连接wifiActState==3 int wifiActState = objKyDBus->checkWifiConnectivity(); //检查wifi的连接状态 @@ -2158,6 +2159,7 @@ void MainWindow::loadWifiListDone(QStringList slist) lbLoadDownImg->hide(); lbLoadUpImg->hide(); ccf->setTopItem(false); + dbus_wifiList.append(QStringList("--")); //没有已连接wifi时,第一个元素为-- } else { QProcess * process = new QProcess; QString name = actWifiName; @@ -2325,8 +2327,12 @@ void MainWindow::loadWifiListDone(QStringList slist) } //ccf->setRate(wrate); - int signal = wsignal.toInt() + 11; - ccf->setSignal(QString::number(signal), wsecu, wcate); + int signal; + if (wsignal.toInt() != 0) + signal = ccf->getSignal(); + else + signal = wsignal.toInt() + 11; + ccf->setSignal(QString::number(signal), wsecu); setTrayIconOfWifi(wsignal.toInt()); activeWifiSignalLv = wsignal.toInt(); //objKyDBus->getWifiMac(wname); @@ -2341,6 +2347,11 @@ void MainWindow::loadWifiListDone(QStringList slist) ccf->setTopItem(false); currSelNetName = ""; syslog(LOG_DEBUG, "already insert an active wifi in the top of wifi list"); + if (m_name.isEmpty() || m_name == "") { + dbus_wifiList.insert(0, QStringList()<resize(W_LIST_WIDGET, wifiListWidget->height() + H_NORMAL_ITEM); @@ -2373,6 +2384,12 @@ void MainWindow::loadWifiListDone(QStringList slist) j ++; count ++; + + if (m_name.isEmpty() || m_name == "") { + dbus_wifiList.append(QStringList()<getWifiListFinished(); } // 更新wifi列表 @@ -2482,6 +2500,17 @@ void MainWindow::updateWifiListDone(QStringList slist) } wifiListWidget->resize(W_LIST_WIDGET, wifiListWidget->height() - H_NORMAL_ITEM); break; + //从向外提供的wifi列表中找到并删除这一行 + QStringList list_to_remove; + foreach (QStringList list, dbus_wifiList) { + if (list.at(0).trimmed() == lastWname) { + list_to_remove = list; + break; + } + } + if (!list_to_remove.isEmpty()) { + dbus_wifiList.removeOne(list_to_remove); + } } } } @@ -2574,6 +2603,11 @@ void MainWindow::updateWifiListDone(QStringList slist) addItem->move(L_VERTICAL_LINE_TO_ITEM, posY); addItem->setSelected(false, false); addItem->show(); + if (m_name.isEmpty() || m_name == "") { + dbus_wifiList.append(QStringList()<wifiListWidget->show(); this->topWifiListWidget->show(); this->stopLoading(); + emit this->getWifiListFinished(); } //用于中英文系统有线网络名称国际话 @@ -3884,6 +3919,11 @@ int MainWindow::getScreenGeometry(QString methodName) return res; } +void MainWindow::requestRefreshWifiList() +{ + this->ksnm->execGetWifiList(this->wcardname); +} + /* get primary screen changed */ void MainWindow::priScreenChanged(int x, int y, int width, int height) { diff --git a/src/mainwindow.h b/src/mainwindow.h index ee10112e..e8a556df 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -185,6 +185,8 @@ public: int addNumberForWifi = 0; //短时间内收到关于wifi连接信号的次数 bool isHuaWeiPC; bool canReconnectWifiTimeInterval = true; + QVector dbus_wifiList; //其他组件通过dbus接口获取到的wifi列表,第一个元素一定为已连接wifi,若没有已连接wifi则显示为-- + void requestRefreshWifiList(); //申请刷新wifi列表 QString currSelNetName = ""; //当前ScrollArea中选中的网络名称 QStringList canReconnectWifiList; //当前可以回连的wifi列表 @@ -403,6 +405,7 @@ signals: void waitLanStop(); void reConnectWifi(const QString& uuid); void actWifiSignalLvChanaged(const int& currentLevel); + void getWifiListFinished(); }; #endif // MAINWINDOW_H diff --git a/src/oneconnform.cpp b/src/oneconnform.cpp index 792540ca..2185cc56 100644 --- a/src/oneconnform.cpp +++ b/src/oneconnform.cpp @@ -52,6 +52,7 @@ OneConnForm::OneConnForm(QWidget *parent, MainWindow *mainWindow, ConfForm *conf ui->lbConned->setAlignment(Qt::AlignLeft); ui->lePassword->setEchoMode(QLineEdit::Normal); ui->lePassword->setContextMenuPolicy(Qt::NoContextMenu); + ui->lePassword->setTextMargins(0,0,24,0); ui->btnConnPWD->setEnabled(false); leQssLow = "QLineEdit{border:none;background:transparent;font-size:14px;}"; @@ -436,6 +437,7 @@ void OneConnForm::setLine(bool isShow) void OneConnForm::setSignal(QString lv, QString secu, QString category) { + this->m_signal = lv.toInt(); int signal = lv.toInt(); if (secu == "--" || secu == "") { hasPwd = false; @@ -499,6 +501,11 @@ void OneConnForm::setSignal(QString lv, QString secu, QString category) ui->lbSignal->setStyleSheet(signalStyle); } +int OneConnForm::getSignal() +{ + return this->m_signal; +} + void OneConnForm::setWifiInfo(QString str1, QString str2, QString str3, int freq) { //freq 0:含2.4G和5G, 1:只有2.4G, 2:只有5G diff --git a/src/oneconnform.h b/src/oneconnform.h index 40e9b020..0319e503 100644 --- a/src/oneconnform.h +++ b/src/oneconnform.h @@ -67,6 +67,7 @@ public: // category:1->normal protocol 1->wifi 6 2->wifi 6+ void setSignal(QString lv, QString secu,QString category = "0"); + int getSignal(); void setWifiName(QString name, QString bssid, QString uuid, QString isname, bool isHW); QString getName(); void setRate(QString rate); @@ -97,6 +98,7 @@ public: bool isConnected; bool isTopItem; int signalLv; + int m_signal; public slots: void waitAnimStep();