mate-desktop 1.29.2
Library with common API for various MATE modules
Loading...
Searching...
No Matches
mate-desktop-thumbnail.c File Reference
View source
#include <config.h>
#include <glib.h>
#include <glib/gstdio.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <string.h>
#include <stdlib.h>
#include "mate-desktop-thumbnail.h"
Include dependency graph for mate-desktop-thumbnail.c:

Data Structures

struct  _MateDesktopThumbnailFactoryPrivate
 

Macros

#define MATE_DESKTOP_USE_UNSTABLE_API
 
#define parent_class   mate_desktop_thumbnail_factory_parent_class
 
#define THUMBNAILER_ENTRY_GROUP   "Thumbnailer Entry"
 
#define THUMBNAILER_EXTENSION   ".thumbnailer"
 

Functions

static void thumbnailers_directory_changed (GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, MateDesktopThumbnailFactory *factory)
 
 G_DEFINE_TYPE_WITH_PRIVATE (MateDesktopThumbnailFactory, mate_desktop_thumbnail_factory, G_TYPE_OBJECT)
 
static Thumbnailer * thumbnailer_ref (Thumbnailer *thumb)
 
static void thumbnailer_unref (Thumbnailer *thumb)
 
static Thumbnailer * thumbnailer_load (Thumbnailer *thumb)
 
static Thumbnailer * thumbnailer_reload (Thumbnailer *thumb)
 
static Thumbnailer * thumbnailer_new (const gchar *path)
 
static gboolean thumbnailer_try_exec (Thumbnailer *thumb)
 
static gpointer init_thumbnailers_dirs (gpointer data)
 
static const gchar *const * get_thumbnailers_dirs (void)
 
static void mate_desktop_thumbnail_factory_register_mime_types (MateDesktopThumbnailFactory *factory, Thumbnailer *thumb)
 
static void mate_desktop_thumbnail_factory_add_thumbnailer (MateDesktopThumbnailFactory *factory, Thumbnailer *thumb)
 
static gboolean mate_desktop_thumbnail_factory_is_disabled (MateDesktopThumbnailFactory *factory, const gchar *mime_type)
 
static gboolean remove_thumbnailer_from_mime_type_map (gchar *key, Thumbnailer *value, gchar *path)
 
static void update_or_create_thumbnailer (MateDesktopThumbnailFactory *factory, const gchar *path)
 
static void remove_thumbnailer (MateDesktopThumbnailFactory *factory, const gchar *path)
 
static void remove_thumbnailers_for_dir (MateDesktopThumbnailFactory *factory, const gchar *thumbnailer_dir, GFileMonitor *monitor)
 
static void mate_desktop_thumbnail_factory_load_thumbnailers_for_dir (MateDesktopThumbnailFactory *factory, const gchar *path)
 
static void mate_desktop_thumbnail_factory_load_thumbnailers (MateDesktopThumbnailFactory *factory)
 
static void external_thumbnailers_disabled_all_changed_cb (GSettings *settings, const gchar *key, MateDesktopThumbnailFactory *factory)
 
static void external_thumbnailers_disabled_changed_cb (GSettings *settings, const gchar *key, MateDesktopThumbnailFactory *factory)
 
static void mate_desktop_thumbnail_factory_init (MateDesktopThumbnailFactory *factory)
 
static void mate_desktop_thumbnail_factory_finalize (GObject *object)
 
static void mate_desktop_thumbnail_factory_class_init (MateDesktopThumbnailFactoryClass *class)
 
MateDesktopThumbnailFactory * mate_desktop_thumbnail_factory_new (MateDesktopThumbnailSize size)
 mate_desktop_thumbnail_factory_new: @size: The thumbnail size to use
 
static char * thumbnail_filename (const char *uri)
 
static char * thumbnail_path (const char *uri, MateDesktopThumbnailSize size)
 
static char * thumbnail_failed_path (const char *uri)
 
static char * validate_thumbnail_path (char *path, const char *uri, time_t mtime, MateDesktopThumbnailSize size)
 
static char * lookup_thumbnail_path (const char *uri, time_t mtime, MateDesktopThumbnailSize size)
 
static char * lookup_failed_thumbnail_path (const char *uri, time_t mtime, MateDesktopThumbnailSize size)
 
char * mate_desktop_thumbnail_factory_lookup (MateDesktopThumbnailFactory *factory, const char *uri, time_t mtime)
 mate_desktop_thumbnail_factory_lookup: @factory: a MateDesktopThumbnailFactory @uri: the uri of a file @mtime: the mtime of the file
 
gboolean mate_desktop_thumbnail_factory_has_valid_failed_thumbnail (MateDesktopThumbnailFactory *factory, const char *uri, time_t mtime)
 mate_desktop_thumbnail_factory_has_valid_failed_thumbnail: @factory: a MateDesktopThumbnailFactory @uri: the uri of a file @mtime: the mtime of the file
 
gboolean mate_desktop_thumbnail_factory_can_thumbnail (MateDesktopThumbnailFactory *factory, const char *uri, const char *mime_type, time_t mtime)
 mate_desktop_thumbnail_factory_can_thumbnail: @factory: a MateDesktopThumbnailFactory @uri: the uri of a file @mime_type: the mime type of the file @mtime: the mtime of the file
 
static char * expand_thumbnailing_elem (const char *elem, const int size, const char *inuri, const char *outfile, gboolean *got_input, gboolean *got_output)
 
static char ** expand_thumbnailing_script (const char *script, const int size, const char *inuri, const char *outfile, GError **error)
 
static GdkPixbuf * get_preview_thumbnail (const char *uri, int size)
 
GdkPixbuf * mate_desktop_thumbnail_factory_generate_thumbnail (MateDesktopThumbnailFactory *factory, const char *uri, const char *mime_type)
 mate_desktop_thumbnail_factory_generate_thumbnail: @factory: a MateDesktopThumbnailFactory @uri: the uri of a file @mime_type: the mime type of the file
 
static gboolean save_thumbnail (GdkPixbuf *pixbuf, char *path, const char *uri, time_t mtime)
 
static GdkPixbuf * make_failed_thumbnail (void)
 
void mate_desktop_thumbnail_factory_save_thumbnail (MateDesktopThumbnailFactory *factory, GdkPixbuf *thumbnail, const char *uri, time_t original_mtime)
 mate_desktop_thumbnail_factory_save_thumbnail: @factory: a MateDesktopThumbnailFactory @thumbnail: the thumbnail as a pixbuf @uri: the uri of a file @original_mtime: the modification time of the original file
 
void mate_desktop_thumbnail_factory_create_failed_thumbnail (MateDesktopThumbnailFactory *factory, const char *uri, time_t mtime)
 mate_desktop_thumbnail_factory_create_failed_thumbnail: @factory: a MateDesktopThumbnailFactory @uri: the uri of a file @mtime: the modification time of the file
 
char * mate_desktop_thumbnail_path_for_uri (const char *uri, MateDesktopThumbnailSize size)
 mate_desktop_thumbnail_path_for_uri: @uri: an uri @size: a thumbnail size
 
gboolean mate_desktop_thumbnail_has_uri (GdkPixbuf *pixbuf, const char *uri)
 mate_desktop_thumbnail_has_uri: @pixbuf: an loaded thumbnail pixbuf @uri: a uri
 
gboolean mate_desktop_thumbnail_is_valid (GdkPixbuf *pixbuf, const char *uri, time_t mtime)
 mate_desktop_thumbnail_is_valid: @pixbuf: an loaded thumbnail #GdkPixbuf @uri: a uri @mtime: the mtime
 

Variables

static const char * appname = "mate-thumbnail-factory"
 
 Thumbnailer
 

Macro Definition Documentation

◆ MATE_DESKTOP_USE_UNSTABLE_API

#define MATE_DESKTOP_USE_UNSTABLE_API

◆ parent_class

#define parent_class   mate_desktop_thumbnail_factory_parent_class

◆ THUMBNAILER_ENTRY_GROUP

#define THUMBNAILER_ENTRY_GROUP   "Thumbnailer Entry"

◆ THUMBNAILER_EXTENSION

#define THUMBNAILER_EXTENSION   ".thumbnailer"

Function Documentation

◆ expand_thumbnailing_elem()

static char * expand_thumbnailing_elem ( const char *  elem,
const int  size,
const char *  inuri,
const char *  outfile,
gboolean *  got_input,
gboolean *  got_output 
)
static

