From d6d10c69ba454a6e555733815680acdfc0ee5402 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 25 Aug 2012 20:18:38 +0200 Subject: fix meecast non-automatic C -> F conversion --- meecastweather/meecastweather.cpp | 26 +++++++++++++++++++++++++- meecastweather/meecastweather.h | 3 +++ 2 files changed, 28 insertions(+), 1 deletion(-) (limited to 'meecastweather') diff --git a/meecastweather/meecastweather.cpp b/meecastweather/meecastweather.cpp index 0263a82..fa62ab7 100644 --- a/meecastweather/meecastweather.cpp +++ b/meecastweather/meecastweather.cpp @@ -145,6 +145,11 @@ void MeeCastWeather::dismiss() // Do nothing } +int MeeCastWeather::convertTemperatureToUserUnit(int temp, Unit unit) +{ + return convertTemperature(temp, unit, _tempUnit); +} + void MeeCastWeather::fileChanged(const QString &path) { qDebug() << "meecast config file changed: " << path; @@ -207,7 +212,24 @@ void MeeCastWeather::parseStationFile() qDebug() << "meecast reading weather info"; QDomElement root = doc.documentElement(); - QDomNodeList list = root.elementsByTagName("period"); + QDomNodeList list; + Unit tempUnit = _tempUnit; + + list = root.elementsByTagName("units"); + if (!list.isEmpty()) { + QDomElement units = list.at(0).toElement(); + list = units.elementsByTagName("t"); + if (!list.isEmpty()) { + QDomElement e = list.at(0).toElement(); + if (e.text() == "C") { + tempUnit = Celsius; + } else if (e.text() == "F") { + tempUnit = Fahrenheit; + } + } + } + + list = root.elementsByTagName("period"); for (int index = 0; index < list.size(); index++) { QDomElement e = list.item(index).toElement(); if (e.attribute("current") == "true") { @@ -223,6 +245,8 @@ void MeeCastWeather::parseStationFile() int temp = e.firstChildElement("temperature").text().toInt(); qDebug() << "temp" << temp; + temp = convertTemperatureToUserUnit(temp, tempUnit); + qDebug() << " -> " << temp; if (temp != _lastTemp) { anythingChanged = true; _lastTemp = temp; diff --git a/meecastweather/meecastweather.h b/meecastweather/meecastweather.h index 9526726..a1ac393 100644 --- a/meecastweather/meecastweather.h +++ b/meecastweather/meecastweather.h @@ -31,6 +31,9 @@ public: void activate(); void dismiss(); +private: + int convertTemperatureToUserUnit(int temp, Unit unit); + private slots: void fileChanged(const QString& path); void parseConfigFile(); -- cgit v1.2.3