[gtk+] Getting started: Drop ugly signal handler cleanup



commit 7fe3455c9a45b438b947eb0c15c6b8dceb26bc63
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jul 24 01:10:08 2013 -0400

    Getting started: Drop ugly signal handler cleanup
    
    I disconnected signals in dispose() to avoid a visible-tab
    change notification during destruction, but this is clunky.
    
    Instead, make the notify::visible-tab signal handler bail out
    early when called during destruction.

 examples/application7/exampleappwin.c |   25 ++++++----------------
 examples/application8/exampleappwin.c |   36 ++++++++------------------------
 2 files changed, 16 insertions(+), 45 deletions(-)
---
diff --git a/examples/application7/exampleappwin.c b/examples/application7/exampleappwin.c
index 8e09c31..a882851 100644
--- a/examples/application7/exampleappwin.c
+++ b/examples/application7/exampleappwin.c
@@ -21,8 +21,6 @@ struct _ExampleAppWindowPrivate
   GtkWidget *search;
   GtkWidget *searchbar;
   GtkWidget *searchentry;
-  gulong text_changed_handler;
-  gulong tab_changed_handler;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
@@ -67,6 +65,9 @@ visible_child_changed (GObject          *stack,
 {
   ExampleAppWindowPrivate *priv;
 
+  if (gtk_widget_in_destruction (GTK_WIDGET (win)))
+    return;
+
   priv = example_app_window_get_instance_private (win);
   gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->searchbar), FALSE);
 }
@@ -88,10 +89,10 @@ example_app_window_init (ExampleAppWindow *win)
                           priv->searchbar, "search-mode-enabled",
                           G_BINDING_BIDIRECTIONAL);
 
-  priv->text_changed_handler = g_signal_connect (priv->searchentry, "changed",
-                                                 G_CALLBACK (search_text_changed), win);
-  priv->tab_changed_handler = g_signal_connect (priv->stack, "notify::visible-child",
-                                                G_CALLBACK (visible_child_changed), win);
+  g_signal_connect (priv->searchentry, "changed",
+                    G_CALLBACK (search_text_changed), win);
+  g_signal_connect (priv->stack, "notify::visible-child",
+                    G_CALLBACK (visible_child_changed), win);
 }
 
 static void
@@ -103,18 +104,6 @@ example_app_window_dispose (GObject *object)
   win = EXAMPLE_APP_WINDOW (object);
   priv = example_app_window_get_instance_private (win);
 
-  if (priv->text_changed_handler != 0)
-    {
-      g_signal_handler_disconnect (priv->searchentry, priv->text_changed_handler);
-      priv->text_changed_handler = 0;
-    }
-
-  if (priv->tab_changed_handler != 0)
-    {
-      g_signal_handler_disconnect (priv->stack, priv->tab_changed_handler);
-      priv->tab_changed_handler = 0;
-    }
-
   g_clear_object (&priv->settings);
 
   G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);
diff --git a/examples/application8/exampleappwin.c b/examples/application8/exampleappwin.c
index 7f9e79d..d3f1cc5 100644
--- a/examples/application8/exampleappwin.c
+++ b/examples/application8/exampleappwin.c
@@ -24,9 +24,6 @@ struct _ExampleAppWindowPrivate
   GtkWidget *gears;
   GtkWidget *sidebar;
   GtkWidget *words;
-  gulong text_changed_handler;
-  gulong tab_changed_handler;
-  gulong words_changed_handler;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW);
@@ -140,6 +137,9 @@ visible_child_changed (GObject          *stack,
 {
   ExampleAppWindowPrivate *priv;
 
+  if (gtk_widget_in_destruction (GTK_WIDGET (win)))
+    return;
+
   priv = example_app_window_get_instance_private (win);
   gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (priv->searchbar), FALSE);
   update_words (win);
@@ -177,12 +177,12 @@ example_app_window_init (ExampleAppWindow *win)
                           priv->searchbar, "search-mode-enabled",
                           G_BINDING_BIDIRECTIONAL);
 
-  priv->text_changed_handler = g_signal_connect (priv->searchentry, "changed",
-                                                 G_CALLBACK (search_text_changed), win);
-  priv->tab_changed_handler = g_signal_connect (priv->stack, "notify::visible-child",
-                                                G_CALLBACK (visible_child_changed), win);
-  priv->words_changed_handler = g_signal_connect (priv->sidebar, "notify::reveal-child",
-                                                  G_CALLBACK (words_changed), win);
+  g_signal_connect (priv->searchentry, "changed",
+                    G_CALLBACK (search_text_changed), win);
+  g_signal_connect (priv->stack, "notify::visible-child",
+                    G_CALLBACK (visible_child_changed), win);
+  g_signal_connect (priv->sidebar, "notify::reveal-child",
+                    G_CALLBACK (words_changed), win);
 
   builder = gtk_builder_new_from_resource ("/org/gtk/exampleapp/gears-menu.ui");
   menu = G_MENU_MODEL (gtk_builder_get_object (builder, "menu"));
@@ -203,24 +203,6 @@ example_app_window_dispose (GObject *object)
   win = EXAMPLE_APP_WINDOW (object);
   priv = example_app_window_get_instance_private (win);
 
-  if (priv->text_changed_handler != 0)
-    {
-      g_signal_handler_disconnect (priv->searchentry, priv->text_changed_handler);
-      priv->text_changed_handler = 0;
-    }
-
-  if (priv->tab_changed_handler != 0)
-    {
-      g_signal_handler_disconnect (priv->stack, priv->tab_changed_handler);
-      priv->tab_changed_handler = 0;
-    }
-
-  if (priv->words_changed_handler != 0)
-    {
-      g_signal_handler_disconnect (priv->sidebar, priv->words_changed_handler);
-      priv->words_changed_handler = 0;
-    }
-
   g_clear_object (&priv->settings);
 
   G_OBJECT_CLASS (example_app_window_parent_class)->dispose (object);


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