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