plug_in_cmds.c 18.5 KB
Newer Older
1
/* The GIMP -- an image manipulation program
2
 * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/* NOTE: This file is autogenerated by pdbgen.pl. */

21
#include "config.h"
22 23 24 25

#include <stdlib.h>
#include <string.h>

26
#include <glib-object.h>
27

28
#include "libgimpbase/gimpbase.h"
29
#include "libgimpbase/gimpprotocol.h"
30

31
#include "pdb-types.h"
32 33
#include "procedural_db.h"

Michael Natterer's avatar
Michael Natterer committed
34
#include "core/gimp.h"
35
#include "plug-in/plug-in-def.h"
36
#include "plug-in/plug-in-params.h"
37
#include "plug-in/plug-in-proc-def.h"
Michael Natterer's avatar
Michael Natterer committed
38
#include "plug-in/plug-in.h"
39
#include "plug-in/plug-ins-query.h"
40
#include "plug-in/plug-ins.h"
41

42
static ProcRecord plugins_query_proc;
43 44
static ProcRecord plugin_domain_register_proc;
static ProcRecord plugin_help_register_proc;
45
static ProcRecord plugin_menu_register_proc;
46
static ProcRecord plugin_menu_branch_register_proc;
47
static ProcRecord plugin_icon_register_proc;
48 49

void
50
register_plug_in_procs (Gimp *gimp)
51
{
52 53 54
  procedural_db_register (gimp, &plugins_query_proc);
  procedural_db_register (gimp, &plugin_domain_register_proc);
  procedural_db_register (gimp, &plugin_help_register_proc);
55
  procedural_db_register (gimp, &plugin_menu_register_proc);
56
  procedural_db_register (gimp, &plugin_menu_branch_register_proc);
57
  procedural_db_register (gimp, &plugin_icon_register_proc);
58 59 60
}

static Argument *
61 62 63 64
plugins_query_invoker (Gimp         *gimp,
                       GimpContext  *context,
                       GimpProgress *progress,
                       Argument     *args)
65 66 67 68 69 70 71 72 73 74 75 76 77
{
  Argument *return_args;
  gchar *search_str;
  gint32 num_plugins = 0;
  gchar **menu_strs;
  gchar **accel_strs;
  gchar **prog_strs;
  gchar **types_strs;
  gint32 *time_ints;
  gchar **realname_strs;

  search_str = (gchar *) args[0].value.pdb_pointer;

78 79 80 81 82 83 84
  num_plugins = plug_ins_query (gimp, search_str,
                                &menu_strs,
                                &accel_strs,
                                &prog_strs,
                                &types_strs,
                                &realname_strs,
                                &time_ints);
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

  return_args = procedural_db_return_args (&plugins_query_proc, TRUE);

  return_args[1].value.pdb_int = num_plugins;
  return_args[2].value.pdb_pointer = menu_strs;
  return_args[3].value.pdb_int = num_plugins;
  return_args[4].value.pdb_pointer = accel_strs;
  return_args[5].value.pdb_int = num_plugins;
  return_args[6].value.pdb_pointer = prog_strs;
  return_args[7].value.pdb_int = num_plugins;
  return_args[8].value.pdb_pointer = types_strs;
  return_args[9].value.pdb_int = num_plugins;
  return_args[10].value.pdb_pointer = time_ints;
  return_args[11].value.pdb_int = num_plugins;
  return_args[12].value.pdb_pointer = realname_strs;

  return return_args;
}

static ProcArg plugins_query_inargs[] =
{
  {
107
    GIMP_PDB_STRING,
108
    "search-string",
109 110 111 112 113 114 115
    "If not an empty string then use this as a search pattern"
  }
};

