From 23748971577ddff3731eab86de92f367c598cb70 Mon Sep 17 00:00:00 2001 From: rbuj Date: Mon, 25 Oct 2021 00:28:08 +0200 Subject: Use GLib's new g_clear_signal_handler() function to simplify code --- src/eom-metadata-sidebar.c | 5 +++++ src/eom-scroll-view.c | 13 +++++++++---- src/eom-thumb-view.c | 25 ++++++++++++++++--------- 3 files changed, 30 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/eom-metadata-sidebar.c b/src/eom-metadata-sidebar.c index 982a937..9b8fc8b 100644 --- a/src/eom-metadata-sidebar.c +++ b/src/eom-metadata-sidebar.c @@ -263,11 +263,16 @@ eom_metadata_sidebar_set_image (EomMetadataSidebar *sidebar, EomImage *image) if (image == priv->image) return; +#if GLIB_CHECK_VERSION(2,62,0) + g_clear_signal_handler (&priv->thumb_changed_id, + priv->image); +#else if (priv->thumb_changed_id != 0) { g_signal_handler_disconnect (priv->image, priv->thumb_changed_id); priv->thumb_changed_id = 0; } +#endif if (priv->image) g_object_unref (priv->image); diff --git a/src/eom-scroll-view.c b/src/eom-scroll-view.c index 24a1f0f..3fc64d4 100644 --- a/src/eom-scroll-view.c +++ b/src/eom-scroll-view.c @@ -87,8 +87,8 @@ struct _EomScrollViewPrivate { /* actual image */ EomImage *image; - guint image_changed_id; - guint frame_changed_id; + gulong image_changed_id; + gulong frame_changed_id; GdkPixbuf *pixbuf; cairo_surface_t *surface; @@ -188,15 +188,20 @@ free_image_resources (EomScrollView *view) priv = view->priv; - if (priv->image_changed_id > 0) { +#if GLIB_CHECK_VERSION(2,62,0) + g_clear_signal_handler (&priv->image_changed_id, priv->image); + g_clear_signal_handler (&priv->frame_changed_id, priv->image); +#else + if (priv->image_changed_id != 0) { g_signal_handler_disconnect (priv->image, priv->image_changed_id); priv->image_changed_id = 0; } - if (priv->frame_changed_id > 0) { + if (priv->frame_changed_id != 0) { g_signal_handler_disconnect (priv->image, priv->frame_changed_id); priv->frame_changed_id = 0; } +#endif if (priv->image != NULL) { eom_image_data_unref (priv->image); diff --git a/src/eom-thumb-view.c b/src/eom-thumb-view.c index 3a2ddf4..0b28440 100644 --- a/src/eom-thumb-view.c +++ b/src/eom-thumb-view.c @@ -78,7 +78,7 @@ struct _EomThumbViewPrivate { gint end_thumb; /* the last visible thumbnail */ GtkWidget *menu; /* a contextual menu for thumbnails */ GtkCellRenderer *pixbuf_cell; - gint visible_range_changed_id; + guint visible_range_changed_id; GtkOrientation orientation; gint n_images; @@ -167,17 +167,24 @@ eom_thumb_view_dispose (GObject *object) priv->visible_range_changed_id = 0; } - model = gtk_icon_view_get_model (GTK_ICON_VIEW (object)); - - if (model && priv->image_add_id != 0) { - g_signal_handler_disconnect (model, priv->image_add_id); - priv->image_add_id = 0; +#if GLIB_CHECK_VERSION(2,62,0) + if ((model = gtk_icon_view_get_model (GTK_ICON_VIEW (object))) != NULL) { + g_clear_signal_handler (&priv->image_add_id, model); + g_clear_signal_handler (&priv->image_removed_id, model); } +#else + if ((model = gtk_icon_view_get_model (GTK_ICON_VIEW (object))) != NULL) { + if (priv->image_add_id != 0) { + g_signal_handler_disconnect (model, priv->image_add_id); + priv->image_add_id = 0; + } - if (model && priv->image_removed_id) { - g_signal_handler_disconnect (model, priv->image_removed_id); - priv->image_removed_id = 0; + if (priv->image_removed_id != 0) { + g_signal_handler_disconnect (model, priv->image_removed_id); + priv->image_removed_id = 0; + } } +#endif G_OBJECT_CLASS (eom_thumb_view_parent_class)->dispose (object); } -- cgit v1.2.1