pass error messages with the return values instead of calling g_message().

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

	* plug-ins/file-xjt/xjt.c: pass error messages with the return
	values instead of calling g_message().


svn path=/trunk/; revision=26675
This commit is contained in:
Sven Neumann
2008-08-20 13:01:57 +00:00
committed by Sven Neumann
parent 6f3a122953
commit 74b29fe9c9
2 changed files with 57 additions and 31 deletions

View File

@ -1,3 +1,8 @@
2008-08-20 Sven Neumann <sven@gimp.org>
* plug-ins/file-xjt/xjt.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-sgi/sgi.c * plug-ins/file-sgi/sgi.c

View File

@ -399,10 +399,12 @@ static void run (const gchar *name,
gint *nreturn_vals, gint *nreturn_vals,
GimpParam **return_vals); GimpParam **return_vals);
static gint32 load_xjt_image (const gchar *filename); static gint32 load_xjt_image (const gchar *filename,
GError **error);
static gint save_xjt_image (const gchar *filename, static gint save_xjt_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);
@ -521,14 +523,15 @@ 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;
gchar *l_env; const gchar *l_env;
GError *error = NULL;
g_pid = getpid (); g_pid = getpid ();
xjt_debug = FALSE; xjt_debug = FALSE;
INIT_I18N (); INIT_I18N ();
l_env = getenv("XJT_DEBUG"); l_env = getenv ("XJT_DEBUG");
if(l_env != NULL) if(l_env != NULL)
{ {
if((*l_env != 'n') && (*l_env != 'N')) xjt_debug = TRUE; if((*l_env != 'n') && (*l_env != 'N')) xjt_debug = TRUE;
@ -543,7 +546,7 @@ run (const gchar *name,
if (strcmp (name, LOAD_PROC) == 0) if (strcmp (name, LOAD_PROC) == 0)
{ {
image_ID = load_xjt_image (param[1].data.d_string); image_ID = load_xjt_image (param[1].data.d_string, &error);
if (image_ID != -1) if (image_ID != -1)
{ {
@ -608,7 +611,8 @@ run (const gchar *name,
{ {
if (save_xjt_image (param[3].data.d_string, if (save_xjt_image (param[3].data.d_string,
param[1].data.d_int32, param[1].data.d_int32,
param[2].data.d_int32) <0) param[2].data.d_int32,
&error) < 0)
{ {
status = GIMP_PDB_EXECUTION_ERROR; status = GIMP_PDB_EXECUTION_ERROR;
} }
@ -624,6 +628,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;
} }
@ -1637,7 +1648,8 @@ p_write_image_prp (const gchar *dirname,
static gint static gint
save_xjt_image (const gchar *filename, save_xjt_image (const gchar *filename,
gint32 image_id, gint32 image_id,
gint32 drawable_id) gint32 drawable_id,
GError **error)
{ {
int l_rc; int l_rc;
int l_len; int l_len;
@ -1703,7 +1715,8 @@ save_xjt_image (const gchar *filename,
l_prop_file = g_strdup_printf ("%s%cPRP", l_dirname, G_DIR_SEPARATOR); l_prop_file = g_strdup_printf ("%s%cPRP", l_dirname, G_DIR_SEPARATOR);
if (g_mkdir (l_dirname, 0777) != 0) if (g_mkdir (l_dirname, 0777) != 0)
{ {
g_message (_("Could not create working folder '%s': %s"), g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not create working folder '%s': %s"),
gimp_filename_to_utf8 (l_dirname), g_strerror (errno)); gimp_filename_to_utf8 (l_dirname), g_strerror (errno));
goto cleanup; goto cleanup;
} }
@ -1712,7 +1725,8 @@ save_xjt_image (const gchar *filename,
l_fp_prp = g_fopen (l_prop_file, "wb"); l_fp_prp = g_fopen (l_prop_file, "wb");
if (l_fp_prp == NULL) if (l_fp_prp == 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 (l_prop_file), g_strerror (errno)); gimp_filename_to_utf8 (l_prop_file), g_strerror (errno));
goto cleanup; goto cleanup;
} }
@ -3202,7 +3216,8 @@ p_next_lineindex (const gchar *file_buff,
*/ */
static t_image_props * static t_image_props *
p_load_prop_file (const gchar *prop_filename) p_load_prop_file (const gchar *prop_filename,
GError **error)
{ {
gint32 l_filesize; gint32 l_filesize;
gint32 l_line_idx; gint32 l_line_idx;
@ -3220,13 +3235,15 @@ p_load_prop_file (const gchar *prop_filename)
l_file_buff = p_load_linefile(prop_filename, &l_filesize); l_file_buff = p_load_linefile(prop_filename, &l_filesize);
if(l_file_buff == NULL) if(l_file_buff == NULL)
{ {
g_message(_("Error: Could not read XJT property file '%s'."), g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error: Could not read XJT property file '%s'."),
gimp_filename_to_utf8 (prop_filename)); gimp_filename_to_utf8 (prop_filename));
goto cleanup; goto cleanup;
} }
if(l_filesize == 0) if(l_filesize == 0)
{ {
g_message(_("Error: XJT property file '%s' is empty."), g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error: XJT property file '%s' is empty."),
gimp_filename_to_utf8 (prop_filename)); gimp_filename_to_utf8 (prop_filename));
goto cleanup; goto cleanup;
} }
@ -3306,7 +3323,8 @@ cleanup:
/* ---------------------- LOAD -------------------------- */ /* ---------------------- LOAD -------------------------- */
static gint32 static gint32
load_xjt_image (const gchar *filename) load_xjt_image (const gchar *filename,
GError **error)
{ {
int l_rc; int l_rc;
int l_len; int l_len;
@ -3349,9 +3367,10 @@ load_xjt_image (const gchar *filename)
l_dirname = gimp_temp_name (".tmpdir"); l_dirname = gimp_temp_name (".tmpdir");
l_prop_file = g_strdup_printf("%s%cPRP", l_dirname, G_DIR_SEPARATOR); l_prop_file = g_strdup_printf("%s%cPRP", l_dirname, G_DIR_SEPARATOR);
if(g_mkdir(l_dirname, 0777) != 0) if (g_mkdir (l_dirname, 0777) != 0)
{ {
g_message (_("Could not create working folder '%s': %s"), g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
_("Could not create working folder '%s': %s"),
gimp_filename_to_utf8 (l_dirname), g_strerror (errno)); gimp_filename_to_utf8 (l_dirname), g_strerror (errno));
goto cleanup; goto cleanup;
} }
@ -3411,9 +3430,10 @@ load_xjt_image (const gchar *filename)
goto cleanup; goto cleanup;
/* check and read Property file (PRP must exist in each xjt archive) */ /* check and read Property file (PRP must exist in each xjt archive) */
l_image_prp_ptr = p_load_prop_file(l_prop_file); l_image_prp_ptr = p_load_prop_file(l_prop_file, error);
if (l_image_prp_ptr == NULL) if (l_image_prp_ptr == NULL)
{ l_rc = -1; {
l_rc = -1;
goto cleanup; goto cleanup;
} }
@ -3423,7 +3443,8 @@ load_xjt_image (const gchar *filename)
l_image_prp_ptr->image_height, l_image_prp_ptr->image_height,
l_image_prp_ptr->image_type); l_image_prp_ptr->image_type);
if(l_image_id < 0) if(l_image_id < 0)
{ l_rc = -1; {
l_rc = -1;
goto cleanup; goto cleanup;
} }