This commit is contained in:
jzxc95 2021-08-26 14:43:27 +08:00
commit 7786c3cab3
8 changed files with 82 additions and 14 deletions

View File

@ -18,7 +18,7 @@ void LanListItem::refreshIcon()
void LanListItem::onInfoButtonClicked()
{
//ZJP_TODO 呼出有线详情页
qDebug() << "On lan info button clicked! name = " << m_data->m_connectName << "; uuid = " << m_data->m_connectUuid << "." <<Q_FUNC_INFO << __LINE__;
qDebug() << "On lan info button clicked! name = " << m_data->m_connectName << "; uuid = " << m_data->m_connectUuid << "." <<Q_FUNC_INFO << __LINE__;
}
void LanListItem::onNetButtonClicked()

View File

@ -28,6 +28,7 @@ bool ListItem::eventFilter(QObject *watched, QEvent *event)
this->onNetButtonClicked();
}
}
return QFrame::eventFilter(watched, event);
}
void ListItem::setName(const QString &name)

View File

@ -9,6 +9,14 @@ WlanListItem::WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *d
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()
{
disconnect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanListItem::onSecurityChanged);
@ -101,13 +109,24 @@ void WlanListItem::refreshIcon()
void WlanListItem::onInfoButtonClicked()
{
//ZJP_TODO 呼出无线详情页
qDebug() << "On wlan info button clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." <<Q_FUNC_INFO << __LINE__;
if(m_data){
qDebug() << "On wlan info button clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." <<Q_FUNC_INFO << __LINE__;
}
else{
qDebug() << "On wlan info button clicked! But there is no wlan connect " ;
}
}
void WlanListItem::onNetButtonClicked()
{
//ZJP_TODO 点击连接/断开
qDebug() << "On wlan clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." <<Q_FUNC_INFO << __LINE__;
if(m_data){
qDebug() << "On wlan clicked! ssid = " << m_data->m_NetSsid << "; name = " << m_data->m_connName << "." <<Q_FUNC_INFO << __LINE__;
}
else{
qDebug() << "On wlan clicked! But there is no wlan connect " ;
}
}
void WlanListItem::onSecurityChanged(QString interface, QString ssid, QString securityType)

View File

@ -12,6 +12,7 @@ class WlanListItem : public ListItem
Q_OBJECT
public:
WlanListItem(KyWirelessNetResource *resource, KyWirelessNetItem *data, QWidget *parent = nullptr);
WlanListItem(QWidget *parent = nullptr);
~WlanListItem();
public:

View File

@ -40,6 +40,7 @@ void TabPage::initUI()
m_activatedNetListWidget->setFrameShape(QFrame::Shape::NoFrame);
m_activatedNetListWidget->setContentsMargins(MAIN_LAYOUT_MARGINS);
m_activatedNetListWidget->setSpacing(NET_LIST_SPACING);
m_activatedNetListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_activatedNetLayout->addWidget(m_activatedNetLabel);
m_activatedNetLayout->addWidget(m_activatedNetListWidget);
m_activatedNetDivider = new Divider(this);

View File

@ -10,17 +10,21 @@
WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
{
m_resource = new KyWirelessNetResource(this);
m_device = new KyNetworkDeviceResourse(this);
m_connectResource = new KyActiveConnectResourse();
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
m_netDeviceResource=new KyNetworkDeviceResourse(this);
devList.empty();
initDevice();
getWirelessIface();
initWlanUI();
initConnections();
getActiveWlan();
getAllWlan();
connect(m_device, &KyNetworkDeviceResourse::deviceAdd, this, &WlanPage::onDeviceAdd);
connect(m_device, &KyNetworkDeviceResourse::deviceRemove, this, &WlanPage::onDeviceRemove);
connect(m_device, &KyNetworkDeviceResourse::deviceNameUpdate, this, &WlanPage::onDeviceNameUpdate);
connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceAdd, this, &WlanPage::onDeviceAdd);
connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceRemove, this, &WlanPage::onDeviceRemove);
connect(m_netDeviceResource, &KyNetworkDeviceResourse::deviceNameUpdate, this, &WlanPage::onDeviceNameUpdate);
}
bool WlanPage::eventFilter(QObject *w, QEvent *e)
@ -81,7 +85,24 @@ void WlanPage::initConnections()
{
connect(m_resource, &KyWirelessNetResource::wifiNetworkAdd, this, &WlanPage::onWlanAdded);
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::getWirelessIface()
{
QStringList netDeviceList;//临时存储网卡列表
m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, netDeviceList);
if (netDeviceList.isEmpty()) {
m_wlanDevice = "wlx5841207b85f0";
qDebug() << "Wlan device is not exist." << Q_FUNC_INFO << __LINE__;
} else {
m_wlanDevice=netDeviceList.at(0);
qDebug() << "Get device successfully, its name is " << m_wlanDevice <<Q_FUNC_INFO << __LINE__;
}
return;
}
/**
@ -93,7 +114,7 @@ void WlanPage::initDevice()
m_settings->beginGroup("DEFAULTCARD");
QString key("wireless");
QString deviceName = m_settings->value(key, "").toString();
m_device->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, devList);
m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, devList);
if (deviceName.isEmpty()) {
qDebug() << "initDevice but defalut wireless card is null";
if (!devList.isEmpty()) {
@ -121,12 +142,12 @@ void WlanPage::getActiveWlan()
QMap<QString,QStringList>::iterator iter = actMap.begin();
int height = 0;
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);
m_activatedWlanSSid = ssid;
KyWirelessNetItem data;
if (!m_resource->getWifiNetwork("wlp3s0", ssid, data)) {
if (!m_resource->getWifiNetwork(m_wlanDevice, ssid, data)) {
return;
}
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
@ -146,6 +167,13 @@ void WlanPage::getActiveWlan()
} else {
//ZJP_TODO 未连接任何WiFi的情况
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();
}
}
@ -159,7 +187,7 @@ void WlanPage::getAllWlan()
m_itemsMap.clear();
QList<KyWirelessNetItem> wlanList;
// if (!m_resource->getAllDeviceWifiNetwork(map))
if (!m_resource->getDeviceWifiNetwork("wlp3s0", wlanList)) //ZJP_TODO 获取默认网卡并传入
if (!m_resource->getDeviceWifiNetwork(m_wlanDevice, wlanList)) //ZJP_TODO 获取默认网卡并传入
{
return;
}
@ -217,6 +245,7 @@ void WlanPage::onWlanRemoved(QString interface, QString ssid)
void WlanPage::onWlanUpdated()
{
//ZJP_TODO 某些特定情况下不可重绘整个列表,此处代码需要修改
getActiveWlan();
getAllWlan();
}
@ -244,7 +273,7 @@ void WlanPage::onDeviceRemove(QString deviceName)
QStringList list;
QString newDefaultDevice = "";
list.empty();
m_device->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, list);
m_netDeviceResource->getNetworkDeviceList(NetworkManager::Device::Type::Wifi, list);
if (!list.isEmpty()) {
newDefaultDevice = list.at(0);
}
@ -271,3 +300,10 @@ void WlanPage::onDeviceNameUpdate(QString oldName, QString newName)
emit deviceNameChanged(oldName, newName);
}
}
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();
}

View File

@ -3,6 +3,7 @@
#include "tabpage.h"
#include "kywirelessnetresource.h"
#include "kylinactiveconnectresource.h"
#include "kylinnetworkdeviceresource.h"
//#define SCROLLAREA_HEIGHT 150
@ -22,6 +23,8 @@ private:
void initWlanUI();
void initConnections();
void initDevice();//初始化默认设备
QString m_wlanDevice; //临时用来存储网卡名
void getWirelessIface(); //一个临时用于获取网卡的函数
void getActiveWlan();
void getAllWlan();
QMap<QString, QListWidgetItem*> m_itemsMap;
@ -35,7 +38,9 @@ private:
QStringList devList;
KyWirelessNetResource *m_resource = nullptr;
KyNetworkDeviceResourse *m_device = nullptr;
KyActiveConnectResourse *m_connectResource = nullptr;
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
KyNetworkDeviceResourse *m_netDeviceResource=nullptr;
private slots:
@ -46,6 +51,9 @@ private slots:
void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType);
void onDeviceRemove(QString deviceName);
void onDeviceNameUpdate(QString oldName, QString newName);
void onActivatedWlanChanged(QString uuid,
NetworkManager::ActiveConnection::State state,
NetworkManager::ActiveConnection::Reason reason);
};
#endif // WLANPAGE_H

View File

@ -1,4 +1,5 @@
#include "radioitembutton.h"
#define BUTTON_SIZE 32,32
RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButton(parent)
{
@ -8,6 +9,7 @@ RadioItemButton::RadioItemButton(bool isActivated, QWidget *parent) : QPushButto
this->setAutoFillBackground(false);
m_iconLabel = new QLabel(this);
m_iconLabel->setScaledContents(true);
this->setFixedSize(BUTTON_SIZE);
}
void RadioItemButton::startLoading()