[Xfce4-commits] <xfce4-weather-plugin:master> Fix wind direction translation (bug #9895).

Harald Judt noreply at xfce.org
Wed Mar 13 12:42:01 CET 2013


Updating branch refs/heads/master
         to 9be059f8f814bb5b78081b8b2c5303cdb95b2a70 (commit)
       from e015f95b0f29977aa11832b47faf462e9c01ef15 (commit)

commit 9be059f8f814bb5b78081b8b2c5303cdb95b2a70
Author: Harald Judt <h.judt at gmx.at>
Date:   Wed Mar 13 12:39:29 2013 +0100

    Fix wind direction translation (bug #9895).

 panel-plugin/weather-data.c      |   85 +++++++++++++++++++-------------------
 panel-plugin/weather-summary.c   |   15 ++----
 panel-plugin/weather-translate.c |   56 -------------------------
 panel-plugin/weather-translate.h |    2 -
 panel-plugin/weather.c           |   55 ++++++++-----------------
 5 files changed, 65 insertions(+), 148 deletions(-)

diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 714cce4..8d75978 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -266,6 +266,48 @@ calc_apparent_temperature(const xml_location *loc,
 }
 
 
+/*
+ * Return wind direction name for wind degrees, which gives the
+ * direction the wind is coming _from_.
+ */
+static gchar*
+wind_dir_name_by_deg(gchar *degrees, gboolean long_name)
+{
+    gdouble deg;
+
+    if (G_UNLIKELY(degrees == NULL))
+        return "";
+
+    deg = string_to_double(degrees, 0);
+
+    if (deg >= 360 - 22.5 || deg < 45 - 22.5)
+        return (long_name) ? _("North") : _("N");
+
+    if (deg >= 45 - 22.5 && deg < 45 + 22.5)
+        return (long_name) ? _("North-East") : _("NE");
+
+    if (deg >= 90 - 22.5 && deg < 90 + 22.5)
+        return (long_name) ? _("East") : _("E");
+
+    if (deg >= 135 - 22.5 && deg < 135 + 22.5)
+        return (long_name) ? _("South-East") : _("SE");
+
+    if (deg >= 180 - 22.5 && deg < 180 + 22.5)
+        return (long_name) ? _("South") : _("S");
+
+    if (deg >= 225 - 22.5 && deg < 225 + 22.5)
+        return (long_name) ? _("South-West") : _("SW");
+
+    if (deg >= 270 - 22.5 && deg < 270 + 22.5)
+        return (long_name) ? _("West") : _("W");
+
+    if (deg >= 315 - 22.5 && deg < 315 + 22.5)
+        return (long_name) ? _("North-West") : _("NW");
+
+    return "";
+}
+
+
 gchar *
 get_data(const xml_time *timeslice,
          const units_config *units,
@@ -343,7 +385,7 @@ get_data(const xml_time *timeslice,
         return g_strdup_printf("%.0f", val);
 
     case WIND_DIRECTION:
-        return CHK_NULL(loc->wind_dir_name);
+        return g_strdup(wind_dir_name_by_deg(loc->wind_dir_deg, FALSE));
 
     case WIND_DIRECTION_DEG:
         return LOCALE_DOUBLE(loc->wind_dir_deg, ROUND_TO_INT("%.1f"));
@@ -526,47 +568,6 @@ is_night_time(const xml_astro *astro)
 }
 
 
-/*
- * Return wind direction name (S, N, W,...) for wind degrees.
- */
-static gchar*
-wind_dir_name_by_deg(gchar *degrees, gboolean long_name)
-{
-    gdouble deg;
-
-    if (G_UNLIKELY(degrees == NULL))
-        return "";
-
-    deg = string_to_double(degrees, 0);
-
-    if (deg >= 360 - 22.5 || deg < 45 - 22.5)
-        return (long_name) ? _("North") : _("N");
-
-    if (deg >= 45 - 22.5 && deg < 45 + 22.5)
-        return (long_name) ? _("North-East") : _("NE");
-
-    if (deg >= 90 - 22.5 && deg < 90 + 22.5)
-        return (long_name) ? _("East") : _("E");
-
-    if (deg >= 135 - 22.5 && deg < 135 + 22.5)
-        return (long_name) ? _("South-East") : _("SE");
-
-    if (deg >= 180 - 22.5 && deg < 180 + 22.5)
-        return (long_name) ? _("South") : _("S");
-
-    if (deg >= 225 - 22.5 && deg < 225 + 22.5)
-        return (long_name) ? _("South-West") : _("SW");
-
-    if (deg >= 270 - 22.5 && deg < 270 + 22.5)
-        return (long_name) ? _("West") : _("W");
-
-    if (deg >= 315 - 22.5 && deg < 315 + 22.5)
-        return (long_name) ? _("North-West") : _("NW");
-
-    return "";
-}
-
-
 static void
 calculate_symbol(xml_time *timeslice,
                  gboolean current_conditions)
diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index 2b86cac..15cf546 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -487,14 +487,11 @@ create_summary_tab(plugin_data *data)
     g_free(wind);
     APPEND_TEXT_ITEM_REAL(value);
 
-    rawvalue = get_data(conditions, data->units, WIND_DIRECTION,
-                        FALSE, data->night_time);
-    wind = translate_wind_direction(rawvalue);
-    g_free(rawvalue);
+    /* wind direction */
     rawvalue = get_data(conditions, data->units, WIND_DIRECTION_DEG,
                         FALSE, data->night_time);
-
-    /* wind direction */
+    wind = get_data(conditions, data->units, WIND_DIRECTION,
+                        FALSE, data->night_time);
     value = g_strdup_printf(_("\tDirection: %s (%s%s)\n"),
                             wind, rawvalue,
                             get_unit(data->units, WIND_DIRECTION_DEG));
@@ -785,16 +782,14 @@ add_forecast_cell(plugin_data *data,
     g_free(value);
 
     /* wind direction and speed */
-    rawvalue = get_data(fcdata, data->units, WIND_DIRECTION,
-                        FALSE, data->night_time);
-    wind_direction = translate_wind_direction(rawvalue);
+    wind_direction = get_data(fcdata, data->units, WIND_DIRECTION,
+                              FALSE, data->night_time);
     wind_speed = get_data(fcdata, data->units, WIND_SPEED,
                           data->round, data->night_time);
     value = g_strdup_printf("%s %s %s", wind_direction, wind_speed,
                             get_unit(data->units, WIND_SPEED));
     g_free(wind_speed);
     g_free(wind_direction);
-    g_free(rawvalue);
     label = gtk_label_new(value);
     if (!(day % 2))
         gtk_widget_modify_fg(GTK_WIDGET(label), GTK_STATE_NORMAL, &black);
diff --git a/panel-plugin/weather-translate.c b/panel-plugin/weather-translate.c
index 004eef1..89c0310 100644
--- a/panel-plugin/weather-translate.c
+++ b/panel-plugin/weather-translate.c
@@ -31,28 +31,6 @@
 #define DAY_LOC_N (sizeof(gchar) * 100)
 
 
-static const gchar *wdirs[] = {
-    /* TRANSLATORS: Wind directions. It's where the wind comes _from_. */
-    N_("S"),
-    N_("SSW"),
-    N_("SW"),
-    N_("WSW"),
-    N_("W"),
-    N_("WNW"),
-    N_("NW"),
-    N_("NNW"),
-    N_("N"),
-    N_("NNE"),
-    N_("NE"),
-    N_("ENE"),
-    N_("E"),
-    N_("ESE"),
-    N_("SE"),
-    N_("SSE"),
-    N_("CALM"),
-    NULL
-};
-
 static const gchar *moon_phases[] = {
     /* TRANSLATORS: Moon phases */
     N_("New moon"),
@@ -237,37 +215,3 @@ translate_day(const gint weekday)
 
     return day_loc;
 }
-
-
-gchar *
-translate_wind_direction(const gchar *wdir)
-{
-    gchar *wdir_loc, *tmp, wdir_i[2];
-    gint i;
-
-    if (wdir == NULL || strlen(wdir) < 1)
-        return NULL;
-
-    /*
-     * If the direction can be translated, then translate the whole
-     * code so that it can be correctly translated to CJK (and
-     * possibly Finnish). If not, use the old behaviour where
-     * individual direction codes are successively translated.
-     */
-    if (g_ascii_strcasecmp(wdir, _(wdir)) != 0)
-        wdir_loc = g_strdup(_(wdir));
-    else {
-        wdir_loc = g_strdup("");
-        for (i = 0; i < strlen(wdir); i++) {
-            wdir_i[0] = wdir[i];
-            wdir_i[1] = '\0';
-
-            tmp = g_strdup_printf("%s%s", wdir_loc,
-                                  translate_str(wdirs, wdir_i));
-            g_free(wdir_loc);
-            wdir_loc = tmp;
-        }
-
-    }
-    return wdir_loc;
-}
diff --git a/panel-plugin/weather-translate.h b/panel-plugin/weather-translate.h
index 1538466..2116795 100644
--- a/panel-plugin/weather-translate.h
+++ b/panel-plugin/weather-translate.h
@@ -32,8 +32,6 @@ const gchar *translate_moon_phase(const gchar *moon_phase);
 /* these return a newly allocated string, that should be freed */
 gchar *translate_day(gint weekday);
 
-gchar *translate_wind_direction(const gchar *wdir);
-
 G_END_DECLS
 
 #endif
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index b078d9f..1c8f438 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -114,7 +114,7 @@ make_label(const plugin_data *data,
 {
     xml_time *conditions;
     const gchar *lbl, *unit;
-    gchar *str, *value, *rawvalue;
+    gchar *str, *value;
 
     switch (type) {
     case TEMPERATURE:
@@ -170,38 +170,19 @@ make_label(const plugin_data *data,
 
     /* get current weather conditions */
     conditions = get_current_conditions(data->weatherdata);
-    rawvalue = get_data(conditions, data->units, type,
-                        data->round, data->night_time);
-
-    switch (type) {
-    case WIND_DIRECTION:
-        value = translate_wind_direction(rawvalue);
-        break;
-    default:
-        value = NULL;
-        break;
-    }
-
-    if (data->labels->len > 1) {
-        if (value != NULL) {
-            str = g_strdup_printf("%s: %s", lbl, value);
-            g_free(value);
-        } else {
-            unit = get_unit(data->units, type);
-            str = g_strdup_printf("%s: %s%s%s", lbl, rawvalue,
-                                  strcmp(unit, "°") ? " " : "", unit);
-        }
-    } else {
-        if (value != NULL) {
-            str = g_strdup_printf("%s", value);
-            g_free(value);
-        } else {
-            unit = get_unit(data->units, type);
-            str = g_strdup_printf("%s%s%s", rawvalue,
-                                  strcmp(unit, "°") ? " " : "", unit);
-        }
-    }
-    g_free(rawvalue);
+    unit = get_unit(data->units, type);
+    value = get_data(conditions, data->units, type,
+                     data->round, data->night_time);
+
+    if (data->labels->len > 1)
+        str = g_strdup_printf("%s: %s%s%s", lbl, value,
+                              strcmp(unit, "°") || strcmp(unit, "")
+                              ? " " : "", unit);
+    else
+        str = g_strdup_printf("%s%s%s", value,
+                              strcmp(unit, "°") || strcmp(unit, "")
+                              ? " " : "", unit);
+    g_free(value);
     return str;
 }
 
@@ -1596,7 +1577,7 @@ weather_get_tooltip_text(const plugin_data *data)
 {
     xml_time *conditions;
     gchar *text, *sym, *alt, *temp;
-    gchar *windspeed, *windbeau, *winddir, *winddir_trans, *winddeg;
+    gchar *windspeed, *windbeau, *winddir, *winddeg;
     gchar *pressure, *humidity, *precipitations;
     gchar *fog, *cloudiness, *sunval, *value;
     gchar *point, *interval_start, *interval_end, *sunrise, *sunset;
@@ -1636,7 +1617,6 @@ weather_get_tooltip_text(const plugin_data *data)
     DATA_AND_UNIT(windspeed, WIND_SPEED);
     DATA_AND_UNIT(windbeau, WIND_BEAUFORT);
     DATA_AND_UNIT(winddir, WIND_DIRECTION);
-    winddir_trans = translate_wind_direction(winddir);
     DATA_AND_UNIT(winddeg, WIND_DIRECTION_DEG);
     DATA_AND_UNIT(pressure, PRESSURE);
     DATA_AND_UNIT(humidity, HUMIDITY);
@@ -1660,7 +1640,7 @@ weather_get_tooltip_text(const plugin_data *data)
                "<b>Humidity:</b> %s\n"),
              data->location_name, alt,
              translate_desc(sym, data->night_time),
-             temp, windspeed, winddir_trans, pressure, humidity);
+             temp, windspeed, winddir, pressure, humidity);
         break;
 
     case TOOLTIP_VERBOSE:
@@ -1691,7 +1671,7 @@ weather_get_tooltip_text(const plugin_data *data)
              interval_start, interval_end,
              precipitations,
              temp, point,
-             windspeed, windbeau, winddir_trans, winddeg,
+             windspeed, windbeau, winddir, winddeg,
              pressure, humidity,
              fog, cloudiness,
              sunval);
@@ -1706,7 +1686,6 @@ weather_get_tooltip_text(const plugin_data *data)
     g_free(point);
     g_free(windspeed);
     g_free(windbeau);
-    g_free(winddir_trans);
     g_free(winddir);
     g_free(winddeg);
     g_free(pressure);


More information about the Xfce4-commits mailing list