static ProcArg plugins_query_outargs[] =
{
  {
116
    GIMP_PDB_INT32,
117
    "num-plugins",
118 119 120
    "The number of plugins"
  },
  {
121
    GIMP_PDB_STRINGARRAY,
122
    "menu-path",
123 124 125
    "The menu path of the plugin"
  },
  {
126
    GIMP_PDB_INT32,
127
    "num-plugins",
128 129 130
    "The number of plugins"
  },
  {
131
    GIMP_PDB_STRINGARRAY,
132
    "plugin-accelerator",
133 134 135
    "String representing keyboard accelerator (could be empty string)"
  },
  {
136
    GIMP_PDB_INT32,
137
    "num-plugins",
138 139 140
    "The number of plugins"
  },
  {
141
    GIMP_PDB_STRINGARRAY,
142
    "plugin-location",
143 144 145
    "Location of the plugin program"
  },
  {
146
    GIMP_PDB_INT32,
147
    "num-plugins",
148 149 150
    "The number of plugins"
  },
  {
151
    GIMP_PDB_STRINGARRAY,
152
    "plugin-image-type",
153 154 155
    "Type of image that this plugin will work on"
  },
  {
156
    GIMP_PDB_INT32,
157
    "num-plugins",
158 159 160
    "The number of plugins"
  },
  {
161
    GIMP_PDB_INT32ARRAY,
162
    "plugin-install-time",
163 164 165
    "Time that the plugin was installed"
  },
  {
166
    GIMP_PDB_INT32,
167
    "num-plugins",
168 169 170
    "The number of plugins"
  },
  {
171
    GIMP_PDB_STRINGARRAY,
172
    "plugin-real-name",
173 174 175 176 177 178
    "The internal name of the plugin"
  }
};

static ProcRecord plugins_query_proc =
{
179 180
  "gimp-plugins-query",
  "gimp-plugins-query",
181 182 183 184 185
  "Queries the plugin database for its contents.",
  "This procedure queries the contents of the plugin database.",
  "Andy Thomas",
  "Andy Thomas",
  "1998",
186
  NULL,
187
  GIMP_INTERNAL,
188 189 190 191 192 193
  1,
  plugins_query_inargs,
  12,
  plugins_query_outargs,
  { { plugins_query_invoker } }
};
194 195

static Argument *
196 197 198 199
plugin_domain_register_invoker (Gimp         *gimp,
                                GimpContext  *context,
                                GimpProgress *progress,
                                Argument     *args)
200 201 202 203 204 205
{
  gboolean success = TRUE;
  gchar *domain_name;
  gchar *domain_path;

  domain_name = (gchar *) args[0].value.pdb_pointer;
206
  if (domain_name == NULL || !g_utf8_validate (domain_name, -1, NULL))
207 208 209 210 211 212
    success = FALSE;

  domain_path = (gchar *) args[1].value.pdb_pointer;

  if (success)
    {
213
      if (gimp->current_plug_in && gimp->current_plug_in->query)
Manish Singh's avatar
Manish Singh committed
214 215 216 217 218 219
        {
          plug_in_def_set_locale_domain_name (gimp->current_plug_in->plug_in_def,
                                              domain_name);
          plug_in_def_set_locale_domain_path (gimp->current_plug_in->plug_in_def,
                                              domain_path);
        }
220 221
      else
        success = FALSE;
222 223
    }

224
  return procedural_db_return_args (&plugin_domain_register_proc, success);
225 226
}

227
static ProcArg plugin_domain_register_inargs[] =
228 229
{
  {
230
    GIMP_PDB_STRING,
231
    "domain-name",
232
    "The name of the textdomain (must be unique)"
233 234
  },
  {
235
    GIMP_PDB_STRING,
236
    "domain-path",
237
    "The absolute path to the compiled message catalog (may be NULL)"
238 239 240
  }
};

241
static ProcRecord plugin_domain_register_proc =
242
{
243 244
  "gimp-plugin-domain-register",
  "gimp-plugin-domain-register",
245
  "Registers a textdomain for localisation.",
246
  "This procedure adds a textdomain to the list of domains Gimp searches for strings when translating its menu entries. There is no need to call this function for plug-ins that have their strings included in the gimp-std-plugins domain as that is used by default. If the compiled message catalog is not in the standard location, you may specify an absolute path to another location. This procedure can only be called in the query function of a plug-in and it has to be called before any procedure is installed.",
247 248 249
  "Sven Neumann",
  "Sven Neumann",
  "2000",
250
  NULL,
251
  GIMP_INTERNAL,
252
  2,
253
  plugin_domain_register_inargs,
254 255
  0,
  NULL,
256 257 258 259
  { { plugin_domain_register_invoker } }
};

static Argument *
260 261 262 263
plugin_help_register_invoker (Gimp         *gimp,
                              GimpContext  *context,
                              GimpProgress *progress,
                              Argument     *args)
264 265
{
  gboolean success = TRUE;
266 267 268 269 270 271
  gchar *domain_name;
  gchar *domain_uri;

  domain_name = (gchar *) args[0].value.pdb_pointer;
  if (domain_name == NULL || !g_utf8_validate (domain_name, -1, NULL))
    success = FALSE;
272

273 274
  domain_uri = (gchar *) args[1].value.pdb_pointer;
  if (domain_uri == NULL || !g_utf8_validate (domain_uri, -1, NULL))
275 276 277 278
    success = FALSE;

  if (success)
    {
279
      if (gimp->current_plug_in && gimp->current_plug_in->query)
Manish Singh's avatar
Manish Singh committed
280 281 282 283 284 285
        {
          plug_in_def_set_help_domain_name (gimp->current_plug_in->plug_in_def,
                                            domain_name);
          plug_in_def_set_help_domain_uri (gimp->current_plug_in->plug_in_def,
                                           domain_uri);
        }
286 287
      else
        success = FALSE;
288 289 290 291 292 293 294 295
    }

  return procedural_db_return_args (&plugin_help_register_proc, success);
}

static ProcArg plugin_help_register_inargs[] =
{
  {
296
    GIMP_PDB_STRING,
297
    "domain-name",
298 299 300 301
    "The XML namespace of the plug-in's help pages"
  },
  {
    GIMP_PDB_STRING,
302
    "domain-uri",
303
    "The root URI of the plug-in's help pages"
304 305 306 307 308
  }
};

static ProcRecord plugin_help_register_proc =
{
309 310
  "gimp-plugin-help-register",
  "gimp-plugin-help-register",
311
  "Register a help path for a plug-in.",
312
  "This procedure changes the help rootdir for the plug-in which calls it. All subsequent calls of gimp_help from this plug-in will be interpreted relative to this rootdir.",
313 314 315
  "Michael Natterer <mitch@gimp.org>",
  "Michael Natterer <mitch@gimp.org>",
  "2000",
316
  NULL,
317
  GIMP_INTERNAL,
318
  2,
319 320 321 322
  plugin_help_register_inargs,
  0,
  NULL,
  { { plugin_help_register_invoker } }
323
};
324 325

