[gnome-desktop/wip/thumbnail-resources: 2/7] thumbnail: Clean up path generation code
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop/wip/thumbnail-resources: 2/7] thumbnail: Clean up path generation code
- Date: Mon, 1 Oct 2012 21:15:47 +0000 (UTC)
commit 9b71a80f5dbb62cd8451cb6dc48992cee5c7ebdd
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Sep 5 18:07:09 2012 -0300
thumbnail: Clean up path generation code
Put the path calculation code in one spot.
https://bugzilla.gnome.org/show_bug.cgi?id=684026
libgnome-desktop/gnome-desktop-thumbnail.c | 147 ++++++++++------------------
libgnome-desktop/libgsystem | 2 +-
2 files changed, 52 insertions(+), 97 deletions(-)
---
diff --git a/libgnome-desktop/gnome-desktop-thumbnail.c b/libgnome-desktop/gnome-desktop-thumbnail.c
index daf8ed5..fcbdf44 100644
--- a/libgnome-desktop/gnome-desktop-thumbnail.c
+++ b/libgnome-desktop/gnome-desktop-thumbnail.c
@@ -846,6 +846,47 @@ gnome_desktop_thumbnail_factory_new (GnomeDesktopThumbnailSize size)
return factory;
}
+static char *
+thumbnail_path (const char *uri,
+ GnomeDesktopThumbnailSize size,
+ gboolean is_fail)
+{
+ GChecksum *checksum;
+ guint8 digest[16];
+ gsize digest_len = sizeof (digest);
+ char *path, *file;
+
+ checksum = g_checksum_new (G_CHECKSUM_MD5);
+ g_checksum_update (checksum, (const guchar *) uri, strlen (uri));
+
+ g_checksum_get_digest (checksum, digest, &digest_len);
+ g_assert (digest_len == 16);
+
+ file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
+
+ /* XXX: appname is only used for failed thumbnails. Is this a mistake? */
+ if (is_fail)
+ {
+ path = g_build_filename (g_get_user_cache_dir (),
+ "thumbnails",
+ "fail",
+ appname,
+ file,
+ NULL);
+ }
+ else
+ {
+ path = g_build_filename (g_get_user_cache_dir (),
+ "thumbnails",
+ size == GNOME_DESKTOP_THUMBNAIL_SIZE_LARGE ? "large" : "normal",
+ NULL);
+ }
+
+ g_free (file);
+ g_checksum_free (checksum);
+ return path;
+}
+
/**
* gnome_desktop_thumbnail_factory_lookup:
* @factory: a #GnomeDesktopThumbnailFactory
@@ -866,31 +907,15 @@ gnome_desktop_thumbnail_factory_lookup (GnomeDesktopThumbnailFactory *factory,
time_t mtime)
{
GnomeDesktopThumbnailFactoryPrivate *priv = factory->priv;
- char *path, *file;
- GChecksum *checksum;
- guint8 digest[16];
- gsize digest_len = sizeof (digest);
GdkPixbuf *pixbuf;
gboolean res;
+ char *path;
g_return_val_if_fail (uri != NULL, NULL);
res = FALSE;
- checksum = g_checksum_new (G_CHECKSUM_MD5);
- g_checksum_update (checksum, (const guchar *) uri, strlen (uri));
-
- g_checksum_get_digest (checksum, digest, &digest_len);
- g_assert (digest_len == 16);
-
- file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
-
- path = g_build_filename (g_get_user_cache_dir (),
- "thumbnails",
- (priv->size == GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL)?"normal":"large",
- file,
- NULL);
- g_free (file);
+ path = thumbnail_path (uri, priv->size, FALSE);
pixbuf = gdk_pixbuf_new_from_file (path, NULL);
if (pixbuf != NULL)
@@ -905,7 +930,7 @@ gnome_desktop_thumbnail_factory_lookup (GnomeDesktopThumbnailFactory *factory,
return path;
g_free (path);
- return FALSE;
+ return NULL;
}
/**
@@ -929,29 +954,13 @@ gnome_desktop_thumbnail_factory_has_valid_failed_thumbnail (GnomeDesktopThumbnai
const char *uri,
time_t mtime)
{
- char *path, *file;
+ char *path;
GdkPixbuf *pixbuf;
gboolean res;
- GChecksum *checksum;
- guint8 digest[16];
- gsize digest_len = sizeof (digest);
-
- checksum = g_checksum_new (G_CHECKSUM_MD5);
- g_checksum_update (checksum, (const guchar *) uri, strlen (uri));
-
- g_checksum_get_digest (checksum, digest, &digest_len);
- g_assert (digest_len == 16);
res = FALSE;
- file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
-
- path = g_build_filename (g_get_user_cache_dir (),
- "thumbnails/fail",
- appname,
- file,
- NULL);
- g_free (file);
+ path = thumbnail_path (uri, priv->size, TRUE);
pixbuf = gdk_pixbuf_new_from_file (path, NULL);
g_free (path);
@@ -1378,34 +1387,14 @@ gnome_desktop_thumbnail_factory_save_thumbnail (GnomeDesktopThumbnailFactory *fa
time_t original_mtime)
{
GnomeDesktopThumbnailFactoryPrivate *priv = factory->priv;
- char *path, *file;
+ char *path;
char *tmp_path;
const char *width, *height;
int tmp_fd;
char mtime_str[21];
gboolean saved_ok;
- GChecksum *checksum;
- guint8 digest[16];
- gsize digest_len = sizeof (digest);
- GError *error;
-
- checksum = g_checksum_new (G_CHECKSUM_MD5);
- g_checksum_update (checksum, (const guchar *) uri, strlen (uri));
-
- g_checksum_get_digest (checksum, digest, &digest_len);
- g_assert (digest_len == 16);
-
- file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
-
- path = g_build_filename (g_get_user_cache_dir (),
- "thumbnails",
- (priv->size == GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL)?"normal":"large",
- file,
- NULL);
-
- g_free (file);
- g_checksum_free (checksum);
+ path = thumbnail_path (uri, priv->size, FALSE);
tmp_path = g_strconcat (path, ".XXXXXX", NULL);
@@ -1487,32 +1476,14 @@ gnome_desktop_thumbnail_factory_create_failed_thumbnail (GnomeDesktopThumbnailFa
const char *uri,
time_t mtime)
{
- char *path, *file;
+ char *path;
char *tmp_path;
int tmp_fd;
char mtime_str[21];
gboolean saved_ok;
GdkPixbuf *pixbuf;
- GChecksum *checksum;
- guint8 digest[16];
- gsize digest_len = sizeof (digest);
-
- checksum = g_checksum_new (G_CHECKSUM_MD5);
- g_checksum_update (checksum, (const guchar *) uri, strlen (uri));
-
- g_checksum_get_digest (checksum, digest, &digest_len);
- g_assert (digest_len == 16);
- file = g_strconcat (g_checksum_get_string (checksum), ".png", NULL);
-
- path = g_build_filename (g_get_user_cache_dir (),
- "thumbnails/fail",
- appname,
- file,
- NULL);
- g_free (file);
-
- g_checksum_free (checksum);
+ path = thumbnail_path (uri, priv->size, TRUE);
tmp_path = g_strconcat (path, ".XXXXXX", NULL);
@@ -1588,23 +1559,7 @@ char *
gnome_desktop_thumbnail_path_for_uri (const char *uri,
GnomeDesktopThumbnailSize size)
{
- char *md5;
- char *file;
- char *path;
-
- md5 = gnome_desktop_thumbnail_md5 (uri);
- file = g_strconcat (md5, ".png", NULL);
- g_free (md5);
-
- path = g_build_filename (g_get_user_cache_dir (),
- "thumbnails",
- (size == GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL)?"normal":"large",
- file,
- NULL);
-
- g_free (file);
-
- return path;
+ return thumbnail_path (uri, size, FALSE);
}
/**
diff --git a/libgnome-desktop/libgsystem b/libgnome-desktop/libgsystem
index 5ed135b..c4068ea 160000
--- a/libgnome-desktop/libgsystem
+++ b/libgnome-desktop/libgsystem
@@ -1 +1 @@
-Subproject commit 5ed135b8f56a4a7d085a7fa144fdc59131ba8d51
+Subproject commit c4068eaa793212eb7caad6e0ff2fb35e4aab184a
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]