mirror of https://github.com/GNOME/gimp.git
plug-ins/file-fits/fits.c pass error messages with the return values
2008-08-20 Sven Neumann <sven@gimp.org> * plug-ins/file-fits/fits.c * plug-ins/file-fli/fli-gimp.c: pass error messages with the return values instead of calling g_message() svn path=/trunk/; revision=26676
This commit is contained in:
parent
74b29fe9c9
commit
584d078e5e
|
@ -1,3 +1,9 @@
|
||||||
|
2008-08-20 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* plug-ins/file-fits/fits.c
|
||||||
|
* plug-ins/file-fli/fli-gimp.c: 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-xjt/xjt.c: pass error messages with the return
|
* plug-ins/file-xjt/xjt.c: pass error messages with the return
|
||||||
|
|
|
@ -73,10 +73,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 FITS_HDU_LIST *create_fits_header (FITS_FILE *ofp,
|
static FITS_HDU_LIST *create_fits_header (FITS_FILE *ofp,
|
||||||
guint width,
|
guint width,
|
||||||
|
@ -207,6 +209,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;
|
||||||
|
|
||||||
l_run_mode = run_mode = (GimpRunMode)param[0].data.d_int32;
|
l_run_mode = run_mode = (GimpRunMode)param[0].data.d_int32;
|
||||||
|
|
||||||
|
@ -246,7 +249,7 @@ run (const gchar *name,
|
||||||
if (status == GIMP_PDB_SUCCESS)
|
if (status == GIMP_PDB_SUCCESS)
|
||||||
{
|
{
|
||||||
check_load_vals ();
|
check_load_vals ();
|
||||||
image_ID = load_image (param[1].data.d_string);
|
image_ID = load_image (param[1].data.d_string, &error);
|
||||||
|
|
||||||
/* Write out error messages of FITS-Library */
|
/* Write out error messages of FITS-Library */
|
||||||
show_fits_errors ();
|
show_fits_errors ();
|
||||||
|
@ -312,7 +315,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))
|
||||||
status = GIMP_PDB_EXECUTION_ERROR;
|
status = GIMP_PDB_EXECUTION_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,12 +328,20 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gint32
|
static gint32
|
||||||
load_image (const gchar *filename)
|
load_image (const gchar *filename,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
gint32 image_ID, *image_list, *nl;
|
gint32 image_ID, *image_list, *nl;
|
||||||
guint picnum;
|
guint picnum;
|
||||||
|
@ -342,23 +354,26 @@ load_image (const gchar *filename)
|
||||||
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),
|
||||||
|
_("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;
|
||||||
}
|
}
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
ifp = fits_open (filename, "r");
|
ifp = fits_open (filename, "r");
|
||||||
if (ifp == NULL)
|
if (ifp == NULL)
|
||||||
{
|
{
|
||||||
g_message (_("Error during open of FITS file"));
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||||
return (-1);
|
"%s", _("Error during open of FITS file"));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (ifp->n_pic <= 0)
|
if (ifp->n_pic <= 0)
|
||||||
{
|
{
|
||||||
g_message (_("FITS file keeps no displayable images"));
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||||
|
"%s", _("FITS file keeps no displayable images"));
|
||||||
fits_close (ifp);
|
fits_close (ifp);
|
||||||
return (-1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
image_list = g_new (gint32, 10);
|
image_list = g_new (gint32, 10);
|
||||||
|
@ -423,7 +438,8 @@ load_image (const gchar *filename)
|
||||||
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)
|
||||||
{
|
{
|
||||||
FITS_FILE* ofp;
|
FITS_FILE* ofp;
|
||||||
GimpImageType drawable_type;
|
GimpImageType drawable_type;
|
||||||
|
@ -434,7 +450,9 @@ save_image (const gchar *filename,
|
||||||
/* Make sure we're not saving an image with an alpha channel */
|
/* Make sure we're not saving an image with an alpha channel */
|
||||||
if (gimp_drawable_has_alpha (drawable_ID))
|
if (gimp_drawable_has_alpha (drawable_ID))
|
||||||
{
|
{
|
||||||
g_message (_("FITS save cannot handle images with alpha channels"));
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||||
|
"%s",
|
||||||
|
_("FITS save cannot handle images with alpha channels"));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,7 +472,8 @@ save_image (const gchar *filename,
|
||||||
ofp = fits_open (filename, "w");
|
ofp = fits_open (filename, "w");
|
||||||
if (!ofp)
|
if (!ofp)
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,19 +81,22 @@ static void run (const gchar *name,
|
||||||
/* return the image-ID of the new image, or -1 in case of an error */
|
/* return the image-ID of the new image, or -1 in case of an error */
|
||||||
static gint32 load_image (const gchar *filename,
|
static gint32 load_image (const gchar *filename,
|
||||||
gint32 from_frame,
|
gint32 from_frame,
|
||||||
gint32 to_frame);
|
gint32 to_frame,
|
||||||
static gboolean load_dialog (const gchar *name);
|
GError **error);
|
||||||
|
static gboolean load_dialog (const gchar *filename);
|
||||||
|
|
||||||
static gboolean save_image (const gchar *filename,
|
static gboolean save_image (const gchar *filename,
|
||||||
gint32 image_id,
|
gint32 image_id,
|
||||||
gint32 from_frame,
|
gint32 from_frame,
|
||||||
gint32 to_frame);
|
gint32 to_frame,
|
||||||
|
GError **error);
|
||||||
static gboolean save_dialog (gint32 image_id);
|
static gboolean save_dialog (gint32 image_id);
|
||||||
|
|
||||||
static gboolean get_info (const gchar *filename,
|
static gboolean get_info (const gchar *filename,
|
||||||
gint32 *width,
|
gint32 *width,
|
||||||
gint32 *height,
|
gint32 *height,
|
||||||
gint32 *frames);
|
gint32 *frames,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GIMP interface
|
* GIMP interface
|
||||||
|
@ -225,6 +228,7 @@ run (const gchar *name,
|
||||||
gint32 drawable_ID;
|
gint32 drawable_ID;
|
||||||
gint32 orig_image_ID;
|
gint32 orig_image_ID;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -274,7 +278,7 @@ run (const gchar *name,
|
||||||
-1 : param[4].data.d_int32);
|
-1 : param[4].data.d_int32);
|
||||||
|
|
||||||
image_ID = load_image (param[1].data.d_string,
|
image_ID = load_image (param[1].data.d_string,
|
||||||
from_frame, to_frame);
|
from_frame, to_frame, &error);
|
||||||
|
|
||||||
if (image_ID != -1)
|
if (image_ID != -1)
|
||||||
{
|
{
|
||||||
|
@ -283,14 +287,16 @@ run (const gchar *name,
|
||||||
values[1].data.d_image = image_ID;
|
values[1].data.d_image = image_ID;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
status = GIMP_PDB_EXECUTION_ERROR;
|
status = GIMP_PDB_EXECUTION_ERROR;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GIMP_RUN_INTERACTIVE:
|
case GIMP_RUN_INTERACTIVE:
|
||||||
if (load_dialog (param[1].data.d_string))
|
if (load_dialog (param[1].data.d_string))
|
||||||
{
|
{
|
||||||
image_ID = load_image (param[1].data.d_string,
|
image_ID = load_image (param[1].data.d_string,
|
||||||
from_frame, to_frame);
|
from_frame, to_frame, &error);
|
||||||
|
|
||||||
if (image_ID != -1)
|
if (image_ID != -1)
|
||||||
{
|
{
|
||||||
|
@ -299,10 +305,14 @@ run (const gchar *name,
|
||||||
values[1].data.d_image = image_ID;
|
values[1].data.d_image = image_ID;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
status = GIMP_PDB_EXECUTION_ERROR;
|
status = GIMP_PDB_EXECUTION_ERROR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
status = GIMP_PDB_CANCEL;
|
status = GIMP_PDB_CANCEL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GIMP_RUN_WITH_LAST_VALS:
|
case GIMP_RUN_WITH_LAST_VALS:
|
||||||
|
@ -333,8 +343,10 @@ run (const gchar *name,
|
||||||
}
|
}
|
||||||
if (! save_image (param[3].data.d_string, image_ID,
|
if (! save_image (param[3].data.d_string, image_ID,
|
||||||
param[5].data.d_int32,
|
param[5].data.d_int32,
|
||||||
param[6].data.d_int32))
|
param[6].data.d_int32, &error))
|
||||||
|
{
|
||||||
status = GIMP_PDB_EXECUTION_ERROR;
|
status = GIMP_PDB_EXECUTION_ERROR;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GIMP_RUN_INTERACTIVE:
|
case GIMP_RUN_INTERACTIVE:
|
||||||
|
@ -353,11 +365,16 @@ run (const gchar *name,
|
||||||
|
|
||||||
if (save_dialog (param[1].data.d_image))
|
if (save_dialog (param[1].data.d_image))
|
||||||
{
|
{
|
||||||
if (! save_image (param[3].data.d_string, image_ID, from_frame, to_frame))
|
if (! save_image (param[3].data.d_string,
|
||||||
|
image_ID, from_frame, to_frame, &error))
|
||||||
|
{
|
||||||
status = GIMP_PDB_EXECUTION_ERROR;
|
status = GIMP_PDB_EXECUTION_ERROR;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
status = GIMP_PDB_CANCEL;
|
status = GIMP_PDB_CANCEL;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,7 +405,8 @@ run (const gchar *name,
|
||||||
|
|
||||||
if (status == GIMP_PDB_SUCCESS)
|
if (status == GIMP_PDB_SUCCESS)
|
||||||
{
|
{
|
||||||
if (get_info (param[0].data.d_string, &width, &height, &frames))
|
if (get_info (param[0].data.d_string,
|
||||||
|
&width, &height, &frames, &error))
|
||||||
{
|
{
|
||||||
*nreturn_vals = 4;
|
*nreturn_vals = 4;
|
||||||
values[1].type = GIMP_PDB_INT32;
|
values[1].type = GIMP_PDB_INT32;
|
||||||
|
@ -399,11 +417,22 @@ run (const gchar *name,
|
||||||
values[3].data.d_int32 = frames;
|
values[3].data.d_int32 = frames;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
status = GIMP_PDB_EXECUTION_ERROR;
|
status = GIMP_PDB_EXECUTION_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -415,7 +444,8 @@ static gboolean
|
||||||
get_info (const gchar *filename,
|
get_info (const gchar *filename,
|
||||||
gint32 *width,
|
gint32 *width,
|
||||||
gint32 *height,
|
gint32 *height,
|
||||||
gint32 *frames)
|
gint32 *frames,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
s_fli_header fli_header;
|
s_fli_header fli_header;
|
||||||
|
@ -426,12 +456,15 @@ get_info (const gchar *filename,
|
||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
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 FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
fli_read_header (file, &fli_header);
|
fli_read_header (file, &fli_header);
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
*width = fli_header.width;
|
*width = fli_header.width;
|
||||||
*height = fli_header.height;
|
*height = fli_header.height;
|
||||||
*frames = fli_header.frames;
|
*frames = fli_header.frames;
|
||||||
|
@ -445,23 +478,23 @@ get_info (const gchar *filename,
|
||||||
static gint32
|
static gint32
|
||||||
load_image (const gchar *filename,
|
load_image (const gchar *filename,
|
||||||
gint32 from_frame,
|
gint32 from_frame,
|
||||||
gint32 to_frame)
|
gint32 to_frame,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
GimpDrawable *drawable;
|
GimpDrawable *drawable;
|
||||||
gint32 image_id, layer_ID;
|
gint32 image_id, layer_ID;
|
||||||
|
|
||||||
guchar *fb, *ofb, *fb_x;
|
guchar *fb, *ofb, *fb_x;
|
||||||
guchar cm[768], ocm[768];
|
guchar cm[768], ocm[768];
|
||||||
GimpPixelRgn pixel_rgn;
|
GimpPixelRgn pixel_rgn;
|
||||||
s_fli_header fli_header;
|
s_fli_header fli_header;
|
||||||
|
|
||||||
gint cnt;
|
gint cnt;
|
||||||
|
|
||||||
file = g_fopen (filename ,"rb");
|
file = g_fopen (filename ,"rb");
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -581,7 +614,8 @@ static gboolean
|
||||||
save_image (const gchar *filename,
|
save_image (const gchar *filename,
|
||||||
gint32 image_id,
|
gint32 image_id,
|
||||||
gint32 from_frame,
|
gint32 from_frame,
|
||||||
gint32 to_frame)
|
gint32 to_frame,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
GimpDrawable *drawable;
|
GimpDrawable *drawable;
|
||||||
|
@ -712,7 +746,8 @@ save_image (const gchar *filename,
|
||||||
file = g_fopen (filename ,"wb");
|
file = g_fopen (filename ,"wb");
|
||||||
if (!file)
|
if (!file)
|
||||||
{
|
{
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -792,7 +827,7 @@ save_image (const gchar *filename,
|
||||||
* Dialogs for interactive usage
|
* Dialogs for interactive usage
|
||||||
*/
|
*/
|
||||||
static gboolean
|
static gboolean
|
||||||
load_dialog (const gchar *name)
|
load_dialog (const gchar *filename)
|
||||||
{
|
{
|
||||||
GtkWidget *dialog;
|
GtkWidget *dialog;
|
||||||
GtkWidget *table;
|
GtkWidget *table;
|
||||||
|
@ -801,7 +836,7 @@ load_dialog (const gchar *name)
|
||||||
gint32 width, height, nframes;
|
gint32 width, height, nframes;
|
||||||
gboolean run;
|
gboolean run;
|
||||||
|
|
||||||
get_info (name, &width, &height, &nframes);
|
get_info (filename, &width, &height, &nframes, NULL);
|
||||||
|
|
||||||
from_frame = 1;
|
from_frame = 1;
|
||||||
to_frame = nframes;
|
to_frame = nframes;
|
||||||
|
|
Loading…
Reference in New Issue