static Argument *
326 327 328 329
plugin_menu_register_invoker (Gimp         *gimp,
                              GimpContext  *context,
                              GimpProgress *progress,
                              Argument     *args)
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
{
  gboolean success = TRUE;
  gchar *procedure_name;
  gchar *menu_path;

  procedure_name = (gchar *) args[0].value.pdb_pointer;
  if (procedure_name == NULL || !g_utf8_validate (procedure_name, -1, NULL))
    success = FALSE;

  menu_path = (gchar *) args[1].value.pdb_pointer;
  if (menu_path == NULL || !g_utf8_validate (menu_path, -1, NULL))
    success = FALSE;

  if (success)
    {
345
      if (gimp->current_plug_in)
346
        {
347
          PlugInProcDef *proc_def = NULL;
348 349 350
          gchar         *canonical;

          canonical = gimp_canonicalize_identifier (procedure_name);
351

352
          if (gimp->current_plug_in->plug_in_def)
353
            proc_def = plug_in_proc_def_find (gimp->current_plug_in->plug_in_def->proc_defs,
354
                                              canonical);
355

356
          if (! proc_def)
357
            proc_def = plug_in_proc_def_find (gimp->current_plug_in->temp_proc_defs,
358
                                              canonical);
359

360 361 362 363 364 365 366 367
          if (proc_def)
            {
              if (proc_def->menu_label)
                {
                  GError *error = NULL;

                  if (! plug_in_proc_args_check (gimp->current_plug_in->name,
                                                 gimp->current_plug_in->prog,
368
                                                 canonical,
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
                                                 menu_path,
                                                 proc_def->db_info.args,
                                                 proc_def->db_info.num_args,
                                                 proc_def->db_info.values,
                                                 proc_def->db_info.num_values,
                                                 &error))
                    {
                      g_message (error->message);
                      g_clear_error (&error);

                      success = FALSE;
                    }
                  else
                    {
                      switch (proc_def->db_info.proc_type)
                        {
                        case GIMP_INTERNAL:
386
                          success = FALSE;
387 388 389 390 391 392 393 394 395 396 397
                          break;

                        case GIMP_PLUGIN:
                        case GIMP_EXTENSION:
                          if (! gimp->current_plug_in->query &&
                              ! gimp->current_plug_in->init)
                            success = FALSE;
                          break;

                        case GIMP_TEMPORARY:
                          break;
398
                        }
399 400

                      if (success)
401 402 403 404
                        {
                          proc_def->menu_paths = g_list_append (proc_def->menu_paths,
                                                                g_strdup (menu_path));

405 406 407
                          if (! gimp->no_interface &&
                              proc_def->db_info.proc_type == GIMP_TEMPORARY)
                            {
408
                              gimp_menus_create_item (gimp, proc_def, menu_path);
409
                            }
410
                        }
411
                    }
412 413 414
                }
              else
                {
415 416
                  g_message ("Plug-in \"%s\"\n(%s)\n\n"
                             "attempted to register the menu item \"%s\" "
417
                             "for procedure \"%s\".\n"
418 419 420 421
                             "The menu label given in gimp_install_procedure() "
                             "already contained a path.  To make this work, "
                             "pass just the menu's label to "
                             "gimp_install_procedure().",
422 423
                             gimp_filename_to_utf8 (gimp->current_plug_in->name),
                             gimp_filename_to_utf8 (gimp->current_plug_in->prog),
424
                             menu_path, canonical);
425 426

                  success = FALSE;
427 428
                }
            }
429
          else
430 431 432 433 434 435 436 437 438 439 440 441
            {
              g_message ("Plug-in \"%s\"\n(%s)\n\n"
                         "attempted to register the menu item \"%s\" "
                         "for the procedure \"%s\"\n."
                         "It has however not installed that procedure.  This "
                         "is not allowed.",
                         gimp_filename_to_utf8 (gimp->current_plug_in->name),
                         gimp_filename_to_utf8 (gimp->current_plug_in->prog),
                         menu_path, canonical);

              success = FALSE;
            }
442 443

          g_free (canonical);
444
        }
445 446
      else
        success = FALSE;
447 448
    }

449
  return procedural_db_return_args (&plugin_menu_register_proc, success);
450 451
}

452
static ProcArg plugin_menu_register_inargs[] =
453 454 455
{
  {
    GIMP_PDB_STRING,
456
    "procedure-name",
457 458 459 460
    "The procedure for which to install the menu path"
  },
  {
    GIMP_PDB_STRING,
461
    "menu-path",
462 463 464 465
    "The procedure's additional menu path"
  }
};

466
static ProcRecord plugin_menu_register_proc =
467
{
468 469
  "gimp-plugin-menu-register",
  "gimp-plugin-menu-register",
470 471 472 473 474
  "Register an additional menu path for a plug-in procedure.",
  "This procedure installs an additional menu entry for the given procedure.",
  "Michael Natterer <mitch@gimp.org>",
  "Michael Natterer <mitch@gimp.org>",
  "2004",
475
  NULL,
476 477
  GIMP_INTERNAL,
  2,
478
  plugin_menu_register_inargs,
479 480
  0,
  NULL,
481
  { { plugin_menu_register_invoker } }
482
};
483

484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527
static Argument *
plugin_menu_branch_register_invoker (Gimp         *gimp,
                                     GimpContext  *context,
                                     GimpProgress *progress,
                                     Argument     *args)
{
  gboolean success = TRUE;
  gchar *menu_path;
  gchar *menu_name;

  menu_path = (gchar *) args[0].value.pdb_pointer;
  if (menu_path == NULL || !g_utf8_validate (menu_path, -1, NULL))
    success = FALSE;

  menu_name = (gchar *) args[1].value.pdb_pointer;
  if (menu_name == NULL || !g_utf8_validate (menu_name, -1, NULL))
    success = FALSE;

  if (success)
    {
      if (gimp->current_plug_in)
        {
          plug_ins_menu_branch_add (gimp, gimp->current_plug_in->prog,
                                    menu_path, menu_name);

          if (! gimp->no_interface)
            {
              gimp_menus_create_branch (gimp, gimp->current_plug_in->prog,
                                        menu_path, menu_name);
            }
          else
            success = FALSE;
        }
      else
        success = FALSE;
    }

  return procedural_db_return_args (&plugin_menu_branch_register_proc, success);
}

