Refactor the floating ref hack into a new function
authorXavier Claessens <xclaesse@gmail.com>
Thu, 16 Apr 2009 12:29:33 +0000 (12:29 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Thu, 16 Apr 2009 12:29:33 +0000 (12:29 +0000)
From: Xavier Claessens <xclaesse@gmail.com>

svn path=/trunk/; revision=2871

libempathy-gtk/empathy-account-widget-irc.c
libempathy-gtk/empathy-account-widget-sip.c
libempathy-gtk/empathy-account-widget.c
libempathy-gtk/empathy-contact-widget.c
libempathy-gtk/empathy-ui-utils.c
libempathy-gtk/empathy-ui-utils.h

index 043f05dc8070a043862bc73d7785e5525ef494e5..3af842415ec219a1e41b4298d86cb05f47408f0b 100644 (file)
@@ -505,9 +505,5 @@ empathy_account_widget_irc_new (McAccount *account)
       "combobox_network", "changed", account_widget_irc_combobox_network_changed_cb,
       NULL);
 
-  g_object_ref (settings->vbox_settings);
-  g_object_force_floating (G_OBJECT (settings->vbox_settings));
-  g_object_unref (gui);
-
-  return settings->vbox_settings;
+  return empathy_builder_unref_and_keep_widget (gui, settings->vbox_settings);
 }
index ffac231d6a819fccff73e579e29ffd9ca124c209..2d494477931ae75a65bf570c8c47c29ffdf6e1ff 100644 (file)
@@ -115,9 +115,5 @@ empathy_account_widget_sip_new (McAccount *account)
       "checkbutton_discover-stun", "toggled", account_widget_sip_discover_stun_toggled_cb,
       NULL);
 
-  g_object_ref (settings->vbox_settings);
-  g_object_force_floating (G_OBJECT (settings->vbox_settings));
-  g_object_unref (gui);
-
-  return settings->vbox_settings;
+  return empathy_builder_unref_and_keep_widget (gui, settings->vbox_settings);
 }
index e57fb2802a4c43ac52aba97e40b23efa5385a206..33cef69ae40c58e0d6968b4bde145b364fad27c3 100644 (file)
@@ -481,11 +481,7 @@ empathy_account_widget_generic_new (McAccount *account)
 
        accounts_widget_generic_setup (account, table_common_settings, table_advanced_settings);
 
-       g_object_ref (widget);
-       g_object_force_floating (G_OBJECT (widget));
-       g_object_unref (gui);
-
-       return widget;
+       return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
@@ -513,11 +509,7 @@ empathy_account_widget_salut_new (McAccount *account)
 
        g_object_unref (gui);
 
-       g_object_ref (widget);
-       g_object_force_floating (G_OBJECT (widget));
-       g_object_unref (gui);
-
-       return widget;
+       return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
@@ -545,11 +537,7 @@ empathy_account_widget_msn_new (McAccount *account)
                                                  "button_forget",
                                                  "entry_password");
 
-       g_object_ref (widget);
-       g_object_force_floating (G_OBJECT (widget));
-       g_object_unref (gui);
-
-       return widget;
+       return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
@@ -590,11 +578,7 @@ empathy_account_widget_jabber_new (McAccount *account)
                          G_CALLBACK (account_widget_jabber_ssl_toggled_cb),
                          spinbutton_port);
 
-       g_object_ref (widget);
-       g_object_force_floating (G_OBJECT (widget));
-       g_object_unref (gui);
-
-       return widget;
+       return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
@@ -625,11 +609,7 @@ empathy_account_widget_icq_new (McAccount *account)
                                                  "button_forget",
                                                  "entry_password");
 
-       g_object_ref (widget);
-       g_object_force_floating (G_OBJECT (widget));
-       g_object_unref (gui);
-
-       return widget;
+       return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
@@ -659,11 +639,7 @@ empathy_account_widget_aim_new (McAccount *account)
                                                  "button_forget",
                                                  "entry_password");
 
-       g_object_ref (widget);
-       g_object_force_floating (G_OBJECT (widget));
-       g_object_unref (gui);
-
-       return widget;
+       return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
@@ -695,11 +671,7 @@ empathy_account_widget_yahoo_new (McAccount *account)
                                                  "button_forget",
                                                  "entry_password");
 
-       g_object_ref (widget);
-       g_object_force_floating (G_OBJECT (widget));
-       g_object_unref (gui);
-
-       return widget;
+       return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
 GtkWidget *
@@ -727,10 +699,6 @@ empathy_account_widget_groupwise_new (McAccount *account)
                                                  "button_forget",
                                                  "entry_password");
 
-       g_object_ref (widget);
-       g_object_force_floating (G_OBJECT (widget));
-       g_object_unref (gui);
-
-       return widget;
+       return empathy_builder_unref_and_keep_widget (gui, widget);
 }
 
index 6d302171af633aa4283265d13209a19d37a8e074..0b2fb82b8b86034fa53f15be137180550ed6f1c2 100644 (file)
@@ -209,11 +209,8 @@ empathy_contact_widget_new (EmpathyContact *contact,
 
   contact_widget_set_contact (information, contact);
 
-  g_object_ref (information->vbox_contact_widget);
-  g_object_force_floating (G_OBJECT (information->vbox_contact_widget));
-  g_object_unref (gui);
-
-  return information->vbox_contact_widget;
+  return empathy_builder_unref_and_keep_widget (gui,
+    information->vbox_contact_widget);
 }
 
 EmpathyContact *
index a1f4a6bfc8ba2d2bc3154521460045c0d24100f3..aa34928998e4feac39d6dcd23127a49e47be6e54 100644 (file)
@@ -166,6 +166,23 @@ empathy_builder_connect (GtkBuilder *gui,
        va_end (args);
 }
 
+GtkWidget *
+empathy_builder_unref_and_keep_widget (GtkBuilder *gui,
+                                      GtkWidget  *widget)
+{
+       /* On construction gui sinks the initial reference to widget. When gui
+        * is finalized it will drop its ref to widget. We take our own ref to
+        * prevent widget being finalised. The widget is forced to have a
+        * floating reference, like when it was initially unowned so that it can
+        * be used like any other GtkWidget. */
+
+       g_object_ref (widget);
+       g_object_force_floating (G_OBJECT (widget));
+       g_object_unref (gui);
+
+       return widget;
+}
+
 const gchar *
 empathy_icon_name_from_account (McAccount *account)
 {
index 3f9cbff251073e6b6e65b460b497867f654a1eab..8dcc4c0376644ae0d92c238c7229fb476e299c4d 100644 (file)
@@ -72,6 +72,8 @@ void            empathy_builder_connect                 (GtkBuilder       *gui,
                                                         gpointer          user_data,
                                                         gchar            *first_object,
                                                         ...);
+GtkWidget     *empathy_builder_unref_and_keep_widget    (GtkBuilder       *gui,
+                                                        GtkWidget        *root);
 
 /* Pixbufs */
 const gchar * empathy_icon_name_from_account            (McAccount        *account);