gimp r26638 - in trunk: . plug-ins/common



Author: neo
Date: Mon Aug 18 06:31:03 2008
New Revision: 26638
URL: http://svn.gnome.org/viewvc/gimp?rev=26638&view=rev

Log:
2008-08-18  Sven Neumann  <sven gimp org>

	* plug-ins/common/file-mng.c
	* plug-ins/common/file-pcx.c: for the most common errors,
	pass the error message with the return values instead of calling
	gimp_message().

	* plug-ins/common/file-gif-save.c
	* plug-ins/common/file-pdf.c
	* plug-ins/common/file-png.c: minor cleanup.



Modified:
   trunk/ChangeLog
   trunk/plug-ins/common/file-gif-save.c
   trunk/plug-ins/common/file-mng.c
   trunk/plug-ins/common/file-pcx.c
   trunk/plug-ins/common/file-pdf.c
   trunk/plug-ins/common/file-png.c

Modified: trunk/plug-ins/common/file-gif-save.c
==============================================================================
--- trunk/plug-ins/common/file-gif-save.c	(original)
+++ trunk/plug-ins/common/file-gif-save.c	Mon Aug 18 06:31:03 2008
@@ -288,13 +288,13 @@
 
       if (export == GIMP_EXPORT_EXPORT)
         gimp_image_delete (image_ID);
+    }
 
-      if (status == GIMP_PDB_EXECUTION_ERROR && error)
-        {
-          *nreturn_vals = 2;
-          values[1].type          = GIMP_PDB_STRING;
-          values[1].data.d_string = error->message;
-        }
+  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;

Modified: trunk/plug-ins/common/file-mng.c
==============================================================================
--- trunk/plug-ins/common/file-mng.c	(original)
+++ trunk/plug-ins/common/file-mng.c	Mon Aug 18 06:31:03 2008
@@ -172,43 +172,45 @@
  * Function prototypes
  */
 
