From 2fcef8b03e547dcc8e846b49e92e158c22b4d84a Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sat, 16 Aug 2008 17:18:13 +0000 Subject: [PATCH] Next step towards fixing bug #344818: 2008-08-16 Sven Neumann 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. svn path=/trunk/; revision=26602 --- ChangeLog | 14 +++++ libgimp/gimp.c | 103 +++++++++++++++++++++++++++++------ libgimp/gimp.def | 1 + libgimp/gimp.h | 4 ++ plug-ins/pygimp/gimpmodule.c | 8 ++- po-libgimp/ChangeLog | 4 ++ po-libgimp/POTFILES.in | 1 + 7 files changed, 114 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index b252ee0e02..57a70d3e39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2008-08-16 Sven Neumann + + 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. + 2008-08-16 Sven Neumann * app/plug-in/gimpplugin-message.c (gimp_plug_in_handle_proc_run): diff --git a/libgimp/gimp.c b/libgimp/gimp.c index 978253e6ec..e55394e3d5 100644 --- a/libgimp/gimp.c +++ b/libgimp/gimp.c @@ -90,7 +90,6 @@ # define USE_WIN32_SHM 1 #endif -#include #include #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 @@ static gboolean gimp_extension_read (GIOChannel *channel, 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 @@ static const GDebugKey gimp_debug_keys[] = { "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 @@ gimp_run_procedure2 (const gchar *name, 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; } @@ -1018,6 +1013,49 @@ gimp_destroy_paramdefs (GimpParamDef *paramdefs, g_free (paramdefs); } +/** + * 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: * @@ -1229,7 +1267,7 @@ gimp_default_display (void) const gchar * gimp_wm_class (void) { - return (const gchar *) _wm_class; + return _wm_class; } /** @@ -1244,7 +1282,7 @@ gimp_wm_class (void) const gchar * gimp_display_name (void) { - return (const gchar *) _display_name; + return _display_name; } /** @@ -1953,3 +1991,32 @@ gimp_extension_read (GIOChannel *channel, 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; + } +} diff --git a/libgimp/gimp.def b/libgimp/gimp.def index bcacf97eb2..36d8fda458 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -236,6 +236,7 @@ EXPORTS 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 diff --git a/libgimp/gimp.h b/libgimp/gimp.h index 489576eca0..8717ddee93 100644 --- a/libgimp/gimp.h +++ b/libgimp/gimp.h @@ -307,6 +307,10 @@ void gimp_destroy_params (GimpParam *params, 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. */ diff --git a/plug-ins/pygimp/gimpmodule.c b/plug-ins/pygimp/gimpmodule.c index 9b631755bf..8b7aedc880 100644 --- a/plug-ins/pygimp/gimpmodule.c +++ b/plug-ins/pygimp/gimpmodule.c @@ -1541,7 +1541,7 @@ pygimp_vectors_import_from_file(PyObject *self, PyObject *args, PyObject *kwargs 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 @@ pygimp_vectors_import_from_file(PyObject *self, PyObject *args, PyObject *kwargs } 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 @@ pygimp_vectors_import_from_string(PyObject *self, PyObject *args, PyObject *kwar &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; } diff --git a/po-libgimp/ChangeLog b/po-libgimp/ChangeLog index d099e31c30..eb300f7d19 100644 --- a/po-libgimp/ChangeLog +++ b/po-libgimp/ChangeLog @@ -1,3 +1,7 @@ +2008-08-16 Sven Neumann + + * POTFILES.in: added libgimp/gimp.c with some new messages. + 2008-08-14 Takeshi AIHANA * ja.po: Updated Japanese translation by Kiyotaka Nishibori. diff --git a/po-libgimp/POTFILES.in b/po-libgimp/POTFILES.in index 1f65539d4c..2bc244f075 100644 --- a/po-libgimp/POTFILES.in +++ b/po-libgimp/POTFILES.in @@ -3,6 +3,7 @@ [encoding: UTF-8] +libgimp/gimp.c libgimp/gimpbrushmenu.c libgimp/gimpbrushselectbutton.c libgimp/gimpexport.c