summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntónio Fernandes <antoniof@gnome.org>2021-08-15 21:50:02 +0100
committerAntónio Fernandes <antoniof@gnome.org>2021-08-16 09:59:25 +0100
commit3b53d7b2f4fc6f806a9b4153697212bf7543e84f (patch)
tree0facd8f8053e5b81fdf81989063bb9238672ee9d
parent59040d0d6128956e63c2374eabd513ecd5241d1b (diff)
downloadnautilus-wip/antoniof/gtk4-preparation-miscellaneous.tar.gz
general: Stop overriding GtkWidget.destroy()wip/antoniof/gtk4-preparation-miscellaneous
It's gone in GTK4. Anything we are doing on ::destroy can be done on ::dispose(). Extra care must be taken, however, because GObject.dispose() may be run multiple times. Also, while we are at it, move some object unreferencing from .finalize() to .dispose(), which is where we should do it.
-rw-r--r--src/nautilus-files-view.c42
-rw-r--r--src/nautilus-location-entry.c18
-rw-r--r--src/nautilus-properties-window.c6
-rw-r--r--src/nautilus-window.c27
4 files changed, 41 insertions, 52 deletions
diff --git a/src/nautilus-files-view.c b/src/nautilus-files-view.c
index f013fa68c..ef0b615c9 100644
--- a/src/nautilus-files-view.c
+++ b/src/nautilus-files-view.c
@@ -3248,7 +3248,7 @@ nautilus_files_view_set_selection (NautilusView *nautilus_files_view,
}
static void
-nautilus_files_view_destroy (GtkWidget *object)
+nautilus_files_view_dispose (GObject *object)
{
NautilusFilesView *view;
NautilusFilesViewPrivate *priv;
@@ -3341,11 +3341,18 @@ nautilus_files_view_destroy (GtkWidget *object)
g_clear_object (&priv->search_query);
g_clear_object (&priv->location);
+ g_clear_object (&priv->view_action_group);
+ g_clear_object (&priv->background_menu_model);
+ g_clear_object (&priv->selection_menu_model);
+ g_clear_object (&priv->toolbar_menu_sections->zoom_section);
+ g_clear_object (&priv->toolbar_menu_sections->extended_section);
+ g_clear_object (&priv->extensions_background_menu);
+ g_clear_object (&priv->templates_menu);
+ g_clear_object (&priv->rename_file_controller);
+ g_clear_object (&priv->new_folder_controller);
+ g_clear_object (&priv->compress_controller);
- /* We don't own the slot, so no unref */
- priv->slot = NULL;
-
- GTK_WIDGET_CLASS (nautilus_files_view_parent_class)->destroy (object);
+ G_OBJECT_CLASS (nautilus_files_view_parent_class)->dispose (object);
}
static void
@@ -3357,16 +3364,9 @@ nautilus_files_view_finalize (GObject *object)
view = NAUTILUS_FILES_VIEW (object);
priv = nautilus_files_view_get_instance_private (view);
- g_clear_object (&priv->view_action_group);
- g_clear_object (&priv->background_menu_model);
- g_clear_object (&priv->selection_menu_model);
- g_clear_object (&priv->toolbar_menu_sections->zoom_section);
- g_clear_object (&priv->toolbar_menu_sections->extended_section);
- g_clear_object (&priv->extensions_background_menu);
- g_clear_object (&priv->templates_menu);
- g_clear_object (&priv->rename_file_controller);
- g_clear_object (&priv->new_folder_controller);
- g_clear_object (&priv->compress_controller);
+ /* We don't own the slot, so no unref */
+ priv->slot = NULL;
+
g_free (priv->toolbar_menu_sections);
g_hash_table_destroy (priv->non_ready_files);
@@ -7327,7 +7327,7 @@ on_clipboard_contents_received (GtkClipboard *clipboard,
view = NAUTILUS_FILES_VIEW (user_data);
priv = nautilus_files_view_get_instance_private (view);
- if (priv->slot == NULL ||
+ if (priv->in_destruction ||
!priv->active)
{
/* We've been destroyed or became inactive since call */
@@ -7369,7 +7369,7 @@ on_clipboard_targets_received (GtkClipboard *clipboard,
priv = nautilus_files_view_get_instance_private (view);
is_data_copied = FALSE;
- if (priv->slot == NULL ||
+ if (priv->in_destruction ||
!priv->active)
{
/* We've been destroyed or became inactive since call */
@@ -8400,7 +8400,7 @@ nautilus_files_view_update_toolbar_menus (NautilusFilesView *view)
/* Don't update after destroy (#349551),
* or if we are not active.
*/
- if (priv->slot == NULL ||
+ if (priv->in_destruction ||
!priv->active)
{
return;
@@ -8557,7 +8557,7 @@ schedule_update_context_menus (NautilusFilesView *view)
/* Don't schedule updates after destroy (#349551),
* or if we are not active.
*/
- if (priv->slot == NULL ||
+ if (priv->in_destruction ||
!priv->active)
{
return;
@@ -8608,7 +8608,7 @@ schedule_update_status (NautilusFilesView *view)
priv = nautilus_files_view_get_instance_private (view);
/* Make sure we haven't already destroyed it */
- if (priv->slot == NULL)
+ if (priv->in_destruction)
{
return;
}
@@ -9699,11 +9699,11 @@ nautilus_files_view_class_init (NautilusFilesViewClass *klass)
widget_class = GTK_WIDGET_CLASS (klass);
oclass = G_OBJECT_CLASS (klass);
+ oclass->dispose = nautilus_files_view_dispose;
oclass->finalize = nautilus_files_view_finalize;
oclass->get_property = nautilus_files_view_get_property;
oclass->set_property = nautilus_files_view_set_property;
- widget_class->destroy = nautilus_files_view_destroy;
widget_class->event = nautilus_files_view_event;
widget_class->parent_set = nautilus_files_view_parent_set;
widget_class->grab_focus = nautilus_files_view_grab_focus;
diff --git a/src/nautilus-location-entry.c b/src/nautilus-location-entry.c
index 91b9ec7cb..4e1043396 100644
--- a/src/nautilus-location-entry.c
+++ b/src/nautilus-location-entry.c
@@ -576,18 +576,14 @@ finalize (GObject *object)
entry = NAUTILUS_LOCATION_ENTRY (object);
priv = nautilus_location_entry_get_instance_private (entry);
- g_object_unref (priv->completer);
g_free (priv->special_text);
-
- g_clear_object (&priv->last_location);
- g_clear_object (&priv->completion);
- g_clear_object (&priv->completions_store);
+ g_free (priv->current_directory);
G_OBJECT_CLASS (nautilus_location_entry_parent_class)->finalize (object);
}
static void
-destroy (GtkWidget *object)
+nautilus_location_entry_dispose (GObject *object)
{
NautilusLocationEntry *entry;
NautilusLocationEntryPrivate *priv;
@@ -602,10 +598,12 @@ destroy (GtkWidget *object)
priv->idle_id = 0;
}
- g_free (priv->current_directory);
- priv->current_directory = NULL;
+ g_clear_object (&priv->completer);
+ g_clear_object (&priv->last_location);
+ g_clear_object (&priv->completion);
+ g_clear_object (&priv->completions_store);
- GTK_WIDGET_CLASS (nautilus_location_entry_parent_class)->destroy (object);
+ G_OBJECT_CLASS (nautilus_location_entry_parent_class)->dispose (object);
}
static void
@@ -851,10 +849,10 @@ nautilus_location_entry_class_init (NautilusLocationEntryClass *class)
GtkBindingSet *binding_set;
widget_class = GTK_WIDGET_CLASS (class);
- widget_class->destroy = destroy;
widget_class->event = nautilus_location_entry_on_event;
gobject_class = G_OBJECT_CLASS (class);
+ gobject_class->dispose = nautilus_location_entry_dispose;
gobject_class->finalize = finalize;
entry_class = GTK_ENTRY_CLASS (class);
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index a841eed97..c0bfdaa79 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -5090,7 +5090,7 @@ nautilus_properties_window_present (GList *original_f
}
static void
-real_destroy (GtkWidget *object)
+real_dispose (GObject *object)
{
NautilusPropertiesWindow *self;
@@ -5133,7 +5133,7 @@ real_destroy (GtkWidget *object)
g_clear_handle_id (&self->update_directory_contents_timeout_id, g_source_remove);
g_clear_handle_id (&self->update_files_timeout_id, g_source_remove);
- GTK_WIDGET_CLASS (nautilus_properties_window_parent_class)->destroy (object);
+ G_OBJECT_CLASS (nautilus_properties_window_parent_class)->dispose (object);
}
static void
@@ -5375,8 +5375,8 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass)
widget_class = GTK_WIDGET_CLASS (klass);
oclass = G_OBJECT_CLASS (klass);
+ oclass->dispose = real_dispose;
oclass->finalize = real_finalize;
- widget_class->destroy = real_destroy;
binding_set = gtk_binding_set_by_class (klass);
g_signal_new ("close",
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index 54566b94d..945f3a833 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -2181,8 +2181,9 @@ destroy_slots_foreach (gpointer data,
close_slot (window, slot, TRUE);
}
+
static void
-nautilus_window_destroy (GtkWidget *object)
+nautilus_window_dispose (GObject *object)
{
NautilusWindow *window;
NautilusApplication *application;
@@ -2209,23 +2210,19 @@ nautilus_window_destroy (GtkWidget *object)
g_clear_weak_pointer (&window->active_slot);
- g_clear_signal_handler (&window->bookmarks_id, nautilus_application_get_bookmarks (application));
+ if (application != NULL)
+ {
+ g_clear_signal_handler (&window->bookmarks_id, nautilus_application_get_bookmarks (application));
+ }
g_clear_handle_id (&window->in_app_notification_undo_timeout_id, g_source_remove);
nautilus_window_unexport_handle (window);
- GTK_WIDGET_CLASS (nautilus_window_parent_class)->destroy (object);
-}
-
-static void
-nautilus_window_dispose (GObject *object)
-{
- NautilusWindow *window;
-
- window = NAUTILUS_WINDOW (object);
-
+ g_clear_object (&window->selected_file);
+ g_clear_object (&window->selected_volume);
g_clear_object (&window->notebook_multi_press_gesture);
+ g_clear_object (&window->pad_controller);
G_OBJECT_CLASS (nautilus_window_parent_class)->dispose (object);
}
@@ -2255,17 +2252,12 @@ nautilus_window_finalize (GObject *object)
window->notification_operation_timeout_id = 0;
}
- g_clear_object (&window->selected_file);
- g_clear_object (&window->selected_volume);
-
g_signal_handlers_disconnect_by_func (nautilus_file_undo_manager_get (),
G_CALLBACK (nautilus_window_on_undo_changed),
window);
g_queue_free_full (window->tab_data_queue, free_navigation_state);
- g_object_unref (window->pad_controller);
-
/* nautilus_window_close() should have run */
g_assert (window->slots == NULL);
@@ -2744,7 +2736,6 @@ nautilus_window_class_init (NautilusWindowClass *class)
oclass->finalize = nautilus_window_finalize;
oclass->constructed = nautilus_window_constructed;
- wclass->destroy = nautilus_window_destroy;
wclass->show = nautilus_window_show;
wclass->realize = nautilus_window_realize;
wclass->key_press_event = nautilus_window_key_press_event;