diff options
author | Matt Porter <mporter@konsulko.com> | 2018-07-27 13:07:56 -0400 |
---|---|---|
committer | Matt Porter <mporter@konsulko.com> | 2018-07-27 13:07:56 -0400 |
commit | db717523a6f9797312c94e756bac1b7b542e40ed (patch) | |
tree | 494726760bdf61f31b767216e5338bfbb06f5869 | |
parent | a8b94699ae7ec155729fcccda2be4f22328ca790 (diff) |
Convert StatusBarModel to get WiFi status info from network binding
The StatusBarModel updates icons using an exposed DBus API that
avoids the appfw. The new networking binding does not support the
out of band StatusBar DBus API. Use events from the network binding
(exposed as Qt properties) to update the WiFi status indicator.
Bug-AGL: SPEC-1628
Change-Id: Ie91f69c1d5d54d4fb225e4e99a1d5a94a0dc83e7
Signed-off-by: Matt Porter <mporter@konsulko.com>
-rw-r--r-- | homescreen/qml/StatusArea.qml | 2 | ||||
-rw-r--r-- | homescreen/src/main.cpp | 4 | ||||
-rw-r--r-- | homescreen/src/statusbarmodel.cpp | 46 | ||||
-rw-r--r-- | homescreen/src/statusbarmodel.h | 7 | ||||
-rw-r--r-- | package/config.xml | 1 |
5 files changed, 59 insertions, 1 deletions
diff --git a/homescreen/qml/StatusArea.qml b/homescreen/qml/StatusArea.qml index ab14a23..1a86a57 100644 --- a/homescreen/qml/StatusArea.qml +++ b/homescreen/qml/StatusArea.qml @@ -117,7 +117,7 @@ Item { Layout.preferredWidth: 76 spacing: -10 Repeater { - model: StatusBarModel {} + model: StatusBarModel { objectName: "statusBar" } delegate: Image { Layout.preferredWidth: 77 Layout.preferredHeight: 73 diff --git a/homescreen/src/main.cpp b/homescreen/src/main.cpp index 19bb0d3..71dc782 100644 --- a/homescreen/src/main.cpp +++ b/homescreen/src/main.cpp @@ -140,5 +140,9 @@ int main(int argc, char *argv[]) QQuickWindow *window = qobject_cast<QQuickWindow *>(root); QObject::connect(window, SIGNAL(frameSwapped()), layoutHandler, SLOT(slotActivateSurface())); + QList<QObject *> sobjs = engine.rootObjects(); + StatusBarModel *statusBar = sobjs.first()->findChild<StatusBarModel *>("statusBar"); + statusBar->init(bindingAddress, engine.rootContext()); + return a.exec(); } diff --git a/homescreen/src/statusbarmodel.cpp b/homescreen/src/statusbarmodel.cpp index 5438e89..19767a9 100644 --- a/homescreen/src/statusbarmodel.cpp +++ b/homescreen/src/statusbarmodel.cpp @@ -19,6 +19,8 @@ #include <QtDBus/QDBusConnection> +#include "network.h" + class StatusBarModel::Private { public: @@ -29,6 +31,7 @@ private: public: StatusBarServer server; QString iconList[StatusBarServer::SupportedCount]; + Network *network; }; StatusBarModel::Private::Private(StatusBarModel *parent) @@ -59,6 +62,49 @@ StatusBarModel::~StatusBarModel() delete d; } +void StatusBarModel::init(QUrl &url, QQmlContext *context) +{ + d->network = new Network(url, context); + context->setContextProperty("network", d->network); + + QObject::connect(d->network, &Network::wifiConnectedChanged, this, &StatusBarModel::onWifiConnectedChanged); + QObject::connect(d->network, &Network::wifiEnabledChanged, this, &StatusBarModel::onWifiEnabledChanged); + QObject::connect(d->network, &Network::wifiStrengthChanged, this, &StatusBarModel::onWifiStrengthChanged); + + setWifiStatus(d->network->wifiConnected(), d->network->wifiEnabled(), d->network->wifiStrength()); +} + +void StatusBarModel::setWifiStatus(bool connected, bool enabled, int strength) +{ + if (enabled && connected) + if (strength < 30) + d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_1Bar-01.png")); + else if (strength < 50) + d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_2Bars-01.png")); + else if (strength < 70) + d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_3Bars-01.png")); + else + d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_Full-01.png")); + else + d->server.setStatusIcon(0, QStringLiteral("qrc:/images/Status/HMI_Status_Wifi_NoBars-01.png")); +} + +void StatusBarModel::onWifiConnectedChanged(bool connected) +{ + setWifiStatus(connected, d->network->wifiEnabled(), d->network->wifiStrength()); +} + +void StatusBarModel::onWifiEnabledChanged(bool enabled) +{ + setWifiStatus(d->network->wifiConnected(), enabled, d->network->wifiStrength()); +} + +void StatusBarModel::onWifiStrengthChanged(int strength) +{ + qInfo() << "Strength changed: " << strength; + setWifiStatus(d->network->wifiConnected(), d->network->wifiEnabled(), strength); +} + int StatusBarModel::rowCount(const QModelIndex &parent) const { if (parent.isValid()) diff --git a/homescreen/src/statusbarmodel.h b/homescreen/src/statusbarmodel.h index 8d6a70b..39fe148 100644 --- a/homescreen/src/statusbarmodel.h +++ b/homescreen/src/statusbarmodel.h @@ -26,14 +26,21 @@ public: explicit StatusBarModel(QObject *parent = NULL); ~StatusBarModel(); + void init(QUrl &url, QQmlContext *context); int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QHash<int, QByteArray> roleNames() const override; + // slots + void onWifiConnectedChanged(bool connected); + void onWifiEnabledChanged(bool enabled); + void onWifiStrengthChanged(int strength); + private: class Private; Private *d; + void setWifiStatus(bool connected, bool enabled, int strength); }; #endif // STATUSBARMODEL_H diff --git a/package/config.xml b/package/config.xml index 036b9ba..f6a040f 100644 --- a/package/config.xml +++ b/package/config.xml @@ -8,6 +8,7 @@ <license>APL 2.0</license> <feature name="urn:AGL:widget:required-api"> <param name="homescreen" value="ws" /> + <param name="network-manager" value="ws" /> <param name="weather" value="ws" /> <param name="windowmanager" value="ws" /> </feature> |