libgimp: change GimpPlugIn and GimpProcedures so temp procs work

This commit is contained in:
Michael Natterer 2019-07-30 21:02:58 +02:00
parent 0a02855a59
commit d64c0ebd30
9 changed files with 88 additions and 37 deletions

View File

@ -2699,7 +2699,7 @@ gimp_temp_proc_run (GPProcRun *proc_run)
{ {
GimpProcedure *procedure; GimpProcedure *procedure;
procedure = gimp_plug_in_get_procedure (PLUG_IN, proc_run->name); procedure = gimp_plug_in_get_temp_procedure (PLUG_IN, proc_run->name);
if (procedure) if (procedure)
{ {

View File

@ -619,13 +619,13 @@ EXPORTS
gimp_patterns_set_popup gimp_patterns_set_popup
gimp_pencil gimp_pencil
gimp_plug_in_add_menu_branch gimp_plug_in_add_menu_branch
gimp_plug_in_add_procedure gimp_plug_in_add_temp_procedure
gimp_plug_in_create_procedure gimp_plug_in_create_procedure
gimp_plug_in_get_procedure gimp_plug_in_get_temp_procedure
gimp_plug_in_get_procedures gimp_plug_in_get_temp_procedures
gimp_plug_in_get_type gimp_plug_in_get_type
gimp_plug_in_info_set_callbacks gimp_plug_in_info_set_callbacks
gimp_plug_in_remove_procedure gimp_plug_in_remove_temp_procedure
gimp_plug_in_set_help_domain gimp_plug_in_set_help_domain
gimp_plug_in_set_translation_domain gimp_plug_in_set_translation_domain
gimp_plugin_domain_register gimp_plugin_domain_register
@ -660,6 +660,8 @@ EXPORTS
gimp_procedure_get_menu_label gimp_procedure_get_menu_label
gimp_procedure_get_menu_paths gimp_procedure_get_menu_paths
gimp_procedure_get_name gimp_procedure_get_name
gimp_procedure_get_plug_in
gimp_procedure_get_proc_type
gimp_procedure_get_return_values gimp_procedure_get_return_values
gimp_procedure_get_type gimp_procedure_get_type
gimp_procedure_new gimp_procedure_new

View File

@ -34,8 +34,6 @@ struct _GimpPlugInMenuBranch
struct _GimpPlugInPrivate struct _GimpPlugInPrivate
{ {
GList *procedures;
gchar *translation_domain_name; gchar *translation_domain_name;
GFile *translation_domain_path; GFile *translation_domain_path;
@ -43,6 +41,8 @@ struct _GimpPlugInPrivate
GFile *help_domain_uri; GFile *help_domain_uri;
GList *menu_branches; GList *menu_branches;
GList *temp_procedures;
}; };

View File

@ -24,6 +24,7 @@
#include "gimp.h" #include "gimp.h"
#include "gimpplugin-private.h" #include "gimpplugin-private.h"
#include "gimpprocedure-private.h"
/** /**
@ -66,10 +67,10 @@ gimp_plug_in_finalize (GObject *object)
GimpPlugIn *plug_in = GIMP_PLUG_IN (object); GimpPlugIn *plug_in = GIMP_PLUG_IN (object);
GList *list; GList *list;
if (plug_in->priv->procedures) if (plug_in->priv->temp_procedures)
{ {
g_list_free_full (plug_in->priv->procedures, g_object_unref); g_list_free_full (plug_in->priv->temp_procedures, g_object_unref);
plug_in->priv->procedures = NULL; plug_in->priv->temp_procedures = NULL;
} }
g_clear_pointer (&plug_in->priv->translation_domain_name, g_free); g_clear_pointer (&plug_in->priv->translation_domain_name, g_free);
@ -160,53 +161,57 @@ gimp_plug_in_create_procedure (GimpPlugIn *plug_in,
} }
void void
gimp_plug_in_add_procedure (GimpPlugIn *plug_in, gimp_plug_in_add_temp_procedure (GimpPlugIn *plug_in,
GimpProcedure *procedure) GimpProcedure *procedure)
{ {
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in)); g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
g_return_if_fail (GIMP_IS_PROCEDURE (procedure)); g_return_if_fail (GIMP_IS_PROCEDURE (procedure));
plug_in->priv->procedures = g_list_prepend (plug_in->priv->procedures, plug_in->priv->temp_procedures = g_list_prepend (plug_in->priv->temp_procedures,
g_object_ref (procedure)); g_object_ref (procedure));
_gimp_procedure_register (procedure);
} }
void void
gimp_plug_in_remove_procedure (GimpPlugIn *plug_in, gimp_plug_in_remove_temp_procedure (GimpPlugIn *plug_in,
const gchar *name) const gchar *name)
{ {
GimpProcedure *procedure; GimpProcedure *procedure;
g_return_if_fail (GIMP_IS_PLUG_IN (plug_in)); g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
g_return_if_fail (name != NULL); g_return_if_fail (name != NULL);
procedure = gimp_plug_in_get_procedure (plug_in, name); procedure = gimp_plug_in_get_temp_procedure (plug_in, name);
if (procedure) if (procedure)
{ {
plug_in->priv->procedures = g_list_remove (plug_in->priv->procedures, _gimp_procedure_unregister (procedure);
procedure);
plug_in->priv->temp_procedures = g_list_remove (plug_in->priv->temp_procedures,
procedure);
g_object_unref (procedure); g_object_unref (procedure);
} }
} }
GList * GList *
gimp_plug_in_get_procedures (GimpPlugIn *plug_in) gimp_plug_in_get_temp_procedures (GimpPlugIn *plug_in)
{ {
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL); g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL);
return plug_in->priv->procedures; return plug_in->priv->temp_procedures;
} }
GimpProcedure * GimpProcedure *
gimp_plug_in_get_procedure (GimpPlugIn *plug_in, gimp_plug_in_get_temp_procedure (GimpPlugIn *plug_in,
const gchar *name) const gchar *name)
{ {
GList *list; GList *list;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL); g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL);
g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (name != NULL, NULL);
for (list = plug_in->priv->procedures; list; list = g_list_next (list)) for (list = plug_in->priv->temp_procedures; list; list = g_list_next (list))
{ {
GimpProcedure *procedure = list->data; GimpProcedure *procedure = list->data;

View File

@ -90,13 +90,13 @@ void gimp_plug_in_add_menu_branch (GimpPlugIn *plug_in,
GimpProcedure * gimp_plug_in_create_procedure (GimpPlugIn *plug_in, GimpProcedure * gimp_plug_in_create_procedure (GimpPlugIn *plug_in,
const gchar *name); const gchar *name);
void gimp_plug_in_add_procedure (GimpPlugIn *plug_in, void gimp_plug_in_add_temp_procedure (GimpPlugIn *plug_in,
GimpProcedure *procedure); GimpProcedure *procedure);
void gimp_plug_in_remove_procedure (GimpPlugIn *plug_in, void gimp_plug_in_remove_temp_procedure (GimpPlugIn *plug_in,
const gchar *name); const gchar *name);
GList * gimp_plug_in_get_procedures (GimpPlugIn *plug_in); GList * gimp_plug_in_get_temp_procedures (GimpPlugIn *plug_in);
GimpProcedure * gimp_plug_in_get_procedure (GimpPlugIn *plug_in, GimpProcedure * gimp_plug_in_get_temp_procedure (GimpPlugIn *plug_in,
const gchar *name); const gchar *name);

View File

@ -34,13 +34,14 @@
#include "gimpprocedure-private.h" #include "gimpprocedure-private.h"
extern GIOChannel *_writechannel;
/* public functions */ /* public functions */
void void
_gimp_procedure_register (GimpProcedure *procedure) _gimp_procedure_register (GimpProcedure *procedure)
{ {
extern GIOChannel *_writechannel;
GParamSpec **args; GParamSpec **args;
GParamSpec **return_vals; GParamSpec **return_vals;
gint n_args; gint n_args;
@ -65,7 +66,7 @@ _gimp_procedure_register (GimpProcedure *procedure)
proc_install.date = (gchar *) gimp_procedure_get_date (procedure); proc_install.date = (gchar *) gimp_procedure_get_date (procedure);
proc_install.menu_label = (gchar *) gimp_procedure_get_menu_label (procedure); proc_install.menu_label = (gchar *) gimp_procedure_get_menu_label (procedure);
proc_install.image_types = (gchar *) gimp_procedure_get_image_types (procedure); proc_install.image_types = (gchar *) gimp_procedure_get_image_types (procedure);
proc_install.type = GIMP_PLUGIN; proc_install.type = gimp_procedure_get_proc_type (procedure);
proc_install.nparams = n_args; proc_install.nparams = n_args;
proc_install.nreturn_vals = n_return_vals; proc_install.nreturn_vals = n_return_vals;
proc_install.params = g_new0 (GPParamDef, n_args); proc_install.params = g_new0 (GPParamDef, n_args);
@ -103,3 +104,14 @@ _gimp_procedure_register (GimpProcedure *procedure)
list->data); list->data);
} }
} }
void
_gimp_procedure_unregister (GimpProcedure *procedure)
{
GPProcUninstall proc_uninstall;
proc_uninstall.name = (gchar *) gimp_procedure_get_name (procedure);
if (! gp_proc_uninstall_write (_writechannel, &proc_uninstall, NULL))
gimp_quit ();
}

