[gimp] Simplify the plug-in query API and fix plugin-browser
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Simplify the plug-in query API and fix plugin-browser
- Date: Sun, 8 Sep 2019 13:01:10 +0000 (UTC)
commit 388776df071bbaffd483e36d67783fe237e16a53
Author: Michael Natterer <mitch gimp org>
Date: Sun Sep 8 14:54:17 2019 +0200
Simplify the plug-in query API and fix plugin-browser
- remove the menu path and image types from "gimp-plugins-query",
they are available via GimpProcedure, also reorder and rename
its remaining return values to make sense
- remove the "menu_path" parameter to gimp_proc_view_new(),
it can also ask GimpProcedure
- adapt plugin-browser to the new API and make it use GimpProcedure
- fix plugin-browser's tree view to show all menu hierarchies
completely, it was still expecting menu paths that contain
the menu label too
app/pdb/plug-in-cmds.c | 44 ++-----------
app/plug-in/gimppluginmanager-query.c | 78 +++++++---------------
app/plug-in/gimppluginmanager-query.h | 4 +-
libgimp/gimpprocbrowserdialog.c | 2 +-
libgimp/gimpprocview.c | 14 +---
libgimp/gimpprocview.h | 3 +-
pdb/groups/plug_in.pdb | 16 +----
plug-ins/common/plugin-browser.c | 120 ++++++++++++++--------------------
8 files changed, 86 insertions(+), 195 deletions(-)
---
diff --git a/app/pdb/plug-in-cmds.c b/app/pdb/plug-in-cmds.c
index 3d6d1290bd..03ab051021 100644
--- a/app/pdb/plug-in-cmds.c
+++ b/app/pdb/plug-in-cmds.c
@@ -58,38 +58,30 @@ plugins_query_invoker (GimpProcedure *procedure,
GimpValueArray *return_vals;
const gchar *search_string;
gint num_plugins = 0;
- gchar **menu_path = NULL;
+ gchar **plugin_procedure = NULL;
gchar **plugin_accelerator = NULL;
gchar **plugin_location = NULL;
- gchar **plugin_image_type = NULL;
gint32 *plugin_install_time = NULL;
- gchar **plugin_real_name = NULL;
search_string = g_value_get_string (gimp_value_array_index (args, 0));
num_plugins = gimp_plug_in_manager_query (gimp->plug_in_manager,
search_string,
- &menu_path,
+ &plugin_procedure,
&plugin_accelerator,
&plugin_location,
- &plugin_image_type,
- &plugin_real_name,
&plugin_install_time);
return_vals = gimp_procedure_get_return_values (procedure, TRUE, NULL);
g_value_set_int (gimp_value_array_index (return_vals, 1), num_plugins);
- gimp_value_take_string_array (gimp_value_array_index (return_vals, 2), menu_path, num_plugins);
+ gimp_value_take_string_array (gimp_value_array_index (return_vals, 2), plugin_procedure, num_plugins);
g_value_set_int (gimp_value_array_index (return_vals, 3), num_plugins);
gimp_value_take_string_array (gimp_value_array_index (return_vals, 4), plugin_accelerator, num_plugins);
g_value_set_int (gimp_value_array_index (return_vals, 5), num_plugins);
gimp_value_take_string_array (gimp_value_array_index (return_vals, 6), plugin_location, num_plugins);
g_value_set_int (gimp_value_array_index (return_vals, 7), num_plugins);
- gimp_value_take_string_array (gimp_value_array_index (return_vals, 8), plugin_image_type, num_plugins);
- g_value_set_int (gimp_value_array_index (return_vals, 9), num_plugins);
- gimp_value_take_int32_array (gimp_value_array_index (return_vals, 10), plugin_install_time, num_plugins);
- g_value_set_int (gimp_value_array_index (return_vals, 11), num_plugins);
- gimp_value_take_string_array (gimp_value_array_index (return_vals, 12), plugin_real_name, num_plugins);
+ gimp_value_take_int32_array (gimp_value_array_index (return_vals, 8), plugin_install_time, num_plugins);
return return_vals;
}
@@ -359,9 +351,9 @@ register_plug_in_procs (GimpPDB *pdb)
0, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
- gimp_param_spec_string_array ("menu-path",
- "menu path",
- "The menu path of the plug-in",
+ gimp_param_spec_string_array ("plugin-procedure",
+ "plugin procedure",
+ "The plug-in procedure name",
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
g_param_spec_int ("num-plugins",
@@ -391,33 +383,11 @@ register_plug_in_procs (GimpPDB *pdb)
"The number of plug-ins",
0, G_MAXINT32, 0,
GIMP_PARAM_READWRITE));
- gimp_procedure_add_return_value (procedure,
- gimp_param_spec_string_array ("plugin-image-type",
- "plugin image type",
- "Type of image that this plug-in will work
on",
- GIMP_PARAM_READWRITE));
- gimp_procedure_add_return_value (procedure,
- g_param_spec_int ("num-plugins",
- "num plugins",
- "The number of plug-ins",
- 0, G_MAXINT32, 0,
- GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_int32_array ("plugin-install-time",
"plugin install time",
"Time that the plug-in was installed",
GIMP_PARAM_READWRITE));
- gimp_procedure_add_return_value (procedure,
- g_param_spec_int ("num-plugins",
- "num plugins",
- "The number of plug-ins",
- 0, G_MAXINT32, 0,
- GIMP_PARAM_READWRITE));
- gimp_procedure_add_return_value (procedure,
- gimp_param_spec_string_array ("plugin-real-name",
- "plugin real name",
- "The internal name of the plug-in",
- GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
diff --git a/app/plug-in/gimppluginmanager-query.c b/app/plug-in/gimppluginmanager-query.c
index 861a89a16b..14f005dc37 100644
--- a/app/plug-in/gimppluginmanager-query.c
+++ b/app/plug-in/gimppluginmanager-query.c
@@ -43,33 +43,27 @@ match_string (GRegex *regex,
gint
gimp_plug_in_manager_query (GimpPlugInManager *manager,
const gchar *search_str,
- gchar ***menu_strs,
+ gchar ***procedure_strs,
gchar ***accel_strs,
gchar ***prog_strs,
- gchar ***types_strs,
- gchar ***realname_strs,
gint32 **time_ints)
{
- gint32 num_plugins = 0;
- GSList *list;
- GSList *matched = NULL;
- gint i = 0;
+ gint num_plugins = 0;
GRegex *sregex = NULL;
+ GSList *matched = NULL;
+ GSList *list;
+ gint i;
g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), 0);
- g_return_val_if_fail (menu_strs != NULL, 0);
+ g_return_val_if_fail (procedure_strs != NULL, 0);
g_return_val_if_fail (accel_strs != NULL, 0);
g_return_val_if_fail (prog_strs != NULL, 0);
- g_return_val_if_fail (types_strs != NULL, 0);
- g_return_val_if_fail (realname_strs != NULL, 0);
g_return_val_if_fail (time_ints != NULL, 0);
- *menu_strs = NULL;
- *accel_strs = NULL;
- *prog_strs = NULL;
- *types_strs = NULL;
- *realname_strs = NULL;
- *time_ints = NULL;
+ *procedure_strs = NULL;
+ *accel_strs = NULL;
+ *prog_strs = NULL;
+ *time_ints = NULL;
if (search_str && ! strlen (search_str))
search_str = NULL;
@@ -92,21 +86,7 @@ gimp_plug_in_manager_query (GimpPlugInManager *manager,
if (proc->file && proc->menu_paths)
{
- gchar *name;
-
- if (proc->menu_label)
- {
- name = proc->menu_label;
- }
- else
- {
- name = strrchr (proc->menu_paths->data, '/');
-
- if (name)
- name = name + 1;
- else
- name = proc->menu_paths->data;
- }
+ gchar *name = proc->menu_label;
name = gimp_strip_uline (name);
@@ -120,37 +100,23 @@ gimp_plug_in_manager_query (GimpPlugInManager *manager,
}
}
- *menu_strs = g_new (gchar *, num_plugins);
- *accel_strs = g_new (gchar *, num_plugins);
- *prog_strs = g_new (gchar *, num_plugins);
- *types_strs = g_new (gchar *, num_plugins);
- *realname_strs = g_new (gchar *, num_plugins);
- *time_ints = g_new (gint, num_plugins);
+ *procedure_strs = g_new (gchar *, num_plugins);
+ *accel_strs = g_new (gchar *, num_plugins);
+ *prog_strs = g_new (gchar *, num_plugins);
+ *time_ints = g_new (gint, num_plugins);
matched = g_slist_reverse (matched);
- for (list = matched; list; list = g_slist_next (list))
+ for (list = matched, i = 0;
+ list;
+ list = g_slist_next (list), i++)
{
GimpPlugInProcedure *proc = list->data;
- gchar *name;
-
- if (proc->menu_label)
- name = g_strdup_printf ("%s/%s",
- (gchar *) proc->menu_paths->data,
- proc->menu_label);
- else
- name = g_strdup (proc->menu_paths->data);
-
- (*menu_strs)[i] = gimp_strip_uline (name);
- (*accel_strs)[i] = NULL;
- (*prog_strs)[i] = g_file_get_path (proc->file);
- (*types_strs)[i] = g_strdup (proc->image_types);
- (*realname_strs)[i] = g_strdup (gimp_object_get_name (proc));
- (*time_ints)[i] = proc->mtime;
-
- g_free (name);
- i++;
+ (*procedure_strs)[i] = g_strdup (gimp_object_get_name (proc));
+ (*accel_strs)[i] = NULL;
+ (*prog_strs)[i] = g_file_get_path (proc->file);
+ (*time_ints)[i] = proc->mtime;
}
g_slist_free (matched);
diff --git a/app/plug-in/gimppluginmanager-query.h b/app/plug-in/gimppluginmanager-query.h
index 94b78c879f..0e5ffc89d6 100644
--- a/app/plug-in/gimppluginmanager-query.h
+++ b/app/plug-in/gimppluginmanager-query.h
@@ -23,11 +23,9 @@
gint gimp_plug_in_manager_query (GimpPlugInManager *manager,
const gchar *search_str,
- gchar ***menu_strs,
+ gchar ***procedure_strs,
gchar ***accel_strs,
gchar ***prog_strs,
- gchar ***types_strs,
- gchar ***realname_strs,
gint32 **time_ints);
diff --git a/libgimp/gimpprocbrowserdialog.c b/libgimp/gimpprocbrowserdialog.c
index 5a19737cd6..f5f66fac30 100644
--- a/libgimp/gimpprocbrowserdialog.c
+++ b/libgimp/gimpprocbrowserdialog.c
@@ -330,7 +330,7 @@ browser_selection_changed (GtkTreeSelection *sel,
-1);
gimp_browser_set_widget (GIMP_BROWSER (dialog->priv->browser),
- gimp_proc_view_new (proc_name, NULL));
+ gimp_proc_view_new (proc_name));
g_free (proc_name);
}
diff --git a/libgimp/gimpprocview.c b/libgimp/gimpprocview.c
index ac8b172460..7668300b9a 100644
--- a/libgimp/gimpprocview.c
+++ b/libgimp/gimpprocview.c
@@ -72,7 +72,6 @@ static GtkWidget * gimp_proc_view_create_args (GimpProcedure *procedure,
/**
* gimp_proc_view_new:
* @procedure_name: The name of a procedure.
- * @menu_path: (nullable): The procedure's menu path, or %NULL.
*
* Returns: (transfer full): a new widget providing a view on a
* GIMP procedure
@@ -80,8 +79,7 @@ static GtkWidget * gimp_proc_view_create_args (GimpProcedure *procedure,
* Since: 2.4
**/
GtkWidget *
-gimp_proc_view_new (const gchar *procedure_name,
- const gchar *menu_path)
+gimp_proc_view_new (const gchar *procedure_name)
{
GimpProcedure *procedure;
GtkWidget *main_vbox;
@@ -151,16 +149,6 @@ gimp_proc_view_new (const gchar *procedure_name,
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
- if (menu_path)
- {
- label = gtk_label_new_with_mnemonic (menu_path);
- gtk_label_set_selectable (GTK_LABEL (label), TRUE);
- gtk_label_set_xalign (GTK_LABEL (label), 0.0);
- gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
- gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
- gtk_widget_show (label);
- }
-
if (blurb)
{
label = gtk_label_new (blurb);
diff --git a/libgimp/gimpprocview.h b/libgimp/gimpprocview.h
index 915a0aa562..4b9451086a 100644
--- a/libgimp/gimpprocview.h
+++ b/libgimp/gimpprocview.h
@@ -31,8 +31,7 @@ G_BEGIN_DECLS
/* For information look into the C source or the html documentation */
-GtkWidget * gimp_proc_view_new (const gchar *procedure_name,
- const gchar *menu_path);
+GtkWidget * gimp_proc_view_new (const gchar *procedure_name);
G_END_DECLS
diff --git a/pdb/groups/plug_in.pdb b/pdb/groups/plug_in.pdb
index 3d74996846..3b2db6e1b4 100644
--- a/pdb/groups/plug_in.pdb
+++ b/pdb/groups/plug_in.pdb
@@ -30,8 +30,8 @@ sub plugins_query {
);
@outargs = (
- { name => 'menu_path', type => 'stringarray',
- desc => 'The menu path of the plug-in',
+ { name => 'plugin_procedure', type => 'stringarray',
+ desc => 'The plug-in procedure name',
array => { name => 'num_plugins',
desc => 'The number of plug-ins' } },
{ name => 'plugin_accelerator', type => 'stringarray',
@@ -43,16 +43,8 @@ sub plugins_query {
desc => 'Location of the plug-in program',
array => { name => 'num_plugins', no_declare => 1,
desc => 'The number of plug-ins' } },
- { name => 'plugin_image_type', type => 'stringarray',
- desc => 'Type of image that this plug-in will work on',
- array => { name => 'num_plugins', no_declare => 1,
- desc => 'The number of plug-ins' } },
{ name => 'plugin_install_time', type => 'int32array',
desc => 'Time that the plug-in was installed',
- array => { name => 'num_plugins', no_declare => 1,
- desc => 'The number of plug-ins' } },
- { name => 'plugin_real_name', type => 'stringarray',
- desc => 'The internal name of the plug-in',
array => { name => 'num_plugins', no_declare => 1,
desc => 'The number of plug-ins' } }
);
@@ -62,11 +54,9 @@ sub plugins_query {
{
num_plugins = gimp_plug_in_manager_query (gimp->plug_in_manager,
search_string,
- &menu_path,
+ &plugin_procedure,
&plugin_accelerator,
&plugin_location,
- &plugin_image_type,
- &plugin_real_name,
&plugin_install_time);
}
CODE
diff --git a/plug-ins/common/plugin-browser.c b/plug-ins/common/plugin-browser.c
index 506e7715e6..3190381cdf 100644
--- a/plug-ins/common/plugin-browser.c
+++ b/plug-ins/common/plugin-browser.c
@@ -78,9 +78,8 @@ typedef struct
gchar *menu;
gchar *accel;
gchar *prog;
- gchar *types;
- gchar *realname;
- gint instime;
+ gchar *procedure;
+ gint instime;
} PInfo;
@@ -335,7 +334,7 @@ insert_into_tree_view (PluginBrowser *browser,
const gchar *name,
gint64 xtime,
const gchar *xtimestr,
- const gchar *menu_str,
+ const gchar *menu_path,
const gchar *types_str,
PInfo *pinfo)
{
@@ -344,29 +343,12 @@ insert_into_tree_view (PluginBrowser *browser,
GtkTreeIter parent, iter;
GtkTreeStore *tree_store;
- /* Find all nodes */
- /* Last one is the leaf part */
-
- tmp_ptr = g_strdup (menu_str);
-
- str_ptr = strrchr (tmp_ptr, '/');
-
- if (str_ptr == NULL)
- {
- g_free (tmp_ptr);
- return; /* No node */
- }
-
- *str_ptr = '\0';
-
- /* printf("inserting %s...\n",menu_str); */
-
- get_parent (browser, tmp_ptr, &parent);
+ get_parent (browser, menu_path, &parent);
tree_store = GTK_TREE_STORE (gtk_tree_view_get_model (browser->tree_view));
gtk_tree_store_append (tree_store, &iter, &parent);
gtk_tree_store_set (tree_store, &iter,
- TREE_COLUMN_MPATH, menu_str,
+ TREE_COLUMN_MPATH, menu_path,
TREE_COLUMN_PATH_NAME, name,
TREE_COLUMN_IMAGE_TYPES, types_str,
TREE_COLUMN_DATE, xtime,
@@ -434,47 +416,48 @@ browser_search (GimpBrowser *gimp_browser,
{
GtkTreeSelection *sel;
GtkTreeIter iter;
- const gchar **menu_strs;
+ const gchar **procedure_strs;
const gchar **accel_strs;
const gchar **prog_strs;
- const gchar **types_strs;
- const gchar **realname_strs;
const gint *time_ints;
gint i;
- menu_strs = GIMP_VALUES_GET_STRING_ARRAY (return_vals, 2);
- accel_strs = GIMP_VALUES_GET_STRING_ARRAY (return_vals, 4);
- prog_strs = GIMP_VALUES_GET_STRING_ARRAY (return_vals, 6);
- types_strs = GIMP_VALUES_GET_STRING_ARRAY (return_vals, 8);
- time_ints = GIMP_VALUES_GET_INT32_ARRAY (return_vals, 10);
- realname_strs = GIMP_VALUES_GET_STRING_ARRAY (return_vals, 12);
+ procedure_strs = GIMP_VALUES_GET_STRING_ARRAY (return_vals, 2);
+ accel_strs = GIMP_VALUES_GET_STRING_ARRAY (return_vals, 4);
+ prog_strs = GIMP_VALUES_GET_STRING_ARRAY (return_vals, 6);
+ time_ints = GIMP_VALUES_GET_INT32_ARRAY (return_vals, 8);
for (i = 0; i < num_plugins; i++)
{
- PInfo *pinfo;
- gchar *menu_str = g_strdup (menu_strs[i]);
- gchar *name;
- gchar xtimestr[50];
- struct tm *x;
- time_t tx;
- gint ret;
+ GimpProcedure *procedure;
+ const gchar *types;
+ PInfo *pinfo;
+ gchar *menu_label;
+ gchar *tmp;
+ GList *menu_paths;
+ const gchar *menu_path;
+ gchar xtimestr[50];
+ struct tm *x;
+ time_t tx;
+ gint ret;
+
+ procedure = gimp_pdb_lookup_procedure (gimp_get_pdb (),
+ procedure_strs[i]);
+
+ types = gimp_procedure_get_image_types (procedure);
+ menu_label = g_strdup (gimp_procedure_get_menu_label (procedure));
+ menu_paths = gimp_procedure_get_menu_paths (procedure);
+
+ menu_path = menu_paths->data;
/* Strip off trailing ellipsis */
- name = strstr (menu_str, "...");
- if (name && name == (menu_str + strlen (menu_str) - 3))
- *name = '\0';
-
- name = strrchr (menu_str, '/');
+ tmp = strstr (menu_label, "...");
+ if (tmp && tmp == (menu_label + strlen (menu_label) - 3))
+ *tmp = '\0';
- if (name)
- {
- *name = '\0';
- name = name + 1;
- }
- else
- {
- name = menu_str;
- }
+ tmp = gimp_strip_uline (menu_label);
+ g_free (menu_label);
+ menu_label = tmp;
tx = time_ints[i];
if (tx)
@@ -499,33 +482,32 @@ browser_search (GimpBrowser *gimp_browser,
pinfo = g_new0 (PInfo, 1);
- pinfo->menu = g_strdup (menu_str);
- pinfo->accel = g_strdup (accel_strs[i]);
- pinfo->prog = g_strdup (prog_strs[i]);
- pinfo->types = g_strdup (types_strs[i]);
- pinfo->instime = time_ints[i];
- pinfo->realname = g_strdup (realname_strs[i]);
+ pinfo->menu = g_strdup (menu_path);
+ pinfo->accel = g_strdup (accel_strs[i]);
+ pinfo->prog = g_strdup (prog_strs[i]);
+ pinfo->instime = time_ints[i];
+ pinfo->procedure = g_strdup (procedure_strs[i]);
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
- LIST_COLUMN_NAME, name,
+ LIST_COLUMN_NAME, menu_label,
LIST_COLUMN_DATE, (gint64) tx,
LIST_COLUMN_DATE_STRING, xtimestr,
- LIST_COLUMN_PATH, menu_str,
- LIST_COLUMN_IMAGE_TYPES, types_strs[i],
+ LIST_COLUMN_PATH, menu_path,
+ LIST_COLUMN_IMAGE_TYPES, types,
LIST_COLUMN_PINFO, pinfo,
-1);
/* Now do the tree view.... */
insert_into_tree_view (browser,
- name,
+ menu_label,
(gint64) tx,
xtimestr,
- menu_str,
- types_strs[i],
+ menu_path,
+ types,
pinfo);
- g_free (menu_str);
+ g_free (menu_label);
}
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (browser->list_view));
@@ -815,8 +797,7 @@ browser_list_selection_changed (GtkTreeSelection *selection,
g_free (mpath);
gimp_browser_set_widget (GIMP_BROWSER (browser->browser),
- gimp_proc_view_new (pinfo->realname,
- pinfo->menu));
+ gimp_proc_view_new (pinfo->procedure));
}
static void
@@ -893,6 +874,5 @@ browser_tree_selection_changed (GtkTreeSelection *selection,
}
gimp_browser_set_widget (GIMP_BROWSER (browser->browser),
- gimp_proc_view_new (pinfo->realname,
- pinfo->menu));
+ gimp_proc_view_new (pinfo->procedure));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]