[gimp] app: derive GimpProcedure from GimpViewable



commit d5255dc1337a36a8e7ec32ed3415c9c14221b373
Author: Michael Natterer <mitch gimp org>
Date:   Fri Jan 1 19:37:10 2016 +0100

    app: derive GimpProcedure from GimpViewable
    
    and remove redundant icon managing code from GimpPlugInProcedure

 app/actions/filters-actions.c         |    2 +-
 app/actions/plug-in-actions.c         |    2 +-
 app/core/gimp-batch.c                 |    2 +-
 app/core/gimp-filter-history.c        |    1 +
 app/file/file-procedure.c             |    1 +
 app/main.c                            |    2 +
 app/menus/plug-in-menus.c             |    1 +
 app/pdb/gimppdb-query.c               |    3 +-
 app/pdb/gimpprocedure.c               |    2 +-
 app/pdb/gimpprocedure.h               |    6 +-
 app/plug-in/gimpplugin-progress.c     |    1 +
 app/plug-in/gimppluginmanager-file.c  |    1 +
 app/plug-in/gimppluginmanager-query.c |    1 +
 app/plug-in/gimppluginprocedure.c     |  155 +++++++++++++++++++-------------
 app/plug-in/gimppluginprocedure.h     |    7 +-
 app/plug-in/plug-in-rc.c              |    6 +-
 app/widgets/gimpfileprocview.c        |    1 +
 app/widgets/gimpprocedureaction.c     |   10 ++-
 18 files changed, 124 insertions(+), 80 deletions(-)
---
diff --git a/app/actions/filters-actions.c b/app/actions/filters-actions.c
index 1b9dcf7..d63a92e 100644
--- a/app/actions/filters-actions.c
+++ b/app/actions/filters-actions.c
@@ -865,7 +865,7 @@ filters_actions_history_changed (Gimp            *gimp,
                     "sensitive", sensitive,
                     "procedure", proc,
                     "label",     label,
-                    "icon-name", gimp_plug_in_procedure_get_icon_name (GIMP_PLUG_IN_PROCEDURE (proc)),
+                    "icon-name", gimp_viewable_get_icon_name (GIMP_VIEWABLE (proc)),
                     "tooltip",   gimp_plug_in_procedure_get_blurb (GIMP_PLUG_IN_PROCEDURE (proc)),
                     NULL);
     }
diff --git a/app/actions/plug-in-actions.c b/app/actions/plug-in-actions.c
index df9f3ae..4f39d4d 100644
--- a/app/actions/plug-in-actions.c
+++ b/app/actions/plug-in-actions.c
@@ -333,7 +333,7 @@ plug_in_actions_add_proc (GimpActionGroup     *group,
     }
 
   entry.name        = gimp_object_get_name (proc);
-  entry.icon_name   = gimp_plug_in_procedure_get_icon_name (proc);
+  entry.icon_name   = gimp_viewable_get_icon_name (GIMP_VIEWABLE (proc));
   entry.label       = label;
   entry.accelerator = NULL;
   entry.tooltip     = gimp_plug_in_procedure_get_blurb (proc);
diff --git a/app/core/gimp-batch.c b/app/core/gimp-batch.c
index eaabf1a..52b06fd 100644
--- a/app/core/gimp-batch.c
+++ b/app/core/gimp-batch.c
@@ -20,7 +20,7 @@
 #include <string.h>
 #include <stdlib.h>
 
-#include <gio/gio.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
diff --git a/app/core/gimp-filter-history.c b/app/core/gimp-filter-history.c
index e17f18e..56a69c3 100644
--- a/app/core/gimp-filter-history.c
+++ b/app/core/gimp-filter-history.c
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 
diff --git a/app/file/file-procedure.c b/app/file/file-procedure.c
index 4a3c2d3..f2d9eb2 100644
--- a/app/file/file-procedure.c
+++ b/app/file/file-procedure.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 
diff --git a/app/main.c b/app/main.c
index 2b348cc..c3c1dba 100644
--- a/app/main.c
+++ b/app/main.c
@@ -39,6 +39,8 @@
 
 #ifndef GIMP_CONSOLE_COMPILATION
 #include <gdk/gdk.h>
+#else
+#include <gdk-pixbuf/gdk-pixbuf.h>
 #endif
 
 #include <babl/babl.h>
