~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to tools/pdbgen/pdb/plug_in.pdb

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# The GIMP -- an 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
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
 
19
 
 
20
# The defs
 
21
 
 
22
sub plugins_query {
 
23
    $blurb = 'Queries the plugin database for its contents.';
 
24
 
 
25
    $help = 'This procedure queries the contents of the plugin database.';
 
26
 
 
27
    $author = $copyright = 'Andy Thomas';
 
28
    $date = '1998';
 
29
 
 
30
    @inargs = (
 
31
        { name  => 'search_string', type => 'string',
 
32
          desc  => 'If not an empty string then use this as a search pattern',
 
33
          alias => 'search_str', no_success => 1 }
 
34
    );
 
35
 
 
36
    @outargs = (
 
37
        { name => 'menu_path', type => 'stringarray',
 
38
          desc => 'The menu path of the plugin',
 
39
          alias => 'menu_strs', init => 1 },
 
40
        { name => 'plugin_accelerator', type => 'stringarray',
 
41
          desc => 'String representing keyboard accelerator (could be empty
 
42
                   string)',
 
43
          alias => 'accel_strs', init => 1 },
 
44
        { name => 'plugin_location', type => 'stringarray',
 
45
          desc => 'Location of the plugin program',
 
46
          alias => 'prog_strs', init => 1 },
 
47
        { name => 'plugin_image_type', type => 'stringarray',
 
48
          desc => 'Type of image that this plugin will work on',
 
49
          alias => 'types_strs', init => 1 },
 
50
        { name => 'plugin_install_time', type => 'int32array',
 
51
          desc => 'Time that the plugin was installed',
 
52
          alias => 'time_ints', init => 1 },
 
53
        { name => 'plugin_real_name', type => 'stringarray',
 
54
          desc => 'The internal name of the plugin',
 
55
          alias => 'realname_strs', init => 1 }
 
56
    );
 
57
 
 
58
    foreach (@outargs) {
 
59
        $_->{array} = { name => 'num_plugins', no_declare => 1,
 
60
                        desc => 'The number of plugins' }
 
61
    }
 
62
 
 
63
    $outargs[0]->{array}->{init} = 1;
 
64
    delete $outargs[0]->{array}->{no_declare};
 
65
 
 
66
    %invoke = (
 
67
        headers => [ qw("libgimpbase/gimpbase.h") ],
 
68
        vars => [ 'GSList *list', 'GSList *matched = NULL', 'gint i = 0',
 
69
                  'regex_t sregex' ],
 
70
        code => <<'CODE'
 
71
{
 
72
  if (search_str && ! strlen (search_str))
 
73
    search_str = NULL;
 
74
 
 
75
  if (! (search_str && regcomp (&sregex, search_str, REG_ICASE)))
 
76
    {
 
77
      /* count number of plugin entries, then allocate arrays of correct size
 
78
       * where we can store the strings.
 
79
       */
 
80
 
 
81
      for (list = gimp->plug_in_proc_defs; list; list = g_slist_next (list))
 
82
        {
 
83
          PlugInProcDef *proc_def = list->data;
 
84
 
 
85
          if (proc_def->prog && proc_def->menu_paths)
 
86
            {
 
87
              gchar *name;
 
88
 
 
89
              if (proc_def->menu_label)
 
90
                {
 
91
                  name = proc_def->menu_label;
 
92
                }
 
93
              else
 
94
                {
 
95
                  name = strrchr (proc_def->menu_paths->data, '/');
 
96
 
 
97
                  if (name)
 
98
                    name = name + 1;
 
99
                  else
 
100
                    name = proc_def->menu_paths->data;
 
101
                }
 
102
 
 
103
              name = gimp_strip_uline (name);
 
104
 
 
105
              if (! search_str || ! match_strings (&sregex, name))
 
106
                {
 
107
                  num_plugins++;
 
108
                  matched = g_slist_prepend (matched, proc_def);
 
109
                }
 
110
 
 
111
              g_free (name);
 
112
            }
 
113
        }
 
114
 
 
115
      menu_strs     = g_new (gchar *, num_plugins);
 
116
      accel_strs    = g_new (gchar *, num_plugins);
 
117
      prog_strs     = g_new (gchar *, num_plugins);
 
118
      types_strs    = g_new (gchar *, num_plugins);
 
119
      realname_strs = g_new (gchar *, num_plugins);
 
120
      time_ints     = g_new (gint   , num_plugins);
 
121
 
 
122
      matched = g_slist_reverse (matched);
 
123
 
 
124
      for (list = matched; list; list = g_slist_next (list))
 
125
        {
 
126
          PlugInProcDef *proc_def = list->data;
 
127
          ProcRecord    *proc_rec = &proc_def->db_info;
 
128
          gchar         *name;
 
129
 
 
130
          if (proc_def->menu_label)
 
131
            name = g_strdup_printf ("%s/%s",
 
132
                                    (gchar *) proc_def->menu_paths->data,
 
133
                                    proc_def->menu_label);
 
134
          else
 
135
            name = g_strdup (proc_def->menu_paths->data);
 
136
 
 
137
          menu_strs[i]     = gimp_strip_uline (name);
 
138
          accel_strs[i]    = NULL;
 
139
          prog_strs[i]     = g_strdup (proc_def->prog);
 
140
          types_strs[i]    = g_strdup (proc_def->image_types);
 
141
          realname_strs[i] = g_strdup (proc_rec->name);
 
142
          time_ints[i]     = proc_def->mtime;
 
143
 
 
144
          g_free (name);
 
145
 
 
146
          i++;
 
147
        }
 
148
 
 
149
      g_slist_free (matched);
 
150
 
 
151
      if (search_str)
 
152
        regfree (&sregex);
 
153
   }
 
154
}
 
155
CODE
 
156
    );
 
