gimp r26676 - in trunk: . plug-ins/file-fits plug-ins/file-fli



Author: neo
Date: Wed Aug 20 13:44:17 2008
New Revision: 26676
URL: http://svn.gnome.org/viewvc/gimp?rev=26676&view=rev

Log:
2008-08-20  Sven Neumann  <sven gimp org>
 
	* plug-ins/file-fits/fits.c
	* plug-ins/file-fli/fli-gimp.c: pass error messages with the
	return values instead of calling g_message()



Modified:
   trunk/ChangeLog
   trunk/plug-ins/file-fits/fits.c
   trunk/plug-ins/file-fli/fli-gimp.c

Modified: trunk/plug-ins/file-fits/fits.c
==============================================================================
--- trunk/plug-ins/file-fits/fits.c	(original)
+++ trunk/plug-ins/file-fits/fits.c	Wed Aug 20 13:44:17 2008
@@ -73,10 +73,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 gint   save_image (const gchar      *filename,
+                          gint32            image_ID,
+                          gint32            drawable_ID,
+                          GError          **error);
 
 static FITS_HDU_LIST *create_fits_header (FITS_FILE *ofp,
 					  guint width,
@@ -207,6 +209,7 @@
   gint32             image_ID;
   gint32             drawable_ID;
   GimpExportReturn   export = GIMP_EXPORT_CANCEL;
+  GError            *error  = NULL;
 
   l_run_mode = run_mode = (GimpRunMode)param[0].data.d_int32;
 
@@ -246,7 +249,7 @@
       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);
 
 	  /* Write out error messages of FITS-Library */
 	  show_fits_errors ();
@@ -312,7 +315,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;
 	}
 
@@ -324,12 +328,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, *image_list, *nl;
   guint  picnum;
@@ -342,23 +354,26 @@
   fp = g_fopen (filename, "rb");
   if (!fp)
     {
-      g_message (_("Could not open '%s' for reading: %s"),
-                 gimp_filename_to_utf8 (filename), g_strerror (errno));
-      return (-1);
+      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 (fp);
 
   ifp = fits_open (filename, "r");
   if (ifp == NULL)
     {
-      g_message (_("Error during open of FITS file"));
-      return (-1);
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   "%s", _("Error during open of FITS file"));
+      return -1;
     }
   if (ifp->n_pic <= 0)
     {
-      g_message (_("FITS file keeps no displayable images"));
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   "%s", _("FITS file keeps no displayable images"));
       fits_close (ifp);
-      return (-1);
+      return -1;
     }
 
   image_list = g_new (gint32, 10);
@@ -421,9 +436,10 @@
 
 
 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)
 {
   FITS_FILE* ofp;
   GimpImageType drawable_type;
@@ -434,7 +450,9 @@
   /*  Make sure we're not saving an image with an alpha channel  */
   if (gimp_drawable_has_alpha (drawable_ID))
     {
-      g_message (_("FITS save cannot handle images with alpha channels"));
+      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
+                   "%s",
+                   _("FITS save cannot handle images with alpha channels"));
       return FALSE;
     }
 
@@ -454,8 +472,9 @@
   ofp = fits_open (filename, "w");
   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);
     }
 

Modified: trunk/plug-ins/file-fli/fli-gimp.c
==============================================================================
--- trunk/plug-ins/file-fli/fli-gimp.c	(original)
+++ trunk/plug-ins/file-fli/fli-gimp.c	Wed Aug 20 13:44:17 2008
@@ -79,21 +79,24 @@
                               GimpParam       **return_vals);
 
 /* return the image-ID of the new image, or -1 in case of an error */
