[Xfce4-commits] <xfce4-weather-plugin:master> Always make sure source temperature unit is Celsius.

Harald Judt noreply at xfce.org
Sat Jan 5 12:04:10 CET 2013


Updating branch refs/heads/master
         to 370991e9d84fb678e3d2e143b5bf7a64ab68e775 (commit)
       from fa2769012fb3f1ea0c47f40136c9f1bc8793a132 (commit)

commit 370991e9d84fb678e3d2e143b5bf7a64ab68e775
Author: Harald Judt <h.judt at gmx.at>
Date:   Wed Jan 2 13:54:52 2013 +0100

    Always make sure source temperature unit is Celsius.
    
    Convert from Fahrenheit to Celsius when parsing the data. This way,
    we don't have to distinguish between units and convert the values later.

 panel-plugin/weather-data.c    |    9 ++-------
 panel-plugin/weather-parsers.c |   12 ++++++++++++
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 4869d09..ab7d45f 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -180,15 +180,10 @@ get_data(const xml_time *timeslice,
     case LONGITUDE:
         return LOCALE_DOUBLE(loc->longitude, "%.4f");
 
-    case TEMPERATURE:      /* source may be in Celsius or Fahrenheit */
+    case TEMPERATURE:      /* source is in °C */
         val = string_to_double(loc->temperature_value, 0);
-        if (units->temperature == FAHRENHEIT &&
-            (!strcmp(loc->temperature_unit, "celcius") ||
-             !strcmp(loc->temperature_unit, "celsius")))
+        if (units->temperature == FAHRENHEIT)
             val = val * 9.0 / 5.0 + 32.0;
-        else if (units->temperature == CELSIUS &&
-                 !strcmp(loc->temperature_unit, "fahrenheit"))
-            val = (val - 32.0) * 5.0 / 9.0;
         return g_strdup_printf(ROUND_TO_INT("%.1f"), val);
 
     case PRESSURE:         /* source is in hectopascals */
diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
index 0e16386..3e7edc5 100644
--- a/panel-plugin/weather-parsers.c
+++ b/panel-plugin/weather-parsers.c
@@ -200,6 +200,18 @@ parse_location(xmlNode *cur_node,
             loc->symbol_id = strtol(PROP(child_node, "number"), NULL, 10);
         }
     }
+
+    /* Convert Fahrenheit to Celsius if necessary, so that we don't
+       have to do it later. met.no usually provides values in Celsius. */
+    if (loc->temperature_value && loc->temperature_unit &&
+        !strcmp(loc->temperature_unit, "fahrenheit")) {
+        gdouble val = string_to_double(loc->temperature_value, 0);
+        val = (val - 32.0) * 5.0 / 9.0;
+        g_free(loc->temperature_value);
+        loc->temperature_value = double_to_string(val, "%.1f");
+        g_free(loc->temperature_unit);
+        loc->temperature_unit = g_strdup("celsius");
+    }
 }
 
 


More information about the Xfce4-commits mailing list