plug-ins/common/file-gbr.c plug-ins/common/file-gih.c

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

	* plug-ins/common/file-gbr.c
	* plug-ins/common/file-gih.c
	* plug-ins/common/file-pat.c
	* plug-ins/common/file-pix.c
	* plug-ins/common/file-sunras.c: for the most common errors, 
pass
	the error message with the return values instead of calling
	g_message().


svn path=/trunk/; revision=26650
This commit is contained in:
Sven Neumann
2008-08-18 19:35:55 +00:00
committed by Sven Neumann
parent 9dde6e448d
commit a1cbd58195
6 changed files with 208 additions and 116 deletions

View File

@ -1,3 +1,13 @@
2008-08-18 Sven Neumann <sven@gimp.org>
* plug-ins/common/file-gbr.c
* plug-ins/common/file-gih.c
* plug-ins/common/file-pat.c
* plug-ins/common/file-pix.c
* plug-ins/common/file-sunras.c: for the most common errors, pass
the error message with the return values instead of calling
g_message().
2008-08-18 Michael Natterer <mitch@gimp.org>
* plug-ins/common/compressor.c: renamed...

View File

@ -88,10 +88,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 gboolean save_image (const gchar *filename,
gint32 image_ID,
gint32 drawable_ID);
gint32 drawable_ID,
GError **error);
static gboolean save_dialog (void);
static void entry_callback (GtkWidget *widget,
@ -195,6 +197,7 @@ run (const gchar *name,
gint32 image_ID;
gint32 drawable_ID;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
run_mode = param[0].data.d_int32;
@ -208,7 +211,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)
{
@ -292,7 +295,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, &info, sizeof (info));
}
@ -322,11 +326,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)
{
gchar *name;
gint fd;
@ -345,7 +357,8 @@ load_image (const gchar *filename)
if (fd == -1)
{
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));
return -1;
}
@ -408,7 +421,8 @@ load_image (const gchar *filename)
if ((read (fd, temp, bn_size)) < bn_size)
{
g_message (_("Error in GIMP brush file '%s'"),
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error in GIMP brush file '%s'"),
gimp_filename_to_utf8 (filename));
close (fd);
g_free (temp);
@ -580,7 +594,8 @@ load_image (const gchar *filename)
static gboolean
save_image (const gchar *filename,
gint32 image_ID,
gint32 drawable_ID)
gint32 drawable_ID,
GError **error)
{
gint fd;
BrushHeader bh;
@ -613,7 +628,8 @@ save_image (const gchar *filename,
if (fd == -1)
{
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));
return FALSE;
}

View File

@ -99,7 +99,7 @@ static struct
static gint num_useable_layers;
static gchar *selection_modes[] = {"incremental",
static const gchar *selection_modes[] = { "incremental",
"angular",
"random",
"velocity",
@ -139,7 +139,8 @@ static void run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals);
static gint32 gih_load_image (const gchar *filename);
static gint32 gih_load_image (const gchar *filename,
GError **error);
static gboolean gih_load_one_brush (gint fd,
gint32 image_ID);
@ -150,7 +151,8 @@ static gboolean gih_save_one_brush (gint fd,
static gboolean gih_save_image (const gchar *filename,
gint32 image_ID,
gint32 orig_image_ID,
gint32 drawable_ID);
gint32 drawable_ID,
GError **error);
const GimpPlugInInfo PLUG_IN_INFO =
@ -258,6 +260,7 @@ run (const gchar *name,
gchar *layer_name;
gint i;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
run_mode = param[0].data.d_int32;
@ -271,7 +274,7 @@ run (const gchar *name,
if (strcmp (name, LOAD_PROC) == 0)
{
image_ID = gih_load_image (param[1].data.d_string);
image_ID = gih_load_image (param[1].data.d_string, &error);
if (image_ID != -1)
{
@ -337,7 +340,8 @@ run (const gchar *name,
if (gihparams.rows < 1) gihparams.rows = 1;
if (gihparams.cols < 1) gihparams.cols = 1;
gihparams.ncells = num_useable_layers * gihparams.rows * gihparams.cols;
gihparams.ncells = (num_useable_layers *
gihparams.rows * gihparams.cols);
if (gihparams.cellwidth == 1 && gihparams.cellheight == 1)
{
@ -409,7 +413,7 @@ run (const gchar *name,
if (status == GIMP_PDB_SUCCESS)
{
if (gih_save_image (param[3].data.d_string,
image_ID, orig_image_ID, drawable_ID))
image_ID, orig_image_ID, drawable_ID, &error))
{
gimp_set_data (SAVE_PROC, &info, sizeof (info));
}
@ -427,6 +431,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;
}
@ -630,7 +641,8 @@ gih_load_one_brush (gint fd,
}
static gint32
gih_load_image (const gchar *filename)
gih_load_image (const gchar *filename,
GError **error)
{
gint fd;
gint i;
@ -646,7 +658,8 @@ gih_load_image (const gchar *filename)
if (fd == -1)
{
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));
return -1;
}
@ -700,7 +713,9 @@ gih_load_image (const gchar *filename)
{
if (! gih_load_one_brush (fd, image_ID))
{
g_message (_("Couldn't load one brush in the pipe, giving up."));
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"%s",
_("Couldn't load one brush in the pipe, giving up."));
close (fd);
g_free (name);
g_string_free (buffer, TRUE);
@ -1231,7 +1246,8 @@ static gboolean
gih_save_image (const gchar *filename,
gint32 image_ID,
gint32 orig_image_ID,
gint32 drawable_ID)
gint32 drawable_ID,
GError **error)
{
GimpDrawable *drawable;
GimpPixelRgn pixel_rgn;
@ -1255,7 +1271,8 @@ gih_save_image (const gchar *filename,
if (fd == -1)
{
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));
return FALSE;
}

View File

@ -63,10 +63,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 gboolean save_image (const gchar *filename,
gint32 image_ID,
gint32 drawable_ID);
gint32 drawable_ID,
GError **error);
static gboolean save_dialog (void);
@ -165,6 +167,7 @@ run (const gchar *name,
gint32 image_ID;
gint32 drawable_ID;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
run_mode = param[0].data.d_int32;
@ -178,7 +181,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)
{
@ -261,7 +264,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, description, sizeof (description));
}
@ -291,11 +295,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)
{
gint fd;
PatternHeader ph;
@ -314,7 +326,8 @@ load_image (const gchar *filename)
if (fd == -1)
{
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));
return -1;
}
@ -431,7 +444,8 @@ load_image (const gchar *filename)
static gboolean
save_image (const gchar *filename,
gint32 image_ID,
gint32 drawable_ID)
gint32 drawable_ID,
GError **error)
{
gint fd;
PatternHeader ph;
@ -444,7 +458,8 @@ save_image (const gchar *filename,
if (fd == -1)
{
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));
return FALSE;
}

