summaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@digia.com>2014-01-07 13:44:16 +0100
committerGatis Paeglis <gatis.paeglis@digia.com>2014-01-16 16:41:08 +0200
commit5980f4bff613e109375d3d841b2891847011074d (patch)
treec5f6f3f96b91b0c9d3ab148013b04b2628cf44bf /src/imports
parentbdc860eef15403f929df449a9c04f4e612bab46e (diff)
List the strongest access point when ssid equal
List only the strongest access point when sensing several access points within the same network. Change-Id: I58bf3083058f6e1c8a0c353b20d731672e64aefc Reviewed-by: Eirik Aavitsland <eirik.aavitsland@digia.com>
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/wifi/qwifinetworklist.cpp46
-rw-r--r--src/imports/wifi/qwifinetworklist.h2
2 files changed, 26 insertions, 22 deletions
diff --git a/src/imports/wifi/qwifinetworklist.cpp b/src/imports/wifi/qwifinetworklist.cpp
index e7fa92d..8ded5fd 100644
--- a/src/imports/wifi/qwifinetworklist.cpp
+++ b/src/imports/wifi/qwifinetworklist.cpp
@@ -14,7 +14,6 @@ QWifiNetworkList::QWifiNetworkList(QWifiManager *manager)
{
}
-
QHash<int, QByteArray> QWifiNetworkList::roleNames() const
{
QHash<int, QByteArray> names;
@@ -27,8 +26,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 +39,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 +56,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 +105,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();
-// }
}
diff --git a/src/imports/wifi/qwifinetworklist.h b/src/imports/wifi/qwifinetworklist.h
index f6e134c..d223bc9 100644
--- a/src/imports/wifi/qwifinetworklist.h
+++ b/src/imports/wifi/qwifinetworklist.h
@@ -18,7 +18,7 @@ public:
void parseScanResults(const QByteArray &data);
- QWifiNetwork *networkForBSSID(const QByteArray &bssid, int *pos);
+ QWifiNetwork *networkForSSID(const QByteArray &ssid, int *pos);
int rowCount(const QModelIndex &) const { return m_networks.size(); }
QVariant data(const QModelIndex &index, int role) const;