gimp r26650 - in trunk: . plug-ins/common
- From: neo svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r26650 - in trunk: . plug-ins/common
- Date: Mon, 18 Aug 2008 19:35:55 +0000 (UTC)
Author: neo
Date: Mon Aug 18 19:35:55 2008
New Revision: 26650
URL: http://svn.gnome.org/viewvc/gimp?rev=26650&view=rev
Log:
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().
Modified:
trunk/ChangeLog
trunk/plug-ins/common/file-gbr.c
trunk/plug-ins/common/file-gih.c
trunk/plug-ins/common/file-pat.c
trunk/plug-ins/common/file-pix.c
trunk/plug-ins/common/file-sunras.c
Modified: trunk/plug-ins/common/file-gbr.c
==============================================================================
--- trunk/plug-ins/common/file-gbr.c (original)
+++ trunk/plug-ins/common/file-gbr.c Mon Aug 18 19:35:55 2008
@@ -88,10 +88,12 @@
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,
@@ -189,12 +191,13 @@
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;
@@ -208,7 +211,7 @@
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 @@
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 @@
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,8 +357,9 @@
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;
}
@@ -408,8 +421,9 @@
if ((read (fd, temp, bn_size)) < bn_size)
{
- g_message (_("Error in GIMP brush file '%s'"),
- gimp_filename_to_utf8 (filename));
+ 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);
return -1;
@@ -578,9 +592,10 @@
}
static gboolean
-save_image (const gchar *filename,
- gint32 image_ID,
- gint32 drawable_ID)
+save_image (const gchar *filename,
+ gint32 image_ID,
+ gint32 drawable_ID,
+ GError **error)
{
gint fd;
BrushHeader bh;
@@ -613,8 +628,9 @@
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;
}
Modified: trunk/plug-ins/common/file-gih.c
==============================================================================
--- trunk/plug-ins/common/file-gih.c (original)
+++ trunk/plug-ins/common/file-gih.c Mon Aug 18 19:35:55 2008
@@ -99,13 +99,13 @@
static gint num_useable_layers;
-static gchar *selection_modes[] = {"incremental",
- "angular",
- "random",
- "velocity",
- "pressure",
- "xtilt",
- "ytilt"};
+static const gchar *selection_modes[] = { "incremental",
+ "angular",
+ "random",
+ "velocity",
+ "pressure",
+ "xtilt",
+ "ytilt" };
static GimpPixPipeParams gihparams;
@@ -139,18 +139,20 @@
gint *nreturn_vals,
GimpParam **return_vals);
-static gint32 gih_load_image (const gchar *filename);
-static gboolean gih_load_one_brush (gint fd,
- gint32 image_ID);
-
-static gboolean gih_save_dialog (gint32 image_ID);
-static gboolean gih_save_one_brush (gint fd,
- GimpPixelRgn *pixel_rgn,
- gchar *name);
-static gboolean gih_save_image (const gchar *filename,
- gint32 image_ID,
- gint32 orig_image_ID,
- gint32 drawable_ID);
+static gint32 gih_load_image (const gchar *filename,
+ GError **error);
+static gboolean gih_load_one_brush (gint fd,
+ gint32 image_ID);
+
+static gboolean gih_save_dialog (gint32 image_ID);
+static gboolean gih_save_one_brush (gint fd,
+ GimpPixelRgn *pixel_rgn,
+ gchar *name);
+static gboolean gih_save_image (const gchar *filename,
+ gint32 image_ID,
+ gint32 orig_image_ID,
+ gint32 drawable_ID,
+ GError **error);
const GimpPlugInInfo PLUG_IN_INFO =
@@ -258,6 +260,7 @@
gchar *layer_name;
gint i;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
+ GError *error = NULL;
run_mode = param[0].data.d_int32;
@@ -271,7 +274,7 @@
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 @@
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 @@
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 @@
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;
}
@@ -489,7 +500,7 @@
name = g_new (gchar, bn_size);
if ((read (fd, name, bn_size)) < bn_size)
{
- g_message (_("Error in GIMP brush pipe file."));
+ g_message (_("Error in GIMP brush pipe file."));
g_free (name);
return FALSE;
}
@@ -630,7 +641,8 @@
}
static gint32
-gih_load_image (const gchar *filename)
+gih_load_image (const gchar *filename,
+ GError **error)
{
gint fd;
gint i;
@@ -646,8 +658,9 @@
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;
}
@@ -700,7 +713,9 @@
{
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);
@@ -1228,21 +1243,22 @@
}
static gboolean
-gih_save_image (const gchar *filename,
- gint32 image_ID,
- gint32 orig_image_ID,
- gint32 drawable_ID)
+gih_save_image (const gchar *filename,
+ gint32 image_ID,
+ gint32 orig_image_ID,
+ gint32 drawable_ID,
+ GError **error)
{
GimpDrawable *drawable;
GimpPixelRgn pixel_rgn;
GimpParasite *pipe_parasite;
- gchar *header;
- gchar *parstring;
+ gchar *header;
+ gchar *parstring;
gint32 *layer_ID;
- gint fd;
- gint nlayers, layer, row, col;
- gint imagew, imageh, offsetx, offsety;
- gint k, x, y, thisx, thisy, xnext, ynext, thisw, thish;
+ gint fd;
+ gint nlayers, layer, row, col;
+ gint imagew, imageh, offsetx, offsety;
+ gint k, x, y, thisx, thisy, xnext, ynext, thisw, thish;
if (gihparams.ncells < 1)
return FALSE;
@@ -1255,8 +1271,9 @@
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;
}
Modified: trunk/plug-ins/common/file-pat.c
==============================================================================
--- trunk/plug-ins/common/file-pat.c (original)
+++ trunk/plug-ins/common/file-pat.c Mon Aug 18 19:35:55 2008
@@ -63,10 +63,12 @@
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);
@@ -159,12 +161,13 @@
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;
@@ -178,7 +181,7 @@
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 @@
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 @@
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,8 +326,9 @@
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;
}
@@ -429,9 +442,10 @@
}
static gboolean
-save_image (const gchar *filename,
- gint32 image_ID,
- gint32 drawable_ID)
+save_image (const gchar *filename,
+ gint32 image_ID,
+ gint32 drawable_ID,
+ GError **error)
{
gint fd;
PatternHeader ph;
@@ -444,8 +458,9 @@
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;
}
Modified: trunk/plug-ins/common/file-pix.c
==============================================================================
--- trunk/plug-ins/common/file-pix.c (original)
+++ trunk/plug-ins/common/file-pix.c Mon Aug 18 19:35:55 2008
@@ -81,10 +81,12 @@
/* 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 @@
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 @@
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 @@
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 @@
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 @@
*/
static gint32
-load_image (const gchar *filename)
+load_image (const gchar *filename,
+ GError **error)
{
gint i, j, tile_height, row;
FILE *file = NULL;
@@ -324,10 +336,12 @@
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"),
- 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;
}
@@ -480,9 +494,10 @@
*/
static gboolean
-save_image (const gchar *filename,
- gint32 image_ID,
- gint32 drawable_ID)
+save_image (const gchar *filename,
+ gint32 image_ID,
+ gint32 drawable_ID,
+ GError **error)
{
gint depth, i, j, row, tile_height, writelen, rectHeight;
gboolean savingColor = TRUE;
@@ -503,10 +518,11 @@
/* Open the output file. */
file = g_fopen (filename, "wb");
- if (!file)
+ if (! file)
{
- 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;
}
Modified: trunk/plug-ins/common/file-sunras.c
==============================================================================
--- trunk/plug-ins/common/file-sunras.c (original)
+++ trunk/plug-ins/common/file-sunras.c Mon Aug 18 19:35:55 2008
@@ -96,10 +96,12 @@
gint *nreturn_vals,
GimpParam **return_vals);
-static gint32 load_image (const gchar *filename);
-static gint save_image (const gchar *filename,
- gint32 image_ID,
- gint32 drawable_ID);
+static gint32 load_image (const gchar *filename,
+ GError **error);
+static gboolean save_image (const gchar *filename,
+ gint32 image_ID,
+ gint32 drawable_ID,
+ GError **error);
static void set_color_table (gint32, L_SUNFILEHEADER *, const guchar *);
static gint32 create_new_image (const gchar *filename,
@@ -251,12 +253,13 @@
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;
l_run_mode = run_mode = param[0].data.d_int32;
@@ -269,7 +272,7 @@
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 @@
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 @@
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,8 +387,9 @@
ifp = g_fopen (filename, "rb");
if (!ifp)
{
- 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;
}
@@ -385,15 +398,18 @@
read_sun_header (ifp, &sunhdr);
if (sunhdr.l_ras_magic != RAS_MAGIC)
{
- g_message (_("Could not open '%s' as SUN-raster-file"),
- gimp_filename_to_utf8 (filename));
+ 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);
}
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 @@
}
-static gint
-save_image (const gchar *filename,
- gint32 image_ID,
- gint32 drawable_ID)
+static gboolean
+save_image (const gchar *filename,
+ gint32 image_ID,
+ gint32 drawable_ID,
+ GError **error)
{
- FILE* ofp;
+ FILE* ofp;
GimpImageType drawable_type;
- gint retval;
+ gboolean retval;
drawable_type = gimp_drawable_type (drawable_ID);
@@ -541,8 +558,9 @@
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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]