From 12ffc111c5b9b9c595650a944b5da99453918dbb Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sun, 26 Jun 2016 14:13:44 +0200 Subject: thumbnailer: Always prefer the backend provided preview If a preview exists for a particular file, in particular a preview icon for videos and images on external devices, prefer those to running a script. https://bugzilla.gnome.org/show_bug.cgi?id=738503 origin commit: https://gitlab.gnome.org/GNOME/gnome-desktop/commit/370b985 https://gitlab.gnome.org/GNOME/gnome-desktop/commit/e629e46 https://gitlab.gnome.org/GNOME/gnome-desktop/commit/a15db1d https://gitlab.gnome.org/GNOME/gnome-desktop/commit/fc19c94 --- libmate-desktop/mate-desktop-thumbnail.c | 66 +++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'libmate-desktop/mate-desktop-thumbnail.c') diff --git a/libmate-desktop/mate-desktop-thumbnail.c b/libmate-desktop/mate-desktop-thumbnail.c index 7802684..b00f155 100644 --- a/libmate-desktop/mate-desktop-thumbnail.c +++ b/libmate-desktop/mate-desktop-thumbnail.c @@ -948,6 +948,64 @@ expand_thumbnailing_script (const char *script, return NULL; } +static GdkPixbuf * +get_preview_thumbnail (const char *uri, + int size) +{ + GdkPixbuf *pixbuf; + GFile *file; + GFileInfo *file_info; + GInputStream *input_stream; + GObject *object; + + g_return_val_if_fail (uri != NULL, NULL); + + input_stream = NULL; + + file = g_file_new_for_uri (uri); + + /* First see if we can get an input stream via preview::icon */ + file_info = g_file_query_info (file, + G_FILE_ATTRIBUTE_PREVIEW_ICON, + G_FILE_QUERY_INFO_NONE, + NULL, /* GCancellable */ + NULL); /* return location for GError */ + g_object_unref (file); + + if (file_info == NULL) + return NULL; + + object = g_file_info_get_attribute_object (file_info, + G_FILE_ATTRIBUTE_PREVIEW_ICON); + if (object) + g_object_ref (object); + g_object_unref (file_info); + + if (!object) + return NULL; + if (!G_IS_LOADABLE_ICON (object)) { + g_object_unref (object); + return NULL; + } + + input_stream = g_loadable_icon_load (G_LOADABLE_ICON (object), + 0, /* size */ + NULL, /* return location for type */ + NULL, /* GCancellable */ + NULL); /* return location for GError */ + g_object_unref (object); + + if (!input_stream) + return NULL; + + pixbuf = gdk_pixbuf_new_from_stream_at_scale (input_stream, + size, size, + TRUE, NULL, NULL); + g_object_unref (input_stream); + + return pixbuf; +} + /** * mate_desktop_thumbnail_factory_generate_thumbnail: * @factory: a #MateDesktopThumbnailFactory @@ -965,8 +1023,8 @@ expand_thumbnailing_script (const char *script, **/ GdkPixbuf * mate_desktop_thumbnail_factory_generate_thumbnail (MateDesktopThumbnailFactory *factory, - const char *uri, - const char *mime_type) + const char *uri, + const char *mime_type) { GdkPixbuf *pixbuf; char *script, *expanded_script; @@ -985,6 +1043,10 @@ mate_desktop_thumbnail_factory_generate_thumbnail (MateDesktopThumbnailFactory * pixbuf = NULL; + pixbuf = get_preview_thumbnail (uri, size); + if (pixbuf != NULL) + return pixbuf; + script = NULL; g_mutex_lock (&factory->priv->lock); if (!mate_desktop_thumbnail_factory_is_disabled (factory, mime_type)) -- cgit v1.2.1