[gimp] libgimp: add more registering API to GimpPlugIn and GimpProcedure



commit 7a9e0d984e9a2227edd21084aba2ce934c98d5cf
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jul 30 19:21:57 2019 +0200

    libgimp: add more registering API to GimpPlugIn and GimpProcedure
    
    Icon, menu branch, translation domain and help domain can now be
    registered using the objects' API instead of the direct PDB calls.

 libgimp/gimp.def                |  6 +++
 libgimp/gimpplugin-private.c    | 81 ++++++++++++++++++++++++++++-------------
 libgimp/gimpplugin-private.h    | 22 +++++++++++
 libgimp/gimpplugin.c            | 75 +++++++++++++++++++++++++++++++++++---
 libgimp/gimpplugin.h            | 37 ++++++++++++-------
 libgimp/gimpprocedure-private.c |  9 +++++
 libgimp/gimpprocedure.c         | 62 +++++++++++++++++++++++++++++++
 libgimp/gimpprocedure.h         |  7 ++++
 8 files changed, 254 insertions(+), 45 deletions(-)
---
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 91feddfa9e..cfeb7256d7 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -618,6 +618,7 @@ EXPORTS
        gimp_patterns_refresh
        gimp_patterns_set_popup
        gimp_pencil
+       gimp_plug_in_add_menu_branch
        gimp_plug_in_add_procedure
        gimp_plug_in_create_procedure
        gimp_plug_in_get_procedure
@@ -625,6 +626,8 @@ EXPORTS
        gimp_plug_in_get_type
        gimp_plug_in_info_set_callbacks
        gimp_plug_in_remove_procedure
+       gimp_plug_in_set_help_domain
+       gimp_plug_in_set_translation_domain
        gimp_plugin_domain_register
        gimp_plugin_get_pdb_error_handler
        gimp_plugin_help_register
@@ -652,6 +655,7 @@ EXPORTS
        gimp_procedure_get_date
        gimp_procedure_get_help
        gimp_procedure_get_help_id
+       gimp_procedure_get_icon
        gimp_procedure_get_image_types
        gimp_procedure_get_menu_label
        gimp_procedure_get_menu_paths
@@ -662,6 +666,7 @@ EXPORTS
        gimp_procedure_new_arguments
        gimp_procedure_new_return_values
        gimp_procedure_run
+       gimp_procedure_set_icon
        gimp_procedure_set_strings
        gimp_progress_cancel
        gimp_progress_end
@@ -686,6 +691,7 @@ EXPORTS
        gimp_register_thumbnail_loader
        gimp_run_procedure
        gimp_run_procedure2
+       gimp_run_procedure_with_array
        gimp_selection_all
        gimp_selection_border
        gimp_selection_bounds
diff --git a/libgimp/gimpplugin-private.c b/libgimp/gimpplugin-private.c
index e9ca4f39dc..b5bea60244 100644
--- a/libgimp/gimpplugin-private.c
+++ b/libgimp/gimpplugin-private.c
@@ -25,45 +25,55 @@
 #include "gimpprocedure-private.h"
 
 
+/*  local function prototpes  */
+
+static void   gimp_plug_in_register (GimpPlugIn *plug_in);
+
+
 /*  public functions  */
 
 void
 _gimp_plug_in_init (GimpPlugIn *plug_in)
 {
-  gchar **procedures;
-  gint    n_procedures;
-  gint    i;
-
   g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
 
   if (! GIMP_PLUG_IN_GET_CLASS (plug_in)->init_procedures)
     return;
 
-  procedures = GIMP_PLUG_IN_GET_CLASS (plug_in)->init_procedures (plug_in,
-                                                                  &n_procedures);
-
-  for (i = 0; i < n_procedures; i++)
-    {
-      GimpProcedure *procedure;
-
-      procedure = gimp_plug_in_create_procedure (plug_in, procedures[i]);
-      _gimp_procedure_register (procedure);
-      g_object_unref (procedure);
-    }
+  gimp_plug_in_register (plug_in);
 }
 
 void
 _gimp_plug_in_query (GimpPlugIn *plug_in)
 {
-  gchar **procedures;
-  gint    n_procedures;
-  gint    i;
-
   g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
 
   if (! GIMP_PLUG_IN_GET_CLASS (plug_in)->query_procedures)
     return;
 
+  gimp_plug_in_register (plug_in);
+}
+
+void
+_gimp_plug_in_quit (GimpPlugIn *plug_in)
+{
+  g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
+
+  if (GIMP_PLUG_IN_GET_CLASS (plug_in)->quit)
+    GIMP_PLUG_IN_GET_CLASS (plug_in)->quit (plug_in);
+}
+
+
+/*  private functions  */
+
+static void
+gimp_plug_in_register (GimpPlugIn *plug_in)
+{
+  gchar **procedures;
+  gint    n_procedures;
+  gint    i;
+  GList  *list;
+
   procedures = GIMP_PLUG_IN_GET_CLASS (plug_in)->query_procedures (plug_in,
                                                                    &n_procedures);
 
@@ -75,13 +85,32 @@ _gimp_plug_in_query (GimpPlugIn *plug_in)
       _gimp_procedure_register (procedure);
       g_object_unref (procedure);
     }
