Unix Thumbnailing API
GNOME has been carrying a thumbnailing API in gnome-desktop, which was moved from libgnomeui, but gnome-desktop really isn't the right place for a thumbnailing API, as gnome-desktop's shared library's primary consumer should be OS components (gnome-settings-daemon, gnome-shell, gnome-control-center, etc.), not applications.
The main API would look something like this:
typedef enum {
GNOME_DESKTOP_THUMBNAIL_FLAGS_NONE = 0,
GNOME_DESKTOP_THUMBNAIL_FLAGS_SAVE, // Whether to save the created (successful or failed) thumbnail to the cache,
// ret_thumbnail_path is always NULL without it
} GtkUnixThumbnailerFlag;
#define GTK_UNIX_THUMBNAILER_FILE_ATTRIBUTES \
G_FILE_ATTRIBUTE_THUMBNAIL_PATH "," \
G_FILE_ATTRIBUTE_THUMBNAILING_FAILED "," \
G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID "," \
G_FILE_ATTRIBUTE_PREVIEW_ICON "," \
G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC "," \
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE
// About @info:
// NULL means we'll look it up if necessary, otherwise must include
// GNOME_DESKTOP_THUMBNAIL_FILE_ATTRIBUTES,
// G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE will however be used rather
// than G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE if present
// G_FILE_ATTRIBUTE_TIME_MODIFIED_SEC will be used if present and
// G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC is missing
GtkTexture *
gtk_unix_thumbnailer_generate_thumbnail_sync (GtkUnixThumbnailer *thumbnailer,
GFile *file,
GFileInfo *info,
GtkUnixThumbnailerFlag flag,
GCancellable *cancellable,
char **ret_thumbnail_path,
GError **error);
This API is incomplete and would likely also need to include an array of string manipulation helpers to create thumbnail cache paths, and the like.
A couple of notes compared to previous discussions in:
First, we decided that GtkTexture was the right "image" API for this, as GTK is trying to wean itself off GdkPixbuf, and GTK can already read and write PNGs internally.
Second, we prefer G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC
as the time resolution to avoid the problems mentioned in gnome-desktop#17
Finally, I marked the API as GtkUnix, because I'd rather land an API that's as close as possible to the current implementation of thumbnailers on free Unix desktops, before trying to wedge Windows or macOS thumbnailing into the mix. It's probable that Windows and macOS variants of this API would be more restrictive variants that only allowed getting a thumbnail bit of data without any way to manipulate a cache, or force a regeneration.