aboutsummaryrefslogtreecommitdiffstats
path: root/homescreen/src/statusbarmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'homescreen/src/statusbarmodel.cpp')
-rw-r--r--homescreen/src/statusbarmodel.cpp46
1 files changed, 46 insertions, 0 deletions
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())