Skip to content

Commit a2f7f15

Browse files
committed
gnome-desktop-thumbnail.c: Check for a filesystem-supplied preview
icon before running thumbnailers. Some devices that transfer media files can also provide a preview icon for these files, saving the thumbnailer having to load the original files in order to create a preview (which can block file managers from loading the remaining files).
1 parent 3ab6b08 commit a2f7f15

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

libcinnamon-desktop/gnome-desktop-thumbnail.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,58 @@ expand_thumbnailing_script (const char *script,
11751175
return NULL;
11761176
}
11771177

1178+
static GdkPixbuf *
1179+
get_preview_thumbnail (const char *uri,
1180+
int size)
1181+
{
1182+
GdkPixbuf *pixbuf;
1183+
GFile *file;
1184+
g_autoptr(GFileInfo) file_info = NULL;
1185+
GInputStream *input_stream;
1186+
GObject *object;
1187+
1188+
g_return_val_if_fail (uri != NULL, NULL);
1189+
1190+
input_stream = NULL;
1191+
1192+
file = g_file_new_for_uri (uri);
1193+
1194+
/* First see if we can get an input stream via preview::icon */
1195+
file_info = g_file_query_info (file,
1196+
G_FILE_ATTRIBUTE_PREVIEW_ICON,
1197+
G_FILE_QUERY_INFO_NONE,
1198+
NULL, /* GCancellable */
1199+
NULL); /* return location for GError */
1200+
g_object_unref (file);
1201+
1202+
if (file_info == NULL)
1203+
return NULL;
1204+
1205+
object = g_file_info_get_attribute_object (file_info,
1206+
G_FILE_ATTRIBUTE_PREVIEW_ICON);
1207+
1208+
if (!object)
1209+
return NULL;
1210+
if (!G_IS_LOADABLE_ICON (object)) {
1211+
return NULL;
1212+
}
1213+
1214+
input_stream = g_loadable_icon_load (G_LOADABLE_ICON (object),
1215+
0, /* size */
1216+
NULL, /* return location for type */
1217+
NULL, /* GCancellable */
1218+
NULL); /* return location for GError */
1219+
1220+
if (!input_stream)
1221+
return NULL;
1222+
1223+
pixbuf = gdk_pixbuf_new_from_stream_at_scale (input_stream,
1224+
size, size,
1225+
TRUE, NULL, NULL);
1226+
g_object_unref (input_stream);
1227+
return pixbuf;
1228+
}
1229+
11781230
/**
11791231
* gnome_desktop_thumbnail_factory_generate_thumbnail:
11801232
* @factory: a #GnomeDesktopThumbnailFactory
@@ -1217,6 +1269,10 @@ gnome_desktop_thumbnail_factory_generate_thumbnail (GnomeDesktopThumbnailFactory
12171269

12181270
pixbuf = NULL;
12191271

1272+
pixbuf = get_preview_thumbnail (uri, size);
1273+
if (pixbuf != NULL)
1274+
return pixbuf;
1275+
12201276
script = NULL;
12211277
g_mutex_lock (&factory->priv->lock);
12221278

0 commit comments

Comments
 (0)