feat(wifi): Add dbus interface to provide wifi list to ukui-control-center.

Description: 新增dbus接口来为控制面板提供wifi列表

Log: 新增dbus接口来为控制面板提供wifi列表
This commit is contained in:
zhangjiaping 2021-05-08 13:39:47 +08:00
parent d2ef240613
commit cdf48d19de
6 changed files with 80 additions and 3 deletions

View File

@ -25,7 +25,13 @@ DbusAdaptor::DbusAdaptor(MainWindow *parent)
: QDBusAbstractAdaptor(parent)
{
// constructor
qDBusRegisterMetaType<QVector<QStringList>>();
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<QStringList> DbusAdaptor::getWifiList()
{
return parent()->dbus_wifiList;
}

View File

@ -14,13 +14,15 @@
#include <QtCore/QObject>
#include <QtDBus/QtDBus>
#include <QtDBus/QDBusMetaType>
QT_BEGIN_NAMESPACE
class QByteArray;
template<class T> class QList;
//template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
class QStringList;
class QVariant;
template<class T> class QVector;
QT_END_NAMESPACE
/*
@ -36,6 +38,11 @@ class DbusAdaptor: public QDBusAbstractAdaptor
Q_CLASSINFO("D-Bus Introspection", ""
" <interface name=\"com.kylin.network\">\n"
" <method name=\"showMainWindow\"/>\n"
" <method name=\"requestRefreshWifiList\"/>\n"
" <method name=\"getWifiList\">\n"
" <arg type=\"av\" direction=\"out\"/>\n"
" </method>\n"
" <signal name=\"getWifiListFinished\"/>\n"
" </interface>\n"
"")
public:
@ -48,7 +55,10 @@ public:
public: // PROPERTIES
public Q_SLOTS: // METHODS
void showMainWindow();
void requestRefreshWifiList();
QVector<QStringList> getWifiList();
Q_SIGNALS: // SIGNALS
void getWifiListFinished();
};
#endif

View File

@ -2099,6 +2099,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的连接状态
@ -2159,6 +2160,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;
@ -2326,8 +2328,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);
@ -2342,6 +2348,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()<<wname<<wsignal<<wsecu<<QString::number(max_freq)<<QString::number(min_freq)<<wcate);
} else {
dbus_wifiList.insert(0, QStringList()<<m_name<<wsignal<<wsecu<<QString::number(max_freq)<<QString::number(min_freq)<<wcate);
}
} else {
//对于未连接的wifi
wifiListWidget->resize(W_LIST_WIDGET, wifiListWidget->height() + H_NORMAL_ITEM);
@ -2375,6 +2386,12 @@ void MainWindow::loadWifiListDone(QStringList slist)
j ++;
count ++;
if (m_name.isEmpty() || m_name == "") {
dbus_wifiList.append(QStringList()<<wname<<wsignal<<wsecu<<QString::number(max_freq)<<QString::number(min_freq)<<wcate);
} else {
dbus_wifiList.append(QStringList()<<m_name<<wsignal<<wsecu<<QString::number(max_freq)<<QString::number(min_freq)<<wcate);
}
}
wnames.append(wname);
@ -2411,6 +2428,7 @@ void MainWindow::loadWifiListDone(QStringList slist)
actWifiBssidList.clear();
wnames.clear();
emit this->getWifiListFinished();
}
// 更新wifi列表
@ -2484,6 +2502,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);
}
}
}
}
@ -2576,6 +2605,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()<<wname<<wsignal<<wsecu<<QString::number(max_freq)<<QString::number(min_freq)<<wcate);
} else {
dbus_wifiList.append(QStringList()<<m_name<<wsignal<<wsecu<<QString::number(max_freq)<<QString::number(min_freq)<<wcate);
}
count += 1;
}
@ -2587,6 +2621,7 @@ void MainWindow::updateWifiListDone(QStringList slist)
this->wifiListWidget->show();
this->topWifiListWidget->show();
this->stopLoading();
emit this->getWifiListFinished();
}
//用于中英文系统有线网络名称国际话
@ -3886,6 +3921,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)
{

View File

@ -185,6 +185,8 @@ public:
int addNumberForWifi = 0; //短时间内收到关于wifi连接信号的次数
bool isHuaWeiPC;
bool canReconnectWifiTimeInterval = true;
QVector<QStringList> 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

View File

@ -435,6 +435,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;
@ -491,6 +492,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

View File

@ -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 setName(QString name, QString bssid, QString uuid, QString isname);
QString getName();
void setRate(QString rate);
@ -96,6 +97,7 @@ public:
bool isConnected;
bool isTopItem;
int signalLv;
int m_signal;
public slots:
void waitAnimStep();