From 105e48fcb2e8498a383447ac60f31677d2bb1b7d Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Wed, 4 Jan 2012 04:18:37 +0100 Subject: only update watch if weather info actually changed --- harmaccuweather/harmaccuweather.cpp | 38 +++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'harmaccuweather') diff --git a/harmaccuweather/harmaccuweather.cpp b/harmaccuweather/harmaccuweather.cpp index 99cc31b..38fc9bc 100644 --- a/harmaccuweather/harmaccuweather.cpp +++ b/harmaccuweather/harmaccuweather.cpp @@ -232,12 +232,38 @@ void HarmAccuWeather::update() QDateTime lastUpdate = s->value("LastUpdate").toDateTime(); if (lastUpdate > _lastUpdate) { _lastUpdate = lastUpdate; - _metric = s->value("useMetric").toBool(); - _lastTemp = s->value("LastTemp").toInt(); - _lastLocation = s->value("LastLocation").toString(); - _lastWxCode = s->value("LastWxCode").toInt(); - qDebug() << "updated weather info" << _lastUpdate << _lastWxCode; - emit changed(); + bool anythingChanged = false; + + qDebug() << "reading weather info at" << _lastUpdate; + + bool useMetric = s->value("useMetric").toBool(); + if (useMetric != _metric) { + _metric = useMetric; + anythingChanged = true; + } + + int temp = s->value("LastTemp").toInt(); + if (_lastTemp != temp) { + _lastTemp = temp; + anythingChanged = true; + } + + QString location = s->value("LastLocation").toString(); + if (_lastLocation != location) { + _lastLocation = location; + anythingChanged = true; + } + + int wxCode = s->value("LastWxCode").toInt(); + if (_lastWxCode != wxCode) { + _lastWxCode = wxCode; + anythingChanged = true; + } + + if (anythingChanged) { + qDebug() << "weather info changed wxcode=" << wxCode; + emit changed(); + } } delete s; -- cgit v1.2.3