[gnome-panel/gnome-3-32] clock: adapt for data changes in libgweather 3.31.91



commit 62cb5ff81c0d13ab85e80e213978ebdc1c67b328
Author: Dmitry Shachnev <mitya57 gmail com>
Date:   Tue Dec 10 23:54:36 2019 +0300

    clock: adapt for data changes in libgweather 3.31.91
    
    Starting with libgweather commit d7682676ac92f1b8, not all stations have
    timezone information associated with them. For example, this is the case
    for all stations in Russia. In this case, gnome-panel crashed because
    wtz was NULL.
    
    To fix that, we find the city nearest to the station, which should have
    the timezone information.

 modules/clock/clock-location.c | 40 ++++++++++++++++++++++++++++++++++------
 modules/clock/clock-location.h |  1 +
 2 files changed, 35 insertions(+), 6 deletions(-)
---
diff --git a/modules/clock/clock-location.c b/modules/clock/clock-location.c
index ae6560de7..457ca96b1 100644
--- a/modules/clock/clock-location.c
+++ b/modules/clock/clock-location.c
@@ -209,12 +209,40 @@ clock_location_get_city (ClockLocation *loc)
         return gweather_location_get_city_name (loc->priv->loc);
 }
 
+GWeatherTimezone *
+clock_location_get_gweather_timezone (ClockLocation *loc)
+{
+       GWeatherTimezone *tz;
+       GWeatherLocation *gloc;
+
+       gloc = loc->priv->loc;
+       tz = gweather_location_get_timezone (gloc);
+
+       if (tz == NULL) {
+               /* Some weather stations do not have timezone information.
+                * In this case, we need to find the nearest city. */
+               while (gweather_location_get_level (gloc) >= GWEATHER_LOCATION_CITY)
+                       gloc = gweather_location_get_parent (gloc);
+               gloc = gweather_location_find_nearest_city (gloc,
+                                                           loc->priv->latitude,
+                                                           loc->priv->longitude);
+               if (gloc == NULL) {
+                       g_warning ("Could not find the nearest city for location \"%s\"",
+                                  gweather_location_get_name (loc->priv->loc));
+                       return gweather_timezone_get_utc ();
+               }
+               tz = gweather_location_get_timezone (gloc);
+       }
+
+       return tz;
+}
+
 const gchar *
 clock_location_get_timezone (ClockLocation *loc)
 {
        GWeatherTimezone *tz;
 
-       tz = gweather_location_get_timezone (loc->priv->loc);
+       tz = clock_location_get_gweather_timezone (loc);
         return gweather_timezone_get_name (tz);
 }
 
@@ -223,7 +251,7 @@ clock_location_get_tzname (ClockLocation *loc)
 {
        GWeatherTimezone *tz;
 
-       tz = gweather_location_get_timezone (loc->priv->loc);
+       tz = clock_location_get_gweather_timezone (loc);
         return gweather_timezone_get_tzid (tz);
 }
 
@@ -243,7 +271,7 @@ clock_location_localtime (ClockLocation *loc)
        GTimeZone *tz;
        GDateTime *dt;
 
-       wtz = gweather_location_get_timezone (loc->priv->loc);
+       wtz = clock_location_get_gweather_timezone (loc);
 
        tz = g_time_zone_new (gweather_timezone_get_tzid (wtz));
        dt = g_date_time_new_now (tz);
@@ -258,7 +286,7 @@ clock_location_is_current_timezone (ClockLocation *loc)
        GWeatherTimezone *wtz;
        const char *zone;
 
-       wtz = gweather_location_get_timezone (loc->priv->loc);
+       wtz = clock_location_get_gweather_timezone (loc);
 
        zone = system_timezone_get (loc->priv->systz);
 
@@ -298,7 +326,7 @@ clock_location_get_offset (ClockLocation *loc)
 {
        GWeatherTimezone *wtz;
 
-       wtz = gweather_location_get_timezone (loc->priv->loc);
+       wtz = clock_location_get_gweather_timezone (loc);
        return gweather_timezone_get_offset (wtz);
 }
 
@@ -380,7 +408,7 @@ clock_location_make_current (ClockLocation *loc,
        mcdata->data = data;
        mcdata->destroy = destroy;
 
-       wtz = gweather_location_get_timezone (loc->priv->loc);
+       wtz = clock_location_get_gweather_timezone (loc);
         set_system_timezone_async (gweather_timezone_get_tzid (wtz),
                                    make_current_cb,
                                    mcdata);
diff --git a/modules/clock/clock-location.h b/modules/clock/clock-location.h
index 345fe0afa..2f2ea1725 100644
--- a/modules/clock/clock-location.h
+++ b/modules/clock/clock-location.h
@@ -48,6 +48,7 @@ const char *clock_location_get_name (ClockLocation *loc);
 void clock_location_set_name (ClockLocation *loc, const gchar *name);
 
 gchar *clock_location_get_city (ClockLocation *loc);
+GWeatherTimezone *clock_location_get_gweather_timezone (ClockLocation *loc);
 const gchar *clock_location_get_timezone (ClockLocation *loc);
 void clock_location_get_coords (ClockLocation *loc, gdouble *latitude, gdouble *longitude);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]