[evolution-data-server/gnome-3-10] Make the Weather calendar work after changes for bug #712388
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/gnome-3-10] Make the Weather calendar work after changes for bug #712388
- Date: Mon, 18 Nov 2013 20:27:16 +0000 (UTC)
commit b9fe27e19d55ca9be535bf9cd81be977c909a609
Author: Milan Crha <mcrha redhat com>
Date: Mon Nov 18 21:16:47 2013 +0100
Make the Weather calendar work after changes for bug #712388
calendar/backends/weather/e-cal-backend-weather.c | 58 ++++++--------------
calendar/backends/weather/e-weather-source.c | 50 +++++++++++++++++-
2 files changed, 65 insertions(+), 43 deletions(-)
---
diff --git a/calendar/backends/weather/e-cal-backend-weather.c
b/calendar/backends/weather/e-cal-backend-weather.c
index 69ba23d..23d6fb5 100644
--- a/calendar/backends/weather/e-cal-backend-weather.c
+++ b/calendar/backends/weather/e-cal-backend-weather.c
@@ -69,9 +69,6 @@ struct _ECalBackendWeatherPrivate {
/* Flags */
gboolean opened;
- /* City (for summary) */
- gchar *city;
-
/* Weather source */
EWeatherSource *source;
@@ -313,7 +310,6 @@ create_weather (ECalBackendWeather *cbw,
GWeatherInfo *report,
gboolean is_forecast)
{
- ECalBackendWeatherPrivate *priv;
ECalComponent *cal_comp;
ECalComponentText comp_summary;
icalcomponent *ical_comp;
@@ -322,19 +318,18 @@ create_weather (ECalBackendWeather *cbw,
gchar *uid;
GSList *text_list = NULL;
ECalComponentText *description;
- gchar *tmp;
+ gchar *tmp, *city_name;
time_t update_time;
icaltimezone *update_zone = NULL;
const GWeatherLocation *location;
const GWeatherTimezone *w_timezone;
+ gdouble tmin = 0.0, tmax = 0.0;
g_return_val_if_fail (E_IS_CAL_BACKEND_WEATHER (cbw), NULL);
if (!gweather_info_get_value_update (report, &update_time))
return NULL;
- priv = cbw->priv;
-
/* create the component and event object */
ical_comp = icalcomponent_new (ICAL_VEVENT_COMPONENT);
cal_comp = e_cal_component_new ();
@@ -373,28 +368,27 @@ create_weather (ECalBackendWeather *cbw,
/* We have to add 1 day to DTEND, as it is not inclusive. */
e_cal_component_set_dtend (cal_comp, &dt);
- {
- gdouble tmin = 0.0, tmax = 0.0;
-
- if (gweather_info_get_value_temp_min (report, GWEATHER_TEMP_UNIT_DEFAULT, &tmin) &&
- gweather_info_get_value_temp_max (report, GWEATHER_TEMP_UNIT_DEFAULT, &tmax) &&
- tmin != tmax) {
- gchar *min, *max;
+ city_name = gweather_info_get_location_name (report);
+ if (gweather_info_get_value_temp_min (report, GWEATHER_TEMP_UNIT_DEFAULT, &tmin) &&
+ gweather_info_get_value_temp_max (report, GWEATHER_TEMP_UNIT_DEFAULT, &tmax) &&
+ tmin != tmax) {
+ gchar *min, *max;
- min = gweather_info_get_temp_min (report);
- max = gweather_info_get_temp_max (report);
- comp_summary.value = g_strdup_printf ("%s : %s / %s", priv->city, min, max);
+ min = gweather_info_get_temp_min (report);
+ max = gweather_info_get_temp_max (report);
+ comp_summary.value = g_strdup_printf ("%s : %s / %s", city_name, min, max);
- g_free (min); g_free (max);
- } else {
- gchar *temp;
+ g_free (min); g_free (max);
+ } else {
+ gchar *temp;
- temp = gweather_info_get_temp (report);
- comp_summary.value = g_strdup_printf ("%s : %s", priv->city, temp);
+ temp = gweather_info_get_temp (report);
+ comp_summary.value = g_strdup_printf ("%s : %s", city_name, temp);
- g_free (temp);
- }
+ g_free (temp);
}
+ g_free (city_name);
+
comp_summary.altrep = NULL;
e_cal_component_set_summary (cal_comp, &comp_summary);
g_free ((gchar *) comp_summary.value);
@@ -482,27 +476,13 @@ e_cal_backend_weather_open (ECalBackendSync *backend,
{
ECalBackendWeather *cbw;
ECalBackendWeatherPrivate *priv;
- ESource *source;
- ESourceWeather *extension;
- const gchar *extension_name;
const gchar *cache_dir;
- gchar *location;
cbw = E_CAL_BACKEND_WEATHER (backend);
priv = cbw->priv;
- source = e_backend_get_source (E_BACKEND (backend));
cache_dir = e_cal_backend_get_cache_dir (E_CAL_BACKEND (backend));
- extension_name = E_SOURCE_EXTENSION_WEATHER_BACKEND;
- extension = e_source_get_extension (source, extension_name);
-
- g_free (priv->city);
-
- location = e_source_weather_dup_location (extension);
- priv->city = g_strdup (strrchr (location, '/') + 1);
- g_free (location);
-
e_cal_backend_set_writable (E_CAL_BACKEND (backend), FALSE);
if (!priv->store) {
@@ -776,8 +756,6 @@ e_cal_backend_weather_finalize (GObject *object)
priv->store = NULL;
}
- g_free (priv->city);
-
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_cal_backend_weather_parent_class)->finalize (object);
}
diff --git a/calendar/backends/weather/e-weather-source.c b/calendar/backends/weather/e-weather-source.c
index d835030..8288d99 100644
--- a/calendar/backends/weather/e-weather-source.c
+++ b/calendar/backends/weather/e-weather-source.c
@@ -71,6 +71,37 @@ e_weather_source_init (EWeatherSource *source)
source->priv = E_WEATHER_SOURCE_GET_PRIVATE (source);
}
+static GWeatherLocation *
+weather_source_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 = weather_source_find_location_by_coords (children[ii], latitude, longitude);
+ if (location)
+ return location;
+ }
+
+ return NULL;
+}
+
EWeatherSource *
e_weather_source_new (const gchar *location)
{
@@ -99,6 +130,18 @@ e_weather_source_new (const gchar *location)
tokens = g_strsplit (location, "/", 2);
glocation = gweather_location_find_by_station_code (world, tokens[0]);
+
+ if (!glocation) {
+ gdouble latitude, longitude;
+ gchar *endptr = NULL;
+
+ latitude = g_ascii_strtod (location, &endptr);
+ if (endptr && *endptr == '/') {
+ longitude = g_ascii_strtod (endptr + 1, NULL);
+ glocation = weather_source_find_location_by_coords (world, latitude, longitude);
+ }
+ }
+
if (glocation != NULL)
gweather_location_ref (glocation);
@@ -109,7 +152,7 @@ e_weather_source_new (const gchar *location)
return NULL;
source = g_object_new (E_TYPE_WEATHER_SOURCE, NULL);
- source->priv->location = gweather_location_ref (glocation);
+ source->priv->location = glocation;
return source;
}
@@ -146,11 +189,12 @@ e_weather_source_parse (EWeatherSource *source,
source->priv->info = gweather_info_new (
source->priv->location,
GWEATHER_FORECAST_LIST);
+ gweather_info_set_enabled_providers (source->priv->info, GWEATHER_PROVIDER_ALL);
g_signal_connect (
source->priv->info, "updated",
G_CALLBACK (weather_source_updated_cb), source);
- } else {
- gweather_info_update (source->priv->info);
}
+
+ gweather_info_update (source->priv->info);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]