[gimp] pdb: add parasite API for items
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] pdb: add parasite API for items
- Date: Fri, 9 Jul 2010 08:19:48 +0000 (UTC)
commit d0c80bae1232169c6aaa1166d2c267f9e426d044
Author: Michael Natterer <mitch gimp org>
Date: Fri Jul 9 10:19:30 2010 +0200
pdb: add parasite API for items
app/pdb/internal-procs.c | 2 +-
app/pdb/parasite-cmds.c | 243 +++++++++++++++++++++++++++++++++++++++++
libgimp/gimpparasite_pdb.c | 152 +++++++++++++++++++++++++
libgimp/gimpparasite_pdb.h | 9 ++
tools/pdbgen/pdb/parasite.pdb | 112 +++++++++++++++++++
5 files changed, 517 insertions(+), 1 deletions(-)
---
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index fa1e7b9..6b91b85 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
#include "internal-procs.h"
-/* 617 procedures registered total */
+/* 621 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
diff --git a/app/pdb/parasite-cmds.c b/app/pdb/parasite-cmds.c
index 921eecf..ebf76ea 100644
--- a/app/pdb/parasite-cmds.c
+++ b/app/pdb/parasite-cmds.c
@@ -28,6 +28,7 @@
#include "core/gimp-parasites.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
+#include "core/gimpitem.h"
#include "core/gimpparamspecs.h"
#include "vectors/gimpvectors.h"
@@ -250,6 +251,121 @@ image_parasite_list_invoker (GimpProcedure *procedure,
}
static GValueArray *
+item_parasite_find_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GValueArray *return_vals;
+ GimpItem *item;
+ const gchar *name;
+ GimpParasite *parasite = NULL;
+
+ item = gimp_value_get_item (&args->values[0], gimp);
+ name = g_value_get_string (&args->values[1]);
+
+ if (success)
+ {
+ parasite = gimp_parasite_copy (gimp_item_parasite_find (item, name));
+
+ if (! parasite)
+ success = FALSE;
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ g_value_take_boxed (&return_vals->values[1], parasite);
+
+ return return_vals;
+}
+
+static GValueArray *
+item_parasite_attach_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpItem *item;
+ const GimpParasite *parasite;
+
+ item = gimp_value_get_item (&args->values[0], gimp);
+ parasite = g_value_get_boxed (&args->values[1]);
+
+ if (success)
+ {
+ gimp_item_parasite_attach (item, parasite);
+ }
+
+ return gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+}
+
+static GValueArray *
+item_parasite_detach_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GimpItem *item;
+ const gchar *name;
+
+ item = gimp_value_get_item (&args->values[0], gimp);
+ name = g_value_get_string (&args->values[1]);
+
+ if (success)
+ {
+ gimp_item_parasite_detach (item, name);
+ }
+
+ return gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+}
+
+static GValueArray *
+item_parasite_list_invoker (GimpProcedure *procedure,
+ Gimp *gimp,
+ GimpContext *context,
+ GimpProgress *progress,
+ const GValueArray *args,
+ GError **error)
+{
+ gboolean success = TRUE;
+ GValueArray *return_vals;
+ GimpItem *item;
+ gint32 num_parasites = 0;
+ gchar **parasites = NULL;
+
+ item = gimp_value_get_item (&args->values[0], gimp);
+
+ if (success)
+ {
+ parasites = gimp_item_parasite_list (item, &num_parasites);
+ }
+
+ return_vals = gimp_procedure_get_return_values (procedure, success,
+ error ? *error : NULL);
+
+ if (success)
+ {
+ g_value_set_int (&return_vals->values[1], num_parasites);
+ gimp_value_take_stringarray (&return_vals->values[2], parasites, num_parasites);
+ }
+
+ return return_vals;
+}
+
+static GValueArray *
drawable_parasite_find_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
@@ -717,6 +833,133 @@ register_parasite_procs (GimpPDB *pdb)
g_object_unref (procedure);
/*
+ * gimp-item-parasite-find
+ */
+ procedure = gimp_procedure_new (item_parasite_find_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-item-parasite-find");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-item-parasite-find",
+ "Look up a parasite in an item",
+ "Finds and returns the parasite that is attached to an item.",
+ "Jay Cox",
+ "Jay Cox",
+ "1998",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_item_id ("item",
+ "item",
+ "The item",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_string ("name",
+ "name",
+ "The name of the parasite to find",
+ FALSE, FALSE, FALSE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_parasite ("parasite",
+ "parasite",
+ "The found parasite",
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-item-parasite-attach
+ */
+ procedure = gimp_procedure_new (item_parasite_attach_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-item-parasite-attach");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-item-parasite-attach",
+ "Add a parasite to an item.",
+ "This procedure attaches a parasite to an item. It has no return values.",
+ "Jay Cox",
+ "Jay Cox",
+ "1998",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_item_id ("item",
+ "item",
+ "The item",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_parasite ("parasite",
+ "parasite",
+ "The parasite to attach to the item",
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-item-parasite-detach
+ */
+ procedure = gimp_procedure_new (item_parasite_detach_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-item-parasite-detach");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-item-parasite-detach",
+ "Removes a parasite from an item.",
+ "This procedure detaches a parasite from an item. It has no return values.",
+ "Jay Cox",
+ "Jay Cox",
+ "1998",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_item_id ("item",
+ "item",
+ "The item",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_string ("name",
+ "name",
+ "The name of the parasite to detach from the item.",
+ FALSE, FALSE, FALSE,
+ NULL,
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
+ * gimp-item-parasite-list
+ */
+ procedure = gimp_procedure_new (item_parasite_list_invoker);
+ gimp_object_set_static_name (GIMP_OBJECT (procedure),
+ "gimp-item-parasite-list");
+ gimp_procedure_set_static_strings (procedure,
+ "gimp-item-parasite-list",
+ "List all parasites.",
+ "Returns a list of all parasites currently attached the an item.",
+ "Marc Lehmann",
+ "Marc Lehmann",
+ "1999",
+ NULL);
+ gimp_procedure_add_argument (procedure,
+ gimp_param_spec_item_id ("item",
+ "item",
+ "The item",
+ pdb->gimp, FALSE,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_int32 ("num-parasites",
+ "num parasites",
+ "The number of attached parasites",
+ 0, G_MAXINT32, 0,
+ GIMP_PARAM_READWRITE));
+ gimp_procedure_add_return_value (procedure,
+ gimp_param_spec_string_array ("parasites",
+ "parasites",
+ "The names of currently attached parasites",
+ GIMP_PARAM_READWRITE));
+ gimp_pdb_register_procedure (pdb, procedure);
+ g_object_unref (procedure);
+
+ /*
* gimp-drawable-parasite-find
*/
procedure = gimp_procedure_new (drawable_parasite_find_invoker);
diff --git a/libgimp/gimpparasite_pdb.c b/libgimp/gimpparasite_pdb.c
index 1355c73..9711f4d 100644
--- a/libgimp/gimpparasite_pdb.c
+++ b/libgimp/gimpparasite_pdb.c
@@ -311,6 +311,158 @@ gimp_image_parasite_list (gint32 image_ID,
}
/**
+ * gimp_item_parasite_find:
+ * @item_ID: The item.
+ * @name: The name of the parasite to find.
+ *
+ * Look up a parasite in an item
+ *
+ * Finds and returns the parasite that is attached to an item.
+ *
+ * Returns: The found parasite.
+ *
+ * Since: GIMP 2.8
+ */
+GimpParasite *
+gimp_item_parasite_find (gint32 item_ID,
+ const gchar *name)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ GimpParasite *parasite = NULL;
+
+ return_vals = gimp_run_procedure ("gimp-item-parasite-find",
+ &nreturn_vals,
+ GIMP_PDB_ITEM, item_ID,
+ GIMP_PDB_STRING, name,
+ GIMP_PDB_END);
+
+ if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+ parasite = gimp_parasite_copy (&return_vals[1].data.d_parasite);
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return parasite;
+}
+
+/**
+ * gimp_item_parasite_attach:
+ * @item_ID: The item.
+ * @parasite: The parasite to attach to the item.
+ *
+ * Add a parasite to an item.
+ *
+ * This procedure attaches a parasite to an item. It has no return
+ * values.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: GIMP 2.8
+ */
+gboolean
+gimp_item_parasite_attach (gint32 item_ID,
+ const GimpParasite *parasite)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gboolean success = TRUE;
+
+ return_vals = gimp_run_procedure ("gimp-item-parasite-attach",
+ &nreturn_vals,
+ GIMP_PDB_ITEM, item_ID,
+ GIMP_PDB_PARASITE, parasite,
+ GIMP_PDB_END);
+
+ success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return success;
+}
+
+/**
+ * gimp_item_parasite_detach:
+ * @item_ID: The item.
+ * @name: The name of the parasite to detach from the item.
+ *
+ * Removes a parasite from an item.
+ *
+ * This procedure detaches a parasite from an item. It has no return
+ * values.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: GIMP 2.8
+ */
+gboolean
+gimp_item_parasite_detach (gint32 item_ID,
+ const gchar *name)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gboolean success = TRUE;
+
+ return_vals = gimp_run_procedure ("gimp-item-parasite-detach",
+ &nreturn_vals,
+ GIMP_PDB_ITEM, item_ID,
+ GIMP_PDB_STRING, name,
+ GIMP_PDB_END);
+
+ success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return success;
+}
+
+/**
+ * gimp_item_parasite_list:
+ * @item_ID: The item.
+ * @num_parasites: The number of attached parasites.
+ * @parasites: The names of currently attached parasites.
+ *
+ * List all parasites.
+ *
+ * Returns a list of all parasites currently attached the an item.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: GIMP 2.8
+ */
+gboolean
+gimp_item_parasite_list (gint32 item_ID,
+ gint *num_parasites,
+ gchar ***parasites)
+{
+ GimpParam *return_vals;
+ gint nreturn_vals;
+ gboolean success = TRUE;
+ gint i;
+
+ return_vals = gimp_run_procedure ("gimp-item-parasite-list",
+ &nreturn_vals,
+ GIMP_PDB_ITEM, item_ID,
+ GIMP_PDB_END);
+
+ *num_parasites = 0;
+ *parasites = NULL;
+
+ success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+ if (success)
+ {
+ *num_parasites = return_vals[1].data.d_int32;
+ *parasites = g_new (gchar *, *num_parasites);
+ for (i = 0; i < *num_parasites; i++)
+ (*parasites)[i] = g_strdup (return_vals[2].data.d_stringarray[i]);
+ }
+
+ gimp_destroy_params (return_vals, nreturn_vals);
+
+ return success;
+}
+
+/**
* gimp_drawable_parasite_find:
* @drawable_ID: The drawable.
* @name: The name of the parasite to find.
diff --git a/libgimp/gimpparasite_pdb.h b/libgimp/gimpparasite_pdb.h
index 3647b60..07a826d 100644
--- a/libgimp/gimpparasite_pdb.h
+++ b/libgimp/gimpparasite_pdb.h
@@ -42,6 +42,15 @@ gboolean gimp_image_parasite_detach (gint32 image_ID,
gboolean gimp_image_parasite_list (gint32 image_ID,
gint *num_parasites,
gchar ***parasites);
+GimpParasite* gimp_item_parasite_find (gint32 item_ID,
+ const gchar *name);
+gboolean gimp_item_parasite_attach (gint32 item_ID,
+ const GimpParasite *parasite);
+gboolean gimp_item_parasite_detach (gint32 item_ID,
+ const gchar *name);
+gboolean gimp_item_parasite_list (gint32 item_ID,
+ gint *num_parasites,
+ gchar ***parasites);
GimpParasite* gimp_drawable_parasite_find (gint32 drawable_ID,
const gchar *name);
gboolean gimp_drawable_parasite_attach (gint32 drawable_ID,
diff --git a/tools/pdbgen/pdb/parasite.pdb b/tools/pdbgen/pdb/parasite.pdb
index 804077d..fd9408e 100644
--- a/tools/pdbgen/pdb/parasite.pdb
+++ b/tools/pdbgen/pdb/parasite.pdb
@@ -223,6 +223,115 @@ CODE
);
}
+sub item_parasite_find {
+ $blurb = 'Look up a parasite in an item';
+
+ $help = <<'HELP';
+Finds and returns the parasite that is attached to an item.
+HELP
+
+ &jay_pdb_misc('1998', '2.8');
+
+ @inargs = (
+ { name => 'item', type => 'item',
+ desc => 'The item' },
+ { name => 'name', type => 'string',
+ desc => 'The name of the parasite to find' }
+ );
+
+ @outargs = (
+ { name => 'parasite', type => 'parasite',
+ desc => 'The found parasite' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ parasite = gimp_parasite_copy (gimp_item_parasite_find (item, name));
+
+ if (! parasite)
+ success = FALSE;
+}
+CODE
+ );
+}
+
+sub item_parasite_attach {
+ $blurb = 'Add a parasite to an item.';
+
+ $help = <<'HELP';
+This procedure attaches a parasite to an item. It has no return values.
+HELP
+
+ &jay_pdb_misc('1998', '2.8');
+
+ @inargs = (
+ { name => 'item', type => 'item',
+ desc => 'The item' },
+ { name => 'parasite', type => 'parasite',
+ desc => 'The parasite to attach to the item' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ gimp_item_parasite_attach (item, parasite);
+}
+CODE
+ );
+}
+
+sub item_parasite_detach {
+ $blurb = 'Removes a parasite from an item.';
+
+ $help = <<'HELP';
+This procedure detaches a parasite from an item. It has no return values.
+HELP
+
+ &jay_pdb_misc('1998', '2.8');
+
+ @inargs = (
+ { name => 'item', type => 'item',
+ desc => 'The item' },
+ { name => 'name', type => 'string',
+ desc => 'The name of the parasite to detach from the item.' }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ gimp_item_parasite_detach (item, name);
+}
+CODE
+ );
+}
+
+sub item_parasite_list {
+ $blurb = 'List all parasites.';
+ $help = 'Returns a list of all parasites currently attached the an item.';
+
+ &marc_pdb_misc('1999', '2.8');
+
+ @inargs = (
+ { name => 'item', type => 'item',
+ desc => 'The item' }
+ );
+
+ @outargs = (
+ { name => 'parasites', type => 'stringarray', void_ret => 1,
+ desc => 'The names of currently attached parasites',
+ array => { desc => 'The number of attached parasites' } }
+ );
+
+ %invoke = (
+ code => <<'CODE'
+{
+ parasites = gimp_item_parasite_list (item, &num_parasites);
+}
+CODE
+ );
+}
+
sub drawable_parasite_find {
$blurb = 'Look up a parasite in a drawable';
@@ -454,6 +563,9 @@ CODE
image_parasite_find
image_parasite_attach image_parasite_detach
image_parasite_list
+ item_parasite_find
+ item_parasite_attach item_parasite_detach
+ item_parasite_list
drawable_parasite_find
drawable_parasite_attach drawable_parasite_detach
drawable_parasite_list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]