Commit 065db21d authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Added an API to allow plug-ins to embed the progress for the actions they

2004-08-29  Michael Natterer  <mitch@gimp.org>

	Added an API to allow plug-ins to embed the progress for the
	actions they trigger into their own GUI (attention: half-done and
	broken code ahead...)

	* app/core/Makefile.am
	* app/core/core-types.h
	* app/core/gimppdbprogress.[ch]: new object implementing dispatching
	progress calls to a temporary PDB procedure in a plug-in.

	* app/Makefile.am: force to link gimppdbprogress.o, bah!

	* app/plug-in/plug-in-progress.[ch]: added API to install,
	uninstall and cancel a PDB progress for this plug-in, but disabled
	the implementation because it doesn't work yet.

	* tools/pdbgen/pdb/progress.pdb: added pdb wrappers for the new
	install, uninstall and cancel functions.

	* libgimp/Makefile.am
	* libgimp/gimp.h
	* libgimp/gimpprogress.[ch]: added an API around the PDB progress
	stuff.

	* app/pdb/internal_procs.c
	* app/pdb/progress_cmds.c
	* libgimp/gimpprogress_pdb.[ch]: regenerated.

	* plug-ins/script-fu/script-fu-scripts.c: use the new API to show
	the progress in the script-fu dialog.
