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
This commit is contained in:
parent
3d85b1c219
commit
34565466a2
3 changed files with 78 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
@ -731,6 +733,23 @@ on_printer_deleted (PpPrinterEntry *printer_entry,
|
|||
priv->remove_printer_timeout_id = g_timeout_add_seconds (10, on_remove_printer_timeout, self);
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
|
@ -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 *
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -390,6 +392,16 @@ supply_levels_draw_cb (GtkWidget *widget,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue