summaryrefslogtreecommitdiffstats
path: root/src/imports/wifi/qwifinetworklist.cpp
diff options
context:
space:
mode:
authorKalle Viironen <kalle.viironen@digia.com>2014-02-21 12:24:09 +0200
committerKalle Viironen <kalle.viironen@digia.com>2014-02-21 12:27:37 +0200
commit436af494659d416cfbd531b8d3ba9fc49e2fa710 (patch)
treeab5e6b48e711a3c3a2e2cd4399ce1b3d34347406 /src/imports/wifi/qwifinetworklist.cpp
parenta10b8b669d357325e9f0b735bcda42758ad2b3d0 (diff)
parent4738811e35a559d238ba20703eb792fca8f5756b (diff)
Merge branch 'stable' into releaseQtEE_v2.0.0
* stable: (90 commits) Doc: Document support services for Yocto recipes doc: minor changes to customization inline code blocks Doc: Clarify which Qt Creator templates work out of the box Doc: Fix missing sudo for i.MX6 embedded Linux deployment Doc: Fixed 32bit package install command for newer ubuntu versions doc: add quide how to use b2qt_build_scripts Doc: Add instructions how to install newer VirtualBox [Wifi] Fix initialization code Doc: Explain about disabling surfaceflinger Enable internet on eAndroid emulator Doc: Add instructions for building Boot2Qt demos Doc: Troubleshooting entry for BeagleBone Black HDMI issues Don't use wifi on Emulator Doc: Document building your own embedded linux stack Update copyright year Doc: Fix the 2.0 release date Doc: ChangeLog: Remove 'black screen after exit' from bugfixes Doc: Use a global Qt documentation template Doc: Add changelog Disable QConnectivity daemon on emulator ... Change-Id: I25ba7e19677c3d91d5e78ab68291296face3c073
Diffstat (limited to 'src/imports/wifi/qwifinetworklist.cpp')
-rw-r--r--src/imports/wifi/qwifinetworklist.cpp64
1 files changed, 43 insertions, 21 deletions
diff --git a/src/imports/wifi/qwifinetworklist.cpp b/src/imports/wifi/qwifinetworklist.cpp
index e7fa92d..60fdc53 100644
--- a/src/imports/wifi/qwifinetworklist.cpp
+++ b/src/imports/wifi/qwifinetworklist.cpp
@@ -1,3 +1,21 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc
+** All rights reserved.
+** For any questions to Digia, please use the contact form at
+** http://qt.digia.com/
+**
+** This file is part of Qt Enterprise Embedded.
+**
+** Licensees holding valid Qt Enterprise licenses may use this file in
+** accordance with the Qt Enterprise License Agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia.
+**
+** If you have questions regarding the use of this file, please use
+** the contact form at http://qt.digia.com/
+**
+****************************************************************************/
#include "qwifinetworklist.h"
#include <QtCore>
@@ -14,7 +32,6 @@ QWifiNetworkList::QWifiNetworkList(QWifiManager *manager)
{
}
-
QHash<int, QByteArray> QWifiNetworkList::roleNames() const
{
QHash<int, QByteArray> names;
@@ -27,8 +44,6 @@ QHash<int, QByteArray> QWifiNetworkList::roleNames() const
return names;
}
-
-
QVariant QWifiNetworkList::data(const QModelIndex &index, int role) const
{
QWifiNetwork *n = m_networks.at(index.row());
@@ -42,15 +57,15 @@ QVariant QWifiNetworkList::data(const QModelIndex &index, int role) const
case ID_NETWORK: return QVariant::fromValue((QObject *) n);
}
- qDebug("QWifiNetworkList::data(), undefined role: %d\n", role);
+ qWarning("QWifiNetworkList::data(), undefined role: %d\n", role);
return QVariant();
}
-QWifiNetwork *QWifiNetworkList::networkForBSSID(const QByteArray &bssid, int *pos)
+QWifiNetwork *QWifiNetworkList::networkForSSID(const QByteArray &ssid, int *pos)
{
for (int i=0; i<m_networks.size(); ++i) {
- if (m_networks.at(i)->bssid() == bssid) {
+ if (m_networks.at(i)->ssid() == ssid) {
if (pos)
*pos = i;
return m_networks.at(i);
@@ -59,37 +74,48 @@ QWifiNetwork *QWifiNetworkList::networkForBSSID(const QByteArray &bssid, int *po
return 0;
}
-
void QWifiNetworkList::parseScanResults(const QByteArray &results)
{
QList<QByteArray> lines = results.split('\n');
- QSet<QByteArray> bssids;
+ QSet<QByteArray> sensibleNetworks;
for (int i=1; i<lines.size(); ++i) {
QList<QByteArray> info = lines.at(i).split('\t');
if (info.size() < 5 || info.at(4).isEmpty() || info.at(0).isEmpty())
continue;
- bssids.insert(info.at(0));
int pos = 0;
- QWifiNetwork *existing = networkForBSSID(info.at(0), &pos);
- if (!existing) {
+ if (!sensibleNetworks.contains(info.at(4)))
+ sensibleNetworks.insert(info.at(4));
+ QWifiNetwork *existingNetwork = networkForSSID(info.at(4), &pos);
+ if (!existingNetwork) {
QWifiNetwork *network = new QWifiNetwork();
network->setBssid(info.at(0));
network->setFlags(info.at(3));
+ // signal strength is in dBm
network->setSignalStrength(info.at(2).toInt());
network->setSsid(info.at(4));
beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size());
m_networks << network;
endInsertRows();
-
} else {
- existing->setSignalStrength(info.at(2).toInt());
- dataChanged(createIndex(pos, 0), createIndex(pos, 0));
+ // ssids are the same, compare bssids..
+ if (existingNetwork->bssid() == info.at(0)) {
+ // same access point, simply update the signal strength
+ existingNetwork->setSignalStrength(info.at(2).toInt());
+ dataChanged(createIndex(pos, 0), createIndex(pos, 0));
+ } else if (existingNetwork->signalStrength() < info.at(2).toInt()) {
+ // replace with a stronger access point within the same network
+ m_networks.at(pos)->setBssid(info.at(0));
+ m_networks.at(pos)->setFlags(info.at(3));
+ m_networks.at(pos)->setSignalStrength(info.at(2).toInt());
+ m_networks.at(pos)->setSsid(info.at(4));
+ dataChanged(createIndex(pos, 0), createIndex(pos, 0));
+ }
}
}
-
- for (int i=0; i<m_networks.size(); ) {
- if (!bssids.contains(m_networks.at(i)->bssid())) {
+ // remove networks that have gone out of range
+ for (int i = 0; i < m_networks.size(); ++i) {
+ if (!sensibleNetworks.contains(m_networks.at(i)->ssid())) {
beginRemoveRows(QModelIndex(), i, i);
delete m_networks.takeAt(i);
endRemoveRows();
@@ -97,10 +123,6 @@ void QWifiNetworkList::parseScanResults(const QByteArray &results)
++i;
}
}
-
-// for (int i=0; i<m_networks.size(); ++i) {
-// qDebug() << " - network:" << m_networks.at(i)->bssid() << m_networks.at(i)->ssid() << m_networks.at(i)->flags() << m_networks.at(i)->signalStrength();
-// }
}