-}
 
-void
-_gimp_plug_in_quit (GimpPlugIn *plug_in)
-{
-  g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
+  if (plug_in->priv->translation_domain_name)
+    {
+      gchar *path = g_file_get_path (plug_in->priv->translation_domain_path);
 
-  if (GIMP_PLUG_IN_GET_CLASS (plug_in)->quit)
-    GIMP_PLUG_IN_GET_CLASS (plug_in)->quit (plug_in);
+      gimp_plugin_domain_register (plug_in->priv->translation_domain_name,
+                                   path);
+
+      g_free (path);
+    }
+
+  if (plug_in->priv->help_domain_name)
+    {
+      gchar *uri = g_file_get_uri (plug_in->priv->help_domain_uri);
+
+      gimp_plugin_domain_register (plug_in->priv->help_domain_name,
+                                   uri);
+
+      g_free (uri);
+    }
+
+  for (list = plug_in->priv->menu_branches; list; list = g_list_next (list))
+    {
+      GimpPlugInMenuBranch *branch = list->data;
+
+      gimp_plugin_menu_branch_register (branch->menu_path,
+                                        branch->menu_label);
+    }
 }
diff --git a/libgimp/gimpplugin-private.h b/libgimp/gimpplugin-private.h
index ce1270ebea..cf1d0a52ad 100644
--- a/libgimp/gimpplugin-private.h
+++ b/libgimp/gimpplugin-private.h
@@ -24,6 +24,28 @@
 G_BEGIN_DECLS
 
 
+typedef struct _GimpPlugInMenuBranch GimpPlugInMenuBranch;
+
+struct _GimpPlugInMenuBranch
+{
+  gchar *menu_path;
+  gchar *menu_label;
+};
+
+struct _GimpPlugInPrivate
+{
+  GList *procedures;
+
+  gchar *translation_domain_name;
+  GFile *translation_domain_path;
+
+  gchar *help_domain_name;
+  GFile *help_domain_uri;
+
+  GList *menu_branches;
+};
+
+
 void   _gimp_plug_in_init  (GimpPlugIn *plug_in);
 void   _gimp_plug_in_query (GimpPlugIn *plug_in);
 void   _gimp_plug_in_quit  (GimpPlugIn *plug_in);
diff --git a/libgimp/gimpplugin.c b/libgimp/gimpplugin.c
index df049f2eaa..591875802c 100644
--- a/libgimp/gimpplugin.c
+++ b/libgimp/gimpplugin.c
@@ -23,6 +23,7 @@
 #include <string.h>
 
 #include "gimp.h"
+#include "gimpplugin-private.h"
 
 
 /**
@@ -37,12 +38,6 @@
  **/
 
 
-struct _GimpPlugInPrivate
-{
-  GList *procedures;
-};
-
-
 static void   gimp_plug_in_finalize (GObject *object);
 
 
