for the most common errors, pass the error message with the return values

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

	* plug-ins/common/file-dicom.c: for the most common errors, pass
	the error message with the return values instead of calling
	gimp_message().


svn path=/trunk/; revision=26634
This commit is contained in:
Sven Neumann
2008-08-17 21:04:02 +00:00
committed by Sven Neumann
parent c60a4ba597
commit cb21ecf5a2
2 changed files with 50 additions and 18 deletions

View File

@ -1,7 +1,13 @@
2008-08-17 Sven Neumann <sven@gimp.org> 2008-08-17 Sven Neumann <sven@gimp.org>
* plug-ins/common/file-csource.c (save_image): in case of an * plug-ins/common/file-dicom.c: for the most common errors, pass
error, pass the error message with the return values. the error message with the return values instead of calling
gimp_message().
2008-08-17 Sven Neumann <sven@gimp.org>
* plug-ins/common/file-csource.c: in case of an error, pass the
error message with the return values.
2008-08-17 Sven Neumann <sven@gimp.org> 2008-08-17 Sven Neumann <sven@gimp.org>

View File

@ -66,10 +66,12 @@ static void run (const gchar *name,
const GimpParam *param, const GimpParam *param,
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 gboolean save_image (const gchar *filename, static gboolean save_image (const gchar *filename,
gint32 image_ID, gint32 image_ID,
gint32 drawable_ID); gint32 drawable_ID,
GError **error);
static void dicom_loader (guint8 *pix_buf, static void dicom_loader (guint8 *pix_buf,
DicomInfo *info, DicomInfo *info,
GimpPixelRgn *pixel_rgn); GimpPixelRgn *pixel_rgn);
@ -190,6 +192,7 @@ run (const gchar *name,
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;
INIT_I18N (); INIT_I18N ();
@ -202,7 +205,7 @@ run (const gchar *name,
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)
{ {
@ -214,6 +217,13 @@ run (const gchar *name,
else else
{ {
status = GIMP_PDB_EXECUTION_ERROR; status = GIMP_PDB_EXECUTION_ERROR;
if (error)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING;
values[1].data.d_string = error->message;
}
} }
} }
else if (strcmp (name, SAVE_PROC) == 0) else if (strcmp (name, SAVE_PROC) == 0)
@ -226,6 +236,7 @@ run (const gchar *name,
case GIMP_RUN_INTERACTIVE: case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS: case GIMP_RUN_WITH_LAST_VALS:
gimp_ui_init (PLUG_IN_BINARY, FALSE); gimp_ui_init (PLUG_IN_BINARY, FALSE);
export = gimp_export_image (&image_ID, &drawable_ID, "DICOM", export = gimp_export_image (&image_ID, &drawable_ID, "DICOM",
GIMP_EXPORT_CAN_HANDLE_RGB | GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_GRAY); GIMP_EXPORT_CAN_HANDLE_GRAY);
@ -260,8 +271,18 @@ 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))
{
status = GIMP_PDB_EXECUTION_ERROR; 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)
@ -276,7 +297,8 @@ run (const gchar *name,
} }
static gint32 static gint32
load_image (const gchar *filename) load_image (const gchar *filename,
GError **error)
{ {
GimpPixelRgn pixel_rgn; GimpPixelRgn pixel_rgn;
gint32 volatile image_ID = -1; gint32 volatile image_ID = -1;
@ -297,9 +319,10 @@ load_image (const gchar *filename)
/* open the file */ /* open the file */
DICOM = g_fopen (filename, "rb"); DICOM = g_fopen (filename, "rb");
if (!DICOM) if (! DICOM)
{ {
g_message (_("Could not open '%s' for reading: %s"), g_set_error (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;
} }
@ -325,7 +348,8 @@ load_image (const gchar *filename)
fread (buf, 1, 4, DICOM); /* This should be dicom */ fread (buf, 1, 4, DICOM); /* This should be dicom */
if (g_ascii_strncasecmp (buf,"DICM",4) != 0) if (g_ascii_strncasecmp (buf,"DICM",4) != 0)
{ {
g_message (_("'%s' is not a DICOM file."), g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("'%s' is not a DICOM file."),
gimp_filename_to_utf8 (filename)); gimp_filename_to_utf8 (filename));
return -1; return -1;
} }
@ -721,7 +745,8 @@ toggle_endian2 (guint16 *buf16,
static gboolean static gboolean
save_image (const gchar *filename, save_image (const gchar *filename,
gint32 image_ID, gint32 image_ID,
gint32 drawable_ID) gint32 drawable_ID,
GError **error)
{ {
FILE *DICOM; FILE *DICOM;
GimpImageType drawable_type; GimpImageType drawable_type;
@ -771,9 +796,10 @@ save_image (const gchar *filename,
if (!DICOM) if (!DICOM)
{ {
g_message (_("Could not open '%s' for writing: %s"),
gimp_filename_to_utf8 (filename), g_strerror (errno));
gimp_drawable_detach (drawable); gimp_drawable_detach (drawable);
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));
return FALSE; return FALSE;
} }