~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/plug-in/gimppluginprocedure.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * gimppluginprocedure.c
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <string.h>
 
24
 
 
25
#include <glib-object.h>
 
26
#include <gdk-pixbuf/gdk-pixbuf.h>
 
27
 
 
28
#include "libgimpbase/gimpbase.h"
 
29
 
 
30
#include "plug-in-types.h"
 
31
 
 
32
#include "core/gimp.h"
 
33
#include "core/gimpmarshal.h"
 
34
#include "core/gimpparamspecs.h"
 
35
 
 
36
#define __YES_I_NEED_GIMP_PLUG_IN_MANAGER_CALL__
 
37
#include "gimppluginmanager-call.h"
 
38
#include "gimppluginprocedure.h"
 
39
 
 
40
#include "gimp-intl.h"
 
41
 
 
42
 
 
43
enum
 
44
{
 
45
  MENU_PATH_ADDED,
 
46
  LAST_SIGNAL
 
47
};
 
48
 
 
49
 
 
50
static void          gimp_plug_in_procedure_finalize    (GObject       *object);
 
51
 
 
52
static gint64        gimp_plug_in_procedure_get_memsize (GimpObject    *object,
 
53
                                                         gint64        *gui_size);
 
54
 
 
55
static GValueArray * gimp_plug_in_procedure_execute     (GimpProcedure *procedure,
 
56
                                                         Gimp          *gimp,
 
57
                                                         GimpContext   *context,
 
58
                                                         GimpProgress  *progress,
 
59
                                                         GValueArray   *args);
 
60
static void       gimp_plug_in_procedure_execute_async  (GimpProcedure *procedure,
 
61
                                                         Gimp          *gimp,
 
62
                                                         GimpContext   *context,
 
63
                                                         GimpProgress  *progress,
 
64
                                                         GValueArray   *args,
 
65
                                                         GimpObject    *display);
 
66
 
 
67
const gchar * gimp_plug_in_procedure_real_get_progname (const GimpPlugInProcedure *procedure);
 
68
 
 
69
 
 
70
G_DEFINE_TYPE (GimpPlugInProcedure, gimp_plug_in_procedure,
 
71
               GIMP_TYPE_PROCEDURE)
 
72
 
 
73
#define parent_class gimp_plug_in_procedure_parent_class
 
74
 
 
75
static guint gimp_plug_in_procedure_signals[LAST_SIGNAL] = { 0 };
 
76
 
 
77
 
 
78
static void
 
79
gimp_plug_in_procedure_class_init (GimpPlugInProcedureClass *klass)
 
80
{
 
81
  GObjectClass       *object_class      = G_OBJECT_CLASS (klass);
 
82
  GimpObjectClass    *gimp_object_class = GIMP_OBJECT_CLASS (klass);
 
83
  GimpProcedureClass *proc_class        = GIMP_PROCEDURE_CLASS (klass);
 
84
 
 
85
  gimp_plug_in_procedure_signals[MENU_PATH_ADDED] =
 
86
    g_signal_new ("menu-path-added",
 
87
                  G_TYPE_FROM_CLASS (klass),
 
88
                  G_SIGNAL_RUN_FIRST,
 
89
                  G_STRUCT_OFFSET (GimpPlugInProcedureClass, menu_path_added),
 
90
                  NULL, NULL,
 
91
                  gimp_marshal_VOID__STRING,
 
92
                  G_TYPE_NONE, 1,
 
93
                  G_TYPE_STRING);
 
94
 
 
95
  object_class->finalize         = gimp_plug_in_procedure_finalize;
 
96
 
 
97
  gimp_object_class->get_memsize = gimp_plug_in_procedure_get_memsize;
 
98
 
 
99
  proc_class->execute            = gimp_plug_in_procedure_execute;
 
100
  proc_class->execute_async      = gimp_plug_in_procedure_execute_async;
 
101
 
 
102
  klass->get_progname            = gimp_plug_in_procedure_real_get_progname;
 
103
  klass->menu_path_added         = NULL;
 
104
}
 
105
 
 
106
static void
 
107
gimp_plug_in_procedure_init (GimpPlugInProcedure *proc)
 
108
{
 
109
  GIMP_PROCEDURE (proc)->proc_type = GIMP_PLUGIN;
 
110
 
 
111
  proc->label            = NULL;
 
112
  proc->icon_data_length = -1;
 
113
}
 
114
 
 
115
static void
 
116
gimp_plug_in_procedure_finalize (GObject *object)
 
117
{
 
118
  GimpPlugInProcedure *proc = GIMP_PLUG_IN_PROCEDURE (object);
 
119
 
 
120
  g_free (proc->prog);
 
121
  g_free (proc->menu_label);
 
122
 
 
123
  g_list_foreach (proc->menu_paths, (GFunc) g_free, NULL);
 
124
  g_list_free (proc->menu_paths);
 
125
 
 
126
  g_free (proc->label);
 
127
 
 
128
  g_free (proc->icon_data);
 
129
  g_free (proc->image_types);
 
130
 
 
131
  g_free (proc->extensions);
 
132
  g_free (proc->prefixes);
 
133
  g_free (proc->magics);
 
134
  g_free (proc->mime_type);
 
135
 
 
136
  g_slist_foreach (proc->extensions_list, (GFunc) g_free, NULL);
 
137
  g_slist_free (proc->extensions_list);
 
138
 
 
139
  g_slist_foreach (proc->prefixes_list, (GFunc) g_free, NULL);
 
140
  g_slist_free (proc->prefixes_list);
 
141
 
 
142
  g_slist_foreach (proc->magics_list, (GFunc) g_free, NULL);
 
143
  g_slist_free (proc->magics_list);
 
144
 
 
145
  g_free (proc->thumb_loader);
 
146
 
 
147
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
148
}
 
149
 
 
150
static gint64
 
151
gimp_plug_in_procedure_get_memsize (GimpObject *object,
 
152
                                    gint64     *gui_size)
 
153
{
 
154
  GimpPlugInProcedure *proc    = GIMP_PLUG_IN_PROCEDURE (object);
 
155
  gint64               memsize = 0;
 
156
  GList               *list;
 
157
  GSList              *slist;
 
158
 
 
159
  if (proc->prog)
 
160
    memsize += strlen (proc->prog) + 1;
 
161
 
 
162
  if (proc->menu_label)
 
163
    memsize += strlen (proc->menu_label) + 1;
 
164
 
 
165
  for (list = proc->menu_paths; list; list = g_list_next (list))
 
166
    memsize += sizeof (GList) + strlen (list->data) + 1;
 
167
 
 
168
  switch (proc->icon_type)
 
169
    {
 
170
    case GIMP_ICON_TYPE_STOCK_ID:
 
171
    case GIMP_ICON_TYPE_IMAGE_FILE:
 
172
      if (proc->icon_data)
 
173
        memsize += strlen ((gchar *) proc->icon_data) + 1;
 
174
      break;
 
175
 
 
176
    case GIMP_ICON_TYPE_INLINE_PIXBUF:
 
177
      memsize += proc->icon_data_length;
 
178
      break;
 
179
    }
 
180
 
 
181
  if (proc->extensions)
 
182
    memsize += strlen (proc->extensions) + 1;
 
183
 
 
184
  if (proc->prefixes)
 
185
    memsize += strlen (proc->prefixes) + 1;
 
186
 
 
187
  if (proc->magics)
 
188
    memsize += strlen (proc->magics) + 1;
 
189
 
 
190
  if (proc->mime_type)
 
191
    memsize += strlen (proc->mime_type) + 1;
 
192
 
 
193
  if (proc->thumb_loader)
 
194
    memsize += strlen (proc->thumb_loader) + 1;
 
195
 
 
196
  for (slist = proc->extensions_list; slist; slist = g_slist_next (slist))
 
197
    memsize += sizeof (GSList) + strlen (slist->data) + 1;
 
198
 
 
199
  for (slist = proc->prefixes_list; slist; slist = g_slist_next (slist))
 
200
    memsize += sizeof (GSList) + strlen (slist->data) + 1;
 
201
 
 
202
  for (slist = proc->magics_list; slist; slist = g_slist_next (slist))
 
203
    memsize += sizeof (GSList) + strlen (slist->data) + 1;
 
204
 
 
205
  return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
 
206
                                                                  gui_size);
 
207
}
 
208
 
 
209
static GValueArray *
 
210
gimp_plug_in_procedure_execute (GimpProcedure *procedure,
 
211
                                Gimp          *gimp,
 
212
                                GimpContext   *context,
 
213
                                GimpProgress  *progress,
 
214
                                GValueArray   *args)
 
215
{
 
216
  if (procedure->proc_type == GIMP_INTERNAL)
 
217
    return GIMP_PROCEDURE_CLASS (parent_class)->execute (procedure, gimp,
 
218
                                                         context, progress,
 
219
                                                         args);
 
220
 
 
221
  return gimp_plug_in_manager_call_run (gimp->plug_in_manager,
 
222
                                        context, progress,
 
223
                                        GIMP_PLUG_IN_PROCEDURE (procedure),
 
224
                                        args, TRUE, FALSE, NULL);
 
225
}
 
226
 
 
227
static void
 
228
gimp_plug_in_procedure_execute_async (GimpProcedure *procedure,
 
229
                                      Gimp          *gimp,
 
230
                                      GimpContext   *context,
 
231
                                      GimpProgress  *progress,
 
232
                                      GValueArray   *args,
 
233
                                      GimpObject    *display)
 
