Blame SOURCES/printers-Update-entries.patch

144ef4
--- gnome-control-center-3.28.2/panels/printers/cc-printers-panel.c
144ef4
+++ gnome-control-center-3.28.2/panels/printers/cc-printers-panel.c
144ef4
@@ -105,6 +105,8 @@ struct _CcPrintersPanelPrivate
144ef4
   gchar    *renamed_printer_name;
144ef4
   gchar    *old_printer_name;
144ef4
   gchar    *deleted_printer_name;
144ef4
+  GList    *deleted_printers;
144ef4
+  GObject  *reference;
144ef4
 
144ef4
   GHashTable *printer_entries;
144ef4
   gboolean    entries_filled;
144ef4
@@ -267,18 +269,40 @@ printer_removed_cb (GObject      *source
144ef4
                     GAsyncResult *result,
144ef4
                     gpointer      user_data)
144ef4
 {
144ef4
-  GError *error = NULL;
144ef4
+  PpPrinter *printer = PP_PRINTER (source_object);
144ef4
+  g_autoptr(GError) error = NULL;
144ef4
+  g_autofree gchar *printer_name = NULL;
144ef4
 
144ef4
-  pp_printer_delete_finish (PP_PRINTER (source_object), result, &error);
144ef4
-  g_object_unref (source_object);
144ef4
+  g_object_get (printer, "printer-name", &printer_name, NULL);
144ef4
+  pp_printer_delete_finish (printer, result, &error);
144ef4
 
144ef4
-  if (error != NULL)
144ef4
+  if (user_data != NULL)
144ef4
     {
144ef4
-      g_warning ("Printer could not be deleted: %s", error->message);
144ef4
-      g_error_free (error);
144ef4
+      g_autoptr(GObject) reference = G_OBJECT (user_data);
144ef4
+
144ef4
+      if (g_object_get_data (reference, "self") != NULL)
144ef4
+        {
144ef4
+          CcPrintersPanel *self = CC_PRINTERS_PANEL (g_object_get_data (reference, "self"));
144ef4
+          CcPrintersPanelPrivate *priv = self->priv;
144ef4
+          GList           *iter;
144ef4
+
144ef4
+          for (iter = priv->deleted_printers; iter != NULL; iter = iter->next)
144ef4
+            {
144ef4
+              if (g_strcmp0 (iter->data, printer_name) == 0)
144ef4
+                {
144ef4
+                  g_free (iter->data);
144ef4
+                  priv->deleted_printers = g_list_delete_link (priv->deleted_printers, iter);
144ef4
+                  break;
144ef4
+                }
144ef4
+            }
144ef4
+        }
144ef4
     }
144ef4
+
144ef4
+  if (error != NULL)
144ef4
+    g_warning ("Printer could not be deleted: %s", error->message);
144ef4
 }
144ef4
 
144ef4
+
144ef4
 static void
144ef4
 cc_printers_panel_dispose (GObject *object)
144ef4
 {
144ef4
@@ -368,6 +392,12 @@ cc_printers_panel_dispose (GObject *obje
144ef4
 
144ef4
   g_clear_pointer (&priv->printer_entries, g_hash_table_destroy);
144ef4
 
144ef4
+  g_list_free_full (priv->deleted_printers, g_free);
144ef4
+  priv->deleted_printers = NULL;
144ef4
+  if (priv->reference != NULL)
144ef4
+    g_object_set_data (priv->reference, "self", NULL);
144ef4
+  g_clear_object (&priv->reference);
144ef4
+
144ef4
   G_OBJECT_CLASS (cc_printers_panel_parent_class)->dispose (object);
144ef4
 }
144ef4
 
788f1e
@@ -740,13 +770,16 @@ on_printer_deletion_undone (GtkButton *b
788f1e
 {
788f1e
   CcPrintersPanelPrivate *priv;
788f1e
   CcPrintersPanel        *self = (CcPrintersPanel*) user_data;
788f1e
+  GtkWidget              *widget;
788f1e
 
788f1e
   priv = PRINTERS_PANEL_PRIVATE (self);
788f1e
 
788f1e
   gtk_revealer_set_reveal_child (priv->notification, FALSE);
788f1e
 
788f1e
   g_clear_pointer (&priv->deleted_printer_name, g_free);
788f1e
-  actualize_printers_list (self);
788f1e
+
788f1e
+  widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "content");
788f1e
+  gtk_list_box_invalidate_filter (GTK_LIST_BOX (widget));
788f1e
 
788f1e
   cancel_notification_timeout (self);
788f1e
 }
788f1e
@@ -768,9 +801,11 @@ on_notification_dismissed (GtkButton *bu
788f1e
       pp_printer_delete_async (printer,
788f1e
                                NULL,
788f1e
                                printer_removed_cb,
788f1e
-                               NULL);
788f1e
+                               g_object_ref (priv->reference));
788f1e
 
788f1e
-      g_clear_pointer (&priv->deleted_printer_name, g_free);
788f1e
+      priv->deleted_printers = g_list_prepend (priv->deleted_printers, priv->deleted_printer_name);
788f1e
+      priv->deleted_printer_name = NULL;
788f1e
+      g_object_unref (printer);
788f1e
     }
