[Xfce4-commits] [apps/mousepad] 09/09: Properly disconnect windows' settings handlers

noreply at xfce.org noreply at xfce.org
Sun Jul 13 05:10:27 CEST 2014


This is an automated email from the git hooks/post-receive script.

mbrush pushed a commit to branch master
in repository apps/mousepad.

commit 0075c9a828045e47ab5b28301c2e4e8e27b565eb
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Sat Jul 12 20:05:52 2014 -0700

    Properly disconnect windows' settings handlers
    
    Since the GSettings lives longer than the windows, if we don't
    disconnect, and destroy the windows, the settings will still try and
    call back into the already destroyed window. There's probably a cleaner
    way to handler this.
---
 mousepad/mousepad-window.c |  150 +++++++++++++++++++++++++++++---------------
 1 file changed, 98 insertions(+), 52 deletions(-)

diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index e18fc42..7e68b1f 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -406,6 +406,21 @@ struct _MousepadWindow
   /* idle update functions for the recent and go menu */
   guint                update_recent_menu_id;
   guint                update_go_menu_id;
+
+  /* settings signal handler ids that must be disconnected on destruction */
+  gulong               menubar_visible_id;
+  gulong               menubar_visible_fs_id;
+  gulong               toolbar_visible_id;
+  gulong               toolbar_visible_fs_id;
+  gulong               toolbar_style_id;
+  gulong               toolbar_icon_size_id;
+  gulong               tab_width_id;
+  gulong               insert_spaces_id;
+  gulong               statusbar_visible_id;
+  gulong               statusbar_visible_fs_id;
+  gulong               path_in_title_id;
+  gulong               always_show_tabs_id;
+  gulong               recent_menu_items_id;
 };
 
 
@@ -702,15 +717,17 @@ mousepad_window_create_menubar (MousepadWindow *window)
   gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);
   gtk_widget_set_visible (window->menubar, active);
 
-  MOUSEPAD_SETTING_CONNECT (MENUBAR_VISIBLE,
-                            G_CALLBACK (mousepad_window_update_main_widgets),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->menubar_visible_id =
+    MOUSEPAD_SETTING_CONNECT (MENUBAR_VISIBLE,
+                              G_CALLBACK (mousepad_window_update_main_widgets),
+                              window,
+                              G_CONNECT_SWAPPED);
 
-  MOUSEPAD_SETTING_CONNECT (MENUBAR_VISIBLE_FULLSCREEN,
-                            G_CALLBACK (mousepad_window_update_main_widgets),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->menubar_visible_fs_id =
+    MOUSEPAD_SETTING_CONNECT (MENUBAR_VISIBLE_FULLSCREEN,
+                              G_CALLBACK (mousepad_window_update_main_widgets),
+                              window,
+                              G_CONNECT_SWAPPED);
 }
 
 
@@ -746,25 +763,29 @@ mousepad_window_create_toolbar (MousepadWindow *window)
   mousepad_window_update_toolbar (window, NULL, NULL);
 
   /* connect to some signals to keep in sync */
-  MOUSEPAD_SETTING_CONNECT (TOOLBAR_VISIBLE,
-                            G_CALLBACK (mousepad_window_update_toolbar),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->toolbar_visible_id =
+    MOUSEPAD_SETTING_CONNECT (TOOLBAR_VISIBLE,
+                              G_CALLBACK (mousepad_window_update_toolbar),
+                              window,
+                              G_CONNECT_SWAPPED);
 
-  MOUSEPAD_SETTING_CONNECT (TOOLBAR_VISIBLE_FULLSCREEN,
-                            G_CALLBACK (mousepad_window_update_main_widgets),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->toolbar_visible_fs_id =
+    MOUSEPAD_SETTING_CONNECT (TOOLBAR_VISIBLE_FULLSCREEN,
+                              G_CALLBACK (mousepad_window_update_main_widgets),
+                              window,
+                              G_CONNECT_SWAPPED);
 
-  MOUSEPAD_SETTING_CONNECT (TOOLBAR_STYLE,
-                            G_CALLBACK (mousepad_window_update_toolbar),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->toolbar_style_id =
+    MOUSEPAD_SETTING_CONNECT (TOOLBAR_STYLE,
+                              G_CALLBACK (mousepad_window_update_toolbar),
+                              window,
+                              G_CONNECT_SWAPPED);
 
-  MOUSEPAD_SETTING_CONNECT (TOOLBAR_ICON_SIZE,
-                            G_CALLBACK (mousepad_window_update_toolbar),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->toolbar_icon_size_id =
+    MOUSEPAD_SETTING_CONNECT (TOOLBAR_ICON_SIZE,
+                              G_CALLBACK (mousepad_window_update_toolbar),
+                              window,
+                              G_CONNECT_SWAPPED);
 }
 
 
@@ -880,25 +901,29 @@ mousepad_window_create_statusbar (MousepadWindow *window)
     mousepad_document_send_signals (window->active);
 
   /* update the statusbar with certain settings */
-  MOUSEPAD_SETTING_CONNECT (TAB_WIDTH,
-                            G_CALLBACK (mousepad_window_update_statusbar_settings),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->tab_width_id =
+    MOUSEPAD_SETTING_CONNECT (TAB_WIDTH,
+                              G_CALLBACK (mousepad_window_update_statusbar_settings),
+                              window,
+                              G_CONNECT_SWAPPED);
 
-  MOUSEPAD_SETTING_CONNECT (INSERT_SPACES,
-                            G_CALLBACK (mousepad_window_update_statusbar_settings),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->insert_spaces_id =
+    MOUSEPAD_SETTING_CONNECT (INSERT_SPACES,
+                              G_CALLBACK (mousepad_window_update_statusbar_settings),
+                              window,
+                              G_CONNECT_SWAPPED);
 
-  MOUSEPAD_SETTING_CONNECT (STATUSBAR_VISIBLE,
-                            G_CALLBACK (mousepad_window_update_main_widgets),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->statusbar_visible_id =
+    MOUSEPAD_SETTING_CONNECT (STATUSBAR_VISIBLE,
+                              G_CALLBACK (mousepad_window_update_main_widgets),
+                              window,
+                              G_CONNECT_SWAPPED);
 
-  MOUSEPAD_SETTING_CONNECT (STATUSBAR_VISIBLE_FULLSCREEN,
-                            G_CALLBACK (mousepad_window_update_main_widgets),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->statusbar_visible_fs_id =
+    MOUSEPAD_SETTING_CONNECT (STATUSBAR_VISIBLE_FULLSCREEN,
+                              G_CALLBACK (mousepad_window_update_main_widgets),
+                              window,
+                              G_CONNECT_SWAPPED);
 }
 
 
@@ -1007,22 +1032,25 @@ mousepad_window_init (MousepadWindow *window)
                           G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE | G_BINDING_INVERT_BOOLEAN);
 
   /* update the window title when 'path-in-title' setting changes */
-  MOUSEPAD_SETTING_CONNECT (PATH_IN_TITLE,
-                            G_CALLBACK (mousepad_window_update_window_title),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->path_in_title_id =
+    MOUSEPAD_SETTING_CONNECT (PATH_IN_TITLE,
+                              G_CALLBACK (mousepad_window_update_window_title),
+                              window,
+                              G_CONNECT_SWAPPED);
 
   /* update the tabs when 'always-show-tabs' setting changes */
-  MOUSEPAD_SETTING_CONNECT (ALWAYS_SHOW_TABS,
-                            G_CALLBACK (mousepad_window_update_tabs),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->always_show_tabs_id =
+    MOUSEPAD_SETTING_CONNECT (ALWAYS_SHOW_TABS,
+                              G_CALLBACK (mousepad_window_update_tabs),
+                              window,
+                              G_CONNECT_SWAPPED);
 
   /* update the recent items menu when 'window-recent-menu-items' setting changes */
-  MOUSEPAD_SETTING_CONNECT (RECENT_MENU_ITEMS,
-                            G_CALLBACK (mousepad_window_update_recent_menu),
-                            window,
-                            G_CONNECT_SWAPPED);
+  window->recent_menu_items_id =
+    MOUSEPAD_SETTING_CONNECT (RECENT_MENU_ITEMS,
+                              G_CALLBACK (mousepad_window_update_recent_menu),
+                              window,
+                              G_CONNECT_SWAPPED);
 }
 
 
@@ -1050,6 +1078,24 @@ mousepad_window_finalize (GObject *object)
 {
   MousepadWindow *window = MOUSEPAD_WINDOW (object);
 
+  /* disconnect settings callbacks since settings lives longer than the window */
+# define DISCONNECT_(setting, lower) \
+      MOUSEPAD_SETTING_DISCONNECT (setting, window->lower##_id)
+  DISCONNECT_ (MENUBAR_VISIBLE, menubar_visible);
+  DISCONNECT_ (MENUBAR_VISIBLE_FULLSCREEN, menubar_visible_fs);
+  DISCONNECT_ (TOOLBAR_VISIBLE, toolbar_visible);
+  DISCONNECT_ (TOOLBAR_VISIBLE_FULLSCREEN, toolbar_visible_fs);
+  DISCONNECT_ (TOOLBAR_STYLE, toolbar_style);
+  DISCONNECT_ (TOOLBAR_ICON_SIZE, toolbar_icon_size);
+  DISCONNECT_ (TAB_WIDTH, tab_width);
+  DISCONNECT_ (INSERT_SPACES, insert_spaces);
+  DISCONNECT_ (STATUSBAR_VISIBLE, statusbar_visible);
+  DISCONNECT_ (STATUSBAR_VISIBLE_FULLSCREEN, statusbar_visible_fs);
+  DISCONNECT_ (PATH_IN_TITLE, path_in_title);
+  DISCONNECT_ (ALWAYS_SHOW_TABS, always_show_tabs);
+  DISCONNECT_ (RECENT_MENU_ITEMS, recent_menu_items);
+# undef DISCONNECT_
+
   /* decrease history clipboard ref count */
   clipboard_history_ref_count--;
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list