234
{
 
235
  gimp_plug_in_manager_call_run (gimp->plug_in_manager,
 
236
                                 context, progress,
 
237
                                 GIMP_PLUG_IN_PROCEDURE (procedure),
 
238
                                 args, FALSE, TRUE, display);
 
239
}
 
240
 
 
241
const gchar *
 
242
gimp_plug_in_procedure_real_get_progname (const GimpPlugInProcedure *procedure)
 
243
{
 
244
  return procedure->prog;
 
245
}
 
246
 
 
247
 
 
248
/*  public functions  */
 
249
 
 
250
GimpProcedure *
 
251
gimp_plug_in_procedure_new (GimpPDBProcType  proc_type,
 
252
                            const gchar     *prog)
 
253
{
 
254
  GimpPlugInProcedure *proc;
 
255
 
 
256
  g_return_val_if_fail (proc_type == GIMP_PLUGIN ||
 
257
                        proc_type == GIMP_EXTENSION, NULL);
 
258
  g_return_val_if_fail (prog != NULL, NULL);
 
259
 
 
260
  proc = g_object_new (GIMP_TYPE_PLUG_IN_PROCEDURE, NULL);
 
261
 
 
262
  proc->prog = g_strdup (prog);
 
263
 
 
264
  GIMP_PROCEDURE (proc)->proc_type = proc_type;
 
265
 
 
266
  return GIMP_PROCEDURE (proc);
 
267
}
 
268
 
 
269
GimpPlugInProcedure *
 
270
gimp_plug_in_procedure_find (GSList      *list,
 
271
                             const gchar *proc_name)
 
272
{
 
273
  GSList *l;
 
274
 
 
275
  for (l = list; l; l = g_slist_next (l))
 
276
    {
 
277
      GimpObject *object = l->data;
 
278
 
 
279
      if (! strcmp (proc_name, object->name))
 
280
        return GIMP_PLUG_IN_PROCEDURE (object);
 
281
    }
 
282
 
 
283
  return NULL;
 
284
}
 
285
 
 
286
const gchar *
 
287
gimp_plug_in_procedure_get_progname (const GimpPlugInProcedure *proc)
 
288
{
 
289
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL);
 
290
 
 
291
  return GIMP_PLUG_IN_PROCEDURE_GET_CLASS (proc)->get_progname (proc);
 
292
}
 
293
 
 
294
void
 
295
gimp_plug_in_procedure_set_locale_domain (GimpPlugInProcedure *proc,
 
296
                                          const gchar         *locale_domain)
 
297
{
 
298
  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
 
299
 
 
300
  proc->locale_domain = locale_domain ? g_quark_from_string (locale_domain) : 0;
 
301
}
 
302
 
 
303
const gchar *
 
304
gimp_plug_in_procedure_get_locale_domain (const GimpPlugInProcedure *proc)
 
305
{
 
306
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL);
 
307
 
 
308
  return g_quark_to_string (proc->locale_domain);
 
309
}
 
310
 
 
311
void
 
312
gimp_plug_in_procedure_set_help_domain (GimpPlugInProcedure *proc,
 
313
                                        const gchar         *help_domain)
 
314
{
 
315
  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
 
316
 
 
317
  proc->help_domain = help_domain ? g_quark_from_string (help_domain) : 0;
 
318
}
 
319
 
 
320
const gchar *
 
321
gimp_plug_in_procedure_get_help_domain (const GimpPlugInProcedure *proc)
 
322
{
 
323
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL);
 
324
 
 
325
  return g_quark_to_string (proc->help_domain);
 
326
}
 
327
 
 
328
gboolean
 
329
gimp_plug_in_procedure_add_menu_path (GimpPlugInProcedure  *proc,
 
330
                                      const gchar          *menu_path,
 
331
                                      GError              **error)
 
332
{
 
333
  GimpProcedure *procedure;
 
334
  gchar         *basename = NULL;
 
335
  const gchar   *required = NULL;
 
336
  gchar         *p;
 
337
 
 
338
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), FALSE);
 
339
  g_return_val_if_fail (menu_path != NULL, FALSE);
 
340
  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
341
 
 
342
  procedure = GIMP_PROCEDURE (proc);
 
343
 
 
344
  p = strchr (menu_path, '>');
 
345
  if (p == NULL || (*(++p) && *p != '/'))
 
346
    {
 
347
      basename = g_filename_display_basename (proc->prog);
 
348
 
 
349
      g_set_error (error, 0, 0,
 
350
                   "Plug-In \"%s\"\n(%s)\n"
 
351
                   "attempted to install procedure \"%s\"\n"
 
352
                   "in the invalid menu location \"%s\".\n"
 
353
                   "The menu path must look like either \"<Prefix>\" "
 
354
                   "or \"<Prefix>/path/to/item\".",
 
355
                   basename, gimp_filename_to_utf8 (proc->prog),
 
356
                   GIMP_OBJECT (proc)->name,
 
357
                   menu_path);
 
358
      goto failure;
 
359
    }
 
