From 2336b5edd6b8a9270c2437c83f41dc456d595b25 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Fri, 31 Oct 2014 22:02:04 +0300 Subject: [PATCH] Check for thumbnails in the new location The thumbnail managing standard was updated to change the location where thumbnails are stored. This has been changed to $XDG_CACHE_HOME/thumbnails/ unless $XDG_CACHE_HOME isn't defined, at which point it's back to $HOME/.cache/thumbnails This patch looks in both places when the thumbnail is created and reports the first one that's found. --- src/file.c | 23 ++++++++++++++++++++++- src/properties_dialog.c | 17 ++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/file.c b/src/file.c index 7491954..faf8740 100644 --- a/src/file.c +++ b/src/file.c @@ -482,7 +482,22 @@ rstto_file_get_thumbnail_path ( RsttoFile *r_file) checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, strlen (uri)); filename = g_strconcat (checksum, ".png", NULL); - r_file->priv->thumbnail_path = g_build_path ("/", g_get_home_dir(), ".thumbnails", "normal", filename, NULL); + /* build and check if the thumbnail is in the new location */ + r_file->priv->thumbnail_path = g_build_path ("/", g_get_user_cache_dir(), "thumbnails", "normal", filename, NULL); + + if(!g_file_test (r_file->priv->thumbnail_path, G_FILE_TEST_EXISTS)) + { + /* Fallback to old version */ + g_free (r_file->priv->thumbnail_path); + + r_file->priv->thumbnail_path = g_build_path ("/", g_get_home_dir(), ".thumbnails", "normal", filename, NULL); + if(!g_file_test (r_file->priv->thumbnail_path, G_FILE_TEST_EXISTS)) + { + /* Thumbnail doesn't exist in either spot */ + g_free (r_file->priv->thumbnail_path); + r_file->priv->thumbnail_path = NULL; + } + } g_free (checksum); g_free (filename); @@ -507,6 +522,12 @@ rstto_file_get_thumbnail ( thumbnailer = rstto_thumbnailer_new(); rstto_thumbnailer_queue_file (thumbnailer, r_file); + if (NULL == thumbnail_path) + { + /* No thumbnail to return at this time */ + return NULL; + } + /* FIXME: * * The thumbnail should be updated on the "ready" signal diff --git a/src/properties_dialog.c b/src/properties_dialog.c index 77f70a8..def362a 100644 --- a/src/properties_dialog.c +++ b/src/properties_dialog.c @@ -436,7 +436,22 @@ properties_dialog_set_file ( file_uri_checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, file_uri, strlen (file_uri)); filename = g_strconcat (file_uri_checksum, ".png", NULL); - thumbnail_path = g_build_path ("/", g_get_home_dir(), ".thumbnails", "normal", filename, NULL); + /* build and check if the thumbnail is in the new location */ + thumbnail_path = g_build_path ("/", g_get_user_cache_dir(), "thumbnails", "normal", filename, NULL); + + if(!g_file_test (thumbnail_path, G_FILE_TEST_EXISTS)) + { + /* Fallback to old version */ + g_free (thumbnail_path); + + thumbnail_path = g_build_path ("/", g_get_home_dir(), ".thumbnails", "normal", filename, NULL); + if(!g_file_test (thumbnail_path, G_FILE_TEST_EXISTS)) + { + /* Thumbnail doesn't exist in either spot */ + g_free (thumbnail_path); + thumbnail_path = NULL; + } + } pixbuf = gdk_pixbuf_new_from_file_at_scale (thumbnail_path, 96, 96, TRUE, NULL); if (NULL != pixbuf) { -- 2.1.2