Feature: Add activated wlan item.

This commit is contained in:
zhangjiaping 2021-08-25 09:03:21 +08:00
parent 1f14ffb8c5
commit 6f523698e5
6 changed files with 84 additions and 23 deletions

View File

@ -11,6 +11,7 @@ class KyWirelessNetItem
{
public:
KyWirelessNetItem(NetworkManager::WirelessNetwork::Ptr net);
KyWirelessNetItem() {;}
~KyWirelessNetItem();
private:

View File

@ -50,7 +50,7 @@ bool KyWirelessNetResource::getDeviceWifiNetwork(QString devIfaceName, QList<KyW
}
}
bool KyWirelessNetResource::getWifiNetwork(QString &devIfaceName, QString &ssid, KyWirelessNetItem &wirelessNetResource)
bool KyWirelessNetResource::getWifiNetwork(const QString &devIfaceName, const QString &ssid, KyWirelessNetItem &wirelessNetResource)
{
// onWifiNetworkDeviceDisappear();

View File

@ -18,7 +18,7 @@ public:
~KyWirelessNetResource();
//ui层调用接口
bool getWifiNetwork(QString &devIfaceName, QString &ssid, KyWirelessNetItem &wirelessNetResource);
bool getWifiNetwork(const QString &devIfaceName, const QString &ssid, KyWirelessNetItem &wirelessNetResource);
bool getAllDeviceWifiNetwork(QMap<QString, QList<KyWirelessNetItem> > &map);
bool getDeviceWifiNetwork(QString devIfaceName, QList<KyWirelessNetItem> &wirelessNetResource);

View File

@ -36,7 +36,7 @@ void WlanListItem::initWlanUI()
{
m_hasPwd = (m_data->m_secuType.isEmpty() || m_data->m_secuType == "") ? false : true;
//设置显示的Wlan名称
this->setName(m_data->m_NetSsid);
this->setName((m_data->m_connName != "") ? m_data->m_connName : m_data->m_NetSsid);
//刷新左侧按钮图标
refreshIcon();
}

View File

@ -10,6 +10,7 @@ WlanPage::WlanPage(QWidget *parent) : TabPage(parent)
m_resource = new KyWirelessNetResource(this);
initWlanUI();
initConnections();
getActiveWlan();
getAllWlan();
}
@ -75,32 +76,71 @@ void WlanPage::initConnections()
}
/**
* @brief WlanPage::getAllWlan Wlan
* @brief WlanPage::getActiveWlan
*/
void WlanPage::getActiveWlan()
{
QMap<QString,QStringList> actMap;
m_activatedNetListWidget->clear();
m_resource->getWirelessActiveConnection(NetworkManager::ActiveConnection::State::Activated, actMap);
QMap<QString,QStringList>::iterator iter = actMap.begin();
int height = 0;
while (iter != actMap.end()) {
if (iter.key() == "wlp3s0" && !iter.value().isEmpty()) {
QString ssid = iter.value().at(0);
m_activatedWlanSSid = ssid;
KyWirelessNetItem data;
if (!m_resource->getWifiNetwork("wlp3s0", ssid, data)) {
return;
}
KyWirelessNetItem *item_data = new KyWirelessNetItem(data);
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data);
qDebug() << "Activated wlan: ssid = " << item_data->m_NetSsid;
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();
break;
}
iter ++;
}
if (height > 0) {
m_activatedNetListWidget->setFixedHeight(height);
} else {
//ZJP_TODO 未连接任何WiFi的情况
m_activatedWlanSSid.clear();
}
}
/**
* @brief WlanPage::getAllWlan Wlan //ZJP_TODO 需要针对网卡进行筛选
*/
void WlanPage::getAllWlan()
{
qDebug() << "Started loading wlan list! time=" << QDateTime::currentDateTime().toString("hh:mm:ss.zzzz");
m_inactivatedNetListWidget->clear();
QMap<QString, QList<KyWirelessNetItem> > map;
if (!m_resource->getAllDeviceWifiNetwork(map))
m_itemsMap.clear();
QList<KyWirelessNetItem> wlanList;
// if (!m_resource->getAllDeviceWifiNetwork(map))
if (!m_resource->getDeviceWifiNetwork("wlp3s0", wlanList)) //ZJP_TODO 获取默认网卡并传入
{
return;
}
QMap<QString, QList<KyWirelessNetItem> >::iterator iter = map.begin();
int height = 0;
while (iter != map.end())
{
foreach (auto itemData, iter.value()) {
KyWirelessNetItem *data = &itemData;
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data);
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height()));
m_inactivatedNetListWidget->addItem(wlanItem);
m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
if (height == 0) height += wlanItemWidget->height();
height += wlanItemWidget->height() + NET_LIST_SPACING;
}
iter++;
foreach (auto itemData, wlanList) {
if (itemData.m_NetSsid == this->m_activatedWlanSSid) { continue; }
KyWirelessNetItem *data = new KyWirelessNetItem(itemData);
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data);
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
m_itemsMap.insert(data->m_NetSsid, wlanItem);
wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height()));
m_inactivatedNetListWidget->addItem(wlanItem);
m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
if (height == 0) height += wlanItemWidget->height();
height += wlanItemWidget->height() + NET_LIST_SPACING;
}
m_inactivatedNetListWidget->setFixedHeight(height);
m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height());
@ -110,16 +150,34 @@ void WlanPage::getAllWlan()
void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item)
{
qDebug() << "A Wlan Added! interface = " << interface << "; ssid = " << item.m_NetSsid << Q_FUNC_INFO <<__LINE__;
getAllWlan();
KyWirelessNetItem *data = new KyWirelessNetItem(item);
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data);
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height()));
m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
// m_inactivatedNetListWidget->insertItem(N, wlanItem);
m_inactivatedNetListWidget->addItem(wlanItem); //ZJP_TODO 目前会添加到列表尾部
m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() + wlanItemWidget->height() + NET_LIST_SPACING);
m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height());
m_itemsMap.insert(data->m_NetSsid, wlanItem);
}
void WlanPage::onWlanRemoved(QString interface, QString ssid)
{
if (!m_itemsMap.contains(ssid)) { return; }
qDebug() << "A Wlan Removed! interface = " << interface << "; ssid = " << ssid << Q_FUNC_INFO <<__LINE__;
getAllWlan();
m_inactivatedNetListWidget->removeItemWidget(m_itemsMap.value(ssid));
m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() -
m_inactivatedNetListWidget->itemWidget(m_itemsMap.value(ssid))->height() -
NET_LIST_SPACING);
m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height());
m_itemsMap.remove(ssid);
}
void WlanPage::onWlanUpdated()
{
//ZJP_TODO 某些特定情况下不可重绘整个列表,此处代码需要修改
getAllWlan();
}

View File

@ -21,6 +21,7 @@ protected:
private:
void initWlanUI();
void initConnections();
void getActiveWlan();
void getAllWlan();
QMap<QString, QListWidgetItem*> m_itemsMap;
QFrame * m_inactivatedWlanListAreaCentralWidget = nullptr;
@ -28,7 +29,8 @@ private:
QFrame * m_hiddenWlanWidget = nullptr;
QHBoxLayout * m_hiddenWlanLayout = nullptr;
QLabel * m_hiddenWlanLabel = nullptr;
QMap<QString, QListWidgetItem *> m_itemMap;
QString m_activatedWlanSSid;
KyWirelessNetResource *m_resource = nullptr;