157
}
 
158
 
 
159
sub plugin_domain_register {
 
160
    $blurb = 'Registers a textdomain for localisation.';
 
161
 
 
162
    $help = <<'HELP';
 
163
This procedure adds a textdomain to the list of domains Gimp searches 
 
164
for strings when translating its menu entries. There is no need to 
 
165
call this function for plug-ins that have their strings included in 
 
166
the gimp-std-plugins domain as that is used by default. If the compiled 
 
167
message catalog is not in the standard location, you may specify an 
 
168
absolute path to another location. This procedure can only be called 
 
169
in the query function of a plug-in and it has to be called before any
 
170
procedure is installed.
 
171
HELP
 
172
 
 
173
    $author = $copyright = 'Sven Neumann';
 
174
    $date = '2000';
 
175
 
 
176
    @inargs = (
 
177
        { name => 'domain_name', type => 'string',
 
178
          desc => 'The name of the textdomain (must be unique)' },
 
179
        { name => 'domain_path', type => 'string',
 
180
          desc => 'The absolute path to the compiled message catalog (may be
 
181
                   NULL)',
 
182
          no_success => 1 },
 
183
    );
 
184
 
 
185
    %invoke = (
 
186
        code => <<'CODE',
 
187
{
 
188
  if (gimp->current_plug_in && gimp->current_plug_in->query)
 
189
    {
 
190
      plug_in_def_set_locale_domain_name (gimp->current_plug_in->plug_in_def,
 
191
                                          domain_name);
 
192
      plug_in_def_set_locale_domain_path (gimp->current_plug_in->plug_in_def,
 
193
                                          domain_path);
 
194
    }
 
195
  else
 
196
    success = FALSE;
 
197
}
 
198
CODE
 
199
    );
 
200
}
 
201
 
 
202
sub plugin_help_register {
 
203
    $blurb = "Register a help path for a plug-in.";
 
204
 
 
205
    $help = <<HELP;
 
206
This procedure changes the help rootdir for the plug-in which calls it. All
 
207
subsequent calls of gimp_help from this plug-in will be interpreted relative
 
208
to this rootdir.
 
209
HELP
 
210
 
 
211
    $author = $copyright = 'Michael Natterer <mitch@gimp.org>';
 
212
    $date = '2000';
 
213
 
 
214
    @inargs = (
 
215
        { name => 'domain_name', type => 'string',
 
216
          desc => "The XML namespace of the plug-in's help pages" },
 
217
        { name => 'domain_uri', type => 'string',
 
218
          desc => "The root URI of the plug-in's help pages" }
 
219
    );
 
220
 
 
221
    %invoke = (
 
222
        code => <<'CODE',
 
223
{
 
224
  if (gimp->current_plug_in && gimp->current_plug_in->query)
 
225
    {
 
226
      plug_in_def_set_help_domain_name (gimp->current_plug_in->plug_in_def,
 
227
                                        domain_name);
 
228
      plug_in_def_set_help_domain_uri (gimp->current_plug_in->plug_in_def,
 
229
                                       domain_uri);
 
230
    }
 
231
  else
 
232
    success = FALSE;
 
233
}
 
234
CODE
 
235
    );
 
236
}
 
