[gnome-control-center] printers: Don't show duplicates while renaming printer



commit 34565466a2e12e0aa2ce960e9c3b7163556373e8
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Dec 6 14:58:01 2017 +0100

    printers: Don't show duplicates while renaming printer
    
    During the time it took to rename a printer asynchronously, we had
    cases where two entries were shown for the same printer: one with
    the old name and another with a new name.
    
    Now we signal from DetailsDialog to the given PrinterEntry which
    passes it along to the main panel object. The CcPrintersPanel object
    blacklists the renamed printer old name.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=790361

 panels/printers/cc-printers-panel.c |   36 +++++++++++++++++++++++++++++++++++
 panels/printers/pp-details-dialog.c |   20 +++++++++++++++++++
 panels/printers/pp-printer-entry.c  |   22 +++++++++++++++++++++
 3 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
index cb9b920..7b174d0 100644
--- a/panels/printers/cc-printers-panel.c
+++ b/panels/printers/cc-printers-panel.c
@@ -102,6 +102,7 @@ struct _CcPrintersPanelPrivate
   gboolean  new_printer_on_network;
 
   gchar    *renamed_printer_name;
+  gchar    *old_printer_name;
   gchar    *deleted_printer_name;
 
   GHashTable *printer_entries;
@@ -213,6 +214,7 @@ cc_printers_panel_dispose (GObject *object)
   g_clear_pointer (&priv->new_printer_make_and_model, g_free);
 
   g_clear_pointer (&priv->renamed_printer_name, g_free);
+  g_clear_pointer (&priv->old_printer_name, g_free);
 
   if (priv->builder)
     {
@@ -732,6 +734,23 @@ on_printer_deleted (PpPrinterEntry *printer_entry,
 }
 
 static void
+on_printer_renamed (PpPrinterEntry *printer_entry,
+                    gchar          *new_name,
+                    gpointer        user_data)
+{
+  CcPrintersPanel        *self = (CcPrintersPanel*) user_data;
+  CcPrintersPanelPrivate *priv;
+
+  priv = PRINTERS_PANEL_PRIVATE (self);
+
+  g_object_get (printer_entry,
+                "printer-name",
+                &priv->old_printer_name,
+                NULL);
+  priv->renamed_printer_name = g_strdup (new_name);
+}
+
+static void
 on_printer_changed (PpPrinterEntry *printer_entry,
                     gpointer        user_data)
 {
@@ -766,6 +785,10 @@ add_printer_entry (CcPrintersPanel *self,
                     "printer-delete",
                     G_CALLBACK (on_printer_deleted),
                     self);
+  g_signal_connect (printer_entry,
+                    "printer-renamed",
+                    G_CALLBACK (on_printer_renamed),
+                    self);
 
   gtk_list_box_insert (GTK_LIST_BOX (content), GTK_WIDGET (printer_entry), -1);
   gtk_widget_show_all (content);
@@ -801,6 +824,7 @@ actualize_printers_list_cb (GObject      *source_object,
   GtkWidget              *widget;
   PpCups                 *cups = PP_CUPS (source_object);
   PpCupsDests            *cups_dests;
+  gboolean                new_printer_available = FALSE;
   GError                 *error = NULL;
   int                     i;
 
@@ -832,11 +856,22 @@ actualize_printers_list_cb (GObject      *source_object,
 
   widget = (GtkWidget*) gtk_builder_get_object (priv->builder, "content");
   gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback) gtk_widget_destroy, NULL);
+
+  for (i = 0; i < priv->num_dests; i++)
+    {
+      new_printer_available = g_strcmp0 (priv->dests[i].name, priv->renamed_printer_name) == 0;
+      if (new_printer_available)
+        break;
+    }
+
   for (i = 0; i < priv->num_dests; i++)
     {
       if (g_strcmp0 (priv->dests[i].name, priv->deleted_printer_name) == 0)
           continue;
 
+      if (new_printer_available && g_strcmp0 (priv->dests[i].name, priv->old_printer_name) == 0)
+          continue;
+
       add_printer_entry (self, priv->dests[i]);
     }
 }
@@ -1197,6 +1232,7 @@ cc_printers_panel_init (CcPrintersPanel *self)
   priv->new_printer_on_network = FALSE;
 
   priv->renamed_printer_name = NULL;
+  priv->old_printer_name = NULL;
   priv->deleted_printer_name = NULL;
 
   priv->permission = NULL;
diff --git a/panels/printers/pp-details-dialog.c b/panels/printers/pp-details-dialog.c
index 17462bc..5db3798 100644
--- a/panels/printers/pp-details-dialog.c
+++ b/panels/printers/pp-details-dialog.c
@@ -65,10 +65,20 @@ struct _PpDetailsDialog {
 struct _PpDetailsDialogClass
 {
   GtkDialogClass parent_class;
+
+  void (*printer_renamed) (PpDetailsDialog *details_dialog, const gchar *new_name);
 };
 
 G_DEFINE_TYPE (PpDetailsDialog, pp_details_dialog, GTK_TYPE_DIALOG)
 
+enum
+{
+  PRINTER_RENAMED,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
 static void
 on_printer_rename_cb (GObject      *source_object,
                       GAsyncResult *result,
@@ -101,6 +111,8 @@ pp_details_dialog_response_cb (GtkDialog *dialog,
     {
       PpPrinter *printer = pp_printer_new (self->printer_name);
 
+      g_signal_emit_by_name (self, "printer-renamed", new_name);
+
       pp_printer_rename_async (printer,
                                new_name,
                                NULL,
@@ -388,6 +400,14 @@ pp_details_dialog_class_init (PpDetailsDialogClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, select_ppd_in_dialog);
   gtk_widget_class_bind_template_callback (widget_class, select_ppd_manually);
   gtk_widget_class_bind_template_callback (widget_class, pp_details_dialog_response_cb);
+
+  signals[PRINTER_RENAMED] = g_signal_new ("printer-renamed",
+                                           G_TYPE_FROM_CLASS (klass),
+                                           G_SIGNAL_RUN_LAST,
+                                           G_STRUCT_OFFSET (PpDetailsDialogClass, printer_renamed),
+                                           NULL, NULL, NULL,
+                                           G_TYPE_NONE, 1,
+                                           G_TYPE_STRING);
 }
 
 PpDetailsDialog *
diff --git a/panels/printers/pp-printer-entry.c b/panels/printers/pp-printer-entry.c
index 6aa202a..10fc934 100644
--- a/panels/printers/pp-printer-entry.c
+++ b/panels/printers/pp-printer-entry.c
@@ -93,6 +93,7 @@ struct _PpPrinterEntryClass
 
   void (*printer_changed) (PpPrinterEntry *printer_entry);
   void (*printer_delete)  (PpPrinterEntry *printer_entry);
+  void (*printer_renamed) (PpPrinterEntry *printer_entry, const gchar *new_name);
 };
 
 G_DEFINE_TYPE (PpPrinterEntry, pp_printer_entry, GTK_TYPE_LIST_BOX_ROW)
@@ -106,6 +107,7 @@ enum {
 enum {
   IS_DEFAULT_PRINTER,
   PRINTER_DELETE,
+  PRINTER_RENAMED,
   LAST_SIGNAL,
 };
 
@@ -391,6 +393,16 @@ supply_levels_draw_cb (GtkWidget      *widget,
 }
 
 static void
+printer_renamed_cb (PpDetailsDialog *dialog,
+                    gchar           *new_name,
+                    gpointer         user_data)
+{
+ PpPrinterEntry *self = PP_PRINTER_ENTRY (user_data);
+
+ g_signal_emit_by_name (self, "printer-renamed", new_name);
+}
+
+static void
 details_dialog_cb (GtkDialog *dialog,
                    gint       response_id,
                    gpointer   user_data)
@@ -424,6 +436,7 @@ on_show_printer_details_dialog (GtkButton      *button,
     self->is_authorized);
 
   g_signal_connect (self->pp_details_dialog, "response", G_CALLBACK (details_dialog_cb), self);
+  g_signal_connect (self->pp_details_dialog, "printer-renamed", G_CALLBACK (printer_renamed_cb), self);
   gtk_widget_show_all (GTK_WIDGET (self->pp_details_dialog));
 }
 
@@ -1066,4 +1079,13 @@ pp_printer_entry_class_init (PpPrinterEntryClass *klass)
                   G_STRUCT_OFFSET (PpPrinterEntryClass, printer_delete),
                   NULL, NULL, NULL,
                   G_TYPE_NONE, 0);
+
+  signals[PRINTER_RENAMED] =
+    g_signal_new ("printer-renamed",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (PpPrinterEntryClass, printer_renamed),
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE, 1,
+                  G_TYPE_STRING);
 }


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