View File

@ -24,7 +24,8 @@
G_BEGIN_DECLS G_BEGIN_DECLS
void _gimp_procedure_register (GimpProcedure *procedure); void _gimp_procedure_register (GimpProcedure *procedure);
void _gimp_procedure_unregister (GimpProcedure *procedure);
G_END_DECLS G_END_DECLS

View File

@ -51,6 +51,9 @@ gimp_pdb_error_quark (void)
struct _GimpProcedurePrivate struct _GimpProcedurePrivate
{ {
GimpPlugIn *plug_in; /* the procedure's plug-in */
GimpPDBProcType proc_type; /* procedure type */
gchar *name; /* procedure name */ gchar *name; /* procedure name */
gchar *menu_label; gchar *menu_label;
gchar *blurb; /* Short procedure description */ gchar *blurb; /* Short procedure description */
@ -113,6 +116,7 @@ gimp_procedure_finalize (GObject *object)
GimpProcedure *procedure = GIMP_PROCEDURE (object); GimpProcedure *procedure = GIMP_PROCEDURE (object);
gint i; gint i;
g_clear_object (&procedure->priv->plug_in);
g_clear_pointer (&procedure->priv->name, g_free); g_clear_pointer (&procedure->priv->name, g_free);
gimp_procedure_free_strings (procedure); gimp_procedure_free_strings (procedure);
@ -146,22 +150,44 @@ gimp_procedure_finalize (GObject *object)
/* public functions */ /* public functions */
GimpProcedure * GimpProcedure *
gimp_procedure_new (const gchar *name, gimp_procedure_new (GimpPlugIn *plug_in,
GimpRunFunc run_func) const gchar *name,
GimpPDBProcType proc_type,
GimpRunFunc run_func)
{ {
GimpProcedure *procedure; GimpProcedure *procedure;
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL);
g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (proc_type != GIMP_INTERNAL, NULL);
g_return_val_if_fail (run_func != NULL, NULL); g_return_val_if_fail (run_func != NULL, NULL);
procedure = g_object_new (GIMP_TYPE_PROCEDURE, NULL); procedure = g_object_new (GIMP_TYPE_PROCEDURE, NULL);
procedure->priv->name = g_strdup (name); procedure->priv->plug_in = g_object_ref (plug_in);
procedure->priv->run_func = run_func; procedure->priv->proc_type = proc_type;
procedure->priv->name = g_strdup (name);
procedure->priv->run_func = run_func;
return procedure; return procedure;
} }
GimpPlugIn *
gimp_procedure_get_plug_in (GimpProcedure *procedure)
{
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL);
return procedure->priv->plug_in;
}
GimpPDBProcType
gimp_procedure_get_proc_type (GimpProcedure *procedure)
{
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), GIMP_PLUGIN);
return procedure->priv->proc_type;
}
void void
gimp_procedure_set_strings (GimpProcedure *procedure, gimp_procedure_set_strings (GimpProcedure *procedure,
const gchar *menu_label, const gchar *menu_label,

View File

@ -58,9 +58,14 @@ struct _GimpProcedureClass
GType gimp_procedure_get_type (void) G_GNUC_CONST; GType gimp_procedure_get_type (void) G_GNUC_CONST;
GimpProcedure * gimp_procedure_new (const gchar *name, GimpProcedure * gimp_procedure_new (GimpPlugIn *plug_in,
const gchar *name,
GimpPDBProcType proc_type,
GimpRunFunc run_func); GimpRunFunc run_func);
GimpPlugIn * gimp_procedure_get_plug_in (GimpProcedure *procedure);
GimpPDBProcType gimp_procedure_get_proc_type (GimpProcedure *procedure);
void gimp_procedure_set_strings (GimpProcedure *procedure, void gimp_procedure_set_strings (GimpProcedure *procedure,
const gchar *menu_label, const gchar *menu_label,
const gchar *blurb, const gchar *blurb,