From a88aa27942a5b97a0930ca4d0f7e4095df90ad62 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 9 Sep 2019 12:10:32 +0200 Subject: [PATCH] app: use GError in all gimpplugin-proc.[ch] functions, not gimp_message() --- app/pdb/pdb-cmds.c | 14 +- app/plug-in/gimpplugin-proc.c | 234 +++++++++++++++------------------- app/plug-in/gimpplugin-proc.h | 54 ++++---- pdb/groups/pdb.pdb | 14 +- 4 files changed, 151 insertions(+), 165 deletions(-) diff --git a/app/pdb/pdb-cmds.c b/app/pdb/pdb-cmds.c index 1bdc95a440..fbbadde5c6 100644 --- a/app/pdb/pdb-cmds.c +++ b/app/pdb/pdb-cmds.c @@ -286,7 +286,7 @@ pdb_set_proc_image_types_invoker (GimpProcedure *procedure, gimp_pdb_is_canonical_procedure (procedure_name, error)) { success = gimp_plug_in_set_proc_image_types (plug_in, procedure_name, - image_types); + image_types, error); } else success = FALSE; @@ -361,7 +361,7 @@ pdb_set_proc_menu_label_invoker (GimpProcedure *procedure, gimp_pdb_is_canonical_procedure (procedure_name, error)) { success = gimp_plug_in_set_proc_menu_label (plug_in, procedure_name, - menu_label); + menu_label, error); } else success = FALSE; @@ -436,7 +436,7 @@ pdb_add_proc_menu_path_invoker (GimpProcedure *procedure, gimp_pdb_is_canonical_procedure (procedure_name, error)) { success = gimp_plug_in_add_proc_menu_path (plug_in, procedure_name, - menu_path); + menu_path, error); } else success = FALSE; @@ -537,7 +537,8 @@ pdb_set_proc_icon_invoker (GimpProcedure *procedure, { success = gimp_plug_in_set_proc_icon (plug_in, procedure_name, icon_type, - icon_data, icon_data_length); + icon_data, icon_data_length, + error); } else success = FALSE; @@ -574,7 +575,7 @@ pdb_set_proc_documentation_invoker (GimpProcedure *procedure, gimp_pdb_is_canonical_procedure (procedure_name, error)) { success = gimp_plug_in_set_proc_help (plug_in, procedure_name, - blurb, help, help_id); + blurb, help, help_id, error); } else success = FALSE; @@ -661,7 +662,8 @@ pdb_set_proc_attribution_invoker (GimpProcedure *procedure, gimp_pdb_is_canonical_procedure (procedure_name, error)) { success = gimp_plug_in_set_proc_attribution (plug_in, procedure_name, - authors, copyright, date); + authors, copyright, date, + error); } else success = FALSE; diff --git a/app/plug-in/gimpplugin-proc.c b/app/plug-in/gimpplugin-proc.c index 633c780ad1..036e09d557 100644 --- a/app/plug-in/gimpplugin-proc.c +++ b/app/plug-in/gimpplugin-proc.c @@ -26,7 +26,7 @@ #include "plug-in-types.h" -#include "core/gimp.h" +#include "pdb/gimppdberror.h" #include "gimpplugin.h" #include "gimpplugin-proc.h" @@ -46,9 +46,10 @@ static GimpPlugInProcedure * gimp_plug_in_proc_find (GimpPlugIn *plug_in, /* public functions */ gboolean -gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *image_types) +gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *image_types, + GError **error) { GimpPlugInProcedure *proc; @@ -59,15 +60,15 @@ gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in, if (! proc) { - gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, - "Plug-in \"%s\"\n(%s)\n" - "attempted to register images types " - "for procedure \"%s\".\n" - "It has however not installed that procedure. " - "This is not allowed.", - gimp_object_get_name (plug_in), - gimp_file_get_utf8_name (plug_in->file), - proc_name); + g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND, + "Plug-in \"%s\"\n(%s)\n" + "attempted to register images types " + "for procedure \"%s\".\n" + "It has however not installed that procedure. " + "This is not allowed.", + gimp_object_get_name (plug_in), + gimp_file_get_utf8_name (plug_in->file), + proc_name); return FALSE; } @@ -78,12 +79,12 @@ gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in, } gboolean -gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *menu_label) +gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *menu_label, + GError **error) { GimpPlugInProcedure *proc; - GError *error = NULL; g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE); g_return_val_if_fail (proc_name != NULL, FALSE); @@ -93,38 +94,29 @@ gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in, if (! proc) { - gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, - "Plug-in \"%s\"\n(%s)\n" - "attempted to register the menu label \"%s\" " - "for procedure \"%s\".\n" - "It has however not installed that procedure. " - "This is not allowed.", - gimp_object_get_name (plug_in), - gimp_file_get_utf8_name (plug_in->file), - menu_label, proc_name); + g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND, + "Plug-in \"%s\"\n(%s)\n" + "attempted to register the menu label \"%s\" " + "for procedure \"%s\".\n" + "It has however not installed that procedure. " + "This is not allowed.", + gimp_object_get_name (plug_in), + gimp_file_get_utf8_name (plug_in->file), + menu_label, proc_name); return FALSE; } - if (! gimp_plug_in_procedure_set_menu_label (proc, menu_label, &error)) - { - gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, - error->message); - g_clear_error (&error); - - return FALSE; - } - - return TRUE; + return gimp_plug_in_procedure_set_menu_label (proc, menu_label, error); } gboolean -gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *menu_path) +gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *menu_path, + GError **error) { GimpPlugInProcedure *proc; - GError *error = NULL; g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE); g_return_val_if_fail (proc_name != NULL, FALSE); @@ -134,80 +126,63 @@ gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in, if (! proc) { - gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, - "Plug-in \"%s\"\n(%s)\n" - "attempted to register the menu item \"%s\" " - "for procedure \"%s\".\n" - "It has however not installed that procedure. " - "This is not allowed.", - gimp_object_get_name (plug_in), - gimp_file_get_utf8_name (plug_in->file), - menu_path, proc_name); + g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND, + "Plug-in \"%s\"\n(%s)\n" + "attempted to register the menu item \"%s\" " + "for procedure \"%s\".\n" + "It has however not installed that procedure. " + "This is not allowed.", + gimp_object_get_name (plug_in), + gimp_file_get_utf8_name (plug_in->file), + menu_path, proc_name); return FALSE; } - if (! gimp_plug_in_procedure_add_menu_path (proc, menu_path, &error)) - { - gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, - error->message); - g_clear_error (&error); - - return FALSE; - } - - return TRUE; + return gimp_plug_in_procedure_add_menu_path (proc, menu_path, error); } gboolean -gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in, +gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in, + const gchar *proc_name, + GimpIconType type, + const guint8 *data, + gint data_length, + GError **error) +{ + GimpPlugInProcedure *proc; + + g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE); + g_return_val_if_fail (proc_name != NULL, FALSE); + + proc = gimp_plug_in_proc_find (plug_in, proc_name); + + if (! proc) + { + g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND, + "Plug-in \"%s\"\n(%s)\n" + "attempted to set the icon " + "for procedure \"%s\".\n" + "It has however not installed that procedure. " + "This is not allowed.", + gimp_object_get_name (plug_in), + gimp_file_get_utf8_name (plug_in->file), + proc_name); + + return FALSE; + } + + return gimp_plug_in_procedure_set_icon (proc, type, data, data_length, + error); +} + +gboolean +gimp_plug_in_set_proc_help (GimpPlugIn *plug_in, const gchar *proc_name, - GimpIconType type, - const guint8 *data, - gint data_length) -{ - GimpPlugInProcedure *proc; - GError *error = NULL; - - g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE); - g_return_val_if_fail (proc_name != NULL, FALSE); - - proc = gimp_plug_in_proc_find (plug_in, proc_name); - - if (! proc) - { - gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, - "Plug-in \"%s\"\n(%s)\n" - "attempted to set the icon " - "for procedure \"%s\".\n" - "It has however not installed that procedure. " - "This is not allowed.", - gimp_object_get_name (plug_in), - gimp_file_get_utf8_name (plug_in->file), - proc_name); - - return FALSE; - } - - if (! gimp_plug_in_procedure_set_icon (proc, type, data, data_length, - &error)) - { - gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, - error->message); - g_clear_error (&error); - - return FALSE; - } - - return TRUE; -} - -gboolean -gimp_plug_in_set_proc_help (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *blurb, - const gchar *help, - const gchar *help_id) + const gchar *blurb, + const gchar *help, + const gchar *help_id, + GError **error) { GimpPlugInProcedure *proc; @@ -218,15 +193,15 @@ gimp_plug_in_set_proc_help (GimpPlugIn *plug_in, if (! proc) { - gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, - "Plug-in \"%s\"\n(%s)\n" - "attempted to register help " - "for procedure \"%s\".\n" - "It has however not installed that procedure. " - "This is not allowed.", - gimp_object_get_name (plug_in), - gimp_file_get_utf8_name (plug_in->file), - proc_name); + g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND, + "Plug-in \"%s\"\n(%s)\n" + "attempted to register help " + "for procedure \"%s\".\n" + "It has however not installed that procedure. " + "This is not allowed.", + gimp_object_get_name (plug_in), + gimp_file_get_utf8_name (plug_in->file), + proc_name); return FALSE; } @@ -238,11 +213,12 @@ gimp_plug_in_set_proc_help (GimpPlugIn *plug_in, } gboolean -gimp_plug_in_set_proc_attribution (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *authors, - const gchar *copyright, - const gchar *date) +gimp_plug_in_set_proc_attribution (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *authors, + const gchar *copyright, + const gchar *date, + GError **error) { GimpPlugInProcedure *proc; @@ -253,15 +229,15 @@ gimp_plug_in_set_proc_attribution (GimpPlugIn *plug_in, if (! proc) { - gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, - "Plug-in \"%s\"\n(%s)\n" - "attempted to register the attribution " - "for procedure \"%s\".\n" - "It has however not installed that procedure. " - "This is not allowed.", - gimp_object_get_name (plug_in), - gimp_file_get_utf8_name (plug_in->file), - proc_name); + g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_PROCEDURE_NOT_FOUND, + "Plug-in \"%s\"\n(%s)\n" + "attempted to register the attribution " + "for procedure \"%s\".\n" + "It has however not installed that procedure. " + "This is not allowed.", + gimp_object_get_name (plug_in), + gimp_file_get_utf8_name (plug_in->file), + proc_name); return FALSE; } diff --git a/app/plug-in/gimpplugin-proc.h b/app/plug-in/gimpplugin-proc.h index 5ead2b9e03..1cd2f2d939 100644 --- a/app/plug-in/gimpplugin-proc.h +++ b/app/plug-in/gimpplugin-proc.h @@ -21,30 +21,36 @@ #define __GIMP_PLUG_IN_PROC_H__ -gboolean gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *image_types); -gboolean gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *menu_label); -gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *menu_path); -gboolean gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in, - const gchar *proc_name, - GimpIconType type, - const guint8 *data, - gint data_length); -gboolean gimp_plug_in_set_proc_help (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *blurb, - const gchar *help, - const gchar *help_id); -gboolean gimp_plug_in_set_proc_attribution (GimpPlugIn *plug_in, - const gchar *proc_name, - const gchar *authors, - const gchar *copyright, - const gchar *date); +gboolean gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *image_types, + GError **error); +gboolean gimp_plug_in_set_proc_menu_label (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *menu_label, + GError **error); +gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *menu_path, + GError **error); +gboolean gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in, + const gchar *proc_name, + GimpIconType type, + const guint8 *data, + gint data_length, + GError **error); +gboolean gimp_plug_in_set_proc_help (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *blurb, + const gchar *help, + const gchar *help_id, + GError **error); +gboolean gimp_plug_in_set_proc_attribution (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *authors, + const gchar *copyright, + const gchar *date, + GError **error); #endif /* __GIMP_PLUG_IN_PROC_H__ */ diff --git a/pdb/groups/pdb.pdb b/pdb/groups/pdb.pdb index 43cb168bd7..b6cb02057a 100644 --- a/pdb/groups/pdb.pdb +++ b/pdb/groups/pdb.pdb @@ -273,7 +273,7 @@ HELP gimp_pdb_is_canonical_procedure (procedure_name, error)) { success = gimp_plug_in_set_proc_image_types (plug_in, procedure_name, - image_types); + image_types, error); } else success = FALSE; @@ -355,7 +355,7 @@ HELP gimp_pdb_is_canonical_procedure (procedure_name, error)) { success = gimp_plug_in_set_proc_menu_label (plug_in, procedure_name, - menu_label); + menu_label, error); } else success = FALSE; @@ -436,7 +436,7 @@ HELP gimp_pdb_is_canonical_procedure (procedure_name, error)) { success = gimp_plug_in_add_proc_menu_path (plug_in, procedure_name, - menu_path); + menu_path, error); } else success = FALSE; @@ -542,7 +542,8 @@ HELP { success = gimp_plug_in_set_proc_icon (plug_in, procedure_name, icon_type, - icon_data, icon_data_length); + icon_data, icon_data_length, + error); } else success = FALSE; @@ -582,7 +583,7 @@ HELP gimp_pdb_is_canonical_procedure (procedure_name, error)) { success = gimp_plug_in_set_proc_help (plug_in, procedure_name, - blurb, help, help_id); + blurb, help, help_id, error); } else success = FALSE; @@ -674,7 +675,8 @@ HELP gimp_pdb_is_canonical_procedure (procedure_name, error)) { success = gimp_plug_in_set_proc_attribution (plug_in, procedure_name, - authors, copyright, date); + authors, copyright, date, + error); } else success = FALSE;