[Xfce4-commits] <xfce4-weather-plugin:master> Unit conversion: Convert temperature (bug #8356).
Harald Judt
noreply at xfce.org
Wed Jul 4 18:30:05 CEST 2012
Updating branch refs/heads/master
to e95ef85f242c6ce778e698b8cf60587daf1bf9ba (commit)
from d0c0b1c93a3c20eb002b366fc331b1b574c41036 (commit)
commit e95ef85f242c6ce778e698b8cf60587daf1bf9ba
Author: Harald Judt <h.judt at gmx.at>
Date: Wed Jul 4 18:13:20 2012 +0200
Unit conversion: Convert temperature (bug #8356).
Implement temperature conversion. Thanks to Andrzej for his patch on
which these changes are built upon.
panel-plugin/weather-data.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 09cae95..f8ebe66 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -43,6 +43,7 @@ gchar *
get_data (xml_time *timeslice, units unit, datas type)
{
const xml_location *loc = NULL;
+ double val;
if (timeslice == NULL)
return g_strdup("");
@@ -57,7 +58,15 @@ get_data (xml_time *timeslice, units unit, datas type)
case LONGITUDE:
return LOCALE_DOUBLE(loc->longitude, "%.4f");
case TEMPERATURE:
- return LOCALE_DOUBLE(loc->temperature_value, "%.1f");
+ val = g_ascii_strtod(loc->temperature_value, NULL);
+ if (unit == IMPERIAL
+ && (strcmp(loc->temperature_unit, "celcius") == 0
+ || strcmp(loc->temperature_unit, "celsius" == 0)))
+ val = val * 9.0 / 5.0 + 32.0;
+ else if (unit == METRIC
+ && strcmp(loc->temperature_unit, "fahrenheit") == 0)
+ val = (val - 32.0) * 5.0 / 9.0;
+ return g_strdup_printf ("%.1f", val);
case PRESSURE:
return LOCALE_DOUBLE(loc->pressure_value, "%.1f");
case WIND_SPEED:
@@ -102,7 +111,7 @@ get_unit (xml_time *timeslice, units unit, datas type)
case ALTITUDE:
return "m";
case TEMPERATURE:
- return strcmp(loc->temperature_unit, "celcius") ? "°F":"°C";
+ return (unit == IMPERIAL) ? _("°F") : _("°C");
case PRESSURE:
return (loc->pressure_unit) ? loc->pressure_unit : "";
case WIND_SPEED:
More information about the Xfce4-commits
mailing list