fixed temp_buf_copy() and temp_buf_to_[color|gray]() to (1) not crash and

2002-04-16  Michael Natterer  <mitch@gimp.org>

	* app/base/temp-buf.c: fixed temp_buf_copy() and
	temp_buf_to_[color|gray]() to (1) not crash and (2) to assume the
	correct pixelformat. Bugs were never noticed because the code was
	never used until today...

	* app/core/gimpviewable.c (gimp_viewable_get_new_preview_pixbuf):
	use temp_buf_copy() to convert GRAY* TempBufs to RGB* before
	creating the pixbuf.

	* app/app_procs.c: don't try to open command line images if the
	filename could not be converted to an URI.

	* app/file/file-open.c
	* app/file/file-save.c: use g_file_test() instead of stat().

	* app/file/file-utils.[ch]: cleanup, changed
	file_utils_filename_to_uri() to take a list of procs, not a Gimp
	pointer.

	* app/core/gimpimage.c: changed accordingly.

	* app/core/gimpimagefile.[ch]: implemented thumbnail saving
	following the thumbnail standard v0.5 (the implementation is not
	yet fully standard compliant).

	* app/gui/file-open-dialog.c: use the new thubmnail functions and
	removed all .xvpics code. Not finished yet...

	* app/core/gimpdocuments.c
	* app/widgets/gimpdocumentview.c: changed accordingly.

	* tools/pdbgen/pdb/fileops.pdb (file_save_thumbnail): set "success"
	correctly.

	* app/pdb/fileops_cmds.c: regenerated.
This commit is contained in:
Michael Natterer 2002-04-16 20:25:27 +00:00 committed by Michael Natterer
parent 3da9502590
commit 99e575d17d
19 changed files with 894 additions and 956 deletions

View File

@ -1,3 +1,41 @@
2002-04-16 Michael Natterer <mitch@gimp.org>
* app/base/temp-buf.c: fixed temp_buf_copy() and
temp_buf_to_[color|gray]() to (1) not crash and (2) to assume the
correct pixelformat. Bugs were never noticed because the code was
never used until today...
* app/core/gimpviewable.c (gimp_viewable_get_new_preview_pixbuf):
use temp_buf_copy() to convert GRAY* TempBufs to RGB* before
creating the pixbuf.
* app/app_procs.c: don't try to open command line images if the
filename could not be converted to an URI.
* app/file/file-open.c
* app/file/file-save.c: use g_file_test() instead of stat().
* app/file/file-utils.[ch]: cleanup, changed
file_utils_filename_to_uri() to take a list of procs, not a Gimp
pointer.
* app/core/gimpimage.c: changed accordingly.
* app/core/gimpimagefile.[ch]: implemented thumbnail saving
following the thumbnail standard v0.5 (the implementation is not
yet fully standard compliant).
* app/gui/file-open-dialog.c: use the new thubmnail functions and
removed all .xvpics code. Not finished yet...
* app/core/gimpdocuments.c
* app/widgets/gimpdocumentview.c: changed accordingly.
* tools/pdbgen/pdb/fileops.pdb (file_save_thumbnail): set "success"
correctly.
* app/pdb/fileops_cmds.c: regenerated.
2002-04-16 Sven Neumann <sven@gimp.org>
* app/widgets/gimppreview.c (gimp_preview_expose_event): don't draw

View File

@ -184,7 +184,8 @@ app_init (gint gimp_argc,
GError *error = NULL;
gchar *uri;
uri = file_utils_filename_to_uri (the_gimp, gimp_argv[i], &error);
uri = file_utils_filename_to_uri (the_gimp->load_procs,
gimp_argv[i], &error);
if (! uri)
{
@ -192,10 +193,12 @@ app_init (gint gimp_argc,
error->message);
g_error_free (error);
}
else
{
file_open_with_display (the_gimp, uri);
file_open_with_display (the_gimp, uri);
g_free (uri);
g_free (uri);
}
}
}
}

View File

@ -71,46 +71,72 @@ temp_buf_to_color (TempBuf *src_buf,
{
guchar *src;
guchar *dest;
glong num_bytes;
glong num_pixels;
src = temp_buf_data (src_buf);
src = temp_buf_data (src_buf);
dest = temp_buf_data (dest_buf);
num_bytes = src_buf->width * src_buf->height;
num_pixels = src_buf->width * src_buf->height;
while (num_bytes--)
if (dest_buf->bytes == 4)
{
guchar tmpch;
*dest++ = *src++; /* alpha channel */
*dest++ = tmpch = *src++;
*dest++ = tmpch;
*dest++ = tmpch;
while (num_pixels--)
{
guchar tmpch;
*dest++ = tmpch = *src++;
*dest++ = tmpch;
*dest++ = tmpch;
*dest++ = *src++; /* alpha channel */
}
}
else
{
while (num_pixels--)
{
guchar tmpch;
*dest++ = tmpch = *src++;
*dest++ = tmpch;
*dest++ = tmpch;
}
}
}
static void
temp_buf_to_gray (TempBuf *src_buf,
TempBuf *dest_buf)
{
guchar *src;
guchar *dest;
glong num_bytes;
glong num_pixels;
gfloat pix;
src = temp_buf_data (src_buf);
src = temp_buf_data (src_buf);
dest = temp_buf_data (dest_buf);
num_bytes = src_buf->width * src_buf->height;
num_pixels = src_buf->width * src_buf->height;
while (num_bytes--)
if (dest_buf->bytes == 2)
{
*dest++ = src[0]; /* alpha channel */
while (num_pixels--)
{
pix = INTENSITY (src[0], src[1], src[2]);
*dest++ = (guchar) pix;
pix = INTENSITY (src[1], src[2], src[3]);
*dest++ = (guchar) pix;
*dest++ = src[3]; /* alpha channel */
src += 4;
src += 4;
}
}
else
{
while (num_pixels--)
{
pix = INTENSITY (src[0], src[1], src[2]);
*dest++ = (guchar) pix;
src += 3;
}
}
}
@ -268,40 +294,38 @@ TempBuf *
temp_buf_copy (TempBuf *src,
TempBuf *dest)
{
TempBuf *new;
glong length;
glong length;
g_return_val_if_fail (src != NULL, NULL);
g_return_val_if_fail (! dest || (dest->width == src->width &&
dest->height == src->height), NULL);
if (!dest)
if (! dest)
{
new = temp_buf_new (src->width, src->height, src->bytes, 0, 0, NULL);
dest = temp_buf_new (src->width, src->height, src->bytes, 0, 0, NULL);
}
if (src->bytes != dest->bytes)
{
if (src->bytes == 4 && dest->bytes == 2) /* RGBA -> GRAYA */
temp_buf_to_gray (src, dest);
else if (src->bytes == 3 && dest->bytes == 1) /* RGB -> GRAY */
temp_buf_to_gray (src, dest);
else if (src->bytes == 2 && dest->bytes == 4) /* GRAYA -> RGBA */
temp_buf_to_color (src, dest);
else if (src->bytes == 1 && dest->bytes == 3) /* GRAYA -> RGBA */
temp_buf_to_color (src, dest);
else
g_warning ("temp_buf_copy(): unimplemented color conversion");
}
else
{
new = dest;
if (dest->width != src->width || dest->height != src->height)
g_message ("In temp_buf_copy, the widths or heights don't match.");
/* The temp buf is smart, and can translate between color and gray */
/* (only necessary if not we allocated it */
if (src->bytes != new->bytes)
{
if (src->bytes == 4) /* RGB color */
temp_buf_to_gray (src, new);
else if (src->bytes == 2) /* grayscale */
temp_buf_to_color (src, new);
else
g_message ("Cannot convert from indexed color.");
return new;
}
/* make the copy */
length = src->width * src->height * src->bytes;
memcpy (temp_buf_data (dest), temp_buf_data (src), length);
}
/* make the copy */
length = src->width * src->height * src->bytes;
memcpy (temp_buf_data (new), temp_buf_data (src), length);
return new;
return dest;
}
TempBuf *

View File

@ -111,6 +111,7 @@ gimp_documents_load (Gimp *gimp)
}
imagefile = gimp_imagefile_new (uri);
gimp_imagefile_update (imagefile);
g_free (uri);

View File

@ -111,6 +111,7 @@ gimp_documents_load (Gimp *gimp)
}
imagefile = gimp_imagefile_new (uri);
gimp_imagefile_update (imagefile);
g_free (uri);

View File

@ -111,6 +111,7 @@ gimp_documents_load (Gimp *gimp)
}
imagefile = gimp_imagefile_new (uri);
gimp_imagefile_update (imagefile);
g_free (uri);

View File

@ -1036,7 +1036,8 @@ gimp_image_set_filename (GimpImage *gimage,
{
gchar *uri;
uri = file_utils_filename_to_uri (gimage->gimp, filename, NULL);
uri = file_utils_filename_to_uri (gimage->gimp->load_procs, filename,
NULL);
gimp_image_set_uri (gimage, uri);

View File

@ -42,11 +42,25 @@
#include "base/temp-buf.h"
#include "gimp.h"
#include "gimpcontainer.h"
#include "gimpimage.h"
#include "gimpimagefile.h"
#include "gimpmarshal.h"
#include "file/file-open.h"
#include "app_procs.h"
#include "libgimp/gimpintl.h"
enum
{
INFO_CHANGED,
LAST_SIGNAL
};
typedef struct
{
const gchar *dirname;
@ -60,33 +74,39 @@ static const ThumbnailSize thumb_sizes[] =
};
static void gimp_imagefile_class_init (GimpImagefileClass *klass);
static void gimp_imagefile_init (GimpImagefile *imagefile);
static void gimp_imagefile_name_changed (GimpObject *object);
static void gimp_imagefile_set_info (GimpImagefile *imagefile,
gint width,
gint height,
gint size);
static TempBuf * gimp_imagefile_get_new_preview (GimpViewable *viewable,
gint width,
gint height);
static void gimp_imagefile_class_init (GimpImagefileClass *klass);
static void gimp_imagefile_init (GimpImagefile *imagefile);
static void gimp_imagefile_name_changed (GimpObject *object);
static void gimp_imagefile_set_info (GimpImagefile *imagefile,
gint width,
gint height,
gint size);
static TempBuf * gimp_imagefile_get_new_preview (GimpViewable *viewable,
gint width,
gint height);
static TempBuf * gimp_imagefile_read_png_thumb (GimpImagefile *imagefile,
gint size);
static gchar * gimp_imagefile_png_thumb_name (const gchar *uri,
gint mtime,
gint size);
static TempBuf * gimp_imagefile_read_png_thumb (GimpImagefile *imagefile,
gint size);
static const gchar * gimp_imagefile_png_thumb_name (const gchar *uri);
static gchar * gimp_imagefile_png_thumb_path (const gchar *uri,
gint size);
static gchar * gimp_imagefile_find_png_thumb (const gchar *uri,
time_t image_mtime,
gint size,
time_t *thumb_mtime);
static TempBuf * gimp_imagefile_read_xv_thumb (GimpImagefile *imagefile);
static guchar * readXVThumb (const gchar *filename,
gint *width,
gint *height,
gchar **imginfo);
static TempBuf * gimp_imagefile_read_xv_thumb (GimpImagefile *imagefile);
static guchar * readXVThumb (const gchar *filename,
gint *width,
gint *height,
gchar **imginfo);
static gboolean gimp_image_file_test (const gchar *filename,
gint *mtime);
static gboolean gimp_imagefile_test (const gchar *filename,
time_t *mtime);
static guint gimp_imagefile_signals[LAST_SIGNAL] = { 0 };
static GimpViewableClass *parent_class = NULL;
@ -129,6 +149,15 @@ gimp_imagefile_class_init (GimpImagefileClass *klass)
object_class = GIMP_OBJECT_CLASS (klass);
viewable_class = GIMP_VIEWABLE_CLASS (klass);
gimp_imagefile_signals[INFO_CHANGED] =
g_signal_new ("info_changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GimpImagefileClass, info_changed),
NULL, NULL,
gimp_marshal_VOID__VOID,
G_TYPE_NONE, 0);
object_class->name_changed = gimp_imagefile_name_changed;
viewable_class->get_new_preview = gimp_imagefile_get_new_preview;
}
@ -136,31 +165,215 @@ gimp_imagefile_class_init (GimpImagefileClass *klass)
static void
gimp_imagefile_init (GimpImagefile *imagefile)
{
imagefile->width = -1;
imagefile->height = -1;
imagefile->size = -1;
imagefile->width = -1;
imagefile->height = -1;
imagefile->size = -1;
imagefile->image_state = GIMP_IMAGEFILE_STATE_UNKNOWN;
imagefile->image_mtime = 0;
imagefile->thumb_state = GIMP_IMAGEFILE_STATE_UNKNOWN;
imagefile->thumb_mtime = 0;
}
GimpImagefile *
gimp_imagefile_new (const gchar *filename)
gimp_imagefile_new (const gchar *uri)
{
GimpImagefile *imagefile;
imagefile = GIMP_IMAGEFILE (g_object_new (GIMP_TYPE_IMAGEFILE, NULL));
if (filename)
gimp_object_set_name (GIMP_OBJECT (imagefile), filename);
if (uri)
gimp_object_set_name (GIMP_OBJECT (imagefile), uri);
return imagefile;
}
void
gimp_imagefile_update (GimpImagefile *imagefile)
{
const gchar *uri;
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
if (uri)
{
gchar *filename = NULL;
gchar *thumbname = NULL;
filename = g_filename_from_uri (uri, NULL, NULL);
imagefile->image_mtime = 0;
if (! filename)
{
/* no thumbnails of remote images :-( */
imagefile->image_state = GIMP_IMAGEFILE_STATE_REMOTE;
goto cleanup;
}
if (! gimp_imagefile_test (filename, &imagefile->image_mtime))
{
imagefile->image_state = GIMP_IMAGEFILE_STATE_NOT_FOUND;
goto cleanup;
}
imagefile->image_state = GIMP_IMAGEFILE_STATE_EXISTS;
/* found the image, now look for the thumbnail */
imagefile->thumb_mtime = 0;
thumbname = gimp_imagefile_find_png_thumb (uri,
imagefile->image_mtime,
128,
&imagefile->thumb_mtime);
if (! thumbname)
{
imagefile->thumb_state = GIMP_IMAGEFILE_STATE_NOT_FOUND;
goto cleanup;
}
imagefile->thumb_state = GIMP_IMAGEFILE_STATE_EXISTS;
cleanup:
g_free (filename);
g_free (thumbname);
{
GimpViewable *viewable;
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (imagefile));
viewable = (GimpViewable *)
gimp_container_get_child_by_name (the_gimp->documents,
uri);
if (GIMP_IS_VIEWABLE (viewable) &&
(viewable != GIMP_VIEWABLE (imagefile)))
gimp_viewable_invalidate_preview (viewable);
}
}
}
void
gimp_imagefile_create_thumbnail (GimpImagefile *imagefile)
{
const gchar *uri;
g_return_if_fail (GIMP_IS_IMAGEFILE (imagefile));
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
if (uri)
{
GimpImage *gimage = NULL;
GimpPDBStatusType dummy;
gchar *filename;
time_t mtime;
filename = g_filename_from_uri (uri, NULL, NULL);
/* no thumbnails of remote images :-( */
if (! filename)
return;
if (gimp_imagefile_test (filename, &mtime))
{
gimage = file_open_image (the_gimp,
uri,
uri,
NULL,
NULL,
GIMP_RUN_NONINTERACTIVE,
&dummy);
}
g_free (filename);
if (gimage)
{
gchar *temp_name;
gchar *thumb_name;
GdkPixbuf *pixbuf;
gint w, h;
gchar *w_str;
gchar *h_str;
gchar *t_str;
if (gimage->width <= 128 && gimage->height <= 128)
{
w = gimage->width;
h = gimage->height;
}
else
{
if (gimage->width < gimage->height)
{
h = 128;
w = MAX (1, (128 * gimage->width) / gimage->height);
}
else
{
w = 128;
h = 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);
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);
g_free (w_str);
g_free (h_str);
g_object_unref (G_OBJECT (pixbuf));
g_object_unref (G_OBJECT (gimage));
g_free (temp_name);
g_free (thumb_name);
gimp_imagefile_update (imagefile);
}
}
}
static void
gimp_imagefile_name_changed (GimpObject *object)
{
GimpImagefile *imagefile;
imagefile = GIMP_IMAGEFILE (object);
if (GIMP_OBJECT_CLASS (parent_class)->name_changed)
GIMP_OBJECT_CLASS (parent_class)->name_changed (object);
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (object));
imagefile->width = -1;
imagefile->height = -1;
imagefile->size = -1;
imagefile->image_state = GIMP_IMAGEFILE_STATE_UNKNOWN;
imagefile->image_mtime = 0;
imagefile->thumb_state = GIMP_IMAGEFILE_STATE_UNKNOWN;
imagefile->thumb_mtime = 0;
g_signal_emit (G_OBJECT (imagefile), gimp_imagefile_signals[INFO_CHANGED], 0);
}
static void
@ -171,7 +384,7 @@ gimp_imagefile_set_info (GimpImagefile *imagefile,
{
gboolean changed;
changed = (imagefile->width != width ||
changed = (imagefile->width != width ||
imagefile->height != height ||
imagefile->size != size);
@ -179,9 +392,9 @@ gimp_imagefile_set_info (GimpImagefile *imagefile,
imagefile->height = height;
imagefile->size = size;
/* emit a name changed signal so the container view updates */
/* if (changed) */
/* gimp_object_name_changed (GIMP_OBJECT (imagefile)); */
if (changed)
g_signal_emit (G_OBJECT (imagefile),
gimp_imagefile_signals[INFO_CHANGED], 0);
}
static void
@ -239,36 +452,32 @@ gimp_imagefile_read_png_thumb (GimpImagefile *imagefile,
{
TempBuf *temp_buf = NULL;
GdkPixbuf *pixbuf = NULL;
gchar *uri = NULL;
gchar *thumbname = NULL;
const gchar *option;
gint mtime;
gint width;
gint height;
gint bytes;
gint y;
time_t y;
guchar *src;
guchar *dest;
GError *error = NULL;
/* check if the image file exists at all */
if (!gimp_image_file_test (GIMP_OBJECT (imagefile)->name, &mtime))
if (imagefile->image_state != GIMP_IMAGEFILE_STATE_EXISTS)
return NULL;
/* FIXME: convert filename to URI */
uri = g_filename_to_uri (GIMP_OBJECT (imagefile)->name, NULL, &error);
if (!uri)
{
g_warning ("%s: %s\n", G_GNUC_FUNCTION, error->message);
goto cleanup;
}
/* try to locate a thumbnail for this image */
thumbname = gimp_imagefile_png_thumb_name (uri, mtime, size);
imagefile->thumb_state = GIMP_IMAGEFILE_STATE_NOT_FOUND;
imagefile->thumb_mtime = 0;
thumbname = gimp_imagefile_find_png_thumb (GIMP_OBJECT (imagefile)->name,
imagefile->image_mtime,
size,
&imagefile->thumb_mtime);
if (!thumbname)
goto cleanup;
imagefile->thumb_state = GIMP_IMAGEFILE_STATE_EXISTS;
pixbuf = gdk_pixbuf_new_from_file (thumbname, &error);
if (!pixbuf)
@ -284,11 +493,11 @@ gimp_imagefile_read_png_thumb (GimpImagefile *imagefile,
/* URI and mtime from the thumbnail need to match our file */
option = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::URI");
if (!option || strcmp (option, uri))
if (!option || strcmp (option, GIMP_OBJECT (imagefile)->name))
goto cleanup;
option = gdk_pixbuf_get_option (pixbuf, "tEXt::Thumb::MTime");
if (!option || sscanf (option, "%d", &y) != 1 || y != mtime)
if (!option || sscanf (option, "%ld", &y) != 1 || y != imagefile->image_mtime)
goto cleanup;
/* now convert the pixbuf to a tempbuf */
@ -313,7 +522,6 @@ gimp_imagefile_read_png_thumb (GimpImagefile *imagefile,
gimp_imagefile_set_info_from_pixbuf (imagefile, pixbuf);
cleanup:
g_free (uri);
g_free (thumbname);
if (pixbuf)
g_object_unref (pixbuf);
@ -323,22 +531,57 @@ gimp_imagefile_read_png_thumb (GimpImagefile *imagefile,
return temp_buf;
}
static gchar *
gimp_imagefile_png_thumb_name (const gchar *uri,
gint mtime,
gint size)
static const gchar *
gimp_imagefile_png_thumb_name (const gchar *uri)
{
guchar digest[16];
gchar name[40];
gchar *thumb_name;
gint thumb_mtime;
gint i, n;
guchar digest[16];
static gchar name[40];
gint i;
gimp_md5_get_digest (uri, -1, digest);
for (i = 0; i < 16; i++)
g_snprintf (name + i, 3, "%02x", digest[i]);
g_snprintf (name + 16, 5, ".png");
g_snprintf (name + (2 * i), 3, "%02x", digest[i]);
g_snprintf (name + 32, 5, ".png");
return (const gchar *) name;
}
static gchar *
gimp_imagefile_png_thumb_path (const gchar *uri,
gint size)
{
const gchar *name;
gchar *thumb_name;
gint i, n;
name = gimp_imagefile_png_thumb_name (uri);
n = G_N_ELEMENTS (thumb_sizes);
for (i = 0; i < n && thumb_sizes[i].size < size; i++)
/* nothing */;
if (i == n)
i--;
thumb_name = g_build_filename (g_get_home_dir(), ".thumbnails",
thumb_sizes[i].dirname,
name, NULL);
return thumb_name;
}
static gchar *
gimp_imagefile_find_png_thumb (const gchar *uri,
time_t image_mtime,
gint size,
time_t *thumb_mtime)
{
const gchar *name;
gchar *thumb_name;
gint i, n;
name = gimp_imagefile_png_thumb_name (uri);
n = G_N_ELEMENTS (thumb_sizes);
for (i = 0; i < n && thumb_sizes[i].size < size; i++)
@ -349,25 +592,25 @@ gimp_imagefile_png_thumb_name (const gchar *uri,
{
thumb_name = g_build_filename (g_get_home_dir(), ".thumbnails",
thumb_sizes[i].dirname,
name, NULL);
if (gimp_image_file_test (thumb_name, &thumb_mtime) &&
mtime < thumb_mtime)
name, NULL);
if (gimp_imagefile_test (thumb_name, thumb_mtime) &&
image_mtime < *thumb_mtime)
return thumb_name;
g_free (thumb_name);
}
for (i = n - 1; i >= 0; i--)
{
thumb_name = g_build_filename (g_get_home_dir(), ".thumbnails",
thumb_sizes[i].dirname,
name, NULL);
if (gimp_image_file_test (thumb_name, &thumb_mtime) &&
mtime < thumb_mtime)
if (gimp_imagefile_test (thumb_name, thumb_mtime) &&
image_mtime < *thumb_mtime)
return thumb_name;
g_free (thumb_name);
}
@ -379,11 +622,12 @@ gimp_imagefile_png_thumb_name (const gchar *uri,
static TempBuf *
gimp_imagefile_read_xv_thumb (GimpImagefile *imagefile)
{
gchar *basename;
gchar *dirname;
gchar *thumbname;
gint file_mtime;
gint thumb_mtime;
gchar *filename;
gchar *basename;
gchar *dirname;
gchar *thumbname;
time_t file_mtime;
time_t thumb_mtime;
gint width;
gint height;
gint x, y;
@ -393,19 +637,30 @@ gimp_imagefile_read_xv_thumb (GimpImagefile *imagefile)
guchar *raw_thumb = NULL;
gchar *image_info = NULL;
/* check if the image file exists at all */
if (!gimp_image_file_test (GIMP_OBJECT (imagefile)->name, &file_mtime))
filename = g_filename_from_uri (GIMP_OBJECT (imagefile)->name, NULL, NULL);
/* can't load thumbnails of non "file:" URIs */
if (! filename)
return NULL;
dirname = g_path_get_dirname (GIMP_OBJECT (imagefile)->name);
basename = g_path_get_basename (GIMP_OBJECT (imagefile)->name);
/* check if the image file exists at all */
if (!gimp_imagefile_test (filename, &file_mtime))
{
g_free (filename);
return NULL;
}
dirname = g_path_get_dirname (filename);
basename = g_path_get_basename (filename);
g_free (filename);
thumbname = g_build_filename (dirname, ".xvpics", basename, NULL);
g_free (dirname);
g_free (basename);
if (gimp_image_file_test (thumbname, &thumb_mtime) &&
if (gimp_imagefile_test (thumbname, &thumb_mtime) &&
thumb_mtime >= file_mtime)
{
raw_thumb = readXVThumb (thumbname, &width, &height, &image_info);
@ -540,8 +795,8 @@ readXVThumb (const gchar *fnam,
static gboolean
gimp_image_file_test (const gchar *filename,
gint *mtime)
gimp_imagefile_test (const gchar *filename,
time_t *mtime)
{
struct stat s;

View File

@ -23,9 +23,19 @@
#define __GIMP_IMAGEFILE_H__
#include <time.h> /* time_t */
#include "gimpviewable.h"
typedef enum
{
GIMP_IMAGEFILE_STATE_UNKNOWN,
GIMP_IMAGEFILE_STATE_REMOTE,
GIMP_IMAGEFILE_STATE_NOT_FOUND,
GIMP_IMAGEFILE_STATE_EXISTS
} GimpImagefileState;
#define GIMP_TYPE_IMAGEFILE (gimp_imagefile_get_type ())
#define GIMP_IMAGEFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_IMAGEFILE, GimpImagefile))
#define GIMP_IMAGEFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_IMAGEFILE, GimpImagefileClass))
@ -43,18 +53,27 @@ struct _GimpImagefile
gint width;
gint height;
gint size;
GimpImagefileState image_state;
time_t image_mtime;
GimpImagefileState thumb_state;
time_t thumb_mtime;
};
struct _GimpImagefileClass
{
GimpViewableClass parent_class;
void (* info_changed) (GimpImagefile *imagefile);
};
GType gimp_imagefile_get_type (void) G_GNUC_CONST;
GimpImagefile * gimp_imagefile_new (const gchar *filename);
void gimp_imagefile_update_thumbnail (GimpImagefile *imagefile);
GimpImagefile * gimp_imagefile_new (const gchar *uri);
void gimp_imagefile_update (GimpImagefile *imagefile);
void gimp_imagefile_create_thumbnail (GimpImagefile *imagefile);
#endif /* __GIMP_IMAGEFILE_H__ */

View File

@ -289,7 +289,7 @@ gimp_viewable_get_new_preview_pixbuf (GimpViewable *viewable,
gint height)
{
TempBuf *temp_buf;
GdkPixbuf *pixbuf = NULL;
GdkPixbuf *pixbuf = NULL;
g_return_val_if_fail (GIMP_IS_VIEWABLE (viewable), NULL);
g_return_val_if_fail (width > 0, NULL);
@ -299,22 +299,40 @@ gimp_viewable_get_new_preview_pixbuf (GimpViewable *viewable,
if (temp_buf)
{
gint width;
gint height;
gint bytes;
TempBuf *color_buf = NULL;
gint width;
gint height;
gint bytes;
bytes = temp_buf->bytes;
width = temp_buf->width;
height = temp_buf->height;
pixbuf = gdk_pixbuf_new_from_data (temp_buf_data (temp_buf),
if (bytes == 1 || bytes == 2)
{
gint color_bytes;
color_bytes = (bytes == 2) ? 4 : 3;
color_buf = temp_buf_new (width, height, color_bytes, 0, 0, NULL);
temp_buf_copy (temp_buf, color_buf);
temp_buf = color_buf;
bytes = color_bytes;
}
pixbuf = gdk_pixbuf_new_from_data (g_memdup (temp_buf_data (temp_buf),
width * height * bytes),
GDK_COLORSPACE_RGB,
(bytes == 2) || (bytes == 4),
(bytes == 4),
8,
width,
height,
width * bytes,
NULL, NULL);
if (color_buf)
temp_buf_free (color_buf);
}
return pixbuf;

View File

@ -51,6 +51,7 @@
#include "core/gimpcoreconfig.h"
#include "core/gimpdocuments.h"
#include "core/gimpimage.h"
#include "core/gimpimagefile.h"
#include "plug-in/plug-in-types.h"
#include "plug-in/plug-in-proc.h"
@ -59,6 +60,7 @@
#include "file/file-utils.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimppreview.h"
#include "file-dialog-utils.h"
#include "file-open-dialog.h"
@ -70,29 +72,26 @@
/* local function prototypes */
static void file_open_dialog_create (Gimp *gimp);
static void file_open_genbutton_callback (GtkWidget *widget,
gpointer data);
static void file_open_selchanged_callback (GtkTreeSelection *sel,
gpointer data);
static void file_open_ok_callback (GtkWidget *widget,
gpointer data);
static void file_open_type_callback (GtkWidget *widget,
gpointer data);
static void file_open_dialog_create (Gimp *gimp);
static void file_open_genbutton_callback (GtkWidget *widget,
gpointer data);
static void file_open_selchanged_callback (GtkTreeSelection *sel,
gpointer data);
static void file_open_ok_callback (GtkWidget *widget,
gpointer data);
static void file_open_type_callback (GtkWidget *widget,
gpointer data);
static void file_open_imagefile_info_changed (GimpImagefile *imagefile,
gpointer data);
static GtkWidget *fileload = NULL;
static GtkWidget *open_options = NULL;
static GtkWidget *fileload = NULL;
static GtkWidget *open_options = NULL;
static GimpImagefile *open_options_imagefile = NULL;
static GtkPreview *open_options_preview = NULL;
static GtkWidget *open_options_fixed = NULL;
static GtkWidget *open_options_label = NULL;
static GtkWidget *open_options_frame = NULL;
static GtkWidget *open_options_genbuttonlabel = NULL;
/* Some state for the thumbnailer */
static gchar *preview_fullname = NULL;
static GtkWidget *open_options_label = NULL;
static GtkWidget *open_options_frame = NULL;
static PlugInProcDef *load_file_proc = NULL;
@ -175,7 +174,6 @@ file_open_dialog_show (Gimp *gimp)
}
/* private functions */
static void
@ -227,17 +225,19 @@ file_open_dialog_create (Gimp *gimp)
GtkWidget *hbox;
GtkWidget *option_menu;
GtkWidget *open_options_genbutton;
GtkWidget *preview;
open_options = gtk_hbox_new (TRUE, 1);
open_options = gtk_hbox_new (TRUE, 4);
/* format-chooser frame */
frame = gtk_frame_new (_("Determine File Type"));
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_box_pack_start (GTK_BOX (open_options), frame, TRUE, TRUE, 4);
gtk_box_pack_start (GTK_BOX (open_options), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
@ -251,84 +251,51 @@ file_open_dialog_create (Gimp *gimp)
gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu),
GTK_ITEM_FACTORY (item_factory)->widget);
gtk_widget_show (vbox);
gtk_widget_show (frame);
/* Preview frame */
open_options_frame = frame = gtk_frame_new ("");
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_box_pack_end (GTK_BOX (open_options), frame, FALSE, TRUE, 4);
open_options_frame = frame = gtk_frame_new (_("Preview"));
gtk_box_pack_end (GTK_BOX (open_options), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
hbox = gtk_hbox_new (TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
open_options_genbutton = gtk_button_new ();
gtk_box_pack_start (GTK_BOX (hbox), open_options_genbutton,
TRUE, FALSE, 0);
gtk_widget_show (open_options_genbutton);
gtk_box_pack_start (GTK_BOX (hbox), open_options_genbutton, TRUE, FALSE, 0);
gtk_widget_show (open_options_genbutton);
g_signal_connect (G_OBJECT (open_options_genbutton), "clicked",
G_CALLBACK (file_open_genbutton_callback),
fileload);
open_options_fixed = gtk_fixed_new ();
gtk_widget_set_size_request (open_options_fixed, 80, 60);
gtk_container_add (GTK_CONTAINER (GTK_BIN (open_options_genbutton)),
open_options_fixed);
gtk_widget_show (open_options_fixed);
gimp_help_set_help_data (open_options_genbutton,
_("Click to create preview"), NULL);
{
GtkWidget* abox;
GtkWidget* sbox;
GtkWidget* align;
open_options_imagefile = gimp_imagefile_new (NULL);
sbox = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (open_options_fixed), sbox);
gtk_widget_show (sbox);
preview = gimp_preview_new (GIMP_VIEWABLE (open_options_imagefile),
128, 0, FALSE);
gtk_container_add (GTK_CONTAINER (open_options_genbutton), preview);
gtk_widget_show (preview);
align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_widget_set_size_request (align, 80, 60);
gtk_box_pack_start (GTK_BOX (sbox), align, FALSE, TRUE, 0);
gtk_widget_show (align);
g_signal_connect (G_OBJECT (open_options_imagefile), "info_changed",
G_CALLBACK (file_open_imagefile_info_changed),
NULL);
abox = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (align), abox);
gtk_widget_show (abox);
open_options_preview =
GTK_PREVIEW (gtk_preview_new (GTK_PREVIEW_COLOR));
gtk_box_pack_start (GTK_BOX (abox), GTK_WIDGET (open_options_preview),
FALSE, TRUE, 0);
gtk_widget_show (GTK_WIDGET (open_options_preview));
open_options_genbuttonlabel = gtk_label_new (_("Generate\nPreview"));
gtk_box_pack_start (GTK_BOX (abox), open_options_genbuttonlabel,
FALSE, TRUE, 0);
gtk_widget_show (open_options_genbuttonlabel);
}
open_options_label = gtk_label_new ("");
open_options_label = gtk_label_new (_("No Selection"));
gtk_box_pack_start (GTK_BOX (vbox), open_options_label, FALSE, FALSE, 0);
gtk_widget_show (open_options_label);
gtk_widget_show (vbox);
gtk_widget_show (frame);
/* pack the containing open_options hbox into the open-dialog */
gtk_box_pack_end (GTK_BOX (GTK_FILE_SELECTION (fileload)->main_vbox),
open_options, FALSE, FALSE, 0);
}
gtk_frame_set_label (GTK_FRAME (open_options_frame), _("Preview"));
gtk_label_set_text (GTK_LABEL (open_options_label), _("No Selection"));
gtk_widget_show (GTK_WIDGET (open_options_genbuttonlabel));
gtk_widget_hide (GTK_WIDGET (open_options_preview));
gtk_widget_set_sensitive (GTK_WIDGET (open_options_frame), FALSE);
gtk_widget_show (open_options);
@ -345,214 +312,60 @@ file_open_type_callback (GtkWidget *widget,
load_file_proc = proc;
}
static guchar *
make_RGBbuf_from_tempbuf (TempBuf *tempbuf,
gint *width_rtn,
gint *height_rtn)
static void
file_open_imagefile_info_changed (GimpImagefile *imagefile,
gpointer data)
{
gint i, j, w, h;
guchar *tbd;
guchar *ptr;
guchar *rtn = NULL;
guchar alpha, r, g, b;
const gchar *uri;
w = (*width_rtn) = tempbuf->width;
h = (*height_rtn) = tempbuf->height;
tbd = temp_buf_data (tempbuf);
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
switch (tempbuf->bytes)
if (! uri)
{
case 4:
rtn = ptr = g_malloc (3 * w * h);
for (i=0; i<h; i++)
{
for (j=0; j<w; j++)
{
r = *(tbd++);
g = *(tbd++);
b = *(tbd++);
alpha = *(tbd++);
gtk_label_set_text (GTK_LABEL (open_options_label), _("No Selection"));
gtk_frame_set_label (GTK_FRAME (open_options_frame), _("Preview"));
}
else
{
gchar *basename;
if (alpha & 128)
{
*(ptr++) = r;
*(ptr++) = g;
*(ptr++) = b;
}
else
{
r = (( (i^j) & 4 ) << 5) | 64;
*(ptr++) = r;
*(ptr++) = r;
*(ptr++) = r;
}
}
}
basename = file_utils_uri_to_utf8_basename (uri);
gtk_frame_set_label (GTK_FRAME (open_options_frame), basename);
g_free (basename);
}
switch (imagefile->thumb_state)
{
case GIMP_IMAGEFILE_STATE_UNKNOWN:
case GIMP_IMAGEFILE_STATE_REMOTE:
case GIMP_IMAGEFILE_STATE_NOT_FOUND:
gtk_label_set_text (GTK_LABEL (open_options_label),
_("No preview available"));
break;
case 2:
rtn = ptr = g_malloc (3 * w * h);
for (i=0; i<h; i++)
{
for (j=0; j<w; j++)
{
r = *(tbd++);
alpha = *(tbd++);
case GIMP_IMAGEFILE_STATE_EXISTS:
if (imagefile->image_mtime > imagefile->thumb_mtime)
{
gtk_label_set_text (GTK_LABEL (open_options_label),
_("Thumbnail is out of date"));
}
else
{
gchar *str;
if (!(alpha & 128))
r = (( (i^j) & 4 ) << 5) | 64;
str = g_strdup_printf (_("(%d x %d)"),
imagefile->width,
imagefile->height);
*(ptr++) = r;
*(ptr++) = r;
*(ptr++) = r;
}
}
gtk_label_set_text (GTK_LABEL (open_options_label), str);
g_free (str);
}
break;
default:
g_warning ("%s: Unknown TempBuf width.", G_STRLOC);
}
return (rtn);
}
/* don't call with preview_fullname as parameter! will be clobbered! */
static void
set_preview (Gimp *gimp,
const gchar *fullfname,
guchar *RGB_source,
gint RGB_w,
gint RGB_h)
{
guchar *thumb_rgb;
guchar *raw_thumb;
gint tnw,tnh, i;
gchar *dirname;
gchar *basename;
gchar *tname;
gchar *imginfo = NULL;
struct stat file_stat;
struct stat thumb_stat;
gboolean thumb_may_be_outdated = FALSE;
gboolean show_generate_label = TRUE;
dirname = g_path_get_dirname (fullfname);
basename = g_path_get_basename (fullfname);
tname = g_build_filename (dirname, ".xvpics", basename, NULL);
/* If the file is newer than its thumbnail, the thumbnail may
* be out of date.
*/
if ((stat (tname, &thumb_stat) == 0) &&
(stat (fullfname, &file_stat ) == 0))
{
if ((thumb_stat.st_mtime) < (file_stat.st_mtime))
{
thumb_may_be_outdated = TRUE;
}
}
raw_thumb = readXVThumb (tname, &tnw, &tnh, &imginfo);
g_free (tname);
gtk_frame_set_label (GTK_FRAME (open_options_frame), basename);
g_free (dirname);
g_free (basename);
g_free (preview_fullname);
preview_fullname = g_strdup (fullfname);
if (RGB_source)
{
gtk_preview_size (open_options_preview, RGB_w, RGB_h);
for (i = 0; i < RGB_h; i++)
{
gtk_preview_draw_row (open_options_preview, &RGB_source[3*i*RGB_w],
0, i,
RGB_w);
}
}
else
{
if (raw_thumb)
{
thumb_rgb = g_malloc (3 * tnw * tnh);
for (i = 0; i < tnw * tnh; i++)
{
thumb_rgb[i*3 ] = ((raw_thumb[i]>>5)*255)/7;
thumb_rgb[i*3+1] = (((raw_thumb[i]>>2)&7)*255)/7;
thumb_rgb[i*3+2] = (((raw_thumb[i])&3)*255)/3;
}
gtk_preview_size (open_options_preview, tnw, tnh);
for (i = 0; i < tnh; i++)
{
gtk_preview_draw_row (open_options_preview, &thumb_rgb[3*i*tnw],
0, i,
tnw);
}
g_free (thumb_rgb);
}
}
if (raw_thumb || RGB_source) /* We can show *some* kind of preview. */
{
if (raw_thumb) /* Managed to commit thumbnail file to disk */
{
gtk_label_set_text (GTK_LABEL (open_options_label),
thumb_may_be_outdated ?
_("This thumbnail may be out of date") :
(imginfo ? imginfo : _("No Information")));
if (imginfo)
g_free (imginfo);
}
else
{
if (gimp->config->write_thumbnails)
{
gtk_label_set_text (GTK_LABEL(open_options_label),
_("Could not write thumbnail file."));
}
else
{
gtk_label_set_text (GTK_LABEL(open_options_label),
_("Thumbnail saving is disabled."));
}
}
gtk_widget_show (GTK_WIDGET (open_options_preview));
gtk_widget_queue_draw (GTK_WIDGET(open_options_preview));
show_generate_label = FALSE;
g_free (raw_thumb);
}
else
{
if (imginfo)
g_free (imginfo);
gtk_widget_hide (GTK_WIDGET (open_options_preview));
gtk_label_set_text (GTK_LABEL (open_options_label),
_("No preview available"));
}
if (show_generate_label)
{
gtk_widget_hide (GTK_WIDGET (open_options_preview));
gtk_widget_show (GTK_WIDGET (open_options_genbuttonlabel));
}
else
{
gtk_widget_hide (GTK_WIDGET (open_options_genbuttonlabel));
gtk_widget_show (GTK_WIDGET (open_options_preview));
break;
}
}
@ -581,6 +394,8 @@ file_open_selchanged_callback (GtkTreeSelection *sel,
&selected);
if (selected)
{
gchar *uri;
fileload = GTK_FILE_SELECTION (data);
gimp = GIMP (g_object_get_data (G_OBJECT (fileload), "gimp"));
@ -588,27 +403,27 @@ file_open_selchanged_callback (GtkTreeSelection *sel,
fullfname = gtk_file_selection_get_filename (fileload);
gtk_widget_set_sensitive (GTK_WIDGET (open_options_frame), TRUE);
set_preview (gimp, fullfname, NULL, 0, 0);
uri = file_utils_filename_to_uri (gimp->load_procs, fullfname, NULL);
gimp_object_set_name (GIMP_OBJECT (open_options_imagefile), uri);
g_free (uri);
}
else
{
gimp_object_set_name (GIMP_OBJECT (open_options_imagefile), NULL);
}
gimp_imagefile_update (open_options_imagefile);
}
static void
file_open_genbutton_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage_to_be_thumbed;
guchar *RGBbuf;
TempBuf *tempbuf;
gint RGBbuf_w;
gint RGBbuf_h;
Gimp *gimp;
/* added for multi-file preview generation... */
GtkFileSelection *fs;
gchar *full_filename = NULL;
gchar *raw_filename = NULL;
struct stat buf;
gint err;
Gimp *gimp;
gchar **selections;
gint i;
@ -616,71 +431,38 @@ file_open_genbutton_callback (GtkWidget *widget,
gimp = GIMP (g_object_get_data (G_OBJECT (fs), "gimp"));
if (! preview_fullname)
{
g_warning ("%s: Tried to generate thumbnail for NULL file name.", G_STRLOC);
return;
}
gimp_set_busy (gimp);
gtk_widget_set_sensitive (GTK_WIDGET (fileload), FALSE);
/* new mult-file preview make: */
gtk_widget_set_sensitive (GTK_WIDGET (fs), FALSE);
selections = gtk_file_selection_get_selections (fs);
for (i = 0; selections[i] != NULL; i++)
{
full_filename = selections[i];
err = stat (full_filename, &buf);
if (! (err == 0 && (buf.st_mode & S_IFDIR)))
if (g_file_test (selections[i], G_FILE_TEST_IS_REGULAR))
{
/* Is not directory. */
GimpPDBStatusType dummy;
raw_filename = g_path_get_basename (full_filename);
gimage_to_be_thumbed = file_open_image (gimp,
full_filename,
raw_filename,
NULL,
NULL,
GIMP_RUN_NONINTERACTIVE,
&dummy);
g_free (raw_filename);
if (gimage_to_be_thumbed)
{
tempbuf = make_thumb_tempbuf (gimage_to_be_thumbed);
RGBbuf = make_RGBbuf_from_tempbuf (tempbuf,
&RGBbuf_w,
&RGBbuf_h);
if (gimp->config->write_thumbnails)
{
file_save_thumbnail (gimage_to_be_thumbed,
full_filename, tempbuf);
}
set_preview (gimp, full_filename,
RGBbuf, RGBbuf_w, RGBbuf_h);
g_object_unref (G_OBJECT (gimage_to_be_thumbed));
if (RGBbuf)
g_free (RGBbuf);
gchar *uri = g_filename_to_uri (selections[i], NULL, NULL);
if (gimp->config->write_thumbnails)
{
gimp_object_set_name (GIMP_OBJECT (open_options_imagefile),
uri);
gimp_imagefile_create_thumbnail (open_options_imagefile);
}
else
#if 0
{
gtk_label_set_text (GTK_LABEL (open_options_label),
_("Failed to generate preview."));
}
}
#endif
g_free (uri);
}
}
g_strfreev (selections);
gtk_widget_set_sensitive (GTK_WIDGET (fileload), TRUE);
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE);
gimp_unset_busy (gimp);
}
@ -690,14 +472,11 @@ file_open_ok_callback (GtkWidget *widget,
{
GtkFileSelection *fs;
Gimp *gimp;
gchar *full_filename;
gchar *raw_filename;
struct stat buf;
gint err;
gchar *entered_filename;
GimpPDBStatusType status;
gchar **selections;
gint i;
gchar *uri = NULL;
gchar *uri;
fs = GTK_FILE_SELECTION (data);
@ -708,50 +487,47 @@ file_open_ok_callback (GtkWidget *widget,
if (selections == NULL)
return;
full_filename = selections[0];
raw_filename = g_strdup (gtk_entry_get_text (GTK_ENTRY(fs->selection_entry)));
err = stat (full_filename, &buf);
if (err == 0 && (buf.st_mode & S_IFDIR))
if (g_file_test (selections[0], G_FILE_TEST_IS_DIR))
{
if (full_filename[strlen (full_filename) - 1] != G_DIR_SEPARATOR)
if (selections[0][strlen (selections[0]) - 1] != G_DIR_SEPARATOR)
{
gchar *s = g_strconcat (full_filename, G_DIR_SEPARATOR_S, NULL);
gchar *s = g_strconcat (selections[0], G_DIR_SEPARATOR_S, NULL);
gtk_file_selection_set_filename (fs, s);
g_free (s);
}
else
{
gtk_file_selection_set_filename (fs, full_filename);
gtk_file_selection_set_filename (fs, selections[0]);
}
g_free (raw_filename);
g_strfreev (selections);
return;
}
entered_filename =
g_strdup (gtk_entry_get_text (GTK_ENTRY (fs->selection_entry)));
gtk_widget_set_sensitive (GTK_WIDGET (fs), FALSE);
if (err) /* e.g. http://server/filename.jpg */
{
full_filename = raw_filename;
if (! g_file_test (selections[0], G_FILE_TEST_EXISTS))
{
/* try with the entered filename in case the user typed an URI */
uri = g_strdup (entered_filename);
}
else
{
uri = g_filename_to_uri (full_filename, NULL, NULL);
full_filename = uri;
uri = g_filename_to_uri (selections[0], NULL, NULL);
}
status = file_open_with_proc_and_display (gimp,
full_filename,
raw_filename,
uri,
entered_filename,
load_file_proc);
if (uri)
g_free (uri);
g_free (entered_filename);
g_free (uri);
if (status == GIMP_PDB_SUCCESS)
{
@ -760,7 +536,7 @@ file_open_ok_callback (GtkWidget *widget,
else if (status != GIMP_PDB_CANCEL)
{
/* Hackery required. Please add error message. --bex */
g_message (_("Opening '%s' failed."), full_filename);
g_message (_("Opening '%s' failed."), uri);
}
/*
@ -769,22 +545,13 @@ file_open_ok_callback (GtkWidget *widget,
for (i = 1; selections[i] != NULL; i++)
{
full_filename = selections[i];
g_free (raw_filename);
raw_filename = g_path_get_basename (full_filename);
err = stat (full_filename, &buf);
if (! (err == 0 && (buf.st_mode & S_IFDIR)))
if (g_file_test (selections[i], G_FILE_TEST_IS_REGULAR))
{
/* Is not directory. */
uri = g_filename_to_uri (full_filename, NULL, NULL);
uri = g_filename_to_uri (selections[i], NULL, NULL);
status = file_open_with_proc_and_display (gimp,
uri,
raw_filename,
uri,
load_file_proc);
if (status == GIMP_PDB_SUCCESS)
@ -801,7 +568,6 @@ file_open_ok_callback (GtkWidget *widget,
}
}
g_free (raw_filename);
g_strfreev (selections);
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE);

View File

@ -26,8 +26,6 @@
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@ -71,12 +69,12 @@ file_open_image (Gimp *gimp,
GimpRunMode run_mode,
GimpPDBStatusType *status)
{
ProcRecord *proc;
Argument *args;
Argument *return_vals;
gint gimage_id;
gint i;
gchar *filename;
ProcRecord *proc;
Argument *args;
Argument *return_vals;
gint gimage_id;
gint i;
gchar *filename;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (status != NULL, NULL);
@ -101,18 +99,17 @@ file_open_image (Gimp *gimp,
if (filename)
{
struct stat statbuf;
/* check if we are opening a file */
if (stat (filename, &statbuf) == 0)
if (g_file_test (filename, G_FILE_TEST_EXISTS))
{
if (! (statbuf.st_mode & S_IFREG))
if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
/* no errors when making thumbnails */
if (run_mode == GIMP_RUN_INTERACTIVE)
g_message (_("%s failed.\n"
"%s is not a regular file."),
open_mode, uri);
g_free (filename);
return NULL;
}
@ -124,6 +121,7 @@ file_open_image (Gimp *gimp,
g_message (_("%s failed.\n"
"%s: %s."),
open_mode, uri, g_strerror (errno));
g_free (filename);
return NULL;
}

View File

@ -26,8 +26,6 @@
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@ -113,16 +111,15 @@ file_save (GimpImage *gimage,
if (filename)
{
struct stat statbuf;
/* check if we are saving to a file */
if (stat (filename, &statbuf) == 0)
if (g_file_test (filename, G_FILE_TEST_EXISTS))
{
if (! (statbuf.st_mode & S_IFREG))
if (! g_file_test (filename, G_FILE_TEST_IS_REGULAR))
{
g_message (_("Save failed.\n"
"%s is not a regular file."),
uri);
g_free (filename);
return GIMP_PDB_CANCEL; /* inhibits error messages by caller */
}
@ -133,10 +130,13 @@ file_save (GimpImage *gimage,
"%s: %s."),
uri,
g_strerror (errno));
g_free (filename);
return GIMP_PDB_CANCEL; /* inhibits error messages by caller */
}
}
g_free (filename);
}
/* ref the image, so it can't get deleted during save */

View File

@ -19,13 +19,12 @@
#include "config.h"
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include <sys/types.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
@ -57,57 +56,63 @@
#include "file-utils.h"
#include "libgimp/gimpintl.h"
/* local function prototypes */
static PlugInProcDef * file_proc_find_by_name (GSList *procs,
const gchar *uri,
gboolean skip_magic);
static void file_convert_string (gchar *instr,
gchar *outmem,
gint maxmem,
gint *nmem);
static gint file_check_single_magic (gchar *offset,
gchar *type,
gchar *value,
gint headsize,
guchar *file_head,
FILE *ifp);
static gint file_check_magic_list (GSList *magics_list,
gint headsize,
guchar *head,
FILE *ifp);
static PlugInProcDef * file_proc_find_by_prefix (GSList *procs,
const gchar *uri,
gboolean skip_magic);
static PlugInProcDef * file_proc_find_by_extension (GSList *procs,
const gchar *uri,
gboolean skip_magic);
static PlugInProcDef * file_proc_find_by_name (GSList *procs,
const gchar *uri,
gboolean skip_magic);
static void file_convert_string (gchar *instr,
gchar *outmem,
gint maxmem,
gint *nmem);
static gint file_check_single_magic (gchar *offset,
gchar *type,
gchar *value,
gint headsize,
guchar *file_head,
FILE *ifp);
static gint file_check_magic_list (GSList *magics_list,
gint headsize,
guchar *head,
FILE *ifp);
/* public functions */
gchar *
file_utils_filename_to_uri (Gimp *gimp,
file_utils_filename_to_uri (GSList *procs,
const gchar *filename,
GError **error)
{
PlugInProcDef *proc;
GSList *procs;
GSList *prefixes;
gchar *absolute;
gchar *uri;
gchar *absolute;
gchar *uri;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (procs != NULL, NULL);
g_return_val_if_fail (filename != NULL, NULL);
/* check for prefixes like http or ftp */
for (procs = gimp->load_procs; procs; procs = g_slist_next (procs))
if (file_proc_find_by_prefix (procs, filename, FALSE))
{
proc = (PlugInProcDef *)procs->data;
for (prefixes = proc->prefixes_list;
prefixes;
prefixes = g_slist_next (prefixes))
{
if (strncmp (filename, prefixes->data, strlen (prefixes->data)) == 0)
return g_strdup (filename);
}
}
if (g_utf8_validate (filename, -1, NULL))
{
return g_strdup (filename);
}
else
{
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
_("Invalid character sequence in URI"));
return NULL;
}
}
if (! g_path_is_absolute (filename))
{
@ -295,22 +300,18 @@ file_proc_find_by_prefix (GSList *procs,
}
static PlugInProcDef *
file_proc_find_by_name (GSList *procs,
const gchar *uri,
gboolean skip_magic)
file_proc_find_by_extension (GSList *procs,
const gchar *uri,
gboolean skip_magic)
{
PlugInProcDef *proc;
GSList *p;
gchar *ext = strrchr (uri, '.');
GSList *p;
gchar *ext;
ext = strrchr (uri, '.');
if (ext)
ext++;
proc = file_proc_find_by_prefix (procs, uri, skip_magic);
if (proc)
return proc;
for (p = procs; p; p = g_slist_next (p))
{
PlugInProcDef *proc = p->data;
@ -343,6 +344,21 @@ file_proc_find_by_name (GSList *procs,
return NULL;
}
static PlugInProcDef *
file_proc_find_by_name (GSList *procs,
const gchar *uri,
gboolean skip_magic)
{
PlugInProcDef *proc;
proc = file_proc_find_by_prefix (procs, uri, skip_magic);
if (! proc)
proc = file_proc_find_by_extension (procs, uri, skip_magic);
return proc;
}
static void
file_convert_string (gchar *instr,
gchar *outmem,

View File

@ -23,7 +23,7 @@
#include <stdio.h>
gchar * file_utils_filename_to_uri (Gimp *gimp,
gchar * file_utils_filename_to_uri (GSList *procs,
const gchar *filename,
GError **error);
PlugInProcDef * file_utils_find_proc (GSList *procs,

View File

@ -51,6 +51,7 @@
#include "core/gimpcoreconfig.h"
#include "core/gimpdocuments.h"
#include "core/gimpimage.h"
#include "core/gimpimagefile.h"
#include "plug-in/plug-in-types.h"
#include "plug-in/plug-in-proc.h"
@ -59,6 +60,7 @@
#include "file/file-utils.h"
#include "widgets/gimpitemfactory.h"
#include "widgets/gimppreview.h"
#include "file-dialog-utils.h"
#include "file-open-dialog.h"
@ -70,29 +72,26 @@
/* local function prototypes */
static void file_open_dialog_create (Gimp *gimp);
static void file_open_genbutton_callback (GtkWidget *widget,
gpointer data);
static void file_open_selchanged_callback (GtkTreeSelection *sel,
gpointer data);
static void file_open_ok_callback (GtkWidget *widget,
gpointer data);
static void file_open_type_callback (GtkWidget *widget,
gpointer data);
static void file_open_dialog_create (Gimp *gimp);
static void file_open_genbutton_callback (GtkWidget *widget,
gpointer data);
static void file_open_selchanged_callback (GtkTreeSelection *sel,
gpointer data);
static void file_open_ok_callback (GtkWidget *widget,
gpointer data);
static void file_open_type_callback (GtkWidget *widget,
gpointer data);
static void file_open_imagefile_info_changed (GimpImagefile *imagefile,
gpointer data);
static GtkWidget *fileload = NULL;
static GtkWidget *open_options = NULL;
static GtkWidget *fileload = NULL;
static GtkWidget *open_options = NULL;
static GimpImagefile *open_options_imagefile = NULL;
static GtkPreview *open_options_preview = NULL;
static GtkWidget *open_options_fixed = NULL;
static GtkWidget *open_options_label = NULL;
static GtkWidget *open_options_frame = NULL;
static GtkWidget *open_options_genbuttonlabel = NULL;
/* Some state for the thumbnailer */
static gchar *preview_fullname = NULL;
static GtkWidget *open_options_label = NULL;
static GtkWidget *open_options_frame = NULL;
static PlugInProcDef *load_file_proc = NULL;
@ -175,7 +174,6 @@ file_open_dialog_show (Gimp *gimp)
}
/* private functions */
static void
@ -227,17 +225,19 @@ file_open_dialog_create (Gimp *gimp)
GtkWidget *hbox;
GtkWidget *option_menu;
GtkWidget *open_options_genbutton;
GtkWidget *preview;
open_options = gtk_hbox_new (TRUE, 1);
open_options = gtk_hbox_new (TRUE, 4);
/* format-chooser frame */
frame = gtk_frame_new (_("Determine File Type"));
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_box_pack_start (GTK_BOX (open_options), frame, TRUE, TRUE, 4);
gtk_box_pack_start (GTK_BOX (open_options), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
@ -251,84 +251,51 @@ file_open_dialog_create (Gimp *gimp)
gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu),
GTK_ITEM_FACTORY (item_factory)->widget);
gtk_widget_show (vbox);
gtk_widget_show (frame);
/* Preview frame */
open_options_frame = frame = gtk_frame_new ("");
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
gtk_box_pack_end (GTK_BOX (open_options), frame, FALSE, TRUE, 4);
open_options_frame = frame = gtk_frame_new (_("Preview"));
gtk_box_pack_end (GTK_BOX (open_options), frame, TRUE, TRUE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 2);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
hbox = gtk_hbox_new (TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
open_options_genbutton = gtk_button_new ();
gtk_box_pack_start (GTK_BOX (hbox), open_options_genbutton,
TRUE, FALSE, 0);
gtk_widget_show (open_options_genbutton);
gtk_box_pack_start (GTK_BOX (hbox), open_options_genbutton, TRUE, FALSE, 0);
gtk_widget_show (open_options_genbutton);
g_signal_connect (G_OBJECT (open_options_genbutton), "clicked",
G_CALLBACK (file_open_genbutton_callback),
fileload);
open_options_fixed = gtk_fixed_new ();
gtk_widget_set_size_request (open_options_fixed, 80, 60);
gtk_container_add (GTK_CONTAINER (GTK_BIN (open_options_genbutton)),
open_options_fixed);
gtk_widget_show (open_options_fixed);
gimp_help_set_help_data (open_options_genbutton,
_("Click to create preview"), NULL);
{
GtkWidget* abox;
GtkWidget* sbox;
GtkWidget* align;
open_options_imagefile = gimp_imagefile_new (NULL);
sbox = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (open_options_fixed), sbox);
gtk_widget_show (sbox);
preview = gimp_preview_new (GIMP_VIEWABLE (open_options_imagefile),
128, 0, FALSE);
gtk_container_add (GTK_CONTAINER (open_options_genbutton), preview);
gtk_widget_show (preview);
align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_widget_set_size_request (align, 80, 60);
gtk_box_pack_start (GTK_BOX (sbox), align, FALSE, TRUE, 0);
gtk_widget_show (align);
g_signal_connect (G_OBJECT (open_options_imagefile), "info_changed",
G_CALLBACK (file_open_imagefile_info_changed),
NULL);
abox = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (align), abox);
gtk_widget_show (abox);
open_options_preview =
GTK_PREVIEW (gtk_preview_new (GTK_PREVIEW_COLOR));
gtk_box_pack_start (GTK_BOX (abox), GTK_WIDGET (open_options_preview),
FALSE, TRUE, 0);
gtk_widget_show (GTK_WIDGET (open_options_preview));
open_options_genbuttonlabel = gtk_label_new (_("Generate\nPreview"));
gtk_box_pack_start (GTK_BOX (abox), open_options_genbuttonlabel,
FALSE, TRUE, 0);
gtk_widget_show (open_options_genbuttonlabel);
}
open_options_label = gtk_label_new ("");
open_options_label = gtk_label_new (_("No Selection"));
gtk_box_pack_start (GTK_BOX (vbox), open_options_label, FALSE, FALSE, 0);
gtk_widget_show (open_options_label);
gtk_widget_show (vbox);
gtk_widget_show (frame);
/* pack the containing open_options hbox into the open-dialog */
gtk_box_pack_end (GTK_BOX (GTK_FILE_SELECTION (fileload)->main_vbox),
open_options, FALSE, FALSE, 0);
}
gtk_frame_set_label (GTK_FRAME (open_options_frame), _("Preview"));
gtk_label_set_text (GTK_LABEL (open_options_label), _("No Selection"));
gtk_widget_show (GTK_WIDGET (open_options_genbuttonlabel));
gtk_widget_hide (GTK_WIDGET (open_options_preview));
gtk_widget_set_sensitive (GTK_WIDGET (open_options_frame), FALSE);
gtk_widget_show (open_options);
@ -345,214 +312,60 @@ file_open_type_callback (GtkWidget *widget,
load_file_proc = proc;
}
static guchar *
make_RGBbuf_from_tempbuf (TempBuf *tempbuf,
gint *width_rtn,
gint *height_rtn)
static void
file_open_imagefile_info_changed (GimpImagefile *imagefile,
gpointer data)
{
gint i, j, w, h;
guchar *tbd;
guchar *ptr;
guchar *rtn = NULL;
guchar alpha, r, g, b;
const gchar *uri;
w = (*width_rtn) = tempbuf->width;
h = (*height_rtn) = tempbuf->height;
tbd = temp_buf_data (tempbuf);
uri = gimp_object_get_name (GIMP_OBJECT (imagefile));
switch (tempbuf->bytes)
if (! uri)
{
case 4:
rtn = ptr = g_malloc (3 * w * h);
for (i=0; i<h; i++)
{
for (j=0; j<w; j++)
{
r = *(tbd++);
g = *(tbd++);
b = *(tbd++);
alpha = *(tbd++);
gtk_label_set_text (GTK_LABEL (open_options_label), _("No Selection"));
gtk_frame_set_label (GTK_FRAME (open_options_frame), _("Preview"));
}
else
{
gchar *basename;
if (alpha & 128)
{
*(ptr++) = r;
*(ptr++) = g;
*(ptr++) = b;
}
else
{
r = (( (i^j) & 4 ) << 5) | 64;
*(ptr++) = r;
*(ptr++) = r;
*(ptr++) = r;
}
}
}
basename = file_utils_uri_to_utf8_basename (uri);
gtk_frame_set_label (GTK_FRAME (open_options_frame), basename);
g_free (basename);
}
switch (imagefile->thumb_state)
{
case GIMP_IMAGEFILE_STATE_UNKNOWN:
case GIMP_IMAGEFILE_STATE_REMOTE:
case GIMP_IMAGEFILE_STATE_NOT_FOUND:
gtk_label_set_text (GTK_LABEL (open_options_label),
_("No preview available"));
break;
case 2:
rtn = ptr = g_malloc (3 * w * h);
for (i=0; i<h; i++)
{
for (j=0; j<w; j++)
{
r = *(tbd++);
alpha = *(tbd++);
case GIMP_IMAGEFILE_STATE_EXISTS:
if (imagefile->image_mtime > imagefile->thumb_mtime)
{
gtk_label_set_text (GTK_LABEL (open_options_label),
_("Thumbnail is out of date"));
}
else
{
gchar *str;
if (!(alpha & 128))
r = (( (i^j) & 4 ) << 5) | 64;
str = g_strdup_printf (_("(%d x %d)"),
imagefile->width,
imagefile->height);
*(ptr++) = r;
*(ptr++) = r;
*(ptr++) = r;
}
}
gtk_label_set_text (GTK_LABEL (open_options_label), str);
g_free (str);
}
break;
default:
g_warning ("%s: Unknown TempBuf width.", G_STRLOC);
}
return (rtn);
}
/* don't call with preview_fullname as parameter! will be clobbered! */
static void
set_preview (Gimp *gimp,
const gchar *fullfname,
guchar *RGB_source,
gint RGB_w,
gint RGB_h)
{
guchar *thumb_rgb;
guchar *raw_thumb;
gint tnw,tnh, i;
gchar *dirname;
gchar *basename;
gchar *tname;
gchar *imginfo = NULL;
struct stat file_stat;
struct stat thumb_stat;
gboolean thumb_may_be_outdated = FALSE;
gboolean show_generate_label = TRUE;
dirname = g_path_get_dirname (fullfname);
basename = g_path_get_basename (fullfname);
tname = g_build_filename (dirname, ".xvpics", basename, NULL);
/* If the file is newer than its thumbnail, the thumbnail may
* be out of date.
*/
if ((stat (tname, &thumb_stat) == 0) &&
(stat (fullfname, &file_stat ) == 0))
{
if ((thumb_stat.st_mtime) < (file_stat.st_mtime))
{
thumb_may_be_outdated = TRUE;
}
}
raw_thumb = readXVThumb (tname, &tnw, &tnh, &imginfo);
g_free (tname);
gtk_frame_set_label (GTK_FRAME (open_options_frame), basename);
g_free (dirname);
g_free (basename);
g_free (preview_fullname);
preview_fullname = g_strdup (fullfname);
if (RGB_source)
{
gtk_preview_size (open_options_preview, RGB_w, RGB_h);
for (i = 0; i < RGB_h; i++)
{
gtk_preview_draw_row (open_options_preview, &RGB_source[3*i*RGB_w],
0, i,
RGB_w);
}
}
else
{
if (raw_thumb)
{
thumb_rgb = g_malloc (3 * tnw * tnh);
for (i = 0; i < tnw * tnh; i++)
{
thumb_rgb[i*3 ] = ((raw_thumb[i]>>5)*255)/7;
thumb_rgb[i*3+1] = (((raw_thumb[i]>>2)&7)*255)/7;
thumb_rgb[i*3+2] = (((raw_thumb[i])&3)*255)/3;
}
gtk_preview_size (open_options_preview, tnw, tnh);
for (i = 0; i < tnh; i++)
{
gtk_preview_draw_row (open_options_preview, &thumb_rgb[3*i*tnw],
0, i,
tnw);
}
g_free (thumb_rgb);
}
}
if (raw_thumb || RGB_source) /* We can show *some* kind of preview. */
{
if (raw_thumb) /* Managed to commit thumbnail file to disk */
{
gtk_label_set_text (GTK_LABEL (open_options_label),
thumb_may_be_outdated ?
_("This thumbnail may be out of date") :
(imginfo ? imginfo : _("No Information")));
if (imginfo)
g_free (imginfo);
}
else
{
if (gimp->config->write_thumbnails)
{
gtk_label_set_text (GTK_LABEL(open_options_label),
_("Could not write thumbnail file."));
}
else
{
gtk_label_set_text (GTK_LABEL(open_options_label),
_("Thumbnail saving is disabled."));
}
}
gtk_widget_show (GTK_WIDGET (open_options_preview));
gtk_widget_queue_draw (GTK_WIDGET(open_options_preview));
show_generate_label = FALSE;
g_free (raw_thumb);
}
else
{
if (imginfo)
g_free (imginfo);
gtk_widget_hide (GTK_WIDGET (open_options_preview));
gtk_label_set_text (GTK_LABEL (open_options_label),
_("No preview available"));
}
if (show_generate_label)
{
gtk_widget_hide (GTK_WIDGET (open_options_preview));
gtk_widget_show (GTK_WIDGET (open_options_genbuttonlabel));
}
else
{
gtk_widget_hide (GTK_WIDGET (open_options_genbuttonlabel));
gtk_widget_show (GTK_WIDGET (open_options_preview));
break;
}
}
@ -581,6 +394,8 @@ file_open_selchanged_callback (GtkTreeSelection *sel,
&selected);
if (selected)
{
gchar *uri;
fileload = GTK_FILE_SELECTION (data);
gimp = GIMP (g_object_get_data (G_OBJECT (fileload), "gimp"));
@ -588,27 +403,27 @@ file_open_selchanged_callback (GtkTreeSelection *sel,
fullfname = gtk_file_selection_get_filename (fileload);
gtk_widget_set_sensitive (GTK_WIDGET (open_options_frame), TRUE);
set_preview (gimp, fullfname, NULL, 0, 0);
uri = file_utils_filename_to_uri (gimp->load_procs, fullfname, NULL);
gimp_object_set_name (GIMP_OBJECT (open_options_imagefile), uri);
g_free (uri);
}
else
{
gimp_object_set_name (GIMP_OBJECT (open_options_imagefile), NULL);
}
gimp_imagefile_update (open_options_imagefile);
}
static void
file_open_genbutton_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage_to_be_thumbed;
guchar *RGBbuf;
TempBuf *tempbuf;
gint RGBbuf_w;
gint RGBbuf_h;
Gimp *gimp;
/* added for multi-file preview generation... */
GtkFileSelection *fs;
gchar *full_filename = NULL;
gchar *raw_filename = NULL;
struct stat buf;
gint err;
Gimp *gimp;
gchar **selections;
gint i;
@ -616,71 +431,38 @@ file_open_genbutton_callback (GtkWidget *widget,
gimp = GIMP (g_object_get_data (G_OBJECT (fs), "gimp"));
if (! preview_fullname)
{
g_warning ("%s: Tried to generate thumbnail for NULL file name.", G_STRLOC);
return;
}
gimp_set_busy (gimp);
gtk_widget_set_sensitive (GTK_WIDGET (fileload), FALSE);
/* new mult-file preview make: */
gtk_widget_set_sensitive (GTK_WIDGET (fs), FALSE);
selections = gtk_file_selection_get_selections (fs);
for (i = 0; selections[i] != NULL; i++)
{
full_filename = selections[i];
err = stat (full_filename, &buf);
if (! (err == 0 && (buf.st_mode & S_IFDIR)))
if (g_file_test (selections[i], G_FILE_TEST_IS_REGULAR))
{
/* Is not directory. */
GimpPDBStatusType dummy;
raw_filename = g_path_get_basename (full_filename);
gimage_to_be_thumbed = file_open_image (gimp,
full_filename,
raw_filename,
NULL,
NULL,
GIMP_RUN_NONINTERACTIVE,
&dummy);
g_free (raw_filename);
if (gimage_to_be_thumbed)
{
tempbuf = make_thumb_tempbuf (gimage_to_be_thumbed);
RGBbuf = make_RGBbuf_from_tempbuf (tempbuf,
&RGBbuf_w,
&RGBbuf_h);
if (gimp->config->write_thumbnails)
{
file_save_thumbnail (gimage_to_be_thumbed,
full_filename, tempbuf);
}
set_preview (gimp, full_filename,
RGBbuf, RGBbuf_w, RGBbuf_h);
g_object_unref (G_OBJECT (gimage_to_be_thumbed));
if (RGBbuf)
g_free (RGBbuf);
gchar *uri = g_filename_to_uri (selections[i], NULL, NULL);
if (gimp->config->write_thumbnails)
{
gimp_object_set_name (GIMP_OBJECT (open_options_imagefile),
uri);
gimp_imagefile_create_thumbnail (open_options_imagefile);
}
else
#if 0
{
gtk_label_set_text (GTK_LABEL (open_options_label),
_("Failed to generate preview."));
}
}
#endif
g_free (uri);
}
}
g_strfreev (selections);
gtk_widget_set_sensitive (GTK_WIDGET (fileload), TRUE);
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE);
gimp_unset_busy (gimp);
}
@ -690,14 +472,11 @@ file_open_ok_callback (GtkWidget *widget,
{
GtkFileSelection *fs;
Gimp *gimp;
gchar *full_filename;
gchar *raw_filename;
struct stat buf;
gint err;
gchar *entered_filename;
GimpPDBStatusType status;
gchar **selections;
gint i;
gchar *uri = NULL;
gchar *uri;
fs = GTK_FILE_SELECTION (data);
@ -708,50 +487,47 @@ file_open_ok_callback (GtkWidget *widget,
if (selections == NULL)
return;
full_filename = selections[0];
raw_filename = g_strdup (gtk_entry_get_text (GTK_ENTRY(fs->selection_entry)));
err = stat (full_filename, &buf);
if (err == 0 && (buf.st_mode & S_IFDIR))
if (g_file_test (selections[0], G_FILE_TEST_IS_DIR))
{
if (full_filename[strlen (full_filename) - 1] != G_DIR_SEPARATOR)
if (selections[0][strlen (selections[0]) - 1] != G_DIR_SEPARATOR)
{
gchar *s = g_strconcat (full_filename, G_DIR_SEPARATOR_S, NULL);
gchar *s = g_strconcat (selections[0], G_DIR_SEPARATOR_S, NULL);
gtk_file_selection_set_filename (fs, s);
g_free (s);
}
else
{
gtk_file_selection_set_filename (fs, full_filename);
gtk_file_selection_set_filename (fs, selections[0]);
}
g_free (raw_filename);
g_strfreev (selections);
return;
}
entered_filename =
g_strdup (gtk_entry_get_text (GTK_ENTRY (fs->selection_entry)));
gtk_widget_set_sensitive (GTK_WIDGET (fs), FALSE);
if (err) /* e.g. http://server/filename.jpg */
{
full_filename = raw_filename;
if (! g_file_test (selections[0], G_FILE_TEST_EXISTS))
{
/* try with the entered filename in case the user typed an URI */
uri = g_strdup (entered_filename);
}
else
{
uri = g_filename_to_uri (full_filename, NULL, NULL);
full_filename = uri;
uri = g_filename_to_uri (selections[0], NULL, NULL);
}
status = file_open_with_proc_and_display (gimp,
full_filename,
raw_filename,
uri,
entered_filename,
load_file_proc);
if (uri)
g_free (uri);
g_free (entered_filename);
g_free (uri);
if (status == GIMP_PDB_SUCCESS)
{
@ -760,7 +536,7 @@ file_open_ok_callback (GtkWidget *widget,
else if (status != GIMP_PDB_CANCEL)
{
/* Hackery required. Please add error message. --bex */
g_message (_("Opening '%s' failed."), full_filename);
g_message (_("Opening '%s' failed."), uri);
}
/*
@ -769,22 +545,13 @@ file_open_ok_callback (GtkWidget *widget,
for (i = 1; selections[i] != NULL; i++)
{
full_filename = selections[i];
g_free (raw_filename);
raw_filename = g_path_get_basename (full_filename);
err = stat (full_filename, &buf);
if (! (err == 0 && (buf.st_mode & S_IFDIR)))
if (g_file_test (selections[i], G_FILE_TEST_IS_REGULAR))
{
/* Is not directory. */
uri = g_filename_to_uri (full_filename, NULL, NULL);
uri = g_filename_to_uri (selections[i], NULL, NULL);
status = file_open_with_proc_and_display (gimp,
uri,
raw_filename,
uri,
load_file_proc);
if (status == GIMP_PDB_SUCCESS)
@ -801,7 +568,6 @@ file_open_ok_callback (GtkWidget *widget,
}
}
g_free (raw_filename);
g_strfreev (selections);
gtk_widget_set_sensitive (GTK_WIDGET (fs), TRUE);

View File

@ -343,8 +343,8 @@ file_save_thumbnail_invoker (Gimp *gimp,
if (success)
{
thumb = make_thumb_tempbuf (gimage);
if (file_save_thumbnail (gimage, filename, thumb))
success = TRUE;
if (! file_save_thumbnail (gimage, filename, thumb))
success = FALSE;
}
return procedural_db_return_args (&file_save_thumbnail_proc, success);

View File

@ -61,6 +61,9 @@ static void gimp_document_view_delete_clicked (GtkWidget *widget
GimpDocumentView *view);
static void gimp_document_view_refresh_clicked (GtkWidget *widget,
GimpDocumentView *view);
static void gimp_document_view_refresh_extended_clicked (GtkWidget *widget,
guint state,
GimpDocumentView *view);
static void gimp_document_view_select_item (GimpContainerEditor *editor,
GimpViewable *viewable);
@ -172,10 +175,11 @@ gimp_document_view_new (GimpViewType view_type,
document_view->refresh_button =
gimp_editor_add_button (GIMP_EDITOR (editor->view),
GTK_STOCK_REFRESH,
_("Refresh (check files for existence)"),
_("Refresh preview\n"
"<Shift> Recreate preview"),
NULL,
G_CALLBACK (gimp_document_view_refresh_clicked),
NULL,
G_CALLBACK (gimp_document_view_refresh_extended_clicked),
editor);
/* set button sensitivity */
@ -310,10 +314,37 @@ gimp_document_view_refresh_clicked (GtkWidget *widget,
GimpDocumentView *view)
{
GimpContainerEditor *editor;
GimpImagefile *imagefile;
editor = GIMP_CONTAINER_EDITOR (view);
g_print ("refresh clicked\n");
imagefile = gimp_context_get_imagefile (editor->view->context);
if (imagefile && gimp_container_have (editor->view->container,
GIMP_OBJECT (imagefile)))
{
gimp_imagefile_update (imagefile);
}
}
static void
gimp_document_view_refresh_extended_clicked (GtkWidget *widget,
guint state,
GimpDocumentView *view)
{
GimpContainerEditor *editor;
GimpImagefile *imagefile;
editor = GIMP_CONTAINER_EDITOR (view);
imagefile = gimp_context_get_imagefile (editor->view->context);
if (imagefile && gimp_container_have (editor->view->container,
GIMP_OBJECT (imagefile)))
{
if (state & GDK_SHIFT_MASK)
gimp_imagefile_create_thumbnail (imagefile);
}
}
static void

View File

@ -246,8 +246,8 @@ HELP
code => <<'CODE'
{
thumb = make_thumb_tempbuf (gimage);
if (file_save_thumbnail (gimage, filename, thumb))
success = TRUE;
if (! file_save_thumbnail (gimage, filename, thumb))
success = FALSE;
}
CODE
);