788f1e
 
788f1e
   gtk_revealer_set_reveal_child (priv->notification, FALSE);
788f1e
@@ -793,8 +828,7 @@ on_printer_deleted (PpPrinterEntry *prin
144ef4
   GtkLabel               *label;
144ef4
   gchar                  *notification_message;
144ef4
   gchar                  *printer_name;
144ef4
-
144ef4
-  gtk_widget_hide (GTK_WIDGET (printer_entry));
144ef4
+  GtkWidget              *widget;
144ef4
 
144ef4
   priv = PRINTERS_PANEL_PRIVATE (self);
144ef4
 
788f1e
@@ -816,6 +850,9 @@ on_printer_deleted (PpPrinterEntry *prin
144ef4
   priv->deleted_printer_name = g_strdup (printer_name);
144ef4
   g_free (printer_name);
144ef4
 
144ef4
+  widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "content");
144ef4
+  gtk_list_box_invalidate_filter (GTK_LIST_BOX (widget));
144ef4
+
144ef4
   gtk_revealer_set_reveal_child (priv->notification, TRUE);
144ef4
 
144ef4
   priv->remove_printer_timeout_id = g_timeout_add_seconds (10, on_remove_printer_timeout, self);
788f1e
@@ -910,6 +947,36 @@ set_current_page (GObject      *source_o
144ef4
 }
144ef4
 
144ef4
 static void
144ef4
+destroy_nonexisting_entries (PpPrinterEntry *entry,
144ef4
+                             gpointer        user_data)
144ef4
+{
144ef4
+  CcPrintersPanelPrivate *priv;
144ef4
+  CcPrintersPanel        *self = (CcPrintersPanel *) user_data;
144ef4
+  g_autofree gchar       *printer_name = NULL;
144ef4
+  gboolean                exists = FALSE;
144ef4
+  gint                    i;
144ef4
+
144ef4
+  priv = PRINTERS_PANEL_PRIVATE (self);
144ef4
+
144ef4
+  g_object_get (G_OBJECT (entry), "printer-name", &printer_name, NULL);
144ef4
+
144ef4
+  for (i = 0; i < priv->num_dests; i++)
144ef4
+    {
144ef4
+      if (g_strcmp0 (priv->dests[i].name, printer_name) == 0)
144ef4
+        {
144ef4
+          exists = TRUE;
144ef4
+          break;
144ef4
+        }
144ef4
+    }
144ef4
+
144ef4
+  if (!exists)
144ef4
+    {
144ef4
+      gtk_widget_destroy (GTK_WIDGET (entry));
144ef4
+      g_hash_table_remove (priv->printer_entries, printer_name);
144ef4
+    }
144ef4
+}
144ef4
+
144ef4
+static void
144ef4
 actualize_printers_list_cb (GObject      *source_object,
144ef4
                             GAsyncResult *result,
144ef4
                             gpointer      user_data)
788f1e
@@ -920,6 +987,7 @@ actualize_printers_list_cb (GObject
144ef4
   PpCups                 *cups = PP_CUPS (source_object);
144ef4
   PpCupsDests            *cups_dests;
144ef4
   gboolean                new_printer_available = FALSE;
144ef4
+  gpointer                item;
144ef4
   GError                 *error = NULL;
144ef4
   int                     i;
144ef4
 
788f1e
@@ -950,7 +1018,7 @@ actualize_printers_list_cb (GObject
144ef4
     gtk_stack_set_visible_child_name (GTK_STACK (widget), "printers-list");
144ef4
 
144ef4
   widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "content");
144ef4
-  gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_destroy, NULL);
144ef4
+  gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) destroy_nonexisting_entries, self);
144ef4
 
144ef4
   for (i = 0; i < priv->num_dests; i++)
144ef4
     {
788f1e
@@ -961,13 +1029,14 @@ actualize_printers_list_cb (GObject
144ef4
 
144ef4
   for (i = 0; i < priv->num_dests; i++)
144ef4
     {
144ef4
-      if (g_strcmp0 (priv->dests[i].name, priv->deleted_printer_name) == 0)
144ef4
-          continue;
144ef4
-
144ef4
       if (new_printer_available && g_strcmp0 (priv->dests[i].name, priv->old_printer_name) == 0)
144ef4
           continue;
144ef4
 
144ef4
-      add_printer_entry (self, priv->dests[i]);
144ef4
+      item = g_hash_table_lookup (priv->printer_entries, priv->dests[i].name);
144ef4
+      if (item != NULL)
144ef4
+        pp_printer_entry_update (PP_PRINTER_ENTRY (item), priv->dests[i], priv->is_authorized);
144ef4
+      else
144ef4
+        add_printer_entry (self, priv->dests[i]);
144ef4
     }
144ef4
 
144ef4
   if (!priv->entries_filled)
788f1e
@@ -983,6 +1052,30 @@ actualize_printers_list_cb (GObject
144ef4
     }
144ef4
 
144ef4
   update_sensitivity (user_data);
144ef4
+
144ef4
+  if (priv->new_printer_name != NULL)
144ef4
+    {
144ef4
+      GtkScrolledWindow      *scrolled_window;
144ef4
+      GtkAllocation           allocation;
144ef4
+      GtkAdjustment          *adjustment;
144ef4
+      GtkWidget              *printer_entry;
144ef4
+
144ef4
+      /* Scroll the view to show the newly added printer-entry. */
144ef4
+      scrolled_window = GTK_SCROLLED_WINDOW (gtk_builder_get_object (priv->builder,
144ef4
+                                                                     "scrolled-window"));
144ef4
+      adjustment = gtk_scrolled_window_get_vadjustment (scrolled_window);
144ef4
+
144ef4
+      printer_entry = GTK_WIDGET (g_hash_table_lookup (priv->printer_entries,
144ef4
+                                                       priv->new_printer_name));
144ef4
+      if (printer_entry != NULL)
144ef4
+        {
144ef4
+          gtk_widget_get_allocation (printer_entry, &allocation);
144ef4
+          g_clear_pointer (&priv->new_printer_name, g_free);
144ef4
+
144ef4
+          gtk_adjustment_set_value (adjustment,
144ef4
+                                    allocation.y - gtk_widget_get_margin_top (printer_entry));
144ef4
+        }
144ef4
+    }
144ef4
 }
144ef4
 
144ef4
 static void
788f1e
@@ -1028,10 +1121,6 @@ new_printer_dialog_response_cb (PpNewPri
144ef4
 {
144ef4
   CcPrintersPanelPrivate *priv;
144ef4
   CcPrintersPanel        *self = (CcPrintersPanel*) user_data;
144ef4
-  GtkScrolledWindow      *scrolled_window;
144ef4
-  GtkAllocation           allocation;
144ef4
-  GtkAdjustment          *adjustment;
144ef4
-  GtkWidget              *printer_entry;
144ef4
 
144ef4
   priv = PRINTERS_PANEL_PRIVATE (self);
144ef4
 
788f1e
@@ -1059,22 +1148,6 @@ new_printer_dialog_response_cb (PpNewPri
144ef4
     }
144ef4
 
144ef4
   actualize_printers_list (self);
144ef4
-
144ef4
-  if (priv->new_printer_name == NULL)
144ef4
-    return;
144ef4
-
144ef4
-  /* Scroll the view to show the newly added printer-entry. */
144ef4
-  scrolled_window = GTK_SCROLLED_WINDOW (gtk_builder_get_object (priv->builder,
144ef4
-                                                                 "scrolled-window"));
144ef4
-  adjustment = gtk_scrolled_window_get_vadjustment (scrolled_window);
144ef4
-
144ef4
-  printer_entry = GTK_WIDGET (g_hash_table_lookup (priv->printer_entries,
144ef4
-                                                   priv->new_printer_name));
144ef4
-  gtk_widget_get_allocation (printer_entry, &allocation);
144ef4
-  g_clear_pointer (&priv->new_printer_name, g_free);
144ef4
-
144ef4
-  gtk_adjustment_set_value (adjustment,
144ef4
-                            allocation.y - gtk_widget_get_margin_top (printer_entry));
144ef4
 }
144ef4
 
144ef4
 static void
788f1e
@@ -1288,11 +1361,17 @@ filter_function (GtkListBoxRow *row,
144ef4
   CcPrintersPanel        *self = (CcPrintersPanel*) user_data;
144ef4
   GtkWidget              *search_entry;
144ef4
   gboolean                retval;
144ef4
-  gchar                  *search;
144ef4
-  gchar                  *name;
144ef4
-  gchar                  *location;
144ef4
-  gchar                  *printer_name;
144ef4
-  gchar                  *printer_location;
144ef4
+  g_autofree gchar       *search = NULL;
144ef4
+  g_autofree gchar       *name = NULL;
144ef4
+  g_autofree gchar       *location = NULL;
144ef4
+  g_autofree gchar       *printer_name = NULL;
144ef4
+  g_autofree gchar       *printer_location = NULL;
144ef4
+  GList                  *iter;
144ef4
+
144ef4
+  g_object_get (G_OBJECT (row),
144ef4
+                "printer-name", &printer_name,
144ef4
+                "printer-location", &printer_location,
144ef4
+                NULL);
144ef4
 
144ef4
   priv = PRINTERS_PANEL_PRIVATE (self);
144ef4
 
788f1e
@@ -1300,31 +1379,72 @@ filter_function (GtkListBoxRow *row,
144ef4
     gtk_builder_get_object (priv->builder, "search-entry");
144ef4
 
144ef4
   if (gtk_entry_get_text_length (GTK_ENTRY (search_entry)) == 0)
144ef4
-    return TRUE;
144ef4
+    {
144ef4
+      retval = TRUE;
144ef4
+    }
144ef4
+  else
144ef4
+    {
144ef4
+      name = cc_util_normalize_casefold_and_unaccent (printer_name);
144ef4
+      location = cc_util_normalize_casefold_and_unaccent (printer_location);
144ef4
 
144ef4
-  g_object_get (G_OBJECT (row),
144ef4
-                "printer-name", &printer_name,
144ef4
-                "printer-location", &printer_location,
144ef4
-                NULL);
144ef4
+      search = cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (search_entry)));
144ef4
 
144ef4
-  name = cc_util_normalize_casefold_and_unaccent (printer_name);
144ef4
-  location = cc_util_normalize_casefold_and_unaccent (printer_location);
144ef4
+      retval = strstr (name, search) != NULL;
144ef4
+      if (location != NULL)
144ef4
+          retval = retval || (strstr (location, search) != NULL);
144ef4
+    }
144ef4
 
144ef4
-  g_free (printer_name);
144ef4
-  g_free (printer_location);
144ef4
+  if (priv->deleted_printer_name != NULL &&
144ef4
+      g_strcmp0 (priv->deleted_printer_name, printer_name) == 0)
144ef4
+    {
144ef4
+      retval = FALSE;
144ef4
+    }
144ef4
 
144ef4
-  search = cc_util_normalize_casefold_and_unaccent (gtk_entry_get_text (GTK_ENTRY (search_entry)));
144ef4
+  if (priv->deleted_printers != NULL)
144ef4
+    {
144ef4
+      for (iter = priv->deleted_printers; iter != NULL; iter = iter->next)
144ef4
+        {
144ef4
+          if (g_strcmp0 (iter->data, printer_name) == 0)
144ef4
+            {
144ef4
+              retval = FALSE;
144ef4
+              break;
144ef4
+            }
144ef4
+        }
144ef4
+    }
144ef4
 
144ef4
+  return retval;
144ef4
+}
144ef4
 
144ef4
-  retval = strstr (name, search) != NULL;
144ef4
-  if (location != NULL)
144ef4
-      retval = retval || (strstr (location, search) != NULL);
144ef4
+static gint
144ef4
+sort_function (GtkListBoxRow *row1,
144ef4
+               GtkListBoxRow *row2,
144ef4
+               gpointer       user_data)
144ef4
+{
144ef4
+  g_autofree gchar *printer_name1 = NULL;
144ef4
+  g_autofree gchar *printer_name2 = NULL;
144ef4
 
144ef4
-  g_free (search);
144ef4
-  g_free (name);
144ef4
-  g_free (location);
144ef4
+  g_object_get (G_OBJECT (row1),
144ef4
+                "printer-name", &printer_name1,
144ef4
+                NULL);
144ef4
 
144ef4
-  return retval;
144ef4
+  g_object_get (G_OBJECT (row2),
144ef4
+                "printer-name", &printer_name2,
144ef4
+                NULL);
144ef4
+
144ef4
+  if (printer_name1 != NULL)
144ef4
+    {
144ef4
+      if (printer_name2 != NULL)
144ef4
+        return g_ascii_strcasecmp (printer_name1, printer_name2);
144ef4
+      else
144ef4
+        return 1;
144ef4
+    }
144ef4
+  else
144ef4
+    {
144ef4
+      if (printer_name2 != NULL)
144ef4
+        return -1;
144ef4
+      else
144ef4
+        return 0;
144ef4
+    }
144ef4
 }
144ef4
 
144ef4
 static void
788f1e
@@ -1364,6 +1484,8 @@ cc_printers_panel_init (CcPrintersPanel
144ef4
   priv->renamed_printer_name = NULL;
144ef4
   priv->old_printer_name = NULL;
144ef4
   priv->deleted_printer_name = NULL;
144ef4
+  priv->deleted_printers = NULL;
144ef4
+  priv->reference = g_object_new (G_TYPE_OBJECT, NULL);
144ef4
 
144ef4
   priv->permission = NULL;
144ef4
   priv->lockdown_settings = NULL;
788f1e
@@ -1380,6 +1502,8 @@ cc_printers_panel_init (CcPrintersPanel
144ef4
   priv->actualize_printers_list_cancellable = g_cancellable_new ();
144ef4
   priv->cups_status_check_cancellable = g_cancellable_new ();
144ef4
 
788f1e
+  g_object_set_data_full (priv->reference, "self", self, NULL);
144ef4
+
144ef4
   builder_result = gtk_builder_add_objects_from_resource (priv->builder,
144ef4
                                                           "/org/gnome/control-center/printers/printers.ui",
144ef4
                                                           objects, &error);
788f1e
@@ -1430,6 +1554,10 @@ cc_printers_panel_init (CcPrintersPanel
144ef4
                             "search-changed",
144ef4
                             G_CALLBACK (gtk_list_box_invalidate_filter),
144ef4
                             widget);
144ef4
+  gtk_list_box_set_sort_func (GTK_LIST_BOX (widget),
144ef4
+                              sort_function,
144ef4
+                              NULL,
144ef4
+                              NULL);
144ef4
 
144ef4
   priv->lockdown_settings = g_settings_new ("org.gnome.desktop.lockdown");
144ef4
   if (priv->lockdown_settings)
144ef4
--- gnome-control-center-3.28.2/panels/printers/pp-printer-entry.c
144ef4
+++ gnome-control-center-3.28.2/panels/printers/pp-printer-entry.c
144ef4
@@ -45,7 +45,6 @@ struct _PpPrinterEntry
144ef4
 {
144ef4
   GtkListBoxRow parent;
144ef4
 
144ef4
-  gchar    *printer_uri;
144ef4
   gchar    *printer_name;
144ef4
   gchar    *ppd_file_name;
144ef4
   int       num_jobs;
788f1e
@@ -156,10 +155,27 @@ pp_printer_entry_set_property (GObject
788f1e
     }
788f1e
 }
788f1e
 
788f1e
+static InkLevelData *
788f1e
+ink_level_data_new (void)
788f1e
+{
788f1e
+  return g_slice_new0 (InkLevelData);
788f1e
+}
788f1e
+
788f1e
+static void
788f1e
+ink_level_data_free (InkLevelData *data)
788f1e
+{
788f1e
+  g_clear_pointer (&data->marker_names, g_free);
788f1e
+  g_clear_pointer (&data->marker_levels, g_free);
788f1e
+  g_clear_pointer (&data->marker_colors, g_free);
788f1e
+  g_clear_pointer (&data->marker_types, g_free);
788f1e
+  g_slice_free (InkLevelData, data);
788f1e
+}
788f1e
+
788f1e
 static void
788f1e
 pp_printer_entry_init (PpPrinterEntry *self)
788f1e
 {
788f1e
   gtk_widget_init_template (GTK_WIDGET (self));
788f1e
+  self->inklevel = ink_level_data_new ();
788f1e
 }
788f1e
 
788f1e
 typedef struct {
788f1e
@@ -260,9 +276,8 @@ tone_down_color (GdkRGBA *color,
788f1e
 }
788f1e
 
788f1e
 static gboolean
788f1e
-supply_levels_draw_cb (GtkWidget      *widget,
788f1e
-                       cairo_t        *cr,
788f1e
-                       PpPrinterEntry *self)
788f1e
+supply_levels_draw_cb (PpPrinterEntry *self,
788f1e
+                       cairo_t        *cr)
788f1e
 {
788f1e
   GtkStyleContext        *context;
788f1e
   gboolean                is_empty = TRUE;
788f1e
@@ -271,10 +286,10 @@ supply_levels_draw_cb (GtkWidget      *w
788f1e
   gint                    height;
788f1e
   int                     i;
788f1e
 
788f1e
-  context = gtk_widget_get_style_context (widget);
788f1e
+  context = gtk_widget_get_style_context (GTK_WIDGET (self->supply_drawing_area));
788f1e
 
788f1e
-  width = gtk_widget_get_allocated_width (widget);
788f1e
-  height = gtk_widget_get_allocated_height (widget);
788f1e
+  width = gtk_widget_get_allocated_width (GTK_WIDGET (self->supply_drawing_area));
788f1e
+  height = gtk_widget_get_allocated_height (GTK_WIDGET (self->supply_drawing_area));
788f1e
 
788f1e
   gtk_render_background (context, cr, 0, 0, width, height);
788f1e
 
788f1e
@@ -376,13 +391,13 @@ supply_levels_draw_cb (GtkWidget      *w
788f1e
 
788f1e
     if (tooltip_text)
788f1e
       {
788f1e
-        gtk_widget_set_tooltip_text (widget, tooltip_text);
788f1e
+        gtk_widget_set_tooltip_text (GTK_WIDGET (self->supply_drawing_area), tooltip_text);
788f1e
         g_free (tooltip_text);
788f1e
       }
788f1e
     else
788f1e
       {
788f1e
-        gtk_widget_set_tooltip_text (widget, NULL);
788f1e
-        gtk_widget_set_has_tooltip (widget, FALSE);
788f1e
+        gtk_widget_set_tooltip_text (GTK_WIDGET (self->supply_drawing_area), NULL);
788f1e
+        gtk_widget_set_has_tooltip (GTK_WIDGET (self->supply_drawing_area), FALSE);
788f1e
       }
788f1e
     }
788f1e
 
788f1e
@@ -727,11 +742,34 @@ pp_printer_entry_new (cups_dest_t  print
144ef4
                       gboolean     is_authorized)
144ef4
 {
144ef4
   PpPrinterEntry *self;
144ef4
+
144ef4
+  self = g_object_new (PP_PRINTER_ENTRY_TYPE, "printer-name", printer.name, NULL);
144ef4
+
144ef4
+  self->clean_command = pp_maintenance_command_new (self->printer_name,
144ef4
+                                                    "Clean",
144ef4
+                                                    "all",
144ef4
+                                                    /* Translators: Name of job which makes printer to clean its heads */
144ef4
+                                                    _("Clean print heads"));
144ef4
+  check_clean_heads_maintenance_command (self);
144ef4
+
144ef4
+  g_signal_connect_object (self->supply_drawing_area, "draw", G_CALLBACK (supply_levels_draw_cb), self, G_CONNECT_SWAPPED);
144ef4
+
144ef4
+  pp_printer_entry_update (self, printer, is_authorized);
144ef4
+
144ef4
+  return self;
144ef4
+}
144ef4
+
144ef4
+void
144ef4
+pp_printer_entry_update (PpPrinterEntry *self,
144ef4
+                         cups_dest_t     printer,
144ef4
+                         gboolean        is_authorized)
144ef4
+{
144ef4
   cups_ptype_t    printer_type = 0;
144ef4
-  gboolean        is_accepting_jobs;
144ef4
+  gboolean        is_accepting_jobs = TRUE;
144ef4
   gboolean        ink_supply_is_empty;
144ef4
   gchar          *instance;
144ef4
   gchar          *printer_uri = NULL;
144ef4
+  const gchar    *device_uri = NULL;
144ef4
   gchar          *location = NULL;
144ef4
   gchar          *printer_icon_name = NULL;
144ef4
   gchar          *default_icon_name = NULL;
788f1e
@@ -798,10 +836,6 @@ pp_printer_entry_new (cups_dest_t  print
144ef4
       N_("The optical photo conductor is no longer functioning")
144ef4
     };
144ef4
 
144ef4
-  self = g_object_new (PP_PRINTER_ENTRY_TYPE, "printer-name", printer.name, NULL);
144ef4
-
788f1e
-  self->inklevel = g_slice_new0 (InkLevelData);
788f1e
-
144ef4
   if (printer.instance)
788f1e
     {
788f1e
       instance = g_strdup_printf ("%s / %s", printer.name, printer.instance);
788f1e
@@ -816,7 +850,7 @@ pp_printer_entry_new (cups_dest_t  print
144ef4
   for (i = 0; i < printer.num_options; i++)
144ef4
     {
144ef4
       if (g_strcmp0 (printer.options[i].name, "device-uri") == 0)
144ef4
-        self->printer_uri = printer.options[i].value;
144ef4
+        device_uri = printer.options[i].value;
144ef4
       else if (g_strcmp0 (printer.options[i].name, "printer-uri-supported") == 0)
144ef4
         printer_uri = printer.options[i].value;
144ef4
       else if (g_strcmp0 (printer.options[i].name, "printer-type") == 0)
788f1e
@@ -826,13 +860,25 @@ pp_printer_entry_new (cups_dest_t  print
144ef4
       else if (g_strcmp0 (printer.options[i].name, "printer-state-reasons") == 0)
144ef4
         reason = printer.options[i].value;
144ef4
       else if (g_strcmp0 (printer.options[i].name, "marker-names") == 0)
144ef4
-        self->inklevel->marker_names = g_strcompress (printer.options[i].value);
144ef4
+        {
144ef4
+          g_free (self->inklevel->marker_names);
06e1d8
+          self->inklevel->marker_names = g_strcompress (printer.options[i].value);
144ef4
+        }
144ef4
       else if (g_strcmp0 (printer.options[i].name, "marker-levels") == 0)
144ef4
-        self->inklevel->marker_levels = g_strdup (printer.options[i].value);
144ef4
+        {
144ef4
+          g_free (self->inklevel->marker_levels);
144ef4
+          self->inklevel->marker_levels = g_strdup (printer.options[i].value);
144ef4
+        }
144ef4
       else if (g_strcmp0 (printer.options[i].name, "marker-colors") == 0)
144ef4
-        self->inklevel->marker_colors = g_strdup (printer.options[i].value);
144ef4
+        {
144ef4
+          g_free (self->inklevel->marker_colors);
144ef4
+          self->inklevel->marker_colors = g_strdup (printer.options[i].value);
144ef4
+        }
144ef4
       else if (g_strcmp0 (printer.options[i].name, "marker-types") == 0)
144ef4
-        self->inklevel->marker_types = g_strdup (printer.options[i].value);
144ef4
+        {
144ef4
+          g_free (self->inklevel->marker_types);
144ef4
+          self->inklevel->marker_types = g_strdup (printer.options[i].value);
144ef4
+        }
144ef4
       else if (g_strcmp0 (printer.options[i].name, "printer-make-and-model") == 0)
144ef4
         printer_make_and_model = printer.options[i].value;
144ef4
       else if (g_strcmp0 (printer.options[i].name, "printer-state") == 0)
788f1e
@@ -896,6 +942,11 @@ pp_printer_entry_new (cups_dest_t  print
144ef4
       gtk_label_set_label (self->error_status, status);
144ef4
       gtk_widget_set_visible (GTK_WIDGET (self->printer_error), TRUE);
144ef4
     }
144ef4
+  else
144ef4
+    {
144ef4
+      gtk_label_set_label (self->error_status, "");
144ef4
+      gtk_widget_set_visible (GTK_WIDGET (self->printer_error), FALSE);
144ef4
+    }
144ef4
 
144ef4
   switch (self->printer_state)
144ef4
     {
788f1e
@@ -921,7 +972,7 @@ pp_printer_entry_new (cups_dest_t  print
144ef4
         break;
144ef4
     }
144ef4
 
144ef4
-  if (printer_is_local (printer_type, self->printer_uri))
144ef4
+  if (printer_is_local (printer_type, device_uri))
144ef4
     printer_icon_name = g_strdup ("printer");
144ef4
   else
144ef4
     printer_icon_name = g_strdup ("printer-network");
788f1e
@@ -931,14 +982,8 @@ pp_printer_entry_new (cups_dest_t  print
144ef4
   self->is_accepting_jobs = is_accepting_jobs;
144ef4
   self->is_authorized = is_authorized;
144ef4
 
144ef4
-  self->printer_hostname = printer_get_hostname (printer_type, self->printer_uri, printer_uri);
144ef4
-
144ef4
-  self->clean_command = pp_maintenance_command_new (self->printer_name,
144ef4
-                                                    "Clean",
144ef4
-                                                    "all",
144ef4
-                                                    /* Translators: Name of job which makes printer to clean its heads */
144ef4
-                                                    _("Clean print heads"));
144ef4
-  check_clean_heads_maintenance_command (self);
144ef4
+  g_free (self->printer_hostname);
144ef4
+  self->printer_hostname = printer_get_hostname (printer_type, device_uri, printer_uri);
144ef4
 
144ef4
   gtk_image_set_from_icon_name (self->printer_icon, printer_icon_name, GTK_ICON_SIZE_DIALOG);
144ef4
   gtk_label_set_text (self->printer_status, printer_status);
788f1e
@@ -970,7 +1015,6 @@ pp_printer_entry_new (cups_dest_t  print
144ef4
       gtk_label_set_text (self->printer_location_address_label, location);
144ef4
     }
144ef4
 
144ef4
-  g_signal_connect (self->supply_drawing_area, "draw", G_CALLBACK (supply_levels_draw_cb), self);
144ef4
   ink_supply_is_empty = supply_level_is_empty (self);
144ef4
   gtk_widget_set_visible (GTK_WIDGET (self->printer_inklevel_label), !ink_supply_is_empty);
144ef4
   gtk_widget_set_visible (GTK_WIDGET (self->supply_frame), !ink_supply_is_empty);
788f1e
@@ -983,8 +1027,6 @@ pp_printer_entry_new (cups_dest_t  print
144ef4
   g_free (instance);
144ef4
   g_free (printer_icon_name);
144ef4
   g_free (default_icon_name);
144ef4
-
144ef4
-  return self;
144ef4
 }
144ef4
 
144ef4
 static void
788f1e
@@ -1008,6 +1050,7 @@ pp_printer_entry_dispose (GObject *objec
788f1e
   g_clear_pointer (&self->printer_location, g_free);
788f1e
   g_clear_pointer (&self->printer_make_and_model, g_free);
788f1e
   g_clear_pointer (&self->printer_hostname, g_free);
788f1e
+  g_clear_pointer (&self->inklevel, ink_level_data_free);
788f1e
 
788f1e
   if (self->get_jobs_cancellable != NULL)
788f1e
     {
144ef4
--- gnome-control-center-3.28.2/panels/printers/pp-printer-entry.h
144ef4
+++ gnome-control-center-3.28.2/panels/printers/pp-printer-entry.h
144ef4
@@ -42,4 +42,8 @@ void            pp_printer_entry_show_jo
144ef4
 
144ef4
 void            pp_printer_entry_authenticate_jobs (PpPrinterEntry *self);
144ef4
 
144ef4
+void            pp_printer_entry_update (PpPrinterEntry *self,
144ef4
+                                         cups_dest_t     printer,
144ef4
+                                         gboolean        is_authorized);
144ef4
+
144ef4
 #endif /* PP_PRINTER_ENTRY_H */