diff options
author | Bastien Nocera <[email protected]> | 2016-06-26 14:13:44 +0200 |
---|---|---|
committer | raveit65 <[email protected]> | 2020-01-09 00:06:04 +0100 |
commit | 12ffc111c5b9b9c595650a944b5da99453918dbb (patch) | |
tree | 54c65eb3ef367c242335d78f9b3a744a5b3018ed | |
parent | e9884b43e1643d1e751a5cb03f653fcd00e585e4 (diff) | |
download | mate-desktop-12ffc111c5b9b9c595650a944b5da99453918dbb.tar.bz2 mate-desktop-12ffc111c5b9b9c595650a944b5da99453918dbb.tar.xz |
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
-rw-r--r-- | libmate-desktop/mate-desktop-thumbnail.c | 66 |
1 files changed, 64 insertions, 2 deletions
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)) |