-static mng_ptr  myalloc       (mng_size_t  size);
-static void     myfree        (mng_ptr     ptr,
-                               mng_size_t  size);
-static mng_bool myopenstream  (mng_handle  handle);
-static mng_bool myclosestream (mng_handle  handle);
-static mng_bool mywritedata   (mng_handle  handle,
-                               mng_ptr     buf,
-                               mng_uint32  size,
-                               mng_uint32 *written_size);
-
-
-static gint32   parse_chunks_type_from_layer_name   (const gchar *str);
-static gint32   parse_disposal_type_from_layer_name (const gchar *str);
-static gint32   parse_ms_tag_from_layer_name        (const gchar *str);
-static gint     find_unused_ia_colour               (guchar      *pixels,
-                                                     gint         numpixels,
-                                                     gint        *colors);
-static gboolean ia_has_transparent_pixels           (guchar      *pixels,
-                                                     gint         numpixels);
-
-
-static gboolean respin_cmap     (png_structp       png_ptr,
-                                 png_infop         png_info_ptr,
-                                 guchar           *remap,
-                                 gint32            image_id,
-                                 GimpDrawable     *drawable);
-static gboolean mng_save_image  (const gchar      *filename,
-                                 gint32            image_id,
-                                 gint32            drawable_id,
-                                 gint32            original_image_id);
-static gint     mng_save_dialog (gint32            image_id);
-static void     query           (void);
-static void     run             (const gchar      *name,
-                                 gint              nparams,
-                                 const GimpParam  *param,
-                                 gint             *nreturn_vals,
-                                 GimpParam       **return_vals);
+static mng_ptr   myalloc       (mng_size_t  size);
+static void      myfree        (mng_ptr     ptr,
+                                mng_size_t  size);
+static mng_bool  myopenstream  (mng_handle  handle);
+static mng_bool  myclosestream (mng_handle  handle);
+static mng_bool  mywritedata   (mng_handle  handle,
+                                mng_ptr     buf,
+                                mng_uint32  size,
+                                mng_uint32 *written_size);
+
+
+static gint32    parse_chunks_type_from_layer_name   (const gchar *str);
+static gint32    parse_disposal_type_from_layer_name (const gchar *str);
+static gint32    parse_ms_tag_from_layer_name        (const gchar *str);
+static gint      find_unused_ia_colour               (guchar      *pixels,
+                                                      gint         numpixels,
+                                                      gint        *colors);
+static gboolean  ia_has_transparent_pixels           (guchar      *pixels,
+                                                      gint         numpixels);
+
+static gboolean  respin_cmap     (png_structp       png_ptr,
+                                  png_infop         png_info_ptr,
+                                  guchar           *remap,
+                                  gint32            image_id,
+                                  GimpDrawable     *drawable);
+
+static gboolean  mng_save_image  (const gchar      *filename,
+                                  gint32            image_id,
+                                  gint32            drawable_id,
+                                  gint32            original_image_id,
+                                  GError          **error);
+static gboolean  mng_save_dialog (gint32            image_id);
+
+static void      query           (void);
+static void      run             (const gchar      *name,
+                                  gint              nparams,
+                                  const GimpParam  *param,
+                                  gint             *nreturn_vals,
+                                  GimpParam       **return_vals);
 
 
 /*
@@ -505,10 +507,11 @@
 
 
 static gboolean
-mng_save_image (const gchar *filename,
-                gint32       image_id,
-                gint32       drawable_id,
-                gint32       original_image_id)
+mng_save_image (const gchar  *filename,
+                gint32        image_id,
+                gint32        drawable_id,
+                gint32        original_image_id,
+                GError      **error)
 {
   gboolean        ret = FALSE;
   gint            rows, cols;
@@ -568,8 +571,9 @@
 
   if (NULL == userdata->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));
       goto err;
     }
 
@@ -655,7 +659,7 @@
                              MNG_BACKGROUNDCOLOR_MANDATORY,
                              0, MNG_BACKGROUNDIMAGE_NOTILE) != MNG_NOERROR)
         {
-          g_warning("Unable to mng_putchunk_back() in mng_save_image()");
+          g_warning ("Unable to mng_putchunk_back() in mng_save_image()");
           goto err3;
         }
 
@@ -663,7 +667,7 @@
                              gimp_rgb_luminance_uchar (&bgcolor),
                              red, green, blue) != MNG_NOERROR)
         {
-          g_warning("Unable to mng_putchunk_bkgd() in mng_save_image()");
+          g_warning ("Unable to mng_putchunk_bkgd() in mng_save_image()");
           goto err3;
         }
     }
@@ -691,7 +695,7 @@
                              (mng_uint32) (xres * 39.37),
                              (mng_uint32) (yres * 39.37), 1) != MNG_NOERROR)
         {
-          g_warning("Unable to mng_putchunk_phyg() in mng_save_image()");
+          g_warning ("Unable to mng_putchunk_phyg() in mng_save_image()");
           goto err3;
         }
 
@@ -699,7 +703,7 @@
                              (mng_uint32) (xres * 39.37),
                              (mng_uint32) (yres * 39.37), 1) != MNG_NOERROR)
         {
-          g_warning("Unable to mng_putchunk_phys() in mng_save_image()");
+          g_warning ("Unable to mng_putchunk_phys() in mng_save_image()");
           goto err3;
         }
     }
@@ -901,9 +905,10 @@
 
       if ((outfile = g_fopen (temp_file_name, "wb")) == NULL)
         {
-          g_message (_("Could not open '%s' for writing: %s"),
-                     gimp_filename_to_utf8 (temp_file_name),
-                     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 (temp_file_name),
+                       g_strerror (errno));
           g_unlink (temp_file_name);
           goto err3;
         }
@@ -1064,9 +1069,10 @@
       infile = g_fopen (temp_file_name, "rb");
       if (NULL == infile)
         {
-          g_message (_("Could not open '%s' for reading: %s"),
-                     gimp_filename_to_utf8 (temp_file_name),
-                     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 (temp_file_name),
+                       g_strerror (errno));
           g_unlink (temp_file_name);
           goto err3;
         }
@@ -1226,7 +1232,7 @@
 
 /* The interactive dialog. */
 
