From 0d994d021c2fe7cf827e8fa7a6fd69e223623ded Mon Sep 17 00:00:00 2001 From: ksn Date: Sun, 26 Sep 2021 16:11:52 +0800 Subject: [PATCH 1/3] modify --- debian/files | 6 +++--- src/frontend/tab-pages/lanpage.cpp | 2 +- src/frontend/tab-pages/wlanpage.cpp | 5 ++++- src/frontend/tab-pages/wlanpage.h | 4 ++++ src/main.cpp | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/debian/files b/debian/files index 1587e6bf..ad42795e 100644 --- a/debian/files +++ b/debian/files @@ -1,3 +1,3 @@ -kylin-nm-dbgsym_3.0.1-1kylin54_amd64.ddeb debug optional automatic=yes -kylin-nm_3.0.1-1kylin54_amd64.buildinfo utils optional -kylin-nm_3.0.1-1kylin54_amd64.deb utils optional +kylin-nm-dbgsym_3.0.1-1kylin54_arm64.ddeb debug optional automatic=yes +kylin-nm_3.0.1-1kylin54_arm64.buildinfo utils optional +kylin-nm_3.0.1-1kylin54_arm64.deb utils optional diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index f6632754..ea0ea61f 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -28,7 +28,6 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) initUI(); initNetSwitch(); initDeviceCombox(); - initList(m_deviceName); connect(m_activeResourse, &KyActiveConnectResourse::stateChangeReason, this, &LanPage::updateLanlist); @@ -392,6 +391,7 @@ void LanPage::addNewItem(KyConnectItem *itemData, QListWidget *listWidget) void LanPage::initList(QString m_deviceName) //程序拉起,初始化显示 { + qDebug() << "initList"; m_activatedLanListWidget->clear(); m_inactivatedLanListWidget->clear(); m_activeMap.clear(); diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 35df284c..42c0e1ac 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -119,6 +119,9 @@ void WlanPage::initConnections() connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::onWlanRemoved); connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::wlanRemove); connect(m_resource, &KyWirelessNetResource::signalStrengthChange, this, &WlanPage::signalStrengthChange); + +// connect(m_resource, &KyWirelessNetResource::signalStrengthChange, this, &WlanPage::onsignalStrengthChange); + connect(m_resource, &KyWirelessNetResource::secuTypeChange, this, &WlanPage::secuTypeChange); // connect(m_resource, &KyWirelessNetResource::wifiNetworkUpdate, this, &WlanPage::onWlanUpdated); @@ -324,7 +327,7 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item) 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->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()); diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index b4c099d7..f04daaa1 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -121,7 +121,11 @@ private slots: void onHiddenWlanClicked(); void showControlCenter(); void onWifiEnabledChanged(bool isWifiOn); + void onRefreshIconTimer(); + +// void onsignalStrengthChange(QString, QString, int); + }; #endif // WLANPAGE_H diff --git a/src/main.cpp b/src/main.cpp index e97b2b9a..080f03da 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) // QApplication a(argc, argv); QString id = QString("kylin-nm"+ QLatin1String(getenv("DISPLAY"))); QtSingleApplication a(id, argc, argv); - qInstallMessageHandler(messageOutput); +// qInstallMessageHandler(messageOutput); if (a.isRunning()) { auto connection = QDBusConnection::sessionBus(); QDBusInterface iface("com.kylin.network", From ef365fa6bcacdf48a0e6d7117c65f9bd9770009a Mon Sep 17 00:00:00 2001 From: ksn Date: Tue, 28 Sep 2021 13:31:13 +0800 Subject: [PATCH 2/3] wlan signalstrength --- src/frontend/list-items/wlanlistitem.cpp | 9 ++ src/frontend/list-items/wlanlistitem.h | 4 +- src/frontend/tab-pages/lanpage.cpp | 1 - src/frontend/tab-pages/wlanpage.cpp | 180 ++++++++++++++++++++--- src/frontend/tab-pages/wlanpage.h | 2 + 5 files changed, 176 insertions(+), 20 deletions(-) diff --git a/src/frontend/list-items/wlanlistitem.cpp b/src/frontend/list-items/wlanlistitem.cpp index 0fccc916..ac0a6110 100644 --- a/src/frontend/list-items/wlanlistitem.cpp +++ b/src/frontend/list-items/wlanlistitem.cpp @@ -68,6 +68,15 @@ void WlanListItem::setExpanded(const bool &expanded) } } +QString WlanListItem::getSsid() +{ + if (!m_data) { + return QString(); + } else { + return m_data->m_NetSsid; + } +} + void WlanListItem::resizeEvent(QResizeEvent *event) { this->blockSignals(true); diff --git a/src/frontend/list-items/wlanlistitem.h b/src/frontend/list-items/wlanlistitem.h index 96a014c1..56b554d4 100644 --- a/src/frontend/list-items/wlanlistitem.h +++ b/src/frontend/list-items/wlanlistitem.h @@ -30,6 +30,8 @@ public: void setWlanSignal(const int &signal); void setWlanState(const int &state); void setExpanded(const bool &expanded); + QString getSsid(); + KyWirelessNetItem *m_data = nullptr; protected: void resizeEvent(QResizeEvent *event); void onRightButtonClicked(); @@ -47,7 +49,7 @@ private: private: KyWirelessNetResource *m_resource = nullptr; - KyWirelessNetItem *m_data = nullptr; + KyWirelessConnectOperation *m_connoperation = nullptr; KyActiveConnectResourse *m_connectResource = nullptr; bool m_hasPwd = true; diff --git a/src/frontend/tab-pages/lanpage.cpp b/src/frontend/tab-pages/lanpage.cpp index ea0ea61f..9c06b463 100644 --- a/src/frontend/tab-pages/lanpage.cpp +++ b/src/frontend/tab-pages/lanpage.cpp @@ -24,7 +24,6 @@ LanPage::LanPage(QWidget *parent) : TabPage(parent) initDeviceState(); - initUI(); initNetSwitch(); initDeviceCombox(); diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 42c0e1ac..709f52d6 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -118,7 +118,7 @@ void WlanPage::initConnections() }); connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::onWlanRemoved); connect(m_resource, &KyWirelessNetResource::wifiNetworkRemove, this, &WlanPage::wlanRemove); - connect(m_resource, &KyWirelessNetResource::signalStrengthChange, this, &WlanPage::signalStrengthChange); +// connect(m_resource, &KyWirelessNetResource::signalStrengthChange, this, &WlanPage::signalStrengthChange); // connect(m_resource, &KyWirelessNetResource::signalStrengthChange, this, &WlanPage::onsignalStrengthChange); @@ -154,7 +154,7 @@ 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); + connect(m_refreshIconTimer, &QTimer::timeout, this, &WlanPage::updateByStrength); } /** @@ -238,7 +238,7 @@ void WlanPage::getActiveWlan() m_activatedWlanUuid.clear(); WlanListItem *wlanItemWidget = new WlanListItem(); qDebug() << "There is no activated wlan." << Q_FUNC_INFO << __LINE__ ; - QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget); + QListWidgetItem *wlanItem = new QListWidgetItem(); wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height())); m_activatedNetListWidget->addItem(wlanItem); // emit this->wlanConnectChanged(); @@ -261,7 +261,7 @@ void WlanPage::appendActiveWlan(const QString &uuid, int &height) KyWirelessNetItem *item_data = new KyWirelessNetItem(data); WlanListItem *wlanItemWidget = new WlanListItem(m_resource, item_data, m_defaultDevice); qDebug() << "Activated wlan: ssid = " << item_data->m_NetSsid; - QListWidgetItem *wlanItem = new QListWidgetItem(m_activatedNetListWidget); + QListWidgetItem *wlanItem = new QListWidgetItem(); wlanItem->setSizeHint(QSize(m_activatedNetListWidget->width(), wlanItemWidget->height())); m_activatedNetListWidget->addItem(wlanItem); emit this->wlanConnectChanged(); @@ -295,7 +295,7 @@ void WlanPage::getAllWlan() } KyWirelessNetItem *data = new KyWirelessNetItem(itemData); WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice); - QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget); + QListWidgetItem *wlanItem = new QListWidgetItem(); qDebug() << itemData.m_NetSsid << itemData.m_isConfigured; connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked); @@ -324,17 +324,34 @@ void WlanPage::onWlanAdded(QString interface, KyWirelessNetItem &item) WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice); connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked); - QListWidgetItem *wlanItem = new QListWidgetItem(m_inactivatedNetListWidget); + + QListWidgetItem *wlanItem = new QListWidgetItem(); //不要指定父对象,否则insert会出错 wlanItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanItemWidget->height())); + int index = getIndexByStrength(interface, data->m_NetSsid); + + m_inactivatedNetListWidget->insertItem(index, wlanItem); m_inactivatedNetListWidget->setItemWidget(wlanItem, wlanItemWidget); -// m_inactivatedNetListWidget->insertItem(N, wlanItem); - m_inactivatedNetListWidget->addItem(wlanItem); //ZJP_TODO 目前会添加到列表尾部 + +// 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()); QPair pair (wlanItem, wlanItemWidget); m_itemsMap.insert(data->m_NetSsid, pair); } +int WlanPage::getIndexByStrength(QString interface, QString ssid) +{ + QList wlanList; + m_resource->getDeviceWifiNetwork(interface, wlanList); + for (int i=0; i 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__; +// } +// } +// updateByStrength(); + qDebug() << "updateByStrength"; QList 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__; + int height = 0; + qDebug() << "tttttotal" << wlanList.count(); + + int row = 0; + int j=0; + for (int i=0; im_activatedWlanSSid) { + continue; + } + qDebug() << "onRefreshIconTimer-1" << i; + qDebug() << "onRefreshIconTimer0 wwwwwwwlan:" << wlanList.at(i).m_NetSsid; + QMap>::iterator iter; + for (iter = m_itemsMap.begin(); iter != m_itemsMap.constEnd(); ++iter,j++) { + if (wlanList.at(i).m_NetSsid == iter.key()) { + if (j == row) { + continue; + } + qDebug() << "onRefreshIconTimer1 " << row << m_itemsMap.value(iter.key()).second->m_data->m_signalStrength; + QListWidgetItem *tempItem = m_itemsMap.value(iter.key()).first; + WlanListItem *tempWidget = m_itemsMap.value(iter.key()).second; + QModelIndex index = m_inactivatedNetListWidget->model()->index(row, 0, QModelIndex()); //new + if (tempItem) { + QModelIndex lastIndex = m_inactivatedNetListWidget->model()->index(m_inactivatedNetListWidget->row(tempItem), 0, QModelIndex()); +// QModelIndex lastIndex = m_inactivatedNetListWidget->model()->index(1, 0, QModelIndex()); + qDebug() << "onRefreshIconTimer2 " << m_inactivatedNetListWidget->row(tempItem) << row; + m_inactivatedNetListWidget->setIndexWidget(lastIndex, m_inactivatedNetListWidget->indexWidget(index)); //把第0个放下来 + m_inactivatedNetListWidget->setIndexWidget(index, tempWidget); //把信号最强的放到0行 + + QString indexSsid = static_cast(m_inactivatedNetListWidget->indexWidget(lastIndex))->getSsid(); + QString lastSsid = static_cast(m_inactivatedNetListWidget->indexWidget(index))->getSsid(); + qDebug() << "onRefreshIconTimer3 " << indexSsid << lastSsid; + QPair curPair = m_itemsMap.value(iter.key()); + QPair lastPair = m_itemsMap.value(lastSsid); + qDebug() << "onRefreshIconTimern " << curPair.second->m_data->m_NetSsid << lastPair.second->m_data->m_NetSsid; + curPair.second = lastPair.second; + lastPair.second = tempWidget; + m_itemsMap[iter.key()] = curPair; + m_itemsMap[lastSsid] = lastPair; + row++; + } + } + } } - return; +// m_inactivatedNetListWidget->setFixedHeight(height); +// m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); + + QMap>::iterator i; + qDebug() << "items:" << m_itemsMap.count(); + for (i = m_itemsMap.begin(); i != m_itemsMap.constEnd(); ++i) { + qDebug() << "item" <m_data; + } + qDebug() << "eeeeeeeeend"; } +void WlanPage::updateByStrength() +{ + qDebug() << "update By Strength"; + QList wlanList; + if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) { + return; + } + int height = 0; + qDebug() << "tttttotal" << wlanList.count(); + + QMap>::iterator iters; + qDebug() << "items:" << m_itemsMap.count(); + for (iters = m_itemsMap.begin(); iters != m_itemsMap.constEnd(); ++iters) { + qDebug() << "item" <m_data; + } + + int row=0; + int j=0; + for (int i=0; im_activatedWlanSSid) { + continue; + } + qDebug() << "i:" << i; + QMap>::iterator iter; + for (iter = m_itemsMap.begin(); iter != m_itemsMap.constEnd(); ++iter,j++) { + qDebug() << wlanList.at(i).m_NetSsid << wlanList.at(i).m_signalStrength; + if (wlanList.at(i).m_NetSsid == iter.key()) { + if (j==row) { + continue; + } + m_inactivatedNetListWidget->removeItemWidget(iter.value().first); + delete iter.value().first; + QListWidgetItem *listwidgetItem = new QListWidgetItem(); +// QListWidgetItem *listwidgetItem = iter.value().first; + qDebug() << "QListWidgetItem" << listwidgetItem; +// *(iter.value().second->m_data) = wlanList.at(i); + KyWirelessNetItem itemData = wlanList.at(i); + WlanListItem *wlanWidget = new WlanListItem(m_resource, &itemData, m_defaultDevice); + wlanWidget->setWlanSignal(itemData.m_signalStrength); + connect(wlanWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); + connect(wlanWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked); + listwidgetItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanWidget->height())); + m_inactivatedNetListWidget->insertItem(row, listwidgetItem); + qDebug() << "iiinsert" << m_inactivatedNetListWidget->row(listwidgetItem); + m_inactivatedNetListWidget->setItemWidget(listwidgetItem, wlanWidget); + QPair pair (listwidgetItem, wlanWidget); + m_itemsMap.insert(iter.key(), pair); + row++; + + if (height == 0) { + height += m_itemsMap[iter.key()].second->height(); + } + height += m_itemsMap[iter.key()].second->height() + NET_LIST_SPACING; + } + } + m_inactivatedNetListWidget->setFixedHeight(height); + m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); + } + + QMap>::iterator i; + qDebug() << "items:" << m_itemsMap.count(); + for (i = m_itemsMap.begin(); i != m_itemsMap.constEnd(); ++i) { + qDebug() << "item" <m_data; + } + qDebug() << "eeeeeeeeend"; +} + + + //for dbus void WlanPage::getWirelessList(QMap > &map) { diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index f04daaa1..47a6ab48 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -61,6 +61,8 @@ protected: private: void initWlanUI(); void initConnections(); + int getIndexByStrength(QString interface, QString ssid); + void updateByStrength(); QString m_activedssid; QString m_disconnectuuid; int m_disconnecting; From 0af291831ce6ae908e94e9273eff431d2d32ff0f Mon Sep 17 00:00:00 2001 From: zhangjiaping Date: Tue, 28 Sep 2021 16:37:31 +0800 Subject: [PATCH 3/3] Feat:Add wifi sort. --- src/frontend/tab-pages/wlanpage.cpp | 192 +++++++--------------------- src/frontend/tab-pages/wlanpage.h | 2 +- src/main.cpp | 2 +- 3 files changed, 49 insertions(+), 147 deletions(-) diff --git a/src/frontend/tab-pages/wlanpage.cpp b/src/frontend/tab-pages/wlanpage.cpp index 709f52d6..66edaa99 100644 --- a/src/frontend/tab-pages/wlanpage.cpp +++ b/src/frontend/tab-pages/wlanpage.cpp @@ -139,6 +139,7 @@ void WlanPage::initConnections() if (key == WIRELESS_SWITCH) { bool status = m_switchGsettings->get(WIRELESS_SWITCH).toBool(); m_wirelessConnectOpreation->setWirelessEnabled(status); + m_netSwitch->setSwitchStatus(m_switchGsettings->get(WIRELESS_SWITCH).toBool()); onWlanSwitchStatusChanged(m_switchGsettings->get(WIRELESS_SWITCH).toBool()); } }); @@ -171,10 +172,10 @@ void WlanPage::initDevice() deviceName = m_devList.at(0); m_settings->setValue(key, deviceName); } else { - qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__; - //检测不到无线网卡不再触发click信号 - m_netSwitch->setSwitchStatus(false); - m_netSwitch->setEnabled(false); + qDebug() << "have no device to use " << Q_FUNC_INFO << __LINE__; + //检测不到无线网卡不再触发click信号 + m_netSwitch->setSwitchStatus(false); + m_netSwitch->setEnabled(false); } updateDefaultDevice(deviceName); qDebug() << "[WlanPage] initDevice defaultDevice = " << deviceName; @@ -343,8 +344,7 @@ int WlanPage::getIndexByStrength(QString interface, QString ssid) { QList wlanList; m_resource->getDeviceWifiNetwork(interface, wlanList); - for (int i=0; iitemWidget((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()); + if (m_itemsMap.value(ssid).second) { + m_inactivatedNetListWidget->takeItem(m_inactivatedNetListWidget->row((m_itemsMap.value(ssid)).first)); + int height = m_itemsMap.value(ssid).second->height(); + m_inactivatedNetListWidget->setFixedHeight(m_inactivatedNetListWidget->height() - height - NET_LIST_SPACING); + m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); + } m_itemsMap.remove(ssid); } @@ -680,151 +682,51 @@ void WlanPage::onWifiEnabledChanged(bool isWifiOn) } } -void WlanPage::onRefreshIconTimer() -{ - //wifi页面打开时,每隔5s主动获取wifi信号强度对图标进行更新 - qDebug() << "refresh wifi icon" << Q_FUNC_INFO << __LINE__; -// QList 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__; -// } -// } -// updateByStrength(); - qDebug() << "updateByStrength"; - QList wlanList; - if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) { - return; - } - int height = 0; - qDebug() << "tttttotal" << wlanList.count(); - - int row = 0; - int j=0; - for (int i=0; im_activatedWlanSSid) { - continue; - } - qDebug() << "onRefreshIconTimer-1" << i; - qDebug() << "onRefreshIconTimer0 wwwwwwwlan:" << wlanList.at(i).m_NetSsid; - QMap>::iterator iter; - for (iter = m_itemsMap.begin(); iter != m_itemsMap.constEnd(); ++iter,j++) { - if (wlanList.at(i).m_NetSsid == iter.key()) { - if (j == row) { - continue; - } - qDebug() << "onRefreshIconTimer1 " << row << m_itemsMap.value(iter.key()).second->m_data->m_signalStrength; - QListWidgetItem *tempItem = m_itemsMap.value(iter.key()).first; - WlanListItem *tempWidget = m_itemsMap.value(iter.key()).second; - QModelIndex index = m_inactivatedNetListWidget->model()->index(row, 0, QModelIndex()); //new - if (tempItem) { - QModelIndex lastIndex = m_inactivatedNetListWidget->model()->index(m_inactivatedNetListWidget->row(tempItem), 0, QModelIndex()); -// QModelIndex lastIndex = m_inactivatedNetListWidget->model()->index(1, 0, QModelIndex()); - qDebug() << "onRefreshIconTimer2 " << m_inactivatedNetListWidget->row(tempItem) << row; - m_inactivatedNetListWidget->setIndexWidget(lastIndex, m_inactivatedNetListWidget->indexWidget(index)); //把第0个放下来 - m_inactivatedNetListWidget->setIndexWidget(index, tempWidget); //把信号最强的放到0行 - - QString indexSsid = static_cast(m_inactivatedNetListWidget->indexWidget(lastIndex))->getSsid(); - QString lastSsid = static_cast(m_inactivatedNetListWidget->indexWidget(index))->getSsid(); - qDebug() << "onRefreshIconTimer3 " << indexSsid << lastSsid; - QPair curPair = m_itemsMap.value(iter.key()); - QPair lastPair = m_itemsMap.value(lastSsid); - qDebug() << "onRefreshIconTimern " << curPair.second->m_data->m_NetSsid << lastPair.second->m_data->m_NetSsid; - curPair.second = lastPair.second; - lastPair.second = tempWidget; - m_itemsMap[iter.key()] = curPair; - m_itemsMap[lastSsid] = lastPair; - row++; - } - } - - } - } -// m_inactivatedNetListWidget->setFixedHeight(height); -// m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); - - QMap>::iterator i; - qDebug() << "items:" << m_itemsMap.count(); - for (i = m_itemsMap.begin(); i != m_itemsMap.constEnd(); ++i) { - qDebug() << "item" <m_data; - } - qDebug() << "eeeeeeeeend"; -} - void WlanPage::updateByStrength() { - qDebug() << "update By Strength"; + qDebug() << "Will update Wlan list by strength." << Q_FUNC_INFO << __LINE__; QList wlanList; if (!m_resource->getDeviceWifiNetwork(m_defaultDevice, wlanList)) { return; } - int height = 0; - qDebug() << "tttttotal" << wlanList.count(); - - QMap>::iterator iters; - qDebug() << "items:" << m_itemsMap.count(); - for (iters = m_itemsMap.begin(); iters != m_itemsMap.constEnd(); ++iters) { - qDebug() << "item" <m_data; - } - - int row=0; - int j=0; - for (int i=0; im_activatedWlanSSid) { +// int height = 0; + int currentRow = 0; + for (int i = 0; i < wlanList.length(); i ++) { + if (wlanList.at(i).m_NetSsid == this->m_activatedWlanSSid) { //排除已连接WiFi continue; } - qDebug() << "i:" << i; - QMap>::iterator iter; - for (iter = m_itemsMap.begin(); iter != m_itemsMap.constEnd(); ++iter,j++) { - qDebug() << wlanList.at(i).m_NetSsid << wlanList.at(i).m_signalStrength; - if (wlanList.at(i).m_NetSsid == iter.key()) { - if (j==row) { - continue; - } - m_inactivatedNetListWidget->removeItemWidget(iter.value().first); - delete iter.value().first; - QListWidgetItem *listwidgetItem = new QListWidgetItem(); -// QListWidgetItem *listwidgetItem = iter.value().first; - qDebug() << "QListWidgetItem" << listwidgetItem; -// *(iter.value().second->m_data) = wlanList.at(i); - KyWirelessNetItem itemData = wlanList.at(i); - WlanListItem *wlanWidget = new WlanListItem(m_resource, &itemData, m_defaultDevice); - wlanWidget->setWlanSignal(itemData.m_signalStrength); - connect(wlanWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); - connect(wlanWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked); - listwidgetItem->setSizeHint(QSize(m_inactivatedNetListWidget->width(), wlanWidget->height())); - m_inactivatedNetListWidget->insertItem(row, listwidgetItem); - qDebug() << "iiinsert" << m_inactivatedNetListWidget->row(listwidgetItem); - m_inactivatedNetListWidget->setItemWidget(listwidgetItem, wlanWidget); - QPair pair (listwidgetItem, wlanWidget); - m_itemsMap.insert(iter.key(), pair); - row++; - - if (height == 0) { - height += m_itemsMap[iter.key()].second->height(); - } - height += m_itemsMap[iter.key()].second->height() + NET_LIST_SPACING; - } + QString currentSsid = wlanList.at(i).m_NetSsid; //应该在第currentRow行的新的WiFi名称 + QModelIndex currentIndex = m_inactivatedNetListWidget->model()->index(currentRow, 0, QModelIndex()); //当前行的index + WlanListItem * lastWlan = static_cast(m_inactivatedNetListWidget->indexWidget(currentIndex)); //原来在第currentRow行的WlanListItem + if (lastWlan && currentSsid == lastWlan->getSsid()) { //WiFi的排序未改变,不需要修改,继续遍历 + currentRow ++; + continue; + } else if (!lastWlan) { //已经超出原列表长度了,需要new一个放上去 + KyWirelessNetItem *data = new KyWirelessNetItem(wlanList.at(i)); + WlanListItem *wlanItemWidget = new WlanListItem(m_resource, data, m_defaultDevice); + QListWidgetItem *wlanItem = new QListWidgetItem(); + connect(wlanItemWidget, &WlanListItem::itemHeightChanged, this, &WlanPage::onItemHeightChanged); + connect(wlanItemWidget, &WlanListItem::connectButtonClicked, this, &WlanPage::onConnectButtonClicked); + QPair 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); + int height = m_inactivatedNetListWidget->height() + wlanItemWidget->height() + NET_LIST_SPACING; + m_inactivatedNetListWidget->setFixedHeight(height); + m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); + } else {//找到了该位置的wifi而且与现在的排序不符,需要调整 + KyWirelessNetItem *data = new KyWirelessNetItem(wlanList.at(i)); + WlanListItem * currentWlan = new WlanListItem(m_resource, data, m_defaultDevice); + QPair newPair; + newPair.first = m_itemsMap.value(lastWlan->getSsid()).first; + newPair.second = currentWlan; + m_itemsMap[currentSsid] = newPair;//先把map中的当前行wlan替换掉,第currentRow行的ssid->currentRow行的控件 + m_itemsMap[lastWlan->getSsid()] = newPair;//临时使原来指向第currentRow行的的wlan依然指向这个value,防止访问空指针的情况发生,等遍历到该ssid时会赋予其正确的value + m_inactivatedNetListWidget->setIndexWidget(currentIndex, currentWlan); //最后把新的wlan填充到currentRow行 } - m_inactivatedNetListWidget->setFixedHeight(height); - m_inactivatedWlanListAreaCentralWidget->setFixedHeight(m_inactivatedNetListWidget->height() + m_hiddenWlanLabel->height()); + currentRow ++; } - - QMap>::iterator i; - qDebug() << "items:" << m_itemsMap.count(); - for (i = m_itemsMap.begin(); i != m_itemsMap.constEnd(); ++i) { - qDebug() << "item" <m_data; - } - qDebug() << "eeeeeeeeend"; } diff --git a/src/frontend/tab-pages/wlanpage.h b/src/frontend/tab-pages/wlanpage.h index 47a6ab48..f232e844 100644 --- a/src/frontend/tab-pages/wlanpage.h +++ b/src/frontend/tab-pages/wlanpage.h @@ -124,7 +124,7 @@ private slots: void showControlCenter(); void onWifiEnabledChanged(bool isWifiOn); - void onRefreshIconTimer(); +// void onRefreshIconTimer(); // void onsignalStrengthChange(QString, QString, int); diff --git a/src/main.cpp b/src/main.cpp index 080f03da..e97b2b9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) // QApplication a(argc, argv); QString id = QString("kylin-nm"+ QLatin1String(getenv("DISPLAY"))); QtSingleApplication a(id, argc, argv); -// qInstallMessageHandler(messageOutput); + qInstallMessageHandler(messageOutput); if (a.isRunning()) { auto connection = QDBusConnection::sessionBus(); QDBusInterface iface("com.kylin.network",