aboutsummaryrefslogtreecommitdiffstats
path: root/homescreen
diff options
context:
space:
mode:
Diffstat (limited to 'homescreen')
-rw-r--r--homescreen/qml/StatusArea.qml2
-rw-r--r--homescreen/src/main.cpp4
-rw-r--r--homescreen/src/statusbarmodel.cpp46
-rw-r--r--homescreen/src/statusbarmodel.h8
4 files changed, 59 insertions, 1 deletions
diff --git a/homescreen/qml/StatusArea.qml b/homescreen/qml/StatusArea.qml
index 24d2b18..3f2b280 100644
--- a/homescreen/qml/StatusArea.qml
+++ b/homescreen/qml/StatusArea.qml
@@ -157,7 +157,7 @@ Item {
}
}
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 704bb9a..39903e8 100644
--- a/homescreen/src/main.cpp
+++ b/homescreen/src/main.cpp
@@ -142,5 +142,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 bb44171..5e63b7d 100644
--- a/homescreen/src/statusbarmodel.cpp
+++ b/homescreen/src/statusbarmodel.cpp
@@ -20,6 +20,8 @@
#include <QtDBus/QDBusConnection>
+#include "network.h"
+
class StatusBarModel::Private
{
public:
@@ -30,6 +32,7 @@ private:
public:
StatusBarServer server;
QString iconList[StatusBarServer::SupportedCount];
+ Network *network;
};
StatusBarModel::Private::Private(StatusBarModel *parent)
@@ -60,6 +63,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..4e31f19 100644
--- a/homescreen/src/statusbarmodel.h
+++ b/homescreen/src/statusbarmodel.h
@@ -18,6 +18,7 @@
#define STATUSBARMODEL_H
#include <QtCore/QAbstractListModel>
+#include <QtQml/QQmlContext>
class StatusBarModel : public QAbstractListModel
{
@@ -26,14 +27,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