plug-ins: more plug-ins ported to gimp_procedure_new2().

This commit is contained in:
Jehan 2023-06-15 16:53:54 +02:00
parent c09711beaa
commit 38ecbfc762
8 changed files with 139 additions and 94 deletions

View File

@ -52,7 +52,7 @@ static GimpProcedure * glob_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * glob_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data);
static gboolean glob_match (const gchar *pattern,
@ -96,9 +96,9 @@ glob_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
glob_run, NULL, NULL);
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
glob_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Returns a list of matching filenames",
@ -141,29 +141,33 @@ glob_create_procedure (GimpPlugIn *plug_in,
static GimpValueArray *
glob_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data)
{
GimpValueArray *return_vals;
const gchar *pattern;
gchar *pattern;
gboolean filename_encoding;
gchar **matches;
pattern = GIMP_VALUES_GET_STRING (args, 0);
filename_encoding = GIMP_VALUES_GET_BOOLEAN (args, 1);
g_object_get (config,
"pattern", &pattern,
"filename-encoding", &filename_encoding,
NULL);
if (! glob_match (pattern, filename_encoding, &matches))
{
return gimp_procedure_new_return_values (procedure,
return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
NULL);
}
return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS,
NULL);
GIMP_VALUES_TAKE_STRV (return_vals, 1, matches);
else
{
return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS,
NULL);
GIMP_VALUES_TAKE_STRV (return_vals, 1, matches);
}
g_free (pattern);
return return_vals;
}

View File

@ -110,7 +110,7 @@ static GimpProcedure * browser_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * browser_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data);
static GtkWidget * browser_dialog_new (void);
@ -162,9 +162,9 @@ browser_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (procedure_name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new (plug_in, procedure_name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
procedure = gimp_procedure_new2 (plug_in, procedure_name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("_Plug-In Browser"));
gimp_procedure_set_icon_name (procedure, GIMP_ICON_PLUGIN);
@ -199,7 +199,7 @@ browser_create_procedure (GimpPlugIn *plug_in,
static GimpValueArray *
browser_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data)
{
browser_dialog_new ();

View File

@ -80,7 +80,7 @@ static GimpProcedure * browser_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * browser_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data);
@ -119,9 +119,9 @@ browser_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("Procedure _Browser"));
gimp_procedure_add_menu_path (procedure, "<Image>/Help/[Programming]");
@ -148,11 +148,12 @@ browser_create_procedure (GimpPlugIn *plug_in,
static GimpValueArray *
browser_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data)
{
GimpRunMode run_mode = GIMP_VALUES_GET_ENUM (args, 0);
GimpRunMode run_mode;
g_object_get (config, "run-mode", &run_mode, NULL);
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
@ -176,11 +177,17 @@ browser_run (GimpProcedure *procedure,
case GIMP_RUN_WITH_LAST_VALS:
case GIMP_RUN_NONINTERACTIVE:
g_printerr (PLUG_IN_PROC " allows only interactive invocation");
{
GError *error = NULL;
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CALLING_ERROR,
NULL);
g_set_error (&error, GIMP_PLUG_IN_ERROR, 0,
_("Procedure %s allows only interactive invocation."),
gimp_procedure_get_name (procedure));
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CALLING_ERROR,
error);
}
break;
default:

View File

@ -76,7 +76,7 @@ static GimpProcedure * editor_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * editor_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data);
static GimpUnit new_unit_dialog (GtkWindow *main_window,
@ -168,9 +168,9 @@ editor_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
editor_run, plug_in, NULL);
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
editor_run, plug_in, NULL);
gimp_procedure_set_menu_label (procedure, _("U_nits"));
gimp_procedure_set_icon_name (procedure, GIMP_ICON_TOOL_MEASURE);
@ -392,7 +392,7 @@ unit_editor_help_clicked (GtkWidget *window)
static GimpValueArray *
editor_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data)
{
GimpUnitEditor *editor = GIMP_UNIT_EDITOR (run_data);

View File

@ -67,7 +67,7 @@ static GimpProcedure * browser_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * browser_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data);
static gboolean browser_open_url (GtkWindow *window,
@ -110,9 +110,9 @@ browser_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, PLUG_IN_PROC))
{
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
browser_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"Open an URL in the user specified "
@ -128,7 +128,7 @@ browser_create_procedure (GimpPlugIn *plug_in,
GIMP_PROC_ARG_STRING (procedure, "url",
"URL",
"URL to open",
"http://www.gimp.org/",
"https://www.gimp.org/",
G_PARAM_READWRITE);
}
@ -137,19 +137,22 @@ browser_create_procedure (GimpPlugIn *plug_in,
static GimpValueArray *
browser_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data)
{
GError *error = NULL;
gchar *url = NULL;
if (! browser_open_url (NULL, GIMP_VALUES_GET_STRING (args, 0),
&error))
g_object_get (config, "url", &url, NULL);
if (! browser_open_url (NULL, url, &error))
{
g_free (url);
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_EXECUTION_ERROR,
error);
}
g_free (url);
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS,
NULL);

