Feat:Add wifi signal refreshing.

This commit is contained in:
jinxujie 2021-09-26 13:58:38 +08:00
parent 26a6c112ca
commit ef212b5090
5 changed files with 58 additions and 21 deletions

View File

@ -37,6 +37,9 @@ WlanListItem::~WlanListItem()
void WlanListItem::setWlanSignal(const int &signal)
{
if (!m_data){
return;
}
m_data->m_signalStrength = signal;
refreshIcon();
}

View File

@ -303,7 +303,7 @@ void MainWindow::resetWindowTheme()
void MainWindow::showControlCenter()
{
QProcess process;
if (m_lanWidget->m_isLanConnected == false && m_wlanWidget->wlanIsConnected == true){
if (m_lanWidget->m_isLanConnected == false && m_wlanWidget->m_wlanIsConnected == true){
process.startDetached("ukui-control-center --wlanconnect");
} else {
process.startDetached("ukui-control-center --wiredconnect");
@ -350,9 +350,9 @@ void MainWindow::onRefreshTrayIcon()
//更新托盘图标显示
if (m_lanWidget->m_isLanConnected == true){
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
} else if (m_wlanWidget->wlanIsConnected == true && m_lanWidget->m_isLanConnected == false){
} else if (m_wlanWidget->m_wlanIsConnected == true && m_lanWidget->m_isLanConnected == false){
m_trayIcon->setIcon(QIcon::fromTheme("network-wireless-signal-excellent-symbolic"));
} else if (m_wlanWidget->wlanIsConnected == false && m_lanWidget->m_isLanConnected == false){
} else if (m_wlanWidget->m_wlanIsConnected == false && m_lanWidget->m_isLanConnected == false){
m_trayIcon->setIcon(QIcon::fromTheme("network-wired-signal-excellent-symbolic"));
}
}

View File

@ -446,9 +446,11 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
if (NetworkManager::ActiveConnection::State::Activated == state){
m_isLanConnected = true;
qDebug() << "[lanpage]lanIsConnected status : " << m_isLanConnected << Q_FUNC_INFO << __LINE__ ;
emit this->lanConnectChanged();
} else {
m_isLanConnected = false;
qDebug() << "=[lanpage]lanIsConnected status : " << m_isLanConnected << Q_FUNC_INFO << __LINE__ ;
qDebug() << "[lanpage]lanIsConnected status : " << m_isLanConnected << Q_FUNC_INFO << __LINE__ ;
emit this->lanConnectChanged();
}
qDebug()<<"[LanPage] State change slot:"<<state;
@ -487,7 +489,6 @@ void LanPage::updateLanlist(QString uuid, NetworkManager::ActiveConnection::Stat
if (m_item->m_connectUuid == uuid) {
m_activatedLanListWidget->removeItemWidget(i.value());
delete(i.value());
emit this->lanConnectChanged();
break;
}
}
@ -708,6 +709,7 @@ void LanPage::activateWired(const QString& devName, const QString& connUuid)
{
qDebug() << "activateWired" << devName << connUuid;
m_wiredConnectOperation->activateConnection(connUuid, devName);
emit this->lanConnectChanged();
}
void LanPage::deactivateWired(const QString& devName, const QString& connUuid)

View File

@ -149,7 +149,9 @@ void WlanPage::initConnections()
void WlanPage::initTimer()
{
m_scanTimer = new QTimer(this);
m_refreshIconTimer = new QTimer(this);
connect(m_scanTimer, &QTimer::timeout, this, &WlanPage::requestScan);
connect(m_refreshIconTimer, &QTimer::timeout, this, &WlanPage::onRefreshIconTimer);
}
/**
@ -288,14 +290,14 @@ void WlanPage::getAllWlan()
if (itemData.m_NetSsid == this->m_activatedWlanSSid) {
continue;
}
KyWirelessNetItem *data = new KyWirelessNetItem(itemData);
WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice);
QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget);
qDebug() << itemData.m_NetSsid << itemData.m_isConfigured;
connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged);
connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked);
m_itemsMap.insert(data->m_NetSsid, wlanItem);
QPair<QListWidgetItem*,WlanListItem*> pair (wlanItem, wlanItemWidget);
m_itemsMap.insert(data->m_NetSsid, pair);
wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height()));
m_inactivatedNetListWidget->addItem(wlanItem);
m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget);
@ -326,20 +328,20 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item)
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);
QPair<QListWidgetItem*,WlanListItem*> pair (wlanItem, wlanItemWidget);
m_itemsMap.insert(data->m_NetSsid, pair);
}
void WlanPage::onWlanRemoved(QString interface, QString ssid)
{
if (!m_itemsMap.contains(ssid)) { return; }
if (m_expandedItem == m_itemsMap.value(ssid)) { m_expandedItem = nullptr; }
if (m_expandedItem == (m_itemsMap.value(ssid)).first) { m_expandedItem = nullptr; }
qDebug() << "A Wlan Removed! interface = " << interface << "; ssid = " << ssid << Q_FUNC_INFO <<__LINE__;
if (interface != m_defaultDevice) {
qDebug() << "wlan remove interface not equal defaultdevice,ignore";
}
int height = m_inactivatedNetListWidget->itemWidget(m_itemsMap.value(ssid))->height();
m_inactivatedNetListWidget->takeItem(m_inactivatedNetListWidget->row(m_itemsMap.value(ssid)));
int height = m_inactivatedNetListWidget->itemWidget((m_itemsMap.value(ssid)).first)->height();
m_inactivatedNetListWidget->takeItem(m_inactivatedNetListWidget->row((m_itemsMap.value(ssid)).first));
m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() - height - NET_LIST_SPACING);
m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height());
m_itemsMap.remove(ssid);
@ -448,11 +450,11 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec
}
}
if(NetworkManager::ActiveConnection::State::Activated == state){
wlanIsConnected = true;
qDebug() << "[wlanpage] wlanIsConnected status : " << wlanIsConnected << Q_FUNC_INFO << __LINE__ ;
m_wlanIsConnected = true;
qDebug() << "[wlanpage] wlanIsConnected status : " << m_wlanIsConnected << Q_FUNC_INFO << __LINE__ ;
} else {
wlanIsConnected = false;
qDebug() << "[wlanpage] wlanIsConnected status : " << wlanIsConnected << Q_FUNC_INFO << __LINE__ ;
m_wlanIsConnected = false;
qDebug() << "[wlanpage] wlanIsConnected status : " << m_wlanIsConnected << Q_FUNC_INFO << __LINE__ ;
}
//弹窗显示wifi连接状况
@ -556,7 +558,7 @@ void WlanPage::onActivatedWlanChanged(QString uuid, NetworkManager::ActiveConnec
void WlanPage::onItemHeightChanged(const QString &ssid)
{
if (!m_itemsMap.contains(ssid)) { return; }
QListWidgetItem *item = m_itemsMap.value(ssid);
QListWidgetItem *item = (m_itemsMap.value(ssid)).first;
if (m_expandedItem && m_expandedItem != item) {
QSize size(m_inactivatedNetListWidget->itemWidget(m_expandedItem)->size().width(), NORMAL_HEIGHT);
@ -648,9 +650,9 @@ void WlanPage::onWifiEnabledChanged(bool isWifiOn)
qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__;
return;
}
if(m_netSwitch->getSwitchStatus() == isWifiOn){
if (m_netSwitch->getSwitchStatus() == isWifiOn) {
return;
}else{
} else {
//m_wirelessConnectOpreation->setWirelessEnabled(isWifiOn);
m_netSwitch->setSwitchStatus(isWifiOn);
//外部命令导致连接状态发生变化,通知主界面刷新图标
@ -658,6 +660,28 @@ void WlanPage::onWifiEnabledChanged(bool isWifiOn)
}
}
void WlanPage::onRefreshIconTimer()
{
//wifi页面打开时每隔5s主动获取wifi信号强度对图标进行更新
qDebug() << "refresh wifi icon" << Q_FUNC_INFO << __LINE__;
QList<KyWirelessNetItem> wlanList;
if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) {
return;
}
foreach (auto itemData, wlanList) {
qDebug() << "pair" << itemData.m_NetSsid << m_itemsMap.value(itemData.m_NetSsid) << "refresh wifi icon secsess"<< Q_FUNC_INFO << __LINE__;
WlanListItem *wlanListItem = nullptr;
wlanListItem = (m_itemsMap.value(itemData.m_NetSsid)).second;
if (wlanListItem) {
qDebug() << "refresh wifi icon secsess"<< Q_FUNC_INFO << __LINE__;
wlanListItem->setWlanSignal(itemData.m_signalStrength);
} else {
qWarning() << "Set wifi signal failed because of null pointer wlanListItem!" << Q_FUNC_INFO << __LINE__;
}
}
return;
}
//for dbus
void WlanPage::getWirelessList(QMap<QString, QVector<QStringList> > &map)
{
@ -802,9 +826,12 @@ void WlanPage::onMainWindowVisibleChanged(const bool &visible)
}
//若页面打开,开始扫描倒计时,若关闭,停止扫描倒计时
if (visible) {
qWarning() << "start refresh Timer" << Q_FUNC_INFO << __LINE__;
m_scanTimer->start(20 * 1000);
m_refreshIconTimer->start(5*1000);
} else {
m_scanTimer->stop();
m_refreshIconTimer->stop();
}
}

View File

@ -18,13 +18,15 @@
#define MORE_TEXT_MARGINS 16,0,0,0
#define SCROLLAREA_HEIGHT 200
class WlanListItem;
class WlanPage : public TabPage
{
Q_OBJECT
public:
explicit WlanPage(QWidget *parent = nullptr);
~WlanPage() = default;
bool wlanIsConnected = false;
bool m_wlanIsConnected = false;
//for dbus
void getWirelessList(QMap<QString, QVector<QStringList> > &map);
@ -67,6 +69,7 @@ private:
//定时触发扫描的定时器
void initTimer();
QTimer * m_scanTimer = nullptr;
QTimer * m_refreshIconTimer = nullptr;
void initDevice();//初始化默认设备
void initDeviceCombox();
@ -74,7 +77,8 @@ private:
void getActiveWlan();
void appendActiveWlan(const QString &uuid, int &height);
void getAllWlan();
QMap<QString, QListWidgetItem*> m_itemsMap;
QMap<QString, QPair<QListWidgetItem*, WlanListItem*>> m_itemsMap;
QListWidgetItem *m_expandedItem = nullptr;
QFrame * m_inactivatedWlanListAreaCentralWidget = nullptr;
QVBoxLayout * m_inactivatedWlanListAreaLayout = nullptr;
@ -117,6 +121,7 @@ private slots:
void onHiddenWlanClicked();
void showControlCenter();
void onWifiEnabledChanged(bool isWifiOn);
void onRefreshIconTimer();
};
#endif // WLANPAGE_H