libgimp: change the return values of GimpPlugIn::init_procedures()

and ::query_procedures() to a GList* of strings.
This commit is contained in:
Michael Natterer 2019-08-02 19:10:13 +02:00
parent e3374e7d4e
commit a50069e176
5 changed files with 47 additions and 56 deletions

View File

@ -34,7 +34,7 @@
/* local function prototpes */
static void gimp_plug_in_register (GimpPlugIn *plug_in,
gboolean init);
GList *procedures);
static void gimp_plug_in_loop (GimpPlugIn *plug_in);
static void gimp_plug_in_proc_run (GimpPlugIn *plug_in,
GPProcRun *proc_run);
@ -52,10 +52,13 @@ _gimp_plug_in_query (GimpPlugIn *plug_in)
{
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
if (! GIMP_PLUG_IN_GET_CLASS (plug_in)->query_procedures)
return;
if (GIMP_PLUG_IN_GET_CLASS (plug_in)->query_procedures)
{
GList *procedures =
GIMP_PLUG_IN_GET_CLASS (plug_in)->query_procedures (plug_in);
gimp_plug_in_register (plug_in, FALSE);
gimp_plug_in_register (plug_in, procedures);
}
}
void
@ -63,10 +66,13 @@ _gimp_plug_in_init (GimpPlugIn *plug_in)
{
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
if (! GIMP_PLUG_IN_GET_CLASS (plug_in)->init_procedures)
return;
if (GIMP_PLUG_IN_GET_CLASS (plug_in)->init_procedures)
{
GList *procedures =
GIMP_PLUG_IN_GET_CLASS (plug_in)->init_procedures (plug_in);
gimp_plug_in_register (plug_in, TRUE);
gimp_plug_in_register (plug_in, procedures);
}
}
void
@ -103,22 +109,16 @@ _gimp_plug_in_extension_read (GIOChannel *channel,
static void
gimp_plug_in_register (GimpPlugIn *plug_in,
gboolean init)
GList *procedures)
{
gchar **procedures;
gchar **name;
GList *list;
GList *list;
if (init)
procedures = GIMP_PLUG_IN_GET_CLASS (plug_in)->init_procedures (plug_in);
else
procedures = GIMP_PLUG_IN_GET_CLASS (plug_in)->query_procedures (plug_in);
for (name = procedures; *name; name++)
for (list = procedures; list; list = g_list_next (list))
{
const gchar *name = list->data;
GimpProcedure *procedure;
procedure = gimp_plug_in_create_procedure (plug_in, *name);
procedure = gimp_plug_in_create_procedure (plug_in, name);
if (procedure)
{
_gimp_procedure_register (procedure);
@ -126,11 +126,11 @@ gimp_plug_in_register (GimpPlugIn *plug_in,
}
else
{
g_warning ("Plug-in failed to create procedure '%s'\n",
*name);
g_warning ("Plug-in failed to create procedure '%s'\n", name);
}
}
g_clear_pointer (&procedures, g_strfreev);
g_list_free_full (procedures, g_free);
if (plug_in->priv->translation_domain_name)
{

View File

@ -225,8 +225,8 @@ gimp_plug_in_add_menu_branch (GimpPlugIn *plug_in,
* %GIMP_EXTENSION procedures it implements is invoked.
*
* This function will only ever be called with names returned by
* implementations of GimpPlugIn::init_procedures() or
* GimpPlugIn::query_procedures().
* implementations of GimpPlugInClass::init_procedures() or
* GimpPlugInClass::query_procedures().
*
* Returns: (transfer full): The newly created #GimpProcedure.
**/

View File

@ -58,41 +58,40 @@ struct _GimpPlugInClass
* @plug_in: a #GimpPlugIn.
*
* This method can be overridden by all plug-ins to return a newly
* allocated array of allocated strings naming the procedures
* allocated GList of allocated strings naming the procedures
* registered by this plug-in.
* This array of strings must be NULL-terminated (i.e. freeable by
* g_strfreev()).
*
* See documentation of init_procedures() for differences.
* See documentation of GimpPlugInClass::init_procedures() for
* differences.
*
* Returns: (array zero-terminated=1) (transfer full):
* Returns: (element-type gchar*) (transfer full):
* the names of the procedures registered by @plug_in.
*/
gchar ** (* query_procedures) (GimpPlugIn *plug_in);
GList * (* query_procedures) (GimpPlugIn *plug_in);
/**
* GimpPlugInClass::init_procedures:
* @plug_in: a #GimpPlugIn.
*
* This method can be overridden by all plug-ins to return a newly
* allocated array of allocated strings naming procedures registered
* allocated #GList of allocated strings naming procedures registered
* by this plug-in.
* This array of strings must be NULL-terminated (i.e. freeable by
* g_strfreev()).
*
* It is different from query_procedures() in that init happens at every
* startup, whereas query happens only once in the life of a plug-in
* (right after installation or update). Hence init_procedures()
* typically returns procedures dependent to runtime conditions (such
* as the presence of a third-party tool), whereas query_procedures()
* would usually return unconditional and always available procedures.
* Most of the time, you only want to override query_procedures() and
* leave init_procedures() untouched.
* It is different from GimpPlugInClass::query_procedures() in that
* init happens at every startup, whereas query happens only once in
* the life of a plug-in (right after installation or update). Hence
* GimpPlugInClass::init_procedures() typically returns procedures
* dependent to runtime conditions (such as the presence of a
* third-party tool), whereas GimpPlugInClass::query_procedures()
* would usually return unconditional and always available
* procedures. Most of the time, you only want to override
* GimpPlugInClass::query_procedures() and leave
* GimpPlugInClass::init_procedures() untouched.
*
* Returns: (array zero-terminated=1) (transfer full):
* Returns: (element-type gchar*) (transfer full):
* the names of the procedures registered by @plug_in.
*/
gchar ** (* init_procedures) (GimpPlugIn *plug_in);
GList * (* init_procedures) (GimpPlugIn *plug_in);
/**
* GimpPlugInClass::create_procedure:

View File

@ -52,7 +52,7 @@ struct _GoatClass
GType goat_get_type (void) G_GNUC_CONST;
static gchar ** goat_query_procedures (GimpPlugIn *plug_in);
static GList * goat_query_procedures (GimpPlugIn *plug_in);
static GimpProcedure * goat_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
@ -80,14 +80,10 @@ goat_init (Goat *goat)
{
}
static gchar **
static GList *
goat_query_procedures (GimpPlugIn *plug_in)
{
gchar **procedures = g_new0 (gchar *, 2);
procedures[0] = g_strdup (PLUG_IN_PROC);
return procedures;
return g_list_append (NULL, g_strdup (PLUG_IN_PROC));
}
static GimpProcedure *

View File

@ -70,7 +70,7 @@ typedef struct
GType help_get_type (void) G_GNUC_CONST;
static gchar ** help_query_procedures (GimpPlugIn *plug_in);
static GList * help_query_procedures (GimpPlugIn *plug_in);
static GimpProcedure * help_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
@ -112,14 +112,10 @@ help_init (Help *help)
{
}
static gchar **
static GList *
help_query_procedures (GimpPlugIn *plug_in)
{
gchar **procedures = g_new0 (gchar *, 2);
procedures[0] = g_strdup (GIMP_HELP_EXT_PROC);
return procedures;
return g_list_append (NULL, g_strdup (GIMP_HELP_EXT_PROC));
}
static GimpProcedure *