360
 
 
361
  if (g_str_has_prefix (menu_path, "<Toolbox>") ||
 
362
      g_str_has_prefix (menu_path, "<Image>"))
 
363
    {
 
364
      if ((procedure->num_args < 1) ||
 
365
          ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]))
 
366
        {
 
367
          required = "INT32";
 
368
          goto failure;
 
369
        }
 
370
    }
 
371
  else if (g_str_has_prefix (menu_path, "<Layers>"))
 
372
    {
 
373
      if ((procedure->num_args < 3)                             ||
 
374
          ! GIMP_IS_PARAM_SPEC_INT32       (procedure->args[0]) ||
 
375
          ! GIMP_IS_PARAM_SPEC_IMAGE_ID    (procedure->args[1]) ||
 
376
          ! (G_TYPE_FROM_INSTANCE (procedure->args[2])
 
377
                               == GIMP_TYPE_PARAM_LAYER_ID ||
 
378
             G_TYPE_FROM_INSTANCE (procedure->args[2])
 
379
                               == GIMP_TYPE_PARAM_DRAWABLE_ID))
 
380
        {
 
381
          required = "INT32, IMAGE, (LAYER | DRAWABLE)";
 
382
          goto failure;
 
383
        }
 
384
    }
 
385
  else if (g_str_has_prefix (menu_path, "<Channels>"))
 
386
    {
 
387
      if ((procedure->num_args < 3)                             ||
 
388
          ! GIMP_IS_PARAM_SPEC_INT32       (procedure->args[0]) ||
 
389
          ! GIMP_IS_PARAM_SPEC_IMAGE_ID    (procedure->args[1]) ||
 
390
          ! (G_TYPE_FROM_INSTANCE (procedure->args[2])
 
391
                               == GIMP_TYPE_PARAM_CHANNEL_ID ||
 
392
             G_TYPE_FROM_INSTANCE (procedure->args[2])
 
393
                               == GIMP_TYPE_PARAM_DRAWABLE_ID))
 
394
        {
 
395
          required = "INT32, IMAGE, (CHANNEL | DRAWABLE)";
 
396
          goto failure;
 
397
        }
 
398
    }
 
399
  else if (g_str_has_prefix (menu_path, "<Vectors>"))
 
400
    {
 
401
      if ((procedure->num_args < 3)                            ||
 
402
          ! GIMP_IS_PARAM_SPEC_INT32      (procedure->args[0]) ||
 
403
          ! GIMP_IS_PARAM_SPEC_IMAGE_ID   (procedure->args[1]) ||
 
404
          ! GIMP_IS_PARAM_SPEC_VECTORS_ID (procedure->args[2]))
 
405
        {
 
406
          required = "INT32, IMAGE, VECTORS";
 
407
          goto failure;
 
408
        }
 
409
    }
 
410
  else if (g_str_has_prefix (menu_path, "<Colormap>"))
 
411
    {
 
412
      if ((procedure->num_args < 2)                            ||
 
413
          ! GIMP_IS_PARAM_SPEC_INT32      (procedure->args[0]) ||
 
414
          ! GIMP_IS_PARAM_SPEC_IMAGE_ID   (procedure->args[1]))
 
415
        {
 
416
          required = "INT32, IMAGE";
 
417
          goto failure;
 
418
        }
 
419
    }
 
420
  else if (g_str_has_prefix (menu_path, "<Load>"))
 
421
    {
 
422
      if ((procedure->num_args < 3)                       ||
 
423
          ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]) ||
 
424
          ! G_IS_PARAM_SPEC_STRING   (procedure->args[1]) ||
 
425
          ! G_IS_PARAM_SPEC_STRING   (procedure->args[2]))
 
426
        {
 
427
          required = "INT32, STRING, STRING";
 
428
          goto failure;
 
429
        }
 
430
 
 
431
      if ((procedure->num_values < 1) ||
 
432
          ! GIMP_IS_PARAM_SPEC_IMAGE_ID (procedure->values[0]))
 
433
        {
 
434
          required = "IMAGE";
 
435
          goto failure;
 
436
        }
 
437
    }
 
438
  else if (g_str_has_prefix (menu_path, "<Save>"))
 
439
    {
 
440
      if ((procedure->num_args < 5)                             ||
 
441
          ! GIMP_IS_PARAM_SPEC_INT32       (procedure->args[0]) ||
 
442
          ! GIMP_IS_PARAM_SPEC_IMAGE_ID    (procedure->args[1]) ||
 
443
          ! GIMP_IS_PARAM_SPEC_DRAWABLE_ID (procedure->args[2]) ||
 
444
          ! G_IS_PARAM_SPEC_STRING         (procedure->args[3]) ||
 
445
          ! G_IS_PARAM_SPEC_STRING         (procedure->args[4]))
 
446
        {
 
447
          required = "INT32, IMAGE, DRAWABLE, STRING, STRING";
 
448
          goto failure;
 
449
        }
 
450
    }
 