@@ -69,6 +64,7 @@ static void
 gimp_plug_in_finalize (GObject *object)
 {
   GimpPlugIn *plug_in = GIMP_PLUG_IN (object);
+  GList      *list;
 
   if (plug_in->priv->procedures)
     {
@@ -76,12 +72,79 @@ gimp_plug_in_finalize (GObject *object)
       plug_in->priv->procedures = NULL;
     }
 
+  g_clear_pointer (&plug_in->priv->translation_domain_name, g_free);
+  g_clear_object  (&plug_in->priv->translation_domain_path);
+
+  g_clear_pointer (&plug_in->priv->help_domain_name, g_free);
+  g_clear_object  (&plug_in->priv->help_domain_uri);
+
+  for (list = plug_in->priv->menu_branches; list; list = g_list_next (list))
+    {
+      GimpPlugInMenuBranch *branch = list->data;
+
+      g_free (branch->menu_path);
+      g_free (branch->menu_label);
+      g_slice_free (GimpPlugInMenuBranch, branch);
+    }
+
+  g_clear_pointer (&plug_in->priv->menu_branches, g_list_free);
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 
 /*  public functions  */
 
+void
+gimp_plug_in_set_translation_domain (GimpPlugIn  *plug_in,
+                                     const gchar *domain_name,
+                                     GFile       *domain_path)
+{
+  g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
+  g_return_if_fail (domain_name != NULL);
+  g_return_if_fail (G_IS_FILE (domain_path));
+
+  g_free (plug_in->priv->translation_domain_name);
+  plug_in->priv->translation_domain_name = g_strdup (domain_name);
+
+  g_set_object (&plug_in->priv->translation_domain_path, domain_path);
+}
+
+void
+gimp_plug_in_set_help_domain (GimpPlugIn  *plug_in,
+                              const gchar *domain_name,
+                              GFile       *domain_uri)
+{
+  g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
+  g_return_if_fail (domain_name != NULL);
+  g_return_if_fail (G_IS_FILE (domain_uri));
+
+  g_free (plug_in->priv->help_domain_name);
+  plug_in->priv->help_domain_name = g_strdup (domain_name);
+
+  g_set_object (&plug_in->priv->help_domain_uri, domain_uri);
+}
+
+void
+gimp_plug_in_add_menu_branch (GimpPlugIn  *plug_in,
+                              const gchar *menu_path,
+                              const gchar *menu_label)
+{
+  GimpPlugInMenuBranch *branch;
+
+  g_return_if_fail (GIMP_IS_PLUG_IN (plug_in));
+  g_return_if_fail (menu_path != NULL);
+  g_return_if_fail (menu_label != NULL);
+
+  branch = g_slice_new (GimpPlugInMenuBranch);
+
+  branch->menu_path  = g_strdup (menu_path);
+  branch->menu_label = g_strdup (menu_label);
+
+  plug_in->priv->menu_branches = g_list_append (plug_in->priv->menu_branches,
+                                                branch);
+}
+
 GimpProcedure *
 gimp_plug_in_create_procedure (GimpPlugIn    *plug_in,
                                const gchar   *name)
diff --git a/libgimp/gimpplugin.h b/libgimp/gimpplugin.h
index c87dd25d02..a92305c1d2 100644
--- a/libgimp/gimpplugin.h
+++ b/libgimp/gimpplugin.h
@@ -74,19 +74,30 @@ struct _GimpPlugInClass
 };
 
 
-GType           gimp_plug_in_get_type         (void) G_GNUC_CONST;
-
-GimpProcedure * gimp_plug_in_create_procedure (GimpPlugIn    *plug_in,
-                                               const gchar   *name);
-
-void            gimp_plug_in_add_procedure    (GimpPlugIn    *plug_in,
-                                               GimpProcedure *procedure);
-void            gimp_plug_in_remove_procedure (GimpPlugIn    *plug_in,
-                                               const gchar   *name);
-
-GList         * gimp_plug_in_get_procedures   (GimpPlugIn   *plug_in);
-GimpProcedure * gimp_plug_in_get_procedure    (GimpPlugIn   *plug_in,
-                                               const gchar  *name);
+GType           gimp_plug_in_get_type               (void) G_GNUC_CONST;
+
+void            gimp_plug_in_set_translation_domain (GimpPlugIn    *plug_in,
+                                                     const gchar   *domain_name,
+                                                     GFile         *domain_path);
+void            gimp_plug_in_set_help_domain        (GimpPlugIn    *plug_in,
+                                                     const gchar   *domain_name,
+                                                     GFile         *domain_uri);
+
+void            gimp_plug_in_add_menu_branch        (GimpPlugIn    *plug_in,
+                                                     const gchar   *menu_path,
+                                                     const gchar   *menu_label);
+
+GimpProcedure * gimp_plug_in_create_procedure       (GimpPlugIn    *plug_in,
+                                                     const gchar   *name);
+
+void            gimp_plug_in_add_procedure          (GimpPlugIn    *plug_in,
+                                                     GimpProcedure *procedure);
+void            gimp_plug_in_remove_procedure       (GimpPlugIn    *plug_in,
+                                                     const gchar   *name);
+
+GList         * gimp_plug_in_get_procedures         (GimpPlugIn    *plug_in);
+GimpProcedure * gimp_plug_in_get_procedure          (GimpPlugIn    *plug_in,
+                                                     const gchar   *name);
 
 
 /*  unrelated old API  */
diff --git a/libgimp/gimpprocedure-private.c b/libgimp/gimpprocedure-private.c
index 2be6a39b58..65c2d71403 100644
--- a/libgimp/gimpprocedure-private.c
+++ b/libgimp/gimpprocedure-private.c
@@ -47,6 +47,9 @@ _gimp_procedure_register (GimpProcedure *procedure)
   gint           n_return_vals;
   GList         *list;
   GPProcInstall  proc_install;
+  GimpIconType   icon_type;
+  const guint8  *icon_data;
+  gint           icon_data_length;
   gint           i;
 
   g_return_if_fail (GIMP_IS_PROCEDURE (procedure));
@@ -83,6 +86,12 @@ _gimp_procedure_register (GimpProcedure *procedure)
   if (! gp_proc_install_write (_writechannel, &proc_install, NULL))
     gimp_quit ();
 