View File

@ -81,10 +81,12 @@ static void run (const gchar *name,
/* Local Helper Functions */
static gint32 load_image (const gchar *filename);
static gint32 load_image (const gchar *filename,
GError **error);
static gboolean save_image (const gchar *filename,
gint32 image_ID,
gint32 drawable_ID);
gint32 drawable_ID,
GError **error);
static guint16 get_short (FILE *file);
static void put_short (guint16 value,
@ -188,6 +190,7 @@ run (const gchar *name,
gint32 image_ID;
gint32 drawable_ID;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
run_mode = param[0].data.d_int32;
@ -201,7 +204,7 @@ run (const gchar *name,
if (strcmp (name, LOAD_PROC) == 0)
{
/* Perform the image load */
image_ID = load_image (param[1].data.d_string);
image_ID = load_image (param[1].data.d_string, &error);
if (image_ID != -1)
{
@ -242,7 +245,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;
}
@ -256,6 +260,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;
}
@ -306,7 +317,8 @@ put_short (guint16 value,
*/
static gint32
load_image (const gchar *filename)
load_image (const gchar *filename,
GError **error)
{
gint i, j, tile_height, row;
FILE *file = NULL;
@ -324,9 +336,11 @@ load_image (const gchar *filename)
PIX_DEBUG_PRINT ("Opening file: %s\n", filename);
file = g_fopen (filename, "rb");
if (NULL == 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));
return -1;
}
@ -482,7 +496,8 @@ load_image (const gchar *filename)
static gboolean
save_image (const gchar *filename,
gint32 image_ID,
gint32 drawable_ID)
gint32 drawable_ID,
GError **error)
{
gint depth, i, j, row, tile_height, writelen, rectHeight;
gboolean savingColor = TRUE;
@ -505,7 +520,8 @@ save_image (const gchar *filename,
file = g_fopen (filename, "wb");
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));
return FALSE;
}

View File

@ -96,10 +96,12 @@ static void run (const gchar *name,
gint *nreturn_vals,
GimpParam **return_vals);
static gint32 load_image (const gchar *filename);
static gint save_image (const gchar *filename,
static gint32 load_image (const gchar *filename,
GError **error);
static gboolean save_image (const gchar *filename,
gint32 image_ID,
gint32 drawable_ID);
gint32 drawable_ID,
GError **error);
static void set_color_table (gint32, L_SUNFILEHEADER *, const guchar *);
static gint32 create_new_image (const gchar *filename,
@ -257,6 +259,7 @@ run (const gchar *name,
gint32 image_ID;
gint32 drawable_ID;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
l_run_mode = run_mode = param[0].data.d_int32;
@ -269,7 +272,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)
{
@ -341,7 +344,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))
{
/* Store psvals data */
gimp_set_data (SAVE_PROC, &psvals, sizeof (SUNRASSaveVals));
@ -360,12 +364,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;
FILE *ifp;
@ -375,7 +387,8 @@ load_image (const gchar *filename)
ifp = g_fopen (filename, "rb");
if (!ifp)
{
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));
return -1;
}
@ -385,7 +398,8 @@ load_image (const gchar *filename)
read_sun_header (ifp, &sunhdr);
if (sunhdr.l_ras_magic != RAS_MAGIC)
{
g_message (_("Could not open '%s' as SUN-raster-file"),
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Could not open '%s' as SUN-raster-file"),
gimp_filename_to_utf8 (filename));
fclose (ifp);
return (-1);
@ -393,7 +407,9 @@ load_image (const gchar *filename)
if ((sunhdr.l_ras_type < 0) || (sunhdr.l_ras_type > 5))
{
g_message (_("The type of this SUN-rasterfile is not supported"));
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"%s",
_("The type of this SUN-rasterfile is not supported"));
fclose (ifp);
return (-1);
}
@ -507,14 +523,15 @@ load_image (const gchar *filename)
}
static gint
static gboolean
save_image (const gchar *filename,
gint32 image_ID,
gint32 drawable_ID)
gint32 drawable_ID,
GError **error)
{
FILE* ofp;
GimpImageType drawable_type;
gint retval;
gboolean retval;
drawable_type = gimp_drawable_type (drawable_ID);
@ -541,7 +558,8 @@ save_image (const gchar *filename,
ofp = g_fopen (filename, "wb");
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));
return FALSE;
}