451
  else if (g_str_has_prefix (menu_path, "<Brushes>")   ||
 
452
           g_str_has_prefix (menu_path, "<Gradients>") ||
 
453
           g_str_has_prefix (menu_path, "<Palettes>")  ||
 
454
           g_str_has_prefix (menu_path, "<Patterns>")  ||
 
455
           g_str_has_prefix (menu_path, "<Fonts>")     ||
 
456
           g_str_has_prefix (menu_path, "<Buffers>"))
 
457
    {
 
458
      if ((procedure->num_args < 1) ||
 
459
          ! GIMP_IS_PARAM_SPEC_INT32 (procedure->args[0]))
 
460
        {
 
461
          required = "INT32";
 
462
          goto failure;
 
463
        }
 
464
    }
 
465
  else
 
466
    {
 
467
      basename = g_filename_display_basename (proc->prog);
 
468
 
 
469
      g_set_error (error, 0, 0,
 
470
                   "Plug-In \"%s\"\n(%s)\n"
 
471
                   "attempted to install procedure \"%s\" "
 
472
                   "in the invalid menu location \"%s\".\n"
 
473
                   "Use either \"<Toolbox>\", \"<Image>\", "
 
474
                   "\"<Layers>\", \"<Channels>\", \"<Vectors>\", "
 
475
                   "\"<Colormap>\", \"<Load>\", \"<Save>\", "
 
476
                   "\"<Brushes>\", \"<Gradients>\", \"<Palettes>\", "
 
477
                   "\"<Patterns>\" or \"<Buffers>\".",
 
478
                   basename, gimp_filename_to_utf8 (proc->prog),
 
479
                   GIMP_OBJECT (proc)->name,
 
480
                   menu_path);
 
481
      goto failure;
 
482
    }
 
483
 
 
484
  g_free (basename);
 
485
 
 
486
  proc->menu_paths = g_list_append (proc->menu_paths, g_strdup (menu_path));
 
487
 
 
488
  g_signal_emit (proc, gimp_plug_in_procedure_signals[MENU_PATH_ADDED], 0,
 
489
                 menu_path);
 
490
 
 
491
  return TRUE;
 
492
 
 
493
 failure:
 
494
  if (required)
 
495
    {
 
496
      gchar *prefix = g_strdup (menu_path);
 
497
 
 
498
      p = strchr (prefix, '>') + 1;
 
499
      *p = '\0';
 
500
 
 
501
      basename = g_filename_display_basename (proc->prog);
 
502
 
 
503
      g_set_error (error, 0, 0,
 
504
                   "Plug-In \"%s\"\n(%s)\n\n"
 
505
                   "attempted to install %s procedure \"%s\" "
 
506
                   "which does not take the standard %s Plug-In "
 
507
                   "arguments: (%s).",
 
508
                   basename, gimp_filename_to_utf8 (proc->prog),
 
509
                   prefix, GIMP_OBJECT (proc)->name, prefix,
 
510
                   required);
 
511
 
 
512
      g_free (prefix);
 
513
    }
 
514
 
 
515
  g_free (basename);
 
516
 
 
517
  return FALSE;
 
518
}
 
519
 
 
520
const gchar *
 
521
gimp_plug_in_procedure_get_label (GimpPlugInProcedure *proc)
 
522
{
 
523
  const gchar *path;
 
524
  gchar       *stripped;
 
525
  gchar       *ellipsis;
 
526
  gchar       *label;
 
527
 
 
528
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL);
 
529
 
 
530
  if (proc->label)
 
531
    return proc->label;
 
532
 
 
533
  if (proc->menu_label)
 
534
    path = dgettext (gimp_plug_in_procedure_get_locale_domain (proc),
 
535
                     proc->menu_label);
 
536
  else if (proc->menu_paths)
 
537
    path = dgettext (gimp_plug_in_procedure_get_locale_domain (proc),
 
538
                     proc->menu_paths->data);
 
539
  else
 
540
    return NULL;
 
541
 
 
542
  stripped = gimp_strip_uline (path);
 
543
 
 
544
  if (proc->menu_label)
 
545
    label = g_strdup (stripped);
 
546
  else
 
547
    label = g_path_get_basename (stripped);
 
548
 
 
549
  g_free (stripped);
 
550
 
 
551
  ellipsis = strstr (label, "...");
 
552
 
 
553
  if (! ellipsis)
 
554
    ellipsis = strstr (label, "\342\200\246" /* U+2026 HORIZONTAL ELLIPSIS */);
 
