From c0063f29c89a6e2f117dfa64517729ec8921dc4b Mon Sep 17 00:00:00 2001 From: Hari Rana Date: Mon, 23 Mar 2026 16:30:40 -0400 Subject: [PATCH] calendar-management/calendars-page: Delete calendar during unmapping The previous commit reintroduced https://gitlab.gnome.org/GNOME/gnome-calendar/-/issues/1270 In order to solve this without destroying the dialog, the calendar is forcefully deleted when unmapping. Part-of: --- .../calendar-management/gcal-calendars-page.c | 60 +++++++++++++------ 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/src/gui/calendar-management/gcal-calendars-page.c b/src/gui/calendar-management/gcal-calendars-page.c index 0bf2acd7..31c04163 100644 --- a/src/gui/calendar-management/gcal-calendars-page.c +++ b/src/gui/calendar-management/gcal-calendars-page.c @@ -185,6 +185,29 @@ delete_calendar (GcalCalendarsPage *self, } } +static void +clear_toast_and_delete_calendar (GcalCalendarsPage *self, + AdwToast *toast) +{ + GcalCalendar *calendar; + + GCAL_ENTRY; + + calendar = g_object_get_data (G_OBJECT (toast), "calendar"); + + if (!calendar) + { + g_assert (self->toast == NULL); + GCAL_RETURN (); + } + + delete_calendar (self, calendar); + + g_clear_object (&self->toast); + + GCAL_EXIT; +} + /* * Callbacks @@ -291,23 +314,7 @@ static void on_toast_dismissed_cb (AdwToast *toast, GcalCalendarsPage *self) { - GcalCalendar *calendar; - - GCAL_ENTRY; - - calendar = g_object_get_data (G_OBJECT (toast), "calendar"); - - if (!calendar) - { - g_assert (self->toast == NULL); - GCAL_RETURN (); - } - - delete_calendar (self, calendar); - - g_clear_object (&self->toast); - - GCAL_EXIT; + clear_toast_and_delete_calendar (self, toast); } @@ -363,6 +370,23 @@ gcal_calendar_management_page_iface_init (GcalCalendarManagementPageInterface *i iface->activate = gcal_calendars_page_activate; } + +/* + * GtkWidget overrides + */ + +static void +gcal_calendars_page_unmap (GtkWidget *widget) +{ + GcalCalendarsPage *self = GCAL_CALENDARS_PAGE (widget); + + if (self->toast) + clear_toast_and_delete_calendar (self, self->toast); + + GTK_WIDGET_CLASS (gcal_calendars_page_parent_class)->unmap (widget); +} + + /* * GObject overrides */ @@ -385,6 +409,8 @@ gcal_calendars_page_class_init (GcalCalendarsPageClass *klass) object_class->finalize = gcal_calendars_page_finalize; + widget_class->unmap = gcal_calendars_page_unmap; + gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/ui/gui/calendar-management/gcal-calendars-page.ui"); gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, listbox);