2019-08-06 18:17:27 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimppdb.c
|
|
|
|
* Copyright (C) 2019 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gimp.h"
|
2019-08-07 00:29:55 +08:00
|
|
|
|
|
|
|
#include "libgimpbase/gimpprotocol.h"
|
|
|
|
#include "libgimpbase/gimpwire.h"
|
|
|
|
|
|
|
|
#include "gimp-private.h"
|
|
|
|
#include "gimpgpparams.h"
|
2019-08-06 18:17:27 +08:00
|
|
|
#include "gimppdb-private.h"
|
2019-08-09 03:52:36 +08:00
|
|
|
#include "gimppdb_pdb.h"
|
2019-08-06 18:17:27 +08:00
|
|
|
#include "gimppdbprocedure.h"
|
2019-08-07 00:29:55 +08:00
|
|
|
#include "gimpplugin-private.h"
|
2019-08-06 18:17:27 +08:00
|
|
|
|
2019-08-11 22:41:58 +08:00
|
|
|
#include "libgimp-intl.h"
|
|
|
|
|
2019-08-06 18:17:27 +08:00
|
|
|
|
2019-08-06 18:50:08 +08:00
|
|
|
/**
|
2021-11-29 02:36:07 +08:00
|
|
|
* GimpPDB:
|
2019-08-06 18:50:08 +08:00
|
|
|
*
|
2021-11-29 02:36:07 +08:00
|
|
|
* Provides access to the Procedural DataBase (PDB).
|
|
|
|
*/
|
2019-08-06 18:50:08 +08:00
|
|
|
|
|
|
|
|
2019-08-06 18:17:27 +08:00
|
|
|
struct _GimpPDBPrivate
|
|
|
|
{
|
2019-09-09 17:16:39 +08:00
|
|
|
GimpPlugIn *plug_in;
|
2019-08-06 18:17:27 +08:00
|
|
|
|
2019-09-09 17:16:39 +08:00
|
|
|
GHashTable *procedures;
|
2019-08-11 22:41:58 +08:00
|
|
|
|
|
|
|
GimpPDBStatusType error_status;
|
|
|
|
gchar *error_message;
|
2019-08-06 18:17:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-09-09 17:16:39 +08:00
|
|
|
static void gimp_pdb_dispose (GObject *object);
|
2019-08-11 22:41:58 +08:00
|
|
|
static void gimp_pdb_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void gimp_pdb_set_error (GimpPDB *pdb,
|
|
|
|
GimpValueArray *return_values);
|
2019-08-06 18:17:27 +08:00
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GimpPDB, gimp_pdb, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
#define parent_class gimp_pdb_parent_class
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pdb_class_init (GimpPDBClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2019-09-09 17:16:39 +08:00
|
|
|
object_class->dispose = gimp_pdb_dispose;
|
2019-08-06 18:17:27 +08:00
|
|
|
object_class->finalize = gimp_pdb_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pdb_init (GimpPDB *pdb)
|
|
|
|
{
|
|
|
|
pdb->priv = gimp_pdb_get_instance_private (pdb);
|
|
|
|
|
|
|
|
pdb->priv->procedures = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
g_free, g_object_unref);
|
2019-08-11 22:41:58 +08:00
|
|
|
|
|
|
|
pdb->priv->error_status = GIMP_PDB_SUCCESS;
|
2019-08-06 18:17:27 +08:00
|
|
|
}
|
|
|
|
|
2019-09-09 17:16:39 +08:00
|
|
|
static void
|
|
|
|
gimp_pdb_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GimpPDB *pdb = GIMP_PDB (object);
|
|
|
|
|
|
|
|
g_clear_pointer (&pdb->priv->procedures, g_hash_table_unref);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2019-08-06 18:17:27 +08:00
|
|
|
static void
|
|
|
|
gimp_pdb_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpPDB *pdb = GIMP_PDB (object);
|
|
|
|
|
|
|
|
g_clear_object (&pdb->priv->plug_in);
|
2019-08-11 22:41:58 +08:00
|
|
|
g_clear_pointer (&pdb->priv->error_message, g_free);
|
2019-08-06 18:17:27 +08:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpPDB *
|
|
|
|
_gimp_pdb_new (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
GimpPDB *pdb;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL);
|
|
|
|
|
|
|
|
pdb = g_object_new (GIMP_TYPE_PDB, NULL);
|
|
|
|
|
|
|
|
pdb->priv->plug_in = g_object_ref (plug_in);
|
|
|
|
|
|
|
|
return pdb;
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpPlugIn *
|
|
|
|
_gimp_pdb_get_plug_in (GimpPDB *pdb)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
|
|
|
|
|
|
|
|
return pdb->priv->plug_in;
|
|
|
|
}
|
|
|
|
|
2019-08-07 00:29:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_pdb_procedure_exists:
|
2021-11-29 02:36:07 +08:00
|
|
|
* @pdb: A PDB instance.
|
2019-08-07 00:29:55 +08:00
|
|
|
* @procedure_name: A procedure name
|
|
|
|
*
|
|
|
|
* This function checks if a procedure exists in the procedural
|
|
|
|
* database.
|
|
|
|
*
|
|
|
|
* Return: %TRUE if the procedure exists, %FALSE otherwise.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_pdb_procedure_exists (GimpPDB *pdb,
|
|
|
|
const gchar *procedure_name)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), FALSE);
|
2019-08-18 18:43:37 +08:00
|
|
|
g_return_val_if_fail (gimp_is_canonical_identifier (procedure_name), FALSE);
|
2019-08-07 00:29:55 +08:00
|
|
|
|
|
|
|
return _gimp_pdb_proc_exists (procedure_name);
|
|
|
|
}
|
|
|
|
|
2019-08-08 06:34:16 +08:00
|
|
|
/**
|
|
|
|
* gimp_pdb_lookup_procedure:
|
|
|
|
* @pdb: A #GimpPDB instance.
|
|
|
|
* @procedure_name: A procedure name
|
|
|
|
*
|
2021-11-29 02:36:07 +08:00
|
|
|
* This function returns the [class@Procedure] which is registered
|
2019-08-08 06:34:16 +08:00
|
|
|
* with @procedure_name if it exists, or returns %NULL otherwise.
|
|
|
|
*
|
2021-11-29 02:36:07 +08:00
|
|
|
* The returned [class@Procedure] is owned by @pdb and must not be modified.
|
2019-08-08 06:34:16 +08:00
|
|
|
*
|
2021-11-29 02:36:07 +08:00
|
|
|
* Return: (nullable) (transfer none): A [class@Procedure], or %NULL.
|
2019-08-08 06:34:16 +08:00
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
2019-08-06 18:17:27 +08:00
|
|
|
GimpProcedure *
|
2019-08-07 00:29:55 +08:00
|
|
|
gimp_pdb_lookup_procedure (GimpPDB *pdb,
|
|
|
|
const gchar *procedure_name)
|
2019-08-06 18:17:27 +08:00
|
|
|
{
|
|
|
|
GimpProcedure *procedure;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
|
2019-08-18 18:43:37 +08:00
|
|
|
g_return_val_if_fail (gimp_is_canonical_identifier (procedure_name), NULL);
|
2019-08-06 18:17:27 +08:00
|
|
|
|
2019-08-07 00:29:55 +08:00
|
|
|
procedure = g_hash_table_lookup (pdb->priv->procedures, procedure_name);
|
2019-08-06 18:17:27 +08:00
|
|
|
|
|
|
|
if (! procedure)
|
|
|
|
{
|
2019-08-07 00:29:55 +08:00
|
|
|
procedure = _gimp_pdb_procedure_new (pdb, procedure_name);
|
2019-08-06 18:17:27 +08:00
|
|
|
|
|
|
|
if (procedure)
|
|
|
|
g_hash_table_insert (pdb->priv->procedures,
|
2019-08-07 00:29:55 +08:00
|
|
|
g_strdup (procedure_name), procedure);
|
2019-08-06 18:17:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return procedure;
|
|
|
|
}
|
|
|
|
|
2019-08-08 06:34:16 +08:00
|
|
|
/**
|
gimppdb: Allow more easy bindable API
Plug-ins that work from different bindings probably want to use their
own list-type to specify arguments, rather than working with a more
cumbersome `GimpValueArray`.
This new API should make it less verbose. For example:
```
args = Gimp.ValueArray.new(5)
args.insert(0, GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE))
args.insert(1, GObject.Value(Gimp.Image, image))
args.insert(2, GObject.Value(Gimp.Drawable, mask))
args.insert(3, GObject.Value(GObject.TYPE_INT, int(time.time())))
args.insert(4, GObject.Value(GObject.TYPE_DOUBLE, turbulence))
Gimp.get_pdb().run_procedure('plug-in-plasma', args)
```
becomes
```
Gimp.get_pdb().run_procedure('plug-in-plasma', [
GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
GObject.Value(Gimp.Image, image),
GObject.Value(Gimp.Drawable, mask),
GObject.Value(GObject.TYPE_INT, int(time.time())),
GObject.Value(GObject.TYPE_DOUBLE, turbulence),
])
```
2020-05-20 00:43:43 +08:00
|
|
|
* gimp_pdb_run_procedure: (skip)
|
2019-08-08 06:34:16 +08:00
|
|
|
* @pdb: the #GimpPDB object.
|
|
|
|
* @procedure_name: the procedure registered name.
|
|
|
|
* @first_type: the #GType of the first argument, or #G_TYPE_NONE.
|
|
|
|
* @...: the call arguments.
|
|
|
|
*
|
|
|
|
* Runs the procedure named @procedure_name with arguments given as
|
|
|
|
* list of (#GType, value) pairs, terminated by #G_TYPE_NONE.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the return values for the procedure call.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2019-08-07 00:29:55 +08:00
|
|
|
GimpValueArray *
|
2019-08-07 01:10:04 +08:00
|
|
|
gimp_pdb_run_procedure (GimpPDB *pdb,
|
|
|
|
const gchar *procedure_name,
|
|
|
|
GType first_type,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GimpValueArray *return_values;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
|
2019-08-18 18:43:37 +08:00
|
|
|
g_return_val_if_fail (gimp_is_canonical_identifier (procedure_name), NULL);
|
2019-08-07 01:10:04 +08:00
|
|
|
|
|
|
|
va_start (args, first_type);
|
|
|
|
|
|
|
|
return_values = gimp_pdb_run_procedure_valist (pdb, procedure_name,
|
|
|
|
first_type, args);
|
|
|
|
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
return return_values;
|
|
|
|
}
|
|
|
|
|
2019-08-08 06:34:16 +08:00
|
|
|
/**
|
gimppdb: Allow more easy bindable API
Plug-ins that work from different bindings probably want to use their
own list-type to specify arguments, rather than working with a more
cumbersome `GimpValueArray`.
This new API should make it less verbose. For example:
```
args = Gimp.ValueArray.new(5)
args.insert(0, GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE))
args.insert(1, GObject.Value(Gimp.Image, image))
args.insert(2, GObject.Value(Gimp.Drawable, mask))
args.insert(3, GObject.Value(GObject.TYPE_INT, int(time.time())))
args.insert(4, GObject.Value(GObject.TYPE_DOUBLE, turbulence))
Gimp.get_pdb().run_procedure('plug-in-plasma', args)
```
becomes
```
Gimp.get_pdb().run_procedure('plug-in-plasma', [
GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
GObject.Value(Gimp.Image, image),
GObject.Value(Gimp.Drawable, mask),
GObject.Value(GObject.TYPE_INT, int(time.time())),
GObject.Value(GObject.TYPE_DOUBLE, turbulence),
])
```
2020-05-20 00:43:43 +08:00
|
|
|
* gimp_pdb_run_procedure_valist: (skip)
|
2019-08-08 06:34:16 +08:00
|
|
|
* @pdb: the #GimpPDB object.
|
|
|
|
* @procedure_name: the procedure registered name.
|
|
|
|
* @first_type: the #GType of the first argument, or #G_TYPE_NONE.
|
|
|
|
* @args: the call arguments.
|
|
|
|
*
|
|
|
|
* Runs the procedure named @procedure_name with @args given in the
|
2021-11-29 02:36:07 +08:00
|
|
|
* order as passed to [method@PDB.run_procedure].
|
2019-08-08 06:34:16 +08:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): the return values for the procedure call.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
2019-08-07 01:10:04 +08:00
|
|
|
GimpValueArray *
|
|
|
|
gimp_pdb_run_procedure_valist (GimpPDB *pdb,
|
|
|
|
const gchar *procedure_name,
|
|
|
|
GType first_type,
|
|
|
|
va_list args)
|
|
|
|
{
|
|
|
|
GimpValueArray *arguments;
|
|
|
|
GimpValueArray *return_values;
|
2019-08-08 19:27:34 +08:00
|
|
|
gchar *error_msg = NULL;
|
2019-08-07 01:10:04 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
|
2019-08-18 18:43:37 +08:00
|
|
|
g_return_val_if_fail (gimp_is_canonical_identifier (procedure_name), NULL);
|
2019-08-07 01:10:04 +08:00
|
|
|
|
2019-08-08 19:27:34 +08:00
|
|
|
arguments = gimp_value_array_new_from_types_valist (&error_msg,
|
|
|
|
first_type,
|
|
|
|
args);
|
2019-08-07 01:10:04 +08:00
|
|
|
|
2019-08-08 19:27:34 +08:00
|
|
|
if (! arguments)
|
2019-08-07 01:10:04 +08:00
|
|
|
{
|
2019-08-08 19:27:34 +08:00
|
|
|
GError *error = g_error_new_literal (GIMP_PDB_ERROR,
|
|
|
|
GIMP_PDB_ERROR_INTERNAL_ERROR,
|
|
|
|
error_msg);
|
|
|
|
g_printerr ("%s: %s", G_STRFUNC, error_msg);
|
|
|
|
g_free (error_msg);
|
|
|
|
|
|
|
|
return gimp_procedure_new_return_values (NULL,
|
|
|
|
GIMP_PDB_CALLING_ERROR,
|
|
|
|
error);
|
2019-08-07 01:10:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return_values = gimp_pdb_run_procedure_array (pdb, procedure_name,
|
|
|
|
arguments);
|
|
|
|
gimp_value_array_unref (arguments);
|
|
|
|
|
|
|
|
return return_values;
|
|
|
|
}
|
|
|
|
|
2019-08-07 01:29:00 +08:00
|
|
|
/**
|
gimppdb: Allow more easy bindable API
Plug-ins that work from different bindings probably want to use their
own list-type to specify arguments, rather than working with a more
cumbersome `GimpValueArray`.
This new API should make it less verbose. For example:
```
args = Gimp.ValueArray.new(5)
args.insert(0, GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE))
args.insert(1, GObject.Value(Gimp.Image, image))
args.insert(2, GObject.Value(Gimp.Drawable, mask))
args.insert(3, GObject.Value(GObject.TYPE_INT, int(time.time())))
args.insert(4, GObject.Value(GObject.TYPE_DOUBLE, turbulence))
Gimp.get_pdb().run_procedure('plug-in-plasma', args)
```
becomes
```
Gimp.get_pdb().run_procedure('plug-in-plasma', [
GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
GObject.Value(Gimp.Image, image),
GObject.Value(Gimp.Drawable, mask),
GObject.Value(GObject.TYPE_INT, int(time.time())),
GObject.Value(GObject.TYPE_DOUBLE, turbulence),
])
```
2020-05-20 00:43:43 +08:00
|
|
|
* gimp_pdb_run_procedure_argv: (rename-to gimp_pdb_run_procedure)
|
2021-04-09 05:14:02 +08:00
|
|
|
* @pdb: the #GimpPDB object.
|
|
|
|
* @procedure_name: the registered name to call.
|
|
|
|
* @arguments: (array length=n_arguments) (nullable): the call arguments or %NULL.
|
|
|
|
* @n_arguments: the number of arguments.
|
gimppdb: Allow more easy bindable API
Plug-ins that work from different bindings probably want to use their
own list-type to specify arguments, rather than working with a more
cumbersome `GimpValueArray`.
This new API should make it less verbose. For example:
```
args = Gimp.ValueArray.new(5)
args.insert(0, GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE))
args.insert(1, GObject.Value(Gimp.Image, image))
args.insert(2, GObject.Value(Gimp.Drawable, mask))
args.insert(3, GObject.Value(GObject.TYPE_INT, int(time.time())))
args.insert(4, GObject.Value(GObject.TYPE_DOUBLE, turbulence))
Gimp.get_pdb().run_procedure('plug-in-plasma', args)
```
becomes
```
Gimp.get_pdb().run_procedure('plug-in-plasma', [
GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
GObject.Value(Gimp.Image, image),
GObject.Value(Gimp.Drawable, mask),
GObject.Value(GObject.TYPE_INT, int(time.time())),
GObject.Value(GObject.TYPE_DOUBLE, turbulence),
])
```
2020-05-20 00:43:43 +08:00
|
|
|
*
|
|
|
|
* Runs the procedure named @procedure_name with @arguments.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the return values for the procedure call.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
GimpValueArray *
|
|
|
|
gimp_pdb_run_procedure_argv (GimpPDB *pdb,
|
|
|
|
const gchar *procedure_name,
|
|
|
|
const GValue *arguments,
|
|
|
|
gint n_arguments)
|
|
|
|
{
|
|
|
|
GimpValueArray *args;
|
|
|
|
GimpValueArray *return_values;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
|
|
|
|
g_return_val_if_fail (gimp_is_canonical_identifier (procedure_name), NULL);
|
2021-04-09 05:14:02 +08:00
|
|
|
/* Not require arguments != NULL.
|
|
|
|
* gimp_value_array_new_from_values(NULL, 0) will return empty GValueArray.
|
|
|
|
*/
|
gimppdb: Allow more easy bindable API
Plug-ins that work from different bindings probably want to use their
own list-type to specify arguments, rather than working with a more
cumbersome `GimpValueArray`.
This new API should make it less verbose. For example:
```
args = Gimp.ValueArray.new(5)
args.insert(0, GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE))
args.insert(1, GObject.Value(Gimp.Image, image))
args.insert(2, GObject.Value(Gimp.Drawable, mask))
args.insert(3, GObject.Value(GObject.TYPE_INT, int(time.time())))
args.insert(4, GObject.Value(GObject.TYPE_DOUBLE, turbulence))
Gimp.get_pdb().run_procedure('plug-in-plasma', args)
```
becomes
```
Gimp.get_pdb().run_procedure('plug-in-plasma', [
GObject.Value(Gimp.RunMode, Gimp.RunMode.NONINTERACTIVE),
GObject.Value(Gimp.Image, image),
GObject.Value(Gimp.Drawable, mask),
GObject.Value(GObject.TYPE_INT, int(time.time())),
GObject.Value(GObject.TYPE_DOUBLE, turbulence),
])
```
2020-05-20 00:43:43 +08:00
|
|
|
|
|
|
|
args = gimp_value_array_new_from_values (arguments, n_arguments);
|
|
|
|
return_values = gimp_pdb_run_procedure_array (pdb, procedure_name, args);
|
|
|
|
gimp_value_array_unref (args);
|
|
|
|
|
|
|
|
return return_values;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_pdb_run_procedure_array:
|
2019-08-07 01:29:00 +08:00
|
|
|
* @pdb: the #GimpPDB object.
|
|
|
|
* @procedure_name: the procedure registered name.
|
|
|
|
* @arguments: the call arguments.
|
|
|
|
*
|
2019-08-08 06:34:16 +08:00
|
|
|
* Runs the procedure named @procedure_name with @arguments.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the return values for the procedure call.
|
2019-08-07 01:29:00 +08:00
|
|
|
*
|
2019-08-08 06:34:16 +08:00
|
|
|
* Since: 3.0
|
2019-08-07 01:29:00 +08:00
|
|
|
*/
|
2019-08-07 01:10:04 +08:00
|
|
|
GimpValueArray *
|
2019-08-07 06:02:29 +08:00
|
|
|
gimp_pdb_run_procedure_array (GimpPDB *pdb,
|
|
|
|
const gchar *procedure_name,
|
|
|
|
const GimpValueArray *arguments)
|
2019-08-07 00:29:55 +08:00
|
|
|
{
|
|
|
|
GPProcRun proc_run;
|
|
|
|
GPProcReturn *proc_return;
|
|
|
|
GimpWireMessage msg;
|
|
|
|
GimpValueArray *return_values;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
|
2019-08-18 18:43:37 +08:00
|
|
|
g_return_val_if_fail (gimp_is_canonical_identifier (procedure_name), NULL);
|
2019-08-07 00:29:55 +08:00
|
|
|
g_return_val_if_fail (arguments != NULL, NULL);
|
|
|
|
|
2019-09-09 07:00:54 +08:00
|
|
|
proc_run.name = (gchar *) procedure_name;
|
|
|
|
proc_run.n_params = gimp_value_array_length (arguments);
|
|
|
|
proc_run.params = _gimp_value_array_to_gp_params (arguments, FALSE);
|
2019-08-07 00:29:55 +08:00
|
|
|
|
2019-08-07 03:28:15 +08:00
|
|
|
if (! gp_proc_run_write (_gimp_plug_in_get_write_channel (pdb->priv->plug_in),
|
|
|
|
&proc_run, pdb->priv->plug_in))
|
2019-08-07 00:29:55 +08:00
|
|
|
gimp_quit ();
|
|
|
|
|
2019-09-09 07:00:54 +08:00
|
|
|
_gimp_gp_params_free (proc_run.params, proc_run.n_params, FALSE);
|
2019-09-05 18:10:53 +08:00
|
|
|
|
2019-08-07 00:29:55 +08:00
|
|
|
_gimp_plug_in_read_expect_msg (pdb->priv->plug_in, &msg, GP_PROC_RETURN);
|
|
|
|
|
|
|
|
proc_return = msg.data;
|
|
|
|
|
|
|
|
return_values = _gimp_gp_params_to_value_array (NULL,
|
|
|
|
NULL, 0,
|
|
|
|
proc_return->params,
|
2019-09-09 07:00:54 +08:00
|
|
|
proc_return->n_params,
|
2019-09-06 02:17:22 +08:00
|
|
|
TRUE);
|
2019-08-07 00:29:55 +08:00
|
|
|
|
|
|
|
gimp_wire_destroy (&msg);
|
|
|
|
|
2019-08-11 22:41:58 +08:00
|
|
|
gimp_pdb_set_error (pdb, return_values);
|
2019-08-07 00:29:55 +08:00
|
|
|
|
|
|
|
return return_values;
|
|
|
|
}
|
|
|
|
|
libgimp: new gimp_pdb_run_procedure_config() function.
While we do have quite a few gimp_pdb_run_procedure*() functions now, I
always felt that one based on a config file was missing, even more as we
are getting further and further into using config objects in plug-ins.
In C, the gimp_pdb_run_procedure() function is without a doubt the
easiest one. But such variable arg functions are not available on
bindings, and having to deal with GValue and GimpValueArray is a real
pain.
Also using a config file has the very great advantage that we don't need
to care about order. For instance, if I need to set the 10th argument of
a PDB call (and leave the rest to default values), I don't have to set
all 9 previous arguments. I can set only this one if I want. This
advantage is useful also for C code by the way.
For the record, here is how you could load then export an image with the
"file-png-*" PDB procedures in Python:
> c = Gimp.get_pdb().lookup_procedure('file-png-load').create_config()
> c.set_property('file', Gio.file_new_for_path('/path/sample.png'))
> r = Gimp.get_pdb().run_procedure_config('file-png-load', c)
> d = Gimp.Display.new(r.index(1)) # Give it a display to work on it.
Now exporting:
> img = r.index(1)
> c = Gimp.get_pdb().lookup_procedure('file-png-save').create_config()
> c.set_property('image', img)
> c.set_property('file', Gio.file_new_for_path('/path/exported.png'))
> layers = img.get_layers()
> c.set_property('drawables', Gimp.ObjectArray.new(Gimp.Drawable, layers, False))
> c.set_property('num-drawables', len(layers))
> r = Gimp.get_pdb().run_procedure_config('file-png-save', c)
2022-02-12 00:44:26 +08:00
|
|
|
/**
|
|
|
|
* gimp_pdb_run_procedure_config:
|
|
|
|
* @pdb: the #GimpPDB object.
|
|
|
|
* @procedure_name: the registered name to call.
|
|
|
|
* @config: a config object obtained with gimp_procedure_create_config().
|
|
|
|
*
|
|
|
|
* Runs the procedure named @procedure_name with @config.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the return values for the procedure call.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
*/
|
|
|
|
GimpValueArray *
|
|
|
|
gimp_pdb_run_procedure_config (GimpPDB *pdb,
|
|
|
|
const gchar *procedure_name,
|
|
|
|
GimpProcedureConfig *config)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure;
|
|
|
|
GimpValueArray *args;
|
|
|
|
GimpValueArray *return_values;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
|
|
|
|
g_return_val_if_fail (gimp_is_canonical_identifier (procedure_name), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_PROCEDURE_CONFIG (config), NULL);
|
|
|
|
|
|
|
|
procedure = gimp_pdb_lookup_procedure (pdb, procedure_name);
|
|
|
|
|
|
|
|
g_return_val_if_fail (gimp_procedure_config_get_procedure (config) == procedure,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
args = gimp_procedure_new_arguments (procedure);
|
|
|
|
|
|
|
|
gimp_procedure_config_get_values (config, args);
|
|
|
|
return_values = gimp_pdb_run_procedure_array (pdb, procedure_name, args);
|
|
|
|
|
|
|
|
gimp_value_array_unref (args);
|
|
|
|
|
|
|
|
return return_values;
|
|
|
|
}
|
|
|
|
|
2019-08-07 06:19:38 +08:00
|
|
|
/**
|
|
|
|
* gimp_pdb_temp_procedure_name:
|
|
|
|
* @pdb: the #GimpPDB object.
|
|
|
|
*
|
|
|
|
* Generates a unique temporary PDB name.
|
|
|
|
*
|
|
|
|
* This function generates a temporary PDB entry name that is
|
|
|
|
* guaranteed to be unique.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): A unique temporary name for a temporary
|
|
|
|
* PDB entry. The returned value must be freed with
|
|
|
|
* g_free().
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
gchar *
|
|
|
|
gimp_pdb_temp_procedure_name (GimpPDB *pdb)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
|
|
|
|
|
|
|
|
return _gimp_pdb_temp_name ();
|
|
|
|
}
|
|
|
|
|
2019-08-08 07:14:35 +08:00
|
|
|
/**
|
|
|
|
* gimp_pdb_dump_to_file:
|
|
|
|
* @pdb: A #GimpPDB.
|
2019-09-22 01:02:40 +08:00
|
|
|
* @file: The dump file.
|
2019-08-08 07:14:35 +08:00
|
|
|
*
|
|
|
|
* Dumps the current contents of the procedural database
|
|
|
|
*
|
|
|
|
* This procedure dumps the contents of the procedural database to the
|
|
|
|
* specified @file. The file will contain all of the information
|
|
|
|
* provided for each registered procedure.
|
|
|
|
*
|
|
|
|
* Returns: TRUE on success.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_pdb_dump_to_file (GimpPDB *pdb,
|
|
|
|
GFile *file)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), FALSE);
|
2020-02-28 03:44:20 +08:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
2019-08-08 07:14:35 +08:00
|
|
|
|
2019-09-12 04:37:40 +08:00
|
|
|
return _gimp_pdb_dump (file);
|
2019-08-08 07:14:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_pdb_query_procedures:
|
|
|
|
* @pdb: A #GimpPDB.
|
|
|
|
* @name: The regex for procedure name.
|
|
|
|
* @blurb: The regex for procedure blurb.
|
|
|
|
* @help: The regex for procedure help.
|
|
|
|
* @help_id: The regex for procedure help-id.
|
|
|
|
* @authors: The regex for procedure authors.
|
|
|
|
* @copyright: The regex for procedure copyright.
|
|
|
|
* @date: The regex for procedure date.
|
|
|
|
* @proc_type: The regex for procedure type: { 'Internal GIMP procedure', 'GIMP Plug-in', 'GIMP Extension', 'Temporary Procedure' }.
|
|
|
|
*
|
|
|
|
* Queries the procedural database for its contents using regular
|
|
|
|
* expression matching.
|
|
|
|
*
|
|
|
|
* This function queries the contents of the procedural database. It
|
|
|
|
* is supplied with eight arguments matching procedures on
|
|
|
|
*
|
|
|
|
* { name, blurb, help, help-id, authors, copyright, date, procedure type}.
|
|
|
|
*
|
|
|
|
* This is accomplished using regular expression matching. For
|
|
|
|
* instance, to find all procedures with "jpeg" listed in the blurb,
|
|
|
|
* all seven arguments can be supplied as ".*", except for the second,
|
|
|
|
* which can be supplied as ".*jpeg.*". There are two return arguments
|
|
|
|
* for this procedure. The first is the number of procedures matching
|
|
|
|
* the query. The second is a concatenated list of procedure names
|
|
|
|
* corresponding to those matching the query. If no matching entries
|
|
|
|
* are found, then the returned string is NULL and the number of
|
|
|
|
* entries is 0.
|
|
|
|
*
|
2020-12-24 04:15:43 +08:00
|
|
|
* Returns: (array zero-terminated=1) (transfer full): The list
|
2019-08-08 07:14:35 +08:00
|
|
|
* of procedure names. Free with g_strfreev().
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
gchar **
|
|
|
|
gimp_pdb_query_procedures (GimpPDB *pdb,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *blurb,
|
|
|
|
const gchar *help,
|
|
|
|
const gchar *help_id,
|
|
|
|
const gchar *authors,
|
|
|
|
const gchar *copyright,
|
|
|
|
const gchar *date,
|
2020-12-24 04:15:43 +08:00
|
|
|
const gchar *proc_type)
|
2019-08-08 07:14:35 +08:00
|
|
|
{
|
|
|
|
gchar **matches;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
|
|
|
|
|
|
|
|
_gimp_pdb_query (name,
|
|
|
|
blurb, help, /* FIXME help_id */
|
|
|
|
authors, copyright, date,
|
|
|
|
proc_type,
|
|
|
|
&matches);
|
|
|
|
|
|
|
|
return matches;
|
|
|
|
}
|
|
|
|
|
2019-08-06 18:17:27 +08:00
|
|
|
GQuark
|
|
|
|
_gimp_pdb_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("gimp-pdb-error-quark");
|
|
|
|
}
|
2019-08-06 18:50:08 +08:00
|
|
|
|
|
|
|
|
2019-08-09 03:52:36 +08:00
|
|
|
/* Temporary API, to go away before 3.0 */
|
|
|
|
|
2019-08-11 22:41:58 +08:00
|
|
|
/**
|
|
|
|
* gimp_pdb_get_last_error:
|
|
|
|
* @pdb: a #GimpPDB.
|
|
|
|
*
|
|
|
|
* Retrieves the error message from the last procedure call.
|
|
|
|
*
|
|
|
|
* If a procedure call fails, then it might pass an error message with
|
|
|
|
* the return values. Plug-ins that are using the libgimp C wrappers
|
|
|
|
* don't access the procedure return values directly. Thus #GimpPDB
|
|
|
|
* stores the error message and makes it available with this
|
|
|
|
* function. The next procedure call unsets the error message again.
|
|
|
|
*
|
|
|
|
* The returned string is owned by @pdb and must not be freed or
|
|
|
|
* modified.
|
|
|
|
*
|
|
|
|
* Returns: the error message
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
const gchar *
|
|
|
|
gimp_pdb_get_last_error (GimpPDB *pdb)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
|
|
|
|
|
|
|
|
if (pdb->priv->error_message && strlen (pdb->priv->error_message))
|
|
|
|
return pdb->priv->error_message;
|
|
|
|
|
|
|
|
switch (pdb->priv->error_status)
|
|
|
|
{
|
|
|
|
case GIMP_PDB_SUCCESS:
|
|
|
|
/* procedure executed successfully */
|
|
|
|
return _("success");
|
|
|
|
|
|
|
|
case GIMP_PDB_EXECUTION_ERROR:
|
|
|
|
/* procedure execution failed */
|
|
|
|
return _("execution error");
|
|
|
|
|
|
|
|
case GIMP_PDB_CALLING_ERROR:
|
|
|
|
/* procedure called incorrectly */
|
|
|
|
return _("calling error");
|
|
|
|
|
|
|
|
case GIMP_PDB_CANCEL:
|
|
|
|
/* procedure execution cancelled */
|
|
|
|
return _("cancelled");
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "invalid return status";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_pdb_get_last_status:
|
|
|
|
* @pdb: a #GimpPDB.
|
|
|
|
*
|
|
|
|
* Retrieves the status from the last procedure call.
|
|
|
|
*
|
|
|
|
* Returns: the #GimpPDBStatusType.
|
|
|
|
*
|
|
|
|
* Since: 3.0
|
|
|
|
**/
|
|
|
|
GimpPDBStatusType
|
|
|
|
gimp_pdb_get_last_status (GimpPDB *pdb)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_PDB (pdb), GIMP_PDB_SUCCESS);
|
|
|
|
|
|
|
|
return pdb->priv->error_status;
|
|
|
|
}
|
|
|
|
|
2019-08-06 18:50:08 +08:00
|
|
|
/* Cruft API */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_pdb_get_data:
|
|
|
|
* @identifier: The identifier associated with data.
|
|
|
|
* @data: A byte array containing data.
|
|
|
|
*
|
|
|
|
* Returns data associated with the specified identifier.
|
|
|
|
*
|
|
|
|
* This procedure returns any data which may have been associated with
|
|
|
|
* the specified identifier. The data is copied into the given memory
|
|
|
|
* location.
|
|
|
|
*
|
|
|
|
* Returns: TRUE on success, FALSE if no data has been associated with
|
|
|
|
* the identifier
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gimp_pdb_get_data (const gchar *identifier,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gint size;
|
|
|
|
guint8 *hack;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
success = _gimp_pdb_get_data (identifier, &size, &hack);
|
|
|
|
|
|
|
|
if (hack)
|
|
|
|
{
|
|
|
|
memcpy (data, (gconstpointer) hack, size * sizeof (guint8));
|
|
|
|
g_free (hack);
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2019-08-07 00:29:55 +08:00
|
|
|
/**
|
|
|
|
* gimp_pdb_get_data_size:
|
|
|
|
* @identifier: The identifier associated with data.
|
|
|
|
*
|
|
|
|
* Returns size of data associated with the specified identifier.
|
|
|
|
*
|
|
|
|
* This procedure returns the size of any data which may have been
|
|
|
|
* associated with the specified identifier. If no data has been
|
|
|
|
* associated with the identifier, an error is returned.
|
|
|
|
*
|
|
|
|
* Returns: The number of bytes in the data.
|
|
|
|
**/
|
|
|
|
gint
|
|
|
|
gimp_pdb_get_data_size (const gchar *identifier)
|
|
|
|
{
|
|
|
|
return _gimp_pdb_get_data_size (identifier);
|
|
|
|
}
|
|
|
|
|
2019-08-06 18:50:08 +08:00
|
|
|
/**
|
|
|
|
* gimp_pdb_set_data:
|
|
|
|
* @identifier: The identifier associated with data.
|
|
|
|
* @data: A byte array containing data.
|
|
|
|
* @bytes: The number of bytes in the data
|
|
|
|
*
|
|
|
|
* Associates the specified identifier with the supplied data.
|
|
|
|
*
|
|
|
|
* This procedure associates the supplied data with the provided
|
|
|
|
* identifier. The data may be subsequently retrieved by a call to
|
|
|
|
* 'procedural-db-get-data'.
|
|
|
|
*
|
|
|
|
* Returns: TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gimp_pdb_set_data (const gchar *identifier,
|
|
|
|
gconstpointer data,
|
|
|
|
guint32 bytes)
|
|
|
|
{
|
|
|
|
return _gimp_pdb_set_data (identifier, bytes, data);
|
|
|
|
}
|
2019-08-11 22:41:58 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pdb_set_error (GimpPDB *pdb,
|
|
|
|
GimpValueArray *return_values)
|
|
|
|
{
|
|
|
|
g_clear_pointer (&pdb->priv->error_message, g_free);
|
|
|
|
pdb->priv->error_status = GIMP_PDB_SUCCESS;
|
|
|
|
|
|
|
|
if (gimp_value_array_length (return_values) > 0)
|
|
|
|
{
|
2019-08-20 07:21:32 +08:00
|
|
|
pdb->priv->error_status = GIMP_VALUES_GET_ENUM (return_values, 0);
|
2019-08-11 22:41:58 +08:00
|
|
|
|
|
|
|
switch (pdb->priv->error_status)
|
|
|
|
{
|
|
|
|
case GIMP_PDB_SUCCESS:
|
|
|
|
case GIMP_PDB_PASS_THROUGH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PDB_EXECUTION_ERROR:
|
|
|
|
case GIMP_PDB_CALLING_ERROR:
|
|
|
|
case GIMP_PDB_CANCEL:
|
|
|
|
if (gimp_value_array_length (return_values) > 1)
|
|
|
|
{
|
|
|
|
GValue *value = gimp_value_array_index (return_values, 1);
|
|
|
|
|
|
|
|
if (G_VALUE_HOLDS_STRING (value))
|
|
|
|
pdb->priv->error_message = g_value_dup_string (value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|