[gthumb] thumbnailer: try with the system thumbnailer if the image is null



commit 328d415606f2beda53da4c43f0563c7bd3cb733c
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Aug 22 18:12:05 2021 +0200

    thumbnailer: try with the system thumbnailer if the image is null
    
    Fixes https://gitlab.gnome.org/GNOME/gthumb/-/issues/184

 gthumb/gth-thumb-loader.c | 71 ++++++++++++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 29 deletions(-)
---
diff --git a/gthumb/gth-thumb-loader.c b/gthumb/gth-thumb-loader.c
index 46bef3f9..47885772 100644
--- a/gthumb/gth-thumb-loader.c
+++ b/gthumb/gth-thumb-loader.c
@@ -764,6 +764,41 @@ watch_thumbnailer_cb (GPid     pid,
 }
 
 
+static void
+load_with_system_thumbnailer (GthThumbLoader *self,
+                             LoadData       *load_data)
+{
+       char   *uri;
+       GError *error = NULL;
+
+       uri = g_file_get_uri (load_data->file_data->file);
+       if (gnome_desktop_thumbnail_factory_generate_from_script (self->priv->thumb_factory,
+                                                                 uri,
+                                                                 gth_file_data_get_mime_type 
(load_data->file_data),
+                                                                 &load_data->thumbnailer_pid,
+                                                                 &load_data->thumbnailer_tmpfile,
+                                                                 &error))
+       {
+               load_data->thumbnailer_watch = g_child_watch_add (load_data->thumbnailer_pid,
+                                                                 watch_thumbnailer_cb,
+                                                                 load_data);
+               load_data->thumbnailer_timeout = g_timeout_add (MAX_THUMBNAILER_LIFETIME,
+                                                               kill_thumbnailer_cb,
+                                                               load_data);
+               load_data->cancellable_watch = g_timeout_add (CHECK_CANCELLABLE_DELAY,
+                                                             check_cancellable_cb,
+                                                             load_data);
+       }
+       else {
+               g_clear_error (&error);
+               failed_to_load_original_image (self, load_data);
+               load_data_unref (load_data);
+       }
+
+       g_free (uri);
+}
+
+
 static void
 original_image_ready_cb (GObject      *source_object,
                         GAsyncResult *res,
@@ -788,8 +823,6 @@ original_image_ready_cb (GObject      *source_object,
                /* error loading the original image, try with the system
                 * thumbnailer */
 
-               char *uri;
-
                if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
                        g_task_return_error (load_data->task, error);
                        load_data_unref (load_data);
@@ -797,37 +830,17 @@ original_image_ready_cb (GObject      *source_object,
                }
 
                g_clear_error (&error);
-
-               uri = g_file_get_uri (load_data->file_data->file);
-               if (gnome_desktop_thumbnail_factory_generate_from_script (self->priv->thumb_factory,
-                                                                         uri,
-                                                                         gth_file_data_get_mime_type 
(load_data->file_data),
-                                                                         &load_data->thumbnailer_pid,
-                                                                         &load_data->thumbnailer_tmpfile,
-                                                                         &error))
-               {
-                       load_data->thumbnailer_watch = g_child_watch_add (load_data->thumbnailer_pid,
-                                                                         watch_thumbnailer_cb,
-                                                                         load_data);
-                       load_data->thumbnailer_timeout = g_timeout_add (MAX_THUMBNAILER_LIFETIME,
-                                                                       kill_thumbnailer_cb,
-                                                                       load_data);
-                       load_data->cancellable_watch = g_timeout_add (CHECK_CANCELLABLE_DELAY,
-                                                                     check_cancellable_cb,
-                                                                     load_data);
-               }
-               else {
-                       g_clear_error (&error);
-                       failed_to_load_original_image (self, load_data);
-                       load_data_unref (load_data);
-               }
-
-               g_free (uri);
-
+               load_with_system_thumbnailer (self, load_data);
                return;
        }
 
        surface = gth_image_get_cairo_surface (image);
+       if (surface == NULL) {
+               g_object_unref (image);
+               load_with_system_thumbnailer (self, load_data);
+               return;
+       }
+
        original_image_loaded_correctly (self,
                                         load_data,
                                         surface,


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