From 05fb1ad4a38eedde18dd80e56db5d2f12a200098 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Tue, 30 Oct 2012 15:33:33 +0100 Subject: [PATCH] Use new location for thumbnails directory as per thumbnails std 8.0 --- src/common/rclinit.cpp | 3 +++ src/utils/pathut.cpp | 50 ++++++++++++++++++++++++++++++++++-------- src/utils/pathut.h | 3 +++ 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/common/rclinit.cpp b/src/common/rclinit.cpp index 1578a9e5..3e798ec2 100644 --- a/src/common/rclinit.cpp +++ b/src/common/rclinit.cpp @@ -111,6 +111,9 @@ RclConfig *recollinit(RclInitFlags flags, // Init unac locking unac_init_mt(); + // Init pathut static values + pathut_init_mt(); + // Init Unac translation exceptions string unacex; if (config->getConfParam("unac_except_trans", unacex) && !unacex.empty()) diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index adce8b21..c4254fa7 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -28,6 +28,7 @@ #include #include #include +#include // Let's include all files where statfs can be defined and hope for no // conflict... @@ -359,10 +360,8 @@ extern string path_canon(const string &is) return ret; } -#include -#include -vector path_dirglob(const string &dir, - const string pattern) + +vector path_dirglob(const string &dir, const string pattern) { vector res; glob_t mglob; @@ -626,12 +625,36 @@ int Pidfile::remove() return unlink(m_path.c_str()); } -// Freedesktop standard paths for thumbnails + +// Freedesktop standard paths for cache directory (thumbnails are now in there) +static const string& xdgcachedir() +{ + static string xdgcache; + if (xdgcache.empty()) { + const char *cp = getenv("XDG_CACHE_HOME"); + if (cp == 0) + xdgcache = path_cat(path_home(), ".cache"); + else + xdgcache = string(cp); + } + return xdgcache; +} +static const string& thumbnailsdir() +{ + static string thumbnailsd; + if (thumbnailsd.empty()) { + thumbnailsd = path_cat(xdgcachedir(), "thumbnails"); + if (access(thumbnailsd.c_str(), 0) != 0) { + thumbnailsd = path_cat(path_home(), ".thumbnails"); + } + } + return thumbnailsd; +} // Place for 256x256 files -static const string thmbdirlarge = ".thumbnails/large"; +static const string thmbdirlarge = "large"; // 128x128 -static const string thmbdirnormal = ".thumbnails/normal"; +static const string thmbdirnormal = "normal"; static void thumbname(const string& url, string& name) { @@ -647,13 +670,13 @@ bool thumbPathForUrl(const string& url, int size, string& path) string name; thumbname(url, name); if (size <= 128) { - path = path_cat(path_home(), thmbdirnormal); + path = path_cat(thumbnailsdir(), thmbdirnormal); path = path_cat(path, name); if (access(path.c_str(), R_OK) == 0) { return true; } } - path = path_cat(path_home(), thmbdirlarge); + path = path_cat(thumbnailsdir(), thmbdirlarge); path = path_cat(path, name); if (access(path.c_str(), R_OK) == 0) { return true; @@ -668,6 +691,15 @@ bool thumbPathForUrl(const string& url, int size, string& path) return false; } +// Call funcs that need static init (not initially reentrant) +void pathut_init_mt() +{ + path_home(); + tmplocation(); + thumbnailsdir(); +} + + #else // TEST_PATHUT #include #include diff --git a/src/utils/pathut.h b/src/utils/pathut.h index 4d9ce34d..0cf169e5 100644 --- a/src/utils/pathut.h +++ b/src/utils/pathut.h @@ -138,4 +138,7 @@ private: // returns true if the file already exists extern bool thumbPathForUrl(const string& url, int size, string& path); +// Must be called in main thread before starting other threads +extern void pathut_init_mt(); + #endif /* _PATHUT_H_INCLUDED_ */