gimp r26602 - in trunk: . libgimp plug-ins/pygimp po-libgimp



Author: neo
Date: Sat Aug 16 17:18:13 2008
New Revision: 26602
URL: http://svn.gnome.org/viewvc/gimp?rev=26602&view=rev

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

	Next step towards fixing bug #344818:

	* libgimp/gimp.[ch]: keep the last error status and error 
message
	in libgimp. Added new functon gimp_pdb_get_error() that allows 
to
	retrieve it.

	* libgimp/gimp.def: updated.

	* plug-ins/pygimp/gimpmodule.c (pygimp_vectors_import_from_file)
	(pygimp_vectors_import_from_string): use the new function to get
	a more useful error message.



Modified:
   trunk/ChangeLog
   trunk/libgimp/gimp.c
   trunk/libgimp/gimp.def
   trunk/libgimp/gimp.h
   trunk/plug-ins/pygimp/gimpmodule.c
   trunk/po-libgimp/ChangeLog
   trunk/po-libgimp/POTFILES.in

Modified: trunk/libgimp/gimp.c
==============================================================================
--- trunk/libgimp/gimp.c	(original)
+++ trunk/libgimp/gimp.c	Sat Aug 16 17:18:13 2008
@@ -90,7 +90,6 @@
 #  define USE_WIN32_SHM 1
 #endif
 
-#include <libintl.h>
 #include <locale.h>
 
 #include "libgimpbase/gimpbasetypes.h"
@@ -104,6 +103,8 @@
 #include "gimp.h"
 #include "gimpunitcache.h"
 
+#include "libgimp-intl.h"
+
 
 #define TILE_MAP_SIZE (_tile_width * _tile_height * 4)
 
@@ -156,6 +157,9 @@
                                                 GIOCondition     condition,
                                                 gpointer         data);
 
+static void       gimp_set_pdb_error           (const GimpParam *return_vals,
+                                                gint             n_return_vals);
+
 
 static GIOChannel *_readchannel  = NULL;
 GIOChannel *_writechannel = NULL;
@@ -203,10 +207,13 @@
   { "on",             GIMP_DEBUG_DEFAULT        }
 };
 
-
 static GimpPlugInInfo PLUG_IN_INFO;
 
 
