[gnome-panel/wip/segeiger/fix-panel-crash: 1/2] panel-menu-items: implement dispose function



commit 2c6c06722450845c1a83414bb0b0a7af4267f16b
Author: Sebastian Geiger <sbastig gmx net>
Date:   Tue Sep 13 14:02:38 2016 +0200

    panel-menu-items: implement dispose function
    
    cleanup gsettings instance and disconnect
    callback to avoid that we receive a signal
    after we have destroyed the widget.

 gnome-panel/panel-menu-items.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/gnome-panel/panel-menu-items.c b/gnome-panel/panel-menu-items.c
index 2dfec6f..b7124fe 100644
--- a/gnome-panel/panel-menu-items.c
+++ b/gnome-panel/panel-menu-items.c
@@ -71,6 +71,7 @@ G_DEFINE_TYPE (PanelDesktopMenuItem, panel_desktop_menu_item, PANEL_TYPE_IMAGE_M
 struct _PanelPlaceMenuItemPrivate {
        GtkWidget   *menu;
        PanelWidget *panel;
+       GSettings   *settings;
 
        GtkRecentManager *recent_manager;
 
@@ -1262,6 +1263,24 @@ panel_desktop_menu_item_create_menu (PanelDesktopMenuItem *desktop_item,
 }
 
 static void
+panel_place_menu_item_dispose (GObject *object)
+{
+  PanelPlaceMenuItem *menuitem = (PanelPlaceMenuItem *) object;
+
+  GSettings *settings = menuitem->priv->settings;
+
+  if (settings)
+    {
+      g_signal_handlers_disconnect_by_func (settings,
+                                            panel_place_menu_item_key_changed,
+                                            menuitem);
+      g_clear_object (&menuitem->priv->settings);
+    }
+
+  G_OBJECT_CLASS (panel_place_menu_item_parent_class)->dispose (object);
+}
+
+static void
 panel_place_menu_item_finalize (GObject *object)
 {
        PanelPlaceMenuItem *menuitem = (PanelPlaceMenuItem *) object;
@@ -1335,6 +1354,9 @@ panel_place_menu_item_init (PanelPlaceMenuItem *menuitem)
        menuitem->priv = PANEL_PLACE_MENU_ITEM_GET_PRIVATE (menuitem);
 
        settings = g_settings_new (GNOME_NAUTILUS_DESKTOP_SCHEMA);
+
+       menuitem->priv->settings = settings;
+
        g_signal_connect (settings, "changed::" GNOME_NAUTILUS_DESKTOP_HOME_ICON_NAME_KEY,
                          G_CALLBACK (panel_place_menu_item_key_changed), menuitem);
 
@@ -1416,6 +1438,7 @@ panel_place_menu_item_class_init (PanelPlaceMenuItemClass *klass)
        GObjectClass *gobject_class = (GObjectClass *) klass;
 
        gobject_class->finalize = panel_place_menu_item_finalize;
+       gobject_class->dispose = panel_place_menu_item_dispose;
 
        g_type_class_add_private (klass, sizeof (PanelPlaceMenuItemPrivate));
 }


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