1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2004-09-22 23:12:24 +08:00
|
|
|
* plug-in-progress.c
|
|
|
|
*
|
1997-11-25 06:05:25 +08:00
|
|
|
* 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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-07-16 20:49:04 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "config.h"
|
1999-03-07 20:56:03 +08:00
|
|
|
|
2003-09-11 06:06:45 +08:00
|
|
|
#include <glib-object.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
#include "plug-in-types.h"
|
2001-12-28 01:58:30 +08:00
|
|
|
|
2003-09-11 06:06:45 +08:00
|
|
|
#include "core/gimp.h"
|
2004-08-30 02:36:30 +08:00
|
|
|
#include "core/gimppdbprogress.h"
|
2004-08-11 02:47:21 +08:00
|
|
|
#include "core/gimpprogress.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2003-02-03 21:21:31 +08:00
|
|
|
#include "pdb/procedural_db.h"
|
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
#include "plug-in.h"
|
|
|
|
#include "plug-in-progress.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
/* local function prototypes */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2004-08-30 02:36:30 +08:00
|
|
|
static void plug_in_progress_cancel_callback (GimpProgress *progress,
|
|
|
|
PlugIn *plug_in);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
/* public functions */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-05-04 03:22:58 +08:00
|
|
|
void
|
2003-01-20 20:17:32 +08:00
|
|
|
plug_in_progress_start (PlugIn *plug_in,
|
|
|
|
const gchar *message,
|
2004-08-11 17:36:51 +08:00
|
|
|
gint display_ID)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
PlugInProcFrame *proc_frame;
|
|
|
|
|
2003-01-20 20:17:32 +08:00
|
|
|
g_return_if_fail (plug_in != NULL);
|
|
|
|
|
2004-09-22 23:26:58 +08:00
|
|
|
proc_frame = plug_in_get_proc_frame (plug_in);
|
2004-09-22 20:27:18 +08:00
|
|
|
|
|
|
|
if (! proc_frame->progress)
|
2004-08-11 02:47:21 +08:00
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
proc_frame->progress = gimp_new_progress (plug_in->gimp, display_ID);
|
2004-08-11 02:47:21 +08:00
|
|
|
|
2004-09-22 20:27:18 +08:00
|
|
|
if (proc_frame->progress)
|
2004-08-17 16:21:30 +08:00
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
proc_frame->progress_created = TRUE;
|
2004-08-17 16:21:30 +08:00
|
|
|
|
2004-09-22 20:27:18 +08:00
|
|
|
g_object_ref (proc_frame->progress);
|
2004-08-17 16:21:30 +08:00
|
|
|
}
|
2004-08-11 02:47:21 +08:00
|
|
|
}
|
|
|
|
|
2004-09-22 20:27:18 +08:00
|
|
|
if (proc_frame->progress)
|
2004-08-11 02:47:21 +08:00
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
if (! proc_frame->progress_cancel_id)
|
|
|
|
proc_frame->progress_cancel_id =
|
|
|
|
g_signal_connect (proc_frame->progress, "cancel",
|
2004-08-30 02:36:30 +08:00
|
|
|
G_CALLBACK (plug_in_progress_cancel_callback),
|
2004-08-11 18:29:56 +08:00
|
|
|
plug_in);
|
|
|
|
|
2004-09-22 20:27:18 +08:00
|
|
|
if (gimp_progress_is_active (proc_frame->progress))
|
2004-08-11 02:47:21 +08:00
|
|
|
{
|
2005-02-13 08:11:24 +08:00
|
|
|
if (message)
|
|
|
|
gimp_progress_set_text (proc_frame->progress, message);
|
2005-02-13 02:00:16 +08:00
|
|
|
|
|
|
|
if (gimp_progress_get_value (proc_frame->progress) > 0.0)
|
|
|
|
gimp_progress_set_value (proc_frame->progress, 0.0);
|
2004-08-11 08:34:34 +08:00
|
|
|
}
|
2004-08-11 18:29:56 +08:00
|
|
|
else
|
2004-08-11 08:34:34 +08:00
|
|
|
{
|
2005-02-13 08:11:24 +08:00
|
|
|
gimp_progress_start (proc_frame->progress,
|
|
|
|
message ? message : "",
|
|
|
|
TRUE);
|
2004-08-11 02:47:21 +08:00
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-05-04 03:22:58 +08:00
|
|
|
void
|
2000-02-25 00:11:26 +08:00
|
|
|
plug_in_progress_update (PlugIn *plug_in,
|
|
|
|
gdouble percentage)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
PlugInProcFrame *proc_frame;
|
|
|
|
|
2003-01-20 20:17:32 +08:00
|
|
|
g_return_if_fail (plug_in != NULL);
|
|
|
|
|
2004-09-22 23:26:58 +08:00
|
|
|
proc_frame = plug_in_get_proc_frame (plug_in);
|
2004-09-22 20:27:18 +08:00
|
|
|
|
|
|
|
if (! proc_frame->progress ||
|
|
|
|
! gimp_progress_is_active (proc_frame->progress) ||
|
|
|
|
! proc_frame->progress_cancel_id)
|
2004-08-11 18:29:56 +08:00
|
|
|
{
|
|
|
|
plug_in_progress_start (plug_in, NULL, -1);
|
|
|
|
}
|
2002-02-22 23:08:47 +08:00
|
|
|
|
2004-09-22 20:27:18 +08:00
|
|
|
if (proc_frame->progress && gimp_progress_is_active (proc_frame->progress))
|
|
|
|
gimp_progress_set_value (proc_frame->progress, percentage);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2001-05-17 02:09:45 +08:00
|
|
|
|
2005-02-12 22:18:12 +08:00
|
|
|
void
|
|
|
|
plug_in_progress_pulse (PlugIn *plug_in)
|
|
|
|
{
|
|
|
|
PlugInProcFrame *proc_frame;
|
|
|
|
|
|
|
|
g_return_if_fail (plug_in != NULL);
|
|
|
|
|
|
|
|
proc_frame = plug_in_get_proc_frame (plug_in);
|
|
|
|
|
|
|
|
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 (proc_frame->progress && gimp_progress_is_active (proc_frame->progress))
|
|
|
|
gimp_progress_pulse (proc_frame->progress);
|
|
|
|
}
|
|
|
|
|
2005-02-13 02:25:58 +08:00
|
|
|
void
|
|
|
|
plug_in_progress_set_text (PlugIn *plug_in,
|
|
|
|
const gchar *message)
|
|
|
|
{
|
|
|
|
PlugInProcFrame *proc_frame;
|
|
|
|
|
|
|
|
g_return_if_fail (plug_in != NULL);
|
|
|
|
|
|
|
|
proc_frame = plug_in_get_proc_frame (plug_in);
|
|
|
|
|
|
|
|
if (proc_frame->progress)
|
|
|
|
gimp_progress_set_text (proc_frame->progress, message);
|
|
|
|
}
|
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
void
|
|
|
|
plug_in_progress_end (PlugIn *plug_in)
|
2001-05-17 02:09:45 +08:00
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
PlugInProcFrame *proc_frame;
|
|
|
|
|
2003-01-20 20:17:32 +08:00
|
|
|
g_return_if_fail (plug_in != NULL);
|
|
|
|
|
2004-09-22 23:26:58 +08:00
|
|
|
proc_frame = plug_in_get_proc_frame (plug_in);
|
2004-09-22 20:27:18 +08:00
|
|
|
|
|
|
|
if (proc_frame->progress)
|
2001-05-17 02:09:45 +08:00
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
if (proc_frame->progress_cancel_id)
|
2004-08-11 02:47:21 +08:00
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
g_signal_handler_disconnect (proc_frame->progress,
|
|
|
|
proc_frame->progress_cancel_id);
|
|
|
|
proc_frame->progress_cancel_id = 0;
|
2004-08-11 02:47:21 +08:00
|
|
|
}
|
|
|
|
|
2004-09-22 20:27:18 +08:00
|
|
|
if (gimp_progress_is_active (proc_frame->progress))
|
|
|
|
gimp_progress_end (proc_frame->progress);
|
2004-08-11 18:29:56 +08:00
|
|
|
|
2004-09-22 20:27:18 +08:00
|
|
|
if (proc_frame->progress_created)
|
2004-08-11 02:47:21 +08:00
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
gimp_free_progress (plug_in->gimp, proc_frame->progress);
|
|
|
|
g_object_unref (proc_frame->progress);
|
|
|
|
proc_frame->progress = NULL;
|
2004-08-11 02:47:21 +08:00
|
|
|
}
|
2001-05-17 02:09:45 +08:00
|
|
|
}
|
2002-03-21 01:46:13 +08:00
|
|
|
}
|
2001-05-17 02:09:45 +08:00
|
|
|
|
2004-08-31 05:03:52 +08:00
|
|
|
gboolean
|
2004-08-30 02:36:30 +08:00
|
|
|
plug_in_progress_install (PlugIn *plug_in,
|
|
|
|
const gchar *progress_callback)
|
|
|
|
{
|
2004-09-22 08:32:00 +08:00
|
|
|
PlugInProcFrame *proc_frame;
|
|
|
|
ProcRecord *proc_rec;
|
2004-08-31 05:03:52 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (plug_in != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (progress_callback != NULL, FALSE);
|
|
|
|
|
|
|
|
proc_rec = procedural_db_lookup (plug_in->gimp, progress_callback);
|
|
|
|
|
|
|
|
if (! proc_rec ||
|
|
|
|
proc_rec->num_args != 3 ||
|
|
|
|
proc_rec->args[0].arg_type != GIMP_PDB_INT32 ||
|
|
|
|
proc_rec->args[1].arg_type != GIMP_PDB_STRING ||
|
|
|
|
proc_rec->args[2].arg_type != GIMP_PDB_FLOAT ||
|
|
|
|
proc_rec->proc_type != GIMP_TEMPORARY ||
|
|
|
|
proc_rec->exec_method.temporary.plug_in != plug_in)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2004-09-22 23:26:58 +08:00
|
|
|
proc_frame = plug_in_get_proc_frame (plug_in);
|
2004-09-22 08:32:00 +08:00
|
|
|
|
2004-09-22 20:27:18 +08:00
|
|
|
if (proc_frame->progress)
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
|
|
|
plug_in_progress_end (plug_in);
|
|
|
|
|
2004-09-22 20:27:18 +08:00
|
|
|
if (proc_frame->progress)
|
2004-08-30 22:57:24 +08:00
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
g_object_unref (proc_frame->progress);
|
|
|
|
proc_frame->progress = NULL;
|
2004-08-30 22:57:24 +08:00
|
|
|
}
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
|
|
|
|
2004-09-22 20:27:18 +08:00
|
|
|
proc_frame->progress = g_object_new (GIMP_TYPE_PDB_PROGRESS,
|
2004-09-23 00:22:43 +08:00
|
|
|
"context", proc_frame->main_context,
|
2004-09-22 20:27:18 +08:00
|
|
|
"callback-name", progress_callback,
|
|
|
|
NULL);
|
2004-08-31 05:03:52 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
|
|
|
|
2004-08-31 05:03:52 +08:00
|
|
|
gboolean
|
2004-08-30 02:36:30 +08:00
|
|
|
plug_in_progress_uninstall (PlugIn *plug_in,
|
|
|
|
const gchar *progress_callback)
|
|
|
|
{
|
2004-09-22 20:27:18 +08:00
|
|
|
PlugInProcFrame *proc_frame;
|
|
|
|
|
2004-08-31 05:03:52 +08:00
|
|
|
g_return_val_if_fail (plug_in != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (progress_callback != NULL, FALSE);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2004-09-22 23:26:58 +08:00
|
|
|
proc_frame = plug_in_get_proc_frame (plug_in);
|
2004-09-22 20:27:18 +08:00
|
|
|
|
|
|
|
if (GIMP_IS_PDB_PROGRESS (proc_frame->progress))
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
|
|
|
plug_in_progress_end (plug_in);
|
2004-09-22 20:27:18 +08:00
|
|
|
g_object_unref (proc_frame->progress);
|
|
|
|
proc_frame->progress = NULL;
|
2004-08-31 05:03:52 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
2004-08-31 05:03:52 +08:00
|
|
|
|
|
|
|
return FALSE;
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
|
|
|
|
2004-08-31 05:03:52 +08:00
|
|
|
gboolean
|
2004-08-30 02:36:30 +08:00
|
|
|
plug_in_progress_cancel (PlugIn *plug_in,
|
|
|
|
const gchar *progress_callback)
|
|
|
|
{
|
2004-08-31 05:03:52 +08:00
|
|
|
g_return_val_if_fail (plug_in != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (progress_callback != NULL, FALSE);
|
|
|
|
|
|
|
|
return FALSE;
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
|
|
|
|
2004-10-14 23:15:03 +08:00
|
|
|
void
|
|
|
|
plug_in_progress_message (PlugIn *plug_in,
|
|
|
|
const gchar *message)
|
|
|
|
{
|
|
|
|
PlugInProcFrame *proc_frame;
|
|
|
|
gchar *domain;
|
|
|
|
|
|
|
|
g_return_if_fail (plug_in != NULL);
|
|
|
|
g_return_if_fail (message != NULL);
|
|
|
|
|
|
|
|
proc_frame = plug_in_get_proc_frame (plug_in);
|
|
|
|
|
|
|
|
domain = plug_in_get_undo_desc (plug_in);
|
|
|
|
|
|
|
|
if (proc_frame->progress)
|
|
|
|
{
|
|
|
|
gimp_progress_message (proc_frame->progress,
|
|
|
|
plug_in->gimp, domain, message);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_message (plug_in->gimp, domain, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (domain);
|
|
|
|
}
|
|
|
|
|
2001-05-17 02:09:45 +08:00
|
|
|
|
2002-03-21 01:46:13 +08:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2004-08-30 02:36:30 +08:00
|
|
|
plug_in_progress_cancel_callback (GimpProgress *progress,
|
|
|
|
PlugIn *plug_in)
|
2002-03-21 01:46:13 +08:00
|
|
|
{
|
2004-09-22 07:56:40 +08:00
|
|
|
PlugInProcFrame *proc_frame = &plug_in->main_proc_frame;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
if (proc_frame->main_loop)
|
|
|
|
{
|
|
|
|
proc_frame->return_vals = g_new (Argument, 1);
|
|
|
|
proc_frame->n_return_vals = 1;
|
|
|
|
|
|
|
|
proc_frame->return_vals->arg_type = GIMP_PDB_STATUS;
|
|
|
|
proc_frame->return_vals->value.pdb_int = GIMP_PDB_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (list = plug_in->temp_proc_frames; list; list = g_list_next (list))
|
2003-02-03 21:21:31 +08:00
|
|
|
{
|
2004-09-22 07:56:40 +08:00
|
|
|
proc_frame = list->data;
|
|
|
|
|
|
|
|
if (proc_frame->main_loop)
|
|
|
|
{
|
|
|
|
proc_frame->return_vals = g_new (Argument, 1);
|
|
|
|
proc_frame->n_return_vals = 1;
|
2003-02-03 21:21:31 +08:00
|
|
|
|
2004-09-22 07:56:40 +08:00
|
|
|
proc_frame->return_vals->arg_type = GIMP_PDB_STATUS;
|
|
|
|
proc_frame->return_vals->value.pdb_int = GIMP_PDB_CANCEL;
|
|
|
|
}
|
2003-02-03 21:21:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
plug_in_close (plug_in, TRUE);
|
|
|
|
plug_in_unref (plug_in);
|
2001-05-17 02:09:45 +08:00
|
|
|
}
|