237
 
 
238
sub plugin_menu_register {
 
239
    $blurb = "Register an additional menu path for a plug-in procedure.";
 
240
 
 
241
    $help = <<HELP;
 
242
This procedure installs an additional menu entry for the given procedure.
 
243
HELP
 
244
 
 
245
    $author = $copyright = 'Michael Natterer <mitch@gimp.org>';
 
246
    $date = '2004';
 
247
    $since = '2.2';
 
248
 
 
249
    @inargs = (
 
250
        { name => 'procedure_name', type => 'string',
 
251
          desc => 'The procedure for which to install the menu path' },
 
252
        { name => 'menu_path', type => 'string',
 
253
          desc => "The procedure's additional menu path" }
 
254
    );
 
255
 
 
256
    %invoke = (
 
257
        code => <<'CODE',
 
258
{
 
259
  if (gimp->current_plug_in)
 
260
    {
 
261
      PlugInProcDef *proc_def = NULL;
 
262
      GSList        *list;
 
263
 
 
264
      if (gimp->current_plug_in->plug_in_def)
 
265
        {
 
266
          for (list = gimp->current_plug_in->plug_in_def->proc_defs;
 
267
               list;
 
268
               list = g_slist_next (list))
 
269
            {
 
270
              PlugInProcDef *pd = list->data;
 
271
 
 
272
              if (! strcmp (procedure_name, pd->db_info.name))
 
273
                {
 
274
                  proc_def = pd;
 
275
                  break;
 
276
                }
 
277
            }
 
278
        }
 
279
 
 
280
      if (! proc_def)
 
281
        {
 
282
          for (list = gimp->current_plug_in->temp_proc_defs;
 
283
               list;
 
284
               list = g_slist_next (list))
 
285
            {
 
286
              PlugInProcDef *pd = list->data;
 
287
 
 
288
              if (! strcmp (procedure_name, pd->db_info.name))
 
289
                {
 
290
                  proc_def = pd;
 
291
                  break;
 
292
                }
 
293
            }
 
294
        }
 
295
 
 
296
      if (proc_def)
 
297
        {
 
298
          if (proc_def->menu_label)
 
299
            {
 
300
              GError *error = NULL;
 
301
 
 
302
              if (! plug_in_proc_args_check (gimp->current_plug_in->name,
 
303
                                             gimp->current_plug_in->prog,
 
304
                                             procedure_name,
 
305
                                             menu_path,
 
306
                                             proc_def->db_info.args,
 
307
                                             proc_def->db_info.num_args,
 
308
                                             proc_def->db_info.values,
 
309
                                             proc_def->db_info.num_values,
 
310
                                             &error))
 
311
                {
 
312
                  g_message (error->message);
 
313
                  g_clear_error (&error);
 
314
 
 
315
                  success = FALSE;
 
316
                }
 
317
              else
 
318
                {
 
319
                  switch (proc_def->db_info.proc_type)
 
320
                    {
 
321
                    case GIMP_INTERNAL:
 
322
                      success = FALSE;
 
323
                      break;
 
324
 
 
325
                    case GIMP_PLUGIN:
 
326
                    case GIMP_EXTENSION:
 
327
                      if (! gimp->current_plug_in->query &&
 
328
                          ! gimp->current_plug_in->init)
 
329
                        success = FALSE;
 
330
                      break;
 
331
 
 
332
                    case GIMP_TEMPORARY:
 
333
                      break;
 
334
                    }
 
335
 
 
336
                  if (success)
 
337
                    {
 
338
                      proc_def->menu_paths = g_list_append (proc_def->menu_paths,
 
339
                                                            g_strdup (menu_path));
 
340
 
 
341
                      if (! gimp->no_interface &&
 
342
                          proc_def->db_info.proc_type == GIMP_TEMPORARY)
 
343
                        {
 
344
                          gimp_menus_create_entry (gimp, proc_def, menu_path);
 
345
                        }
 
346
                    }
 
347
                }
 
348
            }
 
349
          else
 
350
            {
 
351
              g_message ("Plug-In \"%s\"\n(%s)\n\n"
 
352
                         "attempted to install additional menu_path \"%s\"\n"
 
353
                         "for procedure \"%s\".\n"
 
354
                         "However the menu_path given in "
 
355
                         "gimp_install_procedure() already contained "
 
356
                         "a path. To make this work, pass just the menu's "
 
357
                         "label to gimp_install_procedure().",
 
358
                         gimp_filename_to_utf8 (gimp->current_plug_in->name),
 
359
                         gimp_filename_to_utf8 (gimp->current_plug_in->prog),
 
360
                         menu_path, procedure_name);
 
361
 
 
362
              success = FALSE;
 
363
            }
 
364
        }
 
365
      else
 
366
        success = FALSE;
 
367
    }
 
368
  else
 
369
    success = FALSE;
 
370
}
 
371
CODE
 
372
    );
 
373
}
 
