[gnome-panel/wip/muktupavels/gweather-4: 6/6] clock: port to libgweather 4




commit dc5b1183de1e395bcf542770247f0dba45e6d304
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Mar 1 11:06:08 2022 +0200

    clock: port to libgweather 4
    
    https://gitlab.gnome.org/GNOME/gnome-panel/-/issues/38

 .gitlab-ci.yml                       |  2 +-
 configure.ac                         |  4 +--
 modules/clock/Makefile.am            |  1 -
 modules/clock/clock-applet.c         | 14 ++++-----
 modules/clock/clock-location-entry.c | 46 ++++++++++++++---------------
 modules/clock/clock-location-tile.c  | 19 ++++++------
 modules/clock/clock-location.c       | 56 ++++++++++++++++++++++--------------
 modules/clock/clock-location.h       |  2 +-
 8 files changed, 78 insertions(+), 66 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 39f7c3927..7b55de843 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -24,7 +24,7 @@ variables:
                   libgnome-desktop-3-dev
                   libgnome-menu-3-dev
                   libgtk-3-dev
-                  libgweather-3-dev
+                  libgweather-4-dev
                   libpango1.0-dev
                   libpolkit-gobject-1-dev
                   libsm-dev
diff --git a/configure.ac b/configure.ac
index 3987adfd6..a326edd4e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -132,7 +132,7 @@ LIBECAL_REQUIRED=3.33.2
 LIBEDATASERVER_REQUIRED=3.5.3
 LIBSYSTEMD_REQUIRED=230
 CAIRO_REQUIRED=1.0.0
-GWEATHER_REQUIRED=40.beta
+GWEATHER_REQUIRED=3.91.0
 DCONF_REQUIRED=0.13.4
 XRANDR_REQUIRED=1.3.0
 
@@ -217,7 +217,7 @@ PKG_CHECK_MODULES([CLOCK], [
   glib-2.0 >= $GLIB_REQUIRED
   gnome-desktop-3.0 >= $LIBGNOME_DESKTOP_REQUIRED
   gtk+-3.0 >= $GTK_REQUIRED
-  gweather-3.0 >= $GWEATHER_REQUIRED
+  gweather4 >= $GWEATHER_REQUIRED
   pango >= $PANGO_REQUIRED
   polkit-gobject-1
 ])
diff --git a/modules/clock/Makefile.am b/modules/clock/Makefile.am
index 6a2b4c4c1..e1174f0cb 100644
--- a/modules/clock/Makefile.am
+++ b/modules/clock/Makefile.am
@@ -48,7 +48,6 @@ org_gnome_gnome_panel_clock_la_CPPFLAGS = \
        -DCLOCK_EDS_ICONDIR="\"$(CLOCK_EDS_ICONDIR)\"" \
        -DEDS_DISABLE_DEPRECATED \
        -DGNOME_DESKTOP_USE_UNSTABLE_API \
-       -DGWEATHER_I_KNOW_THIS_IS_UNSTABLE \
        -I$(top_srcdir) \
        $(AM_CPPFLAGS) \
        $(NULL)
diff --git a/modules/clock/clock-applet.c b/modules/clock/clock-applet.c
index 88896c97d..5663f7705 100644
--- a/modules/clock/clock-applet.c
+++ b/modules/clock/clock-applet.c
@@ -980,7 +980,7 @@ fill_clock_applet (ClockApplet *cd)
 
         cd->applet_settings = gp_applet_settings_new (applet, "org.gnome.gnome-panel.applet.clock");
         cd->clock_settings = g_settings_new ("org.gnome.desktop.interface");
-        cd->weather_settings = g_settings_new ("org.gnome.GWeather");
+        cd->weather_settings = g_settings_new ("org.gnome.GWeather4");
 
         g_signal_connect (cd->clock_settings, "changed::clock-format",
                           G_CALLBACK (format_changed), cd);
@@ -1109,7 +1109,7 @@ get_weather_station_location (GWeatherLocation *location)
                 station_loc = gweather_location_get_parent (location);
                 g_assert (station_loc != NULL);
         } else {
-                station_loc = gweather_location_ref (location);
+                station_loc = g_object_ref (location);
         }
 
         while (gweather_location_get_level (station_loc) < GWEATHER_LOCATION_WEATHER_STATION) {
@@ -1120,7 +1120,7 @@ get_weather_station_location (GWeatherLocation *location)
                 station_loc = gweather_location_next_child (station_loc, NULL);
                 g_assert (station_loc != NULL);
 
-                gweather_location_unref (tmp);
+                g_object_unref (tmp);
         }
 
         return station_loc;
@@ -1162,10 +1162,10 @@ run_prefs_edit_save (GtkButton   *button,
         }
 
         station_loc = get_weather_station_location (gloc);
-        gweather_location_unref (gloc);
+        g_object_unref (gloc);
 
         weather_code = gweather_location_get_code (station_loc);
-        gweather_location_unref (station_loc);
+        g_object_unref (station_loc);
 
         if (clock_location_entry_has_custom_text (cd->location_entry)) {
                 name = gtk_editable_get_chars (GTK_EDITABLE (cd->location_entry), 0, -1);
@@ -1284,7 +1284,7 @@ location_changed (GObject     *object,
         update_coords (cd, latlon_valid, latitude, longitude);
 
         if (gloc)
-                gweather_location_unref (gloc);
+                g_object_unref (gloc);
 }
 
 static void
@@ -1748,7 +1748,7 @@ clock_applet_dispose (GObject *object)
 
         g_clear_object (&applet->datetime_appinfo);
 
-        g_clear_pointer (&applet->world, gweather_location_unref);
+        g_clear_object (&applet->world);
 
         free_locations (applet);
 
diff --git a/modules/clock/clock-location-entry.c b/modules/clock/clock-location-entry.c
index e20529469..f522d249b 100644
--- a/modules/clock/clock-location-entry.c
+++ b/modules/clock/clock-location-entry.c
@@ -132,9 +132,9 @@ finalize (GObject *object)
     priv = entry->priv;
 
     if (priv->location)
-       gweather_location_unref (priv->location);
+       g_object_unref (priv->location);
     if (priv->top)
-       gweather_location_unref (priv->top);
+       g_object_unref (priv->top);
     if (priv->model)
         g_object_unref (priv->model);
 
@@ -227,11 +227,11 @@ clock_location_entry_class_init (ClockLocationEntryClass *location_entry_class)
     /* properties */
     g_object_class_install_property (
        object_class, PROP_TOP,
-       g_param_spec_boxed ("top",
-                           "Top Location",
-                           "The GWeatherLocation whose children will be used to fill in the entry",
-                           GWEATHER_TYPE_LOCATION,
-                           G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+       g_param_spec_object ("top",
+                            "Top Location",
+                            "The GWeatherLocation whose children will be used to fill in the entry",
+                            GWEATHER_TYPE_LOCATION,
+                            G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
     g_object_class_install_property (
        object_class, PROP_SHOW_NAMED_TIMEZONES,
        g_param_spec_boolean ("show-named-timezones",
@@ -241,11 +241,11 @@ clock_location_entry_class_init (ClockLocationEntryClass *location_entry_class)
                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
     g_object_class_install_property (
        object_class, PROP_LOCATION,
-       g_param_spec_boxed ("location",
-                           "Location",
-                           "The selected GWeatherLocation",
-                           GWEATHER_TYPE_LOCATION,
-                           G_PARAM_READWRITE));
+       g_param_spec_object ("location",
+                            "Location",
+                            "The selected GWeatherLocation",
+                            GWEATHER_TYPE_LOCATION,
+                            G_PARAM_READWRITE));
 }
 
 static void
@@ -256,14 +256,14 @@ set_property (GObject *object, guint prop_id,
 
     switch (prop_id) {
     case PROP_TOP:
-        entry->priv->top = g_value_dup_boxed (value);
+        entry->priv->top = g_value_dup_object (value);
        break;
     case PROP_SHOW_NAMED_TIMEZONES:
        entry->priv->show_named_timezones = g_value_get_boolean (value);
        break;
     case PROP_LOCATION:
        clock_location_entry_set_location (CLOCK_LOCATION_ENTRY (object),
-                                          g_value_get_boxed (value));
+                                          g_value_get_object (value));
        break;
     default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -282,7 +282,7 @@ get_property (GObject *object, guint prop_id,
        g_value_set_boolean (value, entry->priv->show_named_timezones);
        break;
     case PROP_LOCATION:
-       g_value_set_boxed (value, entry->priv->location);
+       g_value_set_object (value, entry->priv->location);
        break;
     default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -328,7 +328,7 @@ set_location_internal (ClockLocationEntry *entry,
     priv = entry->priv;
 
     if (priv->location)
-       gweather_location_unref (priv->location);
+       g_object_unref (priv->location);
 
     g_assert (iter == NULL || loc == NULL);
 
@@ -341,7 +341,7 @@ set_location_internal (ClockLocationEntry *entry,
        priv->custom_text = FALSE;
        g_free (name);
     } else if (loc) {
-       priv->location = gweather_location_ref (loc);
+       priv->location = g_object_ref (loc);
        gtk_entry_set_text (GTK_ENTRY (entry), gweather_location_get_name (loc));
        priv->custom_text = FALSE;
     } else {
@@ -391,11 +391,11 @@ clock_location_entry_set_location (ClockLocationEntry *entry,
                            -1);
        if (gweather_location_equal (loc, cmploc)) {
            set_location_internal (entry, model, &iter, NULL);
-           gweather_location_unref (cmploc);
+           g_object_unref (cmploc);
            return;
        }
 
-       gweather_location_unref (cmploc);
+       g_object_unref (cmploc);
     } while (gtk_tree_model_iter_next (model, &iter));
 
     set_location_internal (entry, model, NULL, loc);
@@ -418,7 +418,7 @@ clock_location_entry_get_location (ClockLocationEntry *entry)
     g_return_val_if_fail (CLOCK_IS_LOCATION_ENTRY (entry), NULL);
 
     if (entry->priv->location)
-       return gweather_location_ref (entry->priv->location);
+       return g_object_ref (entry->priv->location);
     else
        return NULL;
 }
@@ -481,14 +481,14 @@ clock_location_entry_set_city (ClockLocationEntry *entry,
 
        cmpcode = gweather_location_get_code (cmploc);
        if (!cmpcode || strcmp (cmpcode, code) != 0) {
-           gweather_location_unref (cmploc);
+           g_object_unref (cmploc);
            continue;
        }
 
        if (city_name) {
            cmpname = gweather_location_get_city_name (cmploc);
            if (!cmpname || strcmp (cmpname, city_name) != 0) {
-               gweather_location_unref (cmploc);
+               g_object_unref (cmploc);
                g_free (cmpname);
                continue;
            }
@@ -496,7 +496,7 @@ clock_location_entry_set_city (ClockLocationEntry *entry,
        }
 
        set_location_internal (entry, model, &iter, NULL);
-       gweather_location_unref (cmploc);
+       g_object_unref (cmploc);
        return TRUE;
     } while (gtk_tree_model_iter_next (model, &iter));
 
diff --git a/modules/clock/clock-location-tile.c b/modules/clock/clock-location-tile.c
index e4de503bd..2d4a1d435 100644
--- a/modules/clock/clock-location-tile.c
+++ b/modules/clock/clock-location-tile.c
@@ -27,7 +27,7 @@ struct _ClockLocationTilePrivate {
         ClockLocation *location;
 
         GDateTime *last_refresh;
-       long last_offset;
+        gint32 last_offset;
 
         ClockFaceSize size;
 
@@ -387,7 +387,7 @@ clock_needs_label_refresh (ClockLocationTile *this)
 {
         ClockLocationTilePrivate *priv;
        GDateTime *now;
-       long offset;
+       gint32 offset;
        gboolean retval;
 
        priv = this->priv;
@@ -413,16 +413,17 @@ clock_needs_label_refresh (ClockLocationTile *this)
 }
 
 static char *
-format_time (GDateTime   *now, 
-             const char  *tzname,
+format_time (GDateTime           *now,
+             const char          *tzname,
              GDesktopClockFormat  clock_format,
-            long         offset)
+             gint32               offset)
 {
        const char *format;
        GDateTime *local_now;
        char *buf;      
        char *tmp;      
-       long hours, minutes;
+       gint32 hours;
+       gint32 minutes;
 
        local_now = g_date_time_new_now_local ();
 
@@ -469,10 +470,10 @@ format_time (GDateTime   *now,
         minutes = labs (offset % 3600) / 60;
 
        if (hours != 0 && minutes != 0) {
-               tmp = g_strdup_printf ("%s <small>%s %+ld:%ld</small>", buf, tzname, hours, minutes);
+               tmp = g_strdup_printf ("%s <small>%s %+d:%d</small>", buf, tzname, hours, minutes);
        }
        else if (hours != 0) {
-               tmp = g_strdup_printf ("%s <small>%s %+ld</small>", buf, tzname, hours);
+               tmp = g_strdup_printf ("%s <small>%s %+d</small>", buf, tzname, hours);
        }
        else {
                tmp = g_strdup_printf ("%s <small>%s</small>", buf, tzname);
@@ -533,7 +534,7 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
         gchar *tmp;
        const char *tzname;
        GDateTime *now;
-       long offset;
+       gint32 offset;
        int format;
 
        g_return_if_fail (IS_CLOCK_LOCATION_TILE (this));
diff --git a/modules/clock/clock-location.c b/modules/clock/clock-location.c
index 673348199..49338cb17 100644
--- a/modules/clock/clock-location.c
+++ b/modules/clock/clock-location.c
@@ -27,7 +27,7 @@ struct _ClockLocationPrivate {
        GWeatherLocation *world;
        GWeatherLocation *loc;
 
-       GWeatherTimezone *wtz;
+       GTimeZone *wtz;
 
         gdouble latitude;
         gdouble longitude;
@@ -55,13 +55,13 @@ static void clock_location_finalize (GObject *);
 static gboolean update_weather_info (gpointer user_data);
 static void setup_weather_updates (ClockLocation *loc);
 
-static GWeatherTimezone *
+static GTimeZone *
 get_gweather_timezone (ClockLocation *loc)
 {
-       GWeatherTimezone *tz;
+       GTimeZone *tz;
        GWeatherLocation *gloc;
 
-       gloc = gweather_location_ref (loc->priv->loc);
+       gloc = g_object_ref (loc->priv->loc);
        tz = gweather_location_get_timezone (gloc);
 
        if (tz == NULL) {
@@ -74,27 +74,27 @@ get_gweather_timezone (ClockLocation *loc)
 
                        gloc = gweather_location_get_parent (gloc);
 
-                       gweather_location_unref (tmp);
+                       g_object_unref (tmp);
                }
 
                tmp = gloc;
                gloc = gweather_location_find_nearest_city (gloc,
                                                            loc->priv->latitude,
                                                            loc->priv->longitude);
-               gweather_location_unref (tmp);
+               g_object_unref (tmp);
 
                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 ();
+                       return g_time_zone_new_utc ();
                }
 
                tz = gweather_location_get_timezone (gloc);
-               tz = gweather_timezone_ref (tz);
-               gweather_location_unref (gloc);
+               tz = g_time_zone_ref (tz);
+               g_object_unref (gloc);
        } else {
-               tz = gweather_timezone_ref (tz);
-               gweather_location_unref (gloc);
+               tz = g_time_zone_ref (tz);
+               g_object_unref (gloc);
        }
 
        return tz;
@@ -116,7 +116,7 @@ clock_location_new (GnomeWallClock   *wall_clock,
         priv = this->priv;
 
        priv->wall_clock = g_object_ref (wall_clock);
-       priv->world = gweather_location_ref (world);
+       priv->world = g_object_ref (world);
        priv->loc = gweather_location_find_by_station_code (priv->world,
                                                            metar_code);
 
@@ -214,10 +214,10 @@ clock_location_finalize (GObject *g_obj)
 
        g_object_unref (priv->wall_clock);
 
-       gweather_location_unref (priv->world);
-       gweather_location_unref (priv->loc);
+       g_object_unref (priv->world);
+       g_object_unref (priv->loc);
 
-       gweather_timezone_unref (priv->wtz);
+       g_time_zone_unref (priv->wtz);
 
        if (priv->weather_timeout)
                g_source_remove (priv->weather_timeout);
@@ -260,13 +260,13 @@ clock_location_get_city (ClockLocation *loc)
 const gchar *
 clock_location_get_timezone (ClockLocation *loc)
 {
-       return gweather_timezone_get_name (loc->priv->wtz);
+       return g_time_zone_get_identifier (loc->priv->wtz);
 }
 
 const gchar *
 clock_location_get_tzname (ClockLocation *loc)
 {
-       return gweather_timezone_get_tzid (loc->priv->wtz);
+       return g_time_zone_get_identifier (loc->priv->wtz);
 }
 
 void
@@ -285,7 +285,7 @@ clock_location_localtime (ClockLocation *loc)
        GTimeZone *tz;
        GDateTime *dt;
 
-       tzid = gweather_timezone_get_tzid (loc->priv->wtz);
+       tzid = g_time_zone_get_identifier (loc->priv->wtz);
        tz = g_time_zone_new_identifier (tzid);
 
        if (tz == NULL) {
@@ -311,7 +311,7 @@ clock_location_is_current_timezone (ClockLocation *loc)
        zone = g_time_zone_get_identifier (timezone);
 
        if (zone)
-               return strcmp (zone, gweather_timezone_get_tzid (loc->priv->wtz)) == 0;
+               return strcmp (zone, g_time_zone_get_identifier (loc->priv->wtz)) == 0;
        else
                return clock_location_get_offset (loc) == 0;
 }
@@ -340,10 +340,22 @@ clock_location_is_current (ClockLocation *loc)
        return FALSE;
 }
 
-glong
+gint32
 clock_location_get_offset (ClockLocation *loc)
 {
-       return gweather_timezone_get_offset (loc->priv->wtz);
+  GDateTime *dt;
+  gint64 now;
+  int interval;
+
+  dt = g_date_time_new_now_local ();
+  now = g_date_time_to_unix (dt);
+  g_date_time_unref (dt);
+
+  interval = g_time_zone_find_interval (loc->priv->wtz,
+                                        G_TIME_TYPE_STANDARD,
+                                        now);
+
+  return g_time_zone_get_offset (loc->priv->wtz, interval);
 }
 
 typedef struct {
@@ -423,7 +435,7 @@ clock_location_make_current (ClockLocation *loc,
        mcdata->data = data;
        mcdata->destroy = destroy;
 
-       set_system_timezone_async (gweather_timezone_get_tzid (loc->priv->wtz),
+       set_system_timezone_async (g_time_zone_get_identifier (loc->priv->wtz),
                                   make_current_cb,
                                   mcdata);
 }
diff --git a/modules/clock/clock-location.h b/modules/clock/clock-location.h
index b632beda3..d5f51a73d 100644
--- a/modules/clock/clock-location.h
+++ b/modules/clock/clock-location.h
@@ -65,7 +65,7 @@ gboolean clock_location_is_current_timezone (ClockLocation *loc);
 const gchar *clock_location_get_weather_code (ClockLocation *loc);
 GWeatherInfo *clock_location_get_weather_info (ClockLocation *loc);
 
-glong clock_location_get_offset (ClockLocation *loc);
+gint32 clock_location_get_offset (ClockLocation *loc);
 
 G_END_DECLS
 #endif /* __CLOCK_LOCATION_H__ */


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