[Bf-blender-cvs] [be8b4b8] master: Todo T36849: support XDG thumbnail management standard

Campbell Barton noreply at git.blender.org
Mon Apr 7 00:44:27 CEST 2014


Commit: be8b4b8b0c4d4fdeed6ebf88d8a3bd480e4c48ce
Author: Campbell Barton
Date:   Mon Apr 7 08:42:08 2014 +1000
https://developer.blender.org/rBbe8b4b8b0c4d4fdeed6ebf88d8a3bd480e4c48ce

Todo T36849: support XDG thumbnail management standard

===================================================================

M	source/blender/imbuf/intern/thumbs.c

===================================================================

diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c
index 843134a..ff1c399 100644
--- a/source/blender/imbuf/intern/thumbs.c
+++ b/source/blender/imbuf/intern/thumbs.c
@@ -66,9 +66,22 @@
 #  include "utfconv.h"
 #endif
 
+#if defined(WIN32) || defined(__APPLE__)
+   /* pass */
+#else
+#  define USE_FREEDESKTOP
+#endif
+
+/* '$HOME/.cache/thumbnails' or '$HOME/.thumbnails' */
+#ifdef USE_FREEDESKTOP
+#  define THUMBNAILS "thumbnails"
+#else
+#  define THUMBNAILS ".thumbnails"
+#endif
+
 #define URI_MAX (FILE_MAX * 3 + 8)
 
-static int get_thumb_dir(char *dir, ThumbSize size)
+static bool get_thumb_dir(char *dir, ThumbSize size)
 {
 	char *s = dir;
 	const char *subdir;
@@ -78,20 +91,30 @@ static int get_thumb_dir(char *dir, ThumbSize size)
 	SHGetSpecialFolderPathW(0, dir_16, CSIDL_PROFILE, 0);
 	conv_utf_16_to_8(dir_16, dir, FILE_MAX);
 	s += strlen(dir);
+#elif defined(USE_FREEDESKTOP)
+	const char *home_cache = getenv("XDG_CACHE_HOME");
+	const char *home = home_cache ? home_cache : getenv("HOME");
 #else
 	const char *home = getenv("HOME");
+#endif
 	if (!home) return 0;
 	s += BLI_strncpy_rlen(s, home, FILE_MAX);
+
+#ifdef USE_FREEDESKTOP
+	if (!home_cache) {
+		s += BLI_strncpy_rlen(s, "/.cache", FILE_MAX - (s - dir));
+	}
 #endif
+
 	switch (size) {
 		case THB_NORMAL:
-			subdir = "/.thumbnails/normal/";
+			subdir = "/" THUMBNAILS "/normal/";
 			break;
 		case THB_LARGE:
-			subdir = "/.thumbnails/large/";
+			subdir = "/" THUMBNAILS "/large/";
 			break;
 		case THB_FAIL:
-			subdir = "/.thumbnails/fail/blender/";
+			subdir = "/" THUMBNAILS "/fail/blender/";
 			break;
 		default:
 			return 0; /* unknown size */
@@ -103,6 +126,9 @@ static int get_thumb_dir(char *dir, ThumbSize size)
 	return 1;
 }
 
+#undef THUMBNAILS
+
+
 /** ----- begin of adapted code from glib ---
  * The following code is adapted from function g_escape_uri_string from the gnome glib
  * Source: http://svn.gnome.org/viewcvs/glib/trunk/glib/gconvert.c?view=markup




More information about the Bf-blender-cvs mailing list