Feature: Add inactivce wlan item & watch activated wlan changed.
This commit is contained in:
parent
8482baf418
commit
366ca11334
|
@ -9,6 +9,14 @@ WlanListItem::WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *d
|
||||||
initWlanConnection();
|
initWlanConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WlanListItem::WlanListItem(QWidget *parent) : ListItem(parent)
|
||||||
|
{
|
||||||
|
m_netButton->setIcon(QIcon::fromTheme("network-wireless-signal-none-symbolic", QIcon(":/res/w/wifi-none.png")));
|
||||||
|
const QString str="未连接任何wifi";
|
||||||
|
setExpanded(false);
|
||||||
|
this->setName(str);
|
||||||
|
}
|
||||||
|
|
||||||
WlanListItem::~WlanListItem()
|
WlanListItem::~WlanListItem()
|
||||||
{
|
{
|
||||||
disconnect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanListItem::onSecurityChanged);
|
disconnect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanListItem::onSecurityChanged);
|
||||||
|
@ -108,6 +116,7 @@ void WlanListItem::onNetButtonClicked()
|
||||||
{
|
{
|
||||||
//ZJP_TODO 点击连接/断开
|
//ZJP_TODO 点击连接/断开
|
||||||
qDebug() << "On wlan clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." <<Q_FUNC_INFO << __LINE__;
|
qDebug() << "On wlan clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." <<Q_FUNC_INFO << __LINE__;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WlanListItem::onSecurityChanged(QString interface, QString ssid, QString securityType)
|
void WlanListItem::onSecurityChanged(QString interface, QString ssid, QString securityType)
|
||||||
|
|
|
@ -12,6 +12,7 @@ class WlanListItem : public ListItem
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QWidget *parent = nullptr);
|
WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QWidget *parent = nullptr);
|
||||||
|
WlanListItem(QWidget *parent = nullptr);
|
||||||
~WlanListItem();
|
~WlanListItem();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -40,6 +40,7 @@ void TabPage::initUI()
|
||||||
m_activatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
m_activatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
|
||||||
m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
|
||||||
m_activatedNetListWidget->setSpacing(NET_LIST_SPACING);
|
m_activatedNetListWidget->setSpacing(NET_LIST_SPACING);
|
||||||
|
m_activatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
m_activatedNetLayout->addWidget(m_activatedNetLabel);
|
m_activatedNetLayout->addWidget(m_activatedNetLabel);
|
||||||
m_activatedNetLayout->addWidget(m_activatedNetListWidget);
|
m_activatedNetLayout->addWidget(m_activatedNetListWidget);
|
||||||
m_activatedNetDivider = new Divider(this);
|
m_activatedNetDivider = new Divider(this);
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
|
WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
|
||||||
{
|
{
|
||||||
m_resource = new KyWirelessNetResource(this);
|
m_resource = new KyWirelessNetResource(this);
|
||||||
|
m_connectResource = new KyActiveConnectResourse();
|
||||||
|
getDevice();
|
||||||
initWlanUI();
|
initWlanUI();
|
||||||
initConnections();
|
initConnections();
|
||||||
getActiveWlan();
|
getActiveWlan();
|
||||||
|
@ -72,7 +74,22 @@ void WlanPage::initConnections()
|
||||||
{
|
{
|
||||||
connect(m_resource, &KyWirelessNetResource::wifiNetworkAdd, this, &WlanPage::onWlanAdded);
|
connect(m_resource, &KyWirelessNetResource::wifiNetworkAdd, this, &WlanPage::onWlanAdded);
|
||||||
connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::onWlanRemoved);
|
connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::onWlanRemoved);
|
||||||
connect(m_resource, &KyWirelessNetResource::wifiNetworkUpdate, this, &WlanPage::onWlanUpdated);
|
// connect(m_resource, &KyWirelessNetResource::wifiNetworkUpdate, this, &WlanPage::onWlanUpdated);
|
||||||
|
connect(m_connectResource, &KyActiveConnectResourse::stateChangeReason, this, &WlanPage::onActivatedWlanChanged);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WlanPage::getDevice()
|
||||||
|
{
|
||||||
|
QMap<QString, QList<KyWirelessNetItem> > map;
|
||||||
|
if (!m_resource->getAllDeviceWifiNetwork(map)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_wlanDevice = map.begin().key();
|
||||||
|
if (m_wlanDevice.isEmpty()) {
|
||||||
|
m_wlanDevice = "wlx5841207b85f0";
|
||||||
|
} else {
|
||||||
|
qDebug() << "Get device successfully, its name is " << m_wlanDevice <<Q_FUNC_INFO << __LINE__;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -86,12 +103,12 @@ void WlanPage::getActiveWlan()
|
||||||
QMap<QString,QStringList>::iterator iter = actMap.begin();
|
QMap<QString,QStringList>::iterator iter = actMap.begin();
|
||||||
int height = 0;
|
int height = 0;
|
||||||
while (iter != actMap.end()) {
|
while (iter != actMap.end()) {
|
||||||
if (iter.key() == "wlp3s0" && !iter.value().isEmpty()) {
|
if (iter.key() == m_wlanDevice && !iter.value().isEmpty()) {
|
||||||
QString ssid = iter.value().at(0);
|
QString ssid = iter.value().at(0);
|
||||||
m_activatedWlanSSid = ssid;
|
m_activatedWlanSSid = ssid;
|
||||||
|
|
||||||
KyWirelessNetItem data;
|
KyWirelessNetItem data;
|
||||||
if (!m_resource->getWifiNetwork("wlp3s0", ssid, data)) {
|
if (!m_resource->getWifiNetwork(m_wlanDevice, ssid, data)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
|
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
|
||||||
|
@ -111,6 +128,13 @@ void WlanPage::getActiveWlan()
|
||||||
} else {
|
} else {
|
||||||
//ZJP_TODO 未连接任何WiFi的情况
|
//ZJP_TODO 未连接任何WiFi的情况
|
||||||
m_activatedWlanSSid.clear();
|
m_activatedWlanSSid.clear();
|
||||||
|
WlanListItem *wlanItemWidget = new WlanListItem();
|
||||||
|
qDebug() << "There is no activated wlan." << Q_FUNC_INFO << __LINE__ ;
|
||||||
|
QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget);
|
||||||
|
wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height()));
|
||||||
|
m_activatedNetListWidget->addItem(wlanItem);
|
||||||
|
m_activatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
|
||||||
|
height += wlanItemWidget->height();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +148,7 @@ void WlanPage::getAllWlan()
|
||||||
m_itemsMap.clear();
|
m_itemsMap.clear();
|
||||||
QList<KyWirelessNetItem> wlanList;
|
QList<KyWirelessNetItem> wlanList;
|
||||||
// if (!m_resource->getAllDeviceWifiNetwork(map))
|
// if (!m_resource->getAllDeviceWifiNetwork(map))
|
||||||
if (!m_resource->getDeviceWifiNetwork("wlp3s0", wlanList)) //ZJP_TODO 获取默认网卡并传入
|
if (!m_resource->getDeviceWifiNetwork(m_wlanDevice, wlanList)) //ZJP_TODO 获取默认网卡并传入
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -183,5 +207,12 @@ void WlanPage::onWlanRemoved(QString interface, QString ssid)
|
||||||
void WlanPage::onWlanUpdated()
|
void WlanPage::onWlanUpdated()
|
||||||
{
|
{
|
||||||
//ZJP_TODO 某些特定情况下不可重绘整个列表,此处代码需要修改
|
//ZJP_TODO 某些特定情况下不可重绘整个列表,此处代码需要修改
|
||||||
|
getActiveWlan();
|
||||||
getAllWlan();
|
getAllWlan();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnection::State state, NetworkManager::ActiveConnection::Reason reason)
|
||||||
|
{
|
||||||
|
qDebug()<< "Activated wlan changed, uuid = " << uuid << "; state = " << state << "; reason = " << reason << Q_FUNC_INFO <<__LINE__;
|
||||||
|
onWlanUpdated();
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "tabpage.h"
|
#include "tabpage.h"
|
||||||
#include "kywirelessnetresource.h"
|
#include "kywirelessnetresource.h"
|
||||||
|
#include "kylinactiveconnectresource.h"
|
||||||
//#define SCROLLAREA_HEIGHT 150
|
//#define SCROLLAREA_HEIGHT 150
|
||||||
#define MORE_TEXT_MARGINS 16,0,0,0
|
#define MORE_TEXT_MARGINS 16,0,0,0
|
||||||
|
|
||||||
|
@ -21,6 +22,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
void initWlanUI();
|
void initWlanUI();
|
||||||
void initConnections();
|
void initConnections();
|
||||||
|
QString m_wlanDevice; //临时用来存储网卡名
|
||||||
|
void getDevice(); //一个临时用于获取网卡的函数
|
||||||
void getActiveWlan();
|
void getActiveWlan();
|
||||||
void getAllWlan();
|
void getAllWlan();
|
||||||
QMap<QString, QListWidgetItem*> m_itemsMap;
|
QMap<QString, QListWidgetItem*> m_itemsMap;
|
||||||
|
@ -33,11 +36,15 @@ private:
|
||||||
QString m_activatedWlanSSid;
|
QString m_activatedWlanSSid;
|
||||||
|
|
||||||
KyWirelessNetResource *m_resource = nullptr;
|
KyWirelessNetResource *m_resource = nullptr;
|
||||||
|
KyActiveConnectResourse *m_connectResource = nullptr;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onWlanAdded(QString interface, KyWirelessNetItem &item);
|
void onWlanAdded(QString interface, KyWirelessNetItem &item);
|
||||||
void onWlanRemoved(QString interface, QString ssid);
|
void onWlanRemoved(QString interface, QString ssid);
|
||||||
void onWlanUpdated();
|
void onWlanUpdated();
|
||||||
|
void onActivatedWlanChanged(QString uuid,
|
||||||
|
NetworkManager::ActiveConnection::State state,
|
||||||
|
NetworkManager::ActiveConnection::Reason reason);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WLANPAGE_H
|
#endif // WLANPAGE_H
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "radioitembutton.h"
|
#include "radioitembutton.h"
|
||||||
|
#define BUTTON_SIZE 32,32
|
||||||
|
|
||||||
RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButton(parent)
|
RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButton(parent)
|
||||||
{
|
{
|
||||||
|
@ -8,6 +9,7 @@ RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButto
|
||||||
this->setAutoFillBackground(false);
|
this->setAutoFillBackground(false);
|
||||||
m_iconLabel = new QLabel(this);
|
m_iconLabel = new QLabel(this);
|
||||||
m_iconLabel->setScaledContents(true);
|
m_iconLabel->setScaledContents(true);
|
||||||
|
this->setFixedSize(BUTTON_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioItemButton::startLoading()
|
void RadioItemButton::startLoading()
|
||||||
|
|
Loading…
Reference in New Issue