Commit 77c22ab4 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

image preloader: callback not always called when cancelling

fixed other missing callback calls cases after cancelling
parent 3a22267f
...@@ -337,7 +337,7 @@ different_quality_ready_cb (GObject *source_object, ...@@ -337,7 +337,7 @@ different_quality_ready_cb (GObject *source_object,
int original_width; int original_width;
int original_height; int original_height;
GError *error = NULL; GError *error = NULL;
cairo_surface_t *s1; cairo_surface_t *s1 = NULL;
cairo_surface_t *s2; cairo_surface_t *s2;
int w1, h1, w2, h2; int w1, h1, w2, h2;
gboolean got_better_quality; gboolean got_better_quality;
...@@ -367,12 +367,20 @@ different_quality_ready_cb (GObject *source_object, ...@@ -367,12 +367,20 @@ different_quality_ready_cb (GObject *source_object,
/* check whether the image is of different quality */ /* check whether the image is of different quality */
s1 = gth_image_get_cairo_surface (image); s1 = gth_image_get_cairo_surface (image);
if (s1 == NULL)
goto clear_data;
s2 = gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (self->priv->viewer)); s2 = gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (self->priv->viewer));
if (s2 == NULL) {
got_better_quality = TRUE;
}
else {
w1 = cairo_image_surface_get_width (s1); w1 = cairo_image_surface_get_width (s1);
h1 = cairo_image_surface_get_height (s1); h1 = cairo_image_surface_get_height (s1);
w2 = cairo_image_surface_get_width (s2); w2 = cairo_image_surface_get_width (s2);
h2 = cairo_image_surface_get_height (s2); h2 = cairo_image_surface_get_height (s2);
got_better_quality = ((w1 > w2) || (h1 > h2)); got_better_quality = ((w1 > w2) || (h1 > h2));
}
if (got_better_quality) { if (got_better_quality) {
gth_viewer_page_focus (GTH_VIEWER_PAGE (self)); gth_viewer_page_focus (GTH_VIEWER_PAGE (self));
...@@ -384,10 +392,10 @@ different_quality_ready_cb (GObject *source_object, ...@@ -384,10 +392,10 @@ different_quality_ready_cb (GObject *source_object,
gtk_widget_queue_draw (self->priv->viewer); gtk_widget_queue_draw (self->priv->viewer);
} }
cairo_surface_destroy (s1);
clear_data: clear_data:
if (s1 != NULL)
cairo_surface_destroy (s1);
_g_object_unref (requested); _g_object_unref (requested);
_g_object_unref (image); _g_object_unref (image);
g_clear_error (&error); g_clear_error (&error);
...@@ -2189,6 +2197,8 @@ original_image_ready_cb (GObject *source_object, ...@@ -2189,6 +2197,8 @@ original_image_ready_cb (GObject *source_object,
GError *error = NULL; GError *error = NULL;
if (! _gth_image_viewer_page_load_with_preloader_finish (data->viewer_page)) { if (! _gth_image_viewer_page_load_with_preloader_finish (data->viewer_page)) {
g_simple_async_result_take_error (data->result, g_error_new_literal (G_IO_ERROR, G_IO_ERROR_CANCELLED, ""));
g_simple_async_result_complete_in_idle (data->result);
get_original_data_free (data); get_original_data_free (data);
return; return;
} }
......
...@@ -60,6 +60,7 @@ typedef struct { ...@@ -60,6 +60,7 @@ typedef struct {
typedef struct { typedef struct {
int ref; int ref;
gboolean loading;
gboolean finalized; gboolean finalized;
GthImagePreloader *preloader; GthImagePreloader *preloader;
GList *files; /* List of GthFileData */ GList *files; /* List of GthFileData */
...@@ -188,6 +189,7 @@ load_request_new (GthImagePreloader *preloader) ...@@ -188,6 +189,7 @@ load_request_new (GthImagePreloader *preloader)
request = g_new0 (LoadRequest, 1); request = g_new0 (LoadRequest, 1);
request->ref = 1; request->ref = 1;
request->loading = FALSE;
request->finalized = FALSE; request->finalized = FALSE;
request->preloader = preloader; request->preloader = preloader;
request->files = NULL; request->files = NULL;
...@@ -366,8 +368,10 @@ _gth_image_preloader_request_finished (GthImagePreloader *self, ...@@ -366,8 +368,10 @@ _gth_image_preloader_request_finished (GthImagePreloader *self,
{ {
if (self->priv->last_request == load_request) if (self->priv->last_request == load_request)
self->priv->last_request = NULL; self->priv->last_request = NULL;
if (self->priv->current_request == load_request) {
load_request_unref (self->priv->current_request); load_request_unref (self->priv->current_request);
self->priv->current_request = NULL; self->priv->current_request = NULL;
}
load_request_unref (load_request); load_request_unref (load_request);
} }
...@@ -602,6 +606,22 @@ _gth_image_preloader_resize_at_requested_size (GthImagePreloader *self, ...@@ -602,6 +606,22 @@ _gth_image_preloader_resize_at_requested_size (GthImagePreloader *self,
#endif #endif
static void
_gth_image_preloader_request_cancelled (GthImagePreloader *self,
LoadRequest *request)
{
if (request->current_file == request->requested_file) {
g_simple_async_result_take_error (request->result, g_error_new_literal (G_IO_ERROR, G_IO_ERROR_CANCELLED, ""));
g_simple_async_result_complete_in_idle (request->result);
}
_gth_image_preloader_request_finished (self, request);
if (self->priv->last_request != NULL)
_gth_image_preloader_start_request (self, self->priv->last_request);
}
static void static void
image_loader_ready_cb (GObject *source_object, image_loader_ready_cb (GObject *source_object,
GAsyncResult *result, GAsyncResult *result,
...@@ -619,6 +639,8 @@ image_loader_ready_cb (GObject *source_object, ...@@ -619,6 +639,8 @@ image_loader_ready_cb (GObject *source_object,
CacheData *cache_data; CacheData *cache_data;
gboolean resized; gboolean resized;
request->loading = FALSE;
if (request->finalized) { if (request->finalized) {
#ifdef DEBUG_PRELOADER #ifdef DEBUG_PRELOADER
g_print (" --> cancelled\n"); g_print (" --> cancelled\n");
...@@ -645,11 +667,7 @@ image_loader_ready_cb (GObject *source_object, ...@@ -645,11 +667,7 @@ image_loader_ready_cb (GObject *source_object,
if (error != NULL) if (error != NULL)
g_error_free (error); g_error_free (error);
_g_object_unref (image); _g_object_unref (image);
_gth_image_preloader_request_finished (self, request); _gth_image_preloader_request_cancelled (self, request);
if (self->priv->last_request != NULL)
_gth_image_preloader_start_request (self, self->priv->last_request);
return; return;
} }
...@@ -731,6 +749,7 @@ _gth_image_preloader_load_current_file (GthImagePreloader *self, ...@@ -731,6 +749,7 @@ _gth_image_preloader_load_current_file (GthImagePreloader *self,
g_print ("load %s @%d\n", g_file_get_uri (requested_file->file), ignore_requested_size ? -1 : request->requested_size); g_print ("load %s @%d\n", g_file_get_uri (requested_file->file), ignore_requested_size ? -1 : request->requested_size);
#endif #endif
request->loading = TRUE;
gth_image_loader_set_out_profile (self->priv->loader, self->priv->out_profile); gth_image_loader_set_out_profile (self->priv->loader, self->priv->out_profile);
gth_image_loader_load (self->priv->loader, gth_image_loader_load (self->priv->loader,
requested_file, requested_file,
...@@ -760,16 +779,13 @@ _gth_image_preloader_cancel_current_request (GthImagePreloader *self) ...@@ -760,16 +779,13 @@ _gth_image_preloader_cancel_current_request (GthImagePreloader *self)
if (self->priv->current_request == NULL) if (self->priv->current_request == NULL)
return; return;
if ((self->priv->load_next_id > 0) || g_cancellable_is_cancelled (self->priv->current_request->cancellable)) {
if (self->priv->load_next_id > 0) { if (self->priv->load_next_id > 0) {
g_source_remove (self->priv->load_next_id); g_source_remove (self->priv->load_next_id);
self->priv->load_next_id = 0; self->priv->load_next_id = 0;
} }
load_request_completed_with_error (self->priv->current_request, G_IO_ERROR, G_IO_ERROR_CANCELLED); if (! self->priv->current_request->loading)
_gth_image_preloader_request_finished (self, self->priv->current_request); _gth_image_preloader_request_cancelled (self, self->priv->current_request);
_gth_image_preloader_start_request (self, self->priv->last_request);
}
else else
g_cancellable_cancel (self->priv->current_request->cancellable); g_cancellable_cancel (self->priv->current_request->cancellable);
} }
...@@ -827,12 +843,16 @@ gth_image_preloader_load (GthImagePreloader *self, ...@@ -827,12 +843,16 @@ gth_image_preloader_load (GthImagePreloader *self,
va_end (args); va_end (args);
request->files = g_list_reverse (request->files); request->files = g_list_reverse (request->files);
request->requested_file = request->files; request->requested_file = request->files;
request->current_file = request->files;
request->result = g_simple_async_result_new (G_OBJECT (self), request->result = g_simple_async_result_new (G_OBJECT (self),
callback, callback,
user_data, user_data,
gth_image_preloader_load); gth_image_preloader_load);
request->cancellable = (cancellable != NULL) ? g_object_ref (cancellable) : g_cancellable_new (); request->cancellable = (cancellable != NULL) ? g_object_ref (cancellable) : g_cancellable_new ();
if ((self->priv->last_request != NULL) && (self->priv->last_request != self->priv->current_request))
_gth_image_preloader_request_cancelled (self, self->priv->last_request);
self->priv->last_request = request; self->priv->last_request = request;
if (self->priv->current_request != NULL) if (self->priv->current_request != NULL)
_gth_image_preloader_cancel_current_request (self); _gth_image_preloader_cancel_current_request (self);
...@@ -855,6 +875,9 @@ gth_image_preloader_load_finish (GthImagePreloader *self, ...@@ -855,6 +875,9 @@ gth_image_preloader_load_finish (GthImagePreloader *self,
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self), gth_image_preloader_load), FALSE); g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self), gth_image_preloader_load), FALSE);
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
return FALSE;
cache_data = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result)); cache_data = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
g_return_val_if_fail (cache_data != NULL, FALSE); g_return_val_if_fail (cache_data != NULL, FALSE);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment