diff --git a/ChangeLog b/ChangeLog index a3ae27cf56..4a5a1a7653 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-08-18 Sven Neumann + + * plug-ins/common/file-mng.c + * plug-ins/common/file-pcx.c: for the most common errors, + pass the error message with the return values instead of calling + gimp_message(). + + * plug-ins/common/file-gif-save.c + * plug-ins/common/file-pdf.c + * plug-ins/common/file-png.c: minor cleanup. + 2008-08-17 Sven Neumann * plug-ins/common/file-pdf.c: in case of an error, pass the error diff --git a/plug-ins/common/file-gif-save.c b/plug-ins/common/file-gif-save.c index 6252dac78d..87d93158a6 100644 --- a/plug-ins/common/file-gif-save.c +++ b/plug-ins/common/file-gif-save.c @@ -288,13 +288,13 @@ run (const gchar *name, if (export == GIMP_EXPORT_EXPORT) gimp_image_delete (image_ID); + } - if (status == GIMP_PDB_EXECUTION_ERROR && error) - { - *nreturn_vals = 2; - values[1].type = GIMP_PDB_STRING; - values[1].data.d_string = error->message; - } + 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; diff --git a/plug-ins/common/file-mng.c b/plug-ins/common/file-mng.c index 473c587ff7..be669a9c1e 100644 --- a/plug-ins/common/file-mng.c +++ b/plug-ins/common/file-mng.c @@ -172,43 +172,45 @@ struct mnglib_userdata_t * Function prototypes */ -static mng_ptr myalloc (mng_size_t size); -static void myfree (mng_ptr ptr, - mng_size_t size); -static mng_bool myopenstream (mng_handle handle); -static mng_bool myclosestream (mng_handle handle); -static mng_bool mywritedata (mng_handle handle, - mng_ptr buf, - mng_uint32 size, - mng_uint32 *written_size); +static mng_ptr myalloc (mng_size_t size); +static void myfree (mng_ptr ptr, + mng_size_t size); +static mng_bool myopenstream (mng_handle handle); +static mng_bool myclosestream (mng_handle handle); +static mng_bool mywritedata (mng_handle handle, + mng_ptr buf, + mng_uint32 size, + mng_uint32 *written_size); -static gint32 parse_chunks_type_from_layer_name (const gchar *str); -static gint32 parse_disposal_type_from_layer_name (const gchar *str); -static gint32 parse_ms_tag_from_layer_name (const gchar *str); -static gint find_unused_ia_colour (guchar *pixels, - gint numpixels, - gint *colors); -static gboolean ia_has_transparent_pixels (guchar *pixels, - gint numpixels); +static gint32 parse_chunks_type_from_layer_name (const gchar *str); +static gint32 parse_disposal_type_from_layer_name (const gchar *str); +static gint32 parse_ms_tag_from_layer_name (const gchar *str); +static gint find_unused_ia_colour (guchar *pixels, + gint numpixels, + gint *colors); +static gboolean ia_has_transparent_pixels (guchar *pixels, + gint numpixels); +static gboolean respin_cmap (png_structp png_ptr, + png_infop png_info_ptr, + guchar *remap, + gint32 image_id, + GimpDrawable *drawable); -static gboolean respin_cmap (png_structp png_ptr, - png_infop png_info_ptr, - guchar *remap, - gint32 image_id, - GimpDrawable *drawable); -static gboolean mng_save_image (const gchar *filename, - gint32 image_id, - gint32 drawable_id, - gint32 original_image_id); -static gint mng_save_dialog (gint32 image_id); -static void query (void); -static void run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals); +static gboolean mng_save_image (const gchar *filename, + gint32 image_id, + gint32 drawable_id, + gint32 original_image_id, + GError **error); +static gboolean mng_save_dialog (gint32 image_id); + +static void query (void); +static void run (const gchar *name, + gint nparams, + const GimpParam *param, + gint *nreturn_vals, + GimpParam **return_vals); /* @@ -505,10 +507,11 @@ respin_cmap (png_structp png_ptr, static gboolean -mng_save_image (const gchar *filename, - gint32 image_id, - gint32 drawable_id, - gint32 original_image_id) +mng_save_image (const gchar *filename, + gint32 image_id, + gint32 drawable_id, + gint32 original_image_id, + GError **error) { gboolean ret = FALSE; gint rows, cols; @@ -568,8 +571,9 @@ mng_save_image (const gchar *filename, if (NULL == userdata->fp) { - g_message (_("Could not open '%s' for writing: %s"), - gimp_filename_to_utf8 (filename), g_strerror (errno)); + 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)); goto err; } @@ -655,7 +659,7 @@ mng_save_image (const gchar *filename, MNG_BACKGROUNDCOLOR_MANDATORY, 0, MNG_BACKGROUNDIMAGE_NOTILE) != MNG_NOERROR) { - g_warning("Unable to mng_putchunk_back() in mng_save_image()"); + g_warning ("Unable to mng_putchunk_back() in mng_save_image()"); goto err3; } @@ -663,7 +667,7 @@ mng_save_image (const gchar *filename, gimp_rgb_luminance_uchar (&bgcolor), red, green, blue) != MNG_NOERROR) { - g_warning("Unable to mng_putchunk_bkgd() in mng_save_image()"); + g_warning ("Unable to mng_putchunk_bkgd() in mng_save_image()"); goto err3; } } @@ -691,7 +695,7 @@ mng_save_image (const gchar *filename, (mng_uint32) (xres * 39.37), (mng_uint32) (yres * 39.37), 1) != MNG_NOERROR) { - g_warning("Unable to mng_putchunk_phyg() in mng_save_image()"); + g_warning ("Unable to mng_putchunk_phyg() in mng_save_image()"); goto err3; } @@ -699,7 +703,7 @@ mng_save_image (const gchar *filename, (mng_uint32) (xres * 39.37), (mng_uint32) (yres * 39.37), 1) != MNG_NOERROR) { - g_warning("Unable to mng_putchunk_phys() in mng_save_image()"); + g_warning ("Unable to mng_putchunk_phys() in mng_save_image()"); goto err3; } } @@ -901,9 +905,10 @@ mng_save_image (const gchar *filename, if ((outfile = g_fopen (temp_file_name, "wb")) == NULL) { - g_message (_("Could not open '%s' for writing: %s"), - gimp_filename_to_utf8 (temp_file_name), - g_strerror (errno)); + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + _("Could not open '%s' for writing: %s"), + gimp_filename_to_utf8 (temp_file_name), + g_strerror (errno)); g_unlink (temp_file_name); goto err3; } @@ -1064,9 +1069,10 @@ mng_save_image (const gchar *filename, infile = g_fopen (temp_file_name, "rb"); if (NULL == infile) { - g_message (_("Could not open '%s' for reading: %s"), - gimp_filename_to_utf8 (temp_file_name), - g_strerror (errno)); + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + _("Could not open '%s' for reading: %s"), + gimp_filename_to_utf8 (temp_file_name), + g_strerror (errno)); g_unlink (temp_file_name); goto err3; } @@ -1226,7 +1232,7 @@ mng_save_image (const gchar *filename, /* The interactive dialog. */ -static gint +static gboolean mng_save_dialog (gint32 image_id) { GtkWidget *dialog; @@ -1245,7 +1251,6 @@ mng_save_dialog (gint32 image_id) gint num_layers; gboolean run; - dialog = gimp_dialog_new (_("Save as MNG"), PLUG_IN_BINARY, NULL, 0, gimp_standard_help_func, SAVE_PROC, @@ -1540,7 +1545,7 @@ run (const gchar *name, gint *nreturn_vals, GimpParam **return_vals) { - static GimpParam values[1]; + static GimpParam values[2]; INIT_I18N (); @@ -1551,14 +1556,11 @@ run (const gchar *name, if (strcmp (name, SAVE_PROC) == 0) { - GimpRunMode run_mode; - gint32 image_id, original_image_id; - gint32 drawable_id; - GimpExportReturn export = GIMP_EXPORT_IGNORE; - - run_mode = param[0].data.d_int32; - image_id = original_image_id = param[1].data.d_int32; - drawable_id = param[2].data.d_int32; + GimpRunMode run_mode = param[0].data.d_int32; + gint32 image_id = param[1].data.d_int32; + gint32 original_image_id = image_id; + gint32 drawable_id = param[2].data.d_int32; + GimpExportReturn export = GIMP_EXPORT_IGNORE; if ((run_mode == GIMP_RUN_INTERACTIVE) || (run_mode == GIMP_RUN_WITH_LAST_VALS)) @@ -1575,9 +1577,10 @@ run (const gchar *name, } if (export == GIMP_EXPORT_CANCEL) - values[0].data.d_status = GIMP_PDB_CANCEL; - else if ((export == GIMP_EXPORT_IGNORE) - || (export == GIMP_EXPORT_EXPORT)) + { + values[0].data.d_status = GIMP_PDB_CANCEL; + } + else if (export == GIMP_EXPORT_IGNORE || export == GIMP_EXPORT_EXPORT) { if (run_mode == GIMP_RUN_INTERACTIVE) { @@ -1656,12 +1659,25 @@ run (const gchar *name, if (values[0].data.d_status == GIMP_PDB_SUCCESS) { + GError *error = NULL; + if (mng_save_image (param[3].data.d_string, image_id, drawable_id, - original_image_id)) - gimp_set_data (SAVE_PROC, &mng_data, sizeof (mng_data)); + original_image_id, &error)) + { + gimp_set_data (SAVE_PROC, &mng_data, sizeof (mng_data)); + } 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) @@ -1670,10 +1686,13 @@ run (const gchar *name, } else - values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR; + { + values[0].data.d_status = GIMP_PDB_CALLING_ERROR; + } } + /* Only query and run are implemented by this plug-in. */ const GimpPlugInInfo PLUG_IN_INFO = diff --git a/plug-ins/common/file-pcx.c b/plug-ins/common/file-pcx.c index 71ca22eaf5..ec1aa9298c 100644 --- a/plug-ins/common/file-pcx.c +++ b/plug-ins/common/file-pcx.c @@ -46,7 +46,9 @@ static void run (const gchar *name, gint *nreturn_vals, GimpParam **return_vals); -static gint32 load_image (const gchar *filename); +static gint32 load_image (const gchar *filename, + GError **error); + static void load_1 (FILE *fp, gint width, gint height, @@ -73,7 +75,9 @@ static void readline (FILE *fp, static gint save_image (const gchar *filename, gint32 image, - gint32 layer); + gint32 layer, + GError **error); + static void save_8 (FILE *fp, gint width, gint height, @@ -162,12 +166,13 @@ run (const gchar *name, gint *nreturn_vals, GimpParam **return_vals) { - static GimpParam values[2]; - GimpRunMode run_mode; - GimpPDBStatusType status = GIMP_PDB_SUCCESS; - gint32 image_ID; - gint32 drawable_ID; - GimpExportReturn export = GIMP_EXPORT_CANCEL; + static GimpParam values[2]; + GimpRunMode run_mode; + GimpPDBStatusType status = GIMP_PDB_SUCCESS; + gint32 image_ID; + gint32 drawable_ID; + GimpExportReturn export = GIMP_EXPORT_CANCEL; + GError *error = NULL; run_mode = param[0].data.d_int32; @@ -181,7 +186,7 @@ run (const gchar *name, 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) { @@ -205,6 +210,7 @@ run (const gchar *name, case GIMP_RUN_INTERACTIVE: case GIMP_RUN_WITH_LAST_VALS: gimp_ui_init (PLUG_IN_BINARY, FALSE); + export = gimp_export_image (&image_ID, &drawable_ID, "PCX", (GIMP_EXPORT_CAN_HANDLE_RGB | GIMP_EXPORT_CAN_HANDLE_GRAY | @@ -238,7 +244,8 @@ run (const gchar *name, 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; } @@ -252,6 +259,13 @@ run (const gchar *name, 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; } @@ -327,7 +341,8 @@ pcx_header_to_buffer (guint8 *buf) } static gint32 -load_image (const gchar *filename) +load_image (const gchar *filename, + GError **error) { FILE *fd; GimpDrawable *drawable; @@ -339,10 +354,12 @@ load_image (const gchar *filename) guint8 header_buf[128]; fd = g_fopen (filename, "rb"); - if (!fd) + + if (! fd) { - g_message (_("Could not open '%s' for reading: %s"), - gimp_filename_to_utf8 (filename), g_strerror (errno)); + 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)); return -1; } @@ -351,8 +368,9 @@ load_image (const gchar *filename) if (fread (header_buf, 128, 1, fd) == 0) { - g_message (_("Could not read header from '%s'"), - gimp_filename_to_utf8 (filename)); + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + _("Could not read header from '%s'"), + gimp_filename_to_utf8 (filename)); return -1; } @@ -360,8 +378,9 @@ load_image (const gchar *filename) if (pcx_header.manufacturer != 10) { - g_message (_("'%s' is not a PCX file"), - gimp_filename_to_utf8 (filename)); + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + _("'%s' is not a PCX file"), + gimp_filename_to_utf8 (filename)); return -1; } @@ -582,9 +601,10 @@ readline (FILE *fp, } static gint -save_image (const gchar *filename, - gint32 image, - gint32 layer) +save_image (const gchar *filename, + gint32 image, + gint32 layer, + GError **error) { FILE *fp; GimpPixelRgn pixel_rgn; @@ -642,8 +662,9 @@ save_image (const gchar *filename, if ((fp = g_fopen (filename, "wb")) == NULL) { - g_message (_("Could not open '%s' for writing: %s"), - gimp_filename_to_utf8 (filename), g_strerror (errno)); + 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; } @@ -727,10 +748,12 @@ save_image (const gchar *filename, if (fclose (fp) != 0) { - g_message (_("Writing to file '%s' failed: %s"), - gimp_filename_to_utf8 (filename), g_strerror (errno)); + g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno), + _("Writing to file '%s' failed: %s"), + gimp_filename_to_utf8 (filename), g_strerror (errno)); return FALSE; } + return TRUE; } diff --git a/plug-ins/common/file-pdf.c b/plug-ins/common/file-pdf.c index e95f7b271c..cbbbc2e3bd 100644 --- a/plug-ins/common/file-pdf.c +++ b/plug-ins/common/file-pdf.c @@ -502,7 +502,7 @@ run (const gchar *name, status = GIMP_PDB_CALLING_ERROR; } - if (status == GIMP_PDB_EXECUTION_ERROR && error) + if (status != GIMP_PDB_SUCCESS && error) { *nreturn_vals = 2; values[1].type = GIMP_PDB_STRING; diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c index cf11d4c184..7666030903 100644 --- a/plug-ins/common/file-png.c +++ b/plug-ins/common/file-png.c @@ -414,13 +414,6 @@ run (const gchar *name, else { 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 || @@ -544,13 +537,6 @@ run (const gchar *name, else { status = GIMP_PDB_EXECUTION_ERROR; - - if (error) - { - *nreturn_vals = 2; - values[1].type = GIMP_PDB_STRING; - values[1].data.d_string = error->message; - } } } @@ -597,11 +583,20 @@ run (const gchar *name, save_defaults (); } else - status = GIMP_PDB_CALLING_ERROR; + { + status = GIMP_PDB_CALLING_ERROR; + } } else { - status = GIMP_PDB_EXECUTION_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;