Skip to content

Commit 9e2a7e8

Browse files
author
Jehan
committed
libgimp, plug-ins: rename gimp_load_procedure_new2() as gimp_load_procedure_new().
All C load procedures are now moved to the new API.
1 parent 136aca3 commit 9e2a7e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+256
-334
lines changed

libgimp/gimp.def

-1
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ EXPORTS
619619
gimp_load_procedure_get_thumbnail_loader
620620
gimp_load_procedure_get_type
621621
gimp_load_procedure_new
622-
gimp_load_procedure_new2
623622
gimp_load_procedure_set_handles_raw
624623
gimp_load_procedure_set_thumbnail_loader
625624
gimp_main

libgimp/gimploadprocedure.c

+80-140
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
struct _GimpLoadProcedurePrivate
5656
{
5757
GimpRunLoadFunc run_func;
58-
GimpRunLoadFunc2 run_func2;
5958
gpointer run_data;
6059
GDestroyNotify run_data_destroy;
6160

@@ -177,12 +176,18 @@ static GimpValueArray *
177176
gimp_load_procedure_run (GimpProcedure *procedure,
178177
const GimpValueArray *args)
179178
{
180-
GimpLoadProcedure *load_proc = GIMP_LOAD_PROCEDURE (procedure);
181-
GimpValueArray *remaining;
182-
GimpValueArray *return_values;
183-
GimpRunMode run_mode;
184-
GFile *file;
185-
gint i;
179+
GimpLoadProcedure *load_proc = GIMP_LOAD_PROCEDURE (procedure);
180+
GimpValueArray *remaining;
181+
GimpValueArray *return_values;
182+
GimpProcedureConfig *config;
183+
GimpImage *image = NULL;
184+
GimpMetadata *metadata = NULL;
185+
gchar *mimetype = NULL;
186+
GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
187+
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
188+
GimpRunMode run_mode;
189+
GFile *file;
190+
gint i;
186191

187192
run_mode = GIMP_VALUES_GET_ENUM (args, 0);
188193
file = GIMP_VALUES_GET_FILE (args, 1);
@@ -196,103 +201,85 @@ gimp_load_procedure_run (GimpProcedure *procedure,
196201
gimp_value_array_append (remaining, value);
197202
}
198203

199-
if (load_proc->priv->run_func2)
200-
{
201-
GimpProcedureConfig *config;
202-
GimpImage *image = NULL;
203-
GimpMetadata *metadata = NULL;
204-
gchar *mimetype = NULL;
205-
GimpMetadataLoadFlags flags = GIMP_METADATA_LOAD_ALL;
206-
GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR;
207-
208-
config = gimp_procedure_create_config (procedure);
209-
mimetype = (gchar *) gimp_file_procedure_get_mime_types (GIMP_FILE_PROCEDURE (procedure));
204+
config = gimp_procedure_create_config (procedure);
205+
mimetype = (gchar *) gimp_file_procedure_get_mime_types (GIMP_FILE_PROCEDURE (procedure));
210206

211-
if (mimetype != NULL)
212-
{
213-
char *delim;
214-
215-
mimetype = g_strdup (mimetype);
216-
mimetype = g_strstrip (mimetype);
217-
delim = strstr (mimetype, ",");
218-
if (delim)
219-
*delim = '\0';
220-
/* Though docs only writes about the list being comma-separated, our
221-
* code apparently also split by spaces.
222-
*/
223-
delim = strstr (mimetype, " ");
224-
if (delim)
225-
*delim = '\0';
226-
delim = strstr (mimetype, "\t");
227-
if (delim)
228-
*delim = '\0';
229-
230-
metadata = gimp_metadata_load_from_file (file, NULL);
231-
g_free (mimetype);
232-
}
233-
else
234-
{
235-
flags = GIMP_METADATA_LOAD_NONE;
236-
}
207+
if (mimetype != NULL)
208+
{
209+
char *delim;
210+
211+
mimetype = g_strdup (mimetype);
212+
mimetype = g_strstrip (mimetype);
213+
delim = strstr (mimetype, ",");
214+
if (delim)
215+
*delim = '\0';
216+
/* Though docs only writes about the list being comma-separated, our
217+
* code apparently also split by spaces.
218+
*/
219+
delim = strstr (mimetype, " ");
220+
if (delim)
221+
*delim = '\0';
222+
delim = strstr (mimetype, "\t");
223+
if (delim)
224+
*delim = '\0';
225+
226+
metadata = gimp_metadata_load_from_file (file, NULL);
227+
g_free (mimetype);
228+
}
229+
else
230+
{
231+
flags = GIMP_METADATA_LOAD_NONE;
232+
}
237233

238-
if (metadata == NULL)
239-
metadata = gimp_metadata_new ();
234+
if (metadata == NULL)
235+
metadata = gimp_metadata_new ();
240236

241-
return_values = load_proc->priv->run_func2 (procedure,
242-
run_mode,
243-
file,
244-
metadata, &flags,
245-
config,
246-
load_proc->priv->run_data);
237+
return_values = load_proc->priv->run_func (procedure,
238+
run_mode,
239+
file,
240+
metadata, &flags,
241+
config,
242+
load_proc->priv->run_data);
247243

248-
if (return_values != NULL &&
249-
gimp_value_array_length (return_values) > 0 &&
250-
G_VALUE_HOLDS_ENUM (gimp_value_array_index (return_values, 0)))
251-
status = GIMP_VALUES_GET_ENUM (return_values, 0);
244+
if (return_values != NULL &&
245+
gimp_value_array_length (return_values) > 0 &&
246+
G_VALUE_HOLDS_ENUM (gimp_value_array_index (return_values, 0)))
247+
status = GIMP_VALUES_GET_ENUM (return_values, 0);
252248

253-
gimp_procedure_config_end_run (config, status);
249+
gimp_procedure_config_end_run (config, status);
254250

255-
if (status == GIMP_PDB_SUCCESS)
251+
if (status == GIMP_PDB_SUCCESS)
252+
{
253+
if (gimp_value_array_length (return_values) < 2 ||
254+
! GIMP_VALUE_HOLDS_IMAGE (gimp_value_array_index (return_values, 1)))
256255
{
257-
if (gimp_value_array_length (return_values) < 2 ||
258-
! GIMP_VALUE_HOLDS_IMAGE (gimp_value_array_index (return_values, 1)))
259-
{
260-
GError *error = NULL;
261-
262-
status = GIMP_PDB_EXECUTION_ERROR;
263-
g_set_error (&error, GIMP_PLUG_IN_ERROR, 0,
264-
_("This file loading plug-in returned SUCCESS as a status without an image. "
265-
"This is a bug in the plug-in code. Contact the plug-in developer."));
266-
gimp_value_array_unref (return_values);
267-
return_values = gimp_procedure_new_return_values (procedure, status, error);
268-
}
269-
else
270-
{
271-
image = GIMP_VALUES_GET_IMAGE (return_values, 1);
272-
}
256+
GError *error = NULL;
257+
258+
status = GIMP_PDB_EXECUTION_ERROR;
259+
g_set_error (&error, GIMP_PLUG_IN_ERROR, 0,
260+
_("This file loading plug-in returned SUCCESS as a status without an image. "
261+
"This is a bug in the plug-in code. Contact the plug-in developer."));
262+
gimp_value_array_unref (return_values);
263+
return_values = gimp_procedure_new_return_values (procedure, status, error);
273264
}
265+
else
266+
{
267+
image = GIMP_VALUES_GET_IMAGE (return_values, 1);
268+
}
269+
}
274270

275-
if (image != NULL && metadata != NULL && flags != GIMP_METADATA_LOAD_NONE)
276-
gimp_image_metadata_load_finish (image, NULL, metadata, flags);
277-
278-
/* This is debug printing to help plug-in developers figure out best
279-
* practices.
280-
*/
281-
if (G_OBJECT (config)->ref_count > 1)
282-
g_printerr ("%s: ERROR: the GimpSaveProcedureConfig object was refed "
283-
"by plug-in, it MUST NOT do that!\n", G_STRFUNC);
271+
if (image != NULL && metadata != NULL && flags != GIMP_METADATA_LOAD_NONE)
272+
gimp_image_metadata_load_finish (image, NULL, metadata, flags);
284273

285-
g_object_unref (config);
286-
}
287-
else
288-
{
289-
return_values = load_proc->priv->run_func (procedure,
290-
run_mode,
291-
file,
292-
remaining,
293-
load_proc->priv->run_data);
294-
}
274+
/* This is debug printing to help plug-in developers figure out best
275+
* practices.
276+
*/
277+
if (G_OBJECT (config)->ref_count > 1)
278+
g_printerr ("%s: ERROR: the GimpSaveProcedureConfig object was refed "
279+
"by plug-in, it MUST NOT do that!\n", G_STRFUNC);
295280

281+
g_object_unref (config);
282+
g_clear_object (&metadata);
296283
gimp_value_array_unref (remaining);
297284

298285
return return_values;
@@ -369,53 +356,6 @@ gimp_load_procedure_new (GimpPlugIn *plug_in,
369356
return GIMP_PROCEDURE (procedure);
370357
}
371358

372-
/**
373-
* gimp_load_procedure_new2:
374-
* @plug_in: a #GimpPlugIn.
375-
* @name: the new procedure's name.
376-
* @proc_type: the new procedure's #GimpPDBProcType.
377-
* @run_func: the run function for the new procedure.
378-
* @run_data: user data passed to @run_func.
379-
* @run_data_destroy: (nullable): free function for @run_data, or %NULL.
380-
*
381-
* Creates a new load procedure named @name which will call @run_func
382-
* when invoked.
383-
*
384-
* See gimp_procedure_new() for information about @proc_type.
385-
*
386-
* Returns: (transfer full): a new #GimpProcedure.
387-
*
388-
* Since: 3.0
389-
**/
390-
GimpProcedure *
391-
gimp_load_procedure_new2 (GimpPlugIn *plug_in,
392-
const gchar *name,
393-
GimpPDBProcType proc_type,
394-
GimpRunLoadFunc2 run_func,
395-
gpointer run_data,
396-
GDestroyNotify run_data_destroy)
397-
{
398-
GimpLoadProcedure *procedure;
399-
400-
g_return_val_if_fail (GIMP_IS_PLUG_IN (plug_in), NULL);
401-
g_return_val_if_fail (gimp_is_canonical_identifier (name), NULL);
402-
g_return_val_if_fail (proc_type != GIMP_PDB_PROC_TYPE_INTERNAL, NULL);
403-
g_return_val_if_fail (proc_type != GIMP_PDB_PROC_TYPE_EXTENSION, NULL);
404-
g_return_val_if_fail (run_func != NULL, NULL);
405-
406-
procedure = g_object_new (GIMP_TYPE_LOAD_PROCEDURE,
407-
"plug-in", plug_in,
408-
"name", name,
409-
"procedure-type", proc_type,
410-
NULL);
411-
412-
procedure->priv->run_func2 = run_func;
413-
procedure->priv->run_data = run_data;
414-
procedure->priv->run_data_destroy = run_data_destroy;
415-
416-
return GIMP_PROCEDURE (procedure);
417-
}
418-
419359
/**
420360
* gimp_load_procedure_set_handles_raw:
421361
* @procedure: A load procedure object.

libgimp/gimploadprocedure.h

+22-39
Original file line numberDiff line numberDiff line change
@@ -31,47 +31,36 @@ G_BEGIN_DECLS
3131

3232
/**
3333
* GimpRunLoadFunc:
34-
* @procedure: the #GimpProcedure that runs.
35-
* @run_mode: the #GimpRunMode.
36-
* @file: the #GFile to load from.
37-
* @args: the @procedure's remaining arguments.
38-
* @run_data: (closure): the run_data given in gimp_load_procedure_new().
39-
*
40-
* The load function is run during the lifetime of the GIMP session,
41-
* each time a plug-in load procedure is called.
42-
*
43-
* Returns: (transfer full): the @procedure's return values.
44-
*
45-
* Since: 3.0
46-
**/
47-
typedef GimpValueArray * (* GimpRunLoadFunc) (GimpProcedure *procedure,
48-
GimpRunMode run_mode,
49-
GFile *file,
50-
const GimpValueArray *args,
51-
gpointer run_data);
52-
53-
/**
54-
* GimpRunLoadFunc2:
55-
* @procedure: the #GimpProcedure that runs.
56-
* @run_mode: the #GimpRunMode.
57-
* @file: the #GFile to load from.
34+
* @procedure: the [[email protected]] that runs.
35+
* @run_mode: the [enum@RunMode].
36+
* @file: the [[email protected]] to load from.
37+
* @metadata: the [[email protected]] which will be added to the new image.
38+
* @flags: (inout): flags to filter which metadata will be added..
5839
* @config: the @procedure's remaining arguments.
5940
* @run_data: (closure): the run_data given in gimp_load_procedure_new().
6041
*
61-
* The load function is run during the lifetime of the GIMP session,
62-
* each time a plug-in load procedure is called.
42+
* The load function is run during the lifetime of the GIMP session, each time a
43+
* plug-in load procedure is called.
44+
*
45+
* You are expected to read @file and create a [[email protected]] out of its
46+
* data. This image will be the first return value.
47+
* @metadata will be filled from metadata from @file if our infrastructure
48+
* supports this format. You may tweak this object, for instance adding metadata
49+
* specific to the format. You can also edit @flags if you need to filter out
50+
* some specific common fields. For instance, it is customary to remove a
51+
* colorspace field with [flags@MetadataLoadFlags] when a profile was added.
6352
*
6453
* Returns: (transfer full): the @procedure's return values.
6554
*
6655
* Since: 3.0
6756
**/
68-
typedef GimpValueArray * (* GimpRunLoadFunc2) (GimpProcedure *procedure,
69-
GimpRunMode run_mode,
70-
GFile *file,
71-
GimpMetadata *metadata,
72-
GimpMetadataLoadFlags *flags,
73-
GimpProcedureConfig *config,
74-
gpointer run_data);
57+
typedef GimpValueArray * (* GimpRunLoadFunc) (GimpProcedure *procedure,
58+
GimpRunMode run_mode,
59+
GFile *file,
60+
GimpMetadata *metadata,
61+
GimpMetadataLoadFlags *flags,
62+
GimpProcedureConfig *config,
63+
gpointer run_data);
7564

7665

7766
#define GIMP_TYPE_LOAD_PROCEDURE (gimp_load_procedure_get_type ())
@@ -107,12 +96,6 @@ GimpProcedure * gimp_load_procedure_new (GimpPlugIn *plu
10796
GimpRunLoadFunc run_func,
10897
gpointer run_data,
10998
GDestroyNotify run_data_destroy);
110-
GimpProcedure * gimp_load_procedure_new2 (GimpPlugIn *plug_in,
111-
const gchar *name,
112-
GimpPDBProcType proc_type,
113-
GimpRunLoadFunc2 run_func,
114-
gpointer run_data,
115-
GDestroyNotify run_data_destroy);
11699

117100
void gimp_load_procedure_set_handles_raw (GimpLoadProcedure *procedure,
118101
gboolean handles_raw);

plug-ins/common/file-cel.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ cel_create_procedure (GimpPlugIn *plug_in,
134134

135135
if (! strcmp (name, LOAD_PROC))
136136
{
137-
procedure = gimp_load_procedure_new2 (plug_in, name,
138-
GIMP_PDB_PROC_TYPE_PLUGIN,
139-
cel_load, NULL, NULL);
137+
procedure = gimp_load_procedure_new (plug_in, name,
138+
GIMP_PDB_PROC_TYPE_PLUGIN,
139+
cel_load, NULL, NULL);
140140

141141
gimp_procedure_set_menu_label (procedure, _("KISS CEL"));
142142

plug-ins/common/file-compressor.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ compressor_create_procedure (GimpPlugIn *plug_in,
316316

317317
if (! strcmp (name, compressor->load_proc))
318318
{
319-
procedure = gimp_load_procedure_new2 (plug_in, name,
320-
GIMP_PDB_PROC_TYPE_PLUGIN,
321-
compressor_load,
322-
(gpointer) compressor, NULL);
319+
procedure = gimp_load_procedure_new (plug_in, name,
320+
GIMP_PDB_PROC_TYPE_PLUGIN,
321+
compressor_load,
322+
(gpointer) compressor, NULL);
323323

324324
gimp_procedure_set_documentation (procedure,
325325
compressor->load_blurb,

plug-ins/common/file-desktop-link.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ desktop_create_procedure (GimpPlugIn *plug_in,
107107

108108
if (! strcmp (name, LOAD_PROC))
109109
{
110-
procedure = gimp_load_procedure_new2 (plug_in, name,
111-
GIMP_PDB_PROC_TYPE_PLUGIN,
112-
desktop_load, NULL, NULL);
110+
procedure = gimp_load_procedure_new (plug_in, name,
111+
GIMP_PDB_PROC_TYPE_PLUGIN,
112+
desktop_load, NULL, NULL);
113113

114114
gimp_procedure_set_menu_label (procedure, _("Desktop Link"));
115115

0 commit comments

Comments
 (0)