parent 3cb42821
2004-08-29 Michael Natterer <mitch@gimp.org>
Added an API to allow plug-ins to embed the progress for the
actions they trigger into their own GUI (attention: half-done and
broken code ahead...)
* app/core/Makefile.am
* app/core/core-types.h
* app/core/gimppdbprogress.[ch]: new object implementing dispatching
progress calls to a temporary PDB procedure in a plug-in.
* app/Makefile.am: force to link gimppdbprogress.o, bah!
* app/plug-in/plug-in-progress.[ch]: added API to install,
uninstall and cancel a PDB progress for this plug-in, but disabled
the implementation because it doesn't work yet.
* tools/pdbgen/pdb/progress.pdb: added pdb wrappers for the new
install, uninstall and cancel functions.
* libgimp/Makefile.am
* libgimp/gimp.h
* libgimp/gimpprogress.[ch]: added an API around the PDB progress
stuff.
* app/pdb/internal_procs.c
* app/pdb/progress_cmds.c
* libgimp/gimpprogress_pdb.[ch]: regenerated.
* plug-ins/script-fu/script-fu-scripts.c: use the new API to show
the progress in the script-fu dialog.
2004-08-29 Michael Schumacher <schumaml@cvs.gnome.org>
* libgimpwidgets/gimpwidgets.def: added
......
......@@ -90,6 +90,7 @@ gimp_2_1_LDFLAGS = \
-u $(SYMPREFIX)gimp_xml_parser_new \
-u $(SYMPREFIX)gimp_drawable_stroke_vectors \
-u $(SYMPREFIX)gimp_coords_mix \
-u $(SYMPREFIX)gimp_pdb_progress_get_type \
\
-u $(SYMPREFIX)convert_dialog_new \
-u $(SYMPREFIX)grid_dialog_new \
......
......@@ -184,6 +184,8 @@ libappcore_a_sources = \
gimppalette-import.h \
gimpparasitelist.c \
gimpparasitelist.h \
gimppdbprogress.c \
gimppdbprogress.h \
gimppickable.c \
gimppickable.h \
gimppreviewcache.c \
......
......@@ -114,6 +114,7 @@ typedef struct _GimpEnvironTable GimpEnvironTable;
typedef struct _GimpImagefile GimpImagefile;
typedef struct _GimpImageMap GimpImageMap;
typedef struct _GimpParasiteList GimpParasiteList;
typedef struct _GimpPdbProgress GimpPdbProgress;
typedef struct _GimpProjection GimpProjection;
/* typedef struct _GimpTemplate GimpTemplate; in config-types.h */
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimppdbprogress.c
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <glib-object.h>
#include "core-types.h"
#include "core/gimpcontext.h"
#include "pdb/procedural_db.h"
#include "gimppdbprogress.h"
#include "gimpprogress.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_CONTEXT,
PROP_CALLBACK_NAME
};
static void gimp_pdb_progress_class_init (GimpPdbProgressClass *klass);
static void gimp_pdb_progress_init (GimpPdbProgress *progress,
GimpPdbProgressClass *klass);
static void gimp_pdb_progress_progress_iface_init (GimpProgressInterface *progress_iface);
static GObject * gimp_pdb_progress_constructor (GType type,
guint n_params,
GObjectConstructParam *params);
static void gimp_pdb_progress_dispose (GObject *object);
static void gimp_pdb_progress_finalize (GObject *object);
static void gimp_pdb_progress_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static GimpProgress *
gimp_pdb_progress_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable);
static void gimp_pdb_progress_progress_end (GimpProgress *progress);
static gboolean gimp_pdb_progress_progress_is_active (GimpProgress *progress);
static void gimp_pdb_progress_progress_set_text (GimpProgress *progress,
const gchar *message);
static void gimp_pdb_progress_progress_set_value (GimpProgress *progress,
gdouble percentage);
static gdouble gimp_pdb_progress_progress_get_value (GimpProgress *progress);
static GObjectClass *parent_class = NULL;
GType
gimp_pdb_progress_get_type (void)
{
static GType type = 0;
if (! type)
{
static const GTypeInfo info =
{
sizeof (GimpPdbProgressClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_pdb_progress_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpPdbProgress),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_pdb_progress_init,
};
static const GInterfaceInfo progress_iface_info =
{
(GInterfaceInitFunc) gimp_pdb_progress_progress_iface_init,
NULL, /* iface_finalize */
NULL /* iface_data */
};
type = g_type_register_static (G_TYPE_OBJECT,
"GimpPdbProgress",
&info, 0);
g_type_add_interface_static (type, GIMP_TYPE_PROGRESS,
&progress_iface_info);
}
return type;
}
static void
gimp_pdb_progress_class_init (GimpPdbProgressClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->constructor = gimp_pdb_progress_constructor;
object_class->dispose = gimp_pdb_progress_dispose;
object_class->finalize = gimp_pdb_progress_finalize;
object_class->set_property = gimp_pdb_progress_set_property;
g_object_class_install_property (object_class, PROP_CONTEXT,
g_param_spec_object ("context", NULL, NULL,
GIMP_TYPE_CONTEXT,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_CALLBACK_NAME,
g_param_spec_string ("callback-name",
NULL, NULL,
NULL,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
gimp_pdb_progress_init (GimpPdbProgress *progress,
GimpPdbProgressClass *klass)
{
klass->progresses = g_list_prepend (klass->progresses, progress);
}
static void
gimp_pdb_progress_progress_iface_init (GimpProgressInterface *progress_iface)
{
progress_iface->start = gimp_pdb_progress_progress_start;
progress_iface->end = gimp_pdb_progress_progress_end;
progress_iface->is_active = gimp_pdb_progress_progress_is_active;
progress_iface->set_text = gimp_pdb_progress_progress_set_text;
progress_iface->set_value = gimp_pdb_progress_progress_set_value;
progress_iface->get_value = gimp_pdb_progress_progress_get_value;
}
static GObject *
gimp_pdb_progress_constructor (GType type,
guint n_params,
GObjectConstructParam *params)
{
GObject *object;
GimpPdbProgress *progress;
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
progress = GIMP_PDB_PROGRESS (object);
g_assert (GIMP_IS_CONTEXT (progress->context));
return object;
}
static void
gimp_pdb_progress_dispose (GObject *object)
{
GimpPdbProgressClass *klass = GIMP_PDB_PROGRESS_GET_CLASS (object);
klass->progresses = g_list_remove (klass->progresses, object);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
gimp_pdb_progress_finalize (GObject *object)
{
GimpPdbProgress *progress = GIMP_PDB_PROGRESS (object);
if (progress->context)
{
g_object_unref (progress->context);
progress->context = NULL;
}
if (progress->callback_name)
{
g_free (progress->callback_name);
progress->callback_name = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gimp_pdb_progress_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpPdbProgress *progress = GIMP_PDB_PROGRESS (object);
switch (property_id)
{
case PROP_CONTEXT:
if (progress->context)
g_object_unref (progress->context);
progress->context = (GimpContext *) g_value_dup_object (value);
break;
case PROP_CALLBACK_NAME:
if (progress->callback_name)
g_free (progress->callback_name);
progress->callback_name = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gimp_pdb_progress_run_callback (GimpPdbProgress *progress,
gint command,
const gchar *text,
gdouble value)
{
if (! progress->callback_busy)
{
Argument *return_vals;
gint n_return_vals;
progress->callback_busy = TRUE;
g_print ("%s: command = %d, text = %s, value = %f\n",
G_STRFUNC, command, text, value);
return_vals = procedural_db_run_proc (progress->context->gimp,
progress->context,
NULL,
progress->callback_name,
&n_return_vals,
GIMP_PDB_INT32, command,
GIMP_PDB_STRING, text,
GIMP_PDB_FLOAT, value,
GIMP_PDB_END);
if (! return_vals ||
return_vals[0].value.pdb_int != GIMP_PDB_SUCCESS)
{
g_message (_("Unable to run %s callback. "
"The corresponding plug-in may have crashed."),
g_type_name (G_TYPE_FROM_INSTANCE (progress)));
}
if (return_vals)
procedural_db_destroy_args (return_vals, n_return_vals);
g_print ("%s: callback finished\n", G_STRFUNC);
progress->callback_busy = FALSE;
}
}
static GimpProgress *
gimp_pdb_progress_progress_start (GimpProgress *progress,
const gchar *message,
gboolean cancelable)
{
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
if (! pdb_progress->active)
{
gimp_pdb_progress_run_callback (pdb_progress, 0, message, 0.0);
pdb_progress->active = TRUE;
pdb_progress->value = 0.0;
return progress;
}
return NULL;
}
static void
gimp_pdb_progress_progress_end (GimpProgress *progress)
{
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
if (pdb_progress->active)
{
gimp_pdb_progress_run_callback (pdb_progress, 1, NULL, 0.0);
pdb_progress->active = FALSE;
pdb_progress->value = 0.0;
}
}
static gboolean
gimp_pdb_progress_progress_is_active (GimpProgress *progress)
{
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
return pdb_progress->active;
}
static void
gimp_pdb_progress_progress_set_text (GimpProgress *progress,
const gchar *message)
{
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
if (pdb_progress->active)
gimp_pdb_progress_run_callback (pdb_progress, 2, message, 0.0);
}
static void
gimp_pdb_progress_progress_set_value (GimpProgress *progress,
gdouble percentage)
{
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
if (pdb_progress->active)
{
gimp_pdb_progress_run_callback (pdb_progress, 3, NULL, percentage);
pdb_progress->value = percentage;
}
}
static gdouble
gimp_pdb_progress_progress_get_value (GimpProgress *progress)
{
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
return pdb_progress->value;
}
GimpPdbProgress *
gimp_pdb_progress_get_by_callback (GimpPdbProgressClass *klass,
const gchar *callback_name)
{
GList *list;
g_return_val_if_fail (GIMP_IS_PDB_PROGRESS_CLASS (klass), NULL);
g_return_val_if_fail (callback_name != NULL, NULL);
for (list = klass->progresses; list; list = g_list_next (list))
{
GimpPdbProgress *progress = list->data;
if (progress->callback_name &&
! strcmp (callback_name, progress->callback_name))
return progress;
}
return NULL;
}
void
gimp_pdb_progresss_check_callback (GimpPdbProgressClass *klass)
{
GList *list;
g_return_if_fail (GIMP_IS_PDB_PROGRESS_CLASS (klass));
list = klass->progresses;
while (list)
{
GimpPdbProgress *progress = list->data;
list = g_list_next (list);
if (progress->callback_name)
{
if (! procedural_db_lookup (progress->context->gimp,
progress->callback_name))
{
}
}
}
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimppdbprogress.h
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_PDB_PROGRESS_H__
#define __GIMP_PDB_PROGRESS_H__
G_BEGIN_DECLS
#define GIMP_TYPE_PDB_PROGRESS (gimp_pdb_progress_get_type ())
#define GIMP_PDB_PROGRESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_PDB_PROGRESS, GimpPdbProgress))
#define GIMP_PDB_PROGRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_PDB_PROGRESS, GimpPdbProgressClass))
#define GIMP_IS_PDB_PROGRESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_PDB_PROGRESS))
#define GIMP_IS_PDB_PROGRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_PDB_PROGRESS))
#define GIMP_PDB_PROGRESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_PDB_PROGRESS, GimpPdbProgressClass))
typedef struct _GimpPdbProgressClass GimpPdbProgressClass;
struct _GimpPdbProgress
{
GObject object;
gboolean active;
gdouble value;
GimpContext *context;
gchar *callback_name;
gboolean callback_busy;
};
struct _GimpPdbProgressClass
{
GObjectClass parent_class;
GList *progresses;
};
GType gimp_pdb_progress_get_type (void) G_GNUC_CONST;
GimpPdbProgress * gimp_pdb_progress_get_by_callback (GimpPdbProgressClass *klass,
const gchar *callback_name);
void gimp_pdb_progresss_check_callback (GimpPdbProgressClass *klass);
G_END_DECLS
#endif /* __GIMP_PDB_PROGRESS_H__ */
......@@ -70,7 +70,7 @@ void register_transform_tools_procs (Gimp *gimp);
void register_undo_procs (Gimp *gimp);
void register_unit_procs (Gimp *gimp);
/* 377 procedures registered total */
/* 380 procedures registered total */
void
internal_procs_init (Gimp *gimp,
......@@ -97,94 +97,94 @@ internal_procs_init (Gimp *gimp,
(* status_callback) (NULL, _("Display procedures"), 0.103);
register_display_procs (gimp);
(* status_callback) (NULL, _("Drawable procedures"), 0.114);
(* status_callback) (NULL, _("Drawable procedures"), 0.113);
register_drawable_procs (gimp);
(* status_callback) (NULL, _("Edit procedures"), 0.199);
(* status_callback) (NULL, _("Edit procedures"), 0.197);
register_edit_procs (gimp);
(* status_callback) (NULL, _("File Operations"), 0.22);
(* status_callback) (NULL, _("File Operations"), 0.218);
register_fileops_procs (gimp);
(* status_callback) (NULL, _("Floating selections"), 0.244);
(* status_callback) (NULL, _("Floating selections"), 0.242);
register_floating_sel_procs (gimp);
(* status_callback) (NULL, _("Font UI"), 0.26);
(* status_callback) (NULL, _("Font UI"), 0.258);
register_font_select_procs (gimp);
(* status_callback) (NULL, _("Fonts"), 0.268);
(* status_callback) (NULL, _("Fonts"), 0.266);
register_fonts_procs (gimp);
(* status_callback) (NULL, _("Gimprc procedures"), 0.273);
(* status_callback) (NULL, _("Gimprc procedures"), 0.271);
register_gimprc_procs (gimp);
(* status_callback) (NULL, _("Gradient"), 0.289);
(* status_callback) (NULL, _("Gradient"), 0.287);
register_gradient_edit_procs (gimp);
(* status_callback) (NULL, _("Gradient UI"), 0.35);
(* status_callback) (NULL, _("Gradient UI"), 0.347);
register_gradient_select_procs (gimp);
(* status_callback) (NULL, _("Gradients"), 0.358);
(* status_callback) (NULL, _("Gradients"), 0.355);
register_gradients_procs (gimp);
(* status_callback) (NULL, _("Guide procedures"), 0.387);
(* status_callback) (NULL, _("Guide procedures"), 0.384);
register_guides_procs (gimp);
(* status_callback) (NULL, _("Help procedures"), 0.403);
(* status_callback) (NULL, _("Help procedures"), 0.4);
register_help_procs (gimp);
(* status_callback) (NULL, _("Image"), 0.406);
(* status_callback) (NULL, _("Image"), 0.403);
register_image_procs (gimp);
(* status_callback) (NULL, _("Layer"), 0.568);
(* status_callback) (NULL, _("Layer"), 0.563);
register_layer_procs (gimp);
(* status_callback) (NULL, _("Message procedures"), 0.637);
(* status_callback) (NULL, _("Message procedures"), 0.632);
register_message_procs (gimp);
(* status_callback) (NULL, _("Miscellaneous"), 0.645);
(* status_callback) (NULL, _("Miscellaneous"), 0.639);
register_misc_procs (gimp);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.65);
(* status_callback) (NULL, _("Paint Tool procedures"), 0.645);
register_paint_tools_procs (gimp);
(* status_callback) (NULL, _("Palette"), 0.69);
(* status_callback) (NULL, _("Palette"), 0.684);
register_palette_procs (gimp);
(* status_callback) (NULL, _("Palette UI"), 0.706);
(* status_callback) (NULL, _("Palette UI"), 0.7);
register_palette_select_procs (gimp);
(* status_callback) (NULL, _("Palettes"), 0.714);
(* status_callback) (NULL, _("Palettes"), 0.708);
register_palettes_procs (gimp);
(* status_callback) (NULL, _("Parasite procedures"), 0.727);
(* status_callback) (NULL, _("Parasite procedures"), 0.721);
register_parasite_procs (gimp);
(* status_callback) (NULL, _("Paths"), 0.759);
(* status_callback) (NULL, _("Paths"), 0.753);
register_paths_procs (gimp);
(* status_callback) (NULL, _("Pattern UI"), 0.798);
(* status_callback) (NULL, _("Pattern UI"), 0.792);
register_pattern_select_procs (gimp);
(* status_callback) (NULL, _("Patterns"), 0.806);
(* status_callback) (NULL, _("Patterns"), 0.8);
register_patterns_procs (gimp);
(* status_callback) (NULL, _("Plug-in"), 0.82);
(* status_callback) (NULL, _("Plug-in"), 0.813);
register_plug_in_procs (gimp);
(* status_callback) (NULL, _("Procedural database"), 0.833);
(* status_callback) (NULL, _("Procedural database"), 0.826);
register_procedural_db_procs (gimp);
(* status_callback) (NULL, _("Progress"), 0.857);
(* status_callback) (NULL, _("Progress"), 0.85);
register_progress_procs (gimp);
(* status_callback) (NULL, _("Image mask"), 0.862);
(* status_callback) (NULL, _("Image mask"), 0.863);
register_selection_procs (gimp);
(* status_callback) (NULL, _("Selection Tool procedures"), 0.91);
(* status_callback) (NULL, _("Selection Tool procedures"), 0.911);
register_selection_tools_procs (gimp);
(* status_callback) (NULL, _("Text procedures"), 0.923);
(* status_callback) (NULL, _("Text procedures"), 0.924);
register_text_tool_procs (gimp);
(* status_callback) (NULL, _("Transform Tool procedures"), 0.934);
......
......@@ -32,12 +32,18 @@
static ProcRecord progress_init_proc;
static ProcRecord progress_update_proc;
static ProcRecord progress_install_proc;
static ProcRecord progress_uninstall_proc;
static ProcRecord progress_cancel_proc;
void
register_progress_procs (Gimp *gimp)
{
procedural_db_register (gimp, &progress_init_proc);
procedural_db_register (gimp, &progress_update_proc);
procedural_db_register (gimp, &progress_install_proc);
procedural_db_register (gimp, &progress_uninstall_proc);
procedural_db_register (gimp, &progress_cancel_proc);
}
static Argument *
......@@ -146,3 +152,150 @@ static ProcRecord progress_update_proc =
NULL,
{ { progress_update_invoker } }
};
static Argument *
progress_install_invoker (Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
Argument *args)
{
gboolean success = TRUE;
gchar *progress_callback;
progress_callback = (gchar *) args[0].value.pdb_pointer;
if (progress_callback == NULL || !g_utf8_validate (progress_callback, -1, NULL))
success = FALSE;
if (success)
{
if (gimp->current_plug_in && gimp->current_plug_in->open)
plug_in_progress_install (gimp->current_plug_in, progress_callback);
else
success = FALSE;
}
return procedural_db_return_args (&progress_install_proc, success);
}
static ProcArg progress_install_inargs[] =
{
{
GIMP_PDB_STRING,
"progress_callback",
"The callback PDB proc to call"
}
};
static ProcRecord progress_install_proc =
{
"gimp_progress_install",
"Installs a progress callback for the current plug-in.",
"This function installs a temporary PDB procedure which will handle all progress calls made by this plug-in and any procedure it calls. Calling this function multiple times simply replaces the old progress callbacks.",
"Michael Natterer <mitch@gimp.org>",
"Michael Natterer",
"2004",
GIMP_INTERNAL,
1,
progress_install_inargs,
0,
NULL,
{ { progress_install_invoker } }