From cd2495787209cb11492e86ecfbfb1f5505ac4240 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Tue, 26 Mar 2013 14:43:39 +0000
Subject: background: Fix handling of cancellation in async calls

A few of the async calls were still handling the user_data before
checking that it was still valid (eg. the operation was not cancelled),
and also printing warnings when the error was a cancellation.
---
--- a/panels/background/bg-pictures-source.c
+++ b/panels/background/bg-pictures-source.c
@@ -413,7 +413,7 @@
                        GAsyncResult *res,
                        gpointer      user_data)
 {
-  BgPicturesSource *bg_source = BG_PICTURES_SOURCE (user_data);
+  BgPicturesSource *bg_source;
   GList *files, *l;
   GError *err = NULL;
   GFile *parent;
@@ -423,7 +423,8 @@
 
   if (err)
     {
-      g_warning ("Could not get pictures file information: %s", err->message);
+      if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("Could not get pictures file information: %s", err->message);
       g_error_free (err);
 
       g_list_foreach (files, (GFunc) g_object_unref, NULL);
@@ -431,6 +432,8 @@
       return;
     }
 
+  bg_source = BG_PICTURES_SOURCE (user_data);
+
   parent = g_file_enumerator_get_container (G_FILE_ENUMERATOR (source));
 
   /* iterate over the available files */
@@ -453,7 +456,7 @@
                       GAsyncResult *res,
                       gpointer      user_data)
 {
-  BgPicturesSourcePrivate *priv = BG_PICTURES_SOURCE (user_data)->priv;
+  BgPicturesSourcePrivate *priv;
   GFileEnumerator *enumerator;
   GError *err = NULL;
 
@@ -461,12 +464,15 @@
 
   if (err)
     {
-      if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) == FALSE)
+      if (!g_error_matches (err, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) &&
+          !g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
         g_warning ("Could not fill pictures source: %s", err->message);
       g_error_free (err);
       return;
     }
 
+  priv = BG_PICTURES_SOURCE (user_data)->priv;
+
   /* get the files */
   g_file_enumerator_next_files_async (enumerator,
                                       G_MAXINT,
