summaryrefslogtreecommitdiff
path: root/libsowatch/weathernotification.cpp
diff options
context:
space:
mode:
authorJavier S. Pedro <maemo@javispedro.com>2012-08-25 20:18:38 +0200
committerJavier S. Pedro <maemo@javispedro.com>2012-08-25 20:18:38 +0200
commitd6d10c69ba454a6e555733815680acdfc0ee5402 (patch)
tree34b354ea35801e8a4e918b9687655aa3751a6884 /libsowatch/weathernotification.cpp
parentd2e8f4fab19d76e2f00ddbaca0c78ee1276651a6 (diff)
downloadsowatch-d6d10c69ba454a6e555733815680acdfc0ee5402.tar.gz
sowatch-d6d10c69ba454a6e555733815680acdfc0ee5402.zip
fix meecast non-automatic C -> F conversion
Diffstat (limited to 'libsowatch/weathernotification.cpp')
-rw-r--r--libsowatch/weathernotification.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/libsowatch/weathernotification.cpp b/libsowatch/weathernotification.cpp
index fa82f3d..ddfd60b 100644
--- a/libsowatch/weathernotification.cpp
+++ b/libsowatch/weathernotification.cpp
@@ -6,3 +6,24 @@ WeatherNotification::WeatherNotification(QObject *parent) :
Notification(parent)
{
}
+
+qreal WeatherNotification::convertTemperature(qreal temp, Unit from, Unit to)
+{
+ if (from == to) {
+ return temp;
+ } else if (from == Celsius && to == Fahrenheit) {
+ return temp * (9.0f/5.0f) + 32.0f;
+ } else if (from == Fahrenheit && to == Celsius) {
+ return (temp - 32.0f) * (5.0f/9.0f);
+ }
+}
+
+
+int WeatherNotification::convertTemperature(int temp, Unit from, Unit to)
+{
+ if (from == to) {
+ return temp;
+ } else {
+ return qRound(convertTemperature(static_cast<qreal>(temp), from, to));
+ }
+}