diff options
author | Milan Crha <mcrha@redhat.com> | 2013-11-19 04:18:28 +0800 |
---|---|---|
committer | Milan Crha <mcrha@redhat.com> | 2013-11-19 04:18:28 +0800 |
commit | 1db9434e359ff02183d9bf334f4abb3732607e19 (patch) | |
tree | a69b839ae4350c019d156565d9f5faba1cc86602 /modules | |
parent | 0724e3bf1123cce70b030c12704d7f261fff6f19 (diff) | |
download | gsoc2013-evolution-1db9434e359ff02183d9bf334f4abb3732607e19.tar gsoc2013-evolution-1db9434e359ff02183d9bf334f4abb3732607e19.tar.gz gsoc2013-evolution-1db9434e359ff02183d9bf334f4abb3732607e19.tar.bz2 gsoc2013-evolution-1db9434e359ff02183d9bf334f4abb3732607e19.tar.lz gsoc2013-evolution-1db9434e359ff02183d9bf334f4abb3732607e19.tar.xz gsoc2013-evolution-1db9434e359ff02183d9bf334f4abb3732607e19.tar.zst gsoc2013-evolution-1db9434e359ff02183d9bf334f4abb3732607e19.zip |
Bug #712388 - Crash when opening Properties of a Weather calendar
Apart of fixing the crash, the format of saved location is changed,
which requires changes in evolution-data-server, commit with the same
bug number in its description (063a2bc).
Diffstat (limited to 'modules')
-rw-r--r-- | modules/cal-config-weather/evolution-cal-config-weather.c | 88 |
1 files changed, 52 insertions, 36 deletions
diff --git a/modules/cal-config-weather/evolution-cal-config-weather.c b/modules/cal-config-weather/evolution-cal-config-weather.c index 2e5532e5c8..5bdd6f9d20 100644 --- a/modules/cal-config-weather/evolution-cal-config-weather.c +++ b/modules/cal-config-weather/evolution-cal-config-weather.c @@ -69,14 +69,20 @@ cal_config_weather_location_to_string (GBinding *binding, location = g_value_get_boxed (source_value); - if (location != NULL) { - const gchar *code; - gchar *city_name; - - code = gweather_location_get_code (location); - city_name = gweather_location_get_city_name (location); - string = g_strdup_printf ("%s/%s", code, city_name); - g_free (city_name); + while (location && !gweather_location_has_coords (location)) { + location = gweather_location_get_parent (location); + } + + if (location) { + gdouble latitude, longitude; + gchar lat_str[G_ASCII_DTOSTR_BUF_SIZE + 1], lon_str[G_ASCII_DTOSTR_BUF_SIZE + 1]; + + gweather_location_get_coords (location, &latitude, &longitude); + + g_ascii_dtostr (lat_str, G_ASCII_DTOSTR_BUF_SIZE, latitude); + g_ascii_dtostr (lon_str, G_ASCII_DTOSTR_BUF_SIZE, longitude); + + string = g_strdup_printf ("%s/%s", lat_str, lon_str); } g_value_take_string (target_value, string); @@ -84,18 +90,47 @@ cal_config_weather_location_to_string (GBinding *binding, return TRUE; } +static GWeatherLocation * +cal_config_weather_find_location_by_coords (GWeatherLocation *start, + gdouble latitude, + gdouble longitude) +{ + GWeatherLocation *location, **children; + gint ii; + + if (!start) + return NULL; + + location = start; + if (gweather_location_has_coords (location)) { + gdouble lat, lon; + + gweather_location_get_coords (location, &lat, &lon); + + if (lat == latitude && lon == longitude) + return location; + } + + children = gweather_location_get_children (location); + for (ii = 0; children[ii]; ii++) { + location = cal_config_weather_find_location_by_coords (children[ii], latitude, longitude); + if (location) + return location; + } + + return NULL; +} + static gboolean cal_config_weather_string_to_location (GBinding *binding, const GValue *source_value, GValue *target_value, gpointer user_data) { - GWeatherLocation *world; - GWeatherLocation *match, *start; + GWeatherLocation *world, *match; const gchar *string; - const gchar *city_name; - const gchar *code; gchar **tokens; + gdouble latitude, longitude; world = user_data; @@ -104,7 +139,7 @@ cal_config_weather_string_to_location (GBinding *binding, if (string == NULL) return FALSE; - /* String is: STATION-CODE '/' CITY-NAME */ + /* String is: latitude '/' longitude */ tokens = g_strsplit (string, "/", 2); if (g_strv_length (tokens) != 2) { @@ -112,35 +147,16 @@ cal_config_weather_string_to_location (GBinding *binding, return FALSE; } - code = tokens[0]; - city_name = tokens[1]; - - match = start = gweather_location_find_by_station_code (world, code); - while (match) { - gchar *cmp_city_name; + latitude = g_ascii_strtod (tokens[0], NULL); + longitude = g_ascii_strtod (tokens[1], NULL); - /* Does the city name match? */ - cmp_city_name = gweather_location_get_city_name (match); - if (g_strcmp0 (city_name, cmp_city_name) == 0) { - g_free (cmp_city_name); - break; - } - g_free (cmp_city_name); - - /* No match, try parent */ - match = gweather_location_get_parent (match); - } - - if (match == NULL) { - /* No exact match, use start instead */ - match = start; - } + match = cal_config_weather_find_location_by_coords (world, latitude, longitude); g_value_set_boxed (target_value, match); g_strfreev (tokens); - return TRUE; + return match != NULL; } static gboolean |