1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
1 |
/* GIMP - The GNU Image Manipulation Program
|
2 |
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
3 |
*
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
6 |
* the Free Software Foundation; either version 2 of the License, or
|
|
7 |
* (at your option) any later version.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
17 |
*/
|
|
18 |
||
19 |
#include "config.h" |
|
20 |
||
21 |
#include <stdarg.h> |
|
22 |
#include <sys/types.h> |
|
23 |
||
24 |
#include <glib-object.h> |
|
25 |
||
26 |
#include "libgimpbase/gimpbase.h" |
|
27 |
#include "libgimpcolor/gimpcolor.h" |
|
28 |
||
29 |
#include "pdb-types.h" |
|
30 |
||
31 |
#include "core/gimp.h" |
|
32 |
#include "core/gimp-utils.h" |
|
33 |
#include "core/gimpcontext.h" |
|
34 |
#include "core/gimpchannel.h" |
|
35 |
#include "core/gimplayer.h" |
|
36 |
#include "core/gimpparamspecs.h" |
|
37 |
#include "core/gimpprogress.h" |
|
38 |
||
39 |
#include "vectors/gimpvectors.h" |
|
40 |
||
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
41 |
#include "gimppdberror.h" |
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
42 |
#include "gimpprocedure.h" |
43 |
||
44 |
#include "gimp-intl.h" |
|
45 |
||
46 |
||
47 |
static void gimp_procedure_finalize (GObject *object); |
|
48 |
||
49 |
static gint64 gimp_procedure_get_memsize (GimpObject *object, |
|
50 |
gint64 *gui_size); |
|
51 |
||
52 |
static GValueArray * gimp_procedure_real_execute (GimpProcedure *procedure, |
|
53 |
Gimp *gimp, |
|
54 |
GimpContext *context, |
|
55 |
GimpProgress *progress, |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
56 |
GValueArray *args, |
57 |
GError **error); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
58 |
static void gimp_procedure_real_execute_async (GimpProcedure *procedure, |
59 |
Gimp *gimp, |
|
60 |
GimpContext *context, |
|
61 |
GimpProgress *progress, |
|
62 |
GValueArray *args, |
|
63 |
GimpObject *display); |
|
64 |
||
65 |
static void gimp_procedure_free_strings (GimpProcedure *procedure); |
|
66 |
static gboolean gimp_procedure_validate_args (GimpProcedure *procedure, |
|
67 |
GParamSpec **param_specs, |
|
68 |
gint n_param_specs, |
|
69 |
GValueArray *args, |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
70 |
gboolean return_vals, |
71 |
GError **error); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
72 |
|
73 |
||
74 |
G_DEFINE_TYPE (GimpProcedure, gimp_procedure, GIMP_TYPE_OBJECT) |
|
75 |
||
76 |
#define parent_class gimp_procedure_parent_class
|
|
77 |
||
78 |
||
79 |
static void |
|
80 |
gimp_procedure_class_init (GimpProcedureClass *klass) |
|
81 |
{
|
|
82 |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
|
83 |
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass); |
|
84 |
||
85 |
object_class->finalize = gimp_procedure_finalize; |
|
86 |
||
87 |
gimp_object_class->get_memsize = gimp_procedure_get_memsize; |
|
88 |
||
89 |
klass->execute = gimp_procedure_real_execute; |
|
90 |
klass->execute_async = gimp_procedure_real_execute_async; |
|
91 |
}
|
|
92 |
||
93 |
static void |
|
94 |
gimp_procedure_init (GimpProcedure *procedure) |
|
95 |
{
|
|
96 |
procedure->proc_type = GIMP_INTERNAL; |
|
97 |
}
|
|
98 |
||
99 |
static void |
|
100 |
gimp_procedure_finalize (GObject *object) |
|
101 |
{
|
|
102 |
GimpProcedure *procedure = GIMP_PROCEDURE (object); |
|
103 |
gint i; |
|
104 |
||
105 |
gimp_procedure_free_strings (procedure); |
|
106 |
||
107 |
if (procedure->args) |
|
108 |
{
|
|
109 |
for (i = 0; i < procedure->num_args; i++) |
|
110 |
g_param_spec_unref (procedure->args[i]); |
|
111 |
||
112 |
g_free (procedure->args); |
|
113 |
procedure->args = NULL; |
|
114 |
}
|
|
115 |
||
116 |
if (procedure->values) |
|
117 |
{
|
|
118 |
for (i = 0; i < procedure->num_values; i++) |
|
119 |
g_param_spec_unref (procedure->values[i]); |
|
120 |
||
121 |
g_free (procedure->values); |
|
122 |
procedure->values = NULL; |
|
123 |
}
|
|
124 |
||
125 |
G_OBJECT_CLASS (parent_class)->finalize (object); |
|
126 |
}
|
|
127 |
||
128 |
static gint64 |
|
129 |
gimp_procedure_get_memsize (GimpObject *object, |
|
130 |
gint64 *gui_size) |
|
131 |
{
|
|
132 |
GimpProcedure *procedure = GIMP_PROCEDURE (object); |
|
133 |
gint64 memsize = 0; |
|
134 |
gint i; |
|
135 |
||
136 |
if (! procedure->static_strings) |
|
137 |
{
|
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
138 |
memsize += gimp_string_get_memsize (procedure->original_name); |
139 |
memsize += gimp_string_get_memsize (procedure->blurb); |
|
140 |
memsize += gimp_string_get_memsize (procedure->help); |
|
141 |
memsize += gimp_string_get_memsize (procedure->author); |
|
142 |
memsize += gimp_string_get_memsize (procedure->copyright); |
|
143 |
memsize += gimp_string_get_memsize (procedure->date); |
|
144 |
memsize += gimp_string_get_memsize (procedure->deprecated); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
145 |
}
|
146 |
||
147 |
memsize += procedure->num_args * sizeof (GParamSpec *); |
|
148 |
||
149 |
for (i = 0; i < procedure->num_args; i++) |
|
150 |
memsize += gimp_g_param_spec_get_memsize (procedure->args[i]); |
|
151 |
||
152 |
memsize += procedure->num_values * sizeof (GParamSpec *); |
|
153 |
||
154 |
for (i = 0; i < procedure->num_values; i++) |
|
155 |
memsize += gimp_g_param_spec_get_memsize (procedure->values[i]); |
|
156 |
||
157 |
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object, |
|
158 |
gui_size); |
|
159 |
}
|
|
160 |
||
161 |
static GValueArray * |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
162 |
gimp_procedure_real_execute (GimpProcedure *procedure, |
163 |
Gimp *gimp, |
|
164 |
GimpContext *context, |
|
165 |
GimpProgress *progress, |
|
166 |
GValueArray *args, |
|
167 |
GError **error) |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
168 |
{
|
169 |
g_return_val_if_fail (args->n_values >= procedure->num_args, NULL); |
|
170 |
||
171 |
return procedure->marshal_func (procedure, gimp, |
|
172 |
context, progress, |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
173 |
args, error); |
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
174 |
}
|
175 |
||
176 |
static void |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
177 |
gimp_procedure_real_execute_async (GimpProcedure *procedure, |
178 |
Gimp *gimp, |
|
179 |
GimpContext *context, |
|
180 |
GimpProgress *progress, |
|
181 |
GValueArray *args, |
|
182 |
GimpObject *display) |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
183 |
{
|
184 |
GValueArray *return_vals; |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
185 |
GError *error = NULL; |
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
186 |
|
187 |
g_return_if_fail (args->n_values >= procedure->num_args); |
|
188 |
||
189 |
return_vals = GIMP_PROCEDURE_GET_CLASS (procedure)->execute (procedure, |
|
190 |
gimp, |
|
191 |
context, |
|
192 |
progress, |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
193 |
args, |
194 |
&error); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
195 |
|
196 |
g_value_array_free (return_vals); |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
197 |
|
198 |
if (error) |
|
199 |
{
|
|
200 |
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR, |
|
201 |
"%s", error->message); |
|
202 |
g_error_free (error); |
|
203 |
}
|
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
204 |
}
|
205 |
||
206 |
||
207 |
/* public functions */
|
|
208 |
||
209 |
GimpProcedure * |
|
210 |
gimp_procedure_new (GimpMarshalFunc marshal_func) |
|
211 |
{
|
|
212 |
GimpProcedure *procedure; |
|
213 |
||
214 |
g_return_val_if_fail (marshal_func != NULL, NULL); |
|
215 |
||
216 |
procedure = g_object_new (GIMP_TYPE_PROCEDURE, NULL); |
|
217 |
||
218 |
procedure->marshal_func = marshal_func; |
|
219 |
||
220 |
return procedure; |
|
221 |
}
|
|
222 |
||
223 |
void
|
|
224 |
gimp_procedure_set_strings (GimpProcedure *procedure, |
|
1.1.6
by Steve Kowalik
Import upstream version 2.4.0~rc2 |
225 |
const gchar *original_name, |
226 |
const gchar *blurb, |
|
227 |
const gchar *help, |
|
228 |
const gchar *author, |
|
229 |
const gchar *copyright, |
|
230 |
const gchar *date, |
|
231 |
const gchar *deprecated) |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
232 |
{
|
233 |
g_return_if_fail (GIMP_IS_PROCEDURE (procedure)); |
|
234 |
||
235 |
gimp_procedure_free_strings (procedure); |
|
236 |
||
237 |
procedure->original_name = g_strdup (original_name); |
|
238 |
procedure->blurb = g_strdup (blurb); |
|
239 |
procedure->help = g_strdup (help); |
|
240 |
procedure->author = g_strdup (author); |
|
241 |
procedure->copyright = g_strdup (copyright); |
|
242 |
procedure->date = g_strdup (date); |
|
243 |
procedure->deprecated = g_strdup (deprecated); |
|
244 |
||
245 |
procedure->static_strings = FALSE; |
|
246 |
}
|
|
247 |
||
248 |
void
|
|
249 |
gimp_procedure_set_static_strings (GimpProcedure *procedure, |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
250 |
const gchar *original_name, |
251 |
const gchar *blurb, |
|
252 |
const gchar *help, |
|
253 |
const gchar *author, |
|
254 |
const gchar *copyright, |
|
255 |
const gchar *date, |
|
256 |
const gchar *deprecated) |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
257 |
{
|
258 |
g_return_if_fail (GIMP_IS_PROCEDURE (procedure)); |
|
259 |
||
260 |
gimp_procedure_free_strings (procedure); |
|
261 |
||
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
262 |
procedure->original_name = (gchar *) original_name; |
263 |
procedure->blurb = (gchar *) blurb; |
|
264 |
procedure->help = (gchar *) help; |
|
265 |
procedure->author = (gchar *) author; |
|
266 |
procedure->copyright = (gchar *) copyright; |
|
267 |
procedure->date = (gchar *) date; |
|
268 |
procedure->deprecated = (gchar *) deprecated; |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
269 |
|
270 |
procedure->static_strings = TRUE; |
|
271 |
}
|
|
272 |
||
273 |
void
|
|
274 |
gimp_procedure_take_strings (GimpProcedure *procedure, |
|
275 |
gchar *original_name, |
|
276 |
gchar *blurb, |
|
277 |
gchar *help, |
|
278 |
gchar *author, |
|
279 |
gchar *copyright, |
|
280 |
gchar *date, |
|
281 |
gchar *deprecated) |
|
282 |
{
|
|
283 |
g_return_if_fail (GIMP_IS_PROCEDURE (procedure)); |
|
284 |
||
285 |
gimp_procedure_free_strings (procedure); |
|
286 |
||
287 |
procedure->original_name = original_name; |
|
288 |
procedure->blurb = blurb; |
|
289 |
procedure->help = help; |
|
290 |
procedure->author = author; |
|
291 |
procedure->copyright = copyright; |
|
292 |
procedure->date = date; |
|
293 |
procedure->deprecated = deprecated; |
|
294 |
||
295 |
procedure->static_strings = FALSE; |
|
296 |
}
|
|
297 |
||
298 |
GValueArray * |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
299 |
gimp_procedure_execute (GimpProcedure *procedure, |
300 |
Gimp *gimp, |
|
301 |
GimpContext *context, |
|
302 |
GimpProgress *progress, |
|
303 |
GValueArray *args, |
|
304 |
GError **error) |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
305 |
{
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
306 |
GValueArray *return_vals; |
307 |
GError *pdb_error = NULL; |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
308 |
|
309 |
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL); |
|
310 |
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL); |
|
311 |
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL); |
|
312 |
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL); |
|
313 |
g_return_val_if_fail (args != NULL, NULL); |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
314 |
g_return_val_if_fail (error == NULL || *error == NULL, NULL); |
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
315 |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
316 |
if (! gimp_procedure_validate_args (procedure, |
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
317 |
procedure->args, procedure->num_args, |
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
318 |
args, FALSE, &pdb_error)) |
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
319 |
{
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
320 |
return_vals = gimp_procedure_get_return_values (procedure, FALSE, |
321 |
pdb_error); |
|
322 |
g_propagate_error (error, pdb_error); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
323 |
|
324 |
return return_vals; |
|
325 |
}
|
|
326 |
||
327 |
/* call the procedure */
|
|
328 |
return_vals = GIMP_PROCEDURE_GET_CLASS (procedure)->execute (procedure, |
|
329 |
gimp, |
|
330 |
context, |
|
331 |
progress, |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
332 |
args, |
333 |
error); |
|
334 |
||
335 |
||
336 |
if (return_vals) |
|
337 |
{
|
|
338 |
if (g_value_get_enum (&return_vals->values[0]) != GIMP_PDB_SUCCESS) |
|
339 |
{
|
|
340 |
/* If the error has not already been set, construct one
|
|
341 |
* from the error message that is optionally passed with
|
|
342 |
* the return values.
|
|
343 |
*/
|
|
344 |
if (error && *error == NULL) |
|
345 |
{
|
|
346 |
if (return_vals->n_values > 1 && |
|
347 |
G_VALUE_HOLDS_STRING (&return_vals->values[1])) |
|
348 |
{
|
|
349 |
g_set_error (error, 0, 0, |
|
350 |
g_value_get_string (&return_vals->values[1])); |
|
351 |
}
|
|
352 |
}
|
|
353 |
}
|
|
354 |
}
|
|
355 |
else
|
|
356 |
{
|
|
357 |
g_warning ("%s: no return values, shouldn't happen", G_STRFUNC); |
|
358 |
||
359 |
pdb_error = g_error_new (GIMP_PDB_ERROR, GIMP_PDB_INVALID_RETURN_VALUE, |
|
360 |
_("Procedure '%s' returned no return values"), |
|
361 |
gimp_object_get_name (GIMP_OBJECT (procedure))); |
|
362 |
||
363 |
return_vals = gimp_procedure_get_return_values (procedure, FALSE, |
|
364 |
pdb_error); |
|
365 |
if (error && *error == NULL) |
|
366 |
g_propagate_error (error, pdb_error); |
|
367 |
else
|
|
368 |
g_error_free (pdb_error); |
|
369 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
370 |
}
|
371 |
||
372 |
return return_vals; |
|
373 |
}
|
|
374 |
||
375 |
void
|
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
376 |
gimp_procedure_execute_async (GimpProcedure *procedure, |
377 |
Gimp *gimp, |
|
378 |
GimpContext *context, |
|
379 |
GimpProgress *progress, |
|
380 |
GValueArray *args, |
|
381 |
GimpObject *display, |
|
382 |
GError **error) |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
383 |
{
|
384 |
g_return_if_fail (GIMP_IS_PROCEDURE (procedure)); |
|
385 |
g_return_if_fail (GIMP_IS_GIMP (gimp)); |
|
386 |
g_return_if_fail (GIMP_IS_CONTEXT (context)); |
|
387 |
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress)); |
|
388 |
g_return_if_fail (args != NULL); |
|
389 |
g_return_if_fail (display == NULL || GIMP_IS_OBJECT (display)); |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
390 |
g_return_if_fail (error == NULL || *error == NULL); |
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
391 |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
392 |
if (gimp_procedure_validate_args (procedure, |
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
393 |
procedure->args, procedure->num_args, |
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
394 |
args, FALSE, error)) |
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
395 |
{
|
396 |
GIMP_PROCEDURE_GET_CLASS (procedure)->execute_async (procedure, gimp, |
|
397 |
context, progress, |
|
398 |
args, display); |
|
399 |
}
|
|
400 |
}
|
|
401 |
||
402 |
GValueArray * |
|
403 |
gimp_procedure_get_arguments (GimpProcedure *procedure) |
|
404 |
{
|
|
405 |
GValueArray *args; |
|
406 |
GValue value = { 0, }; |
|
407 |
gint i; |
|
408 |
||
409 |
g_return_val_if_fail (GIMP_IS_PROCEDURE (procedure), NULL); |
|
410 |
||
411 |
args = g_value_array_new (procedure->num_args); |
|
412 |
||
413 |
for (i = 0; i < procedure->num_args; i++) |
|
414 |
{
|
|
415 |
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (procedure->args[i])); |
|
416 |
g_value_array_append (args, &value); |
|
417 |
g_value_unset (&value); |
|
418 |
}
|
|
419 |
||
420 |
return args; |
|
421 |
}
|
|
422 |
||
423 |
GValueArray * |
|
424 |
gimp_procedure_get_return_values (GimpProcedure *procedure, |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
425 |
gboolean success, |
426 |
const GError *error) |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
427 |
{
|
428 |
GValueArray *args; |
|
429 |
GValue value = { 0, }; |
|
430 |
gint i; |
|
431 |
||
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
432 |
g_return_val_if_fail (success == FALSE || GIMP_IS_PROCEDURE (procedure), |
433 |
NULL); |
|
434 |
||
435 |
if (success) |
|
436 |
{
|
|
437 |
args = g_value_array_new (procedure->num_values + 1); |
|
438 |
||
439 |
g_value_init (&value, GIMP_TYPE_PDB_STATUS_TYPE); |
|
440 |
g_value_set_enum (&value, GIMP_PDB_SUCCESS); |
|
441 |
g_value_array_append (args, &value); |
|
442 |
g_value_unset (&value); |
|
443 |
||
444 |
for (i = 0; i < procedure->num_values; i++) |
|
445 |
{
|
|
446 |
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (procedure->values[i])); |
|
447 |
g_value_array_append (args, &value); |
|
448 |
g_value_unset (&value); |
|
449 |
}
|
|
450 |
}
|
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
451 |
else
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
452 |
{
|
453 |
args = g_value_array_new ((error && error->message) ? 2 : 1); |
|
454 |
||
455 |
g_value_init (&value, GIMP_TYPE_PDB_STATUS_TYPE); |
|
456 |
||
457 |
/* errors in the GIMP_PDB_ERROR domain are calling errors */
|
|
458 |
if (error && error->domain == GIMP_PDB_ERROR) |
|
459 |
{
|
|
460 |
switch ((GimpPdbErrorCode) error->code) |
|
461 |
{
|
|
462 |
case GIMP_PDB_PROCEDURE_NOT_FOUND: |
|
463 |
case GIMP_PDB_INVALID_ARGUMENT: |
|
464 |
case GIMP_PDB_INVALID_RETURN_VALUE: |
|
465 |
case GIMP_PDB_INTERNAL_ERROR: |
|
466 |
g_value_set_enum (&value, GIMP_PDB_CALLING_ERROR); |
|
467 |
break; |
|
468 |
||
469 |
case GIMP_PDB_CANCELLED: |
|
470 |
g_value_set_enum (&value, GIMP_PDB_CANCEL); |
|
471 |
break; |
|
472 |
||
473 |
default: |
|
474 |
g_assert_not_reached (); |
|
475 |
}
|
|
476 |
}
|
|
477 |
else
|
|
478 |
{
|
|
479 |
g_value_set_enum (&value, GIMP_PDB_EXECUTION_ERROR); |
|
480 |
}
|
|
481 |
||
482 |
g_value_array_append (args, &value); |
|
483 |
g_value_unset (&value); |
|
484 |
||
485 |
if (error && error->message) |
|
486 |
{
|
|
487 |
g_value_init (&value, G_TYPE_STRING); |
|
488 |
g_value_set_string (&value, error->message); |
|
489 |
g_value_array_append (args, &value); |
|
490 |
g_value_unset (&value); |
|
491 |
}
|
|
492 |
}
|
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
493 |
|
494 |
return args; |
|
495 |
}
|
|
496 |
||
497 |
void
|
|
498 |
gimp_procedure_add_argument (GimpProcedure *procedure, |
|
499 |
GParamSpec *pspec) |
|
500 |
{
|
|
501 |
g_return_if_fail (GIMP_IS_PROCEDURE (procedure)); |
|
502 |
g_return_if_fail (G_IS_PARAM_SPEC (pspec)); |
|
503 |
||
504 |
procedure->args = g_renew (GParamSpec *, procedure->args, |
|
505 |
procedure->num_args + 1); |
|
506 |
||
507 |
procedure->args[procedure->num_args] = pspec; |
|
508 |
||
509 |
g_param_spec_ref (pspec); |
|
510 |
g_param_spec_sink (pspec); |
|
511 |
||
512 |
procedure->num_args++; |
|
513 |
}
|
|
514 |
||
515 |
void
|
|
516 |
gimp_procedure_add_return_value (GimpProcedure *procedure, |
|
517 |
GParamSpec *pspec) |
|
518 |
{
|
|
519 |
g_return_if_fail (GIMP_IS_PROCEDURE (procedure)); |
|
520 |
g_return_if_fail (G_IS_PARAM_SPEC (pspec)); |
|
521 |
||
522 |
procedure->values = g_renew (GParamSpec *, procedure->values, |
|
523 |
procedure->num_values + 1); |
|
524 |
||
525 |
procedure->values[procedure->num_values] = pspec; |
|
526 |
||
527 |
g_param_spec_ref (pspec); |
|
528 |
g_param_spec_sink (pspec); |
|
529 |
||
530 |
procedure->num_values++; |
|
531 |
}
|
|
532 |
||
533 |
||
534 |
/* private functions */
|
|
535 |
||
536 |
static void |
|
537 |
gimp_procedure_free_strings (GimpProcedure *procedure) |
|
538 |
{
|
|
539 |
if (! procedure->static_strings) |
|
540 |
{
|
|
541 |
g_free (procedure->original_name); |
|
542 |
g_free (procedure->blurb); |
|
543 |
g_free (procedure->help); |
|
544 |
g_free (procedure->author); |
|
545 |
g_free (procedure->copyright); |
|
546 |
g_free (procedure->date); |
|
547 |
g_free (procedure->deprecated); |
|
548 |
}
|
|
549 |
||
550 |
procedure->original_name = NULL; |
|
551 |
procedure->blurb = NULL; |
|
552 |
procedure->help = NULL; |
|
553 |
procedure->author = NULL; |
|
554 |
procedure->copyright = NULL; |
|
555 |
procedure->date = NULL; |
|
556 |
procedure->deprecated = NULL; |
|
557 |
||
558 |
procedure->static_strings = FALSE; |
|
559 |
}
|
|
560 |
||
561 |
static gboolean |
|
562 |
gimp_procedure_validate_args (GimpProcedure *procedure, |
|
563 |
GParamSpec **param_specs, |
|
564 |
gint n_param_specs, |
|
565 |
GValueArray *args, |
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
566 |
gboolean return_vals, |
567 |
GError **error) |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
568 |
{
|
569 |
gint i; |
|
570 |
||
571 |
for (i = 0; i < MIN (args->n_values, n_param_specs); i++) |
|
572 |
{
|
|
573 |
GValue *arg = &args->values[i]; |
|
574 |
GParamSpec *pspec = param_specs[i]; |
|
575 |
GType arg_type = G_VALUE_TYPE (arg); |
|
576 |
GType spec_type = G_PARAM_SPEC_VALUE_TYPE (pspec); |
|
577 |
||
578 |
if (arg_type != spec_type) |
|
579 |
{
|
|
580 |
if (return_vals) |
|
581 |
{
|
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
582 |
g_set_error (error, |
583 |
GIMP_PDB_ERROR, GIMP_PDB_INVALID_RETURN_VALUE, |
|
584 |
_("Procedure '%s' returned a wrong value type " |
|
585 |
"for return value '%s' (#%d). "
|
|
586 |
"Expected %s, got %s."), |
|
587 |
gimp_object_get_name (GIMP_OBJECT (procedure)), |
|
588 |
g_param_spec_get_name (pspec), |
|
589 |
i + 1, g_type_name (spec_type), |
|
590 |
g_type_name (arg_type)); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
591 |
}
|
592 |
else
|
|
593 |
{
|
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
594 |
g_set_error (error, |
595 |
GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, |
|
596 |
_("Procedure '%s' has been called with a " |
|
597 |
"wrong value type for argument '%s' (#%d). "
|
|
598 |
"Expected %s, got %s."), |
|
599 |
gimp_object_get_name (GIMP_OBJECT (procedure)), |
|
600 |
g_param_spec_get_name (pspec), |
|
601 |
i + 1, g_type_name (spec_type), |
|
602 |
g_type_name (arg_type)); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
603 |
}
|
604 |
||
605 |
return FALSE; |
|
606 |
}
|
|
607 |
else if (! (pspec->flags & GIMP_PARAM_NO_VALIDATE)) |
|
608 |
{
|
|
609 |
GValue string_value = { 0, }; |
|
610 |
||
611 |
g_value_init (&string_value, G_TYPE_STRING); |
|
612 |
||
613 |
if (g_value_type_transformable (arg_type, G_TYPE_STRING)) |
|
614 |
g_value_transform (arg, &string_value); |
|
615 |
else
|
|
616 |
g_value_set_static_string (&string_value, |
|
617 |
"<not transformable to string>"); |
|
618 |
||
619 |
if (g_param_value_validate (pspec, arg)) |
|
620 |
{
|
|
621 |
if (GIMP_IS_PARAM_SPEC_DRAWABLE_ID (pspec) && |
|
622 |
g_value_get_int (arg) == -1) |
|
623 |
{
|
|
624 |
if (return_vals) |
|
625 |
{
|
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
626 |
g_set_error (error, |
627 |
GIMP_PDB_ERROR, GIMP_PDB_INVALID_RETURN_VALUE, |
|
628 |
_("Procedure '%s' returned an " |
|
629 |
"invalid ID for argument '%s'. "
|
|
630 |
"Most likely a plug-in is trying "
|
|
631 |
"to work on a layer that doesn't "
|
|
632 |
"exist any longer."), |
|
633 |
gimp_object_get_name (GIMP_OBJECT (procedure)), |
|
634 |
g_param_spec_get_name (pspec)); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
635 |
}
|
636 |
else
|
|
637 |
{
|
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
638 |
g_set_error (error, |
639 |
GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, |
|
640 |
_("Procedure '%s' has been called with an " |
|
641 |
"invalid ID for argument '%s'. "
|
|
642 |
"Most likely a plug-in is trying "
|
|
643 |
"to work on a layer that doesn't "
|
|
644 |
"exist any longer."), |
|
645 |
gimp_object_get_name (GIMP_OBJECT (procedure)), |
|
646 |
g_param_spec_get_name (pspec)); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
647 |
}
|
648 |
}
|
|
649 |
else if (GIMP_IS_PARAM_SPEC_IMAGE_ID (pspec) && |
|
650 |
g_value_get_int (arg) == -1) |
|
651 |
{
|
|
652 |
if (return_vals) |
|
653 |
{
|
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
654 |
g_set_error (error, |
655 |
GIMP_PDB_ERROR, GIMP_PDB_INVALID_RETURN_VALUE, |
|
656 |
_("Procedure '%s' returned an " |
|
657 |
"invalid ID for argument '%s'. "
|
|
658 |
"Most likely a plug-in is trying "
|
|
659 |
"to work on an image that doesn't "
|
|
660 |
"exist any longer."), |
|
661 |
gimp_object_get_name (GIMP_OBJECT (procedure)), |
|
662 |
g_param_spec_get_name (pspec)); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
663 |
}
|
664 |
else
|
|
665 |
{
|
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
666 |
g_set_error (error, |
667 |
GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, |
|
668 |
_("Procedure '%s' has been called with an " |
|
669 |
"invalid ID for argument '%s'. "
|
|
670 |
"Most likely a plug-in is trying "
|
|
671 |
"to work on an image that doesn't "
|
|
672 |
"exist any longer."), |
|
673 |
gimp_object_get_name (GIMP_OBJECT (procedure)), |
|
674 |
g_param_spec_get_name (pspec)); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
675 |
}
|
676 |
}
|
|
677 |
else
|
|
678 |
{
|
|
1.1.8
by Steve Kowalik
Import upstream version 2.4.1 |
679 |
const gchar *value = g_value_get_string (&string_value); |
680 |
||
681 |
if (value == NULL) |
|
682 |
value = "(null)"; |
|
683 |
||
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
684 |
if (return_vals) |
685 |
{
|
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
686 |
g_set_error (error, |
687 |
GIMP_PDB_ERROR, GIMP_PDB_INVALID_RETURN_VALUE, |
|
688 |
_("Procedure '%s' returned " |
|
689 |
"'%s' as return value '%s' "
|
|
690 |
"(#%d, type %s). "
|
|
691 |
"This value is out of range."), |
|
692 |
gimp_object_get_name (GIMP_OBJECT (procedure)), |
|
693 |
value, |
|
694 |
g_param_spec_get_name (pspec), |
|
695 |
i + 1, g_type_name (spec_type)); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
696 |
}
|
697 |
else
|
|
698 |
{
|
|
1.1.15
by Sebastien Bacher
Import upstream version 2.6.0 |
699 |
g_set_error (error, |
700 |
GIMP_PDB_ERROR, GIMP_PDB_INVALID_ARGUMENT, |
|
701 |
_("Procedure '%s' has been called with " |
|
702 |
"value '%s' for argument '%s' "
|
|
703 |
"(#%d, type %s). "
|
|
704 |
"This value is out of range."), |
|
705 |
gimp_object_get_name (GIMP_OBJECT (procedure)), |
|
706 |
value, |
|
707 |
g_param_spec_get_name (pspec), |
|
708 |
i + 1, g_type_name (spec_type)); |
|
1.1.4
by Daniel Holbach
Import upstream version 2.3.16 |
709 |
}
|
710 |
}
|
|
711 |
||
712 |
return FALSE; |
|
713 |
}
|
|
714 |
||
715 |
g_value_unset (&string_value); |
|
716 |
}
|
|
717 |
}
|
|
718 |
||
719 |
return TRUE; |
|
720 |
}
|