[gnome-control-center/gnome-3-24] printers: Make actualize_printers_list cancellable



commit a16ea8c9409ae70ebef58b48bbd6cf0e870bcdd3
Author: Felipe Borges <felipeborges gnome org>
Date:   Mon Mar 20 13:29:59 2017 +0100

    printers: Make actualize_printers_list cancellable
    
    This way we can safely interrupt an update without crashing
    g-c-c.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780299

 panels/printers/cc-printers-panel.c |   32 ++++++++++++++++++++++++++++----
 panels/printers/pp-cups.c           |    6 +++++-
 2 files changed, 33 insertions(+), 5 deletions(-)
---
diff --git a/panels/printers/cc-printers-panel.c b/panels/printers/cc-printers-panel.c
index 5159321..182ff0a 100644
--- a/panels/printers/cc-printers-panel.c
+++ b/panels/printers/cc-printers-panel.c
@@ -90,6 +90,7 @@ struct _CcPrintersPanelPrivate
   PPDList      *all_ppds_list;
   GCancellable *get_all_ppds_cancellable;
   GCancellable *subscription_renew_cancellable;
+  GCancellable *actualize_printers_list_cancellable;
 
   gchar    *new_printer_name;
   gchar    *new_printer_location;
@@ -199,6 +200,9 @@ cc_printers_panel_dispose (GObject *object)
   g_cancellable_cancel (priv->subscription_renew_cancellable);
   g_clear_object (&priv->subscription_renew_cancellable);
 
+  g_cancellable_cancel (priv->actualize_printers_list_cancellable);
+  g_clear_object (&priv->actualize_printers_list_cancellable);
+
   detach_from_cups_notifier (CC_PRINTERS_PANEL (object));
 
   if (priv->cups_status_check_id > 0)
@@ -630,13 +634,25 @@ actualize_printers_list_cb (GObject      *source_object,
   GtkWidget              *widget;
   PpCups                 *cups = PP_CUPS (source_object);
   PpCupsDests            *cups_dests;
+  GError                 *error = NULL;
   int                     i;
 
+  cups_dests = pp_cups_get_dests_finish (cups, result, &error);
+
+  if (cups_dests == NULL && error != NULL)
+    {
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        {
+          g_warning ("Could not get dests: %s", error->message);
+        }
+
+      g_error_free (error);
+      return;
+    }
+
   priv = PRINTERS_PANEL_PRIVATE (self);
 
   free_dests (self);
-  cups_dests = pp_cups_get_dests_finish (cups, result, NULL);
-
   priv->dests = cups_dests->dests;
   priv->num_dests = cups_dests->num_of_dests;
   g_free (cups_dests);
@@ -656,10 +672,16 @@ actualize_printers_list_cb (GObject      *source_object,
 static void
 actualize_printers_list (CcPrintersPanel *self)
 {
-  PpCups *cups;
+  CcPrintersPanelPrivate *priv;
+  PpCups                 *cups;
+
+  priv = PRINTERS_PANEL_PRIVATE (self);
 
   cups = pp_cups_new ();
-  pp_cups_get_dests_async (cups, NULL, actualize_printers_list_cb, self);
+  pp_cups_get_dests_async (cups,
+                           priv->actualize_printers_list_cancellable,
+                           actualize_printers_list_cb,
+                           self);
 }
 
 static void
@@ -949,6 +971,8 @@ cc_printers_panel_init (CcPrintersPanel *self)
                                                  g_free,
                                                  NULL);
 
+  priv->actualize_printers_list_cancellable = g_cancellable_new ();
+
   builder_result = gtk_builder_add_objects_from_resource (priv->builder,
                                                           "/org/gnome/control-center/printers/printers.ui",
                                                           objects, &error);
diff --git a/panels/printers/pp-cups.c b/panels/printers/pp-cups.c
index 6521b90..0d0d4a5 100644
--- a/panels/printers/pp-cups.c
+++ b/panels/printers/pp-cups.c
@@ -73,7 +73,10 @@ _pp_cups_get_dests_thread (GTask        *task,
   dests = g_new0 (PpCupsDests, 1);
   dests->num_of_dests = cupsGetDests (&dests->dests);
 
-  g_task_return_pointer (task, dests, (GDestroyNotify) pp_cups_dests_free);
+  if (g_task_set_return_on_cancel (task, FALSE))
+    {
+      g_task_return_pointer (task, dests, (GDestroyNotify) pp_cups_dests_free);
+    }
 }
 
 void
@@ -85,6 +88,7 @@ pp_cups_get_dests_async (PpCups              *cups,
   GTask       *task;
 
   task = g_task_new (cups, cancellable, callback, user_data);
+  g_task_set_return_on_cancel (task, TRUE);
   g_task_run_in_thread (task, (GTaskThreadFunc) _pp_cups_get_dests_thread);
   g_object_unref (task);
 }


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