374
 
 
375
sub plugin_icon_register {
 
376
    $blurb = "Register an icon for a plug-in procedure.";
 
377
 
 
378
    $help = <<HELP;
 
379
This procedure installs an icon for the given procedure.
 
380
HELP
 
381
 
 
382
    $author = $copyright = 'Michael Natterer <mitch@gimp.org>';
 
383
    $date = '2004';
 
384
    $since = '2.2';
 
385
 
 
386
    @inargs = (
 
387
        { name => 'procedure_name', type => 'string', wrap => 1,
 
388
          desc => 'The procedure for which to install the icon' },
 
389
        { name => 'icon_type', type => 'enum GimpIconType',
 
390
          desc => 'The type of the icon' },
 
391
        { name => 'icon_data', type => 'int8array',
 
392
          desc => "The procedure's icon. The format depends on the 'icon_type' parameter",
 
393
          array => { name => 'icon_data_length', type => '0 < int32',
 
394
                     desc => "The length of 'icon_data': %%desc%%" } }
 
395
    );
 
396
 
 
397
    %invoke = (
 
398
        code => <<'CODE',
 
399
{
 
400
  if (gimp->current_plug_in && gimp->current_plug_in->query)
 
401
    {
 
402
      GSList *list;
 
403
 
 
404
      for (list = gimp->current_plug_in->plug_in_def->proc_defs;
 
405
           list;
 
406
           list = g_slist_next (list))
 
407
        {
 
408
          PlugInProcDef *proc_def = list->data;
 
409
 
 
410
          if (! strcmp (procedure_name, proc_def->db_info.name))
 
411
            {
 
412
              if (proc_def->icon_data)
 
413
                {
 
414
                  g_free (proc_def->icon_data);
 
415
                  proc_def->icon_data_length = -1;
 
416
                  proc_def->icon_data        = NULL;
 
417
                }
 
418
 
 
419
              proc_def->icon_type = icon_type;
 
420
 
 
421
              switch (proc_def->icon_type)
 
422
                {
 
423
                case GIMP_ICON_TYPE_STOCK_ID:
 
424
                case GIMP_ICON_TYPE_IMAGE_FILE:
 
425
                  proc_def->icon_data_length = -1;
 
426
                  proc_def->icon_data        = g_strdup (icon_data);
 
427
                  break;
 
428
 
 
429
                case GIMP_ICON_TYPE_INLINE_PIXBUF:
 
430
                  proc_def->icon_data_length = icon_data_length;
 
431
                  proc_def->icon_data        = g_memdup (icon_data,
 
432
                                                         icon_data_length);
 
433
                  break;
 
434
                }
 
435
 
 
436
              break;
 
437
            }
 
438
        }
 
439
 
 
440
      if (! list)
 
441
        success = FALSE;
 
442
    }
 
443
  else
 
444
    success = FALSE;
 
445
}
 
446
CODE
 
447
    );
 
448
}
 
449
 
 
450
 
 
451
$extra{app}->{code} = <<'CODE';
 
452
static int
 
453
match_strings (regex_t *preg,
 
454
               gchar   *a)
 
455
{
 
456
  return regexec (preg, a, 0, NULL, 0);
 
457
}
 
458
CODE
 
459
 
 
460
@headers = qw(<string.h> <stdlib.h> "regexrepl/regex.h"
 
461
              "libgimpbase/gimpprotocol.h" "core/gimp.h" 
 
462
              "plug-in/plug-in.h" "plug-in/plug-ins.h"
 
463
              "plug-in/plug-in-def.h" "plug-in/plug-in-params.h"
 
464
              "plug-in/plug-in-proc-def.h");
 
465
 
 
466
@procs = qw(plugins_query
 
467
            plugin_domain_register plugin_help_register
 
468
            plugin_menu_register plugin_icon_register);
 
469
%exports = (app => [@procs], lib => [@procs[1,2,3,4]]);
 
470
 
 
471
$desc = 'Plug-in';
 
472
 
 
473
1;