◆ expand_thumbnailing_script()

static char ** expand_thumbnailing_script ( const char *  script,
const int  size,
const char *  inuri,
const char *  outfile,
GError **  error 
)
static

References expand_thumbnailing_elem().

Referenced by mate_desktop_thumbnail_factory_generate_thumbnail().

Here is the call graph for this function:

◆ external_thumbnailers_disabled_all_changed_cb()

static void external_thumbnailers_disabled_all_changed_cb ( GSettings *  settings,
const gchar *  key,
MateDesktopThumbnailFactory *  factory 
)
static

◆ external_thumbnailers_disabled_changed_cb()

◆ G_DEFINE_TYPE_WITH_PRIVATE()

G_DEFINE_TYPE_WITH_PRIVATE ( MateDesktopThumbnailFactory  ,
mate_desktop_thumbnail_factory  ,
G_TYPE_OBJECT   
)

◆ get_preview_thumbnail()

static GdkPixbuf * get_preview_thumbnail ( const char *  uri,
int  size 
)
static

◆ get_thumbnailers_dirs()

static const gchar *const * get_thumbnailers_dirs ( void  )
static

References init_thumbnailers_dirs().

Referenced by mate_desktop_thumbnail_factory_load_thumbnailers().

Here is the call graph for this function:

◆ init_thumbnailers_dirs()

static gpointer init_thumbnailers_dirs ( gpointer  data)
static

Referenced by get_thumbnailers_dirs().

◆ lookup_failed_thumbnail_path()

static char * lookup_failed_thumbnail_path ( const char *  uri,
time_t  mtime,
MateDesktopThumbnailSize  size 
)
static

References thumbnail_failed_path(), and validate_thumbnail_path().

Referenced by mate_desktop_thumbnail_factory_has_valid_failed_thumbnail().

Here is the call graph for this function:

◆ lookup_thumbnail_path()

static char * lookup_thumbnail_path ( const char *  uri,
time_t  mtime,
MateDesktopThumbnailSize  size 
)
static

References thumbnail_path(), and validate_thumbnail_path().

Referenced by mate_desktop_thumbnail_factory_lookup().

Here is the call graph for this function:

◆ make_failed_thumbnail()

static GdkPixbuf * make_failed_thumbnail ( void  )
static

◆ mate_desktop_thumbnail_factory_add_thumbnailer()

static void mate_desktop_thumbnail_factory_add_thumbnailer ( MateDesktopThumbnailFactory *  factory,
Thumbnailer *  thumb 
)
static

References mate_desktop_thumbnail_factory_register_mime_types(), _MateDesktopThumbnailFactory::priv, and _MateDesktopThumbnailFactoryPrivate::thumbnailers.

Referenced by mate_desktop_thumbnail_factory_load_thumbnailers_for_dir(), and update_or_create_thumbnailer().

Here is the call graph for this function:

◆ mate_desktop_thumbnail_factory_can_thumbnail()

gboolean mate_desktop_thumbnail_factory_can_thumbnail ( MateDesktopThumbnailFactory *  factory,
const char *  uri,
const char *  mime_type,
time_t  mtime 
)

mate_desktop_thumbnail_factory_can_thumbnail: @factory: a MateDesktopThumbnailFactory @uri: the uri of a file @mime_type: the mime type of the file @mtime: the mtime of the file

Returns TRUE if this MateDesktopThumbnailFactory can (at least try) to thumbnail this file. Thumbnails or files with failed thumbnails won't be thumbnailed.

Usage of this function is threadsafe.

Return value: TRUE if the file can be thumbnailed.

Since: 2.2

References _MateDesktopThumbnailFactoryPrivate::lock, mate_desktop_thumbnail_factory_has_valid_failed_thumbnail(), mate_desktop_thumbnail_factory_is_disabled(), _MateDesktopThumbnailFactoryPrivate::mime_types_map, _MateDesktopThumbnailFactory::priv, Thumbnailer, and thumbnailer_try_exec().

Here is the call graph for this function:

◆ mate_desktop_thumbnail_factory_class_init()

static void mate_desktop_thumbnail_factory_class_init ( MateDesktopThumbnailFactoryClass *  class)
static

References mate_desktop_thumbnail_factory_finalize().

Here is the call graph for this function:

◆ mate_desktop_thumbnail_factory_create_failed_thumbnail()

void mate_desktop_thumbnail_factory_create_failed_thumbnail ( MateDesktopThumbnailFactory *  factory,
const char *  uri,
time_t  mtime 
)

mate_desktop_thumbnail_factory_create_failed_thumbnail: @factory: a MateDesktopThumbnailFactory @uri: the uri of a file @mtime: the modification time of the file

Creates a failed thumbnail for the file so that we don't try to re-thumbnail the file later.

Usage of this function is threadsafe.

Since: 2.2

References make_failed_thumbnail(), save_thumbnail(), and thumbnail_failed_path().

Referenced by create_thumbnail_for_filename().

Here is the call graph for this function:

◆ mate_desktop_thumbnail_factory_finalize()

◆ mate_desktop_thumbnail_factory_generate_thumbnail()

GdkPixbuf * mate_desktop_thumbnail_factory_generate_thumbnail ( MateDesktopThumbnailFactory *  factory,
const char *  uri,
const char *  mime_type 
)

mate_desktop_thumbnail_factory_generate_thumbnail: @factory: a MateDesktopThumbnailFactory @uri: the uri of a file @mime_type: the mime type of the file

Tries to generate a thumbnail for the specified file. If it succeeds it returns a pixbuf that can be used as a thumbnail.

Usage of this function is threadsafe.

Return value: (transfer full): thumbnail pixbuf if thumbnailing succeeded, NULL otherwise.

Since: 2.2

References expand_thumbnailing_script(), get_preview_thumbnail(), _MateDesktopThumbnailFactoryPrivate::lock, mate_desktop_thumbnail_factory_is_disabled(), MATE_DESKTOP_THUMBNAIL_SIZE_LARGE, _MateDesktopThumbnailFactoryPrivate::mime_types_map, _MateDesktopThumbnailFactory::priv, _MateDesktopThumbnailFactoryPrivate::size, and Thumbnailer.

Referenced by main().

Here is the call graph for this function:

◆ mate_desktop_thumbnail_factory_has_valid_failed_thumbnail()

gboolean mate_desktop_thumbnail_factory_has_valid_failed_thumbnail ( MateDesktopThumbnailFactory *  factory,
const char *  uri,
time_t  mtime 
)

mate_desktop_thumbnail_factory_has_valid_failed_thumbnail: @factory: a MateDesktopThumbnailFactory @uri: the uri of a file @mtime: the mtime of the file

Tries to locate an failed thumbnail for the file specified. Writing and looking for failed thumbnails is important to avoid to try to thumbnail e.g. broken images several times.

Usage of this function is threadsafe.

Return value: TRUE if there is a failed thumbnail for the file.

Since: 2.2

References lookup_failed_thumbnail_path(), _MateDesktopThumbnailFactory::priv, and _MateDesktopThumbnailFactoryPrivate::size.

Referenced by mate_desktop_thumbnail_factory_can_thumbnail().

Here is the call graph for this function:

◆ mate_desktop_thumbnail_factory_init()

◆ mate_desktop_thumbnail_factory_is_disabled()

◆ mate_desktop_thumbnail_factory_load_thumbnailers()

static void mate_desktop_thumbnail_factory_load_thumbnailers ( MateDesktopThumbnailFactory *  factory)
static

References get_thumbnailers_dirs(), _MateDesktopThumbnailFactoryPrivate::loaded, mate_desktop_thumbnail_factory_load_thumbnailers_for_dir(), and _MateDesktopThumbnailFactory::priv.

Referenced by external_thumbnailers_disabled_all_changed_cb(), and mate_desktop_thumbnail_factory_init().

Here is the call graph for this function:

◆ mate_desktop_thumbnail_factory_load_thumbnailers_for_dir()

static void mate_desktop_thumbnail_factory_load_thumbnailers_for_dir ( MateDesktopThumbnailFactory *  factory,
const gchar *  path 
)
static

◆ mate_desktop_thumbnail_factory_lookup()

char * mate_desktop_thumbnail_factory_lookup ( MateDesktopThumbnailFactory *  factory,
const char *  uri,
time_t  mtime 
)

mate_desktop_thumbnail_factory_lookup: @factory: a MateDesktopThumbnailFactory @uri: the uri of a file @mtime: the mtime of the file