+static GimpPDBStatusType  pdb_error_status   = GIMP_PDB_SUCCESS;
+static gchar             *pdb_error_message  = NULL;
+
+
 /**
  * gimp_main:
  * @info: the PLUG_IN_INFO structure
@@ -964,22 +971,10 @@
   proc_return->nparams = 0;
   proc_return->params  = NULL;
 
-  switch (return_vals[0].data.d_status)
-    {
-    case GIMP_PDB_EXECUTION_ERROR:
-      break;
-
-    case GIMP_PDB_CALLING_ERROR:
-      g_printerr ("a calling error occurred while trying to run: \"%s\"\n",
-                  name);
-      break;
-
-    default:
-      break;
-    }
-
   gimp_wire_destroy (&msg);
 
+  gimp_set_pdb_error (return_vals, *n_return_vals);
+
   return return_vals;
 }
 
@@ -1019,6 +1014,49 @@
 }
 
 /**
+ * gimp_get_pdb_error:
+ *
+ * Retrieves the error message from the last procedure call.
+ *
+ * If a procedure call fails, then it might pass an error message with
+ * the return values. Plug-ins that are using the libgimp C wrappers
+ * don't access the procedure return values directly. Thus ligimp
+ * stores the error message and makes it available with this
+ * function. A successful procedure call unsets the error message again.
+ *
+ * The returned string is owned by libgimp and must not be freed or
+ * modified.
+ *
+ * Return value: the error message
+ *
+ * Since: GIMP 2.6
+ **/
+const gchar *
+gimp_get_pdb_error (void)
+{
+  if (pdb_error_message && strlen (pdb_error_message))
+    return pdb_error_message;
+
+  switch (pdb_error_status)
+    {
+    case GIMP_PDB_SUCCESS:
+      return _("success");
+
+    case GIMP_PDB_EXECUTION_ERROR:
+      return _("execution error");
+
+    case GIMP_PDB_CALLING_ERROR:
+      return _("calling error");
+
+    case GIMP_PDB_CANCEL:
+      return _("cancelled");
+
+    default:
+      return "invalid return status";
+    }
+}
+
+/**
  * gimp_tile_width:
  *
  * Returns the tile width GIMP is using.
@@ -1229,7 +1267,7 @@
 const gchar *
 gimp_wm_class (void)
 {
-  return (const gchar *) _wm_class;
+  return _wm_class;
 }
 
 /**
@@ -1244,7 +1282,7 @@
 const gchar *
 gimp_display_name (void)
 {
-  return (const gchar *) _display_name;
+  return _display_name;
 }
 
 /**
@@ -1953,3 +1991,32 @@
 
   return TRUE;
 }
+
+static void
+gimp_set_pdb_error (const GimpParam *return_vals,
+                    gint             n_return_vals)
+{
+  if (pdb_error_message)
+    {
+      g_free (pdb_error_message);
+      pdb_error_message = NULL;
+    }
+
+  pdb_error_status = return_vals[0].data.d_status;
+
+  switch (pdb_error_status)
+    {
+    case GIMP_PDB_SUCCESS:
+    case GIMP_PDB_PASS_THROUGH:
+      break;
+
+    case GIMP_PDB_EXECUTION_ERROR:
+    case GIMP_PDB_CALLING_ERROR:
+    case GIMP_PDB_CANCEL:
+      if (n_return_vals > 1 && return_vals[1].type == GIMP_PDB_STRING)
+        {
+          pdb_error_message = g_strdup (return_vals[1].data.d_string);
+        }
+      break;
+    }
+}

Modified: trunk/libgimp/gimp.def
==============================================================================
--- trunk/libgimp/gimp.def	(original)
+++ trunk/libgimp/gimp.def	Sat Aug 16 17:18:13 2008
@@ -236,6 +236,7 @@
 	gimp_get_module_load_inhibit
 	gimp_get_monitor_resolution
 	gimp_get_path_by_tattoo
+	gimp_get_pdb_error
 	gimp_get_progname
 	gimp_get_theme_dir
 	gimp_getpid

Modified: trunk/libgimp/gimp.h
==============================================================================
--- trunk/libgimp/gimp.h	(original)
+++ trunk/libgimp/gimp.h	Sat Aug 16 17:18:13 2008
@@ -307,6 +307,10 @@
 void           gimp_destroy_paramdefs   (GimpParamDef    *paramdefs,
                                          gint             n_params);
 
+/* Retrieve the error message for the last procedure call.
+ */
+const gchar  * gimp_get_pdb_error       (void);
+
 
 /* Return various constants given by the GIMP core at plug-in config time.
  */

Modified: trunk/plug-ins/pygimp/gimpmodule.c
==============================================================================
--- trunk/plug-ins/pygimp/gimpmodule.c	(original)
+++ trunk/plug-ins/pygimp/gimpmodule.c	Sat Aug 16 17:18:13 2008
@@ -1541,7 +1541,7 @@
             Py_XDECREF(read_method);
             PyErr_SetString(PyExc_TypeError,
                             "svg_file must be an object that has a \"read\" "
-                            "method, or a filename (str)");   
+                            "method, or a filename (str)");
             return NULL;
         }
 
@@ -1583,7 +1583,8 @@
     }
 
     if (!success) {
-        PyErr_SetString(pygimp_error, "Vectors import failed");
+        PyErr_Format(pygimp_error,
+                     "Vectors import failed: %s", gimp_get_pdb_error());
         return NULL;
     }
 
@@ -1614,7 +1615,8 @@
                                               &num_vectors, &vectors);
 
     if (!success) {
-        PyErr_SetString(pygimp_error, "Vectors import failed");
+        PyErr_Format(pygimp_error,
+                     "Vectors import failed: %s", gimp_get_pdb_error());
         return NULL;
     }
 

Modified: trunk/po-libgimp/POTFILES.in
==============================================================================
--- trunk/po-libgimp/POTFILES.in	(original)
+++ trunk/po-libgimp/POTFILES.in	Sat Aug 16 17:18:13 2008
@@ -3,6 +3,7 @@
 
 [encoding: UTF-8]
 
+libgimp/gimp.c
 libgimp/gimpbrushmenu.c
 libgimp/gimpbrushselectbutton.c
 libgimp/gimpexport.c



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