Commit a12e4164 authored by Sergios - Anestis Kefalidis's avatar Sergios - Anestis Kefalidis Committed by Alexander Schwinn
Browse files

Support shared thumbnail repositories of the freedesktop.org thumbnail spec

Related:
libxfce4util!18
thunar!126
thunar#262
parent 50555624
Pipeline #10445 passed with stages
in 2 minutes and 21 seconds
......@@ -148,6 +148,7 @@ PKG_CHECK_MODULES([GIO], [gio-2.0 >= 2.50.0])
PKG_CHECK_MODULES([GIO_UNIX], [gio-unix-2.0 >= 2.50.0])
PKG_CHECK_MODULES([GMODULE], [gmodule-2.0 >= 2.50.0])
PKG_CHECK_MODULES([GTHREAD], [gthread-2.0 >= 2.50.0])
XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.17.1])
dnl *************************
dnl *** Check for plugins ***
......
......@@ -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 = \
......
......@@ -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;
}
......
......@@ -37,6 +37,8 @@
#include <xdg-cache/xdg-cache-cache.h>
#include <xdg-cache/xdg-cache-thumbnail.h>
#include <libxfce4util/libxfce4util.h>
/* Property identifiers */
......@@ -265,24 +267,63 @@ 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;
}
......
......@@ -67,6 +67,7 @@ tumblerd_CFLAGS = \
$(GLIB_CFLAGS) \
$(GTHREAD_CFLAGS) \
$(PLATFORM_CFLAGS) \
$(LIBXFCE4UTIL_CFLAGS) \
$(PLATFORM_CPPFLAGS)
tumblerd_LDFLAGS = \
......@@ -82,6 +83,7 @@ tumblerd_LDADD = \
$(GIO_UNIX_LIBS) \
$(GLIB_LIBS) \
$(GTHREAD_LIBS) \
$(LIBXFCE4UTIL_LIBS) \
$(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la
servicedir = $(datadir)/dbus-1/services
......
......@@ -47,6 +47,8 @@
#include <tumblerd/tumbler-registry.h>
#include <tumblerd/tumbler-service.h>
#include <libxfce4util/libxfce4util.h>
static void
......@@ -74,124 +76,6 @@ xfce_is_valid_tilde_prefix (const gchar *p)
}
/* from libxfce4util */
static gchar *
xfce_expand_variables (const gchar *command,
gchar **envp)
{
GString *buf;
const gchar *start;
gchar *variable;
const gchar *p;
const gchar *value;
gchar **ep;
guint len;
#ifdef HAVE_GETPWNAM
struct passwd *pw;
gchar *username;
#endif
if (G_UNLIKELY (command == NULL))
return NULL;
buf = g_string_sized_new (strlen (command));
for (p = command; *p != '\0'; ++p)
{
continue_without_increase:
if (*p == '~'
&& (p == command
|| xfce_is_valid_tilde_prefix (p - 1)))
{
/* walk to the end of the string or to a directory separator */
for (start = ++p; *p != '\0' && *p != G_DIR_SEPARATOR; ++p);
if (G_LIKELY (start == p))
{
/* add the current user directory */
buf = g_string_append (buf, g_get_home_dir ());
}
else
{
#ifdef HAVE_GETPWNAM
username = g_strndup (start, p - start);
pw = getpwnam (username);
g_free (username);
/* add the users' home directory if found, fallback to the
* not-expanded string */
if (pw != NULL && pw->pw_dir != NULL)
buf = g_string_append (buf, pw->pw_dir);
else
#endif
buf = g_string_append_len (buf, start - 1, p - start + 1);
}
/* we are either at the end of the string or *p is a separator,
* so continue to add it to the result buffer */
}
else if (*p == '$')
{
/* walk to the end of a valid variable name */
for (start = ++p; *p != '\0' && (g_ascii_isalnum (*p) || *p == '_'); ++p);
if (start < p)
{
value = NULL;
len = p - start;
/* lookup the variable in the environment supplied by the user */
if (envp != NULL)
{
/* format is NAME=VALUE */
for (ep = envp; *ep != NULL; ++ep)
if (strncmp (*ep, start, len) == 0
&& (*ep)[len] == '=')
{
value = (*ep) + len + 1;
break;
}
}
/* fallback to the environment */
if (value == NULL)
{
variable = g_strndup (start, len);
value = g_getenv (variable);
g_free (variable);
}
if (G_LIKELY (value != NULL))
{
buf = g_string_append (buf, value);
}
else
{
/* the variable name was valid, but no value was
* found, insert nothing and continue */
}
/* *p is at the start of the charater after the variable,
* so continue scanning without advancing the string offset
* so two variables are replaced properly */
goto continue_without_increase;
}
else
{
/* invalid variable format, add the
* $ character and continue */
--p;
}
}
buf = g_string_append_c (buf, *p);
}
return g_string_free (buf, FALSE);
}
static GSList *
locations_from_strv (gchar **array)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment