mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-07-03 17:33:25 +00:00
libgimp: port gimpprogress to the new plug-in API, untested
It's tested to still work when using the old API though.
This commit is contained in:
parent
026cc0f149
commit
fad59611bc
4 changed files with 221 additions and 76 deletions
|
@ -34,18 +34,23 @@ typedef struct
|
||||||
gchar *progress_callback;
|
gchar *progress_callback;
|
||||||
GimpProgressVtable vtable;
|
GimpProgressVtable vtable;
|
||||||
gpointer data;
|
gpointer data;
|
||||||
|
GDestroyNotify data_destroy;
|
||||||
} GimpProgressData;
|
} GimpProgressData;
|
||||||
|
|
||||||
|
|
||||||
/* local function prototypes */
|
/* local function prototypes */
|
||||||
|
|
||||||
static void gimp_progress_data_free (GimpProgressData *data);
|
static void gimp_progress_data_free (GimpProgressData *data);
|
||||||
|
|
||||||
static void gimp_temp_progress_run (const gchar *name,
|
static void gimp_temp_progress_run (const gchar *name,
|
||||||
gint nparams,
|
gint nparams,
|
||||||
const GimpParam *param,
|
const GimpParam *param,
|
||||||
gint *nreturn_vals,
|
gint *nreturn_vals,
|
||||||
GimpParam **return_vals);
|
GimpParam **return_vals);
|
||||||
|
static GimpValueArray *
|
||||||
|
gimp_temp_progress_run_func (GimpProcedure *procedure,
|
||||||
|
const GimpValueArray *args,
|
||||||
|
gpointer run_data);
|
||||||
|
|
||||||
|
|
||||||
/* private variables */
|
/* private variables */
|
||||||
|
@ -68,21 +73,12 @@ static const gdouble gimp_progress_step = (1.0 / 256.0);
|
||||||
**/
|
**/
|
||||||
const gchar *
|
const gchar *
|
||||||
gimp_progress_install_vtable (const GimpProgressVtable *vtable,
|
gimp_progress_install_vtable (const GimpProgressVtable *vtable,
|
||||||
gpointer user_data)
|
gpointer user_data,
|
||||||
|
GDestroyNotify user_data_destroy)
|
||||||
{
|
{
|
||||||
static const GimpParamDef args[] =
|
GimpPlugIn *plug_in;
|
||||||
{
|
gchar *progress_callback;
|
||||||
{ GIMP_PDB_INT32, "command", "" },
|
GimpProgressData *progress_data;
|
||||||
{ GIMP_PDB_STRING, "text", "" },
|
|
||||||
{ GIMP_PDB_FLOAT, "value", "" }
|
|
||||||
};
|
|
||||||
|
|
||||||
static const GimpParamDef values[] =
|
|
||||||
{
|
|
||||||
{ GIMP_PDB_FLOAT, "value", "" }
|
|
||||||
};
|
|
||||||
|
|
||||||
gchar *progress_callback;
|
|
||||||
|
|
||||||
g_return_val_if_fail (vtable != NULL, NULL);
|
g_return_val_if_fail (vtable != NULL, NULL);
|
||||||
g_return_val_if_fail (vtable->start != NULL, NULL);
|
g_return_val_if_fail (vtable->start != NULL, NULL);
|
||||||
|
@ -90,54 +86,127 @@ gimp_progress_install_vtable (const GimpProgressVtable *vtable,
|
||||||
g_return_val_if_fail (vtable->set_text != NULL, NULL);
|
g_return_val_if_fail (vtable->set_text != NULL, NULL);
|
||||||
g_return_val_if_fail (vtable->set_value != NULL, NULL);
|
g_return_val_if_fail (vtable->set_value != NULL, NULL);
|
||||||
|
|
||||||
|
plug_in = gimp_get_plug_in ();
|
||||||
|
|
||||||
progress_callback = gimp_procedural_db_temp_name ();
|
progress_callback = gimp_procedural_db_temp_name ();
|
||||||
|
|
||||||
gimp_install_temp_proc (progress_callback,
|
progress_data = g_slice_new0 (GimpProgressData);
|
||||||
"Temporary progress callback procedure",
|
|
||||||
"",
|
progress_data->progress_callback = progress_callback;
|
||||||
"",
|
progress_data->vtable.start = vtable->start;
|
||||||
"",
|
progress_data->vtable.end = vtable->end;
|
||||||
"",
|
progress_data->vtable.set_text = vtable->set_text;
|
||||||
NULL,
|
progress_data->vtable.set_value = vtable->set_value;
|
||||||
"",
|
progress_data->vtable.pulse = vtable->pulse;
|
||||||
GIMP_TEMPORARY,
|
progress_data->vtable.get_window = vtable->get_window;
|
||||||
G_N_ELEMENTS (args), G_N_ELEMENTS (values),
|
progress_data->data = user_data;
|
||||||
args, values,
|
progress_data->data_destroy = user_data_destroy;
|
||||||
gimp_temp_progress_run);
|
|
||||||
|
if (plug_in)
|
||||||
|
{
|
||||||
|
GimpProcedure *procedure = gimp_procedure_new (plug_in,
|
||||||
|
progress_callback,
|
||||||
|
GIMP_TEMPORARY,
|
||||||
|
gimp_temp_progress_run_func,
|
||||||
|
progress_data,
|
||||||
|
(GDestroyNotify)
|
||||||
|
gimp_progress_data_free);
|
||||||
|
|
||||||
|
gimp_procedure_add_argument (procedure,
|
||||||
|
g_param_spec_enum ("command",
|
||||||
|
"Command",
|
||||||
|
"The progress command",
|
||||||
|
GIMP_TYPE_PROGRESS_COMMAND,
|
||||||
|
GIMP_PROGRESS_COMMAND_START,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
|
gimp_procedure_add_argument (procedure,
|
||||||
|
g_param_spec_string ("text",
|
||||||
|
"Text",
|
||||||
|
"The progress text",
|
||||||
|
NULL,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
|
gimp_procedure_add_argument (procedure,
|
||||||
|
g_param_spec_double ("value",
|
||||||
|
"Vakue",
|
||||||
|
"The progress value",
|
||||||
|
0.0, 1.0, 0.0,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
|
|
||||||
|
gimp_procedure_add_return_value (procedure,
|
||||||
|
g_param_spec_double ("value",
|
||||||
|
"Vakue",
|
||||||
|
"The progress value",
|
||||||
|
0.0, 1.0, 0.0,
|
||||||
|
G_PARAM_READWRITE));
|
||||||
|
|
||||||
|
gimp_plug_in_add_temp_procedure (plug_in, procedure);
|
||||||
|
g_object_unref (procedure);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
static const GimpParamDef args[] =
|
||||||
|
{
|
||||||
|
{ GIMP_PDB_INT32, "command", "" },
|
||||||
|
{ GIMP_PDB_STRING, "text", "" },
|
||||||
|
{ GIMP_PDB_FLOAT, "value", "" }
|
||||||
|
};
|
||||||
|
|
||||||
|
static const GimpParamDef values[] =
|
||||||
|
{
|
||||||
|
{ GIMP_PDB_FLOAT, "value", "" }
|
||||||
|
};
|
||||||
|
|
||||||
|
gimp_install_temp_proc (progress_callback,
|
||||||
|
"Temporary progress callback procedure",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
NULL,
|
||||||
|
"",
|
||||||
|
GIMP_TEMPORARY,
|
||||||
|
G_N_ELEMENTS (args), G_N_ELEMENTS (values),
|
||||||
|
args, values,
|
||||||
|
gimp_temp_progress_run);
|
||||||
|
}
|
||||||
|
|
||||||
if (_gimp_progress_install (progress_callback))
|
if (_gimp_progress_install (progress_callback))
|
||||||
{
|
{
|
||||||
GimpProgressData *progress_data;
|
/* Allow callbacks to be watched */
|
||||||
|
if (plug_in)
|
||||||
gimp_extension_enable (); /* Allow callbacks to be watched */
|
|
||||||
|
|
||||||
/* Now add to hash table so we can find it again */
|
|
||||||
if (! gimp_progress_ht)
|
|
||||||
{
|
{
|
||||||
gimp_progress_ht =
|
gimp_plug_in_extension_enable (plug_in);
|
||||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
||||||
g_free,
|
|
||||||
(GDestroyNotify) gimp_progress_data_free);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gimp_extension_enable ();
|
||||||
|
|
||||||
progress_data = g_slice_new0 (GimpProgressData);
|
/* Now add to hash table so we can find it again */
|
||||||
|
if (! gimp_progress_ht)
|
||||||
|
{
|
||||||
|
gimp_progress_ht =
|
||||||
|
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
|
g_free,
|
||||||
|
(GDestroyNotify) gimp_progress_data_free);
|
||||||
|
}
|
||||||
|
|
||||||
progress_data->progress_callback = progress_callback;
|
g_hash_table_insert (gimp_progress_ht,
|
||||||
progress_data->vtable.start = vtable->start;
|
g_strdup (progress_callback),
|
||||||
progress_data->vtable.end = vtable->end;
|
progress_data);
|
||||||
progress_data->vtable.set_text = vtable->set_text;
|
}
|
||||||
progress_data->vtable.set_value = vtable->set_value;
|
|
||||||
progress_data->vtable.pulse = vtable->pulse;
|
|
||||||
progress_data->vtable.get_window = vtable->get_window;
|
|
||||||
progress_data->data = user_data;
|
|
||||||
|
|
||||||
g_hash_table_insert (gimp_progress_ht, progress_callback, progress_data);
|
|
||||||
|
|
||||||
return progress_callback;
|
return progress_callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
gimp_uninstall_temp_proc (progress_callback);
|
if (plug_in)
|
||||||
g_free (progress_callback);
|
{
|
||||||
|
gimp_plug_in_remove_temp_procedure (plug_in, progress_callback);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gimp_uninstall_temp_proc (progress_callback);
|
||||||
|
gimp_progress_data_free (progress_data);
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -149,35 +218,37 @@ gimp_progress_install_vtable (const GimpProgressVtable *vtable,
|
||||||
* Uninstalls a temporary progress procedure that was installed using
|
* Uninstalls a temporary progress procedure that was installed using
|
||||||
* gimp_progress_install().
|
* gimp_progress_install().
|
||||||
*
|
*
|
||||||
* Returns: the @user_data that was passed to gimp_progress_install().
|
|
||||||
*
|
|
||||||
* Since: 2.2
|
* Since: 2.2
|
||||||
**/
|
**/
|
||||||
gpointer
|
void
|
||||||
gimp_progress_uninstall (const gchar *progress_callback)
|
gimp_progress_uninstall (const gchar *progress_callback)
|
||||||
{
|
{
|
||||||
GimpProgressData *progress_data;
|
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
||||||
gpointer user_data;
|
|
||||||
|
|
||||||
g_return_val_if_fail (progress_callback != NULL, NULL);
|
g_return_if_fail (progress_callback != NULL);
|
||||||
g_return_val_if_fail (gimp_progress_ht != NULL, NULL);
|
|
||||||
|
|
||||||
progress_data = g_hash_table_lookup (gimp_progress_ht, progress_callback);
|
if (plug_in)
|
||||||
|
|
||||||
if (! progress_data)
|
|
||||||
{
|
{
|
||||||
g_warning ("Can't find internal progress data");
|
gimp_plug_in_remove_temp_procedure (plug_in, progress_callback);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GimpProgressData *progress_data;
|
||||||
|
|
||||||
_gimp_progress_uninstall (progress_callback);
|
g_return_if_fail (gimp_progress_ht != NULL);
|
||||||
gimp_uninstall_temp_proc (progress_callback);
|
|
||||||
|
|
||||||
user_data = progress_data->data;
|
progress_data = g_hash_table_lookup (gimp_progress_ht, progress_callback);
|
||||||
|
|
||||||
g_hash_table_remove (gimp_progress_ht, progress_callback);
|
if (! progress_data)
|
||||||
|
{
|
||||||
|
g_warning ("Can't find internal progress data");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return user_data;
|
gimp_uninstall_temp_proc (progress_callback);
|
||||||
|
|
||||||
|
g_hash_table_remove (gimp_progress_ht, progress_callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -332,6 +403,13 @@ gimp_progress_update (gdouble percentage)
|
||||||
static void
|
static void
|
||||||
gimp_progress_data_free (GimpProgressData *data)
|
gimp_progress_data_free (GimpProgressData *data)
|
||||||
{
|
{
|
||||||
|
_gimp_progress_uninstall (data->progress_callback);
|
||||||
|
|
||||||
|
g_free (data->progress_callback);
|
||||||
|
|
||||||
|
if (data->data_destroy)
|
||||||
|
data->data_destroy (data->data);
|
||||||
|
|
||||||
g_slice_free (GimpProgressData, data);
|
g_slice_free (GimpProgressData, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,3 +487,69 @@ gimp_temp_progress_run (const gchar *name,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static GimpValueArray *
|
||||||
|
gimp_temp_progress_run_func (GimpProcedure *procedure,
|
||||||
|
const GimpValueArray *args,
|
||||||
|
gpointer run_data)
|
||||||
|
{
|
||||||
|
GimpProgressData *progress_data = run_data;
|
||||||
|
GimpProgressCommand command;
|
||||||
|
const gchar *text;
|
||||||
|
gdouble value;
|
||||||
|
|
||||||
|
command = g_value_get_enum (gimp_value_array_index (args, 0));
|
||||||
|
text = g_value_get_string (gimp_value_array_index (args, 1));
|
||||||
|
value = g_value_get_double (gimp_value_array_index (args, 2));
|
||||||
|
|
||||||
|
switch (command)
|
||||||
|
{
|
||||||
|
case GIMP_PROGRESS_COMMAND_START:
|
||||||
|
progress_data->vtable.start (text, value != 0.0,
|
||||||
|
progress_data->data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GIMP_PROGRESS_COMMAND_END:
|
||||||
|
progress_data->vtable.end (progress_data->data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GIMP_PROGRESS_COMMAND_SET_TEXT:
|
||||||
|
progress_data->vtable.set_text (text, progress_data->data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GIMP_PROGRESS_COMMAND_SET_VALUE:
|
||||||
|
progress_data->vtable.set_value (value, progress_data->data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GIMP_PROGRESS_COMMAND_PULSE:
|
||||||
|
if (progress_data->vtable.pulse)
|
||||||
|
progress_data->vtable.pulse (progress_data->data);
|
||||||
|
else
|
||||||
|
progress_data->vtable.set_value (-1, progress_data->data);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GIMP_PROGRESS_COMMAND_GET_WINDOW:
|
||||||
|
{
|
||||||
|
GimpValueArray *return_vals;
|
||||||
|
guint32 window_id = 0;
|
||||||
|
|
||||||
|
if (progress_data->vtable.get_window)
|
||||||
|
window_id = progress_data->vtable.get_window (progress_data->data);
|
||||||
|
|
||||||
|
return_vals = gimp_procedure_new_return_values (procedure,
|
||||||
|
GIMP_PDB_SUCCESS,
|
||||||
|
NULL);
|
||||||
|
g_value_set_double (gimp_value_array_index (return_vals, 1), window_id);
|
||||||
|
|
||||||
|
return return_vals;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return gimp_procedure_new_return_values (procedure,
|
||||||
|
GIMP_PDB_CALLING_ERROR,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
||||||
|
}
|
||||||
|
|
|
@ -57,8 +57,9 @@ struct _GimpProgressVtable
|
||||||
|
|
||||||
|
|
||||||
const gchar * gimp_progress_install_vtable (const GimpProgressVtable *vtable,
|
const gchar * gimp_progress_install_vtable (const GimpProgressVtable *vtable,
|
||||||
gpointer user_data);
|
gpointer user_data,
|
||||||
gpointer gimp_progress_uninstall (const gchar *progress_callback);
|
GDestroyNotify user_data_destroy);
|
||||||
|
void gimp_progress_uninstall (const gchar *progress_callback);
|
||||||
|
|
||||||
gboolean gimp_progress_init (const gchar *message);
|
gboolean gimp_progress_init (const gchar *message);
|
||||||
gboolean gimp_progress_init_printf (const gchar *format,
|
gboolean gimp_progress_init_printf (const gchar *format,
|
||||||
|
|
|
@ -90,7 +90,7 @@ gimp_progress_bar_init (GimpProgressBar *bar)
|
||||||
vtable.pulse = gimp_progress_bar_pulse;
|
vtable.pulse = gimp_progress_bar_pulse;
|
||||||
vtable.get_window = gimp_progress_bar_get_window;
|
vtable.get_window = gimp_progress_bar_get_window;
|
||||||
|
|
||||||
bar->progress_callback = gimp_progress_install_vtable (&vtable, bar);
|
bar->progress_callback = gimp_progress_install_vtable (&vtable, bar, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -447,7 +447,7 @@ server_progress_install (void)
|
||||||
vtable.set_text = server_progress_set_text;
|
vtable.set_text = server_progress_set_text;
|
||||||
vtable.set_value = server_progress_set_value;
|
vtable.set_value = server_progress_set_value;
|
||||||
|
|
||||||
return gimp_progress_install_vtable (&vtable, NULL);
|
return gimp_progress_install_vtable (&vtable, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue