[gthumb] image preloader: call the callback even after cancelling



commit 171e4ed31bc7e9a7ea3c5a498541515732bd9899
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Thu Oct 26 08:48:21 2017 +0200

    image preloader: call the callback even after cancelling

 extensions/image_viewer/gth-image-viewer-page.c |   12 +++++---
 gthumb/gth-image-preloader.c                    |   33 +++++++++++++++-------
 2 files changed, 29 insertions(+), 16 deletions(-)
---
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index f081c20..6c8b2f3 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -2310,11 +2310,13 @@ get_original_image_ready_cb (GObject            *source_object,
        cairo_surface_t      *image = NULL;
        GError               *error = NULL;
 
-       gth_image_viewer_page_get_original_finish (self->viewer_page,
-                                                  result,
-                                                  &image,
-                                                  &error);
-       gth_image_task_set_destination_surface (GTH_IMAGE_TASK (self), image);
+       if (gth_image_viewer_page_get_original_finish (self->viewer_page,
+                                                      result,
+                                                      &image,
+                                                      &error))
+       {
+               gth_image_task_set_destination_surface (GTH_IMAGE_TASK (self), image);
+       }
        gth_task_completed (GTH_TASK (self), error);
 
        cairo_surface_destroy (image);
diff --git a/gthumb/gth-image-preloader.c b/gthumb/gth-image-preloader.c
index c4d29ea..7d9277a 100644
--- a/gthumb/gth-image-preloader.c
+++ b/gthumb/gth-image-preloader.c
@@ -223,6 +223,20 @@ load_request_unref (LoadRequest *request)
 }
 
 
+static void
+load_request_completed_with_error (LoadRequest *request,
+                                  GQuark       domain,
+                                  int          code)
+{
+       GError *error;
+
+       error = g_error_new_literal (domain, code, "");
+       g_simple_async_result_set_from_error (request->result, error);
+
+       g_error_free (error);
+}
+
+
 /* -- GthImagePreloader -- */
 
 
@@ -417,14 +431,8 @@ _gth_image_preloader_request_completed (GthImagePreloader *self,
                                                                   (GDestroyNotify) cache_data_unref);
                        g_simple_async_result_complete_in_idle (request->result);
                }
-               else {
-                       GError *error;
-
-                       error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_FOUND, "");
-                       g_simple_async_result_set_from_error (request->result, error);
-
-                       g_error_free (error);
-               }
+               else
+                       load_request_completed_with_error (request, G_IO_ERROR, G_IO_ERROR_NOT_FOUND);
        }
 
        /* queue the next file */
@@ -752,10 +760,13 @@ _gth_image_preloader_cancel_current_request (GthImagePreloader *self)
        if (self->priv->current_request == NULL)
                return;
 
-       if (self->priv->load_next_id > 0) {
-               g_source_remove (self->priv->load_next_id);
-               self->priv->load_next_id = 0;
+       if ((self->priv->load_next_id > 0) || g_cancellable_is_cancelled 
(self->priv->current_request->cancellable)) {
+               if (self->priv->load_next_id > 0) {
+                       g_source_remove (self->priv->load_next_id);
+                       self->priv->load_next_id = 0;
+               }
 
+               load_request_completed_with_error (self->priv->current_request, G_IO_ERROR, 
G_IO_ERROR_CANCELLED);
                _gth_image_preloader_request_finished (self, self->priv->current_request);
                _gth_image_preloader_start_request (self, self->priv->last_request);
        }


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