Merge pull request #129 from mammonsama666/0507-dev

feat(wifi): Add dbus interface to provide wifi list to ukui-control-center.
This commit is contained in:
chenlelin 2021-05-08 21:43:10 +08:00 committed by GitHub
commit 1c791e182c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 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

@ -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()<<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);
@ -2373,6 +2384,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);
@ -2409,6 +2426,7 @@ void MainWindow::loadWifiListDone(QStringList slist)
actWifiBssidList.clear();
wnames.clear();
emit this->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()<<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;
}
@ -2585,6 +2619,7 @@ void MainWindow::updateWifiListDone(QStringList slist)
this->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)
{

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

@ -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

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 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();