View File

@ -48,12 +48,12 @@ G_DECLARE_FINAL_TYPE (GimpHelpBrowser, gimp_help_browser,
GimpPlugIn)
static GimpValueArray * help_browser_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data);
static void temp_proc_install (GimpPlugIn *plug_in);
static GimpValueArray * temp_proc_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data);
static GimpHelpProgress * help_browser_progress_new (void);
@ -85,9 +85,9 @@ help_browser_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, GIMP_HELP_BROWSER_EXT_PROC))
{
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
help_browser_run, plug_in, NULL);
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
help_browser_run, plug_in, NULL);
gimp_procedure_set_documentation (procedure,
"Browse the GIMP user manual",
@ -149,18 +149,29 @@ on_app_activate (GApplication *gapp,
static GimpValueArray *
help_browser_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer user_data)
{
GimpHelpBrowser *browser = GIMP_HELP_BROWSER (user_data);
GimpHelpBrowser *browser = GIMP_HELP_BROWSER (user_data);
gchar **domain_names = NULL;
gchar **domain_uris = NULL;
if (! gimp_help_init (GIMP_VALUES_GET_STRV (args, 1),
GIMP_VALUES_GET_STRV (args, 2)))
g_object_get (config,
"domain-names", &domain_names,
"domain-uris", &domain_uris,
NULL);
if (! gimp_help_init ((const gchar **) domain_names,
(const gchar **) domain_uris))
{
g_strfreev (domain_names);
g_strfreev (domain_uris);
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CALLING_ERROR,
NULL);
}
g_strfreev (domain_names);
g_strfreev (domain_uris);
temp_proc_install (gimp_procedure_get_plug_in (procedure));
@ -186,9 +197,9 @@ temp_proc_install (GimpPlugIn *plug_in)
{
GimpProcedure *procedure;
procedure = gimp_procedure_new (plug_in, GIMP_HELP_BROWSER_TEMP_EXT_PROC,
GIMP_PDB_PROC_TYPE_TEMPORARY,
temp_proc_run, plug_in, NULL);
procedure = gimp_procedure_new2 (plug_in, GIMP_HELP_BROWSER_TEMP_EXT_PROC,
GIMP_PDB_PROC_TYPE_TEMPORARY,
temp_proc_run, plug_in, NULL);
gimp_procedure_set_documentation (procedure,
"DON'T USE THIS ONE",
@ -286,25 +297,28 @@ show_help_on_idle (gpointer user_data)
static GimpValueArray *
temp_proc_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer user_data)
{
GimpHelpBrowser *browser = GIMP_HELP_BROWSER (user_data);
IdleClosure *closure;
const char *str;
gchar *str;
closure = g_new0 (IdleClosure, 1);
closure->browser = browser;
str = GIMP_VALUES_GET_STRING (args, 0);
g_object_get (config, "help-domain", &str, NULL);
closure->help_domain = g_strdup ((str && *str)? str : GIMP_HELP_DEFAULT_DOMAIN);
g_free (str);
str = GIMP_VALUES_GET_STRING (args, 1);
g_object_get (config, "help-locales", &str, NULL);
if (str && *str)
closure->help_locales = g_strdup (str);
g_free (str);
str = GIMP_VALUES_GET_STRING (args, 2);
g_object_get (config, "help-id", &str, NULL);
closure->help_id = g_strdup ((str && *str)? str : GIMP_HELP_DEFAULT_ID);
g_free (str);
/* Do this on idle, to make sure everything is initialized already */
g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,

View File

@ -73,10 +73,10 @@ static GimpProcedure * help_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * help_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data);
static GimpValueArray * help_temp_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data);
static void help_temp_proc_install (GimpPlugIn *plug_in);
@ -126,9 +126,9 @@ help_create_procedure (GimpPlugIn *plug_in,
if (! strcmp (name, GIMP_HELP_EXT_PROC))
{
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
help_run, NULL, NULL);
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_EXTENSION,
help_run, NULL, NULL);
gimp_procedure_set_attribution (procedure,
"Sven Neumann <sven@gimp.org>, "
@ -153,16 +153,23 @@ help_create_procedure (GimpPlugIn *plug_in,
static GimpValueArray *
help_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data)
{
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gchar **domain_names = NULL;
gchar **domain_uris = NULL;
if (! gimp_help_init (GIMP_VALUES_GET_STRV (args, 0),
GIMP_VALUES_GET_STRV (args, 1)))
{
status = GIMP_PDB_CALLING_ERROR;
}
g_object_get (config,
"domain-names", &domain_names,
"domain-uris", &domain_uris,
NULL);
if (! gimp_help_init ((const gchar **) domain_names,
(const gchar **) domain_uris))
status = GIMP_PDB_CALLING_ERROR;
g_strfreev (domain_names);
g_strfreev (domain_uris);
if (status == GIMP_PDB_SUCCESS)
{
@ -191,9 +198,9 @@ help_temp_proc_install (GimpPlugIn *plug_in)
{
GimpProcedure *procedure;
procedure = gimp_procedure_new (plug_in, GIMP_HELP_TEMP_EXT_PROC,
GIMP_PDB_PROC_TYPE_TEMPORARY,
help_temp_run, NULL, NULL);
procedure = gimp_procedure_new2 (plug_in, GIMP_HELP_TEMP_EXT_PROC,
GIMP_PDB_PROC_TYPE_TEMPORARY,
help_temp_run, NULL, NULL);
gimp_procedure_set_attribution (procedure,
"Sven Neumann <sven@gimp.org>, "
@ -233,26 +240,27 @@ help_temp_proc_install (GimpPlugIn *plug_in)
static GimpValueArray *
help_temp_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data)
{
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
const gchar *help_proc = NULL;
const gchar *help_domain = GIMP_HELP_DEFAULT_DOMAIN;
const gchar *help_locales = NULL;
const gchar *help_id = GIMP_HELP_DEFAULT_ID;
gchar *help_proc = NULL;
gchar *help_domain = NULL;
gchar *help_locales = NULL;
gchar *help_id = NULL;
if (GIMP_VALUES_GET_STRING (args, 0))
help_proc = GIMP_VALUES_GET_STRING (args, 0);
g_object_get (config,
"help-proc", &help_proc,
"help-domain", &help_domain,
"help-locales", &help_locales,
"help-id", &help_id,
NULL);
if (GIMP_VALUES_GET_STRING (args, 1))
help_domain = GIMP_VALUES_GET_STRING (args, 1);
if (help_domain == NULL)
help_domain = g_strdup (GIMP_HELP_DEFAULT_DOMAIN);
if (GIMP_VALUES_GET_STRING (args, 2))
help_locales = GIMP_VALUES_GET_STRING (args, 2);
if (GIMP_VALUES_GET_STRING (args, 3))
help_id = GIMP_VALUES_GET_STRING (args, 3);
if (help_id == NULL)
help_id = g_strdup (GIMP_HELP_DEFAULT_ID);
if (! help_proc)
status = GIMP_PDB_CALLING_ERROR;
@ -260,6 +268,11 @@ help_temp_run (GimpProcedure *procedure,
if (status == GIMP_PDB_SUCCESS)
help_load (help_proc, help_domain, help_locales, help_id);
g_free (help_proc);
g_free (help_domain);
g_free (help_locales);
g_free (help_id);
return gimp_procedure_new_return_values (procedure, status, NULL);
}

View File

@ -504,14 +504,18 @@ create_custom_widget (GtkPrintOperation *operation,
#ifndef EMBED_PAGE_SETUP
static GimpValueArray *
print_temp_proc_run (GimpProcedure *procedure,
const GimpValueArray *args,
GimpProcedureConfig *config,
gpointer run_data)
{
GimpImage *image = GIMP_VALUES_GET_IMAGE (args, 0);
GimpImage *image;
g_object_get (config, "image", &image, NULL);
if (print_operation)
print_page_setup_load (print_operation, image);
g_object_unref (image);
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
}
@ -529,9 +533,9 @@ print_temp_proc_install (GimpImage *image)
gchar *name = print_temp_proc_name (image);
GimpProcedure *procedure;
procedure = gimp_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_TEMPORARY,
print_temp_proc_run, NULL, NULL);
procedure = gimp_procedure_new2 (plug_in, name,
GIMP_PDB_PROC_TYPE_TEMPORARY,
print_temp_proc_run, NULL, NULL);
gimp_procedure_set_documentation (procedure,
"DON'T USE THIS ONE",