Commit fcc13b8c authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

app/plug-in/Makefile.am new files containing utility functions for

2004-09-22  Michael Natterer  <mitch@gimp.org>

	* app/plug-in/Makefile.am
	* app/plug-in/plug-in-proc-frame.[ch]: new files containing
	utility functions for initializing/freeing PlugInProcFrames.
	Added the progress stuff to the proc_frame.

	* app/plug-in/plug-in.[ch]: removed the progress stuff from the
	PlugIn struct and use the new proc_frame utility functions.

	* app/plug-in/plug-in-message.c
	* app/plug-in/plug-in-progress.c
	* app/plug-in/plug-in-run.c: changed accordingly.
parent 77ba473f
2004-09-22 Michael Natterer <mitch@gimp.org>
* app/plug-in/Makefile.am
* app/plug-in/plug-in-proc-frame.[ch]: new files containing
utility functions for initializing/freeing PlugInProcFrames.
Added the progress stuff to the proc_frame.
* app/plug-in/plug-in.[ch]: removed the progress stuff from the
PlugIn struct and use the new proc_frame utility functions.
* app/plug-in/plug-in-message.c
* app/plug-in/plug-in-progress.c
* app/plug-in/plug-in-run.c: changed accordingly.
2004-09-22 Michael Natterer <mitch@gimp.org>
Prepare for enabling private contexts for plug-ins and scripts:
......
......@@ -29,6 +29,8 @@ libappplug_in_a_SOURCES = \
plug-in-params.h \
plug-in-proc.c \
plug-in-proc.h \
plug-in-proc-frame.c \
plug-in-proc-frame.h \
plug-in-progress.c \
plug-in-progress.h \
plug-in-rc.c \
......
......@@ -389,7 +389,7 @@ plug_in_handle_proc_run (PlugIn *plug_in,
* procedural_db_execute() will return appropriate error return_vals.
*/
return_vals = procedural_db_execute (plug_in->gimp, proc_frame->context,
plug_in->progress,
proc_frame->progress,
proc_name, args);
plug_in_pop (plug_in->gimp);
......
......@@ -45,39 +45,46 @@ plug_in_progress_start (PlugIn *plug_in,
const gchar *message,
gint display_ID)
{
PlugInProcFrame *proc_frame;
g_return_if_fail (plug_in != NULL);
if (plug_in->temp_proc_frames)
proc_frame = plug_in->temp_proc_frames->data;
else
proc_frame = &plug_in->main_proc_frame;
if (! message)
message = plug_in->prog;
if (! plug_in->progress)
if (! proc_frame->progress)
{
plug_in->progress = gimp_new_progress (plug_in->gimp, display_ID);
proc_frame->progress = gimp_new_progress (plug_in->gimp, display_ID);
if (plug_in->progress)
if (proc_frame->progress)
{
plug_in->progress_created = TRUE;
proc_frame->progress_created = TRUE;
g_object_ref (plug_in->progress);
g_object_ref (proc_frame->progress);
}
}
if (plug_in->progress)
if (proc_frame->progress)
{
if (! plug_in->progress_cancel_id)
plug_in->progress_cancel_id =
g_signal_connect (plug_in->progress, "cancel",
if (! proc_frame->progress_cancel_id)
proc_frame->progress_cancel_id =
g_signal_connect (proc_frame->progress, "cancel",
G_CALLBACK (plug_in_progress_cancel_callback),
plug_in);
if (gimp_progress_is_active (plug_in->progress))
if (gimp_progress_is_active (proc_frame->progress))
{
gimp_progress_set_text (plug_in->progress, message);
gimp_progress_set_value (plug_in->progress, 0.0);
gimp_progress_set_text (proc_frame->progress, message);
gimp_progress_set_value (proc_frame->progress, 0.0);
}
else
{
gimp_progress_start (plug_in->progress, message, TRUE);
gimp_progress_start (proc_frame->progress, message, TRUE);
}
}
}
......@@ -86,41 +93,55 @@ void
plug_in_progress_update (PlugIn *plug_in,
gdouble percentage)
{
PlugInProcFrame *proc_frame;
g_return_if_fail (plug_in != NULL);
if (! plug_in->progress ||
! gimp_progress_is_active (plug_in->progress) ||
! plug_in->progress_cancel_id)
if (plug_in->temp_proc_frames)
proc_frame = plug_in->temp_proc_frames->data;
else
proc_frame = &plug_in->main_proc_frame;
if (! proc_frame->progress ||
! gimp_progress_is_active (proc_frame->progress) ||
! proc_frame->progress_cancel_id)
{
plug_in_progress_start (plug_in, NULL, -1);
}
if (plug_in->progress && gimp_progress_is_active (plug_in->progress))
gimp_progress_set_value (plug_in->progress, percentage);
if (proc_frame->progress && gimp_progress_is_active (proc_frame->progress))
gimp_progress_set_value (proc_frame->progress, percentage);
}
void
plug_in_progress_end (PlugIn *plug_in)
{
PlugInProcFrame *proc_frame;
g_return_if_fail (plug_in != NULL);
if (plug_in->progress)
if (plug_in->temp_proc_frames)
proc_frame = plug_in->temp_proc_frames->data;
else
proc_frame = &plug_in->main_proc_frame;
if (proc_frame->progress)
{
if (plug_in->progress_cancel_id)
if (proc_frame->progress_cancel_id)
{
g_signal_handler_disconnect (plug_in->progress,
plug_in->progress_cancel_id);
plug_in->progress_cancel_id = 0;
g_signal_handler_disconnect (proc_frame->progress,
proc_frame->progress_cancel_id);
proc_frame->progress_cancel_id = 0;
}
if (gimp_progress_is_active (plug_in->progress))
gimp_progress_end (plug_in->progress);
if (gimp_progress_is_active (proc_frame->progress))
gimp_progress_end (proc_frame->progress);
if (plug_in->progress_created)
if (proc_frame->progress_created)
{
gimp_free_progress (plug_in->gimp, plug_in->progress);
g_object_unref (plug_in->progress);
plug_in->progress = NULL;
gimp_free_progress (plug_in->gimp, proc_frame->progress);
g_object_unref (proc_frame->progress);
proc_frame->progress = NULL;
}
}
}
......@@ -153,21 +174,21 @@ plug_in_progress_install (PlugIn *plug_in,
else
proc_frame = &plug_in->main_proc_frame;
if (plug_in->progress)
if (proc_frame->progress)
{
plug_in_progress_end (plug_in);
if (plug_in->progress)
if (proc_frame->progress)
{
g_object_unref (plug_in->progress);
plug_in->progress = NULL;
g_object_unref (proc_frame->progress);
proc_frame->progress = NULL;
}
}
plug_in->progress = g_object_new (GIMP_TYPE_PDB_PROGRESS,
"context", proc_frame->context,
"callback-name", progress_callback,
NULL);
proc_frame->progress = g_object_new (GIMP_TYPE_PDB_PROGRESS,
"context", proc_frame->context,
"callback-name", progress_callback,
NULL);
return TRUE;
}
......@@ -176,14 +197,21 @@ gboolean
plug_in_progress_uninstall (PlugIn *plug_in,
const gchar *progress_callback)
{
PlugInProcFrame *proc_frame;
g_return_val_if_fail (plug_in != NULL, FALSE);
g_return_val_if_fail (progress_callback != NULL, FALSE);
if (GIMP_IS_PDB_PROGRESS (plug_in->progress))
if (plug_in->temp_proc_frames)
proc_frame = plug_in->temp_proc_frames->data;
else
proc_frame = &plug_in->main_proc_frame;
if (GIMP_IS_PDB_PROGRESS (proc_frame->progress))
{
plug_in_progress_end (plug_in);
g_object_unref (plug_in->progress);
plug_in->progress = NULL;
g_object_unref (proc_frame->progress);
proc_frame->progress = NULL;
return TRUE;
}
......
......@@ -71,6 +71,7 @@
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpenvirontable.h"
#include "core/gimpprogress.h"
#include "plug-in.h"
#include "plug-ins.h"
......@@ -162,7 +163,7 @@ plug_in_call_query (Gimp *gimp,
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (plug_in_def != NULL);
plug_in = plug_in_new (gimp, context, NULL, plug_in_def->prog);
plug_in = plug_in_new (gimp, context, NULL, NULL, plug_in_def->prog);
if (plug_in)
{
......@@ -203,7 +204,7 @@ plug_in_call_init (Gimp *gimp,
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (plug_in_def != NULL);
plug_in = plug_in_new (gimp, context, NULL, plug_in_def->prog);
plug_in = plug_in_new (gimp, context, NULL, NULL, plug_in_def->prog);
if (plug_in)
{
......@@ -234,16 +235,17 @@ plug_in_call_init (Gimp *gimp,
}
PlugIn *
plug_in_new (Gimp *gimp,
GimpContext *context,
ProcRecord *proc_rec,
const gchar *prog)
plug_in_new (Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
ProcRecord *proc_rec,
const gchar *prog)
{
PlugIn *plug_in;
PlugInProcFrame *proc_frame;
PlugIn *plug_in;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
g_return_val_if_fail (prog != NULL, NULL);
g_return_val_if_fail (g_path_is_absolute (prog), NULL);
......@@ -274,20 +276,11 @@ plug_in_new (Gimp *gimp,
plug_in->ext_main_loop = NULL;
proc_frame = &plug_in->main_proc_frame;
proc_frame->context = g_object_ref (context);
proc_frame->proc_rec = proc_rec;
proc_frame->main_loop = NULL;
proc_frame->return_vals = NULL;
proc_frame->n_return_vals = 0;
plug_in_proc_frame_init (&plug_in->main_proc_frame,
context, progress, proc_rec);
plug_in->temp_proc_frames = NULL;
plug_in->progress = NULL;
plug_in->progress_created = FALSE;
plug_in->progress_cancel_id = 0;
plug_in->plug_in_def = NULL;
return plug_in;
......@@ -316,13 +309,7 @@ plug_in_unref (PlugIn *plug_in)
g_free (plug_in->name);
g_free (plug_in->prog);
if (plug_in->progress)
plug_in_progress_end (plug_in);
if (plug_in->progress)
g_object_unref (plug_in->progress);
g_object_unref (plug_in->main_proc_frame.context);
plug_in_proc_frame_dispose (&plug_in->main_proc_frame, plug_in);
g_free (plug_in);
}
......@@ -620,15 +607,6 @@ plug_in_close (PlugIn *plug_in,
wire_clear_error ();
if (plug_in->progress)
plug_in_progress_end (plug_in);
if (plug_in->progress)
{
g_object_unref (plug_in->progress);
plug_in->progress = NULL;
}
while (plug_in->temp_proc_frames)
{
#ifdef GIMP_UNSTABLE
......@@ -648,6 +626,8 @@ plug_in_close (PlugIn *plug_in,
g_main_loop_quit (plug_in->main_proc_frame.main_loop);
}
plug_in_proc_frame_dispose (&plug_in->main_proc_frame, plug_in);
if (plug_in->ext_main_loop &&
g_main_loop_is_running (plug_in->ext_main_loop))
{
......@@ -868,20 +848,19 @@ plug_in_pop (Gimp *gimp)
}
void
plug_in_proc_frame_push (PlugIn *plug_in,
GimpContext *context,
ProcRecord *proc_rec)
plug_in_proc_frame_push (PlugIn *plug_in,
GimpContext *context,
GimpProgress *progress,
ProcRecord *proc_rec)
{
PlugInProcFrame *proc_frame;
g_return_if_fail (plug_in != NULL);
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
g_return_if_fail (proc_rec != NULL);
proc_frame = g_new0 (PlugInProcFrame, 1);
proc_frame->context = g_object_ref (context);
proc_frame->proc_rec = proc_rec;
proc_frame = plug_in_proc_frame_new (context, progress, proc_rec);
plug_in->temp_proc_frames = g_list_prepend (plug_in->temp_proc_frames,
proc_frame);
......@@ -897,11 +876,10 @@ plug_in_proc_frame_pop (PlugIn *plug_in)
proc_frame = (PlugInProcFrame *) plug_in->temp_proc_frames->data;
plug_in_proc_frame_free (proc_frame, plug_in);
plug_in->temp_proc_frames = g_list_remove (plug_in->temp_proc_frames,
proc_frame);
g_object_unref (proc_frame->context);
g_free (proc_frame);
}
void
......
......@@ -22,19 +22,12 @@
#include <sys/types.h> /* pid_t */
#include "plug-in-proc-frame.h"
#define WRITE_BUFFER_SIZE 512
struct _PlugInProcFrame
{
GimpContext *context;
ProcRecord *proc_rec;
GMainLoop *main_loop;
Argument *return_vals;
gint n_return_vals;
};
struct _PlugIn
{
Gimp *gimp;
......@@ -69,49 +62,47 @@ struct _PlugIn
GList *temp_proc_frames;
GimpProgress *progress; /* Progress dialog */
gboolean progress_created; /* Was the progress created by the plug-in */
gulong progress_cancel_id;
PlugInDef *plug_in_def; /* Valid only during query() and init() */
};
void plug_in_init (Gimp *gimp);
void plug_in_exit (Gimp *gimp);
void plug_in_init (Gimp *gimp);
void plug_in_exit (Gimp *gimp);
void plug_in_call_query (Gimp *gimp,
GimpContext *context,
PlugInDef *plug_in_def);
void plug_in_call_init (Gimp *gimp,
GimpContext *context,
PlugInDef *plug_in_def);
void plug_in_call_query (Gimp *gimp,
GimpContext *context,
PlugInDef *plug_in_def);
void plug_in_call_init (Gimp *gimp,
GimpContext *context,
PlugInDef *plug_in_def);
PlugIn * plug_in_new (Gimp *gimp,
GimpContext *context,
ProcRecord *proc_rec,
const gchar *prog);
PlugIn * plug_in_new (Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
ProcRecord *proc_rec,
const gchar *prog);
void plug_in_ref (PlugIn *plug_in);
void plug_in_unref (PlugIn *plug_in);
void plug_in_ref (PlugIn *plug_in);
void plug_in_unref (PlugIn *plug_in);
gboolean plug_in_open (PlugIn *plug_in);
void plug_in_close (PlugIn *plug_in,
gboolean kill_it);
gboolean plug_in_open (PlugIn *plug_in);
void plug_in_close (PlugIn *plug_in,
gboolean kill_it);
void plug_in_push (Gimp *gimp,
PlugIn *plug_in);
void plug_in_pop (Gimp *gimp);
void plug_in_push (Gimp *gimp,
PlugIn *plug_in);
void plug_in_pop (Gimp *gimp);
void plug_in_proc_frame_push (PlugIn *plug_in,
GimpContext *context,
ProcRecord *proc_rec);
void plug_in_proc_frame_pop (PlugIn *plug_in);
void plug_in_proc_frame_push (PlugIn *plug_in,
GimpContext *context,
GimpProgress *progress,
ProcRecord *proc_rec);
void plug_in_proc_frame_pop (PlugIn *plug_in);
void plug_in_main_loop (PlugIn *plug_in);
void plug_in_main_loop_quit (PlugIn *plug_in);
void plug_in_main_loop (PlugIn *plug_in);
void plug_in_main_loop_quit (PlugIn *plug_in);
gchar * plug_in_get_undo_desc (PlugIn *plug_in);
gchar * plug_in_get_undo_desc (PlugIn *plug_in);
#endif /* __PLUG_IN_H__ */
......@@ -86,7 +86,7 @@ plug_in_run (Gimp *gimp,
goto done;
}
plug_in = plug_in_new (gimp, context, proc_rec,
plug_in = plug_in_new (gimp, context, progress, proc_rec,
proc_rec->exec_method.plug_in.filename);
if (plug_in)
......@@ -101,9 +101,6 @@ plug_in_run (Gimp *gimp,
goto done;
}
if (progress)
plug_in->progress = g_object_ref (progress);
config.version = GIMP_PROTOCOL_VERSION;
config.tile_width = TILE_WIDTH;
config.tile_height = TILE_HEIGHT;
......@@ -250,7 +247,7 @@ plug_in_temp_run (ProcRecord *proc_rec,
{
GPProcRun proc_run;
plug_in_proc_frame_push (plug_in, context, proc_rec);
plug_in_proc_frame_push (plug_in, context, progress, proc_rec);
proc_run.name = proc_rec->name;
proc_run.nparams = argc;
......
......@@ -86,7 +86,7 @@ plug_in_run (Gimp *gimp,
goto done;
}
plug_in = plug_in_new (gimp, context, proc_rec,
plug_in = plug_in_new (gimp, context, progress, proc_rec,
proc_rec->exec_method.plug_in.filename);
if (plug_in)
......@@ -101,9 +101,6 @@ plug_in_run (Gimp *gimp,
goto done;
}
if (progress)
plug_in->progress = g_object_ref (progress);
config.version = GIMP_PROTOCOL_VERSION;
config.tile_width = TILE_WIDTH;
config.tile_height = TILE_HEIGHT;
......@@ -250,7 +247,7 @@ plug_in_temp_run (ProcRecord *proc_rec,
{
GPProcRun proc_run;
plug_in_proc_frame_push (plug_in, context, proc_rec);
plug_in_proc_frame_push (plug_in, context, progress, proc_rec);
proc_run.name = proc_rec->name;
proc_run.nparams = argc;
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* plug-in-proc-frame.c
*
* 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 <glib-object.h>
#include "plug-in-types.h"
#include "core/gimpcontext.h"
#include "core/gimpprogress.h"
#include "plug-in-proc-frame.h"
#include "plug-in-progress.h"
/* publuc functions */
PlugInProcFrame *
plug_in_proc_frame_new (GimpContext *context,
GimpProgress *progress,
ProcRecord *proc_rec)
{
PlugInProcFrame *proc_frame;
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
g_return_val_if_fail (proc_rec != NULL, NULL);
proc_frame = g_new0 (PlugInProcFrame, 1);
plug_in_proc_frame_init (proc_frame, context, progress, proc_rec);
return proc_frame;
}
void
plug_in_proc_frame_init (PlugInProcFrame *proc_frame,
GimpContext *context,
GimpProgress *progress,
ProcRecord *proc_rec)
{
g_return_if_fail (proc_frame != NULL);
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
g_return_if_fail (proc_rec != NULL);
proc_frame->context = g_object_ref (context);
proc_frame->proc_rec = proc_rec;
proc_frame->main_loop = NULL;
proc_frame->return_vals = NULL;
proc_frame->n_return_vals = 0;
proc_frame->progress = progress ? g_object_ref (progress) : NULL;
proc_frame->progress_created = FALSE;
proc_frame->progress_cancel_id = 0;
}
void
plug_in_proc_frame_dispose (PlugInProcFrame *proc_frame,
PlugIn *plug_in)
{
g_return_if_fail (proc_frame != NULL);
g_return_if_fail (plug_in != NULL);
if (proc_frame->progress)
{
plug_in_progress_end (plug_in);
if (proc_frame->progress)
{
g_object_unref (proc_frame->progress);
proc_frame->progress = NULL;