[Xfce4-commits] <xfce4-weather-plugin:master> Setup units on location auto-detection.

Harald Judt noreply at xfce.org
Tue Nov 27 16:46:12 CET 2012


Updating branch refs/heads/master
         to 4d0a9b80910a8f9c475194e9be18973ebb1d3438 (commit)
       from eb682f84044aaba3c78ed0dfc2ba98fcddb16fbb (commit)

commit 4d0a9b80910a8f9c475194e9be18973ebb1d3438
Author: Harald Judt <h.judt at gmx.at>
Date:   Fri Nov 23 11:47:56 2012 +0100

    Setup units on location auto-detection.

 panel-plugin/weather-config.c |    8 ++++-
 panel-plugin/weather-search.c |   67 ++++++++++++++++++++++++++++-------------
 panel-plugin/weather-search.h |    2 +-
 3 files changed, 53 insertions(+), 24 deletions(-)

diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 10e18ff..b27ce43 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -289,8 +289,11 @@ sanitize_location_name(const gchar *location_name)
 
 static void
 setup_units(xfceweather_dialog *dialog,
-            units_config *units)
+            const units_config *units)
 {
+    if (G_UNLIKELY(units == NULL))
+        return;
+
     SET_COMBO_VALUE(dialog->combo_unit_temperature, units->temperature);
     SET_COMBO_VALUE(dialog->combo_unit_pressure, units->pressure);
     SET_COMBO_VALUE(dialog->combo_unit_windspeed, units->windspeed);
@@ -461,7 +464,7 @@ static void
 auto_locate_cb(const gchar *loc_name,
                const gchar *lat,
                const gchar *lon,
-               const unit_systems unit_system,
+               const units_config *units,
                gpointer user_data)
 {
     xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
@@ -475,6 +478,7 @@ auto_locate_cb(const gchar *loc_name,
         lookup_altitude_timezone(user_data);
     } else
         gtk_entry_set_text(GTK_ENTRY(dialog->text_loc_name), _("Unset"));
+    setup_units(dialog, units);
     gtk_widget_set_sensitive(dialog->text_loc_name, TRUE);
 }
 
diff --git a/panel-plugin/weather-search.c b/panel-plugin/weather-search.c
index e0fa05f..48991bd 100644
--- a/panel-plugin/weather-search.c
+++ b/panel-plugin/weather-search.c
@@ -38,7 +38,7 @@ typedef struct {
     void (*cb) (const gchar *loc_name,
                 const gchar *lat,
                 const gchar *lon,
-                const unit_systems unit_system,
+                const units_config *units,
                 gpointer user_data);
     gpointer user_data;
 } geolocation_data;
@@ -314,21 +314,46 @@ free_search_dialog(search_dialog *dialog)
 }
 
 
-static unit_systems
-get_preferred_unit_system(const gchar *country_code)
+static units_config *
+get_preferred_units(const gchar *country_code)
 {
+    units_config *units;
+
+    if (G_UNLIKELY(country_code == NULL))
+        return NULL;
+
+    units = g_slice_new0(units_config);
+    if (G_UNLIKELY(units == NULL))
+        return NULL;
+
     /* List gathered from http://www.maxmind.com/app/iso3166 */
-    if (country_code == NULL)
-        return METRIC;
-    else if (!strcmp(country_code, "US"))  /* United States */
-        return IMPERIAL;
-    else if (!strcmp(country_code, "GB"))  /* United Kingdom */
-        return IMPERIAL;
-    else if (!strcmp(country_code, "LR"))  /* Liberia */
-        return IMPERIAL;
-    else if (!strcmp(country_code, "MM"))  /* Myanmar(Burma) */
-        return IMPERIAL;
-    return METRIC;
+    if (!strcmp(country_code, "US") ||        /* United States */
+        !strcmp(country_code, "GB") ||        /* United Kingdom */
+        !strcmp(country_code, "JM") ||        /* Jamaica */
+        !strcmp(country_code, "LR") ||        /* Liberia */
+        !strcmp(country_code, "MM")) {        /* Myanmar(Burma) */
+        units->pressure = PSI;
+        units->windspeed = MPH;
+        units->precipitations = INCHES;
+        units->altitude = FEET;
+    } else {
+        units->pressure = HECTOPASCAL;
+        units->windspeed = KMH;
+        units->precipitations = MILLIMETERS;
+        units->altitude = METERS;
+    }
+
+    if (!strcmp(country_code, "US") ||        /* United States */
+        !strcmp(country_code, "JM")) {        /* Jamaica */
+        units->temperature = FAHRENHEIT;
+    } else {
+        units->temperature = CELSIUS;
+    }
+
+    if (!strcmp(country_code, "RU"))          /* Russian Federation */
+        units->pressure = TORR;
+
+    return units;
 }
 
 
@@ -340,7 +365,7 @@ cb_geolocation(SoupSession *session,
     geolocation_data *data = (geolocation_data *) user_data;
     xml_geolocation *geo;
     gchar *full_loc, *p;
-    unit_systems unit_system;
+    units_config *units;
     gsize length;
 
     geo = (xml_geolocation *)
@@ -348,7 +373,7 @@ cb_geolocation(SoupSession *session,
     weather_dump(weather_dump_geolocation, geo);
 
     if (!geo) {
-        data->cb(NULL, NULL, NULL, METRIC, data->user_data);
+        data->cb(NULL, NULL, NULL, NULL, data->user_data);
         g_free(data);
         return;
     }
@@ -373,10 +398,10 @@ cb_geolocation(SoupSession *session,
     } else
         full_loc = NULL;
 
-    unit_system = get_preferred_unit_system(geo->country_code);
-
-    data->cb(full_loc, geo->latitude, geo->longitude,
-             unit_system, data->user_data);
+    units = get_preferred_units(geo->country_code);
+    weather_dump(weather_dump_units_config, units);
+    data->cb(full_loc, geo->latitude, geo->longitude, units, data->user_data);
+    g_slice_free(units_config, units);
     xml_geolocation_free(geo);
     g_free(full_loc);
     g_free(data);
@@ -387,7 +412,7 @@ void weather_search_by_ip(SoupSession *session,
                           void (*gui_cb) (const gchar *loc_name,
                                           const gchar *lat,
                                           const gchar *lon,
-                                          const unit_systems unit_system,
+                                          const units_config *units,
                                           gpointer user_data),
                           gpointer user_data)
 {
diff --git a/panel-plugin/weather-search.h b/panel-plugin/weather-search.h
index eb00879..1cb04b9 100644
--- a/panel-plugin/weather-search.h
+++ b/panel-plugin/weather-search.h
@@ -52,7 +52,7 @@ void weather_search_by_ip(SoupSession *session,
                           void (*gui_cb) (const gchar *loc_name,
                                           const gchar *lat,
                                           const gchar *lon,
-                                          const unit_systems unit_system,
+                                          const units_config *units,
                                           gpointer user_data),
                           gpointer user_data);
 


More information about the Xfce4-commits mailing list