diff options
author | Sergios - Anestis Kefalidis <megistios@gmail.com> | 2021-07-24 13:34:25 +0000 |
---|---|---|
committer | Alexander Schwinn <alexxcons@xfce.org> | 2021-07-24 13:34:25 +0000 |
commit | a12e4164e1095aad9ca557c75887f1490f39f08b (patch) | |
tree | f748019eac2d938a055422147b6c2a90e042bcd3 /plugins | |
parent | 50555624288c9f4237fc7661ff15b8990afb7aab (diff) | |
download | tumbler-a12e4164e1095aad9ca557c75887f1490f39f08b.tar.gz |
Support shared thumbnail repositories of the freedesktop.org thumbnail spec
Related:
https://gitlab.xfce.org/xfce/libxfce4util/-/merge_requests/18
https://gitlab.xfce.org/xfce/thunar/-/merge_requests/126
https://gitlab.xfce.org/xfce/thunar/-/issues/262
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/xdg-cache/Makefile.am | 2 | ||||
-rw-r--r-- | plugins/xdg-cache/xdg-cache-cache.c | 9 | ||||
-rw-r--r-- | plugins/xdg-cache/xdg-cache-thumbnail.c | 53 |
3 files changed, 57 insertions, 7 deletions
diff --git a/plugins/xdg-cache/Makefile.am b/plugins/xdg-cache/Makefile.am index 2aba1eb..ad71c9f 100644 --- a/plugins/xdg-cache/Makefile.am +++ b/plugins/xdg-cache/Makefile.am @@ -42,6 +42,7 @@ tumbler_xdg_cache_la_CFLAGS = \ $(GLIB_CFLAGS) \ $(PLATFORM_CFLAGS) \ $(PLATFORM_CPPFLAGS) \ + $(LIBXFCE4UTIL_CFLAGS) \ $(PNG_CFLAGS) tumbler_xdg_cache_la_LDFLAGS = \ @@ -55,6 +56,7 @@ tumbler_xdg_cache_la_LIBADD = \ $(GDK_PIXBUF_LIBS) \ $(GIO_LIBS) \ $(GLIB_LIBS) \ + $(LIBXFCE4UTIL_LIBS) \ $(PNG_LIBS) tumbler_xdg_cache_la_DEPENDENCIES = \ diff --git a/plugins/xdg-cache/xdg-cache-cache.c b/plugins/xdg-cache/xdg-cache-cache.c index d7f2b42..d68db3e 100644 --- a/plugins/xdg-cache/xdg-cache-cache.c +++ b/plugins/xdg-cache/xdg-cache-cache.c @@ -537,6 +537,7 @@ xdg_cache_cache_is_thumbnail (TumblerCache *cache, GFile *flavor_dir; GFile *file; gchar *path; + gchar *needle; g_return_val_if_fail (XDG_CACHE_IS_CACHE (cache), FALSE); g_return_val_if_fail (uri != NULL, FALSE); @@ -559,7 +560,13 @@ xdg_cache_cache_is_thumbnail (TumblerCache *cache, g_free (path); } - return is_thumbnail; + if (is_thumbnail) + return TRUE; + + /* check if it is a thumbnail in a shared repository */ + needle = g_strrstr (uri, "/.sh_thumbnails/"); + + return needle != NULL; } diff --git a/plugins/xdg-cache/xdg-cache-thumbnail.c b/plugins/xdg-cache/xdg-cache-thumbnail.c index ea6a0d8..e5d8344 100644 --- a/plugins/xdg-cache/xdg-cache-thumbnail.c +++ b/plugins/xdg-cache/xdg-cache-thumbnail.c @@ -37,6 +37,8 @@ #include <xdg-cache/xdg-cache-cache.h> #include <xdg-cache/xdg-cache-thumbnail.h> +#include <libxfce4util/libxfce4util.h> + /* Property identifiers */ @@ -266,23 +268,62 @@ xdg_cache_thumbnail_load (TumblerThumbnail *thumbnail, static gboolean +has_valid_shared_thumbnail (const gchar *uri, + const gchar *size, + guint64 mtime) +{ + gchar *thumbnail_path; + gboolean found; + + thumbnail_path = xfce_create_shared_thumbnail_path (uri, size); + + if (g_file_test (thumbnail_path, G_FILE_TEST_EXISTS)) + { + guint64 thumb_mtime; + gchar *thumb_uri; + + if (xdg_cache_cache_read_thumbnail_info (thumbnail_path, &thumb_uri, &thumb_mtime, NULL, NULL)) + found = mtime == thumb_mtime; + else + found = FALSE; + } + else + found = FALSE; + + /* free memory */ + g_free (thumbnail_path); + + return found; +} + + + +static gboolean xdg_cache_thumbnail_needs_update (TumblerThumbnail *thumbnail, const gchar *uri, guint64 mtime) { XDGCacheThumbnail *cache_thumbnail = XDG_CACHE_THUMBNAIL (thumbnail); + gboolean is_valid = TRUE; g_return_val_if_fail (XDG_CACHE_IS_THUMBNAIL (thumbnail), FALSE); g_return_val_if_fail (uri != NULL && *uri != '\0', FALSE); - if (cache_thumbnail->cached_uri == NULL) - return TRUE; + if (cache_thumbnail->cached_uri == NULL + || cache_thumbnail->cached_mtime == 0 + || strcmp (cache_thumbnail->uri, uri) != 0 + || cache_thumbnail->cached_mtime != mtime) + { + is_valid = FALSE; + } - if (cache_thumbnail->cached_mtime == 0) - return TRUE; + if (!is_valid) /* if the personal repository is invalid, look for a shared thumbnail repository */ + { + if (has_valid_shared_thumbnail (uri, tumbler_thumbnail_flavor_get_name (cache_thumbnail->flavor), mtime)) + return FALSE; + } - return strcmp (cache_thumbnail->uri, uri) != 0 - || cache_thumbnail->cached_mtime != mtime; + return !is_valid; } |