[gnome-control-center/2023-printer-panel-doesn-t-return-to-empty-state-after-deleting-last-printer] printers: Show empty-state after removal of the last printer



commit 5ceabcb5c7e79601b4ae121a6a36dcf96e03e2a5
Author: Marek Kasik <mkasik redhat com>
Date:   Thu Aug 18 16:57:24 2022 +0200

    printers: Show empty-state after removal of the last printer
    
    Check whether the currently removed printer was last. Also
    check whether there are other printer being removed by CUPS
    right now (their amount is still part of self->num_dests).
    
    Do this check also in actualize_printers_list_cb() to catch
    corner cases from timing point of view. This will handle them
    with some delay if they show up.
    
    When undone, just check whether the number of printers is higher
    than 0 and show the printers-list page.
    
    Fixes #2023

 panels/printers/cc-printers-panel.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
index f102c0592..34774a7bf 100644
--- a/panels/printers/cc-printers-panel.c
+++ b/panels/printers/cc-printers-panel.c
@@ -127,6 +127,9 @@ static void actualize_printers_list (CcPrintersPanel *self);
 static void update_sensitivity (gpointer user_data);
 static void detach_from_cups_notifier (gpointer data);
 static void free_dests (CcPrintersPanel *self);
+static void set_current_page (GObject      *source_object,
+                              GAsyncResult *result,
+                              gpointer      user_data);
 
 static void
 execute_action (CcPrintersPanel *self,
@@ -619,6 +622,12 @@ on_printer_deletion_undone (CcPrintersPanel *self)
   gtk_list_box_invalidate_filter (GTK_LIST_BOX (widget));
 
   g_clear_handle_id (&self->remove_printer_timeout_id, g_source_remove);
+
+  if (self->num_dests > 0)
+    {
+      widget = (GtkWidget *) gtk_builder_get_object (self->builder, "main-vbox");
+      gtk_stack_set_visible_child_name (GTK_STACK (widget), "printers-list");
+    }
 }
 
 static void
@@ -687,6 +696,9 @@ on_printer_deleted (CcPrintersPanel *self,
   gtk_revealer_set_reveal_child (self->notification, TRUE);
 
   self->remove_printer_timeout_id = g_timeout_add_seconds (10, G_SOURCE_FUNC (on_remove_printer_timeout), 
self);
+
+  if (self->num_dests == 1 + g_list_length (self->deleted_printers))
+    pp_cups_connection_test_async (self->cups, NULL, set_current_page, self);
 }
 
 static void
@@ -817,7 +829,9 @@ actualize_printers_list_cb (GObject      *source_object,
   g_free (cups_dests);
 
   widget = (GtkWidget*) gtk_builder_get_object (self->builder, "main-vbox");
-  if (self->num_dests == 0 && !self->new_printer_name)
+  if ((self->num_dests == 0 && self->new_printer_name == NULL) ||
+      (self->num_dests == 1 + g_list_length (self->deleted_printers) &&
+       self->deleted_printer_name != NULL))
     pp_cups_connection_test_async (PP_CUPS (source_object), NULL, set_current_page, self);
   else
     gtk_stack_set_visible_child_name (GTK_STACK (widget), "printers-list");


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