Tries to locate an existing thumbnail for the file specified.

Usage of this function is threadsafe.

Return value: (transfer full): The absolute path of the thumbnail, or NULL if none exist.

Since: 2.2

References lookup_thumbnail_path(), _MateDesktopThumbnailFactory::priv, and _MateDesktopThumbnailFactoryPrivate::size.

Referenced by create_thumbnail_for_filename().

Here is the call graph for this function:

◆ mate_desktop_thumbnail_factory_new()

MateDesktopThumbnailFactory * mate_desktop_thumbnail_factory_new ( MateDesktopThumbnailSize  size)

mate_desktop_thumbnail_factory_new: @size: The thumbnail size to use

Creates a new MateDesktopThumbnailFactory.

This function must be called on the main thread.

Return value: a new MateDesktopThumbnailFactory

Since: 2.2

References MATE_DESKTOP_TYPE_THUMBNAIL_FACTORY, _MateDesktopThumbnailFactory::priv, and _MateDesktopThumbnailFactoryPrivate::size.

Referenced by main().

◆ mate_desktop_thumbnail_factory_register_mime_types()

static void mate_desktop_thumbnail_factory_register_mime_types ( MateDesktopThumbnailFactory *  factory,
Thumbnailer *  thumb 
)
static

References _MateDesktopThumbnailFactoryPrivate::mime_types_map, _MateDesktopThumbnailFactory::priv, and thumbnailer_ref().

Referenced by mate_desktop_thumbnail_factory_add_thumbnailer(), and update_or_create_thumbnailer().

Here is the call graph for this function:

◆ mate_desktop_thumbnail_factory_save_thumbnail()

void mate_desktop_thumbnail_factory_save_thumbnail ( MateDesktopThumbnailFactory *  factory,
GdkPixbuf *  thumbnail,
const char *  uri,
time_t  original_mtime 
)

mate_desktop_thumbnail_factory_save_thumbnail: @factory: a MateDesktopThumbnailFactory @thumbnail: the thumbnail as a pixbuf @uri: the uri of a file @original_mtime: the modification time of the original file

Saves @thumbnail at the right place. If the save fails a failed thumbnail is written.

Usage of this function is threadsafe.

Since: 2.2

References make_failed_thumbnail(), _MateDesktopThumbnailFactory::priv, save_thumbnail(), _MateDesktopThumbnailFactoryPrivate::size, thumbnail_failed_path(), and thumbnail_path().

Referenced by create_thumbnail_for_filename().

Here is the call graph for this function:

◆ mate_desktop_thumbnail_has_uri()

gboolean mate_desktop_thumbnail_has_uri ( GdkPixbuf *  pixbuf,
const char *  uri 
)

mate_desktop_thumbnail_has_uri: @pixbuf: an loaded thumbnail pixbuf @uri: a uri

Returns whether the thumbnail has the correct uri embedded in the Thumb::URI option in the png.

Return value: TRUE if the thumbnail is for @uri

Since: 2.2

◆ mate_desktop_thumbnail_is_valid()

gboolean mate_desktop_thumbnail_is_valid ( GdkPixbuf *  pixbuf,
const char *  uri,
time_t  mtime 
)

mate_desktop_thumbnail_is_valid: @pixbuf: an loaded thumbnail #GdkPixbuf @uri: a uri @mtime: the mtime

Returns whether the thumbnail has the correct uri and mtime embedded in the png options.

Return value: TRUE if the thumbnail has the right @uri and @mtime

Since: 2.2

Referenced by validate_thumbnail_path().

◆ mate_desktop_thumbnail_path_for_uri()

char * mate_desktop_thumbnail_path_for_uri ( const char *  uri,
MateDesktopThumbnailSize  size 
)

mate_desktop_thumbnail_path_for_uri: @uri: an uri @size: a thumbnail size

Returns the filename that a thumbnail of size @size for @uri would have.

Return value: an absolute filename

Since: 2.2

References thumbnail_path().

Here is the call graph for this function:

◆ remove_thumbnailer()

static void remove_thumbnailer ( MateDesktopThumbnailFactory *  factory,
const gchar *  path 
)
static

