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>
* 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;
GimpPDBStatusType dummy;
gchar *filename;
gchar *thumb_name;
time_t mtime;
filename = g_filename_from_uri (uri, NULL, NULL);
@ -280,6 +281,11 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile)
if (! filename)
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))
{
gimage = file_open_image (the_gimp,
@ -295,49 +301,52 @@ gimp_imagefile_create_thumbnail (GimpImagefile *imagefile)
if (gimage)
{
gchar *temp_name;
gchar *thumb_name;
gchar *temp_name = NULL;
GdkPixbuf *pixbuf;
gint w, h;
gint width, height;
gchar *w_str;
gchar *h_str;
gchar *t_str;
GError *error = NULL;
if (gimage->width <= 128 && gimage->height <= 128)
{
w = gimage->width;
h = gimage->height;
width = gimage->width;
height = gimage->height;
}
else
{
if (gimage->width < gimage->height)
{
h = 128;
w = MAX (1, (128 * gimage->width) / gimage->height);
height = 128;
width = MAX (1, (128 * gimage->width) / gimage->height);
}
else
{
w = 128;
h = MAX (1, (128 * gimage->height) / gimage->width);
width = 128;
height = MAX (1, (128 * gimage->height) / gimage->width);
}
}
pixbuf = gimp_viewable_get_new_preview_pixbuf (GIMP_VIEWABLE (gimage),
w, h);
temp_name = NULL;
thumb_name = gimp_imagefile_png_thumb_path (uri, 128);
pixbuf =
gimp_viewable_get_new_preview_pixbuf (GIMP_VIEWABLE (gimage),
width, height);
w_str = g_strdup_printf ("%d", gimage->width);
h_str = g_strdup_printf ("%d", gimage->height);
t_str = g_strdup_printf ("%ld", mtime);
gdk_pixbuf_save (pixbuf, thumb_name, "png", NULL,
"tEXt::Thumb::Image::Width", w_str,
"tEXt::Thumb::Image::Height", h_str,
"tEXt::Thumb::URI", uri,
"tEXt::Thumb::MTime", t_str,
NULL);
if (! gdk_pixbuf_save (pixbuf, thumb_name, "png", &error,
"tEXt::Thumb::Image::Width", w_str,
"tEXt::Thumb::Image::Height", h_str,
"tEXt::Thumb::URI", uri,
"tEXt::Thumb::MTime", t_str,
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 (h_str);
@ -534,15 +543,23 @@ gimp_imagefile_read_png_thumb (GimpImagefile *imagefile,
static const gchar *
gimp_imagefile_png_thumb_name (const gchar *uri)
{
guchar digest[16];
static gchar name[40];
gint i;
static gchar name[40];
guchar digest[16];
guchar n;
gint i;
gimp_md5_get_digest (uri, -1, digest);
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;
}
@ -552,7 +569,8 @@ gimp_imagefile_png_thumb_path (const gchar *uri,
gint size)
{
const gchar *name;
gchar *thumb_name;
gchar *thumb_dir;
gchar *thumb_name = NULL;
gint i, n;
name = gimp_imagefile_png_thumb_name (uri);
@ -564,9 +582,32 @@ gimp_imagefile_png_thumb_path (const gchar *uri,
if (i == n)
i--;
thumb_name = g_build_filename (g_get_home_dir(), ".thumbnails",
thumb_sizes[i].dirname,
name, NULL);
thumb_dir = g_build_filename (g_get_home_dir(), ".thumbnails",
thumb_sizes[i].dirname, 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;
}

View File

@ -574,7 +574,7 @@ curves_spline_invoker (Gimp *gimp,
success = FALSE;
num_points = args[2].value.pdb_int;
if (num_points <= 3 || num_points > 32)
if (num_points <= 3 || num_points > 34)
success = FALSE;
control_pts = (guint8 *) args[3].value.pdb_pointer;
@ -648,7 +648,7 @@ static ProcArg curves_spline_inargs[] =
{
GIMP_PDB_INT32,
"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,

View File

@ -330,7 +330,7 @@ HELP
{ name => 'control_pts', type => 'int8array',
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%%)' } }
);