-static gint32    load_image  (const  gchar *filename,
-                              gint32        from_frame,
-                              gint32        to_frame);
-static gboolean  load_dialog (const gchar  *name);
-
-static gboolean  save_image  (const gchar  *filename,
-                              gint32        image_id,
-                              gint32        from_frame,
-                              gint32        to_frame);
-static gboolean  save_dialog (gint32        image_id);
-
-static gboolean  get_info    (const gchar  *filename,
-                              gint32       *width,
-                              gint32       *height,
-                              gint32       *frames);
+static gint32    load_image  (const  gchar  *filename,
+                              gint32         from_frame,
+                              gint32         to_frame,
+                              GError       **error);
+static gboolean  load_dialog (const gchar   *filename);
+
+static gboolean  save_image  (const gchar   *filename,
+                              gint32         image_id,
+                              gint32         from_frame,
+                              gint32         to_frame,
+                              GError       **error);
+static gboolean  save_dialog (gint32         image_id);
+
+static gboolean  get_info    (const gchar   *filename,
+                              gint32        *width,
+                              gint32        *height,
+                              gint32        *frames,
+                              GError       **error);
 
 /*
  * GIMP interface
@@ -218,13 +221,14 @@
      gint             *nreturn_vals,
      GimpParam       **return_vals)
 {
-  GimpPDBStatusType status = GIMP_PDB_SUCCESS;
-  GimpRunMode       run_mode;
-  gint32            pc;
-  gint32            image_ID;
-  gint32            drawable_ID;
-  gint32            orig_image_ID;
-  GimpExportReturn  export = GIMP_EXPORT_CANCEL;
+  GimpPDBStatusType  status = GIMP_PDB_SUCCESS;
+  GimpRunMode        run_mode;
+  gint32             pc;
+  gint32             image_ID;
+  gint32             drawable_ID;
+  gint32             orig_image_ID;
+  GimpExportReturn   export = GIMP_EXPORT_CANCEL;
+  GError            *error  = NULL;
 
   run_mode = param[0].data.d_int32;
 
@@ -274,7 +278,7 @@
                         -1 : param[4].data.d_int32);
 
           image_ID = load_image (param[1].data.d_string,
-				 from_frame, to_frame);
+                                 from_frame, to_frame, &error);
 
 	  if (image_ID != -1)
 	    {
@@ -283,14 +287,16 @@
 	      values[1].data.d_image = image_ID;
 	    }
 	  else
-	    status = GIMP_PDB_EXECUTION_ERROR;
+            {
+              status = GIMP_PDB_EXECUTION_ERROR;
+            }
 	  break;
 
 	case GIMP_RUN_INTERACTIVE:
 	  if (load_dialog (param[1].data.d_string))
 	    {
 	      image_ID = load_image (param[1].data.d_string,
-				     from_frame, to_frame);
+                                     from_frame, to_frame, &error);
 
 	      if (image_ID != -1)
 		{
@@ -299,10 +305,14 @@
 		  values[1].data.d_image = image_ID;
 		}
 	      else
-		status = GIMP_PDB_EXECUTION_ERROR;
-	    }
+                {
+                  status = GIMP_PDB_EXECUTION_ERROR;
+                }
+            }
 	  else
-	    status = GIMP_PDB_CANCEL;
+            {
+              status = GIMP_PDB_CANCEL;
+            }
 	  break;
 
 	case GIMP_RUN_WITH_LAST_VALS:
@@ -333,8 +343,10 @@
 	    }
 	  if (! save_image (param[3].data.d_string, image_ID,
 			    param[5].data.d_int32,
-			    param[6].data.d_int32))
-	    status = GIMP_PDB_EXECUTION_ERROR;
+			    param[6].data.d_int32, &error))
+            {
+              status = GIMP_PDB_EXECUTION_ERROR;
+            }
 	  break;
 
 	case GIMP_RUN_INTERACTIVE:
@@ -353,11 +365,16 @@
 
 	  if (save_dialog (param[1].data.d_image))
 	    {
-	      if (! save_image (param[3].data.d_string, image_ID, from_frame, to_frame))
-		status = GIMP_PDB_EXECUTION_ERROR;
-	    }
+	      if (! save_image (param[3].data.d_string,
+                                image_ID, from_frame, to_frame, &error))
+                {
+                  status = GIMP_PDB_EXECUTION_ERROR;
+                }
+            }
 	  else
-	    status = GIMP_PDB_CANCEL;
+            {
+              status = GIMP_PDB_CANCEL;
+            }
 	  break;
 	}
 
@@ -388,7 +405,8 @@
 
       if (status == GIMP_PDB_SUCCESS)
 	{
-	  if (get_info (param[0].data.d_string, &width, &height, &frames))
+	  if (get_info (param[0].data.d_string,
+                        &width, &height, &frames, &error))
 	    {
 	      *nreturn_vals = 4;
 	      values[1].type = GIMP_PDB_INT32;
@@ -399,11 +417,22 @@
 	      values[3].data.d_int32 = frames;
 	    }
 	  else
-	    status = GIMP_PDB_EXECUTION_ERROR;
-	}
+            {
+              status = GIMP_PDB_EXECUTION_ERROR;
+            }
+        }
     }
   else
-    status = GIMP_PDB_CALLING_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;
 }
@@ -412,10 +441,11 @@
  * Open FLI animation and return header-info
  */
 static gboolean
