From 2a6228743925a91db932b4851f405100930bd4e2 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Sun, 8 Sep 2019 16:54:08 +0200 Subject: [PATCH] pdb: add gimp_pdb_set_proc_image_types() and all the needed code in libgimp/ and app/ to set a plug-in procedure's image types using the new API. Remove the image types from GPProcInstall. --- app/pdb/internal-procs.c | 2 +- app/pdb/pdb-cmds.c | 63 ++++++++++++++++++++++++++++++++ app/plug-in/gimpplugin-message.c | 1 - app/plug-in/gimpplugin-proc.c | 52 ++++++++++++++++++++++++++ app/plug-in/gimpplugin-proc.h | 19 ++++++---- libgimp/gimppdb_pdb.c | 39 ++++++++++++++++++++ libgimp/gimppdb_pdb.h | 2 + libgimp/gimpprocedure.c | 8 +++- libgimpbase/gimpprotocol.c | 8 ---- libgimpbase/gimpprotocol.h | 3 +- pdb/groups/pdb.pdb | 37 +++++++++++++++++++ 11 files changed, 213 insertions(+), 21 deletions(-) diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index 0fed61c82c..cbc9b7f935 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -28,7 +28,7 @@ #include "internal-procs.h" -/* 749 procedures registered total */ +/* 750 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/app/pdb/pdb-cmds.c b/app/pdb/pdb-cmds.c index e60aedd98f..97042ed1b9 100644 --- a/app/pdb/pdb-cmds.c +++ b/app/pdb/pdb-cmds.c @@ -263,6 +263,39 @@ pdb_get_proc_info_invoker (GimpProcedure *procedure, return return_vals; } +static GimpValueArray * +pdb_set_proc_image_types_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + const gchar *procedure_name; + const gchar *image_types; + + procedure_name = g_value_get_string (gimp_value_array_index (args, 0)); + image_types = g_value_get_string (gimp_value_array_index (args, 1)); + + if (success) + { + GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in; + + if (plug_in && + gimp_pdb_is_canonical_procedure (procedure_name, error)) + { + success = gimp_plug_in_set_proc_image_types (plug_in, procedure_name, + image_types); + } + else + success = FALSE; + } + + return gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); +} + static GimpValueArray * pdb_get_proc_image_types_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -981,6 +1014,36 @@ register_pdb_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-pdb-set-proc-image-types + */ + procedure = gimp_procedure_new (pdb_set_proc_image_types_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-pdb-set-proc-image-types"); + gimp_procedure_set_static_strings (procedure, + "Set the supported image types for a plug-in procedure.", + "This procedure sets the supported images types for the given procedure.", + "Michael Natterer ", + "Michael Natterer", + "2019", + NULL); + gimp_procedure_add_argument (procedure, + gimp_param_spec_string ("procedure-name", + "procedure name", + "The procedure for which to install the menu path", + FALSE, FALSE, TRUE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_argument (procedure, + gimp_param_spec_string ("image-types", + "image types", + "The procedure's supported image types", + FALSE, TRUE, FALSE, + NULL, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-pdb-get-proc-image-types */ diff --git a/app/plug-in/gimpplugin-message.c b/app/plug-in/gimpplugin-message.c index 74027da4c4..ba7e09ce2f 100644 --- a/app/plug-in/gimpplugin-message.c +++ b/app/plug-in/gimpplugin-message.c @@ -870,7 +870,6 @@ gimp_plug_in_handle_proc_install (GimpPlugIn *plug_in, if (proc_install->menu_label && strlen (proc_install->menu_label)) proc->menu_label = g_strdup (proc_install->menu_label); - gimp_plug_in_procedure_set_image_types (proc, proc_install->image_types); gimp_plug_in_procedure_set_help_id (proc, proc_install->help_id); for (i = 0; i < proc_install->nparams; i++) diff --git a/app/plug-in/gimpplugin-proc.c b/app/plug-in/gimpplugin-proc.c index c523b8a58e..ff7ab5a495 100644 --- a/app/plug-in/gimpplugin-proc.c +++ b/app/plug-in/gimpplugin-proc.c @@ -37,6 +37,58 @@ #include "gimp-intl.h" +gboolean +gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *image_types) +{ + GimpPlugInProcedure *proc = NULL; + + g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE); + g_return_val_if_fail (proc_name != NULL, FALSE); + + if (plug_in->plug_in_def) + proc = gimp_plug_in_procedure_find (plug_in->plug_in_def->procedures, + proc_name); + + if (! proc) + proc = gimp_plug_in_procedure_find (plug_in->temp_procedures, proc_name); + + if (! proc) + { + gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR, + "Plug-in \"%s\"\n(%s)\n" + "attempted to register images types " + "for the 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; + } + + switch (GIMP_PROCEDURE (proc)->proc_type) + { + case GIMP_PDB_PROC_TYPE_INTERNAL: + return FALSE; + + case GIMP_PDB_PROC_TYPE_PLUGIN: + case GIMP_PDB_PROC_TYPE_EXTENSION: + if (plug_in->call_mode != GIMP_PLUG_IN_CALL_QUERY && + plug_in->call_mode != GIMP_PLUG_IN_CALL_INIT) + return FALSE; + + case GIMP_PDB_PROC_TYPE_TEMPORARY: + break; + } + + gimp_plug_in_procedure_set_image_types (proc, image_types); + + return TRUE; +} + gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in, const gchar *proc_name, diff --git a/app/plug-in/gimpplugin-proc.h b/app/plug-in/gimpplugin-proc.h index 9308aff43f..6cd5fb70cb 100644 --- a/app/plug-in/gimpplugin-proc.h +++ b/app/plug-in/gimpplugin-proc.h @@ -21,14 +21,17 @@ #define __GIMP_PLUG_IN_PROC_H__ -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_image_types (GimpPlugIn *plug_in, + const gchar *proc_name, + const gchar *image_types); +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); #endif /* __GIMP_PLUG_IN_PROC_H__ */ diff --git a/libgimp/gimppdb_pdb.c b/libgimp/gimppdb_pdb.c index 7ddcf37630..8a4a2ad2d9 100644 --- a/libgimp/gimppdb_pdb.c +++ b/libgimp/gimppdb_pdb.c @@ -262,6 +262,45 @@ _gimp_pdb_get_proc_info (const gchar *procedure_name, return success; } +/** + * _gimp_pdb_set_proc_image_types: + * @procedure_name: The procedure for which to install the menu path. + * @image_types: The procedure's supported image types. + * + * Set the supported image types for a plug-in procedure. + * + * This procedure sets the supported images types for the given + * procedure. + * + * Returns: TRUE on success. + * + * Since: 3.0 + **/ +gboolean +_gimp_pdb_set_proc_image_types (const gchar *procedure_name, + const gchar *image_types) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + gboolean success = TRUE; + + args = gimp_value_array_new_from_types (NULL, + G_TYPE_STRING, procedure_name, + G_TYPE_STRING, image_types, + G_TYPE_NONE); + + return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-pdb-set-proc-image-types", + args); + gimp_value_array_unref (args); + + success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS; + + gimp_value_array_unref (return_vals); + + return success; +} + /** * _gimp_pdb_get_proc_image_types: * @procedure_name: The procedure name. diff --git a/libgimp/gimppdb_pdb.h b/libgimp/gimppdb_pdb.h index d4d2f535b0..41bc5766a0 100644 --- a/libgimp/gimppdb_pdb.h +++ b/libgimp/gimppdb_pdb.h @@ -48,6 +48,8 @@ G_GNUC_INTERNAL gboolean _gimp_pdb_get_proc_info (const gchar GimpPDBProcType *proc_type, gint *num_args, gint *num_values); +G_GNUC_INTERNAL gboolean _gimp_pdb_set_proc_image_types (const gchar *procedure_name, + const gchar *image_types); G_GNUC_INTERNAL gchar* _gimp_pdb_get_proc_image_types (const gchar *procedure_name); G_GNUC_INTERNAL gchar* _gimp_pdb_get_proc_menu_label (const gchar *procedure_name); G_GNUC_INTERNAL gboolean _gimp_pdb_add_proc_menu_path (const gchar *procedure_name, diff --git a/libgimp/gimpprocedure.c b/libgimp/gimpprocedure.c index 8266d55581..10e48120d3 100644 --- a/libgimp/gimpprocedure.c +++ b/libgimp/gimpprocedure.c @@ -372,7 +372,6 @@ gimp_procedure_real_install (GimpProcedure *procedure) proc_install.copyright = (gchar *) gimp_procedure_get_copyright (procedure); proc_install.date = (gchar *) gimp_procedure_get_date (procedure); proc_install.menu_label = (gchar *) gimp_procedure_get_menu_label (procedure); - proc_install.image_types = (gchar *) gimp_procedure_get_image_types (procedure); proc_install.type = gimp_procedure_get_proc_type (procedure); proc_install.nparams = n_args; proc_install.nreturn_vals = n_return_vals; @@ -402,6 +401,9 @@ gimp_procedure_real_install (GimpProcedure *procedure) gimp_procedure_install_icon (procedure); + _gimp_pdb_set_proc_image_types (gimp_procedure_get_name (procedure), + procedure->priv->image_types); + for (list = gimp_procedure_get_menu_paths (procedure); list; list = g_list_next (list)) @@ -590,6 +592,10 @@ gimp_procedure_set_image_types (GimpProcedure *procedure, g_free (procedure->priv->image_types); procedure->priv->image_types = g_strdup (image_types); + + if (procedure->priv->installed) + _gimp_pdb_set_proc_image_types (gimp_procedure_get_name (procedure), + procedure->priv->image_types); } /** diff --git a/libgimpbase/gimpprotocol.c b/libgimpbase/gimpprotocol.c index bc35fe0fca..4d1c62223b 100644 --- a/libgimpbase/gimpprotocol.c +++ b/libgimpbase/gimpprotocol.c @@ -1224,9 +1224,6 @@ _gp_proc_install_read (GIOChannel *channel, if (! _gimp_wire_read_string (channel, &proc_install->menu_label, 1, user_data)) goto cleanup; - if (! _gimp_wire_read_string (channel, - &proc_install->image_types, 1, user_data)) - goto cleanup; if (! _gimp_wire_read_int32 (channel, &proc_install->type, 1, user_data)) @@ -1270,7 +1267,6 @@ _gp_proc_install_read (GIOChannel *channel, g_free (proc_install->copyright); g_free (proc_install->date); g_free (proc_install->menu_label); - g_free (proc_install->image_types); if (proc_install->params) { @@ -1472,9 +1468,6 @@ _gp_proc_install_write (GIOChannel *channel, if (! _gimp_wire_write_string (channel, &proc_install->menu_label, 1, user_data)) return; - if (! _gimp_wire_write_string (channel, - &proc_install->image_types, 1, user_data)) - return; if (! _gimp_wire_write_int32 (channel, &proc_install->type, 1, user_data)) @@ -1520,7 +1513,6 @@ _gp_proc_install_destroy (GimpWireMessage *msg) g_free (proc_install->copyright); g_free (proc_install->date); g_free (proc_install->menu_label); - g_free (proc_install->image_types); for (i = 0; i < proc_install->nparams; i++) { diff --git a/libgimpbase/gimpprotocol.h b/libgimpbase/gimpprotocol.h index 81405097ef..a0727bc54e 100644 --- a/libgimpbase/gimpprotocol.h +++ b/libgimpbase/gimpprotocol.h @@ -26,7 +26,7 @@ G_BEGIN_DECLS /* Increment every time the protocol changes */ -#define GIMP_PROTOCOL_VERSION 0x0109 +#define GIMP_PROTOCOL_VERSION 0x010A enum @@ -289,7 +289,6 @@ struct _GPProcInstall gchar *copyright; gchar *date; gchar *menu_label; - gchar *image_types; guint32 type; guint32 nparams; guint32 nreturn_vals; diff --git a/pdb/groups/pdb.pdb b/pdb/groups/pdb.pdb index dade635db9..b87e5b3ed9 100644 --- a/pdb/groups/pdb.pdb +++ b/pdb/groups/pdb.pdb @@ -246,6 +246,42 @@ CODE ); } +sub pdb_set_proc_image_types { + $blurb = "Set the supported image types for a plug-in procedure."; + + $help = < 'procedure_name', type => 'string', non_empty => 1, + desc => 'The procedure for which to install the menu path' }, + { name => 'image_types', type => 'string', null_ok => 1, + desc => "The procedure's supported image types" } + ); + + %invoke = ( + code => <<'CODE' +{ + GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in; + + if (plug_in && + gimp_pdb_is_canonical_procedure (procedure_name, error)) + { + success = gimp_plug_in_set_proc_image_types (plug_in, procedure_name, + image_types); + } + else + success = FALSE; +} +CODE + ); +} + sub pdb_get_proc_image_types { $blurb = <<'BLURB'; Queries the procedural database for the image types supported by the @@ -851,6 +887,7 @@ CODE pdb_query pdb_proc_exists pdb_get_proc_info + pdb_set_proc_image_types pdb_get_proc_image_types pdb_get_proc_menu_label pdb_add_proc_menu_path