create the thumbnail directories if they don't exist.

2002-04-16  Sven Neumann  <sven@gimp.org>

	* app/core/gimpimagefile.c (gimp_imagefile_png_thumb_path): create
	the thumbnail directories if they don't exist.
	(gimp_imagefile_png_thumb_name): reimplemented w/o snprintf().

	* app/pdb/color_cmds.c
	* tools/pdbgen/pdb/color.pdb: merged fix for bug #78877 from stable
	branch.
This commit is contained in:
Sven Neumann 2002-04-16 21:36:04 +00:00 committed by Sven Neumann
parent 99e575d17d
commit 8dfccd03bb
4 changed files with 83 additions and 32 deletions

View File

@ -1,3 +1,13 @@
2002-04-16 Sven Neumann <sven@gimp.org>
* app/core/gimpimagefile.c (gimp_imagefile_png_thumb_path): create
the thumbnail directories if they don't exist.
(gimp_imagefile_png_thumb_name): reimplemented w/o snprintf().
* app/pdb/color_cmds.c
* tools/pdbgen/pdb/color.pdb: merged fix for bug #78877 from stable
branch.
2002-04-16 Michael Natterer <mitch@gimp.org> 2002-04-16 Michael Natterer <mitch@gimp.org>
* app/base/temp-buf.c: fixed temp_buf_copy() and * app/base/temp-buf.c: fixed temp_buf_copy() and

View File