-static gint
+static gboolean
 mng_save_dialog (gint32 image_id)
 {
   GtkWidget *dialog;
@@ -1245,7 +1251,6 @@
   gint       num_layers;
   gboolean   run;
 
-
   dialog = gimp_dialog_new (_("Save as MNG"), PLUG_IN_BINARY,
                             NULL, 0,
                             gimp_standard_help_func, SAVE_PROC,
@@ -1540,7 +1545,7 @@
      gint             *nreturn_vals,
      GimpParam       **return_vals)
 {
-  static GimpParam values[1];
+  static GimpParam values[2];
 
   INIT_I18N ();
 
@@ -1551,14 +1556,11 @@
 
   if (strcmp (name, SAVE_PROC) == 0)
     {
-      GimpRunMode      run_mode;
-      gint32           image_id, original_image_id;
-      gint32           drawable_id;
-      GimpExportReturn export = GIMP_EXPORT_IGNORE;
-
-      run_mode = param[0].data.d_int32;
-      image_id = original_image_id = param[1].data.d_int32;
-      drawable_id = param[2].data.d_int32;
+      GimpRunMode      run_mode          = param[0].data.d_int32;
+      gint32           image_id          = param[1].data.d_int32;
+      gint32           original_image_id = image_id;
+      gint32           drawable_id       = param[2].data.d_int32;
+      GimpExportReturn export            = GIMP_EXPORT_IGNORE;
 
       if ((run_mode == GIMP_RUN_INTERACTIVE)
           || (run_mode == GIMP_RUN_WITH_LAST_VALS))
@@ -1575,9 +1577,10 @@
         }
 
       if (export == GIMP_EXPORT_CANCEL)
-        values[0].data.d_status = GIMP_PDB_CANCEL;
-      else if ((export == GIMP_EXPORT_IGNORE)
-               || (export == GIMP_EXPORT_EXPORT))
+        {
+          values[0].data.d_status = GIMP_PDB_CANCEL;
+        }
+      else if (export == GIMP_EXPORT_IGNORE || export == GIMP_EXPORT_EXPORT)
         {
           if (run_mode == GIMP_RUN_INTERACTIVE)
             {
@@ -1656,12 +1659,25 @@
 
           if (values[0].data.d_status == GIMP_PDB_SUCCESS)
             {
+              GError *error = NULL;
+
               if (mng_save_image (param[3].data.d_string,
                                   image_id, drawable_id,
-                                  original_image_id))
-                gimp_set_data (SAVE_PROC, &mng_data, sizeof (mng_data));
+                                  original_image_id, &error))
+                {
+                  gimp_set_data (SAVE_PROC, &mng_data, sizeof (mng_data));
+                }
               else
-                values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
+                {
+                  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
+
+                  if (error)
+                    {
+                      *nreturn_vals = 2;
+                      values[1].type          = GIMP_PDB_STRING;
+                      values[1].data.d_string = error->message;
+                    }
+                }
             }
 
           if (export == GIMP_EXPORT_EXPORT)
@@ -1670,10 +1686,13 @@
 
     }
   else
-    values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
+    {
+      values[0].data.d_status = GIMP_PDB_CALLING_ERROR;
+    }
 }
 
 
+
 /* Only query and run are implemented by this plug-in. */
 
 const GimpPlugInInfo PLUG_IN_INFO =

Modified: trunk/plug-ins/common/file-pcx.c
==============================================================================
--- trunk/plug-ins/common/file-pcx.c	(original)
+++ trunk/plug-ins/common/file-pcx.c	Mon Aug 18 06:31:03 2008
@@ -46,7 +46,9 @@
                           gint             *nreturn_vals,
                           GimpParam       **return_vals);
 
-static gint32 load_image (const gchar      *filename);
+static gint32 load_image (const gchar      *filename,
+                          GError          **error);
+
 static void   load_1     (FILE             *fp,
                           gint              width,
                           gint              height,
@@ -73,7 +75,9 @@
 
 static gint   save_image (const gchar      *filename,
                           gint32            image,
-                          gint32            layer);
+                          gint32            layer,
+                          GError          **error);
+
 static void   save_8     (FILE             *fp,
                           gint              width,
                           gint              height,
@@ -162,12 +166,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;
 
@@ -181,7 +186,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)
         {
@@ -205,6 +210,7 @@
         case GIMP_RUN_INTERACTIVE:
         case GIMP_RUN_WITH_LAST_VALS:
           gimp_ui_init (PLUG_IN_BINARY, FALSE);
+
           export = gimp_export_image (&image_ID, &drawable_ID, "PCX",
                                       (GIMP_EXPORT_CAN_HANDLE_RGB |
                                        GIMP_EXPORT_CAN_HANDLE_GRAY |
@@ -238,7 +244,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;
             }
@@ -252,6 +259,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;
 }
 
@@ -327,7 +341,8 @@
 }
 
 static gint32
-load_image (const gchar *filename)
+load_image (const gchar  *filename,
+            GError      **error)
 {
   FILE         *fd;
   GimpDrawable *drawable;
@@ -339,10 +354,12 @@
   guint8        header_buf[128];
 
   fd = g_fopen (filename, "rb");
-  if (!fd)
+
+  if (! fd)
     {
-      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;
     }
 
@@ -351,8 +368,9 @@
 
   if (fread (header_buf, 128, 1, fd) == 0)
     {
-      g_message (_("Could not read header from '%s'"),
-                 gimp_filename_to_utf8 (filename));
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   _("Could not read header from '%s'"),
+                   gimp_filename_to_utf8 (filename));
       return -1;
     }
 
@@ -360,8 +378,9 @@
 
   if (pcx_header.manufacturer != 10)
     {
-      g_message (_("'%s' is not a PCX file"),
-                 gimp_filename_to_utf8 (filename));
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   _("'%s' is not a PCX file"),
+                   gimp_filename_to_utf8 (filename));
       return -1;
     }
 
@@ -582,9 +601,10 @@
 }
 
 static gint
-save_image (const gchar *filename,
-            gint32       image,
-            gint32       layer)
+save_image (const gchar  *filename,
+            gint32        image,
+            gint32        layer,
+            GError      **error)
 {
   FILE          *fp;
   GimpPixelRgn   pixel_rgn;
@@ -642,8 +662,9 @@
 
   if ((fp = g_fopen (filename, "wb")) == NULL)
     {
-      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;
     }
 
@@ -727,10 +748,12 @@
 
   if (fclose (fp) != 0)
     {
-      g_message (_("Writing to file '%s' failed: %s"),
-                 gimp_filename_to_utf8 (filename), g_strerror (errno));
+      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
+                   _("Writing to file '%s' failed: %s"),
+                   gimp_filename_to_utf8 (filename), g_strerror (errno));
       return FALSE;
     }
+
   return TRUE;
 }
 

Modified: trunk/plug-ins/common/file-pdf.c
==============================================================================
--- trunk/plug-ins/common/file-pdf.c	(original)
+++ trunk/plug-ins/common/file-pdf.c	Mon Aug 18 06:31:03 2008
@@ -502,7 +502,7 @@
       status = GIMP_PDB_CALLING_ERROR;
     }
 
-  if (status == GIMP_PDB_EXECUTION_ERROR && error)
+  if (status != GIMP_PDB_SUCCESS && error)
     {
       *nreturn_vals = 2;
       values[1].type          = GIMP_PDB_STRING;

Modified: trunk/plug-ins/common/file-png.c
==============================================================================
--- trunk/plug-ins/common/file-png.c	(original)
+++ trunk/plug-ins/common/file-png.c	Mon Aug 18 06:31:03 2008
@@ -414,13 +414,6 @@
       else
         {
           status = GIMP_PDB_EXECUTION_ERROR;
-
-          if (error)
-            {
-              *nreturn_vals = 2;
-              values[1].type          = GIMP_PDB_STRING;
-              values[1].data.d_string = error->message;
-            }
         }
     }
   else if (strcmp (name, SAVE_PROC)  == 0 ||
@@ -544,13 +537,6 @@
           else
             {
               status = GIMP_PDB_EXECUTION_ERROR;
-
-              if (error)
-                {
-                  *nreturn_vals = 2;
-                  values[1].type          = GIMP_PDB_STRING;
-                  values[1].data.d_string = error->message;
-                }
             }
         }
 
@@ -597,11 +583,20 @@
           save_defaults ();
         }
       else
-        status = GIMP_PDB_CALLING_ERROR;
+        {
+          status = GIMP_PDB_CALLING_ERROR;
+        }
     }
   else
     {
-      status = GIMP_PDB_EXECUTION_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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]