diff options
Diffstat (limited to 'sysinfowatchlet/sysinfowatchlet.cpp')
-rw-r--r-- | sysinfowatchlet/sysinfowatchlet.cpp | 20 |
1 files changed, 19 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 { |