@ -272,6 +272,7 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile)
GimpImage *gimage = NULL; GimpImage *gimage = NULL;
GimpPDBStatusType dummy; GimpPDBStatusType dummy;
gchar *filename; gchar *filename;
gchar *thumb_name;
time_t mtime; time_t mtime;
filename = g_filename_from_uri (uri, NULL, NULL); filename = g_filename_from_uri (uri, NULL, NULL);
@ -280,6 +281,11 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile)
if (! filename) if (! filename)
return; return;
thumb_name = gimp_imagefile_png_thumb_path (uri, 128);
/* the thumbnail directory doesn't exist and couldn't be created */
if (! thumb_name)
return;
if (gimp_imagefile_test (filename, &mtime)) if (gimp_imagefile_test (filename, &mtime))
{ {
gimage = file_open_image (the_gimp, gimage = file_open_image (the_gimp,
@ -295,49 +301,52 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile)
if (gimage) if (gimage)
{ {
gchar *temp_name; gchar *temp_name = NULL;
gchar *thumb_name;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
gint w, h; gint width, height;
gchar *w_str; gchar *w_str;
gchar *h_str; gchar *h_str;
gchar *t_str; gchar *t_str;
GError *error = NULL;
if (gimage->width <= 128 && gimage->height <= 128) if (gimage->width <= 128 && gimage->height <= 128)
{ {
w = gimage->width; width = gimage->width;
h = gimage->height; height = gimage->height;
} }
else else
{ {
if (gimage->width < gimage->height) if (gimage->width < gimage->height)
{ {
h = 128; height = 128;
w = MAX (1, (128 * gimage->width) / gimage->height); width = MAX (1, (128 * gimage->width) / gimage->height);
} }
else else
{ {
w = 128; width = 128;
h = MAX (1, (128 * gimage->height) / gimage->width); height = MAX (1, (128 * gimage->height) / gimage->width);
} }
} }
pixbuf = gimp_viewable_get_new_preview_pixbuf (GIMP_VIEWABLE (gimage), pixbuf =
w, h); gimp_viewable_get_new_preview_pixbuf (GIMP_VIEWABLE (gimage),
width, height);
temp_name = NULL;
thumb_name = gimp_imagefile_png_thumb_path (uri, 128);
w_str = g_strdup_printf ("%d", gimage->width); w_str = g_strdup_printf ("%d", gimage->width);
h_str = g_strdup_printf ("%d", gimage->height); h_str = g_strdup_printf ("%d", gimage->height);
t_str = g_strdup_printf ("%ld", mtime); t_str = g_strdup_printf ("%ld", mtime);
gdk_pixbuf_save (pixbuf, thumb_name, "png", NULL, if (! gdk_pixbuf_save (pixbuf, thumb_name, "png", &error,
"tEXt::Thumb::Image::Width", w_str, "tEXt::Thumb::Image::Width", w_str,
"tEXt::Thumb::Image::Height", h_str, "tEXt::Thumb::Image::Height", h_str,
"tEXt::Thumb::URI", uri, "tEXt::Thumb::URI", uri,
"tEXt::Thumb::MTime", t_str, "tEXt::Thumb::MTime", t_str,
NULL); NULL))
{
g_message (_("Couldn't write thumbnail for '%s'\nas '%s'.\n%s"),
uri, thumb_name, error->message);
g_error_free (error);
}
g_free (w_str); g_free (w_str);
g_free (h_str); g_free (h_str);
@ -534,15 +543,23 @@ gimp_imagefile_read_png_thumb (GimpImagefile *imagefile,
static const gchar * static const gchar *
gimp_imagefile_png_thumb_name (const gchar *uri) gimp_imagefile_png_thumb_name (const gchar *uri)
{ {
guchar digest[16]; static gchar name[40];
static gchar name[40]; guchar digest[16];
gint i; guchar n;
gint i;
gimp_md5_get_digest (uri, -1, digest); gimp_md5_get_digest (uri, -1, digest);
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
g_snprintf (name + (2 * i), 3, "%02x", digest[i]); {
g_snprintf (name + 32, 5, ".png"); n = (digest[i] >> 4) & 0xF;
name[i * 2] = (n > 9) ? 'a' + n - 10 : '0' + n;
n = digest[i] & 0xF;
name[i * 2 + 1] = (n > 9) ? 'a' + n - 10 : '0' + n;
}
strncpy (name + 32, ".png", 5);
return (const gchar *) name; return (const gchar *) name;
} }
@ -552,7 +569,8 @@ gimp_imagefile_png_thumb_path (const gchar *uri,
gint size) gint size)
{ {
const gchar *name; const gchar *name;
gchar *thumb_name; gchar *thumb_dir;
gchar *thumb_name = NULL;
gint i, n; gint i, n;
name = gimp_imagefile_png_thumb_name (uri); name = gimp_imagefile_png_thumb_name (uri);
@ -564,9 +582,32 @@ gimp_imagefile_png_thumb_path (const gchar *uri,
if (i == n) if (i == n)
i--; i--;
thumb_name = g_build_filename (g_get_home_dir(), ".thumbnails", thumb_dir = g_build_filename (g_get_home_dir(), ".thumbnails",
thumb_sizes[i].dirname, thumb_sizes[i].dirname, NULL);
name, NULL);
if (! g_file_test (thumb_dir, G_FILE_TEST_IS_DIR))
{
gchar *parent = g_build_filename (g_get_home_dir(), ".thumbnails", NULL);
if (g_file_test (parent, G_FILE_TEST_IS_DIR) ||
(mkdir (parent, 0700) == 0))
{
mkdir (thumb_dir, 0700);
}
g_free (parent);
if (! g_file_test (thumb_dir, G_FILE_TEST_IS_DIR))
{
g_message (_("Couldn't create thumbnail directory '%s'"),
thumb_dir);
g_free (thumb_dir);
return NULL;
}
}
thumb_name = g_build_filename (thumb_dir, name, NULL);
g_free (thumb_dir);
return thumb_name; return thumb_name;
} }

View File

@ -574,7 +574,7 @@ curves_spline_invoker (Gimp *gimp,
success = FALSE; success = FALSE;
num_points = args[2].value.pdb_int; num_points = args[2].value.pdb_int;
if (num_points <= 3 || num_points > 32) if (num_points <= 3 || num_points > 34)
success = FALSE; success = FALSE;
control_pts = (guint8 *) args[3].value.pdb_pointer; control_pts = (guint8 *) args[3].value.pdb_pointer;
@ -648,7 +648,7 @@ static ProcArg curves_spline_inargs[] =
{ {
GIMP_PDB_INT32, GIMP_PDB_INT32,
"num_points", "num_points",
"The number of values in the control point array (3 < num_points <= 32)" "The number of values in the control point array (3 < num_points <= 34)"
}, },
{ {
GIMP_PDB_INT8ARRAY, GIMP_PDB_INT8ARRAY,

View File

@ -330,7 +330,7 @@ HELP
{ name => 'control_pts', type => 'int8array', { name => 'control_pts', type => 'int8array',
desc => 'The spline control points: { cp1.x, cp1.y, cp2.x, cp2.y, desc => 'The spline control points: { cp1.x, cp1.y, cp2.x, cp2.y,
... }', ... }',
array => { name => 'num_points', type => '3 < int32 <= 32', array => { name => 'num_points', type => '3 < int32 <= 34',
desc => 'The number of values in the control point array desc => 'The number of values in the control point array
(%%desc%%)' } } (%%desc%%)' } }
); );