[gnome-control-center/printers-Clear-GSource-id-when-printer-removal-finishes: 2/2] printers: Clear GSource id when printer removal finishes



commit fb3e693ddfb00888a1bfc112a02c9f693ea6f89f
Author: Marek Kasik <mkasik redhat com>
Date:   Thu Jun 4 15:28:56 2020 +0200

    printers: Clear GSource id when printer removal finishes
    
    Remove GSource used for real deletion of a printer when
    the "Undo" notification was dismissed.
    Also set the timout id of the notitification to 0 when triggered.
    Replace cancel_notification_timeout() with one line.
    
    The issue fixed here could be reproduced this way:
    1) Open Printers panel
    2) Remove a printer
    3) Press back button to go to overview
    4) Wait 10 seconds
    5) Return to the printers panel
    6) Close gnome-control-center
    
    Result:
    Critical warning on removal of non-existing GSource

 panels/printers/cc-printers-panel.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)
---
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
index 68c5b194d..242c2479a 100644
--- a/panels/printers/cc-printers-panel.c
+++ b/panels/printers/cc-printers-panel.c
@@ -613,17 +613,6 @@ free_dests (CcPrintersPanel *self)
   self->num_dests = 0;
 }
 
-static void
-cancel_notification_timeout (CcPrintersPanel *self)
-{
-  if (self->remove_printer_timeout_id == 0)
-    return;
-
-  g_source_remove (self->remove_printer_timeout_id);
-
-  self->remove_printer_timeout_id = 0;
-}
-
 static void
 on_printer_deletion_undone (CcPrintersPanel *self)
 {
@@ -632,12 +621,14 @@ on_printer_deletion_undone (CcPrintersPanel *self)
   g_clear_pointer (&self->deleted_printer_name, g_free);
   actualize_printers_list (self);
 
-  cancel_notification_timeout (self);
+  g_clear_handle_id (&self->remove_printer_timeout_id, g_source_remove);
 }
 
 static void
 on_notification_dismissed (CcPrintersPanel *self)
 {
+  g_clear_handle_id (&self->remove_printer_timeout_id, g_source_remove);
+
   if (self->deleted_printer_name != NULL)
     {
       PpPrinter *printer;
@@ -655,9 +646,11 @@ on_notification_dismissed (CcPrintersPanel *self)
 }
 
 static gboolean
-on_remove_printer_timeout (gpointer user_data)
+on_remove_printer_timeout (CcPrintersPanel *self)
 {
-  on_notification_dismissed (user_data);
+  self->remove_printer_timeout_id = 0;
+
+  on_notification_dismissed (self);
 
   return G_SOURCE_REMOVE;
 }
@@ -689,7 +682,7 @@ on_printer_deleted (CcPrintersPanel *self,
 
   gtk_revealer_set_reveal_child (self->notification, TRUE);
 
-  self->remove_printer_timeout_id = g_timeout_add_seconds (10, on_remove_printer_timeout, self);
+  self->remove_printer_timeout_id = g_timeout_add_seconds (10, G_SOURCE_FUNC (on_remove_printer_timeout), 
self);
 }
 
 static void


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