555
 
 
556
  if (ellipsis && ellipsis == (label + strlen (label) - 3))
 
557
    *ellipsis = '\0';
 
558
 
 
559
  proc->label = label;
 
560
 
 
561
  return proc->label;
 
562
}
 
563
 
 
564
const gchar *
 
565
gimp_plug_in_procedure_get_blurb (const GimpPlugInProcedure *proc)
 
566
{
 
567
  GimpProcedure *procedure;
 
568
 
 
569
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL);
 
570
 
 
571
  procedure = GIMP_PROCEDURE (proc);
 
572
 
 
573
  /*  do not to pass the empty string to gettext()  */
 
574
  if (procedure->blurb && strlen (procedure->blurb))
 
575
    return dgettext (gimp_plug_in_procedure_get_locale_domain (proc),
 
576
                     procedure->blurb);
 
577
 
 
578
  return NULL;
 
579
}
 
580
 
 
581
void
 
582
gimp_plug_in_procedure_set_icon (GimpPlugInProcedure *proc,
 
583
                                 GimpIconType         icon_type,
 
584
                                 const guint8        *icon_data,
 
585
                                 gint                 icon_data_length)
 
586
{
 
587
  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
 
588
  g_return_if_fail (icon_type == -1 || icon_data != NULL);
 
589
  g_return_if_fail (icon_type == -1 || icon_data_length > 0);
 
590
 
 
591
  if (proc->icon_data)
 
592
    {
 
593
      g_free (proc->icon_data);
 
594
      proc->icon_data_length = -1;
 
595
      proc->icon_data        = NULL;
 
596
    }
 
597
 
 
598
  proc->icon_type = icon_type;
 
599
 
 
600
  switch (proc->icon_type)
 
601
    {
 
602
    case GIMP_ICON_TYPE_STOCK_ID:
 
603
    case GIMP_ICON_TYPE_IMAGE_FILE:
 
604
      proc->icon_data_length = -1;
 
605
      proc->icon_data        = (guint8 *) g_strdup ((gchar *) icon_data);
 
606
      break;
 
607
 
 
608
    case GIMP_ICON_TYPE_INLINE_PIXBUF:
 
609
      proc->icon_data_length = icon_data_length;
 
610
      proc->icon_data        = g_memdup (icon_data, icon_data_length);
 
611
      break;
 
612
    }
 
613
}
 
614
 
 
615
const gchar *
 
616
gimp_plug_in_procedure_get_stock_id (const GimpPlugInProcedure *proc)
 
617
{
 
618
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL);
 
619
 
 
620
  switch (proc->icon_type)
 
621
    {
 
622
    case GIMP_ICON_TYPE_STOCK_ID:
 
623
      return (gchar *) proc->icon_data;
 
624
 
 
625
    default:
 
626
      return NULL;
 
627
    }
 
628
}
 
629
 
 
630
GdkPixbuf *
 
631
gimp_plug_in_procedure_get_pixbuf (const GimpPlugInProcedure *proc)
 
632
{
 
633
  GdkPixbuf *pixbuf = NULL;
 
634
  GError    *error  = NULL;
 
635
 
 
636
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL);
 
637
 
 
638
  switch (proc->icon_type)
 
639
    {
 
640
    case GIMP_ICON_TYPE_INLINE_PIXBUF:
 
641
      pixbuf = gdk_pixbuf_new_from_inline (proc->icon_data_length,
 
642
                                           proc->icon_data, TRUE, &error);
 
643
      break;
 
644
 
 
645
    case GIMP_ICON_TYPE_IMAGE_FILE:
 
646
      pixbuf = gdk_pixbuf_new_from_file ((gchar *) proc->icon_data,
 
647
                                         &error);
 
648
      break;
 
649
 
 
650
    default:
 
651
      break;
 
652
    }
 
653
 
 
654
  if (! pixbuf && error)
 
655
    {
 
656
      g_printerr (error->message);
 
657
      g_clear_error (&error);
 
658
    }
 
659
 
 
660
  return pixbuf;
 
661
}
 
662
 
 
663
gchar *
 
664
gimp_plug_in_procedure_get_help_id (const GimpPlugInProcedure *proc)
 
665
{
 
666
  const gchar *domain;
 
667
 
 
668
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), NULL);
 
669
 
 
670
  domain = gimp_plug_in_procedure_get_help_domain (proc);
 
671
 
 
672
  if (domain)
 
673
    return g_strconcat (domain, "?", GIMP_OBJECT (proc)->name, NULL);
 
674
 
 
675
  return g_strdup (GIMP_OBJECT (proc)->name);
 
676
}
 
677
 
 
678
gboolean
 
679
gimp_plug_in_procedure_get_sensitive (const GimpPlugInProcedure *proc,
 
680
                                      GimpImageType              image_type)
 
