plug-ins/common/file-raw.c plug-ins/common/file-tga.c

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

	* plug-ins/common/file-raw.c
	* plug-ins/common/file-tga.c
	* plug-ins/common/file-tiff-load.c
	* plug-ins/common/file-tiff-save.c: pass error messages with the
	return values instead of calling gimp_message().


svn path=/trunk/; revision=26640
This commit is contained in:
Sven Neumann
2008-08-18 10:02:20 +00:00
committed by Sven Neumann
parent edabd739d4
commit fc059e310d
5 changed files with 133 additions and 61 deletions

View File

@ -1,3 +1,11 @@
2008-08-18 Sven Neumann <sven@gimp.org>
* plug-ins/common/file-raw.c
* plug-ins/common/file-tga.c
* plug-ins/common/file-tiff-load.c
* plug-ins/common/file-tiff-save.c: pass error messages with the
return values instead of calling gimp_message().
2008-08-18 Sven Neumann <sven@gimp.org> 2008-08-18 Sven Neumann <sven@gimp.org>
* plug-ins/common/file-pnm.c * plug-ins/common/file-pnm.c

View File

@ -113,10 +113,13 @@ static int mmap_read (gint fd,
gint32 len, gint32 len,
gint32 pos, gint32 pos,
gint rowstride); gint rowstride);
static gint32 load_image (const gchar *filename);
static gint32 load_image (const gchar *filename,
GError **error);
static GimpPDBStatusType save_image (const gchar *filename, static GimpPDBStatusType save_image (const gchar *filename,
gint32 image_id, gint32 image_id,
gint32 drawable_id); gint32 drawable_id,
GError **error);
/* gui functions */ /* gui functions */
static void preview_update (GimpPreviewArea *preview); static void preview_update (GimpPreviewArea *preview);
@ -207,11 +210,12 @@ run (const gchar *name,
gint *nreturn_vals, gint *nreturn_vals,
GimpParam **return_vals) GimpParam **return_vals)
{ {
static GimpParam values[2]; static GimpParam values[2];
GimpRunMode run_mode; GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_id; GError *error = NULL;
gint32 drawable_id; gint32 image_id;
gint32 drawable_id;
run_mode = param[0].data.d_int32; run_mode = param[0].data.d_int32;
@ -240,9 +244,12 @@ run (const gchar *name,
if (preview_fd < 0) if (preview_fd < 0)
{ {
g_message (_("Could not open '%s' for reading: %s"), g_set_error (&error,
gimp_filename_to_utf8 (param[1].data.d_string), G_FILE_ERROR, g_file_error_from_errno (errno),
g_strerror (errno)); _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (param[1].data.d_string),
g_strerror (errno));
status = GIMP_PDB_EXECUTION_ERROR; status = GIMP_PDB_EXECUTION_ERROR;
} }
else else
@ -265,7 +272,7 @@ run (const gchar *name,
/* we are okay, and the user clicked OK in the load dialog */ /* we are okay, and the user clicked OK in the load dialog */
if (status == GIMP_PDB_SUCCESS) if (status == GIMP_PDB_SUCCESS)
{ {
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)
{ {
@ -310,12 +317,21 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS) if (status == GIMP_PDB_SUCCESS)
{ {
status = save_image (param[3].data.d_string, image_id, drawable_id); status = save_image (param[3].data.d_string, image_id, drawable_id,
&error);
} }
} }
values[0].data.d_status = status;
g_free (runtime); g_free (runtime);
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;
} }
@ -487,7 +503,8 @@ raw_load_palette (RawGimpData *data,
static GimpPDBStatusType static GimpPDBStatusType
save_image (const gchar *filename, save_image (const gchar *filename,
gint32 image_id, gint32 image_id,
gint32 drawable_id) gint32 drawable_id,
GError **error)
{ {
GimpDrawable *drawable; GimpDrawable *drawable;
GimpPixelRgn pixel_rgn; GimpPixelRgn pixel_rgn;
@ -525,8 +542,9 @@ save_image (const gchar *filename,
if (! fp) if (! fp)
{ {
g_message (_("Could not open '%s' for writing: %s"), g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
gimp_filename_to_utf8 (filename), g_strerror (errno)); _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
return GIMP_PDB_EXECUTION_ERROR; return GIMP_PDB_EXECUTION_ERROR;
} }
@ -552,8 +570,9 @@ save_image (const gchar *filename,
if (! fp) if (! fp)
{ {
g_message (_("Could not open '%s' for writing: %s"), g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
gimp_filename_to_utf8 (newfile), g_strerror (errno)); _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (newfile), g_strerror (errno));
return GIMP_PDB_EXECUTION_ERROR; return GIMP_PDB_EXECUTION_ERROR;
} }
@ -628,7 +647,8 @@ save_image (const gchar *filename,
} }
static gint32 static gint32
load_image (const gchar *filename) load_image (const gchar *filename,
GError **error)
{ {
RawGimpData *data; RawGimpData *data;
gint32 layer_id = -1; gint32 layer_id = -1;
@ -642,8 +662,9 @@ load_image (const gchar *filename)
data->fp = g_fopen (filename, "rb"); data->fp = g_fopen (filename, "rb");
if (! data->fp) if (! data->fp)
{ {
g_message (_("Could not open '%s' for reading: %s"), g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
gimp_filename_to_utf8 (filename), g_strerror (errno)); _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
return -1; return -1;
} }

View File

@ -185,10 +185,12 @@ static void run (const gchar *name,
gint *nreturn_vals, gint *nreturn_vals,
GimpParam **return_vals); GimpParam **return_vals);
static gint32 load_image (const gchar *filename); static gint32 load_image (const gchar *filename,
GError **error);
static gint save_image (const gchar *filename, static gint save_image (const gchar *filename,
gint32 image_ID, gint32 image_ID,
gint32 drawable_ID); gint32 drawable_ID,
GError **error);
static gboolean save_dialog (void); static gboolean save_dialog (void);
@ -276,12 +278,13 @@ run (const gchar *name,
gint *nreturn_vals, gint *nreturn_vals,
GimpParam **return_vals) GimpParam **return_vals)
{ {
static GimpParam values[2]; static GimpParam values[2];
GimpRunMode run_mode; GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID; gint32 image_ID;
gint32 drawable_ID; gint32 drawable_ID;
GimpExportReturn export = GIMP_EXPORT_CANCEL; GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
#ifdef PROFILE #ifdef PROFILE
struct tms tbuf1, tbuf2; struct tms tbuf1, tbuf2;
@ -303,7 +306,7 @@ run (const gchar *name,
times (&tbuf1); times (&tbuf1);
#endif #endif
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)
{ {
@ -381,7 +384,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))
{ {
/* Store psvals data */ /* Store psvals data */
gimp_set_data (SAVE_PROC, &tsvals, sizeof (tsvals)); gimp_set_data (SAVE_PROC, &tsvals, sizeof (tsvals));
@ -400,6 +404,13 @@ 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;
#ifdef PROFILE #ifdef PROFILE
@ -411,7 +422,8 @@ run (const gchar *name,
} }
static gint32 static gint32
load_image (const gchar *filename) load_image (const gchar *filename,
GError **error)
{ {
FILE *fp; FILE *fp;
tga_info info; tga_info info;
@ -423,10 +435,12 @@ load_image (const gchar *filename)
gint32 image_ID = -1; gint32 image_ID = -1;
fp = g_fopen (filename, "rb"); fp = g_fopen (filename, "rb");
if (!fp)
if (! fp)
{ {
g_message (_("Could not open '%s' for reading: %s"), g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
gimp_filename_to_utf8 (filename), g_strerror (errno)); _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
return -1; return -1;
} }
@ -1120,9 +1134,10 @@ ReadImage (FILE *fp,
static gint static gint
save_image (const gchar *filename, save_image (const gchar *filename,
gint32 image_ID, gint32 image_ID,
gint32 drawable_ID) gint32 drawable_ID,
GError **error)
{ {
GimpPixelRgn pixel_rgn; GimpPixelRgn pixel_rgn;
GimpDrawable *drawable; GimpDrawable *drawable;
@ -1151,8 +1166,9 @@ save_image (const gchar *filename,
if ((fp = g_fopen (filename, "wb")) == NULL) if ((fp = g_fopen (filename, "wb")) == NULL)
{ {
g_message (_("Could not open '%s' for writing: %s"), g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
gimp_filename_to_utf8 (filename), g_strerror (errno)); _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
return FALSE; return FALSE;
} }

View File

@ -107,12 +107,13 @@ static void run (const gchar *name,
gint *nreturn_vals, gint *nreturn_vals,
GimpParam **return_vals); GimpParam **return_vals);
static gboolean load_dialog (TIFF *tif, static gboolean load_dialog (TIFF *tif,
TiffSelectedPages *pages); TiffSelectedPages *pages);
static gint32 load_image (const gchar *filename, static gint32 load_image (const gchar *filename,
TIFF *tif, TIFF *tif,
TiffSelectedPages *pages); TiffSelectedPages *pages,
GError **error);
static void load_rgba (TIFF *tif, static void load_rgba (TIFF *tif,
channel_data *channel); channel_data *channel);
@ -259,6 +260,7 @@ run (const gchar *name,
{ {
static GimpParam values[2]; static GimpParam values[2];
GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GError *error = NULL;
gint32 image; gint32 image;
TiffSelectedPages pages; TiffSelectedPages pages;
@ -285,8 +287,9 @@ run (const gchar *name,
if (fd == -1) if (fd == -1)
{ {
g_message (_("Could not open '%s' for reading: %s"), g_set_error (&error, G_FILE_ERROR, g_file_error_from_errno (errno),
gimp_filename_to_utf8 (filename), g_strerror (errno)); _("Could not open '%s' for reading: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
status = GIMP_PDB_EXECUTION_ERROR; status = GIMP_PDB_EXECUTION_ERROR;
} }
else else
@ -337,7 +340,8 @@ run (const gchar *name,
{ {
gimp_set_data (LOAD_PROC, &target, sizeof (target)); gimp_set_data (LOAD_PROC, &target, sizeof (target));
image = load_image (param[1].data.d_string, tif, &pages); image = load_image (param[1].data.d_string, tif, &pages,
&error);
g_free (pages.pages); g_free (pages.pages);
@ -372,6 +376,13 @@ 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;
} }
@ -535,9 +546,10 @@ load_dialog (TIFF *tif,
} }
static gint32 static gint32
load_image (const gchar *filename, load_image (const gchar *filename,
TIFF *tif, TIFF *tif,
TiffSelectedPages *pages) TiffSelectedPages *pages,
GError **error)
{ {
gushort bps, spp, photomet; gushort bps, spp, photomet;
guint16 orientation; guint16 orientation;
@ -744,7 +756,8 @@ load_image (const gchar *filename,
{ {
if ((image = gimp_image_new (cols, rows, image_type)) == -1) if ((image = gimp_image_new (cols, rows, image_type)) == -1)
{ {
g_message ("Could not create a new image"); g_message ("Could not create a new image: %s",
gimp_get_pdb_error ());
return -1; return -1;
} }

View File

@ -108,7 +108,8 @@ static gboolean save_paths (TIFF *tif,
static gboolean save_image (const gchar *filename, static gboolean save_image (const gchar *filename,
gint32 image, gint32 image,
gint32 drawable, gint32 drawable,
gint32 orig_image); gint32 orig_image,
GError **error);
static gboolean save_dialog (gboolean has_alpha, static gboolean save_dialog (gboolean has_alpha,
gboolean is_monochrome); gboolean is_monochrome);
@ -218,6 +219,7 @@ run (const gchar *name,
gint32 drawable; gint32 drawable;
gint32 orig_image; gint32 orig_image;
GimpExportReturn export = GIMP_EXPORT_CANCEL; GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
run_mode = param[0].data.d_int32; run_mode = param[0].data.d_int32;
@ -341,7 +343,8 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS) if (status == GIMP_PDB_SUCCESS)
{ {
if (save_image (param[3].data.d_string, image, drawable, orig_image)) if (save_image (param[3].data.d_string, image, drawable, orig_image,
&error))
{ {
/* Store mvals data */ /* Store mvals data */
gimp_set_data (SAVE_PROC, &tsvals, sizeof (TiffSaveVals)); gimp_set_data (SAVE_PROC, &tsvals, sizeof (TiffSaveVals));
@ -360,6 +363,13 @@ 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;
} }
@ -617,10 +627,11 @@ save_paths (TIFF *tif,
*/ */
static gboolean static gboolean
save_image (const gchar *filename, save_image (const gchar *filename,
gint32 image, gint32 image,
gint32 layer, gint32 layer,
gint32 orig_image) /* the export function might have created a duplicate */ gint32 orig_image, /* the export function might have */
GError **error) /* created a duplicate */
{ {
TIFF *tif; TIFF *tif;
gushort red[256]; gushort red[256];
@ -668,8 +679,9 @@ save_image (const gchar *filename,
if (fd == -1) if (fd == -1)
{ {
g_message (_("Could not open '%s' for writing: %s"), g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
gimp_filename_to_utf8 (filename), g_strerror (errno)); _("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
return FALSE; return FALSE;
} }
@ -769,7 +781,9 @@ save_image (const gchar *filename,
break; break;
case GIMP_INDEXEDA_IMAGE: case GIMP_INDEXEDA_IMAGE:
g_message ("TIFF save cannot handle indexed images with alpha channel."); g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"%s",
"TIFF save cannot handle indexed images with alpha channel.");
default: default:
return FALSE; return FALSE;
} }