|
|
57bc60 |
From b8b0347edfb6896b72fd5a207e6cd12d0e578505 Mon Sep 17 00:00:00 2001
|
|
|
57bc60 |
From: Felipe Borges <felipeborges@gnome.org>
|
|
|
57bc60 |
Date: Thu, 6 Apr 2017 13:11:36 +0200
|
|
|
57bc60 |
Subject: [PATCH] printers: Make actualize_printers_list* cancellable
|
|
|
57bc60 |
|
|
|
57bc60 |
This way we can safely interrupt an update without crashing
|
|
|
57bc60 |
g-c-c.
|
|
|
57bc60 |
|
|
|
57bc60 |
https://bugzilla.gnome.org/show_bug.cgi?id=780299
|
|
|
57bc60 |
---
|
|
|
57bc60 |
panels/printers/cc-printers-panel.c | 31 ++++++++++++++++++++++++++++---
|
|
|
57bc60 |
panels/printers/pp-cups.c | 6 +++++-
|
|
|
57bc60 |
2 files changed, 33 insertions(+), 4 deletions(-)
|
|
|
57bc60 |
|
|
|
57bc60 |
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
|
|
|
57bc60 |
index fb5560843..fb1299982 100644
|
|
|
57bc60 |
--- a/panels/printers/cc-printers-panel.c
|
|
|
57bc60 |
+++ b/panels/printers/cc-printers-panel.c
|
|
|
57bc60 |
@@ -107,6 +107,7 @@ struct _CcPrintersPanelPrivate
|
|
|
57bc60 |
GHashTable *preferred_drivers;
|
|
|
57bc60 |
GCancellable *get_all_ppds_cancellable;
|
|
|
57bc60 |
GCancellable *subscription_renew_cancellable;
|
|
|
57bc60 |
+ GCancellable *actualize_printers_list_cancellable;
|
|
|
57bc60 |
|
|
|
57bc60 |
gchar *new_printer_name;
|
|
|
57bc60 |
gchar *new_printer_location;
|
|
|
57bc60 |
@@ -196,6 +197,9 @@ cc_printers_panel_dispose (GObject *object)
|
|
|
57bc60 |
g_cancellable_cancel (priv->subscription_renew_cancellable);
|
|
|
57bc60 |
g_clear_object (&priv->subscription_renew_cancellable);
|
|
|
57bc60 |
|
|
|
57bc60 |
+ g_cancellable_cancel (priv->actualize_printers_list_cancellable);
|
|
|
57bc60 |
+ g_clear_object (&priv->actualize_printers_list_cancellable);
|
|
|
57bc60 |
+
|
|
|
57bc60 |
detach_from_cups_notifier (CC_PRINTERS_PANEL (object));
|
|
|
57bc60 |
|
|
|
57bc60 |
if (priv->cups_status_check_id > 0)
|
|
|
57bc60 |
@@ -1172,6 +1176,7 @@ actualize_printers_list_cb (GObject *source_object,
|
|
|
57bc60 |
gboolean valid = FALSE;
|
|
|
57bc60 |
PpCups *cups = PP_CUPS (source_object);
|
|
|
57bc60 |
PpCupsDests *cups_dests;
|
|
|
57bc60 |
+ GError *error = NULL;
|
|
|
57bc60 |
gchar *current_printer_name = NULL;
|
|
|
57bc60 |
gchar *printer_icon_name = NULL;
|
|
|
57bc60 |
gchar *default_icon_name = NULL;
|
|
|
57bc60 |
@@ -1181,6 +1186,19 @@ actualize_printers_list_cb (GObject *source_object,
|
|
|
57bc60 |
int i, j;
|
|
|
57bc60 |
int num_jobs = 0;
|
|
|
57bc60 |
|
|
|
57bc60 |
+ cups_dests = pp_cups_get_dests_finish (cups, result, &error);
|
|
|
57bc60 |
+
|
|
|
57bc60 |
+ if (cups_dests == NULL && error != NULL)
|
|
|
57bc60 |
+ {
|
|
|
57bc60 |
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
57bc60 |
+ {
|
|
|
57bc60 |
+ g_warning ("Could not get dests: %s", error->message);
|
|
|
57bc60 |
+ }
|
|
|
57bc60 |
+
|
|
|
57bc60 |
+ g_error_free (error);
|
|
|
57bc60 |
+ return;
|
|
|
57bc60 |
+ }
|
|
|
57bc60 |
+
|
|
|
57bc60 |
priv = PRINTERS_PANEL_PRIVATE (self);
|
|
|
57bc60 |
|
|
|
57bc60 |
treeview = (GtkTreeView*)
|
|
|
57bc60 |
@@ -1210,7 +1228,6 @@ actualize_printers_list_cb (GObject *source_object,
|
|
|
57bc60 |
}
|
|
|
57bc60 |
|
|
|
57bc60 |
free_dests (self);
|
|
|
57bc60 |
- cups_dests = pp_cups_get_dests_finish (cups, result, NULL);
|
|
|
57bc60 |
|
|
|
57bc60 |
priv->dests = cups_dests->dests;
|
|
|
57bc60 |
priv->num_dests = cups_dests->num_of_dests;
|
|
|
57bc60 |
@@ -1413,10 +1430,16 @@ actualize_printers_list_cb (GObject *source_object,
|
|
|
57bc60 |
static void
|
|
|
57bc60 |
actualize_printers_list (CcPrintersPanel *self)
|
|
|
57bc60 |
{
|
|
|
57bc60 |
- PpCups *cups;
|
|
|
57bc60 |
+ CcPrintersPanelPrivate *priv;
|
|
|
57bc60 |
+ PpCups *cups;
|
|
|
57bc60 |
+
|
|
|
57bc60 |
+ priv = PRINTERS_PANEL_PRIVATE (self);
|
|
|
57bc60 |
|
|
|
57bc60 |
cups = pp_cups_new ();
|
|
|
57bc60 |
- pp_cups_get_dests_async (cups, NULL, actualize_printers_list_cb, self);
|
|
|
57bc60 |
+ pp_cups_get_dests_async (cups,
|
|
|
57bc60 |
+ priv->actualize_printers_list_cancellable,
|
|
|
57bc60 |
+ actualize_printers_list_cb,
|
|
|
57bc60 |
+ self);
|
|
|
57bc60 |
}
|
|
|
57bc60 |
|
|
|
57bc60 |
static void
|
|
|
57bc60 |
@@ -3106,6 +3129,8 @@ cc_printers_panel_init (CcPrintersPanel *self)
|
|
|
57bc60 |
|
|
|
57bc60 |
priv->preferred_drivers = NULL;
|
|
|
57bc60 |
|
|
|
57bc60 |
+ priv->actualize_printers_list_cancellable = g_cancellable_new ();
|
|
|
57bc60 |
+
|
|
|
57bc60 |
builder_result = gtk_builder_add_objects_from_resource (priv->builder,
|
|
|
57bc60 |
"/org/gnome/control-center/printers/printers.ui",
|
|
|
57bc60 |
objects, &error);
|
|
|
57bc60 |
diff --git a/panels/printers/pp-cups.c b/panels/printers/pp-cups.c
|
|
|
57bc60 |
index 6521b90ba..0d0d4a52b 100644
|
|
|
57bc60 |
--- a/panels/printers/pp-cups.c
|
|
|
57bc60 |
+++ b/panels/printers/pp-cups.c
|
|
|
57bc60 |
@@ -73,7 +73,10 @@ _pp_cups_get_dests_thread (GTask *task,
|
|
|
57bc60 |
dests = g_new0 (PpCupsDests, 1);
|
|
|
57bc60 |
dests->num_of_dests = cupsGetDests (&dests->dests);
|
|
|
57bc60 |
|
|
|
57bc60 |
- g_task_return_pointer (task, dests, (GDestroyNotify) pp_cups_dests_free);
|
|
|
57bc60 |
+ if (g_task_set_return_on_cancel (task, FALSE))
|
|
|
57bc60 |
+ {
|
|
|
57bc60 |
+ g_task_return_pointer (task, dests, (GDestroyNotify) pp_cups_dests_free);
|
|
|
57bc60 |
+ }
|
|
|
57bc60 |
}
|
|
|
57bc60 |
|
|
|
57bc60 |
void
|
|
|
57bc60 |
@@ -85,6 +88,7 @@ pp_cups_get_dests_async (PpCups *cups,
|
|
|
57bc60 |
GTask *task;
|
|
|
57bc60 |
|
|
|
57bc60 |
task = g_task_new (cups, cancellable, callback, user_data);
|
|
|
57bc60 |
+ g_task_set_return_on_cancel (task, TRUE);
|
|
|
57bc60 |
g_task_run_in_thread (task, (GTaskThreadFunc) _pp_cups_get_dests_thread);
|
|
|
57bc60 |
g_object_unref (task);
|
|
|
57bc60 |
}
|
|
|
57bc60 |
--
|
|
|
57bc60 |
2.12.2
|
|
|
57bc60 |
|