plug-ins/common/file-pnm.c plug-ins/common/file-ps.c for the most common
2008-08-18 Sven Neumann <sven@gimp.org> * plug-ins/common/file-pnm.c * plug-ins/common/file-ps.c * plug-ins/common/file-psp.c: for the most common errors, pass the error message with the return values instead of calling gimp_message(). svn path=/trunk/; revision=26639
This commit is contained in:
committed by
Sven Neumann
parent
592d59765e
commit
edabd739d4
@ -1,3 +1,11 @@
|
||||
2008-08-18 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* plug-ins/common/file-pnm.c
|
||||
* plug-ins/common/file-ps.c
|
||||
* plug-ins/common/file-psp.c: for the most common errors, pass the
|
||||
error message with the return values instead of calling
|
||||
gimp_message().
|
||||
|
||||
2008-08-18 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* plug-ins/common/file-mng.c
|
||||
|
||||
@ -699,7 +699,7 @@ load_image (const gchar *filename,
|
||||
|
||||
if (setjmp (pp->jmpbuf))
|
||||
{
|
||||
g_set_error (error, 0, 0,
|
||||
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
||||
_("Error while reading '%s'. File corrupted?"),
|
||||
gimp_filename_to_utf8 (filename));
|
||||
return image;
|
||||
|
||||
@ -125,11 +125,13 @@ static void run (const gchar *name,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_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,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID,
|
||||
gboolean pbm);
|
||||
gboolean pbm,
|
||||
GError **error);
|
||||
|
||||
static gint save_dialog (void);
|
||||
|
||||
@ -321,13 +323,14 @@ 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;
|
||||
gboolean pbm = FALSE; /* flag for PBM output */
|
||||
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;
|
||||
gboolean pbm = FALSE; /* flag for PBM output */
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
@ -340,7 +343,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)
|
||||
{
|
||||
@ -437,7 +440,8 @@ run (const gchar *name,
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
if (save_image (param[3].data.d_string, image_ID, drawable_ID, pbm))
|
||||
if (save_image (param[3].data.d_string, image_ID, drawable_ID, pbm,
|
||||
&error))
|
||||
{
|
||||
/* Store psvals data */
|
||||
gimp_set_data (name, &psvals, sizeof (PNMSaveVals));
|
||||
@ -456,11 +460,19 @@ 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;
|
||||
}
|
||||
|
||||
static gint32
|
||||
load_image (const gchar *filename)
|
||||
load_image (const gchar *filename,
|
||||
GError **error)
|
||||
{
|
||||
GimpPixelRgn pixel_rgn;
|
||||
gint32 volatile image_ID = -1;
|
||||
@ -477,8 +489,9 @@ load_image (const gchar *filename)
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -916,10 +929,11 @@ pnmsaverow_ascii_indexed (PNMRowInfo *ri,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID,
|
||||
gboolean pbm)
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID,
|
||||
gboolean pbm,
|
||||
GError **error)
|
||||
{
|
||||
GimpPixelRgn pixel_rgn;
|
||||
GimpDrawable *drawable;
|
||||
@ -955,8 +969,9 @@ save_image (const gchar *filename,
|
||||
|
||||
if (fd == -1)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -194,10 +194,12 @@ 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 gint save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID);
|
||||
gint32 drawable_ID,
|
||||
GError **error);
|
||||
|
||||
static gint save_gray (FILE *ofp,
|
||||
gint32 image_ID,
|
||||
@ -759,13 +761,14 @@ 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 = -1;
|
||||
gint32 drawable_ID = -1;
|
||||
gint32 orig_image_ID = -1;
|
||||
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
||||
static GimpParam values[2];
|
||||
GimpRunMode run_mode;
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
gint32 image_ID = -1;
|
||||
gint32 drawable_ID = -1;
|
||||
gint32 orig_image_ID = -1;
|
||||
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
||||
GError *error = NULL;
|
||||
|
||||
l_run_mode = run_mode = param[0].data.d_int32;
|
||||
|
||||
@ -812,7 +815,7 @@ run (const gchar *name,
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
check_load_vals ();
|
||||
image_ID = load_image (param[1].data.d_string);
|
||||
image_ID = load_image (param[1].data.d_string, &error);
|
||||
|
||||
if (image_ID != -1)
|
||||
{
|
||||
@ -851,7 +854,7 @@ run (const gchar *name,
|
||||
strcpy (plvals.pages, "1");
|
||||
|
||||
check_load_vals ();
|
||||
image_ID = load_image (param[0].data.d_string);
|
||||
image_ID = load_image (param[0].data.d_string, &error);
|
||||
|
||||
if (image_ID != -1)
|
||||
{
|
||||
@ -944,7 +947,8 @@ run (const gchar *name,
|
||||
ps_set_save_size (&psvals, orig_image_ID);
|
||||
|
||||
check_save_vals ();
|
||||
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 */
|
||||
gimp_set_data (name, &psvals, sizeof (PSSaveVals));
|
||||
@ -990,12 +994,20 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
static gint32
|
||||
load_image (const gchar *filename)
|
||||
load_image (const gchar *filename,
|
||||
GError **error)
|
||||
{
|
||||
gint32 image_ID = 0;
|
||||
gint32 *image_list, *nl;
|
||||
@ -1020,8 +1032,9 @@ load_image (const gchar *filename)
|
||||
ifp = g_fopen (filename, "r");
|
||||
if (ifp == NULL)
|
||||
{
|
||||
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;
|
||||
}
|
||||
fclose (ifp);
|
||||
@ -1156,9 +1169,10 @@ load_image (const gchar *filename)
|
||||
|
||||
|
||||
static gint
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID)
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID,
|
||||
GError **error)
|
||||
{
|
||||
FILE* ofp;
|
||||
GimpImageType drawable_type;
|
||||
@ -1193,8 +1207,9 @@ save_image (const gchar *filename,
|
||||
ofp = g_fopen (filename, "wb");
|
||||
if (!ofp)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@ -528,10 +528,12 @@ static void run (const gchar *name,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_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,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID);
|
||||
gint32 drawable_ID,
|
||||
GError **error);
|
||||
|
||||
/* Various local variables...
|
||||
*/
|
||||
@ -607,7 +609,7 @@ query (void)
|
||||
"",
|
||||
"0,string,Paint\\040Shop\\040Pro\\040Image\\040File\n\032");
|
||||
|
||||
/* Removed until Saving is implemented -- njl195@zepler.org */
|
||||
/* commented out until saving is implemented */
|
||||
#if 0
|
||||
gimp_install_procedure (SAVE_PROC,
|
||||
"saves images in the Paint Shop Pro PSP file format",
|
||||
@ -1725,7 +1727,8 @@ compression_name (gint compression)
|
||||
/* The main function for loading PSP-images
|
||||
*/
|
||||
static gint32
|
||||
load_image (const gchar *filename)
|
||||
load_image (const gchar *filename,
|
||||
GError **error)
|
||||
{
|
||||
FILE *f;
|
||||
struct stat st;
|
||||
@ -1744,8 +1747,9 @@ load_image (const gchar *filename)
|
||||
f = g_fopen (filename, "rb");
|
||||
if (f == NULL)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1917,9 +1921,10 @@ load_image (const gchar *filename)
|
||||
}
|
||||
|
||||
static gint
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID)
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID,
|
||||
GError **error)
|
||||
{
|
||||
g_message ("Saving not implemented yet");
|
||||
|
||||
@ -1933,12 +1938,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;
|
||||
|
||||
INIT_I18N ();
|
||||
|
||||
@ -1952,7 +1958,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)
|
||||
{
|
||||
@ -2028,7 +2034,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))
|
||||
{
|
||||
gimp_set_data (SAVE_PROC, &psvals, sizeof (PSPSaveVals));
|
||||
}
|
||||
@ -2046,5 +2053,12 @@ 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user