Commit 5e347ed2 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

plug-ins/file-psd/psd.c plug-ins/file-psd/psd-load.[ch]

2008-08-20  Sven Neumann  <sven@gimp.org>

	* plug-ins/file-psd/psd.c
	* plug-ins/file-psd/psd-load.[ch]
	* plug-ins/file-psd/psd-save.c 
	* plug-ins/file-psd/psd-thumb-load.[ch]: pass error messages 
with
	the return values instead of calling g_message().


svn path=/trunk/; revision=26671
parent 50849396
2008-08-20 Sven Neumann <sven@gimp.org>
* plug-ins/file-psd/psd.c
* plug-ins/file-psd/psd-load.[ch]
* plug-ins/file-psd/psd-save.c
* plug-ins/file-psd/psd-thumb-load.[ch]: pass error messages with
the return values instead of calling g_message().
2008-08-20 Sven Neumann <sven@gimp.org> 2008-08-20 Sven Neumann <sven@gimp.org>
* plug-ins/file-jpeg/jpeg.[ch] * plug-ins/file-jpeg/jpeg.[ch]
......
...@@ -105,7 +105,8 @@ static void convert_1_bit (const gchar *src, ...@@ -105,7 +105,8 @@ static void convert_1_bit (const gchar *src,
/* Main file load function */ /* Main file load function */
gint32 gint32
load_image (const gchar *filename) load_image (const gchar *filename,
GError **load_error)
{ {
FILE *f; FILE *f;
struct stat st; struct stat st;
...@@ -122,7 +123,8 @@ load_image (const gchar *filename) ...@@ -122,7 +123,8 @@ load_image (const gchar *filename)
f = g_fopen (filename, "rb"); f = g_fopen (filename, "rb");
if (f == NULL) if (f == NULL)
{ {
g_message (_("Could not open '%s' for reading: %s"), g_set_error (load_error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno)); gimp_filename_to_utf8 (filename), g_strerror (errno));
return -1; return -1;
} }
...@@ -205,7 +207,8 @@ load_image (const gchar *filename) ...@@ -205,7 +207,8 @@ load_image (const gchar *filename)
load_error: load_error:
if (error) if (error)
{ {
g_message (_("Error loading PSD file:\n\n%s"), error->message); g_set_error (load_error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error loading PSD file: %s"), error->message);
g_error_free (error); g_error_free (error);
} }
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
#define __PSD_LOAD_H__ #define __PSD_LOAD_H__
gint32 load_image (const gchar *filename); gint32 load_image (const gchar *filename,
GError **error);
#endif /* __PSD_LOAD_H__ */ #endif /* __PSD_LOAD_H__ */
...@@ -156,7 +156,8 @@ static void save_layer_and_mask (FILE *fd, ...@@ -156,7 +156,8 @@ static void save_layer_and_mask (FILE *fd,
static void save_data (FILE *fd, static void save_data (FILE *fd,
gint32 image_id); gint32 image_id);
static gint save_image (const gchar *filename, static gint save_image (const gchar *filename,
gint32 image_id); gint32 image_id,
GError **error);
static void xfwrite (FILE *fd, static void xfwrite (FILE *fd,
gconstpointer buf, gconstpointer buf,
glong len, glong len,
...@@ -239,6 +240,7 @@ run (const gchar *name, ...@@ -239,6 +240,7 @@ run (const gchar *name,
{ {
static GimpParam values[2]; static GimpParam values[2];
GimpRunMode run_mode; GimpRunMode run_mode;
GError *error = NULL;
run_mode = param[0].data.d_int32; run_mode = param[0].data.d_int32;
...@@ -284,11 +286,22 @@ run (const gchar *name, ...@@ -284,11 +286,22 @@ run (const gchar *name,
break; break;
} }
if (save_image (param[3].data.d_string, image_id)) if (save_image (param[3].data.d_string, image_id, &error))
{
values[0].data.d_status = GIMP_PDB_SUCCESS; values[0].data.d_status = GIMP_PDB_SUCCESS;
}
else else
{
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
if (error)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING;
values[1].data.d_string = error->message;
}
}
if (export == GIMP_EXPORT_EXPORT) if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image_id); gimp_image_delete (image_id);
} }
...@@ -395,7 +408,9 @@ write_pascalstring (FILE *fd, ...@@ -395,7 +408,9 @@ write_pascalstring (FILE *fd,
xfwrite (fd, val, len, why); xfwrite (fd, val, len, why);
} }
else else
{
write_gint16 (fd, 0, why); write_gint16 (fd, 0, why);
}
/* If total length (length byte + content) is not a multiple of PADDING, /* If total length (length byte + content) is not a multiple of PADDING,
add zeros to pad it. */ add zeros to pad it. */
...@@ -1519,7 +1534,8 @@ get_image_data (FILE *fd, ...@@ -1519,7 +1534,8 @@ get_image_data (FILE *fd,
static gint static gint
save_image (const gchar *filename, save_image (const gchar *filename,
gint32 image_id) gint32 image_id,
GError **error)
{ {
FILE *fd; FILE *fd;
gint32 *layers; gint32 *layers;
...@@ -1532,7 +1548,10 @@ save_image (const gchar *filename, ...@@ -1532,7 +1548,10 @@ save_image (const gchar *filename,
if (gimp_image_width (image_id) > 30000 || if (gimp_image_width (image_id) > 30000 ||
gimp_image_height (image_id) > 30000) gimp_image_height (image_id) > 30000)
{ {
g_message (_("Unable to save '%s'. The PSD file format does not support images that are more than 30,000 pixels wide or tall."), g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Unable to save '%s'. The PSD file format does not "
"support images that are more than 30,000 pixels wide "
"or tall."),
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
return FALSE; return FALSE;
} }
...@@ -1544,7 +1563,10 @@ save_image (const gchar *filename, ...@@ -1544,7 +1563,10 @@ save_image (const gchar *filename,
drawable = gimp_drawable_get (layers[i]); drawable = gimp_drawable_get (layers[i]);
if (drawable->width > 30000 || drawable->height > 30000) if (drawable->width > 30000 || drawable->height > 30000)
{ {
g_message (_("Unable to save '%s'. The PSD file format does not support images with layers that are more than 30,000 pixels wide or tall."), g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Unable to save '%s'. The PSD file format does not "
"support images with layers that are more than 30,000 "
"pixels wide or tall."),
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
g_free (layers); g_free (layers);
return FALSE; return FALSE;
...@@ -1556,7 +1578,8 @@ save_image (const gchar *filename, ...@@ -1556,7 +1578,8 @@ save_image (const gchar *filename,
fd = g_fopen (filename, "wb"); fd = g_fopen (filename, "wb");
if (fd == NULL) if (fd == NULL)
{ {
g_message (_("Could not open '%s' for writing: %s"), g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno)); gimp_filename_to_utf8 (filename), g_strerror (errno));
return FALSE; return FALSE;
} }
......
...@@ -59,7 +59,8 @@ static gint add_image_resources (const gint32 image_id, ...@@ -59,7 +59,8 @@ static gint add_image_resources (const gint32 image_id,
gint32 gint32
load_thumbnail_image (const gchar *filename, load_thumbnail_image (const gchar *filename,
gint *width, gint *width,
gint *height) gint *height,
GError **load_error)
{ {
FILE *f; FILE *f;
struct stat st; struct stat st;
...@@ -75,7 +76,8 @@ load_thumbnail_image (const gchar *filename, ...@@ -75,7 +76,8 @@ load_thumbnail_image (const gchar *filename,
f = g_fopen (filename, "rb"); f = g_fopen (filename, "rb");
if (f == NULL) if (f == NULL)
{ {
g_message (_("Could not open '%s' for reading: %s"), g_set_error (load_error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno)); gimp_filename_to_utf8 (filename), g_strerror (errno));
return -1; return -1;
} }
...@@ -123,6 +125,13 @@ load_thumbnail_image (const gchar *filename, ...@@ -123,6 +125,13 @@ load_thumbnail_image (const gchar *filename,
/* ----- Process load errors ----- */ /* ----- Process load errors ----- */
load_error: load_error:
if (error)
{
g_set_error (load_error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error loading PSD file: %s"), error->message);
g_error_free (error);
}
/* Delete partially loaded image */ /* Delete partially loaded image */
if (image_id > 0) if (image_id > 0)
gimp_image_delete (image_id); gimp_image_delete (image_id);
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
gint32 load_thumbnail_image (const gchar *filename, gint32 load_thumbnail_image (const gchar *filename,
gint *width, gint *width,
gint *height); gint *height,
GError **error);
#endif /* __PSD_THUMB_LOAD_H__ */ #endif /* __PSD_THUMB_LOAD_H__ */
...@@ -172,6 +172,7 @@ run (const gchar *name, ...@@ -172,6 +172,7 @@ run (const gchar *name,
GimpRunMode run_mode; GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID; gint32 image_ID;
GError *error = NULL;
#ifdef PSD_SAVE #ifdef PSD_SAVE
gint32 drawable_ID; gint32 drawable_ID;
GimpExportReturn export = GIMP_EXPORT_CANCEL; GimpExportReturn export = GIMP_EXPORT_CANCEL;
...@@ -190,7 +191,7 @@ run (const gchar *name, ...@@ -190,7 +191,7 @@ run (const gchar *name,
/* File load */ /* File load */
if (strcmp (name, LOAD_PROC) == 0) if (strcmp (name, LOAD_PROC) == 0)
{ {
image_ID = load_image (param[1].data.d_string); image_ID = load_image (param[1].data.d_string, &error);
if (image_ID != -1) if (image_ID != -1)
{ {
...@@ -217,7 +218,7 @@ run (const gchar *name, ...@@ -217,7 +218,7 @@ run (const gchar *name,
gint width = 0; gint width = 0;
gint height = 0; gint height = 0;
image_ID = load_thumbnail_image (filename, &width, &height); image_ID = load_thumbnail_image (filename, &width, &height, &error);
if (image_ID != -1) if (image_ID != -1)
{ {
...@@ -267,7 +268,8 @@ run (const gchar *name, ...@@ -267,7 +268,8 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS) if (status == GIMP_PDB_SUCCESS)
{ {
if (save_image (param[3].data.d_string, image_ID, drawable_ID)) if (save_image (param[3].data.d_string, image_ID, drawable_ID,
&error))
{ {
} }
else else
...@@ -287,5 +289,12 @@ run (const gchar *name, ...@@ -287,5 +289,12 @@ run (const gchar *name,
status = GIMP_PDB_CALLING_ERROR; status = GIMP_PDB_CALLING_ERROR;
} }
if (status != GIMP_PDB_SUCCESS && error)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING;
values[1].data.d_string = error->message;
}
values[0].data.d_status = status; values[0].data.d_status = status;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment