diff options
Diffstat (limited to 'libmate-desktop/mate-desktop-thumbnail.c')
-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)) |