diff options
author | Gatis Paeglis <gatis.paeglis@theqtcompany.com> | 2014-11-06 18:06:49 +0100 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@theqtcompany.com> | 2014-12-02 12:39:18 +0200 |
commit | fc2f6ac9d7e7ac8ab343c11786f7437610fa0a19 (patch) | |
tree | 1f11946d6641ccffd42e8b078ede641775debc53 /src/imports/wifi/qwifinetworklistmodel.cpp | |
parent | 5e83898cff3991d1c08f628d2687f7e2038f182b (diff) |
[Wifi] graduate from Qt.labs.wifi 0.1 to B2Qt.Wifi 1.0
- Make wifi library available from c++
1) included with "#include <B2QtWifi>", available classes are:
QWifiDevice, QWifiManager, QWifiConfiguration
- Re-design of API:
1) connectedSSID -> currentSSID
get current network from this property instead of networks state change events
2) networkStateChanaged(QWifiNetwork *) -> networkStateChanged(NetworkState)
Don't expose QWifiNetwork objects to library users, use data model roles
instead, no need to pollute API with "read-only" class. The flaws of exposing
QWifiNetwork become apparent when looking at C++ API.
3) New BackendState enum for backend state changes events, backendStateChanged(BackendState)
Initializing backend can be lengthy operation and can block GUI thread,
same is true for DHCP requests, now these operations are moved into a separate thread
and backend state change events are delivered asynchronously.
4) Make WifiManager a Singleton, we don't want several instances starting
and stopping system processes and it makes global state handling simpler.
5) Rename Interface -> WifiDevice
6!) Introducing QWifiConfiguration. This abstraction allows for easy
way to add new features, whatever we choose to support from:
http://w1.fi/cgit/hostap/plain/wpa_supplicant/wpa_supplicant.conf
The idea for it is to be a Qt-style wrapper for "network {}" configurations
from wpa_supplicant.conf.
Also this makes life simpler for developers if they know what network they
will be using, they can omit scanning, listing, selecting parts and do something
like this instead:
WifiConfiguration {
id: config
ssid: "network name"
passphrase: "12345678"
}
if (!WifiManager.connect(config))
print("failed to connect: " + WifiManager.lastError)
- Optimizations:
1) Async. event delivery.
2) eLinux: Don't use "ifup", it is slow because it starts dhcp
request even before any network has been configured. Use
start-stop-daemon and ifconfig directly.
- Bug fixes (many), but most importantly:
1) Get backend state properly when WifiManager is created.
- Public header cleanup
- Other:
1) Added categorized logging.
2) Methods to get/set wifi interface name. Not exposed to qml.
- Missing parts that will be added as a separate patch:
* [doc] Getting started guide for c++ and qml
* [doc] Update for qml docs and new docs for c++. The current docs
are out-of-date.
Task-number: QTEE-649
Task-number: QTEE-810
Change-Id: I7dc8709aed2de622828a119749aef31534a4296d
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src/imports/wifi/qwifinetworklistmodel.cpp')
-rw-r--r-- | src/imports/wifi/qwifinetworklistmodel.cpp | 142 |
1 files changed, 0 insertions, 142 deletions
diff --git a/src/imports/wifi/qwifinetworklistmodel.cpp b/src/imports/wifi/qwifinetworklistmodel.cpp deleted file mode 100644 index 1886413..0000000 --- a/src/imports/wifi/qwifinetworklistmodel.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Digia Plc -** All rights reserved. -** For any questions to Digia, please use the contact form at -** http://www.qt.io -** -** 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://www.qt.io -** -****************************************************************************/ -#include "qwifinetworklistmodel.h" - -#include <QtCore> - -const int ID_NETWORK = (Qt::ItemDataRole) (Qt::UserRole + 1); - -QWifiNetworkListModel::QWifiNetworkListModel(QWifiManager *manager) - : m_manager(manager) -{ -} - -QWifiNetworkListModel::~QWifiNetworkListModel() -{ - qDeleteAll(m_networks); - qDeleteAll(m_outOfRangeNetworks); - m_networks.clear(); - m_outOfRangeNetworks.clear(); -} - -QHash<int, QByteArray> QWifiNetworkListModel::roleNames() const -{ - QHash<int, QByteArray> names; - names.insert(ID_NETWORK, "network"); - return names; -} - -QVariant QWifiNetworkListModel::data(const QModelIndex &index, int role) const -{ - QWifiNetwork *n = m_networks.at(index.row()); - switch (role) { - case ID_NETWORK: return QVariant::fromValue((QObject *) n); - } - - qWarning("QWifiNetworkListModel::data(), undefined role: %d\n", role); - - return QVariant(); -} - -QWifiNetwork *QWifiNetworkListModel::networkForSSID(const QByteArray &ssid, int *pos) -{ - for (int i = 0; i < m_networks.size(); ++i) { - if (m_networks.at(i)->ssid() == ssid) { - if (pos) - *pos = i; - return m_networks.at(i); - } - } - return 0; -} - -QWifiNetwork *QWifiNetworkListModel::outOfRangeListContains(const QByteArray &ssid) -{ - for (int i = 0; i < m_outOfRangeNetworks.length(); ++i) - if (m_outOfRangeNetworks.at(i)->ssid() == ssid) - return m_outOfRangeNetworks.takeAt(i); - return 0; -} - -void QWifiNetworkListModel::parseScanResults(const QByteArray &results) -{ - QList<QByteArray> lines = results.split('\n'); - 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; - int pos = 0; - sensibleNetworks.insert(info.at(4)); - QWifiNetwork *knownNetwork = networkForSSID(info.at(4), &pos); - if (!knownNetwork) - knownNetwork = outOfRangeListContains(info.at(4)); - // signal strength is in dBm. Deprecated, but still widely used "wext" - // wifi driver reports positive values for signal strength, we workaround that. - int signalStrength = qAbs(info.at(2).trimmed().toInt()) * -1; - if (!knownNetwork) { - QWifiNetwork *network = new QWifiNetwork(); - network->setOutOfRange(false); - network->setBssid(info.at(0)); - network->setFlags(info.at(3)); - network->setSignalStrength(signalStrength); - network->setSsid(info.at(4)); - beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size()); - m_networks << network; - endInsertRows(); - } else { - if (knownNetwork->outOfRange()) { - // known network has come back into a range - knownNetwork->setOutOfRange(false); - beginInsertRows(QModelIndex(), m_networks.size(), m_networks.size()); - m_networks << knownNetwork; - endInsertRows(); - pos = m_networks.length() - 1; - } - // ssids are the same, compare bssids.. - if (knownNetwork->bssid() == info.at(0)) { - // same access point, simply update the signal strength - knownNetwork->setSignalStrength(signalStrength); - knownNetwork->setOutOfRange(false); - dataChanged(createIndex(pos, 0), createIndex(pos, 0)); - } else if (knownNetwork->signalStrength() < signalStrength) { - // replace with a stronger access point within the same network - m_networks.at(pos)->setOutOfRange(false); - m_networks.at(pos)->setBssid(info.at(0)); - m_networks.at(pos)->setFlags(info.at(3)); - m_networks.at(pos)->setSignalStrength(signalStrength); - m_networks.at(pos)->setSsid(info.at(4)); - dataChanged(createIndex(pos, 0), createIndex(pos, 0)); - } - } - } - // remove out-of-range networks from the data model - for (int i = 0; i < m_networks.size();) { - if (!sensibleNetworks.contains(m_networks.at(i)->ssid())) { - beginRemoveRows(QModelIndex(), i, i); - QWifiNetwork *n = m_networks.takeAt(i); - n->setOutOfRange(true); - m_outOfRangeNetworks.append(n); - endRemoveRows(); - } else { - ++i; - } - } -} |