2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-08-30 02:36:30 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimppdbprogress.c
|
|
|
|
* Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-08-30 02:36:30 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-08-30 02:36:30 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2004-08-30 02:36:30 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2012-03-30 01:19:01 +08:00
|
|
|
#include <gegl.h>
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2004-08-30 02:36:30 +08:00
|
|
|
#include "core-types.h"
|
|
|
|
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
|
2006-04-26 17:13:47 +08:00
|
|
|
#include "pdb/gimppdb.h"
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2006-10-10 02:49:15 +08:00
|
|
|
#include "gimp.h"
|
2006-04-04 04:54:55 +08:00
|
|
|
#include "gimpparamspecs.h"
|
2004-08-30 02:36:30 +08:00
|
|
|
#include "gimppdbprogress.h"
|
|
|
|
#include "gimpprogress.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2006-04-26 17:13:47 +08:00
|
|
|
PROP_PDB,
|
2004-08-30 02:36:30 +08:00
|
|
|
PROP_CONTEXT,
|
|
|
|
PROP_CALLBACK_NAME
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_pdb_progress_class_init (GimpPdbProgressClass *klass);
|
|
|
|
static void gimp_pdb_progress_init (GimpPdbProgress *progress,
|
|
|
|
GimpPdbProgressClass *klass);
|
2005-12-11 03:24:36 +08:00
|
|
|
static void gimp_pdb_progress_progress_iface_init (GimpProgressInterface *iface);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void gimp_pdb_progress_constructed (GObject *object);
|
2004-08-30 02:36:30 +08:00
|
|
|
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);
|
|
|
|
|
2011-02-06 19:07:55 +08:00
|
|
|
static GimpProgress * gimp_pdb_progress_progress_start (GimpProgress *progress,
|
2014-07-13 05:45:20 +08:00
|
|
|
gboolean cancellable,
|
|
|
|
const gchar *message);
|
2011-02-06 19:07:55 +08:00
|
|
|
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 void gimp_pdb_progress_progress_pulse (GimpProgress *progress);
|
|
|
|
static guint32 gimp_pdb_progress_progress_get_window_id (GimpProgress *progress);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
static GObjectClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_pdb_progress_get_type (void)
|
|
|
|
{
|
|
|
|
static GType type = 0;
|
|
|
|
|
|
|
|
if (! type)
|
|
|
|
{
|
2006-10-18 21:17:50 +08:00
|
|
|
const GTypeInfo info =
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2006-10-18 21:17:50 +08:00
|
|
|
const GInterfaceInfo progress_iface_info =
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
|
|
|
(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);
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
object_class->constructed = gimp_pdb_progress_constructed;
|
2004-08-30 02:36:30 +08:00
|
|
|
object_class->dispose = gimp_pdb_progress_dispose;
|
|
|
|
object_class->finalize = gimp_pdb_progress_finalize;
|
|
|
|
object_class->set_property = gimp_pdb_progress_set_property;
|
|
|
|
|
2006-04-26 17:13:47 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_PDB,
|
|
|
|
g_param_spec_object ("pdb", NULL, NULL,
|
|
|
|
GIMP_TYPE_PDB,
|
|
|
|
GIMP_PARAM_WRITABLE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2004-08-30 02:36:30 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_CONTEXT,
|
|
|
|
g_param_spec_object ("context", NULL, NULL,
|
|
|
|
GIMP_TYPE_CONTEXT,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_WRITABLE |
|
2004-08-30 02:36:30 +08:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class, PROP_CALLBACK_NAME,
|
|
|
|
g_param_spec_string ("callback-name",
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
2006-01-19 04:29:40 +08:00
|
|
|
GIMP_PARAM_WRITABLE |
|
2004-08-30 02:36:30 +08:00
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pdb_progress_init (GimpPdbProgress *progress,
|
|
|
|
GimpPdbProgressClass *klass)
|
|
|
|
{
|
|
|
|
klass->progresses = g_list_prepend (klass->progresses, progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-12-11 03:24:36 +08:00
|
|
|
gimp_pdb_progress_progress_iface_init (GimpProgressInterface *iface)
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
2011-02-06 19:07:55 +08:00
|
|
|
iface->start = gimp_pdb_progress_progress_start;
|
|
|
|
iface->end = gimp_pdb_progress_progress_end;
|
|
|
|
iface->is_active = gimp_pdb_progress_progress_is_active;
|
|
|
|
iface->set_text = gimp_pdb_progress_progress_set_text;
|
|
|
|
iface->set_value = gimp_pdb_progress_progress_set_value;
|
|
|
|
iface->get_value = gimp_pdb_progress_progress_get_value;
|
|
|
|
iface->pulse = gimp_pdb_progress_progress_pulse;
|
|
|
|
iface->get_window_id = gimp_pdb_progress_progress_get_window_id;
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
|
|
|
|
2011-01-13 05:53:58 +08:00
|
|
|
static void
|
|
|
|
gimp_pdb_progress_constructed (GObject *object)
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
2011-01-13 05:53:58 +08:00
|
|
|
GimpPdbProgress *progress = GIMP_PDB_PROGRESS (object);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2012-11-13 04:51:22 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2018-02-12 05:23:10 +08:00
|
|
|
gimp_assert (GIMP_IS_PDB (progress->pdb));
|
|
|
|
gimp_assert (GIMP_IS_CONTEXT (progress->context));
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-07-16 00:38:01 +08:00
|
|
|
g_clear_object (&progress->pdb);
|
|
|
|
g_clear_object (&progress->context);
|
|
|
|
g_clear_pointer (&progress->callback_name, g_free);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2006-04-26 17:13:47 +08:00
|
|
|
case PROP_PDB:
|
|
|
|
if (progress->pdb)
|
|
|
|
g_object_unref (progress->pdb);
|
2008-07-23 14:47:23 +08:00
|
|
|
progress->pdb = g_value_dup_object (value);
|
2006-04-26 17:13:47 +08:00
|
|
|
break;
|
|
|
|
|
2004-08-30 02:36:30 +08:00
|
|
|
case PROP_CONTEXT:
|
|
|
|
if (progress->context)
|
|
|
|
g_object_unref (progress->context);
|
2008-07-23 14:47:23 +08:00
|
|
|
progress->context = g_value_dup_object (value);
|
2004-08-30 02:36:30 +08:00
|
|
|
break;
|
2006-04-26 17:13:47 +08:00
|
|
|
|
2004-08-30 02:36:30 +08:00
|
|
|
case PROP_CALLBACK_NAME:
|
|
|
|
if (progress->callback_name)
|
|
|
|
g_free (progress->callback_name);
|
|
|
|
progress->callback_name = g_value_dup_string (value);
|
|
|
|
break;
|
2006-04-26 17:13:47 +08:00
|
|
|
|
2004-08-30 02:36:30 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
static gdouble
|
2004-08-30 22:57:24 +08:00
|
|
|
gimp_pdb_progress_run_callback (GimpPdbProgress *progress,
|
|
|
|
GimpProgressCommand command,
|
|
|
|
const gchar *text,
|
|
|
|
gdouble value)
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
2005-09-10 02:07:31 +08:00
|
|
|
gdouble retval = 0;
|
|
|
|
|
2005-06-25 00:46:00 +08:00
|
|
|
if (progress->callback_name && ! progress->callback_busy)
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
2012-05-04 06:50:23 +08:00
|
|
|
GimpValueArray *return_vals;
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
progress->callback_busy = TRUE;
|
|
|
|
|
2006-04-26 17:13:47 +08:00
|
|
|
return_vals =
|
|
|
|
gimp_pdb_execute_procedure_by_name (progress->pdb,
|
|
|
|
progress->context,
|
2007-12-03 02:05:54 +08:00
|
|
|
NULL, NULL,
|
2006-04-26 17:13:47 +08:00
|
|
|
progress->callback_name,
|
2019-08-04 20:10:42 +08:00
|
|
|
GIMP_TYPE_PROGRESS_COMMAND, command,
|
|
|
|
G_TYPE_STRING, text,
|
|
|
|
G_TYPE_DOUBLE, value,
|
2006-04-26 17:13:47 +08:00
|
|
|
G_TYPE_NONE);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) !=
|
|
|
|
GIMP_PDB_SUCCESS)
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
2006-10-10 02:49:15 +08:00
|
|
|
gimp_message (progress->context->gimp, NULL, GIMP_MESSAGE_ERROR,
|
|
|
|
_("Unable to run %s callback. "
|
|
|
|
"The corresponding plug-in may have crashed."),
|
|
|
|
g_type_name (G_TYPE_FROM_INSTANCE (progress)));
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
2012-05-04 06:50:23 +08:00
|
|
|
else if (gimp_value_array_length (return_vals) >= 2 &&
|
|
|
|
G_VALUE_HOLDS_DOUBLE (gimp_value_array_index (return_vals, 1)))
|
2005-09-10 02:07:31 +08:00
|
|
|
{
|
2012-05-04 06:50:23 +08:00
|
|
|
retval = g_value_get_double (gimp_value_array_index (return_vals, 1));
|
2005-09-10 02:07:31 +08:00
|
|
|
}
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
gimp_value_array_unref (return_vals);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
progress->callback_busy = FALSE;
|
|
|
|
}
|
2005-09-10 02:07:31 +08:00
|
|
|
|
|
|
|
return retval;
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GimpProgress *
|
|
|
|
gimp_pdb_progress_progress_start (GimpProgress *progress,
|
2014-07-13 05:45:20 +08:00
|
|
|
gboolean cancellable,
|
|
|
|
const gchar *message)
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
|
|
|
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
|
|
|
|
|
|
|
|
if (! pdb_progress->active)
|
|
|
|
{
|
2004-08-30 22:57:24 +08:00
|
|
|
gimp_pdb_progress_run_callback (pdb_progress,
|
|
|
|
GIMP_PROGRESS_COMMAND_START,
|
|
|
|
message, 0.0);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2004-08-30 22:57:24 +08:00
|
|
|
gimp_pdb_progress_run_callback (pdb_progress,
|
|
|
|
GIMP_PROGRESS_COMMAND_END,
|
|
|
|
NULL, 0.0);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
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)
|
2004-08-30 22:57:24 +08:00
|
|
|
gimp_pdb_progress_run_callback (pdb_progress,
|
|
|
|
GIMP_PROGRESS_COMMAND_SET_TEXT,
|
|
|
|
message, 0.0);
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_pdb_progress_progress_set_value (GimpProgress *progress,
|
|
|
|
gdouble percentage)
|
|
|
|
{
|
|
|
|
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
|
|
|
|
|
|
|
|
if (pdb_progress->active)
|
|
|
|
{
|
2004-08-30 22:57:24 +08:00
|
|
|
gimp_pdb_progress_run_callback (pdb_progress,
|
|
|
|
GIMP_PROGRESS_COMMAND_SET_VALUE,
|
|
|
|
NULL, percentage);
|
2004-08-30 02:36:30 +08:00
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-02-12 23:46:31 +08:00
|
|
|
static void
|
|
|
|
gimp_pdb_progress_progress_pulse (GimpProgress *progress)
|
|
|
|
{
|
|
|
|
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
|
|
|
|
|
|
|
|
if (pdb_progress->active)
|
|
|
|
gimp_pdb_progress_run_callback (pdb_progress,
|
|
|
|
GIMP_PROGRESS_COMMAND_PULSE,
|
|
|
|
NULL, 0.0);
|
|
|
|
}
|
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
static guint32
|
2011-02-06 19:07:55 +08:00
|
|
|
gimp_pdb_progress_progress_get_window_id (GimpProgress *progress)
|
2005-09-10 02:07:31 +08:00
|
|
|
{
|
|
|
|
GimpPdbProgress *pdb_progress = GIMP_PDB_PROGRESS (progress);
|
|
|
|
|
|
|
|
return (guint32)
|
|
|
|
gimp_pdb_progress_run_callback (pdb_progress,
|
|
|
|
GIMP_PROGRESS_COMMAND_GET_WINDOW,
|
|
|
|
NULL, 0.0);
|
|
|
|
}
|
|
|
|
|
2004-08-30 02:36:30 +08:00
|
|
|
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;
|
|
|
|
|
2010-06-07 01:15:49 +08:00
|
|
|
if (! g_strcmp0 (callback_name, progress->callback_name))
|
2006-04-12 20:49:29 +08:00
|
|
|
return progress;
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|