[gimp] pdb: move gimp_plugin_icon_register_invoker() from "plugin" to "pdb"



commit 303ccbedad6be19c75717e67d241099027f4df40
Author: Michael Natterer <mitch gimp org>
Date:   Sun Sep 8 16:22:32 2019 +0200

    pdb: move gimp_plugin_icon_register_invoker() from "plugin" to "pdb"
    
    and call it gimp_pdb_set_proc_icon(). Change icon registration code in
    libgimp/ and app/ so it's now possible to register icons for temporary
    procedures.

 app/file-data/file-data.c         |  21 ++++---
 app/pdb/pdb-cmds.c                |  79 ++++++++++++++++++++++++++
 app/pdb/plug-in-cmds.c            |  87 -----------------------------
 app/plug-in/gimpplugin.c          |  59 ++++++++++++++++++--
 app/plug-in/gimpplugin.h          |   5 ++
 app/plug-in/gimppluginprocedure.c |  75 ++++++++++++++-----------
 app/plug-in/gimppluginprocedure.h |  10 ++--
 app/plug-in/plug-in-rc.c          |   3 +-
 app/xcf/xcf.c                     |   6 +-
 libgimp/gimppdb_pdb.c             |  45 +++++++++++++++
 libgimp/gimppdb_pdb.h             |   4 ++
 libgimp/gimpplugin_pdb.c          |  45 ---------------
 libgimp/gimpplugin_pdb.h          |   4 --
 libgimp/gimpprocedure.c           | 114 +++++++++++++++++++++-----------------
 pdb/groups/pdb.pdb                |  43 ++++++++++++++
 pdb/groups/plug_in.pdb            |  53 +-----------------
 16 files changed, 362 insertions(+), 291 deletions(-)
---
diff --git a/app/file-data/file-data.c b/app/file-data/file-data.c
index 39e5a94177..109088dabe 100644
--- a/app/file-data/file-data.c
+++ b/app/file-data/file-data.c
@@ -60,7 +60,8 @@ file_data_init (Gimp *gimp)
   proc->menu_label = g_strdup (N_("GIMP brush"));
   gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_ICON_NAME,
                                    (const guint8 *) "gimp-brush",
-                                   strlen ("gimp-brush") + 1);
+                                   strlen ("gimp-brush") + 1,
+                                   NULL);
   gimp_plug_in_procedure_set_image_types (proc, NULL);
   gimp_plug_in_procedure_set_file_proc (proc, "gbr, gbp", "",
                                         "20, string, GIMP");
@@ -125,7 +126,8 @@ file_data_init (Gimp *gimp)
   proc->menu_label = g_strdup (N_("GIMP brush"));
   gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_ICON_NAME,
                                    (const guint8 *) "gimp-brush",
-                                   strlen ("gimp-brush") + 1);
+                                   strlen ("gimp-brush") + 1,
+                                   NULL);
 
 #if 0
   /* do not register as file procedure */
@@ -211,7 +213,8 @@ file_data_init (Gimp *gimp)
   proc->menu_label = g_strdup (N_("GIMP brush (animated)"));
   gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_ICON_NAME,
                                    (const guint8 *) "gimp-brush",
-                                   strlen ("gimp-brush") + 1);
+                                   strlen ("gimp-brush") + 1,
+                                   NULL);
   gimp_plug_in_procedure_set_image_types (proc, NULL);
   gimp_plug_in_procedure_set_file_proc (proc, "gih", "", "");
   gimp_plug_in_procedure_set_mime_types (proc, "image/gimp-x-gih");
@@ -273,7 +276,8 @@ file_data_init (Gimp *gimp)
   proc->menu_label = g_strdup (N_("GIMP brush (animated)"));
   gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_ICON_NAME,
                                    (const guint8 *) "gimp-brush",
-                                   strlen ("gimp-brush") + 1);
+                                   strlen ("gimp-brush") + 1,
+                                   NULL);
 
 #if 0
   /* do not register as file procedure */
@@ -366,7 +370,8 @@ file_data_init (Gimp *gimp)
   proc->menu_label = g_strdup (N_("GIMP pattern"));
   gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_ICON_NAME,
                                    (const guint8 *) "gimp-pattern",
-                                   strlen ("gimp-pattern") + 1);
+                                   strlen ("gimp-pattern") + 1,
+                                   NULL);
   gimp_plug_in_procedure_set_image_types (proc, NULL);
   gimp_plug_in_procedure_set_file_proc (proc, "pat", "",
                                         "20,string,GPAT");
@@ -427,7 +432,8 @@ file_data_init (Gimp *gimp)
   proc->menu_label = g_strdup (N_("GIMP pattern"));
   gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_ICON_NAME,
                                    (const guint8 *) "gimp-pattern",
-                                   strlen ("gimp-pattern") + 1);
+                                   strlen ("gimp-pattern") + 1,
+                                   NULL);
 
 #if 0
   /* do not register as file procedure */
@@ -508,7 +514,8 @@ file_data_init (Gimp *gimp)
   proc->menu_label = g_strdup (N_("GIMP extension"));
   gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_ICON_NAME,
                                    (const guint8 *) "gimp-plugin",
-                                   strlen ("gimp-plugin") + 1);
+                                   strlen ("gimp-plugin") + 1,
+                                   NULL);
   gimp_plug_in_procedure_set_file_proc (proc, "gex", "",
                                         "20, string, GIMP");
   gimp_plug_in_procedure_set_generic_file_proc (proc, TRUE);
diff --git a/app/pdb/pdb-cmds.c b/app/pdb/pdb-cmds.c
index d352c30616..e7f277ea83 100644
--- a/app/pdb/pdb-cmds.c
+++ b/app/pdb/pdb-cmds.c
@@ -443,6 +443,44 @@ pdb_get_proc_menu_paths_invoker (GimpProcedure         *procedure,
   return return_vals;
 }
 
+static GimpValueArray *
+pdb_set_proc_icon_invoker (GimpProcedure         *procedure,
+                           Gimp                  *gimp,
+                           GimpContext           *context,
+                           GimpProgress          *progress,
+                           const GimpValueArray  *args,
+                           GError               **error)
+{
+  gboolean success = TRUE;
+  const gchar *procedure_name;
+  gint icon_type;
+  gint icon_data_length;
+  const guint8 *icon_data;
+
+  procedure_name = g_value_get_string (gimp_value_array_index (args, 0));
+  icon_type = g_value_get_enum (gimp_value_array_index (args, 1));
+  icon_data_length = g_value_get_int (gimp_value_array_index (args, 2));
+  icon_data = gimp_value_get_uint8_array (gimp_value_array_index (args, 3));
+
+  if (success)
+    {
+      GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
+
+      if (plug_in &&
+          gimp_pdb_is_canonical_procedure (procedure_name, error))
+        {
+          success = gimp_plug_in_set_proc_icon (plug_in, procedure_name,
+                                                icon_type,
+                                                icon_data, icon_data_length);
+        }
+      else
+        success = FALSE;
+    }
+
+  return gimp_procedure_get_return_values (procedure, success,
+                                           error ? *error : NULL);
+}
+
 static GimpValueArray *
 pdb_get_proc_documentation_invoker (GimpProcedure         *procedure,
                                     Gimp                  *gimp,
@@ -1067,6 +1105,47 @@ register_pdb_procs (GimpPDB *pdb)
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
 
+  /*
+   * gimp-pdb-set-proc-icon
+   */
+  procedure = gimp_procedure_new (pdb_set_proc_icon_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-pdb-set-proc-icon");
+  gimp_procedure_set_static_strings (procedure,
+                                     "Register an icon for a plug-in procedure.",
+                                     "This procedure installs an icon for the given procedure.",
+                                     "Michael Natterer <mitch gimp org>",
+                                     "Michael Natterer",
+                                     "2019",
+                                     NULL);
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_string ("procedure-name",
+                                                       "procedure name",
+                                                       "The procedure for which to install the icon",
+                                                       FALSE, FALSE, TRUE,
+                                                       NULL,
+                                                       GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_enum ("icon-type",
+                                                  "icon type",
+                                                  "The type of the icon",
+                                                  GIMP_TYPE_ICON_TYPE,
+                                                  GIMP_ICON_TYPE_ICON_NAME,
+                                                  GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               g_param_spec_int ("icon-data-length",
+                                                 "icon data length",
+                                                 "The length of 'icon-data'",
+                                                 1, G_MAXINT32, 1,
+                                                 GIMP_PARAM_READWRITE));
+  gimp_procedure_add_argument (procedure,
+                               gimp_param_spec_uint8_array ("icon-data",
+                                                            "icon data",
+                                                            "The procedure's icon. The format depends on the 
'icon_type' parameter",
+                                                            GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
   /*
    * gimp-pdb-get-proc-documentation
    */
diff --git a/app/pdb/plug-in-cmds.c b/app/pdb/plug-in-cmds.c
index 84a3f341fd..bde3437d64 100644
--- a/app/pdb/plug-in-cmds.c
+++ b/app/pdb/plug-in-cmds.c
@@ -182,52 +182,6 @@ plugin_menu_branch_register_invoker (GimpProcedure         *procedure,
                                            error ? *error : NULL);
 }
 
-static GimpValueArray *
-plugin_icon_register_invoker (GimpProcedure         *procedure,
-                              Gimp                  *gimp,
-                              GimpContext           *context,
-                              GimpProgress          *progress,
-                              const GimpValueArray  *args,
-                              GError               **error)
-{
-  gboolean success = TRUE;
-  const gchar *procedure_name;
-  gint icon_type;
-  gint icon_data_length;
-  const guint8 *icon_data;
-
-  procedure_name = g_value_get_string (gimp_value_array_index (args, 0));
-  icon_type = g_value_get_enum (gimp_value_array_index (args, 1));
-  icon_data_length = g_value_get_int (gimp_value_array_index (args, 2));
-  icon_data = gimp_value_get_uint8_array (gimp_value_array_index (args, 3));
-
-  if (success)
-    {
-      GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
-
-      if (plug_in &&
-          plug_in->call_mode == GIMP_PLUG_IN_CALL_QUERY &&
-          gimp_pdb_is_canonical_procedure (procedure_name, error))
-        {
-          GimpPlugInProcedure *proc;
-
-          proc = gimp_plug_in_procedure_find (plug_in->plug_in_def->procedures,
-                                              procedure_name);
-
-          if (proc)
-            gimp_plug_in_procedure_set_icon (proc, icon_type,
-                                             icon_data, icon_data_length);
-          else
-            success = FALSE;
-        }
-      else
-        success = FALSE;
-    }
-
-  return gimp_procedure_get_return_values (procedure, success,
-                                           error ? *error : NULL);
-}
-
 static GimpValueArray *
 plugin_set_pdb_error_handler_invoker (GimpProcedure         *procedure,
                                       Gimp                  *gimp,
@@ -449,47 +403,6 @@ register_plug_in_procs (GimpPDB *pdb)
   gimp_pdb_register_procedure (pdb, procedure);
   g_object_unref (procedure);
 
-  /*
-   * gimp-plugin-icon-register
-   */
-  procedure = gimp_procedure_new (plugin_icon_register_invoker);
-  gimp_object_set_static_name (GIMP_OBJECT (procedure),
-                               "gimp-plugin-icon-register");
-  gimp_procedure_set_static_strings (procedure,
-                                     "Register an icon for a plug-in procedure.",
-                                     "This procedure installs an icon for the given procedure.",
-                                     "Michael Natterer <mitch gimp org>",
-                                     "Michael Natterer",
-                                     "2004",
-                                     NULL);
-  gimp_procedure_add_argument (procedure,
-                               gimp_param_spec_string ("procedure-name",
-                                                       "procedure name",
-                                                       "The procedure for which to install the icon",
-                                                       FALSE, FALSE, TRUE,
-                                                       NULL,
-                                                       GIMP_PARAM_READWRITE));
-  gimp_procedure_add_argument (procedure,
-                               g_param_spec_enum ("icon-type",
-                                                  "icon type",
-                                                  "The type of the icon",
-                                                  GIMP_TYPE_ICON_TYPE,
-                                                  GIMP_ICON_TYPE_ICON_NAME,
-                                                  GIMP_PARAM_READWRITE));
-  gimp_procedure_add_argument (procedure,
-                               g_param_spec_int ("icon-data-length",
-                                                 "icon data length",
-                                                 "The length of 'icon-data'",
-                                                 1, G_MAXINT32, 1,
-                                                 GIMP_PARAM_READWRITE));
-  gimp_procedure_add_argument (procedure,
-                               gimp_param_spec_uint8_array ("icon-data",
-                                                            "icon data",
-                                                            "The procedure's icon. The format depends on the 
'icon_type' parameter",
-                                                            GIMP_PARAM_READWRITE));
-  gimp_pdb_register_procedure (pdb, procedure);
-  g_object_unref (procedure);
-
   /*
    * gimp-plugin-set-pdb-error-handler
    */
diff --git a/app/plug-in/gimpplugin.c b/app/plug-in/gimpplugin.c
index 57f3eff5c4..aa181fa2ba 100644
--- a/app/plug-in/gimpplugin.c
+++ b/app/plug-in/gimpplugin.c
@@ -924,21 +924,70 @@ gimp_plug_in_add_proc_menu_path (GimpPlugIn  *plug_in,
       break;
     }
 
-  if (! proc->menu_label)
+  if (! gimp_plug_in_procedure_add_menu_path (proc, menu_path, &error))
+    {
+      gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
+                            error->message);
+      g_clear_error (&error);
+
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+gboolean
+gimp_plug_in_set_proc_icon (GimpPlugIn   *plug_in,
+                            const gchar  *proc_name,
+                            GimpIconType  type,
+                            const guint8 *data,
+                            gint          data_length)
+{
+  GimpPlugInProcedure *proc  = NULL;
+  GError              *error = NULL;
+
+  g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), FALSE);
+  g_return_val_if_fail (proc_name != NULL, FALSE);
+
+  if (plug_in->plug_in_def)
+    proc = gimp_plug_in_procedure_find (plug_in->plug_in_def->procedures,
+                                        proc_name);
+
+  if (! proc)
+    proc = gimp_plug_in_procedure_find (plug_in->temp_procedures, proc_name);
+
+  if (! proc)
     {
       gimp_message (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
                     "Plug-in \"%s\"\n(%s)\n"
-                    "attempted to register the procedure \"%s\" "
-                    "in the menu \"%s\", but the procedure has no label. "
+                    "attempted to set the icon "
+                    "for the procedure \"%s\".\n"
+                    "It has however not installed that procedure. "
                     "This is not allowed.",
                     gimp_object_get_name (plug_in),
                     gimp_file_get_utf8_name (plug_in->file),
-                    proc_name, menu_path);
+                    proc_name);
 
       return FALSE;
     }
 
-  if (! gimp_plug_in_procedure_add_menu_path (proc, menu_path, &error))
+  switch (GIMP_PROCEDURE (proc)->proc_type)
+    {
+    case GIMP_PDB_PROC_TYPE_INTERNAL:
+      return FALSE;
+
+    case GIMP_PDB_PROC_TYPE_PLUGIN:
+    case GIMP_PDB_PROC_TYPE_EXTENSION:
+      if (plug_in->call_mode != GIMP_PLUG_IN_CALL_QUERY &&
+          plug_in->call_mode != GIMP_PLUG_IN_CALL_INIT)
+        return FALSE;
+
+    case GIMP_PDB_PROC_TYPE_TEMPORARY:
+      break;
+    }
+
+  if (! gimp_plug_in_procedure_set_icon (proc, type, data, data_length,
+                                         &error))
     {
       gimp_message_literal (plug_in->manager->gimp, NULL, GIMP_MESSAGE_ERROR,
                             error->message);
diff --git a/app/plug-in/gimpplugin.h b/app/plug-in/gimpplugin.h
index 659f70ca28..82949061d5 100644
--- a/app/plug-in/gimpplugin.h
+++ b/app/plug-in/gimpplugin.h
@@ -108,6 +108,11 @@ const gchar * gimp_plug_in_get_undo_desc      (GimpPlugIn             *plug_in);
 gboolean      gimp_plug_in_add_proc_menu_path (GimpPlugIn             *plug_in,
                                                const gchar            *proc_name,
                                                const gchar            *menu_path);
+gboolean      gimp_plug_in_set_proc_icon      (GimpPlugIn             *plug_in,
+                                               const gchar            *proc_name,
+                                               GimpIconType            type,
+                                               const guint8           *data,
+                                               gint                    data_length);
 
 void          gimp_plug_in_add_temp_proc      (GimpPlugIn             *plug_in,
                                                GimpTemporaryProcedure *procedure);
diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c
index 2e9e9fe542..92cc5274aa 100644
--- a/app/plug-in/gimppluginprocedure.c
+++ b/app/plug-in/gimppluginprocedure.c
@@ -818,30 +818,31 @@ gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure  *proc,
   return FALSE;
 }
 
-void
-gimp_plug_in_procedure_set_icon (GimpPlugInProcedure *proc,
-                                 GimpIconType         icon_type,
-                                 const guint8        *icon_data,
-                                 gint                 icon_data_length)
+gboolean
+gimp_plug_in_procedure_set_icon (GimpPlugInProcedure  *proc,
+                                 GimpIconType          icon_type,
+                                 const guint8         *icon_data,
+                                 gint                  icon_data_length,
+                                 GError              **error)
 {
-  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
-
-  gimp_plug_in_procedure_take_icon (proc, icon_type,
-                                    g_memdup (icon_data, icon_data_length),
-                                    icon_data_length);
+  return gimp_plug_in_procedure_take_icon (proc, icon_type,
+                                           g_memdup (icon_data, icon_data_length),
+                                           icon_data_length, error);
 }
 
-void
-gimp_plug_in_procedure_take_icon (GimpPlugInProcedure *proc,
-                                  GimpIconType         icon_type,
-                                  guint8              *icon_data,
-                                  gint                 icon_data_length)
+gboolean
+gimp_plug_in_procedure_take_icon (GimpPlugInProcedure  *proc,
+                                  GimpIconType          icon_type,
+                                  guint8               *icon_data,
+                                  gint                  icon_data_length,
+                                  GError              **error)
 {
   const gchar *icon_name   = NULL;
   GdkPixbuf   *icon_pixbuf = NULL;
-  GError      *error       = NULL;
+  gboolean     success     = TRUE;
 
-  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
+  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
   if (proc->icon_data)
     {
@@ -869,15 +870,26 @@ gimp_plug_in_procedure_take_icon (GimpPlugInProcedure *proc,
 
       loader = gdk_pixbuf_loader_new ();
 
-      gdk_pixbuf_loader_write (loader,
-                               proc->icon_data,
-                               proc->icon_data_length,
-                               NULL);
-      gdk_pixbuf_loader_close (loader, NULL);
-      icon_pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+      if (! gdk_pixbuf_loader_write (loader,
+                                     proc->icon_data,
+                                     proc->icon_data_length,
+                                     error))
+        {
+          gdk_pixbuf_loader_close (loader, NULL);
+          success = FALSE;
+        }
+      else if (! gdk_pixbuf_loader_close (loader, error))
+        {
+          success = FALSE;
+        }
 
-      if (icon_pixbuf)
-        g_object_ref (icon_pixbuf);
+      if (success)
+        {
+          icon_pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+
+          if (icon_pixbuf)
+            g_object_ref (icon_pixbuf);
+        }
 
       g_object_unref (loader);
       break;
@@ -887,14 +899,11 @@ gimp_plug_in_procedure_take_icon (GimpPlugInProcedure *proc,
       proc->icon_data        = icon_data;
 
       icon_pixbuf = gdk_pixbuf_new_from_file ((gchar *) proc->icon_data,
-                                              &error);
-      break;
-    }
+                                              error);
 
-  if (! icon_pixbuf && error)
-    {
-      g_printerr ("%s: %s\n", G_STRFUNC, error->message);
-      g_clear_error (&error);
+      if (! icon_pixbuf)
+        success = FALSE;
+      break;
     }
 
   gimp_viewable_set_icon_name (GIMP_VIEWABLE (proc), icon_name);
@@ -902,6 +911,8 @@ gimp_plug_in_procedure_take_icon (GimpPlugInProcedure *proc,
 
   if (icon_pixbuf)
     g_object_unref (icon_pixbuf);
+
+  return success;
 }
 
 static GimpPlugInImageType
diff --git a/app/plug-in/gimppluginprocedure.h b/app/plug-in/gimppluginprocedure.h
index 2c0348a965..bf61358710 100644
--- a/app/plug-in/gimppluginprocedure.h
+++ b/app/plug-in/gimppluginprocedure.h
@@ -111,14 +111,16 @@ gboolean      gimp_plug_in_procedure_add_menu_path     (GimpPlugInProcedure *pro
                                                         const gchar         *menu_path,
                                                         GError             **error);
 
-void          gimp_plug_in_procedure_set_icon          (GimpPlugInProcedure *proc,
+gboolean      gimp_plug_in_procedure_set_icon          (GimpPlugInProcedure *proc,
                                                         GimpIconType         type,
                                                         const guint8        *data,
-                                                        gint                 data_length);
-void          gimp_plug_in_procedure_take_icon         (GimpPlugInProcedure *proc,
+                                                        gint                 data_length,
+                                                        GError             **error);
+gboolean      gimp_plug_in_procedure_take_icon         (GimpPlugInProcedure *proc,
                                                         GimpIconType         type,
                                                         guint8              *data,
-                                                        gint                 data_length);
+                                                        gint                 data_length,
+                                                        GError             **error);
 
 void          gimp_plug_in_procedure_set_image_types   (GimpPlugInProcedure *proc,
                                                         const gchar         *image_types);
diff --git a/app/plug-in/plug-in-rc.c b/app/plug-in/plug-in-rc.c
index 73d32eb6c5..5370338730 100644
--- a/app/plug-in/plug-in-rc.c
+++ b/app/plug-in/plug-in-rc.c
@@ -593,7 +593,8 @@ plug_in_icon_deserialize (GScanner            *scanner,
     }
 
   gimp_plug_in_procedure_take_icon (proc, icon_type,
-                                    icon_data, icon_data_length);
+                                    icon_data, icon_data_length,
+                                    NULL);
 
   if (! gimp_scanner_parse_token (scanner, G_TOKEN_RIGHT_PAREN))
     return G_TOKEN_RIGHT_PAREN;
diff --git a/app/xcf/xcf.c b/app/xcf/xcf.c
index c855d135f7..7864cfc130 100644
--- a/app/xcf/xcf.c
+++ b/app/xcf/xcf.c
@@ -114,7 +114,8 @@ xcf_init (Gimp *gimp)
   proc->menu_label = g_strdup (N_("GIMP XCF image"));
   gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_ICON_NAME,
                                    (const guint8 *) "gimp-wilber",
-                                   strlen ("gimp-wilber") + 1);
+                                   strlen ("gimp-wilber") + 1,
+                                   NULL);
   gimp_plug_in_procedure_set_image_types (proc, "RGB*, GRAY*, INDEXED*");
   gimp_plug_in_procedure_set_file_proc (proc, "xcf", "", NULL);
   gimp_plug_in_procedure_set_mime_types (proc, "image/x-xcf");
@@ -185,7 +186,8 @@ xcf_init (Gimp *gimp)
   proc->menu_label = g_strdup (N_("GIMP XCF image"));
   gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_ICON_NAME,
                                    (const guint8 *) "gimp-wilber",
-                                   strlen ("gimp-wilber") + 1);
+                                   strlen ("gimp-wilber") + 1,
+                                   NULL);
   gimp_plug_in_procedure_set_image_types (proc, NULL);
   gimp_plug_in_procedure_set_file_proc (proc, "xcf", "",
                                         "0,string,gimp\\040xcf\\040");
