gimp/libgimp/gimppdb.c
Michael Natterer 450a9f90b4 libgimp: add a GimpPDB class and subclass GimpProcedure as GimpPDBProcedure
The idea is that we already have a GimpProcedure object in libgimp
which has name, help, blurb, arguments, return values and everything,
so we really don't need a parallel API to query PDB procedures for
their properties.

- make run() a virtual function of GimpProcedure
- move GIMP_PDB_ERROR to GimpPDB
- GimpPDBProcedure is a trivial subblass which populates
  GimpProcedure's members by querying the PDB.
- make "plug-in", "procedure-type" and "name" construct-only
  properties of GimpProcedure.

This is all work in progress.
2019-08-06 12:22:23 +02:00

121 lines
2.7 KiB
C

/* 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"
#include "gimppdb-private.h"
#include "gimppdbprocedure.h"
struct _GimpPDBPrivate
{
GimpPlugIn *plug_in;
GHashTable *procedures;
};
static void gimp_pdb_finalize (GObject *object);
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);
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);
}
static void
gimp_pdb_finalize (GObject *object)
{
GimpPDB *pdb = GIMP_PDB (object);
g_clear_object (&pdb->priv->plug_in);
g_clear_pointer (&pdb->priv->procedures, g_hash_table_unref);
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;
}
GimpProcedure *
gimp_pdb_lookup (GimpPDB *pdb,
const gchar *name)
{
GimpProcedure *procedure;
g_return_val_if_fail (GIMP_IS_PDB (pdb), NULL);
g_return_val_if_fail (name != NULL, NULL);
procedure = g_hash_table_lookup (pdb->priv->procedures, name);
if (! procedure)
{
procedure = _gimp_pdb_procedure_new (pdb, name);
if (procedure)
g_hash_table_insert (pdb->priv->procedures,
g_strdup (name), procedure);
}
return procedure;
}
GQuark
_gimp_pdb_error_quark (void)
{
return g_quark_from_static_string ("gimp-pdb-error-quark");
}