681
{
 
682
  gboolean sensitive;
 
683
 
 
684
  g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), FALSE);
 
685
 
 
686
  switch (image_type)
 
687
    {
 
688
    case GIMP_RGB_IMAGE:
 
689
      sensitive = proc->image_types_val & GIMP_PLUG_IN_RGB_IMAGE;
 
690
      break;
 
691
    case GIMP_RGBA_IMAGE:
 
692
      sensitive = proc->image_types_val & GIMP_PLUG_IN_RGBA_IMAGE;
 
693
      break;
 
694
    case GIMP_GRAY_IMAGE:
 
695
      sensitive = proc->image_types_val & GIMP_PLUG_IN_GRAY_IMAGE;
 
696
      break;
 
697
    case GIMP_GRAYA_IMAGE:
 
698
      sensitive = proc->image_types_val & GIMP_PLUG_IN_GRAYA_IMAGE;
 
699
      break;
 
700
    case GIMP_INDEXED_IMAGE:
 
701
      sensitive = proc->image_types_val & GIMP_PLUG_IN_INDEXED_IMAGE;
 
702
      break;
 
703
    case GIMP_INDEXEDA_IMAGE:
 
704
      sensitive = proc->image_types_val & GIMP_PLUG_IN_INDEXEDA_IMAGE;
 
705
      break;
 
706
    default:
 
707
      sensitive = FALSE;
 
708
      break;
 
709
    }
 
710
 
 
711
  return sensitive ? TRUE : FALSE;
 
712
}
 
713
 
 
714
static GimpPlugInImageType
 
715
image_types_parse (const gchar *name,
 
716
                   const gchar *image_types)
 
717
{
 
718
  const gchar         *type_spec = image_types;
 
719
  GimpPlugInImageType  types     = 0;
 
720
 
 
721
  /*  If the plug_in registers with image_type == NULL or "", return 0
 
722
   *  By doing so it won't be touched by plug_in_set_menu_sensitivity()
 
723
   */
 
724
  if (! image_types)
 
725
    return types;
 
726
 
 
727
  while (*image_types)
 
728
    {
 
729
      while (*image_types &&
 
730
             ((*image_types == ' ') ||
 
731
              (*image_types == '\t') ||
 
732
              (*image_types == ',')))
 
733
        image_types++;
 
734
 
 
735
      if (*image_types)
 
736
        {
 
737
          if (g_str_has_prefix (image_types, "RGBA"))
 
738
            {
 
739
              types |= GIMP_PLUG_IN_RGBA_IMAGE;
 
740
              image_types += strlen ("RGBA");
 
741
            }
 
742
          else if (g_str_has_prefix (image_types, "RGB*"))
 
743
            {
 
744
              types |= GIMP_PLUG_IN_RGB_IMAGE | GIMP_PLUG_IN_RGBA_IMAGE;
 
745
              image_types += strlen ("RGB*");
 
746
            }
 
747
          else if (g_str_has_prefix (image_types, "RGB"))
 
748
            {
 
749
              types |= GIMP_PLUG_IN_RGB_IMAGE;
 
750
              image_types += strlen ("RGB");
 
751
            }
 
752
          else if (g_str_has_prefix (image_types, "GRAYA"))
 
753
            {
 
754
              types |= GIMP_PLUG_IN_GRAYA_IMAGE;
 
755
              image_types += strlen ("GRAYA");
 
756
            }
 
757
          else if (g_str_has_prefix (image_types, "GRAY*"))
 
758
            {
 
759
              types |= GIMP_PLUG_IN_GRAY_IMAGE | GIMP_PLUG_IN_GRAYA_IMAGE;
 
760
              image_types += strlen ("GRAY*");
 
761
            }
 
762
          else if (g_str_has_prefix (image_types, "GRAY"))
 
763
            {
 
764
              types |= GIMP_PLUG_IN_GRAY_IMAGE;
 
765
              image_types += strlen ("GRAY");
 
766
            }
 
767
          else if (g_str_has_prefix (image_types, "INDEXEDA"))
 
768
            {
 
769
              types |= GIMP_PLUG_IN_INDEXEDA_IMAGE;
 
770
              image_types += strlen ("INDEXEDA");
 
771
            }
 
772
          else if (g_str_has_prefix (image_types, "INDEXED*"))
 
773
            {
 
774
              types |= GIMP_PLUG_IN_INDEXED_IMAGE | GIMP_PLUG_IN_INDEXEDA_IMAGE;
 
775
              image_types += strlen ("INDEXED*");
 
776
            }
 
777
          else if (g_str_has_prefix (image_types, "INDEXED"))
 
778
            {
 
779
              types |= GIMP_PLUG_IN_INDEXED_IMAGE;
 
780
              image_types += strlen ("INDEXED");
 
781
            }
 
782
          else if (g_str_has_prefix (image_types, "*"))
 
783
            {
 
784
              types |= (GIMP_PLUG_IN_RGB_IMAGE     | GIMP_PLUG_IN_RGBA_IMAGE  |
 
785
                        GIMP_PLUG_IN_GRAY_IMAGE    | GIMP_PLUG_IN_GRAYA_IMAGE |
 
786
                        GIMP_PLUG_IN_INDEXED_IMAGE | GIMP_PLUG_IN_INDEXEDA_IMAGE);
 
787
              image_types += strlen ("*");
 
788
            }
 
789
          else
 
790
            {
 
791
              g_printerr ("%s: image-type contains unrecognizable parts:"
 
792
                          "'%s'\n", name, type_spec);
 
793
 
 
794
              while (*image_types &&
 
795
                     ((*image_types != ' ') ||
 
796
                      (*image_types != '\t') ||
 
797
                      (*image_types != ',')))
 
798
                {
 
799
                  image_types++;
 
800
                }
 
801
            }
 
802
        }
 
803
    }
 
804
 
 
805
  return types;
 
806
}
 
