[gimp/gimp-2-8] Bug 622758 - Fix error display for thumbnail creation



commit c767b0ff66e39738c30521aa05bf091cca69e070
Author: Jehan <jehan girinstud io>
Date:   Mon Dec 23 03:25:05 2013 +1300

    Bug 622758 - Fix error display for thumbnail creation
    
    Do not stay forever in "Creating Preview..." state during
    auto-thumbnailing, and fix error showing when creation fails.
    (cherry picked from commit 6208d2197941f5650e869d83e542a05fe4894244)

 app/core/gimpimagefile.c     |   33 +++++++++++++++++++++++++--------
 app/core/gimpimagefile.h     |    2 +-
 libgimpthumb/gimpthumbnail.c |    5 +++--
 3 files changed, 29 insertions(+), 11 deletions(-)
---
diff --git a/app/core/gimpimagefile.c b/app/core/gimpimagefile.c
index 5f80aae..34ef7c8 100644
--- a/app/core/gimpimagefile.c
+++ b/app/core/gimpimagefile.c
@@ -314,7 +314,7 @@ gimp_imagefile_update (GimpImagefile *imagefile)
     }
 }
 
-void
+gboolean
 gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
                                  GimpContext   *context,
                                  GimpProgress  *progress,
@@ -325,12 +325,12 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
   GimpThumbnail        *thumbnail;
   GimpThumbState        image_state;
 
-  g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
-  g_return_if_fail (GIMP_IS_CONTEXT (context));
-  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
+  g_return_val_if_fail (GIMP_IS_IMAGEFILE (imagefile), FALSE);
+  g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
+  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE);
 
   if (size < 1)
-    return;
+    return TRUE;
 
   private = GET_PRIVATE (imagefile);
 
@@ -402,11 +402,19 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile,
       if (! success)
         {
           gimp_message_literal (private->gimp,
-                               G_OBJECT (progress), GIMP_MESSAGE_ERROR,
-                               error->message);
+                                G_OBJECT (progress), GIMP_MESSAGE_ERROR,
+                                error->message);
           g_clear_error (&error);
+
+          g_object_set (thumbnail,
+                        "thumb-state", GIMP_THUMB_STATE_FAILED,
+                        NULL);
         }
+
+      return success;
     }
+
+  return TRUE;
 }
 
 /*  The weak version doesn't ref the imagefile but deals gracefully
@@ -440,7 +448,16 @@ gimp_imagefile_create_thumbnail_weak (GimpImagefile *imagefile,
 
   g_object_add_weak_pointer (G_OBJECT (imagefile), (gpointer) &imagefile);
 
-  gimp_imagefile_create_thumbnail (local, context, progress, size, replace);
+  if (! gimp_imagefile_create_thumbnail (local, context, progress, size, replace))
+    {
+      /* The weak version works on a local copy so the thumbnail status
+       * of the actual image is not properly updated in case of creation
+       * failure, thus it would end up in a generic GIMP_THUMB_STATE_NOT_FOUND,
+       * which is less informative. */
+      g_object_set (private->thumbnail,
+                    "thumb-state", GIMP_THUMB_STATE_FAILED,
+                    NULL);
+    }
 
   if (imagefile)
     {
diff --git a/app/core/gimpimagefile.h b/app/core/gimpimagefile.h
index 20a62f2..1670341 100644
--- a/app/core/gimpimagefile.h
+++ b/app/core/gimpimagefile.h
@@ -64,7 +64,7 @@ GIcon         * gimp_imagefile_get_gicon             (GimpImagefile *imagefile);
 void            gimp_imagefile_set_mime_type         (GimpImagefile *imagefile,
                                                       const gchar   *mime_type);
 void            gimp_imagefile_update                (GimpImagefile *imagefile);
-void            gimp_imagefile_create_thumbnail      (GimpImagefile *imagefile,
+gboolean        gimp_imagefile_create_thumbnail      (GimpImagefile *imagefile,
                                                       GimpContext   *context,
                                                       GimpProgress  *progress,
                                                       gint           size,
diff --git a/libgimpthumb/gimpthumbnail.c b/libgimpthumb/gimpthumbnail.c
index 30cc191..fc90e41 100644
--- a/libgimpthumb/gimpthumbnail.c
+++ b/libgimpthumb/gimpthumbnail.c
@@ -710,14 +710,15 @@ gimp_thumbnail_update_thumb (GimpThumbnail *thumbnail,
 
   filename = gimp_thumb_find_thumb (thumbnail->image_uri, &size);
 
-  if (! filename)
+  /* We don't want to clear the GIMP_THUMB_STATE_FAILED state, because
+   * it is normal to have no filename if thumbnail creation failed. */
+  if (state != GIMP_THUMB_STATE_FAILED && ! filename)
     state = GIMP_THUMB_STATE_NOT_FOUND;
 
   switch (state)
     {
     case GIMP_THUMB_STATE_EXISTS:
     case GIMP_THUMB_STATE_OLD:
-    case GIMP_THUMB_STATE_FAILED:
     case GIMP_THUMB_STATE_OK:
       g_return_if_fail (thumbnail->thumb_filename != NULL);
 


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