Blob Blame History Raw
From f7927e9a8201761b6654955739e87b93d3695169 Mon Sep 17 00:00:00 2001
From: mtwebster <miketwebster@gmail.com>
Date: Fri, 3 Jul 2015 10:08:02 -0400
Subject: [PATCH] gnome-desktop-thumbnailer.c: block known-buggy image types
 from being thumbnailed.

---
 libcinnamon-desktop/gnome-desktop-thumbnail.c | 86 +++++++++++++++++----------
 1 file changed, 54 insertions(+), 32 deletions(-)

diff --git a/libcinnamon-desktop/gnome-desktop-thumbnail.c b/libcinnamon-desktop/gnome-desktop-thumbnail.c
index b740c3a..cffa5d0 100644
--- a/libcinnamon-desktop/gnome-desktop-thumbnail.c
+++ b/libcinnamon-desktop/gnome-desktop-thumbnail.c
@@ -1027,52 +1027,74 @@ gnome_desktop_thumbnail_factory_has_valid_failed_thumbnail (GnomeDesktopThumbnai
   return res;
 }
 
+/* forbidden/buggy GdkPixbufFormat names */
+const char *forbidden[] = { "tga", "icns", "jpeg2000" };
+
+static gboolean
+type_is_forbidden (const gchar *name)
+{
+    gint i = 0;
+    for (i = 0; i < G_N_ELEMENTS (forbidden); i++) {
+        if (g_strcmp0 (forbidden[i], name) == 0) {
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
+
 static gboolean
 mimetype_supported_by_gdk_pixbuf (const char *mime_type)
 {
-        guint i;
-        static gsize formats_hash = 0;
-        gchar *key;
-        gboolean result;
+    guint i;
+    static gsize formats_hash = 0;
+    gchar *key;
+    gboolean result;
 
-	if (g_once_init_enter (&formats_hash)) {
-                GSList *formats, *list;
-		GHashTable *hash;
+    if (g_once_init_enter (&formats_hash)) {
+        GSList *formats, *list;
+        GHashTable *hash;
 
-                hash = g_hash_table_new_full (g_str_hash,
-					      (GEqualFunc) g_content_type_equals,
-					      g_free, NULL);
+        hash = g_hash_table_new_full (g_str_hash,
+                                      (GEqualFunc) g_content_type_equals,
+                                      g_free, NULL);
 
-                formats = gdk_pixbuf_get_formats ();
-                list = formats;
+        formats = gdk_pixbuf_get_formats ();
+        list = formats;
 
-                while (list) {
-                        GdkPixbufFormat *format = list->data;
-                        gchar **mime_types;
+        while (list) {
+            GdkPixbufFormat *format = list->data;
+            gchar **mime_types;
 
-                        mime_types = gdk_pixbuf_format_get_mime_types (format);
+            if (type_is_forbidden (format->name)) {
+                gdk_pixbuf_format_set_disabled (format, TRUE);
+                list = list->next;
+                continue;
+            }
 
-                        for (i = 0; mime_types[i] != NULL; i++)
-                                g_hash_table_insert (hash,
-                                                     (gpointer) g_content_type_from_mime_type (mime_types[i]),
-                                                     GUINT_TO_POINTER (1));	
+            mime_types = gdk_pixbuf_format_get_mime_types (format);
 
-                        g_strfreev (mime_types);
-                        list = list->next;
-                }
-                g_slist_free (formats);
+            for (i = 0; mime_types[i] != NULL; i++)
+                g_hash_table_insert (hash,
+                                     (gpointer) g_content_type_from_mime_type (mime_types[i]),
+                                     GUINT_TO_POINTER (1));
 
-		g_once_init_leave (&formats_hash, (gsize) hash);
+            g_strfreev (mime_types);
+            list = list->next;
         }
 
-        key = g_content_type_from_mime_type (mime_type);
-        if (g_hash_table_lookup ((void*)formats_hash, key))
-                result = TRUE;
-        else
-                result = FALSE;
-        g_free (key);
+        g_slist_free (formats);
+
+        g_once_init_leave (&formats_hash, (gsize) hash);
+    }
+
+    key = g_content_type_from_mime_type (mime_type);
+    if (g_hash_table_lookup ((void*)formats_hash, key))
+            result = TRUE;
+    else
+            result = FALSE;
+    g_free (key);
 
-        return result;
+    return result;
 }
 
 /**
-- 
2.4.3