[gnome-desktop] thumbnailer: Always prefer the backend provided preview
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop] thumbnailer: Always prefer the backend provided preview
- Date: Tue, 13 Dec 2016 11:19:57 +0000 (UTC)
commit 370b985d23c55f6bfdbe9cffbff7c3b5d86737f9
Author: Bastien Nocera <hadess hadess net>
Date: Sun Jun 26 14:13:44 2016 +0200
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
libgnome-desktop/gnome-desktop-thumbnail.c | 60 ++++++++++++++++++++++++++++
1 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/libgnome-desktop/gnome-desktop-thumbnail.c b/libgnome-desktop/gnome-desktop-thumbnail.c
index 0605a76..775c578 100644
--- a/libgnome-desktop/gnome-desktop-thumbnail.c
+++ b/libgnome-desktop/gnome-desktop-thumbnail.c
@@ -1049,6 +1049,62 @@ 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);
+ 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;
+}
+
/**
* gnome_desktop_thumbnail_factory_generate_thumbnail:
* @factory: a #GnomeDesktopThumbnailFactory
@@ -1086,6 +1142,10 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
pixbuf = NULL;
+ pixbuf = get_preview_thumbnail (uri, size);
+ if (pixbuf != NULL)
+ return pixbuf;
+
script = NULL;
g_mutex_lock (&factory->priv->lock);
if (!gnome_desktop_thumbnail_factory_is_disabled (factory, mime_type))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]