[Xfce4-commits] <thunar:master> Generate thumbnails paths on the fly.
Nick Schermer
noreply at xfce.org
Thu Sep 27 22:50:01 CEST 2012
Updating branch refs/heads/master
to fa891128e3a3ce06fb2b6c1a227fbbb700cd2b43 (commit)
from 99fff9f6aaa3b64547eaf5f2244da310c8ad51bb (commit)
commit fa891128e3a3ce06fb2b6c1a227fbbb700cd2b43
Author: Nick Schermer <nick at xfce.org>
Date: Thu Sep 27 22:47:13 2012 +0200
Generate thumbnails paths on the fly.
This saves a lot of md5 hash creations, also make
the code a bit more efficient.
Drop thumbnail::* namespace collection, since we don't
use that.
thunar/thunar-file.c | 40 +++++++++++++++++++++++++---------------
thunar/thunar-file.h | 2 +-
thunarx/thunarx-file-info.h | 1 -
3 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index ae1598b..1c9478e 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -703,10 +703,8 @@ thunar_file_load (ThunarFile *file,
GError *err = NULL;
GFile *thumbnail_dir;
gchar *base_name;
- gchar *md5_hash;
gchar *p;
gchar *thumbnail_dir_path;
- gchar *uri = NULL;
const gchar *display_name;
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE);
@@ -899,18 +897,6 @@ thunar_file_load (ThunarFile *file,
file->flags =
(file->flags & ~THUNAR_FILE_THUMB_STATE_MASK) | THUNAR_FILE_THUMB_STATE_UNKNOWN;
- /* determine thumbnail path */
- uri = thunar_file_dup_uri (file);
- md5_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
- base_name = g_strdup_printf ("%s.png", md5_hash);
- file->thumbnail_path = g_build_filename (xfce_get_homedir (), ".thumbnails",
- "normal", base_name, NULL);
- g_free (base_name);
- g_free (md5_hash);
- g_free (uri);
-
- /* TODO monitor the thumbnail file for changes */
-
if (err != NULL)
{
g_propagate_error (error, err);
@@ -2791,9 +2777,33 @@ thunar_file_is_desktop (const ThunarFile *file)
const gchar *
-thunar_file_get_thumbnail_path (const ThunarFile *file)
+thunar_file_get_thumbnail_path (ThunarFile *file)
{
+ GChecksum *checksum;
+ gchar *basename;
+ gchar *uri;
+
_thunar_return_val_if_fail (THUNAR_IS_FILE (file), NULL);
+
+ if (G_UNLIKELY (file->thumbnail_path == NULL))
+ {
+ checksum = g_checksum_new (G_CHECKSUM_MD5);
+ if (G_LIKELY (checksum != NULL))
+ {
+ uri = thunar_file_dup_uri (file);
+ g_checksum_update (checksum, (const guchar *) uri, strlen (uri));
+ g_free (uri);
+
+ basename = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
+ g_checksum_free (checksum);
+
+ file->thumbnail_path = g_build_filename (xfce_get_homedir (), ".thumbnails",
+ "normal", basename, NULL);
+
+ g_free (basename);
+ }
+ }
+
return file->thumbnail_path;
}
diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h
index 70e9df8..289e518 100644
--- a/thunar/thunar-file.h
+++ b/thunar/thunar-file.h
@@ -222,7 +222,7 @@ gboolean thunar_file_set_custom_icon (ThunarFile *fil
const gchar *custom_icon,
GError **error);
-const gchar *thunar_file_get_thumbnail_path (const ThunarFile *file);
+const gchar *thunar_file_get_thumbnail_path (ThunarFile *file);
gboolean thunar_file_is_thumbnail (const ThunarFile *file);
void thunar_file_set_thumb_state (ThunarFile *file,
ThunarFileThumbState state);
diff --git a/thunarx/thunarx-file-info.h b/thunarx/thunarx-file-info.h
index 0e78600..c8e305f 100644
--- a/thunarx/thunarx-file-info.h
+++ b/thunarx/thunarx-file-info.h
@@ -43,7 +43,6 @@ G_BEGIN_DECLS;
"preview::*," \
"standard::*," \
"time::*," \
- "thumbnail::*," \
"trash::*," \
"unix::*," \
"metadata::emblems"
More information about the Xfce4-commits
mailing list