+  icon_type = gimp_procedure_get_icon (procedure,
+                                       &icon_data, &icon_data_length);
+  if (icon_data)
+    _gimp_plugin_icon_register (gimp_procedure_get_name (procedure),
+                                icon_type, icon_data_length, icon_data);
+
   g_free (proc_install.params);
   g_free (proc_install.return_vals);
 
diff --git a/libgimp/gimpprocedure.c b/libgimp/gimpprocedure.c
index cc46ec90cc..4309313cc7 100644
--- a/libgimp/gimpprocedure.c
+++ b/libgimp/gimpprocedure.c
@@ -61,6 +61,10 @@ struct _GimpProcedurePrivate
   gchar            *date;           /* Date field                     */
   gchar            *image_types;
 
+  GimpIconType      icon_type;
+  guint8           *icon_data;
+  gint              icon_data_length;
+
   GList            *menu_paths;
 
   gint32            n_args;         /* Number of procedure arguments  */
@@ -113,6 +117,9 @@ gimp_procedure_finalize (GObject *object)
 
   gimp_procedure_free_strings (procedure);
 
+  g_clear_pointer (&procedure->priv->icon_data, g_free);
+  procedure->priv->icon_data_length = 0;
+
   g_list_free_full (procedure->priv->menu_paths, g_free);
   procedure->priv->menu_paths = NULL;
 
@@ -252,6 +259,61 @@ gimp_procedure_get_image_types (GimpProcedure *procedure)
   return procedure->priv->image_types;
 }
 
+void
+gimp_procedure_set_icon (GimpProcedure *procedure,
+                         GimpIconType   icon_type,
+                         const guint8  *icon_data)
+{
+  g_return_if_fail (GIMP_IS_PROCEDURE (procedure));
+  g_return_if_fail (icon_data != NULL);
+  g_return_if_fail (icon_data != procedure->priv->icon_data);
+
+  g_clear_pointer (&procedure->priv->icon_data, g_free);
+  procedure->priv->icon_data_length = 0;
+
+  procedure->priv->icon_type = icon_type;
+
+  switch (icon_type)
+    {
+    case GIMP_ICON_TYPE_ICON_NAME:
+    case GIMP_ICON_TYPE_IMAGE_FILE:
+      procedure->priv->icon_data =
+        (guint8 *) g_strdup ((const gchar *) icon_data);
+
+      procedure->priv->icon_data_length =
+        strlen ((const gchar *) icon_data);
+      break;
+
+    case GIMP_ICON_TYPE_INLINE_PIXBUF:
+      g_return_if_fail (g_ntohl (*((gint32 *) icon_data)) == 0x47646b50);
+
+      procedure->priv->icon_data_length =
+        g_ntohl (*((gint32 *) (icon_data + 4)));
+
+      procedure->priv->icon_data =
+        g_memdup (icon_data, procedure->priv->icon_data_length);
+      break;
+
+    default:
+      g_return_if_reached ();
+    }
+}
+
+GimpIconType
+gimp_procedure_get_icon (GimpProcedure  *procedure,
+                         const guint8  **icon_data,
+                         gint           *icon_data_length)
+{
+  g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), -1);
+  g_return_val_if_fail (icon_data != NULL, -1);
+  g_return_val_if_fail (icon_data_length != NULL, -1);
+
+  *icon_data        = (guint8 *) procedure->priv->icon_data;
+  *icon_data_length = procedure->priv->icon_data_length;
+
+  return procedure->priv->icon_type;
+}
+
 void
 gimp_procedure_add_menu_path (GimpProcedure *procedure,
                               const gchar   *menu_path)
diff --git a/libgimp/gimpprocedure.h b/libgimp/gimpprocedure.h
index ce13eb3946..7eab533f44 100644
--- a/libgimp/gimpprocedure.h
+++ b/libgimp/gimpprocedure.h
@@ -81,6 +81,13 @@ const gchar    * gimp_procedure_get_copyright      (GimpProcedure     *procedure
 const gchar    * gimp_procedure_get_date           (GimpProcedure     *procedure);
 const gchar    * gimp_procedure_get_image_types    (GimpProcedure     *procedure);
 
+void             gimp_procedure_set_icon           (GimpProcedure     *procedure,
+                                                    GimpIconType       icon_type,
+                                                    const guint8      *icon_data);
+GimpIconType     gimp_procedure_get_icon           (GimpProcedure     *procedure,
+                                                    const guint8     **icon_data,
+                                                    gint              *icon_data_length);
+
 void             gimp_procedure_add_menu_path      (GimpProcedure     *procedure,
                                                     const gchar       *menu_path);
 GList          * gimp_procedure_get_menu_paths     (GimpProcedure     *procedure);


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