[gimp] pdb: add pdb API to get a procedure's image types, menu label and menu paths
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] pdb: add pdb API to get a procedure's image types, menu label and menu paths
- Date: Sat, 7 Sep 2019 19:12:32 +0000 (UTC)
commit 48692e58c3d1b06f07396b8a30e06a0ae1662ef4
Author: Michael Natterer <mitch gimp org>
Date: Sat Sep 7 21:08:13 2019 +0200
pdb: add pdb API to get a procedure's image types, menu label and menu paths
app/pdb/internal-procs.c | 2 +-
app/pdb/pdb-cmds.c | 242 +++++++++++++++++++++++++++++++++++++++++++++++
libgimp/gimppdb_pdb.c | 121 ++++++++++++++++++++++++
libgimp/gimppdb_pdb.h | 4 +
pdb/groups/pdb.pdb | 159 +++++++++++++++++++++++++++++++
5 files changed, 527 insertions(+), 1 deletion(-)
---
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index 3f904c5ada..0fed61c82c 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
#include "internal-procs.h"
-/* 746 procedures registered total */
+/* 749 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/app/pdb/pdb-cmds.c b/app/pdb/pdb-cmds.c
index ff088e91fc..631b1dd087 100644
--- a/app/pdb/pdb-cmds.c
+++ b/app/pdb/pdb-cmds.c
@@ -35,6 +35,7 @@
#include "gimp-pdb-compat.h"
#include "gimppdb-query.h"
#include "plug-in/gimppluginmanager-data.h"
+#include "plug-in/gimppluginprocedure.h"
#include "gimppdb.h"
#include "gimppdberror.h"
@@ -260,6 +261,153 @@ pdb_proc_info_invoker (GimpProcedure *procedure,
return return_vals;
}
+static GimpValueArray *
+pdb_proc_image_types_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpValueArray *return_vals;
+ const gchar *procedure_name;
+ gchar *image_types = NULL;
+
+ procedure_name = g_value_get_string (gimp_value_array_index (args, 0));
+
+ if (success)
+ {
+ if (gimp_pdb_is_canonical_procedure (procedure_name, error))
+ {
+ GimpProcedure *proc = lookup_procedure (gimp->pdb, procedure_name,
+ error);
+
+ if (GIMP_IS_PLUG_IN_PROCEDURE (proc))
+ {
+ image_types = g_strdup (GIMP_PLUG_IN_PROCEDURE (proc)->image_types);
+ }
+ else
+ success = FALSE;
+ }
+ else
+ success = FALSE;
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ g_value_take_string (gimp_value_array_index (return_vals, 1), image_types);
+
+ return return_vals;
+}
+
+static GimpValueArray *
+pdb_proc_menu_label_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpValueArray *return_vals;
+ const gchar *procedure_name;
+ gchar *menu_label = NULL;
+
+ procedure_name = g_value_get_string (gimp_value_array_index (args, 0));
+
+ if (success)
+ {
+ if (gimp_pdb_is_canonical_procedure (procedure_name, error))
+ {
+ GimpProcedure *proc = lookup_procedure (gimp->pdb, procedure_name,
+ error);
+
+ if (GIMP_IS_PLUG_IN_PROCEDURE (proc))
+ {
+ menu_label = g_strdup (GIMP_PLUG_IN_PROCEDURE (proc)->menu_label);
+ }
+ else
+ success = FALSE;
+ }
+ else
+ success = FALSE;
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ g_value_take_string (gimp_value_array_index (return_vals, 1), menu_label);
+
+ return return_vals;
+}
+
+static GimpValueArray *
+pdb_proc_menu_paths_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GimpValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpValueArray *return_vals;
+ const gchar *procedure_name;
+ gint num_menu_paths = 0;
+ gchar **menu_paths = NULL;
+
+ procedure_name = g_value_get_string (gimp_value_array_index (args, 0));
+
+ if (success)
+ {
+ if (gimp_pdb_is_canonical_procedure (procedure_name, error))
+ {
+ GimpProcedure *proc = lookup_procedure (gimp->pdb, procedure_name,
+ error);
+
+ if (GIMP_IS_PLUG_IN_PROCEDURE (proc))
+ {
+ GimpPlugInProcedure *plug_in_proc = GIMP_PLUG_IN_PROCEDURE (proc);
+
+ num_menu_paths = g_list_length (plug_in_proc->menu_paths);
+
+ if (num_menu_paths > 0)
+ {
+ GList *list;
+ gint i;
+
+ menu_paths = g_new0 (gchar *, num_menu_paths + 1);
+
+ for (list = plug_in_proc->menu_paths, i = 0;
+ list;
+ list = g_list_next (list), i++)
+ {
+ menu_paths[i] = g_strdup (list->data);
+ }
+ }
+ }
+ else
+ success = FALSE;
+ }
+ else
+ success = FALSE;
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ {
+ g_value_set_int (gimp_value_array_index (return_vals, 1), num_menu_paths);
+ gimp_value_take_string_array (gimp_value_array_index (return_vals, 2), menu_paths, num_menu_paths);
+ }
+
+ return return_vals;
+}
+
static GimpValueArray *
pdb_proc_documentation_invoker (GimpProcedure *procedure,
Gimp *gimp,
@@ -760,6 +908,100 @@ register_pdb_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
+ /*
+ * gimp-pdb-proc-image-types
+ */
+ procedure = gimp_procedure_new (pdb_proc_image_types_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-pdb-proc-image-types");
+ gimp_procedure_set_static_strings (procedure,
+ "Queries the procedural database for the image types supported by the
specified procedure.",
+ "This procedure returns the image types supported by the specified
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 name",
+ FALSE, FALSE, TRUE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_string ("image-types",
+ "image types",
+ "The image types",
+ FALSE, FALSE, FALSE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-pdb-proc-menu-label
+ */
+ procedure = gimp_procedure_new (pdb_proc_menu_label_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-pdb-proc-menu-label");
+ gimp_procedure_set_static_strings (procedure,
+ "Queries the procedural database for the procedure's menu label.",
+ "This procedure returns the menu label of the specified 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 name",
+ FALSE, FALSE, TRUE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_string ("menu-label",
+ "menu label",
+ "The menu_label",
+ FALSE, FALSE, FALSE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-pdb-proc-menu-paths
+ */
+ procedure = gimp_procedure_new (pdb_proc_menu_paths_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-pdb-proc-menu-paths");
+ gimp_procedure_set_static_strings (procedure,
+ "Queries the procedural database for the procedure's menu paths.",
+ "This procedure returns the menu paths of the specified 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 name",
+ FALSE, FALSE, TRUE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ g_param_spec_int ("num-menu-paths",
+ "num menu paths",
+ "The number of menu paths",
+ 0, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_string_array ("menu-paths",
+ "menu paths",
+ "The menu paths of the plug-in",
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
/*
* gimp-pdb-proc-documentation
*/
diff --git a/libgimp/gimppdb_pdb.c b/libgimp/gimppdb_pdb.c
index 0549eb641a..f950ff138a 100644
--- a/libgimp/gimppdb_pdb.c
+++ b/libgimp/gimppdb_pdb.c
@@ -262,6 +262,127 @@ _gimp_pdb_proc_info (const gchar *procedure_name,
return success;
}
+/**
+ * _gimp_pdb_proc_image_types:
+ * @procedure_name: The procedure name.
+ *
+ * Queries the procedural database for the image types supported by the
+ * specified procedure.
+ *
+ * This procedure returns the image types supported by the specified
+ * procedure.
+ *
+ * Returns: (transfer full): The image types.
+ * The returned value must be freed with g_free().
+ *
+ * Since: 3.0
+ **/
+gchar *
+_gimp_pdb_proc_image_types (const gchar *procedure_name)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ gchar *image_types = NULL;
+
+ args = gimp_value_array_new_from_types (NULL,
+ G_TYPE_STRING, procedure_name,
+ G_TYPE_NONE);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-pdb-proc-image-types",
+ args);
+ gimp_value_array_unref (args);
+
+ if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
+ image_types = GIMP_VALUES_DUP_STRING (return_vals, 1);
+
+ gimp_value_array_unref (return_vals);
+
+ return image_types;
+}
+
+/**
+ * _gimp_pdb_proc_menu_label:
+ * @procedure_name: The procedure name.
+ *
+ * Queries the procedural database for the procedure's menu label.
+ *
+ * This procedure returns the menu label of the specified procedure.
+ *
+ * Returns: (transfer full): The menu_label.
+ * The returned value must be freed with g_free().
+ *
+ * Since: 3.0
+ **/
+gchar *
+_gimp_pdb_proc_menu_label (const gchar *procedure_name)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ gchar *menu_label = NULL;
+
+ args = gimp_value_array_new_from_types (NULL,
+ G_TYPE_STRING, procedure_name,
+ G_TYPE_NONE);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-pdb-proc-menu-label",
+ args);
+ gimp_value_array_unref (args);
+
+ if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
+ menu_label = GIMP_VALUES_DUP_STRING (return_vals, 1);
+
+ gimp_value_array_unref (return_vals);
+
+ return menu_label;
+}
+
+/**
+ * _gimp_pdb_proc_menu_paths:
+ * @procedure_name: The procedure name.
+ * @num_menu_paths: (out): The number of menu paths.
+ *
+ * Queries the procedural database for the procedure's menu paths.
+ *
+ * This procedure returns the menu paths of the specified procedure.
+ *
+ * Returns: (array length=num_menu_paths) (element-type gchar*) (transfer full):
+ * The menu paths of the plug-in.
+ * The returned value must be freed with g_strfreev().
+ *
+ * Since: 3.0
+ **/
+gchar **
+_gimp_pdb_proc_menu_paths (const gchar *procedure_name,
+ gint *num_menu_paths)
+{
+ GimpValueArray *args;
+ GimpValueArray *return_vals;
+ gchar **menu_paths = NULL;
+
+ args = gimp_value_array_new_from_types (NULL,
+ G_TYPE_STRING, procedure_name,
+ G_TYPE_NONE);
+
+ return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+ "gimp-pdb-proc-menu-paths",
+ args);
+ gimp_value_array_unref (args);
+
+ *num_menu_paths = 0;
+
+ if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
+ {
+ *num_menu_paths = GIMP_VALUES_GET_INT (return_vals, 1);
+ menu_paths = GIMP_VALUES_DUP_STRING_ARRAY (return_vals, 2);
+ }
+
+ gimp_value_array_unref (return_vals);
+
+ return menu_paths;
+}
+
/**
* _gimp_pdb_proc_documentation:
* @procedure_name: The procedure name.
diff --git a/libgimp/gimppdb_pdb.h b/libgimp/gimppdb_pdb.h
index f105004aa4..c42de31c2e 100644
--- a/libgimp/gimppdb_pdb.h
+++ b/libgimp/gimppdb_pdb.h
@@ -48,6 +48,10 @@ G_GNUC_INTERNAL gboolean _gimp_pdb_proc_info (const gchar *pro
GimpPDBProcType *proc_type,
gint *num_args,
gint *num_values);
+G_GNUC_INTERNAL gchar* _gimp_pdb_proc_image_types (const gchar *procedure_name);
+G_GNUC_INTERNAL gchar* _gimp_pdb_proc_menu_label (const gchar *procedure_name);
+G_GNUC_INTERNAL gchar** _gimp_pdb_proc_menu_paths (const gchar *procedure_name,
+ gint *num_menu_paths);
G_GNUC_INTERNAL gboolean _gimp_pdb_proc_documentation (const gchar *procedure_name,
gchar **blurb,
gchar **help,
diff --git a/pdb/groups/pdb.pdb b/pdb/groups/pdb.pdb
index 0bdd2a2c68..83261cdc78 100644
--- a/pdb/groups/pdb.pdb
+++ b/pdb/groups/pdb.pdb
@@ -246,6 +246,161 @@ CODE
);
}
+sub pdb_proc_image_types {
+ $blurb = <<'BLURB';
+Queries the procedural database for the image types supported by the
+specified procedure.
+BLURB
+
+ $help = <<'HELP';
+This procedure returns the image types supported by the specified procedure.
+HELP
+
+ &mitch_pdb_misc('2019', '3.0');
+
+ $lib_private = 1;
+
+ @inargs = (
+ { name => 'procedure_name', type => 'string', non_empty => 1,
+ desc => 'The procedure name' }
+ );
+
+ @outargs = (
+ { name => 'image_types', type => 'string',
+ desc => 'The image types' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ if (gimp_pdb_is_canonical_procedure (procedure_name, error))
+ {
+ GimpProcedure *proc = lookup_procedure (gimp->pdb, procedure_name,
+ error);
+
+ if (GIMP_IS_PLUG_IN_PROCEDURE (proc))
+ {
+ image_types = g_strdup (GIMP_PLUG_IN_PROCEDURE (proc)->image_types);
+ }
+ else
+ success = FALSE;
+ }
+ else
+ success = FALSE;
+}
+CODE
+ );
+}
+
+sub pdb_proc_menu_label {
+ $blurb = <<'BLURB';
+Queries the procedural database for the procedure's menu label.
+BLURB
+
+ $help = <<'HELP';
+This procedure returns the menu label of the specified procedure.
+HELP
+
+ &mitch_pdb_misc('2019', '3.0');
+
+ $lib_private = 1;
+
+ @inargs = (
+ { name => 'procedure_name', type => 'string', non_empty => 1,
+ desc => 'The procedure name' }
+ );
+
+ @outargs = (
+ { name => 'menu_label', type => 'string',
+ desc => 'The menu_label' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ if (gimp_pdb_is_canonical_procedure (procedure_name, error))
+ {
+ GimpProcedure *proc = lookup_procedure (gimp->pdb, procedure_name,
+ error);
+
+ if (GIMP_IS_PLUG_IN_PROCEDURE (proc))
+ {
+ menu_label = g_strdup (GIMP_PLUG_IN_PROCEDURE (proc)->menu_label);
+ }
+ else
+ success = FALSE;
+ }
+ else
+ success = FALSE;
+}
+CODE
+ );
+}
+
+sub pdb_proc_menu_paths {
+ $blurb = <<'BLURB';
+Queries the procedural database for the procedure's menu paths.
+BLURB
+
+ $help = <<'HELP';
+This procedure returns the menu paths of the specified procedure.
+HELP
+
+ &mitch_pdb_misc('2019', '3.0');
+
+ $lib_private = 1;
+
+ @inargs = (
+ { name => 'procedure_name', type => 'string', non_empty => 1,
+ desc => 'The procedure name' }
+ );
+
+ @outargs = (
+ { name => 'menu_paths', type => 'stringarray',
+ desc => 'The menu paths of the plug-in',
+ array => { name => 'num_menu_paths',
+ desc => 'The number of menu paths' } },
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ if (gimp_pdb_is_canonical_procedure (procedure_name, error))
+ {
+ GimpProcedure *proc = lookup_procedure (gimp->pdb, procedure_name,
+ error);
+
+ if (GIMP_IS_PLUG_IN_PROCEDURE (proc))
+ {
+ GimpPlugInProcedure *plug_in_proc = GIMP_PLUG_IN_PROCEDURE (proc);
+
+ num_menu_paths = g_list_length (plug_in_proc->menu_paths);
+
+ if (num_menu_paths > 0)
+ {
+ GList *list;
+ gint i;
+
+ menu_paths = g_new0 (gchar *, num_menu_paths + 1);
+
+ for (list = plug_in_proc->menu_paths, i = 0;
+ list;
+ list = g_list_next (list), i++)
+ {
+ menu_paths[i] = g_strdup (list->data);
+ }
+ }
+ }
+ else
+ success = FALSE;
+ }
+ else
+ success = FALSE;
+}
+CODE
+ );
+}
+
sub pdb_proc_documentation {
$blurb = <<'BLURB';
Queries the procedural database for documentation on the specified procedure.
@@ -604,6 +759,7 @@ CODE
"core/gimp.h"
"core/gimpparamspecs-desc.h"
"plug-in/gimppluginmanager-data.h"
+ "plug-in/gimppluginprocedure.h"
"gimppdb-query.h"
"gimppdb-utils.h"
"gimppdberror.h"
@@ -615,6 +771,9 @@ CODE
pdb_query
pdb_proc_exists
pdb_proc_info
+ pdb_proc_image_types
+ pdb_proc_menu_label
+ pdb_proc_menu_paths
pdb_proc_documentation
pdb_proc_attribution
pdb_proc_argument
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]