diff options
-rw-r--r-- | network/network.cpp | 13 | ||||
-rw-r--r-- | network/network.h | 5 | ||||
-rw-r--r-- | network/wifinetworkmodel.cpp | 3 | ||||
-rw-r--r-- | network/wifinetworkmodel.h | 3 |
4 files changed, 23 insertions, 1 deletions
diff --git a/network/network.cpp b/network/network.cpp index d2a00ff..7bcf6d0 100644 --- a/network/network.cpp +++ b/network/network.cpp @@ -31,7 +31,8 @@ Network::Network (QUrl &url, QQmlContext *context, QObject * parent) : m_mloop(nullptr), m_wifi(nullptr), m_wifiConnected(false), - m_wifiEnabled(false) + m_wifiEnabled(false), + m_wifiStrength(0) { m_mloop = new MessageEngine(url); m_wifi = new WifiNetworkModel(); @@ -41,6 +42,7 @@ Network::Network (QUrl &url, QQmlContext *context, QObject * parent) : QObject::connect(m_mloop, &MessageEngine::connected, this, &Network::onConnected); QObject::connect(m_mloop, &MessageEngine::disconnected, this, &Network::onDisconnected); QObject::connect(m_mloop, &MessageEngine::messageReceived, this, &Network::onMessageReceived); + QObject::connect(m_wifi, &WifiNetworkModel::strengthChanged, this, &Network::updateWifiStrength); } Network::~Network() @@ -159,6 +161,9 @@ bool Network::addService(QJsonObject service) WifiNetwork *network = new WifiNetwork(address, security, id, ssid, state, strength); m_wifi->addNetwork(network); + if ((state == "ready") || (state == "online")) + updateWifiStrength(strength); + return true; } @@ -202,6 +207,12 @@ void Network::updateWifiStatus(QJsonObject properties) } } +void Network::updateWifiStrength(int strength) +{ + m_wifiStrength = strength; + emit wifiStrengthChanged(m_wifiStrength); +} + void Network::parseTechnologies(QJsonArray technologies) { for (auto value : technologies) { diff --git a/network/network.h b/network/network.h index dc52dd2..499f612 100644 --- a/network/network.h +++ b/network/network.h @@ -43,9 +43,11 @@ class Network : public QObject Q_PROPERTY(bool wifiConnected READ wifiConnected NOTIFY wifiConnectedChanged) Q_PROPERTY(bool wifiEnabled READ wifiEnabled NOTIFY wifiEnabledChanged) + Q_PROPERTY(bool wifiStrength READ wifiStrength NOTIFY wifiStrengthChanged) bool wifiConnected() const { return m_wifiConnected; } bool wifiEnabled() const { return m_wifiEnabled; } + bool wifiStrength() const { return m_wifiStrength; } signals: void inputRequest(int id); @@ -53,6 +55,7 @@ class Network : public QObject void statusChanged(bool connected); void wifiConnectedChanged(bool connected); void wifiEnabledChanged(bool enabled); + void wifiStrengthChanged(int strength); private: MessageEngine *m_mloop; @@ -60,6 +63,7 @@ class Network : public QObject WifiNetworkModel *m_wifi; bool m_wifiConnected; bool m_wifiEnabled; + int m_wifiStrength; void updateWifiStatus(QJsonObject properties); void updateServiceProperties(QJsonObject data); @@ -79,6 +83,7 @@ class Network : public QObject void onConnected(); void onDisconnected(); void onMessageReceived(MessageType, Message*); + void updateWifiStrength(int); const QStringList events { "agent", diff --git a/network/wifinetworkmodel.cpp b/network/wifinetworkmodel.cpp index 8a83919..3cfd7dd 100644 --- a/network/wifinetworkmodel.cpp +++ b/network/wifinetworkmodel.cpp @@ -163,6 +163,9 @@ void WifiNetworkModel::updateProperties(QString service, QJsonObject properties) if (properties.contains("strength")) { network->setStrength(properties.value("strength").toInt()); emit dataChanged(indexOf(network), indexOf(network)); + if ((network->state() == "ready") || + (network->state() == "online")) + emit strengthChanged(network->strength()); } } } diff --git a/network/wifinetworkmodel.h b/network/wifinetworkmodel.h index 27e635a..0df4459 100644 --- a/network/wifinetworkmodel.h +++ b/network/wifinetworkmodel.h @@ -58,6 +58,9 @@ class WifiNetworkModel : public QAbstractListModel QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; void updateProperties(QString service, QJsonObject properties); + signals: + void strengthChanged(int strength); + protected: QHash<int, QByteArray> roleNames() const; |