gimp r26646 - in trunk: . plug-ins/common
- From: neo svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r26646 - in trunk: . plug-ins/common
- Date: Mon, 18 Aug 2008 19:08:54 +0000 (UTC)
Author: neo
Date: Mon Aug 18 19:08:54 2008
New Revision: 26646
URL: http://svn.gnome.org/viewvc/gimp?rev=26646&view=rev
Log:
2008-08-18 Sven Neumann <sven gimp org>
* plug-ins/common/file-xbm.c
* plug-ins/common/file-xpm.c
* plug-ins/common/file-xwd.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-xbm.c
trunk/plug-ins/common/file-xpm.c
trunk/plug-ins/common/file-xwd.c
Modified: trunk/plug-ins/common/file-xbm.c
==============================================================================
--- trunk/plug-ins/common/file-xbm.c (original)
+++ trunk/plug-ins/common/file-xbm.c Mon Aug 18 19:08:54 2008
@@ -100,23 +100,26 @@
gint *nreturn_vals,
GimpParam **return_vals);
-static gint32 load_image (const gchar *filename);
-static gint save_image (const gchar *filename,
- const gchar *prefix,
- const gchar *comment,
- gboolean save_mask,
- gint32 image_ID,
- gint32 drawable_ID);
-static gboolean save_dialog (gint32 drawable_ID);
+static gint32 load_image (const gchar *filename,
+ GError **error);
+static gint save_image (const gchar *filename,
+ const gchar *prefix,
+ const gchar *comment,
+ gboolean save_mask,
+ gint32 image_ID,
+ gint32 drawable_ID,
+ GError **error);
+static gboolean save_dialog (gint32 drawable_ID);
#if 0
/* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
-static void comment_entry_callback (GtkWidget *widget,
- gpointer data);
+static void comment_entry_callback (GtkWidget *widget,
+ gpointer data);
#endif
-static void prefix_entry_callback (GtkWidget *widget,
- gpointer data);
-static void mask_ext_entry_callback (GtkWidget *widget,
- gpointer data);
+static void prefix_entry_callback (GtkWidget *widget,
+ gpointer data);
+static void mask_ext_entry_callback (GtkWidget *widget,
+ gpointer data);
+
const GimpPlugInInfo PLUG_IN_INFO =
{
@@ -132,6 +135,7 @@
static int verbose = VERBOSE;
#endif
+
static void
query (void)
{
@@ -232,12 +236,13 @@
{
static GimpParam values[2];
GimpRunMode run_mode;
- GimpPDBStatusType status = GIMP_PDB_SUCCESS;
+ GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID;
gint32 drawable_ID;
- GimpParasite *parasite = NULL;
+ GimpParasite *parasite = NULL;
gchar *mask_filename = NULL;
- GimpExportReturn export = GIMP_EXPORT_CANCEL;
+ GError *error = NULL;
+ GimpExportReturn export = GIMP_EXPORT_CANCEL;
INIT_I18N ();
@@ -258,7 +263,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)
{
@@ -441,12 +446,14 @@
xsvals.prefix,
xsvals.comment,
FALSE,
- image_ID, drawable_ID)
- && (!xsvals.write_mask || save_image (mask_filename,
- mask_prefix,
- xsvals.comment,
- TRUE,
- image_ID, drawable_ID)))
+ image_ID, drawable_ID,
+ &error)
+ && (! xsvals.write_mask || save_image (mask_filename,
+ mask_prefix,
+ xsvals.comment,
+ TRUE,
+ image_ID, drawable_ID,
+ &error)))
{
/* Store xsvals data */
gimp_set_data (SAVE_PROC, &xsvals, sizeof (xsvals));
@@ -468,6 +475,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;
}
@@ -691,13 +705,15 @@
static gint
-load_image (const gchar *filename)
+load_image (const gchar *filename,
+ GError **error)
{
- FILE *fp;
- gint32 image_ID, layer_ID;
-
GimpPixelRgn pixel_rgn;
GimpDrawable *drawable;
+
+ FILE *fp;
+ gint32 image_ID;
+ gint32 layer_ID;
guchar *data;
gint intbits;
gint width = 0;
@@ -715,10 +731,11 @@
};
fp = g_fopen (filename, "rb");
- if (!fp)
+ if (! fp)
{
- 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;
}
@@ -941,12 +958,13 @@
}
static gboolean
-save_image (const gchar *filename,
- const gchar *prefix,
- const gchar *comment,
- gboolean save_mask,
- gint32 image_ID,
- gint32 drawable_ID)
+save_image (const gchar *filename,
+ const gchar *prefix,
+ const gchar *comment,
+ gboolean save_mask,
+ gint32 image_ID,
+ gint32 drawable_ID,
+ GError **error)
{
GimpDrawable *drawable;
GimpPixelRgn pixel_rgn;
@@ -986,7 +1004,7 @@
has_alpha = gimp_drawable_has_alpha (drawable_ID);
- if (!has_alpha && save_mask)
+ if (! has_alpha && save_mask)
{
g_message (_("You cannot save a cursor mask for an image\n"
"which has no alpha channel."));
@@ -1011,10 +1029,11 @@
/* Now actually save the data. */
fp = g_fopen (filename, "w");
- if (!fp)
+ if (! fp)
{
- 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;
}
@@ -1147,6 +1166,7 @@
/* Write the trailer. */
fprintf (fp, " };\n");
fclose (fp);
+
return TRUE;
}
Modified: trunk/plug-ins/common/file-xpm.c
==============================================================================
--- trunk/plug-ins/common/file-xpm.c (original)
+++ trunk/plug-ins/common/file-xpm.c Mon Aug 18 19:08:54 2008
@@ -105,15 +105,16 @@
gint *nreturn_vals,
GimpParam **return_vals);
-static gint32 load_image (const gchar *filename);
+static gint32 load_image (const gchar *filename,
+ GError **error);
static guchar * parse_colors (XpmImage *xpm_image);
static void parse_image (gint32 image_ID,
XpmImage *xpm_image,
guchar *cmap);
static gboolean save_image (const gchar *filename,
gint32 image_ID,
- gint32 drawable_ID);
-
+ gint32 drawable_ID,
+ GError **error);
static gboolean save_dialog (void);
@@ -212,12 +213,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;
@@ -231,7 +233,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)
{
@@ -311,8 +313,7 @@
if (status == GIMP_PDB_SUCCESS)
{
if (save_image (param[3].data.d_string,
- image_ID,
- drawable_ID))
+ image_ID, drawable_ID, &error))
{
gimp_set_data ("file_xpm_save", &xpmvals, sizeof (XpmSaveVals));
}
@@ -330,11 +331,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)
{
XpmImage xpm_image;
guchar *cmap;
@@ -350,12 +359,14 @@
break;
case XpmOpenFailed:
- g_message (_("Error opening file '%s'"),
- gimp_filename_to_utf8 (filename));
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ _("Error opening file '%s'"),
+ gimp_filename_to_utf8 (filename));
return -1;
case XpmFileInvalid:
- g_message (_("XPM file invalid"));
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ "%s", _("XPM file invalid"));
return -1;
default:
@@ -578,9 +589,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)
{
GimpDrawable *drawable;
GimpPixelRgn pixel_rgn;
@@ -604,7 +616,7 @@
gint i, j, k;
gint threshold = xpmvals.threshold;
- gboolean rc = FALSE;
+ gboolean success = FALSE;
/* get some basic stats about the image */
alpha = gimp_drawable_has_alpha (drawable_ID);
@@ -690,6 +702,7 @@
gimp_progress_update ((gdouble) (i+j) / (gdouble) height);
}
}
+
g_free (buffer);
if (indexed)
@@ -747,8 +760,26 @@
image->data = ibuff;
/* do the save */
- rc = (XpmWriteFileFromXpmImage ((char *) filename,
- image, NULL) == XpmSuccess);
+ switch (XpmWriteFileFromXpmImage ((char *) filename, image, NULL))
+ {
+ case XpmSuccess:
+ success = TRUE;
+ break;
+
+ case XpmOpenFailed:
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ _("Error opening file '%s'"),
+ gimp_filename_to_utf8 (filename));
+ break;
+
+ case XpmFileInvalid:
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ "%s", _("XPM file invalid"));
+ break;
+
+ default:
+ break;
+ }
/* clean up resources */
gimp_drawable_detach (drawable);
@@ -758,7 +789,7 @@
if (hash)
g_hash_table_destroy (hash);
- return rc;
+ return success;
}
static gboolean
Modified: trunk/plug-ins/common/file-xwd.c
==============================================================================
--- trunk/plug-ins/common/file-xwd.c (original)
+++ trunk/plug-ins/common/file-xwd.c Mon Aug 18 19:08:54 2008
@@ -144,10 +144,12 @@
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 gint32 create_new_image (const gchar *filename,
guint width,
guint height,
@@ -311,12 +313,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;
@@ -330,7 +333,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)
{
@@ -388,7 +391,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;
}
@@ -402,11 +406,19 @@
status = GIMP_PDB_CANCEL;
}
+ 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)
{
FILE *ifp;
gint depth, bpp;
@@ -417,16 +429,18 @@
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;
}
read_xwd_header (ifp, &xwdhdr);
if (xwdhdr.l_file_version != 7)
{
- g_message (_("Could not read XWD header from '%s'"),
- gimp_filename_to_utf8 (filename));
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ _("Could not read XWD header from '%s'"),
+ gimp_filename_to_utf8 (filename));
fclose (ifp);
return -1;
}
@@ -552,19 +566,20 @@
g_free (xwdcolmap);
if (image_ID == -1)
- g_message (_("XWD-file %s has format %d, depth %d and bits per pixel %d. "
- "Currently this is not supported."),
- gimp_filename_to_utf8 (filename),
- (gint) xwdhdr.l_pixmap_format, depth, bpp);
+ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+ _("XWD-file %s has format %d, depth %d and bits per pixel %d. "
+ "Currently this is not supported."),
+ gimp_filename_to_utf8 (filename),
+ (gint) xwdhdr.l_pixmap_format, depth, bpp);
return image_ID;
}
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;
@@ -593,10 +608,11 @@
/* Open the output file. */
ofp = g_fopen (filename, "wb");
- if (!ofp)
+ 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]