diff --git a/app/menus/plug-in-menus.c b/app/menus/plug-in-menus.c
index 9bcf41d..8da0ca4 100644
--- a/app/menus/plug-in-menus.c
+++ b/app/menus/plug-in-menus.c
@@ -20,6 +20,7 @@
 #include <string.h>
 
 #include <gtk/gtk.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 
diff --git a/app/pdb/gimppdb-query.c b/app/pdb/gimppdb-query.c
index 32a24af..376b9ab 100644
--- a/app/pdb/gimppdb-query.c
+++ b/app/pdb/gimppdb-query.c
@@ -20,7 +20,8 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <gio/gio.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 
diff --git a/app/pdb/gimpprocedure.c b/app/pdb/gimpprocedure.c
index 2ec02a4..da3b42a 100644
--- a/app/pdb/gimpprocedure.c
+++ b/app/pdb/gimpprocedure.c
@@ -70,7 +70,7 @@ static gboolean         gimp_procedure_validate_args (GimpProcedure   *procedure
                                                       GError         **error);
 
 
-G_DEFINE_TYPE (GimpProcedure, gimp_procedure, GIMP_TYPE_OBJECT)
+G_DEFINE_TYPE (GimpProcedure, gimp_procedure, GIMP_TYPE_VIEWABLE)
 
 #define parent_class gimp_procedure_parent_class
 
diff --git a/app/pdb/gimpprocedure.h b/app/pdb/gimpprocedure.h
index dd837d4..4cbae07 100644
--- a/app/pdb/gimpprocedure.h
+++ b/app/pdb/gimpprocedure.h
@@ -19,7 +19,7 @@
 #define __GIMP_PROCEDURE_H__
 
 
-#include "core/gimpobject.h"
+#include "core/gimpviewable.h"
 
 
 typedef GimpValueArray * (* GimpMarshalFunc) (GimpProcedure         *procedure,
@@ -42,7 +42,7 @@ typedef struct _GimpProcedureClass GimpProcedureClass;
 
 struct _GimpProcedure
 {
-  GimpObject        parent_instance;
+  GimpViewable      parent_instance;
 
   GimpPDBProcType   proc_type;      /* Type of procedure              */
 
@@ -67,7 +67,7 @@ struct _GimpProcedure
 
 struct _GimpProcedureClass
 {
-  GimpObjectClass parent_class;
+  GimpViewableClass parent_class;
 
   GimpValueArray * (* execute)       (GimpProcedure   *procedure,
                                       Gimp            *gimp,
diff --git a/app/plug-in/gimpplugin-progress.c b/app/plug-in/gimpplugin-progress.c
index 70d90e6..2aaff0e 100644
--- a/app/plug-in/gimpplugin-progress.c
+++ b/app/plug-in/gimpplugin-progress.c
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
 
 #include "plug-in-types.h"
 
diff --git a/app/plug-in/gimppluginmanager-file.c b/app/plug-in/gimppluginmanager-file.c
index 5022d14..dc4e951 100644
--- a/app/plug-in/gimppluginmanager-file.c
+++ b/app/plug-in/gimppluginmanager-file.c
@@ -20,6 +20,7 @@
 #include "config.h"
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
 
 #include "plug-in-types.h"
 
diff --git a/app/plug-in/gimppluginmanager-query.c b/app/plug-in/gimppluginmanager-query.c
index 4c5ef61..2a65005 100644
--- a/app/plug-in/gimppluginmanager-query.c
+++ b/app/plug-in/gimppluginmanager-query.c
@@ -22,6 +22,7 @@
 #include <string.h>
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 
diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c
index c750e53..67d26ff 100644
--- a/app/plug-in/gimppluginprocedure.c
+++ b/app/plug-in/gimppluginprocedure.c
@@ -53,25 +53,28 @@ enum
 };
 
 
-static void             gimp_plug_in_procedure_finalize    (GObject        *object);
+static void     gimp_plug_in_procedure_finalize        (GObject        *object);
 
-static gint64           gimp_plug_in_procedure_get_memsize (GimpObject     *object,
-                                                            gint64         *gui_size);
+static gint64   gimp_plug_in_procedure_get_memsize     (GimpObject     *object,
+                                                        gint64         *gui_size);
 
-static GimpValueArray * gimp_plug_in_procedure_execute     (GimpProcedure  *procedure,
-                                                            Gimp           *gimp,
-                                                            GimpContext    *context,
-                                                            GimpProgress   *progress,
-                                                            GimpValueArray *args,
-                                                            GError        **error);
-static void          gimp_plug_in_procedure_execute_async  (GimpProcedure  *procedure,
-                                                            Gimp           *gimp,
-                                                            GimpContext    *context,
-                                                            GimpProgress   *progress,
-                                                            GimpValueArray *args,
-                                                            GimpObject     *display);
+static gchar  * gimp_plug_in_procedure_get_description (GimpViewable   *viewable,
+                                                        gchar         **tooltip);
 
-GFile * gimp_plug_in_procedure_real_get_file (const GimpPlugInProcedure *procedure);
+static GimpValueArray * gimp_plug_in_procedure_execute (GimpProcedure  *procedure,
+                                                        Gimp           *gimp,
+                                                        GimpContext    *context,
+                                                        GimpProgress   *progress,
+                                                        GimpValueArray *args,
+                                                        GError        **error);
+static void     gimp_plug_in_procedure_execute_async   (GimpProcedure  *procedure,
+                                                        Gimp           *gimp,
+                                                        GimpContext    *context,
+                                                        GimpProgress   *progress,
+                                                        GimpValueArray *args,
+                                                        GimpObject     *display);
+
+static GFile  * gimp_plug_in_procedure_real_get_file   (const GimpPlugInProcedure *procedure);
 
 
 G_DEFINE_TYPE (GimpPlugInProcedure, gimp_plug_in_procedure,
@@ -87,6 +90,7 @@ gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
 {
   GObjectClass       *object_class      = G_OBJECT_CLASS (klass);
   GimpObjectClass    *gimp_object_class = GIMP_OBJECT_CLASS (klass);
+  GimpViewableClass  *viewable_class    = GIMP_VIEWABLE_CLASS (klass);
   GimpProcedureClass *proc_class        = GIMP_PROCEDURE_CLASS (klass);
 
   gimp_plug_in_procedure_signals[MENU_PATH_ADDED] =
@@ -99,15 +103,18 @@ gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
                   G_TYPE_NONE, 1,
                   G_TYPE_STRING);
 
-  object_class->finalize         = gimp_plug_in_procedure_finalize;
+  object_class->finalize            = gimp_plug_in_procedure_finalize;
+
+  gimp_object_class->get_memsize    = gimp_plug_in_procedure_get_memsize;
 
-  gimp_object_class->get_memsize = gimp_plug_in_procedure_get_memsize;
+  viewable_class->default_icon_name = "system-run";
+  viewable_class->get_description   = gimp_plug_in_procedure_get_description;
 
-  proc_class->execute            = gimp_plug_in_procedure_execute;
-  proc_class->execute_async      = gimp_plug_in_procedure_execute_async;
+  proc_class->execute               = gimp_plug_in_procedure_execute;
+  proc_class->execute_async         = gimp_plug_in_procedure_execute_async;
 
-  klass->get_file                = gimp_plug_in_procedure_real_get_file;
-  klass->menu_path_added         = NULL;
+  klass->get_file                   = gimp_plug_in_procedure_real_get_file;
+  klass->menu_path_added            = NULL;
 }
 
 static void
@@ -194,6 +201,18 @@ gimp_plug_in_procedure_get_memsize (GimpObject *object,
                                                                   gui_size);
 }
 
+static gchar *
+gimp_plug_in_procedure_get_description (GimpViewable  *viewable,
+                                        gchar        **tooltip)
+{
+  GimpPlugInProcedure *proc = GIMP_PLUG_IN_PROCEDURE (viewable);
+
+  if (tooltip)
+    *tooltip = g_strdup (gimp_plug_in_procedure_get_blurb (proc));
+
+  return g_strdup (gimp_plug_in_procedure_get_label (proc));
+}
+
 static GimpValueArray *
 gimp_plug_in_procedure_execute (GimpProcedure  *procedure,
                                 Gimp           *gimp,
@@ -589,80 +608,90 @@ gimp_plug_in_procedure_set_icon (GimpPlugInProcedure *proc,
                                  const guint8        *icon_data,
                                  gint                 icon_data_length)
 {
-  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
-  g_return_if_fail (icon_type == -1 || icon_data != NULL);
-  g_return_if_fail (icon_type == -1 || icon_data_length > 0);
-
-  if (proc->icon_data)
-    {
-      g_free (proc->icon_data);
-      proc->icon_data_length = -1;
-      proc->icon_data        = NULL;
-    }
+  guint8 *data_copy = NULL;
 
-  proc->icon_type = icon_type;
+  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
 
   switch (proc->icon_type)
     {
     case GIMP_ICON_TYPE_ICON_NAME:
-    case GIMP_ICON_TYPE_IMAGE_FILE:
-      proc->icon_data_length = -1;
-      proc->icon_data        = (guint8 *) g_strdup ((gchar *) icon_data);
+      data_copy = (guint8 *) g_strdup ((gchar *) icon_data);
       break;
 
     case GIMP_ICON_TYPE_INLINE_PIXBUF:
-      proc->icon_data_length = icon_data_length;
-      proc->icon_data        = g_memdup (icon_data, icon_data_length);
+      data_copy = g_memdup (icon_data, icon_data_length);
       break;
-    }
-}
 
-const gchar *
-gimp_plug_in_procedure_get_icon_name (const GimpPlugInProcedure *proc)
-{
-  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL);
-
-  switch (proc->icon_type)
-    {
-    case GIMP_ICON_TYPE_ICON_NAME:
-      return (gchar *) proc->icon_data;
+    case GIMP_ICON_TYPE_IMAGE_FILE:
+      data_copy = (guint8 *) g_strdup ((gchar *) icon_data);
+      break;
 
     default:
-      return NULL;
+      g_return_if_reached ();
     }
+
+  gimp_plug_in_procedure_take_icon (proc, icon_type,
+                                    data_copy, icon_data_length);
 }
 
-GdkPixbuf *
-gimp_plug_in_procedure_get_pixbuf (const GimpPlugInProcedure *proc)
+void
+gimp_plug_in_procedure_take_icon (GimpPlugInProcedure *proc,
+                                  GimpIconType         icon_type,
+                                  guint8              *icon_data,
+                                  gint                 icon_data_length)
 {
-  GdkPixbuf *pixbuf = NULL;
-  GError    *error  = NULL;
+  const gchar *icon_name   = NULL;
+  GdkPixbuf   *icon_pixbuf = NULL;
+  GError      *error       = NULL;
 
-  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL);
+  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
+
+  if (proc->icon_data)
+    {
+      g_free (proc->icon_data);
+      proc->icon_data_length = -1;
+      proc->icon_data        = NULL;
+    }
+
+  proc->icon_type = icon_type;
 
   switch (proc->icon_type)
     {
+    case GIMP_ICON_TYPE_ICON_NAME:
+      proc->icon_data_length = -1;
+      proc->icon_data        = icon_data;
+
+      icon_name = (const gchar *) proc->icon_data;
+      break;
+
     case GIMP_ICON_TYPE_INLINE_PIXBUF:
-      pixbuf = gdk_pixbuf_new_from_inline (proc->icon_data_length,
-                                           proc->icon_data, TRUE, &error);
+      proc->icon_data_length = icon_data_length;
+      proc->icon_data        = icon_data;
+
+      icon_pixbuf = gdk_pixbuf_new_from_inline (proc->icon_data_length,
+                                                proc->icon_data, TRUE, &error);
       break;
 
     case GIMP_ICON_TYPE_IMAGE_FILE:
-      pixbuf = gdk_pixbuf_new_from_file ((gchar *) proc->icon_data,
-                                         &error);
-      break;
+      proc->icon_data_length = -1;
+      proc->icon_data        = icon_data;
 
-    default:
+      icon_pixbuf = gdk_pixbuf_new_from_file ((gchar *) proc->icon_data,
+                                              &error);
       break;
     }
 
-  if (! pixbuf && error)
+  if (! icon_pixbuf && error)
     {
       g_printerr ("%s\n", error->message);
       g_clear_error (&error);
     }
 
-  return pixbuf;
+  gimp_viewable_set_icon_name (GIMP_VIEWABLE (proc), icon_name);
+  g_object_set (proc, "icon-pixbuf", icon_pixbuf, NULL);
+
+  if (icon_pixbuf)
+    g_object_unref (icon_pixbuf);
 }
 
 gchar *
diff --git a/app/plug-in/gimppluginprocedure.h b/app/plug-in/gimppluginprocedure.h
index 988d873..2f1270c 100644
--- a/app/plug-in/gimppluginprocedure.h
+++ b/app/plug-in/gimppluginprocedure.h
@@ -102,14 +102,17 @@ gboolean      gimp_plug_in_procedure_add_menu_path   (GimpPlugInProcedure
                                                       GError                   **error);
 
 const gchar * gimp_plug_in_procedure_get_label       (GimpPlugInProcedure       *proc);
+
 const gchar * gimp_plug_in_procedure_get_blurb       (const GimpPlugInProcedure *proc);
 
 void          gimp_plug_in_procedure_set_icon        (GimpPlugInProcedure       *proc,
                                                       GimpIconType               type,
                                                       const guint8              *data,
                                                       gint                       data_length);
-const gchar * gimp_plug_in_procedure_get_icon_name   (const GimpPlugInProcedure *proc);
-GdkPixbuf   * gimp_plug_in_procedure_get_pixbuf      (const GimpPlugInProcedure *proc);
+void          gimp_plug_in_procedure_take_icon       (GimpPlugInProcedure       *proc,
+                                                      GimpIconType               type,
+                                                      guint8                    *data,
+                                                      gint                       data_length);
 
 gchar       * gimp_plug_in_procedure_get_help_id     (const GimpPlugInProcedure *proc);
 
diff --git a/app/plug-in/plug-in-rc.c b/app/plug-in/plug-in-rc.c
index 0b67335..18146c3 100644
--- a/app/plug-in/plug-in-rc.c
+++ b/app/plug-in/plug-in-rc.c
@@ -21,6 +21,7 @@
 #include "config.h"
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 #include "libgimpbase/gimpprotocol.h"
@@ -558,9 +559,8 @@ plug_in_icon_deserialize (GScanner            *scanner,
       break;
     }
 
-  proc->icon_type        = icon_type;
-  proc->icon_data_length = icon_data_length;
-  proc->icon_data        = icon_data;
+  gimp_plug_in_procedure_take_icon (proc, icon_type,
+                                    icon_data, icon_data_length);
 
   if (! gimp_scanner_parse_token (scanner, G_TOKEN_RIGHT_PAREN))
     return G_TOKEN_RIGHT_PAREN;
diff --git a/app/widgets/gimpfileprocview.c b/app/widgets/gimpfileprocview.c
index f3010c8..cb102d5 100644
--- a/app/widgets/gimpfileprocview.c
+++ b/app/widgets/gimpfileprocview.c
@@ -23,6 +23,7 @@
 #include <string.h>
 
 #include <gtk/gtk.h>
+#include <gegl.h>
 
 #include "widgets-types.h"
 
diff --git a/app/widgets/gimpprocedureaction.c b/app/widgets/gimpprocedureaction.c
index 5b0cc46..1337647 100644
--- a/app/widgets/gimpprocedureaction.c
+++ b/app/widgets/gimpprocedureaction.c
@@ -21,12 +21,13 @@
 #include "config.h"
 
 #include <gtk/gtk.h>
+#include <gegl.h>
 
 #include "widgets-types.h"
 
 #include "core/gimpmarshal.h"
 
-#include "plug-in/gimppluginprocedure.h" /* FIXME history */
+#include "pdb/gimpprocedure.h"
 
 #include "gimpprocedureaction.h"
 
@@ -52,7 +53,7 @@ static void   gimp_procedure_action_set_property  (GObject      *object,
 static void   gimp_procedure_action_get_property  (GObject      *object,
                                                    guint         prop_id,
                                                    GValue       *value,
-                                                 GParamSpec   *pspec);
+                                                   GParamSpec   *pspec);
 
 static void   gimp_procedure_action_activate      (GtkAction    *action);
 static void   gimp_procedure_action_connect_proxy (GtkAction    *action,
@@ -184,8 +185,9 @@ gimp_procedure_action_connect_proxy (GtkAction *action,
     {
       GdkPixbuf *pixbuf;
 
-      /* FIXME history */
-      pixbuf = gimp_plug_in_procedure_get_pixbuf (GIMP_PLUG_IN_PROCEDURE (procedure_action->procedure));
+      g_object_get (procedure_action->procedure,
+                    "icon-pixbuf", &pixbuf,
+                    NULL);
 
       if (pixbuf)
         {


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