diff --git a/libgimp/gimppdb_pdb.c b/libgimp/gimppdb_pdb.c
index 2c9edfe3c1..7ddcf37630 100644
--- a/libgimp/gimppdb_pdb.c
+++ b/libgimp/gimppdb_pdb.c
@@ -422,6 +422,51 @@ _gimp_pdb_get_proc_menu_paths (const gchar *procedure_name,
   return menu_paths;
 }
 
+/**
+ * _gimp_pdb_set_proc_icon:
+ * @procedure_name: The procedure for which to install the icon.
+ * @icon_type: The type of the icon.
+ * @icon_data_length: The length of 'icon-data'.
+ * @icon_data: (array length=icon_data_length) (element-type guint8): The procedure's icon. The format 
depends on the 'icon_type' parameter.
+ *
+ * Register an icon for a plug-in procedure.
+ *
+ * This procedure installs an icon for the given procedure.
+ *
+ * Returns: TRUE on success.
+ *
+ * Since: 3.0
+ **/
+gboolean
+_gimp_pdb_set_proc_icon (const gchar  *procedure_name,
+                         GimpIconType  icon_type,
+                         gint          icon_data_length,
+                         const guint8 *icon_data)
+{
+  GimpValueArray *args;
+  GimpValueArray *return_vals;
+  gboolean success = TRUE;
+
+  args = gimp_value_array_new_from_types (NULL,
+                                          G_TYPE_STRING, procedure_name,
+                                          GIMP_TYPE_ICON_TYPE, icon_type,
+                                          G_TYPE_INT, icon_data_length,
+                                          GIMP_TYPE_UINT8_ARRAY, NULL,
+                                          G_TYPE_NONE);
+  gimp_value_set_uint8_array (gimp_value_array_index (args, 3), icon_data, icon_data_length);
+
+  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
+                                              "gimp-pdb-set-proc-icon",
+                                              args);
+  gimp_value_array_unref (args);
+
+  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
+
+  gimp_value_array_unref (return_vals);
+
+  return success;
+}
+
 /**
  * _gimp_pdb_get_proc_documentation:
  * @procedure_name: The procedure name.
diff --git a/libgimp/gimppdb_pdb.h b/libgimp/gimppdb_pdb.h
index 43b0faca79..d4d2f535b0 100644
--- a/libgimp/gimppdb_pdb.h
+++ b/libgimp/gimppdb_pdb.h
@@ -54,6 +54,10 @@ G_GNUC_INTERNAL gboolean    _gimp_pdb_add_proc_menu_path     (const gchar
                                                               const gchar       *menu_path);
 G_GNUC_INTERNAL gchar**     _gimp_pdb_get_proc_menu_paths    (const gchar       *procedure_name,
                                                               gint              *num_menu_paths);
+G_GNUC_INTERNAL gboolean    _gimp_pdb_set_proc_icon          (const gchar       *procedure_name,
+                                                              GimpIconType       icon_type,
+                                                              gint               icon_data_length,
+                                                              const guint8      *icon_data);
 G_GNUC_INTERNAL gboolean    _gimp_pdb_get_proc_documentation (const gchar       *procedure_name,
                                                               gchar            **blurb,
                                                               gchar            **help,
diff --git a/libgimp/gimpplugin_pdb.c b/libgimp/gimpplugin_pdb.c
index 4732bf608f..114c4a7b64 100644
--- a/libgimp/gimpplugin_pdb.c
+++ b/libgimp/gimpplugin_pdb.c
@@ -149,51 +149,6 @@ _gimp_plugin_menu_branch_register (const gchar *menu_path,
   return success;
 }
 
-/**
- * _gimp_plugin_icon_register:
- * @procedure_name: The procedure for which to install the icon.
- * @icon_type: The type of the icon.
- * @icon_data_length: The length of 'icon-data'.
- * @icon_data: (array length=icon_data_length) (element-type guint8): The procedure's icon. The format 
depends on the 'icon_type' parameter.
- *
- * Register an icon for a plug-in procedure.
- *
- * This procedure installs an icon for the given procedure.
- *
- * Returns: TRUE on success.
- *
- * Since: 2.2
- **/
-gboolean
-_gimp_plugin_icon_register (const gchar  *procedure_name,
-                            GimpIconType  icon_type,
-                            gint          icon_data_length,
-                            const guint8 *icon_data)
-{
-  GimpValueArray *args;
-  GimpValueArray *return_vals;
-  gboolean success = TRUE;
-
-  args = gimp_value_array_new_from_types (NULL,
-                                          G_TYPE_STRING, procedure_name,
-                                          GIMP_TYPE_ICON_TYPE, icon_type,
-                                          G_TYPE_INT, icon_data_length,
-                                          GIMP_TYPE_UINT8_ARRAY, NULL,
-                                          G_TYPE_NONE);
-  gimp_value_set_uint8_array (gimp_value_array_index (args, 3), icon_data, icon_data_length);
-
-  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
-                                              "gimp-plugin-icon-register",
-                                              args);
-  gimp_value_array_unref (args);
-
-  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
-
-  gimp_value_array_unref (return_vals);
-
-  return success;
-}
-
 /**
  * _gimp_plugin_set_pdb_error_handler:
  * @handler: Who is responsible for handling procedure call errors.
diff --git a/libgimp/gimpplugin_pdb.h b/libgimp/gimpplugin_pdb.h
index 2fe7a15295..e5dcd1b289 100644
--- a/libgimp/gimpplugin_pdb.h
+++ b/libgimp/gimpplugin_pdb.h
@@ -38,10 +38,6 @@ G_GNUC_INTERNAL gboolean            _gimp_plugin_help_register         (const gc
                                                                         const gchar         *domain_uri);
 G_GNUC_INTERNAL gboolean            _gimp_plugin_menu_branch_register  (const gchar         *menu_path,
                                                                         const gchar         *menu_name);
-G_GNUC_INTERNAL gboolean            _gimp_plugin_icon_register         (const gchar         *procedure_name,
-                                                                        GimpIconType         icon_type,
-                                                                        gint                 
icon_data_length,
-                                                                        const guint8        *icon_data);
 G_GNUC_INTERNAL gboolean            _gimp_plugin_set_pdb_error_handler (GimpPDBErrorHandler  handler);
 G_GNUC_INTERNAL GimpPDBErrorHandler _gimp_plugin_get_pdb_error_handler (void);
 
diff --git a/libgimp/gimpprocedure.c b/libgimp/gimpprocedure.c
index 5852141470..8266d55581 100644
--- a/libgimp/gimpprocedure.c
+++ b/libgimp/gimpprocedure.c
@@ -289,57 +289,11 @@ gimp_procedure_get_property (GObject    *object,
 }
 
 static void
-gimp_procedure_real_install (GimpProcedure *procedure)
+gimp_procedure_install_icon (GimpProcedure *procedure)
 {
-  GParamSpec   **args;
-  GParamSpec   **return_vals;
-  gint           n_args        = 0;
-  gint           n_return_vals = 0;
-  GList         *list;
-  GimpPlugIn    *plug_in;
-  GPProcInstall  proc_install;
-  GimpIconType   icon_type;
-  guint8        *icon_data        = NULL;
-  gsize          icon_data_length = 0;
-  gint           i;
-
-  g_return_if_fail (procedure->priv->installed == FALSE);
-
-  args        = gimp_procedure_get_arguments (procedure, &n_args);
-  return_vals = gimp_procedure_get_return_values (procedure, &n_return_vals);
-
-  proc_install.name         = (gchar *) gimp_procedure_get_name (procedure);
-  proc_install.blurb        = (gchar *) gimp_procedure_get_blurb (procedure);
-  proc_install.help         = (gchar *) gimp_procedure_get_help (procedure);
-  proc_install.help_id      = (gchar *) gimp_procedure_get_help_id (procedure);
-  proc_install.authors      = (gchar *) gimp_procedure_get_authors (procedure);
-  proc_install.copyright    = (gchar *) gimp_procedure_get_copyright (procedure);
-  proc_install.date         = (gchar *) gimp_procedure_get_date (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.type         = gimp_procedure_get_proc_type (procedure);
-  proc_install.nparams      = n_args;
-  proc_install.nreturn_vals = n_return_vals;
-  proc_install.params       = g_new0 (GPParamDef, n_args);
-  proc_install.return_vals  = g_new0 (GPParamDef, n_return_vals);
-
-  for (i = 0; i < n_args; i++)
-    {
-      _gimp_param_spec_to_gp_param_def (args[i],
-                                        &proc_install.params[i]);
-    }
-
-  for (i = 0; i < n_return_vals; i++)
-    {
-      _gimp_param_spec_to_gp_param_def (return_vals[i],
-                                        &proc_install.return_vals[i]);
-    }
-
-  plug_in = gimp_procedure_get_plug_in (procedure);
-
-  if (! gp_proc_install_write (_gimp_plug_in_get_write_channel (plug_in),
-                               &proc_install, plug_in))
-    gimp_quit ();
+  GimpIconType  icon_type;
+  guint8       *icon_data        = NULL;
+  gsize         icon_data_length = 0;
 
   icon_type = gimp_procedure_get_icon_type (procedure);
 
@@ -378,8 +332,8 @@ gimp_procedure_real_install (GimpProcedure *procedure)
     }
 
   if (icon_data)
-    _gimp_plugin_icon_register (gimp_procedure_get_name (procedure),
-                                icon_type, icon_data_length, icon_data);
+    _gimp_pdb_set_proc_icon (gimp_procedure_get_name (procedure),
+                             icon_type, icon_data_length, icon_data);
 
   switch (icon_type)
     {
@@ -391,10 +345,63 @@ gimp_procedure_real_install (GimpProcedure *procedure)
       g_free (icon_data);
       break;
     }
+}
+
+static void
+gimp_procedure_real_install (GimpProcedure *procedure)
+{
+  GParamSpec   **args;
+  GParamSpec   **return_vals;
+  gint           n_args        = 0;
+  gint           n_return_vals = 0;
+  GList         *list;
+  GimpPlugIn    *plug_in;
+  GPProcInstall  proc_install;
+  gint           i;
+
+  g_return_if_fail (procedure->priv->installed == FALSE);
+
+  args        = gimp_procedure_get_arguments (procedure, &n_args);
+  return_vals = gimp_procedure_get_return_values (procedure, &n_return_vals);
+
+  proc_install.name         = (gchar *) gimp_procedure_get_name (procedure);
+  proc_install.blurb        = (gchar *) gimp_procedure_get_blurb (procedure);
+  proc_install.help         = (gchar *) gimp_procedure_get_help (procedure);
+  proc_install.help_id      = (gchar *) gimp_procedure_get_help_id (procedure);
+  proc_install.authors      = (gchar *) gimp_procedure_get_authors (procedure);
+  proc_install.copyright    = (gchar *) gimp_procedure_get_copyright (procedure);
+  proc_install.date         = (gchar *) gimp_procedure_get_date (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.type         = gimp_procedure_get_proc_type (procedure);
+  proc_install.nparams      = n_args;
+  proc_install.nreturn_vals = n_return_vals;
+  proc_install.params       = g_new0 (GPParamDef, n_args);
+  proc_install.return_vals  = g_new0 (GPParamDef, n_return_vals);
+
+  for (i = 0; i < n_args; i++)
+    {
+      _gimp_param_spec_to_gp_param_def (args[i],
+                                        &proc_install.params[i]);
+    }
+
+  for (i = 0; i < n_return_vals; i++)
+    {
+      _gimp_param_spec_to_gp_param_def (return_vals[i],
+                                        &proc_install.return_vals[i]);
+    }
+
+  plug_in = gimp_procedure_get_plug_in (procedure);
+
+  if (! gp_proc_install_write (_gimp_plug_in_get_write_channel (plug_in),
+                               &proc_install, plug_in))
+    gimp_quit ();
 
   g_free (proc_install.params);
   g_free (proc_install.return_vals);
 
+  gimp_procedure_install_icon (procedure);
+
   for (list = gimp_procedure_get_menu_paths (procedure);
        list;
        list = g_list_next (list))
@@ -1642,6 +1649,9 @@ gimp_procedure_set_icon (GimpProcedure *procedure,
     default:
       g_return_if_reached ();
     }
+
+  if (procedure->priv->installed)
+    gimp_procedure_install_icon (procedure);
 }
 
 
diff --git a/pdb/groups/pdb.pdb b/pdb/groups/pdb.pdb
index 0a30ac67a5..d000e8d4e1 100644
--- a/pdb/groups/pdb.pdb
+++ b/pdb/groups/pdb.pdb
@@ -437,6 +437,48 @@ CODE
     );
 }
 
+sub pdb_set_proc_icon {
+    $blurb = "Register an icon for a plug-in procedure.";
+
+    $help = <<HELP;
+This procedure installs an icon for the given procedure.
+HELP
+
+    &mitch_pdb_misc('2019', '3.0');
+
+    $lib_private = 1;
+
+    @inargs = (
+       { name => 'procedure_name', type => 'string', non_empty => 1,
+         desc => 'The procedure for which to install the icon' },
+        { name => 'icon_type', type => 'enum GimpIconType',
+          desc => 'The type of the icon' },
+       { name => 'icon_data', type => 'int8array',
+         desc => "The procedure's icon. The format depends on the
+                   'icon_type' parameter",
+         array => { name => 'icon_data_length', type => '1 <= int32',
+                     desc => "The length of 'icon-data'" } }
+    );
+
+    %invoke = (
+        code => <<'CODE'
+{
+  GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
+
+  if (plug_in &&
+      gimp_pdb_is_canonical_procedure (procedure_name, error))
+    {
+      success = gimp_plug_in_set_proc_icon (plug_in, procedure_name,
+                                            icon_type,
+                                            icon_data, icon_data_length);
+    }
+  else
+    success = FALSE;
+}
+CODE
+    );
+}
+
 sub pdb_get_proc_documentation {
     $blurb = <<'BLURB';
 Queries the procedural database for documentation on the specified procedure.
@@ -813,6 +855,7 @@ CODE
             pdb_get_proc_menu_label
             pdb_add_proc_menu_path
             pdb_get_proc_menu_paths
+            pdb_set_proc_icon
             pdb_get_proc_documentation
             pdb_get_proc_attribution
             pdb_get_proc_argument
diff --git a/pdb/groups/plug_in.pdb b/pdb/groups/plug_in.pdb
index d515ab8aec..259559d840 100644
--- a/pdb/groups/plug_in.pdb
+++ b/pdb/groups/plug_in.pdb
@@ -183,56 +183,6 @@ CODE
     );
 }
 
-sub plugin_icon_register {
-    $blurb = "Register an icon for a plug-in procedure.";
-
-    $help = <<HELP;
-This procedure installs an icon for the given procedure.
-HELP
-
-    &mitch_pdb_misc('2004', '2.2');
-
-    $lib_private = 1;
-
-    @inargs = (
-       { name => 'procedure_name', type => 'string', non_empty => 1,
-         desc => 'The procedure for which to install the icon' },
-        { name => 'icon_type', type => 'enum GimpIconType',
-          desc => 'The type of the icon' },
-       { name => 'icon_data', type => 'int8array',
-         desc => "The procedure's icon. The format depends on the
-                   'icon_type' parameter",
-         array => { name => 'icon_data_length', type => '1 <= int32',
-                     desc => "The length of 'icon-data'" } }
-    );
-
-    %invoke = (
-        code => <<'CODE'
-{
-  GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
-
-  if (plug_in &&
-      plug_in->call_mode == GIMP_PLUG_IN_CALL_QUERY &&
-      gimp_pdb_is_canonical_procedure (procedure_name, error))
-    {
-      GimpPlugInProcedure *proc;
-
-      proc = gimp_plug_in_procedure_find (plug_in->plug_in_def->procedures,
-                                          procedure_name);
-
-      if (proc)
-        gimp_plug_in_procedure_set_icon (proc, icon_type,
-                                         icon_data, icon_data_length);
-      else
-        success = FALSE;
-    }
-  else
-    success = FALSE;
-}
-CODE
-    );
-}
-
 sub plugin_set_pdb_error_handler {
     $blurb = "Sets an error handler for procedure calls.";
 
@@ -322,11 +272,10 @@ CODE
            plugin_domain_register
             plugin_help_register
             plugin_menu_branch_register
-            plugin_icon_register
             plugin_set_pdb_error_handler
             plugin_get_pdb_error_handler);
 
-%exports = (app => [@procs], lib => [@procs[1,2,3,4,5,6]]);
+%exports = (app => [@procs], lib => [@procs[1,2,3,4,5]]);
 
 $desc = 'Plug-in';
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]