summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sysinfowatchlet/sysinfowatchlet.cpp20
-rw-r--r--sysinfowatchlet/sysinfowatchlet.h2
2 files changed, 21 insertions, 1 deletions
diff --git a/sysinfowatchlet/sysinfowatchlet.cpp b/sysinfowatchlet/sysinfowatchlet.cpp
index 46d45e7..e159fc7 100644
--- a/sysinfowatchlet/sysinfowatchlet.cpp
+++ b/sysinfowatchlet/sysinfowatchlet.cpp
@@ -1,3 +1,5 @@
+#include <QtDebug>
+
#include "sysinfowatchlet.h"
using namespace sowatch;
@@ -12,12 +14,28 @@ SysInfoWatchlet::SysInfoWatchlet(WatchServer* server) :
rootContext()->setContextProperty("networkName", "");
setSource(QUrl(SOWATCH_QML_DIR "/sysinfowatchlet/" + server->watch()->model() + ".qml"));
connect(this, SIGNAL(activated()), SLOT(handleActivated()));
+ connect(this, SIGNAL(deactivated()), SLOT(handleDeactivated()));
}
void SysInfoWatchlet::handleActivated()
{
+ updateInformation();
+ connect(_devInfo, SIGNAL(batteryLevelChanged(int)), this, SLOT(updateInformation()));
+ connect(_netMgr, SIGNAL(onlineStateChanged(bool)), this, SLOT(updateInformation()));
+}
+
+void SysInfoWatchlet::handleDeactivated()
+{
+ disconnect(_devInfo, SIGNAL(batteryLevelChanged(int)), this, SLOT(updateInformation()));
+ disconnect(_netMgr, SIGNAL(onlineStateChanged(bool)), this, SLOT(updateInformation()));
+}
+
+void SysInfoWatchlet::updateInformation()
+{
QList<QNetworkConfiguration> cfgs = _netMgr->allConfigurations(QNetworkConfiguration::Active);
- rootContext()->setContextProperty("batteryLevel", _devInfo->batteryLevel());
+ int batteryLevel = _devInfo->batteryLevel();
+ qDebug() << "Updating system information (batteryLevel =" << batteryLevel << "%)";
+ rootContext()->setContextProperty("batteryLevel", batteryLevel);
if (cfgs.size() > 0) {
rootContext()->setContextProperty("networkName", cfgs[0].name());
} else {
diff --git a/sysinfowatchlet/sysinfowatchlet.h b/sysinfowatchlet/sysinfowatchlet.h
index 25d8f57..9ef3d7f 100644
--- a/sysinfowatchlet/sysinfowatchlet.h
+++ b/sysinfowatchlet/sysinfowatchlet.h
@@ -18,6 +18,8 @@ public:
private slots:
void handleActivated();
+ void handleDeactivated();
+ void updateInformation();
private:
QSystemDeviceInfo *_devInfo;