printers: Use a shared PpCups object

This commit is contained in:
Robert Ancell 2020-06-27 10:51:23 +12:00 committed by Robert Ancell
parent f8204635ce
commit 68042c95c1

View file

@ -70,6 +70,8 @@ struct _CcPrintersPanel
GtkBuilder *builder; GtkBuilder *builder;
PpCups *cups;
cups_dest_t *dests; cups_dest_t *dests;
int num_dests; int num_dests;
@ -297,6 +299,7 @@ cc_printers_panel_dispose (GObject *object)
NULL); NULL);
} }
g_clear_object (&self->cups);
g_clear_object (&self->pp_new_printer_dialog); g_clear_object (&self->pp_new_printer_dialog);
g_clear_pointer (&self->new_printer_name, g_free); g_clear_pointer (&self->new_printer_name, g_free);
g_clear_pointer (&self->renamed_printer_name, g_free); g_clear_pointer (&self->renamed_printer_name, g_free);
@ -494,10 +497,8 @@ static gboolean
renew_subscription (gpointer data) renew_subscription (gpointer data)
{ {
CcPrintersPanel *self = (CcPrintersPanel*) data; CcPrintersPanel *self = (CcPrintersPanel*) data;
g_autoptr(PpCups) cups = NULL;
cups = pp_cups_new (); pp_cups_renew_subscription_async (self->cups,
pp_cups_renew_subscription_async (cups,
self->subscription_id, self->subscription_id,
subscription_events, subscription_events,
SUBSCRIPTION_DURATION, SUBSCRIPTION_DURATION,
@ -560,10 +561,8 @@ static void
attach_to_cups_notifier (gpointer data) attach_to_cups_notifier (gpointer data)
{ {
CcPrintersPanel *self = (CcPrintersPanel*) data; CcPrintersPanel *self = (CcPrintersPanel*) data;
g_autoptr(PpCups) cups = NULL;
cups = pp_cups_new (); pp_cups_renew_subscription_async (self->cups,
pp_cups_renew_subscription_async (cups,
self->subscription_id, self->subscription_id,
subscription_events, subscription_events,
SUBSCRIPTION_DURATION, SUBSCRIPTION_DURATION,
@ -584,7 +583,6 @@ static void
detach_from_cups_notifier (gpointer data) detach_from_cups_notifier (gpointer data)
{ {
CcPrintersPanel *self = (CcPrintersPanel*) data; CcPrintersPanel *self = (CcPrintersPanel*) data;
g_autoptr(PpCups) cups = NULL;
if (self->dbus_subscription_id != 0) { if (self->dbus_subscription_id != 0) {
g_dbus_connection_signal_unsubscribe (self->cups_bus_connection, g_dbus_connection_signal_unsubscribe (self->cups_bus_connection,
@ -592,8 +590,7 @@ detach_from_cups_notifier (gpointer data)
self->dbus_subscription_id = 0; self->dbus_subscription_id = 0;
} }
cups = pp_cups_new (); pp_cups_cancel_subscription_async (self->cups,
pp_cups_cancel_subscription_async (cups,
self->subscription_id, self->subscription_id,
subscription_cancel_cb, subscription_cancel_cb,
NULL); NULL);
@ -911,10 +908,7 @@ actualize_printers_list_cb (GObject *source_object,
static void static void
actualize_printers_list (CcPrintersPanel *self) actualize_printers_list (CcPrintersPanel *self)
{ {
g_autoptr(PpCups) cups = NULL; pp_cups_get_dests_async (self->cups,
cups = pp_cups_new ();
pp_cups_get_dests_async (cups,
cc_panel_get_cancellable (CC_PANEL (self)), cc_panel_get_cancellable (CC_PANEL (self)),
actualize_printers_list_cb, actualize_printers_list_cb,
self); self);
@ -1068,10 +1062,8 @@ static gboolean
cups_status_check (gpointer user_data) cups_status_check (gpointer user_data)
{ {
CcPrintersPanel *self = (CcPrintersPanel*) user_data; CcPrintersPanel *self = (CcPrintersPanel*) user_data;
g_autoptr(PpCups) cups = NULL;
cups = pp_cups_new (); pp_cups_connection_test_async (self->cups, NULL, cups_status_check_cb, self);
pp_cups_connection_test_async (cups, NULL, cups_status_check_cb, self);
return self->cups_status_check_id != 0; return self->cups_status_check_id != 0;
} }
@ -1219,7 +1211,6 @@ cc_printers_panel_init (CcPrintersPanel *self)
{ {
GtkWidget *top_widget; GtkWidget *top_widget;
GtkWidget *widget; GtkWidget *widget;
g_autoptr(PpCups) cups = NULL;
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
gchar *objects[] = { "overlay", "permission-infobar", "top-right-buttons", "printer-add-button", "search-button", NULL }; gchar *objects[] = { "overlay", "permission-infobar", "top-right-buttons", "printer-add-button", "search-button", NULL };
guint builder_result; guint builder_result;
@ -1230,6 +1221,8 @@ cc_printers_panel_init (CcPrintersPanel *self)
self->builder = gtk_builder_new (); self->builder = gtk_builder_new ();
self->reference = g_object_new (G_TYPE_OBJECT, NULL); self->reference = g_object_new (G_TYPE_OBJECT, NULL);
self->cups = pp_cups_new ();
self->printer_entries = g_hash_table_new_full (g_str_hash, self->printer_entries = g_hash_table_new_full (g_str_hash,
g_str_equal, g_str_equal,
g_free, g_free,
@ -1330,8 +1323,7 @@ Please check your installation");
get_all_ppds_async_cb, get_all_ppds_async_cb,
self); self);
cups = pp_cups_new (); pp_cups_connection_test_async (self->cups, cc_panel_get_cancellable (CC_PANEL (self)), connection_test_cb, self);
pp_cups_connection_test_async (cups, cc_panel_get_cancellable (CC_PANEL (self)), connection_test_cb, self);
gtk_container_add (GTK_CONTAINER (self), top_widget); gtk_container_add (GTK_CONTAINER (self), top_widget);
gtk_widget_show_all (GTK_WIDGET (self)); gtk_widget_show_all (GTK_WIDGET (self));
} }