[gimp] app: add gimp_container_remove_handlers_by_{func,data}()
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add gimp_container_remove_handlers_by_{func,data}()
- Date: Fri, 7 Feb 2020 21:38:02 +0000 (UTC)
commit 0891f1275a6b8670da86de2a7abb17809bdd4458
Author: Ell <ell_se yahoo com>
Date: Fri Feb 7 23:23:53 2020 +0200
app: add gimp_container_remove_handlers_by_{func,data}()
... which remove all handlers matching the given callback/callback-
data.
temp
app/core/gimpcontainer.c | 116 +++++++++++++++++++++++++++++++++++++----------
app/core/gimpcontainer.h | 7 +++
2 files changed, 99 insertions(+), 24 deletions(-)
---
diff --git a/app/core/gimpcontainer.c b/app/core/gimpcontainer.c
index 95fbed9661..bbfbe5fb4b 100644
--- a/app/core/gimpcontainer.c
+++ b/app/core/gimpcontainer.c
@@ -115,6 +115,9 @@ static gboolean gimp_container_deserialize (GimpConfig *config,
static void gimp_container_disconnect_callback (GimpObject *object,
gpointer data);
+static void gimp_container_free_handler (GimpContainer *container,
+ GimpContainerHandler *handler);
+
G_DEFINE_TYPE_WITH_CODE (GimpContainer, gimp_container, GIMP_TYPE_OBJECT,
G_ADD_PRIVATE (GimpContainer)
@@ -519,6 +522,37 @@ gimp_container_disconnect_callback (GimpObject *object,
gimp_container_remove (container, object);
}
+static void
+gimp_container_free_handler_foreach_func (GimpObject *object,
+ GimpContainerHandler *handler)
+{
+ gulong handler_id;
+
+ handler_id = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (object),
+ handler->quark));
+
+ if (handler_id)
+ {
+ g_signal_handler_disconnect (object, handler_id);
+
+ g_object_set_qdata (G_OBJECT (object), handler->quark, NULL);
+ }
+}
+
+static void
+gimp_container_free_handler (GimpContainer *container,
+ GimpContainerHandler *handler)
+{
+ D (g_print ("%s: id = %d\n", G_STRFUNC, handler->quark));
+
+ gimp_container_foreach (container,
+ (GFunc) gimp_container_free_handler_foreach_func,
+ handler);
+
+ g_free (handler->signame);
+ g_slice_free (GimpContainerHandler, handler);
+}
+
GType
gimp_container_get_children_type (GimpContainer *container)
{
@@ -1041,23 +1075,6 @@ gimp_container_add_handler (GimpContainer *container,
return handler->quark;
}
-static void
-gimp_container_remove_handler_foreach_func (GimpObject *object,
- GimpContainerHandler *handler)
-{
- gulong handler_id;
-
- handler_id = GPOINTER_TO_UINT (g_object_get_qdata (G_OBJECT (object),
- handler->quark));
-
- if (handler_id)
- {
- g_signal_handler_disconnect (object, handler_id);
-
- g_object_set_qdata (G_OBJECT (object), handler->quark, NULL);
- }
-}
-
void
gimp_container_remove_handler (GimpContainer *container,
GQuark id)
@@ -1083,14 +1100,65 @@ gimp_container_remove_handler (GimpContainer *container,
return;
}
- D (g_print ("%s: id = %d\n", G_STRFUNC, handler->quark));
+ gimp_container_free_handler (container, handler);
- gimp_container_foreach (container,
- (GFunc) gimp_container_remove_handler_foreach_func,
- handler);
+ container->priv->handlers = g_list_delete_link (container->priv->handlers,
+ list);
+}
- container->priv->handlers = g_list_remove (container->priv->handlers, handler);
+void
+gimp_container_remove_handlers_by_func (GimpContainer *container,
+ GCallback callback,
+ gpointer callback_data)
+{
+ GList *list;
- g_free (handler->signame);
- g_slice_free (GimpContainerHandler, handler);
+ g_return_if_fail (GIMP_IS_CONTAINER (container));
+ g_return_if_fail (callback != NULL);
+
+ list = container->priv->handlers;
+
+ while (list)
+ {
+ GimpContainerHandler *handler = list->data;
+ GList *next = g_list_next (list);
+
+ if (handler->callback == callback &&
+ handler->callback_data == callback_data)
+ {
+ gimp_container_free_handler (container, handler);
+
+ container->priv->handlers = g_list_delete_link (
+ container->priv->handlers, list);
+ }
+
+ list = next;
+ }
+}
+
+void
+gimp_container_remove_handlers_by_data (GimpContainer *container,
+ gpointer callback_data)
+{
+ GList *list;
+
+ g_return_if_fail (GIMP_IS_CONTAINER (container));
+
+ list = container->priv->handlers;
+
+ while (list)
+ {
+ GimpContainerHandler *handler = list->data;
+ GList *next = g_list_next (list);
+
+ if (handler->callback_data == callback_data)
+ {
+ gimp_container_free_handler (container, handler);
+
+ container->priv->handlers = g_list_delete_link (
+ container->priv->handlers, list);
+ }
+
+ list = next;
+ }
}
diff --git a/app/core/gimpcontainer.h b/app/core/gimpcontainer.h
index dda4bbdbae..88465b5486 100644
--- a/app/core/gimpcontainer.h
+++ b/app/core/gimpcontainer.h
@@ -138,6 +138,13 @@ GQuark gimp_container_add_handler (GimpContainer *contain
gpointer callback_data);
void gimp_container_remove_handler (GimpContainer *container,
GQuark id);
+void gimp_container_remove_handlers_by_func
+ (GimpContainer *container,
+ GCallback callback,
+ gpointer callback_data);
+void gimp_container_remove_handlers_by_data
+ (GimpContainer *container,
+ gpointer callback_data);
#endif /* __GIMP_CONTAINER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]