static ProcArg plugin_menu_branch_register_inargs[] =
{
  {
    GIMP_PDB_STRING,
528
    "menu-path",
529 530 531 532
    "The sub-menu's menu path"
  },
  {
    GIMP_PDB_STRING,
533
    "menu-name",
534 535 536 537 538 539
    "The name of the sub-menu"
  }
};

static ProcRecord plugin_menu_branch_register_proc =
{
540 541
  "gimp-plugin-menu-branch-register",
  "gimp-plugin-menu-branch-register",
542 543 544 545 546 547 548 549 550 551 552 553 554 555
  "Register a sub-menu.",
  "This procedure installs an sub-menu which does not belong to any procedure.",
  "Michael Natterer <mitch@gimp.org>",
  "Michael Natterer <mitch@gimp.org>",
  "2005",
  NULL,
  GIMP_INTERNAL,
  2,
  plugin_menu_branch_register_inargs,
  0,
  NULL,
  { { plugin_menu_branch_register_invoker } }
};

556
static Argument *
557 558 559 560
plugin_icon_register_invoker (Gimp         *gimp,
                              GimpContext  *context,
                              GimpProgress *progress,
                              Argument     *args)
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
{
  gboolean success = TRUE;
  gchar *procedure_name;
  gint32 icon_type;
  gint32 icon_data_length;
  guint8 *icon_data;

  procedure_name = (gchar *) args[0].value.pdb_pointer;
  if (procedure_name == NULL || !g_utf8_validate (procedure_name, -1, NULL))
    success = FALSE;

  icon_type = args[1].value.pdb_int;
  if (icon_type < GIMP_ICON_TYPE_STOCK_ID || icon_type > GIMP_ICON_TYPE_IMAGE_FILE)
    success = FALSE;

  icon_data_length = args[2].value.pdb_int;
577 578
  if (icon_data_length <= 0)
    success = FALSE;
579 580 581 582 583 584 585

  icon_data = (guint8 *) args[3].value.pdb_pointer;

  if (success)
    {
      if (gimp->current_plug_in && gimp->current_plug_in->query)
        {
586
          PlugInProcDef *proc_def;
587 588 589
          gchar         *canonical;

          canonical = gimp_canonicalize_identifier (procedure_name);
590

591
          proc_def = plug_in_proc_def_find (gimp->current_plug_in->plug_in_def->proc_defs,
592 593 594
                                            canonical);

          g_free (canonical);
595

596 597 598 599
          if (proc_def)
            plug_in_proc_def_set_icon (proc_def, icon_type,
                                       icon_data, icon_data_length);
          else
600 601
            success = FALSE;
        }
602 603
      else
        success = FALSE;
604 605 606 607 608 609 610 611 612
    }

  return procedural_db_return_args (&plugin_icon_register_proc, success);
}

static ProcArg plugin_icon_register_inargs[] =
{
  {
    GIMP_PDB_STRING,
613
    "procedure-name",
614 615 616 617
    "The procedure for which to install the icon"
  },
  {
    GIMP_PDB_INT32,
618
    "icon-type",
619 620 621 622
    "The type of the icon"
  },
  {
    GIMP_PDB_INT32,
623
    "icon-data-length",
624
    "The length of 'icon_data': 0 < icon_data_length"
625 626 627
  },
  {
    GIMP_PDB_INT8ARRAY,
628
    "icon-data",
629 630 631 632 633 634
    "The procedure's icon. The format depends on the 'icon_type' parameter"
  }
};

static ProcRecord plugin_icon_register_proc =
{
635 636
  "gimp-plugin-icon-register",
  "gimp-plugin-icon-register",
637 638 639 640 641
  "Register an icon for a plug-in procedure.",
  "This procedure installs an icon for the given procedure.",
  "Michael Natterer <mitch@gimp.org>",
  "Michael Natterer <mitch@gimp.org>",
  "2004",
642
  NULL,
643 644 645 646 647 648 649
  GIMP_INTERNAL,
  4,
  plugin_icon_register_inargs,
  0,
  NULL,
  { { plugin_icon_register_invoker } }
};