From 1b0c6d90209460dd81628f4d9c028f91f596e46c Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Wed, 4 Jan 2012 03:46:45 +0100 Subject: make sysinfowatchlet selfupdate --- sysinfowatchlet/sysinfowatchlet.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'sysinfowatchlet/sysinfowatchlet.cpp') 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 + #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 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 { -- cgit v1.2.3