diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-11-18 16:15:11 -0600 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-11-18 16:15:11 -0600 |
commit | 6e1ae4ba0f9e4ee93dd3b827f0d4c9f1eafde5ad (patch) | |
tree | c7418ee8333f64717684dc20bf4b0f5bfb024fac /ui/qt5 | |
parent | 8dd9910c0cce121b7120cd542fa1557da7eb2282 (diff) | |
download | horizon-6e1ae4ba0f9e4ee93dd3b827f0d4c9f1eafde5ad.tar.gz horizon-6e1ae4ba0f9e4ee93dd3b827f0d4c9f1eafde5ad.tar.bz2 horizon-6e1ae4ba0f9e4ee93dd3b827f0d4c9f1eafde5ad.tar.xz horizon-6e1ae4ba0f9e4ee93dd3b827f0d4c9f1eafde5ad.zip |
Qt UI: Sort wireless network list by signal strength
Diffstat (limited to 'ui/qt5')
-rw-r--r-- | ui/qt5/netsimplewifipage.cc | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ui/qt5/netsimplewifipage.cc b/ui/qt5/netsimplewifipage.cc index bec143c..7ca866c 100644 --- a/ui/qt5/netsimplewifipage.cc +++ b/ui/qt5/netsimplewifipage.cc @@ -161,6 +161,7 @@ int NetworkSimpleWirelessPage::nextId() const { #ifdef HAS_INSTALL_ENV int NetworkSimpleWirelessPage::processScan(wpactrl_t *c, const char *, size_t) { assert(c == &control); + std::vector<QListWidgetItem *> netitems; stralloc buf = STRALLOC_ZERO; @@ -209,7 +210,7 @@ int NetworkSimpleWirelessPage::processScan(wpactrl_t *c, const char *, size_t) { icon = QIcon::fromTheme("network-wireless-signal-excellent"); } - QListWidgetItem *netitem = new QListWidgetItem(ssidListView); + QListWidgetItem *netitem = new QListWidgetItem; netitem->setText(QString::fromStdString(ssid)); netitem->setIcon(icon); netitem->setToolTip(tr("Frequency: %1 MHz\nBSSID: %2\nRSSI: %3") @@ -217,6 +218,18 @@ int NetworkSimpleWirelessPage::processScan(wpactrl_t *c, const char *, size_t) { .arg(fromMacAddress(network.bssid)) .arg(network.signal_level)); netitem->setData(Qt::UserRole, QString::fromStdString(flags)); + netitem->setData(Qt::UserRole + 1, network.signal_level); + netitems.push_back(netitem); + } + + std::sort(netitems.begin(), netitems.end(), + [](QListWidgetItem *left, QListWidgetItem *right) { + return left->data(Qt::UserRole + 1).toInt() < + right->data(Qt::UserRole + 1).toInt(); + }); + + for(auto &item : netitems) { + ssidListView->addItem(item); } return 1; |