References _MateDesktopThumbnailFactoryPrivate::lock, _MateDesktopThumbnailFactoryPrivate::mime_types_map, _MateDesktopThumbnailFactory::priv, remove_thumbnailer_from_mime_type_map(), Thumbnailer, thumbnailer_unref(), and _MateDesktopThumbnailFactoryPrivate::thumbnailers.

Referenced by thumbnailers_directory_changed().

Here is the call graph for this function:

◆ remove_thumbnailer_from_mime_type_map()

static gboolean remove_thumbnailer_from_mime_type_map ( gchar *  key,
Thumbnailer *  value,
gchar *  path 
)
static

◆ remove_thumbnailers_for_dir()

static void remove_thumbnailers_for_dir ( MateDesktopThumbnailFactory *  factory,
const gchar *  thumbnailer_dir,
GFileMonitor *  monitor 
)
static

◆ save_thumbnail()

static gboolean save_thumbnail ( GdkPixbuf *  pixbuf,
char *  path,
const char *  uri,
time_t  mtime 
)
static

◆ thumbnail_failed_path()

static char * thumbnail_failed_path ( const char *  uri)
static

References appname, and thumbnail_filename().

Referenced by lookup_failed_thumbnail_path(), mate_desktop_thumbnail_factory_create_failed_thumbnail(), and mate_desktop_thumbnail_factory_save_thumbnail().

Here is the call graph for this function:

◆ thumbnail_filename()

static char * thumbnail_filename ( const char *  uri)
static

◆ thumbnail_path()

static char * thumbnail_path ( const char *  uri,
MateDesktopThumbnailSize  size 
)
static

References MATE_DESKTOP_THUMBNAIL_SIZE_LARGE, and thumbnail_filename().

Referenced by lookup_thumbnail_path(), mate_desktop_thumbnail_factory_save_thumbnail(), and mate_desktop_thumbnail_path_for_uri().

Here is the call graph for this function:

◆ thumbnailer_load()

static Thumbnailer * thumbnailer_load ( Thumbnailer *  thumb)
static

References THUMBNAILER_ENTRY_GROUP, and thumbnailer_unref().

Referenced by thumbnailer_new(), and thumbnailer_reload().

Here is the call graph for this function:

◆ thumbnailer_new()

static Thumbnailer * thumbnailer_new ( const gchar *  path)
static

References Thumbnailer, and thumbnailer_load().

Referenced by mate_desktop_thumbnail_factory_load_thumbnailers_for_dir(), and update_or_create_thumbnailer().

Here is the call graph for this function:

◆ thumbnailer_ref()

static Thumbnailer * thumbnailer_ref ( Thumbnailer *  thumb)
static

◆ thumbnailer_reload()

static Thumbnailer * thumbnailer_reload ( Thumbnailer *  thumb)
static

References thumbnailer_load().

Referenced by update_or_create_thumbnailer().

Here is the call graph for this function:

◆ thumbnailer_try_exec()

static gboolean thumbnailer_try_exec ( Thumbnailer *  thumb)
static

◆ thumbnailer_unref()

◆ thumbnailers_directory_changed()

static void thumbnailers_directory_changed ( GFileMonitor *  monitor,
GFile *  file,
GFile *  other_file,
GFileMonitorEvent  event_type,
MateDesktopThumbnailFactory *  factory 
)
static

References mate_desktop_thumbnail_factory_load_thumbnailers_for_dir(), remove_thumbnailer(), remove_thumbnailers_for_dir(), THUMBNAILER_EXTENSION, and update_or_create_thumbnailer().

Referenced by mate_desktop_thumbnail_factory_load_thumbnailers_for_dir(), and remove_thumbnailers_for_dir().

Here is the call graph for this function:

◆ update_or_create_thumbnailer()

static void update_or_create_thumbnailer ( MateDesktopThumbnailFactory *  factory,
const gchar *  path 
)
static

◆ validate_thumbnail_path()

static char * validate_thumbnail_path ( char *  path,
const char *  uri,
time_t  mtime,
MateDesktopThumbnailSize  size 
)
static

References mate_desktop_thumbnail_is_valid().

Referenced by lookup_failed_thumbnail_path(), and lookup_thumbnail_path().

Here is the call graph for this function:

Variable Documentation

◆ appname

const char* appname = "mate-thumbnail-factory"
static

Referenced by thumbnail_failed_path().

◆ Thumbnailer