807
 
 
808
void
 
809
gimp_plug_in_procedure_set_image_types (GimpPlugInProcedure *proc,
 
810
                                        const gchar         *image_types)
 
811
{
 
812
  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
 
813
 
 
814
  if (proc->image_types)
 
815
    g_free (proc->image_types);
 
816
 
 
817
  proc->image_types     = g_strdup (image_types);
 
818
  proc->image_types_val = image_types_parse (gimp_object_get_name (GIMP_OBJECT (proc)),
 
819
                                             proc->image_types);
 
820
}
 
821
 
 
822
static GSList *
 
823
extensions_parse (gchar *extensions)
 
824
{
 
825
  GSList *list = NULL;
 
826
 
 
827
  /* EXTENSIONS can be NULL.  Avoid calling strtok if it is.  */
 
828
  if (extensions)
 
829
    {
 
830
      gchar *extension;
 
831
      gchar *next_token;
 
832
 
 
833
      extensions = g_strdup (extensions);
 
834
 
 
835
      next_token = extensions;
 
836
      extension = strtok (next_token, " \t,");
 
837
 
 
838
      while (extension)
 
839
        {
 
840
          list = g_slist_prepend (list, g_strdup (extension));
 
841
          extension = strtok (NULL, " \t,");
 
842
        }
 
843
 
 
844
      g_free (extensions);
 
845
    }
 
846
 
 
847
  return g_slist_reverse (list);
 
848
}
 
849
 
 
850
void
 
851
gimp_plug_in_procedure_set_file_proc (GimpPlugInProcedure *proc,
 
852
                                      const gchar         *extensions,
 
853
                                      const gchar         *prefixes,
 
854
                                      const gchar         *magics)
 
855
{
 
856
  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
 
857
 
 
858
  proc->file_proc = TRUE;
 
859
 
 
860
  if (proc->extensions != extensions)
 
861
    {
 
862
      if (proc->extensions)
 
863
        g_free (proc->extensions);
 
864
      proc->extensions = g_strdup (extensions);
 
865
    }
 
866
 
 
867
  proc->extensions_list = extensions_parse (proc->extensions);
 
868
 
 
869
  if (proc->prefixes != prefixes)
 
870
    {
 
871
      if (proc->prefixes)
 
872
        g_free (proc->prefixes);
 
873
      proc->prefixes = g_strdup (prefixes);
 
874
    }
 
875
 
 
876
  proc->prefixes_list = extensions_parse (proc->prefixes);
 
877
 
 
878
  if (proc->magics != magics)
 
879
    {
 
880
      if (proc->magics)
 
881
        g_free (proc->magics);
 
882
      proc->magics = g_strdup (magics);
 
883
    }
 
884
 
 
885
  proc->magics_list = extensions_parse (proc->magics);
 
886
}
 
887
 
 
888
void
 
889
gimp_plug_in_procedure_set_mime_type (GimpPlugInProcedure *proc,
 
890
                                      const gchar         *mime_type)
 
891
{
 
892
  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
 
893
 
 
894
  proc->file_proc = TRUE;
 
895
 
 
896
  if (proc->mime_type)
 
897
    g_free (proc->mime_type);
 
898
 
 
899
  proc->mime_type = g_strdup (mime_type);
 
900
}
 
901
 
 
902
void
 
903
gimp_plug_in_procedure_set_thumb_loader (GimpPlugInProcedure *proc,
 
904
                                         const gchar         *thumb_loader)
 
905
{
 
906
  g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc));
 
907
 
 
908
  proc->file_proc = TRUE;
 
909
 
 
910
  if (proc->thumb_loader)
 
911
    g_free (proc->thumb_loader);
 
912
 
 
913
  proc->thumb_loader = g_strdup (thumb_loader);
 
914
}