Commit d5255dc1 authored by Michael Natterer's avatar Michael Natterer 😴

app: derive GimpProcedure from GimpViewable

and remove redundant icon managing code from GimpPlugInProcedure
parent e0ab7213
......@@ -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);
}
......
......@@ -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);
......
......@@ -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"
......
......@@ -20,6 +20,7 @@
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
......
......@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
......
......@@ -39,6 +39,8 @@
#ifndef GIMP_CONSOLE_COMPILATION
#include <gdk/gdk.h>
#else
#include <gdk-pixbuf/gdk-pixbuf.h>
#endif
#include <babl/babl.h>
......
......@@ -20,6 +20,7 @@
#include <string.h>
#include <gtk/gtk.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
......
......@@ -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"
......
......@@ -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
......
......@@ -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,
......
......@@ -20,6 +20,7 @@
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "plug-in-types.h"
......
......@@ -20,6 +20,7 @@
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "plug-in-types.h"
......
......@@ -22,6 +22,7 @@
#include <string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
......
......@@ -58,6 +58,9 @@ static void gimp_plug_in_procedure_finalize (GObject *obje
static gint64 gimp_plug_in_procedure_get_memsize (GimpObject *object,
gint64 *gui_size);
static gchar * gimp_plug_in_procedure_get_description (GimpViewable *viewable,
gchar **tooltip);
static GimpValueArray * gimp_plug_in_procedure_execute (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
......@@ -71,7 +74,7 @@ static void gimp_plug_in_procedure_execute_async (GimpProcedure *proc
GimpValueArray *args,
GimpObject *display);
GFile * gimp_plug_in_procedure_real_get_file (const GimpPlugInProcedure *procedure);
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] =
......@@ -103,6 +107,9 @@ gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
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;
......@@ -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;
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_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 *
......
......@@ -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);
......
......@@ -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;
......
......@@ -23,6 +23,7 @@
#include <string.h>
#include <gtk/gtk.h>
#include <gegl.h>
#include "widgets-types.h"
......
......@@ -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"
......@@ -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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment