[gnome-photos] local-item: Cancel g_file_trash_async during destruction



commit 5cb60e0eec53fbe00a3aabbd2993ca616576cb0f
Author: Rafael Fonseca <r4f4rfs gmail com>
Date:   Tue Mar 22 16:26:55 2016 +0100

    local-item: Cancel g_file_trash_async during destruction
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763908

 src/photos-local-item.c |   35 ++++++++++++++++++++++++++++-------
 1 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index 8b03a6b..b821f4c 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -37,6 +37,7 @@
 struct _PhotosLocalItem
 {
   PhotosBaseItem parent_instance;
+  GCancellable *cancellable;
 };
 
 struct _PhotosLocalItemClass
@@ -163,7 +164,6 @@ photos_local_item_get_source_widget (PhotosBaseItem *item)
 static void
 photos_local_item_trash_finish (GObject *source_object, GAsyncResult *res, gpointer user_data)
 {
-  PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (user_data);
   GError *error;
   GFile *file = G_FILE (source_object);
 
@@ -171,14 +171,17 @@ photos_local_item_trash_finish (GObject *source_object, GAsyncResult *res, gpoin
   g_file_trash_finish (file, res, &error);
   if (error != NULL)
     {
-      const gchar *uri;
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        {
+          PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (user_data);
+          const gchar *uri;
+
+          uri = photos_base_item_get_uri (PHOTOS_BASE_ITEM (self));
+          g_warning ("Unable to trash %s: %s", uri, error->message);
+        }
 
-      uri = photos_base_item_get_uri (PHOTOS_BASE_ITEM (self));
-      g_warning ("Unable to trash %s: %s", uri, error->message);
       g_error_free (error);
     }
-
-  g_object_unref (self);
 }
 
 
@@ -187,13 +190,14 @@ photos_local_item_trash (PhotosBaseItem *item)
 {
   GFile *file;
   const gchar *uri;
+  PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (item);
 
   if (photos_base_item_is_collection (item))
     return;
 
   uri = photos_base_item_get_uri (item);
   file = g_file_new_for_uri (uri);
-  g_file_trash_async (file, G_PRIORITY_DEFAULT, NULL, photos_local_item_trash_finish, g_object_ref (item));
+  g_file_trash_async (file, G_PRIORITY_DEFAULT, self->cancellable, photos_local_item_trash_finish, self);
 
   g_object_unref (file);
 
@@ -223,8 +227,24 @@ photos_local_item_constructed (GObject *object)
 
 
 static void
+photos_local_item_dispose (GObject *object)
+{
+  PhotosLocalItem *self = PHOTOS_LOCAL_ITEM (object);
+
+  if (self->cancellable != NULL)
+    {
+      g_cancellable_cancel (self->cancellable);
+      g_clear_object (&self->cancellable);
+    }
+
+  G_OBJECT_CLASS (photos_local_item_parent_class)->dispose (object);
+}
+
+
+static void
 photos_local_item_init (PhotosLocalItem *self)
 {
+  self->cancellable = g_cancellable_new ();
 }
 
 
@@ -235,6 +255,7 @@ photos_local_item_class_init (PhotosLocalItemClass *class)
   PhotosBaseItemClass *base_item_class = PHOTOS_BASE_ITEM_CLASS (class);
 
   object_class->constructed = photos_local_item_constructed;
+  object_class->dispose = photos_local_item_dispose;
   base_item_class->create_name_fallback = photos_local_item_create_name_fallback;
   base_item_class->create_pipeline_path = photos_local_item_create_pipeline_path;
   base_item_class->create_thumbnail = photos_local_item_create_thumbnail;


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