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.
This commit is contained in:
Michael Natterer 2019-09-08 16:54:08 +02:00
parent d75a25c565
commit 2a62287439
11 changed files with 213 additions and 21 deletions

View File

@ -28,7 +28,7 @@
#include "internal-procs.h" #include "internal-procs.h"
/* 749 procedures registered total */ /* 750 procedures registered total */
void void
internal_procs_init (GimpPDB *pdb) internal_procs_init (GimpPDB *pdb)

View File

@ -263,6 +263,39 @@ pdb_get_proc_info_invoker (GimpProcedure *procedure,
return return_vals; 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 * static GimpValueArray *
pdb_get_proc_image_types_invoker (GimpProcedure *procedure, pdb_get_proc_image_types_invoker (GimpProcedure *procedure,
Gimp *gimp, Gimp *gimp,
@ -981,6 +1014,36 @@ register_pdb_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure); gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (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 <mitch@gimp.org>",
"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 * gimp-pdb-get-proc-image-types
*/ */

View File

@ -870,7 +870,6 @@ gimp_plug_in_handle_proc_install (GimpPlugIn *plug_in,
if (proc_install->menu_label && strlen (proc_install->menu_label)) if (proc_install->menu_label && strlen (proc_install->menu_label))
proc->menu_label = g_strdup (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); gimp_plug_in_procedure_set_help_id (proc, proc_install->help_id);
for (i = 0; i < proc_install->nparams; i++) for (i = 0; i < proc_install->nparams; i++)

View File

@ -37,6 +37,58 @@
#include "gimp-intl.h" #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 gboolean
gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in, gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name, const gchar *proc_name,

View File

@ -21,14 +21,17 @@
#define __GIMP_PLUG_IN_PROC_H__ #define __GIMP_PLUG_IN_PROC_H__
gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in, gboolean gimp_plug_in_set_proc_image_types (GimpPlugIn *plug_in,
const gchar *proc_name, const gchar *proc_name,
const gchar *menu_path); const gchar *image_types);
gboolean gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in, gboolean gimp_plug_in_add_proc_menu_path (GimpPlugIn *plug_in,
const gchar *proc_name, const gchar *proc_name,
GimpIconType type, const gchar *menu_path);
const guint8 *data, gboolean gimp_plug_in_set_proc_icon (GimpPlugIn *plug_in,
gint data_length); const gchar *proc_name,
GimpIconType type,
const guint8 *data,
gint data_length);
#endif /* __GIMP_PLUG_IN_PROC_H__ */ #endif /* __GIMP_PLUG_IN_PROC_H__ */

View File

@ -262,6 +262,45 @@ _gimp_pdb_get_proc_info (const gchar *procedure_name,
return success; 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: * _gimp_pdb_get_proc_image_types:
* @procedure_name: The procedure name. * @procedure_name: The procedure name.

View File

@ -48,6 +48,8 @@ G_GNUC_INTERNAL gboolean _gimp_pdb_get_proc_info (const gchar
GimpPDBProcType *proc_type, GimpPDBProcType *proc_type,
gint *num_args, gint *num_args,
gint *num_values); 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_image_types (const gchar *procedure_name);
G_GNUC_INTERNAL gchar* _gimp_pdb_get_proc_menu_label (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, G_GNUC_INTERNAL gboolean _gimp_pdb_add_proc_menu_path (const gchar *procedure_name,

View File

@ -372,7 +372,6 @@ gimp_procedure_real_install (GimpProcedure *procedure)
proc_install.copyright = (gchar *) gimp_procedure_get_copyright (procedure); proc_install.copyright = (gchar *) gimp_procedure_get_copyright (procedure);
proc_install.date = (gchar *) gimp_procedure_get_date (procedure); proc_install.date = (gchar *) gimp_procedure_get_date (procedure);
proc_install.menu_label = (gchar *) gimp_procedure_get_menu_label (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.type = gimp_procedure_get_proc_type (procedure);
proc_install.nparams = n_args; proc_install.nparams = n_args;
proc_install.nreturn_vals = n_return_vals; proc_install.nreturn_vals = n_return_vals;
@ -402,6 +401,9 @@ gimp_procedure_real_install (GimpProcedure *procedure)
gimp_procedure_install_icon (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); for (list = gimp_procedure_get_menu_paths (procedure);
list; list;
list = g_list_next (list)) list = g_list_next (list))
@ -590,6 +592,10 @@ gimp_procedure_set_image_types (GimpProcedure *procedure,
g_free (procedure->priv->image_types); g_free (procedure->priv->image_types);
procedure->priv->image_types = g_strdup (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);
} }
/** /**

View File

@ -1224,9 +1224,6 @@ _gp_proc_install_read (GIOChannel *channel,
if (! _gimp_wire_read_string (channel, if (! _gimp_wire_read_string (channel,
&proc_install->menu_label, 1, user_data)) &proc_install->menu_label, 1, user_data))
goto cleanup; goto cleanup;
if (! _gimp_wire_read_string (channel,
&proc_install->image_types, 1, user_data))
goto cleanup;
if (! _gimp_wire_read_int32 (channel, if (! _gimp_wire_read_int32 (channel,
&proc_install->type, 1, user_data)) &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->copyright);
g_free (proc_install->date); g_free (proc_install->date);
g_free (proc_install->menu_label); g_free (proc_install->menu_label);
g_free (proc_install->image_types);
if (proc_install->params) if (proc_install->params)
{ {
@ -1472,9 +1468,6 @@ _gp_proc_install_write (GIOChannel *channel,
if (! _gimp_wire_write_string (channel, if (! _gimp_wire_write_string (channel,
&proc_install->menu_label, 1, user_data)) &proc_install->menu_label, 1, user_data))
return; return;
if (! _gimp_wire_write_string (channel,
&proc_install->image_types, 1, user_data))
return;
if (! _gimp_wire_write_int32 (channel, if (! _gimp_wire_write_int32 (channel,
&proc_install->type, 1, user_data)) &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->copyright);
g_free (proc_install->date); g_free (proc_install->date);
g_free (proc_install->menu_label); g_free (proc_install->menu_label);
g_free (proc_install->image_types);
for (i = 0; i < proc_install->nparams; i++) for (i = 0; i < proc_install->nparams; i++)
{ {

View File

@ -26,7 +26,7 @@ G_BEGIN_DECLS
/* Increment every time the protocol changes /* Increment every time the protocol changes
*/ */
#define GIMP_PROTOCOL_VERSION 0x0109 #define GIMP_PROTOCOL_VERSION 0x010A
enum enum
@ -289,7 +289,6 @@ struct _GPProcInstall
gchar *copyright; gchar *copyright;
gchar *date; gchar *date;
gchar *menu_label; gchar *menu_label;
gchar *image_types;
guint32 type; guint32 type;
guint32 nparams; guint32 nparams;
guint32 nreturn_vals; guint32 nreturn_vals;

View File

@ -246,6 +246,42 @@ CODE
); );
} }
sub pdb_set_proc_image_types {
$blurb = "Set the supported image types for a plug-in procedure.";
$help = <<HELP;
This procedure sets the supported images types for the given procedure.
HELP
&mitch_pdb_misc('2019', '3.0');
$lib_private = 1;
@inargs = (
{ name => '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 { sub pdb_get_proc_image_types {
$blurb = <<'BLURB'; $blurb = <<'BLURB';
Queries the procedural database for the image types supported by the Queries the procedural database for the image types supported by the
@ -851,6 +887,7 @@ CODE
pdb_query pdb_query
pdb_proc_exists pdb_proc_exists
pdb_get_proc_info pdb_get_proc_info
pdb_set_proc_image_types
pdb_get_proc_image_types pdb_get_proc_image_types
pdb_get_proc_menu_label pdb_get_proc_menu_label
pdb_add_proc_menu_path pdb_add_proc_menu_path