Index: glib/gutils.c
===================================================================
--- glib/gutils.c	(revision 6868)
+++ glib/gutils.c	(working copy)
@@ -2420,10 +2420,13 @@
   g_return_val_if_fail (directory >= G_USER_DIRECTORY_DESKTOP &&
                         directory < G_USER_N_DIRECTORIES, NULL);
 
-  G_LOCK (g_utils_global);
-
   if (G_UNLIKELY (g_user_special_dirs == NULL))
     {
+      gchar *cache_dir;
+      cache_dir = g_get_user_cache_dir ();
+
+      G_LOCK (g_utils_global);
+
       g_user_special_dirs = g_new0 (gchar *, G_USER_N_DIRECTORIES);
 
       load_user_special_dirs ();
@@ -2436,10 +2439,33 @@
           g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] =
             g_build_filename (g_home_dir, "Desktop", NULL);
         }
+
+      if (g_user_special_dirs[G_USER_DIRECTORY_THUMBNAILS] == NULL)
+        {
+          g_get_any_init ();
+
+	  /* Newer xdg-base-directory-compliant thumbnail cache */
+          g_user_special_dirs[G_USER_DIRECTORY_THUMBNAILS] =
+            g_build_filename (cache_dir, "thumbnails", NULL);
+	  
+          if (!g_file_test (g_user_special_dirs[G_USER_DIRECTORY_THUMBNAILS], G_FILE_TEST_IS_DIR) 
+              && g_home_dir) 
+	    {
+              /* Check for old-style ~/.thumbnails if no xdg cache found */
+              gchar *old_style_thumbnail_dir;	      
+              old_style_thumbnail_dir = g_build_filename (g_home_dir, ".thumbnails", NULL);
+              if (g_file_test (old_style_thumbnail_dir, G_FILE_TEST_IS_DIR)) 
+	        {
+                  g_free (g_user_special_dirs[G_USER_DIRECTORY_THUMBNAILS]);
+                  g_user_special_dirs[G_USER_DIRECTORY_THUMBNAILS] = old_style_thumbnail_dir;
+                }
+              else
+		g_free (old_style_thumbnail_dir);
+            }
+        }
+      G_UNLOCK (g_utils_global);
     }
 
-  G_UNLOCK (g_utils_global);
-
   return g_user_special_dirs[directory];
 }
 
Index: glib/gutils.h
===================================================================
--- glib/gutils.h	(revision 6868)
+++ glib/gutils.h	(working copy)
@@ -158,6 +158,7 @@
  * @G_USER_DIRECTORY_PICTURES: the user's Pictures directory
  * @G_USER_DIRECTORY_PUBLIC_SHARE: the user's shared directory
  * @G_USER_DIRECTORY_TEMPLATES: the user's Templates directory
+ * @G_USER_DIRECTORY_THUMBNAILS: the user's Thumbnail cache directory
  * @G_USER_DIRECTORY_VIDEOS: the user's Movies directory
  * @G_USER_N_DIRECTORIES: the number of enum values
  *
@@ -179,6 +180,7 @@
   G_USER_DIRECTORY_PICTURES,
   G_USER_DIRECTORY_PUBLIC_SHARE,
   G_USER_DIRECTORY_TEMPLATES,
+  G_USER_DIRECTORY_THUMBNAILS,
   G_USER_DIRECTORY_VIDEOS,
 
   G_USER_N_DIRECTORIES
