diff options
Diffstat (limited to 'network')
-rw-r--r-- | network/abstractnetworkmodel.cpp | 13 | ||||
-rw-r--r-- | network/network.cpp | 7 | ||||
-rw-r--r-- | network/wifinetworkmodel.cpp | 20 | ||||
-rw-r--r-- | network/wirednetworkmodel.cpp | 19 |
4 files changed, 43 insertions, 16 deletions
diff --git a/network/abstractnetworkmodel.cpp b/network/abstractnetworkmodel.cpp index 6eada6a..ad5a31a 100644 --- a/network/abstractnetworkmodel.cpp +++ b/network/abstractnetworkmodel.cpp @@ -11,12 +11,15 @@ AbstractNetworkModel::AbstractNetworkModel(QObject *parent) void AbstractNetworkModel::addNetwork(ConnectionProfile *network) { beginInsertRows(QModelIndex(), rowCount(), rowCount()); - m_networks << network; + m_networks.insert(rowCount(), network); endInsertRows(); } void AbstractNetworkModel::removeNetwork(ConnectionProfile *network) { + if (m_networks.isEmpty() || (network == nullptr)) + return; + int row = m_networks.indexOf(network); beginRemoveRows(QModelIndex(), row, row); m_networks.removeAt(row); @@ -26,14 +29,20 @@ void AbstractNetworkModel::removeNetwork(ConnectionProfile *network) void AbstractNetworkModel::removeAllNetworks() { + if (m_networks.isEmpty()) + return; + beginRemoveRows(QModelIndex(), 0, m_networks.count() - 1); qDeleteAll(m_networks.begin(), m_networks.end()); - m_networks.clear(); endRemoveRows(); + m_networks.clear(); } ConnectionProfile *AbstractNetworkModel::getNetwork(QString service) { + if (m_networks.isEmpty()) + return nullptr; + for (auto network : m_networks) { if (network->service() == service) return network; diff --git a/network/network.cpp b/network/network.cpp index 679f374..4ce701f 100644 --- a/network/network.cpp +++ b/network/network.cpp @@ -200,9 +200,9 @@ void Network::parseTechnologies(QJsonArray technologies) QJsonObject properties = technology.value("properties").toObject(); QString type = properties.value("type").toString(); - AdapterIf* adapter = findAdapter(type); - if (adapter) - adapter->updateStatus(properties); + AdapterIf* adapter = findAdapter(type); + if (adapter) + adapter->updateStatus(properties); } } @@ -233,7 +233,6 @@ void Network::processEvent(NetworkMessage *nmsg) for (auto value : services) { QJsonObject service = value.toObject(); QString action = service.value("action").toString(); - QString id = service.value("service").toString(); if (action == "changed") { addService(service); } else if (action == "removed") { diff --git a/network/wifinetworkmodel.cpp b/network/wifinetworkmodel.cpp index 71e5298..7c32779 100644 --- a/network/wifinetworkmodel.cpp +++ b/network/wifinetworkmodel.cpp @@ -1,5 +1,6 @@ #include "wifinetworkmodel.h" #include "connectionprofile.h" +#include <QVector> #include <QDebug> WifiNetworkModel::WifiNetworkModel(QObject *parent) @@ -47,24 +48,33 @@ QHash<int, QByteArray> WifiNetworkModel::roleNames() const { void WifiNetworkModel::updateProperties(QString service, QJsonObject properties) { ConnectionProfile *network; + QVector<int> vroles; + bool sbcast = false; - // FIXME: add role parameter to emits if ((network = getNetwork(service))) { if (properties.contains("ipv4")) { QString address = properties.value("ipv4").toObject().value("address").toString(); network->setAddress(address); - emit dataChanged(indexOf(network), indexOf(network)); + vroles.push_back(AddressRole); } if (properties.contains("state")) { network->setState(properties.value("state").toString()); - emit dataChanged(indexOf(network), indexOf(network)); + vroles.push_back(StateRole); + if ((network->state() == "ready") || + (network->state() == "online")) + sbcast = true; } if (properties.contains("strength")) { network->setStrength(properties.value("strength").toInt()); - emit dataChanged(indexOf(network), indexOf(network)); + vroles.push_back(StrengthRole); if ((network->state() == "ready") || (network->state() == "online")) - emit strengthChanged(network->strength()); + sbcast = true; + } + if (!vroles.isEmpty()) { + emit dataChanged(indexOf(network), indexOf(network), vroles); + if (sbcast) + emit strengthChanged(network->strength()); } } } diff --git a/network/wirednetworkmodel.cpp b/network/wirednetworkmodel.cpp index d14bce4..01a50fb 100644 --- a/network/wirednetworkmodel.cpp +++ b/network/wirednetworkmodel.cpp @@ -1,5 +1,6 @@ #include "wirednetworkmodel.h" #include "connectionprofile.h" +#include <QVector> #include <QDebug> WiredNetworkModel::WiredNetworkModel(QObject *parent) @@ -9,8 +10,13 @@ WiredNetworkModel::WiredNetworkModel(QObject *parent) QVariant WiredNetworkModel::data(const QModelIndex &index, int role) const { + QVariant ret; + + if (!index.isValid()) + return ret; + if (index.row() < 0 || index.row() >= m_networks.count()) - return QVariant(); + return ret; const ConnectionProfile *network = m_networks[index.row()]; @@ -25,7 +31,7 @@ QVariant WiredNetworkModel::data(const QModelIndex &index, int role) const return network->state(); } - return QVariant(); + return ret; } QHash<int, QByteArray> WiredNetworkModel::roleNames() const { @@ -41,17 +47,20 @@ QHash<int, QByteArray> WiredNetworkModel::roleNames() const { void WiredNetworkModel::updateProperties(QString service, QJsonObject properties) { ConnectionProfile *network; + QVector<int> vroles; - // FIXME: add role parameter to emits if ((network = getNetwork(service))) { if (properties.contains("ipv4")) { QString address = properties.value("ipv4").toObject().value("address").toString(); network->setAddress(address); - emit dataChanged(indexOf(network), indexOf(network)); + vroles.push_back(AddressRole); } if (properties.contains("state")) { network->setState(properties.value("state").toString()); - emit dataChanged(indexOf(network), indexOf(network)); + vroles.push_back(StateRole); } + if (!vroles.isEmpty()) + emit dataChanged(indexOf(network), indexOf(network), vroles); + } } |