-get_info (const gchar *filename,
-	  gint32      *width,
-	  gint32      *height,
-	  gint32      *frames)
+get_info (const gchar  *filename,
+	  gint32       *width,
+	  gint32       *height,
+	  gint32       *frames,
+          GError      **error)
 {
   FILE *file;
   s_fli_header fli_header;
@@ -426,13 +456,16 @@
 
   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 FALSE;
     }
+
   fli_read_header (file, &fli_header);
   fclose (file);
-  *width = fli_header.width;
+
+  *width  = fli_header.width;
   *height = fli_header.height;
   *frames = fli_header.frames;
 
@@ -443,26 +476,26 @@
  * load fli animation and store as framestack
  */
 static gint32
-load_image (const gchar *filename,
-	    gint32       from_frame,
-	    gint32       to_frame)
+load_image (const gchar  *filename,
+	    gint32        from_frame,
+	    gint32        to_frame,
+            GError      **error)
 {
-  FILE *file;
+  FILE         *file;
   GimpDrawable *drawable;
-  gint32 image_id, layer_ID;
-
-  guchar *fb, *ofb, *fb_x;
-  guchar cm[768], ocm[768];
-  GimpPixelRgn pixel_rgn;
-  s_fli_header fli_header;
-
-  gint cnt;
+  gint32        image_id, layer_ID;
+  guchar       *fb, *ofb, *fb_x;
+  guchar        cm[768], ocm[768];
+  GimpPixelRgn  pixel_rgn;
+  s_fli_header  fli_header;
+  gint          cnt;
 
   file = g_fopen (filename ,"rb");
   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;
     }
 
@@ -578,10 +611,11 @@
  * (some code was taken from the GIF plugin.)
  */
 static gboolean
-save_image (const gchar *filename,
-	    gint32       image_id,
-	    gint32       from_frame,
-	    gint32       to_frame)
+save_image (const gchar  *filename,
+	    gint32        image_id,
+	    gint32        from_frame,
+	    gint32        to_frame,
+            GError      **error)
 {
   FILE *file;
   GimpDrawable *drawable;
@@ -712,8 +746,9 @@
   file = g_fopen (filename ,"wb");
   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;
     }
   fseek (file, 128, SEEK_SET);
@@ -792,7 +827,7 @@
  * Dialogs for interactive usage
  */
 static gboolean
-load_dialog (const gchar *name)
+load_dialog (const gchar *filename)
 {
   GtkWidget *dialog;
   GtkWidget *table;
@@ -801,7 +836,7 @@
   gint32     width, height, nframes;
   gboolean   run;
 
-  get_info (name, &width, &height, &nframes);
+  get_info (filename, &width, &height, &nframes, NULL);
 
   from_frame = 1;
   to_frame   = nframes;



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