gimpproceduraldb_pdb.c 15.4 KB
Newer Older
1
/* LIBGIMP - The GIMP Library
2
 * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
3 4 5
 *
 * gimpproceduraldb_pdb.c
 *
6
 * This library is free software: you can redistribute it and/or
7 8
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
9
 * version 3 of the License, or (at your option) any later version.
10 11 12 13
 *
 * This library 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
14
 * Lesser General Public License for more details.
15 16
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library.  If not, see
18
 * <https://www.gnu.org/licenses/>.
19 20
 */

21
/* NOTE: This file is auto-generated by pdbgen.pl */
22

Sven Neumann's avatar
Sven Neumann committed
23 24
#include "config.h"

25 26
#include <string.h>

27 28
#include "gimp.h"

29 30 31 32 33 34 35 36 37 38 39

/**
 * SECTION: gimpproceduraldb
 * @title: gimpproceduraldb
 * @short_description: Functions for querying and changing procedural database (PDB) entries.
 *
 * Functions for querying and changing procedural database (PDB)
 * entries.
 **/


40 41 42 43 44 45
/**
 * gimp_procedural_db_temp_name:
 *
 * Generates a unique temporary PDB name.
 *
 * This procedure generates a temporary PDB entry name that is
46
 * guaranteed to be unique.
47 48
 *
 * Returns: A unique temporary name for a temporary PDB entry.
49
 **/
50 51 52 53 54 55 56
gchar *
gimp_procedural_db_temp_name (void)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gchar *temp_name = NULL;

57
  return_vals = gimp_run_procedure ("gimp-procedural-db-temp-name",
58 59
                                    &nreturn_vals,
                                    GIMP_PDB_END);
60 61 62 63 64 65 66 67 68

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    temp_name = g_strdup (return_vals[1].data.d_string);

  gimp_destroy_params (return_vals, nreturn_vals);

  return temp_name;
}

69 70 71 72 73 74 75 76
/**
 * gimp_procedural_db_dump:
 * @filename: The dump filename.
 *
 * Dumps the current contents of the procedural database
 *
 * This procedure dumps the contents of the procedural database to the
 * specified file. The file will contain all of the information
77
 * provided for each registered procedure.
78 79
 *
 * Returns: TRUE on success.
80
 **/
81
gboolean
82
gimp_procedural_db_dump (const gchar *filename)
83
{
84
  GimpParam *return_vals;
85
  gint nreturn_vals;
86
  gboolean success = TRUE;
87

88
  return_vals = gimp_run_procedure ("gimp-procedural-db-dump",
89 90 91
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, filename,
                                    GIMP_PDB_END);
92

93 94
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

95
  gimp_destroy_params (return_vals, nreturn_vals);
96 97

  return success;
98 99
}

100 101 102 103 104 105 106 107
/**
 * gimp_procedural_db_query:
 * @name: The regex for procedure name.
 * @blurb: The regex for procedure blurb.
 * @help: The regex for procedure help.
 * @author: The regex for procedure author.
 * @copyright: The regex for procedure copyright.
 * @date: The regex for procedure date.
108
 * @proc_type: The regex for procedure type: { 'Internal GIMP procedure', 'GIMP Plug-in', 'GIMP Extension', 'Temporary Procedure' }.
109
 * @num_matches: The number of matching procedures.
110
 * @procedure_names: The list of procedure names.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
 *
 * Queries the procedural database for its contents using regular
 * expression matching.
 *
 * This procedure queries the contents of the procedural database. It
 * is supplied with seven arguments matching procedures on { name,
 * blurb, help, author, copyright, date, procedure type}. This is
 * accomplished using regular expression matching. For instance, to
 * find all procedures with \"jpeg\" listed in the blurb, all seven
 * arguments can be supplied as \".*\", except for the second, which
 * can be supplied as \".*jpeg.*\". There are two return arguments for
 * this procedure. The first is the number of procedures matching the
 * query. The second is a concatenated list of procedure names
 * corresponding to those matching the query. If no matching entries
 * are found, then the returned string is NULL and the number of
 * entries is 0.
 *
 * Returns: TRUE on success.
129
 **/
130
gboolean
131
gimp_procedural_db_query (const gchar   *name,
132 133 134 135 136 137 138 139
                          const gchar   *blurb,
                          const gchar   *help,
                          const gchar   *author,
                          const gchar   *copyright,
                          const gchar   *date,
                          const gchar   *proc_type,
                          gint          *num_matches,
                          gchar       ***procedure_names)
140
{
141
  GimpParam *return_vals;
142
  gint nreturn_vals;
143
  gboolean success = TRUE;
144
  gint i;
145

146
  return_vals = gimp_run_procedure ("gimp-procedural-db-query",
147 148 149 150 151 152 153 154 155
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, name,
                                    GIMP_PDB_STRING, blurb,
                                    GIMP_PDB_STRING, help,
                                    GIMP_PDB_STRING, author,
                                    GIMP_PDB_STRING, copyright,
                                    GIMP_PDB_STRING, date,
                                    GIMP_PDB_STRING, proc_type,
                                    GIMP_PDB_END);
156

157
  *num_matches = 0;
158 159
  *procedure_names = NULL;

160 161 162
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
163
    {
164
      *num_matches = return_vals[1].data.d_int32;
165 166 167 168 169 170
      if (*num_matches > 0)
        {
          *procedure_names = g_new0 (gchar *, *num_matches + 1);
          for (i = 0; i < *num_matches; i++)
            (*procedure_names)[i] = g_strdup (return_vals[2].data.d_stringarray[i]);
        }
171 172 173
    }

  gimp_destroy_params (return_vals, nreturn_vals);
174 175

  return success;
176 177
}

178 179 180 181 182 183 184 185 186 187 188
/**
 * gimp_procedural_db_proc_exists:
 * @procedure_name: The procedure name.
 *
 * Checks if the specified procedure exists in the procedural database
 *
 * This procedure checks if the specified procedure is registered in
 * the procedural database.
 *
 * Returns: Whether a procedure of that name is registered.
 *
189
 * Since: 2.6
190
 **/
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
gboolean
gimp_procedural_db_proc_exists (const gchar *procedure_name)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean exists = FALSE;

  return_vals = gimp_run_procedure ("gimp-procedural-db-proc-exists",
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, procedure_name,
                                    GIMP_PDB_END);

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    exists = return_vals[1].data.d_int32;

  gimp_destroy_params (return_vals, nreturn_vals);

  return exists;
}

211 212
/**
 * _gimp_procedural_db_proc_info:
213
 * @procedure_name: The procedure name.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
 * @blurb: A short blurb.
 * @help: Detailed procedure help.
 * @author: Author(s) of the procedure.
 * @copyright: The copyright.
 * @date: Copyright date.
 * @proc_type: The procedure type.
 * @num_args: The number of input arguments.
 * @num_values: The number of return values.
 *
 * Queries the procedural database for information on the specified
 * procedure.
 *
 * This procedure returns information on the specified procedure. A
 * short blurb, detailed help, author(s), copyright information,
 * procedure type, number of input, and number of return values are
 * returned. For specific information on each input argument and return
230 231
 * value, use the gimp_procedural_db_proc_arg() and
 * gimp_procedural_db_proc_val() procedures.
232 233
 *
 * Returns: TRUE on success.
234
 **/
235
gboolean
236
_gimp_procedural_db_proc_info (const gchar      *procedure_name,
237 238 239 240 241 242 243 244
                               gchar           **blurb,
                               gchar           **help,
                               gchar           **author,
                               gchar           **copyright,
                               gchar           **date,
                               GimpPDBProcType  *proc_type,
                               gint             *num_args,
                               gint             *num_values)
245
{
246
  GimpParam *return_vals;
247
  gint nreturn_vals;
248
  gboolean success = TRUE;
249

250
  return_vals = gimp_run_procedure ("gimp-procedural-db-proc-info",
251 252 253
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, procedure_name,
                                    GIMP_PDB_END);
254

255 256 257 258 259 260 261 262
  *blurb = NULL;
  *help = NULL;
  *author = NULL;
  *copyright = NULL;
  *date = NULL;
  *proc_type = 0;
  *num_args = 0;
  *num_values = 0;
263

264 265 266
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
267
    {
268 269 270 271 272 273 274 275
      *blurb = g_strdup (return_vals[1].data.d_string);
      *help = g_strdup (return_vals[2].data.d_string);
      *author = g_strdup (return_vals[3].data.d_string);
      *copyright = g_strdup (return_vals[4].data.d_string);
      *date = g_strdup (return_vals[5].data.d_string);
      *proc_type = return_vals[6].data.d_int32;
      *num_args = return_vals[7].data.d_int32;
      *num_values = return_vals[8].data.d_int32;
276 277 278
    }

  gimp_destroy_params (return_vals, nreturn_vals);
279 280

  return success;
281 282
}

283 284
/**
 * gimp_procedural_db_proc_arg:
285
 * @procedure_name: The procedure name.
286 287 288 289 290 291 292 293 294 295 296 297
 * @arg_num: The argument number.
 * @arg_type: The type of argument.
 * @arg_name: The name of the argument.
 * @arg_desc: A description of the argument.
 *
 * Queries the procedural database for information on the specified
 * procedure's argument.
 *
 * This procedure returns information on the specified procedure's
 * argument. The argument type, name, and a description are retrieved.
 *
 * Returns: TRUE on success.
298
 **/
299
gboolean
300
gimp_procedural_db_proc_arg (const gchar     *procedure_name,
301 302 303 304
                             gint             arg_num,
                             GimpPDBArgType  *arg_type,
                             gchar          **arg_name,
                             gchar          **arg_desc)
305
{
306
  GimpParam *return_vals;
307
  gint nreturn_vals;
308
  gboolean success = TRUE;
309

310
  return_vals = gimp_run_procedure ("gimp-procedural-db-proc-arg",
311 312 313 314
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, procedure_name,
                                    GIMP_PDB_INT32, arg_num,
                                    GIMP_PDB_END);
315 316 317 318

  *arg_type = 0;
  *arg_name = NULL;
  *arg_desc = NULL;
319

320 321 322
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
323
    {
324 325 326
      *arg_type = return_vals[1].data.d_int32;
      *arg_name = g_strdup (return_vals[2].data.d_string);
      *arg_desc = g_strdup (return_vals[3].data.d_string);
327
    }
328

329
  gimp_destroy_params (return_vals, nreturn_vals);
330 331

  return success;
332 333
}

334 335
/**
 * gimp_procedural_db_proc_val:
336
 * @procedure_name: The procedure name.
337 338 339 340 341 342 343 344 345 346 347 348 349
 * @val_num: The return value number.
 * @val_type: The type of return value.
 * @val_name: The name of the return value.
 * @val_desc: A description of the return value.
 *
 * Queries the procedural database for information on the specified
 * procedure's return value.
 *
 * This procedure returns information on the specified procedure's
 * return value. The return value type, name, and a description are
 * retrieved.
 *
 * Returns: TRUE on success.
350
 **/
351
gboolean
352
gimp_procedural_db_proc_val (const gchar     *procedure_name,
353 354 355 356
                             gint             val_num,
                             GimpPDBArgType  *val_type,
                             gchar          **val_name,
                             gchar          **val_desc)
357
{
358
  GimpParam *return_vals;
359
  gint nreturn_vals;
360
  gboolean success = TRUE;
361

362
  return_vals = gimp_run_procedure ("gimp-procedural-db-proc-val",
363 364 365 366
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, procedure_name,
                                    GIMP_PDB_INT32, val_num,
                                    GIMP_PDB_END);
367 368 369 370

  *val_type = 0;
  *val_name = NULL;
  *val_desc = NULL;
371

372 373 374
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
375
    {
376 377 378
      *val_type = return_vals[1].data.d_int32;
      *val_name = g_strdup (return_vals[2].data.d_string);
      *val_desc = g_strdup (return_vals[3].data.d_string);
379
    }
380

381
  gimp_destroy_params (return_vals, nreturn_vals);
382 383

  return success;
384 385
}

386 387 388 389 390 391 392 393 394 395 396 397 398 399
/**
 * _gimp_procedural_db_get_data:
 * @identifier: The identifier associated with data.
 * @bytes: The number of bytes in the data.
 * @data: A byte array containing data.
 *
 * Returns data associated with the specified identifier.
 *
 * This procedure returns any data which may have been associated with
 * the specified identifier. The data is a variable length array of
 * bytes. If no data has been associated with the identifier, an error
 * is returned.
 *
 * Returns: TRUE on success.
400
 **/
401
gboolean
402
_gimp_procedural_db_get_data (const gchar  *identifier,
403 404
                              gint         *bytes,
                              guint8      **data)
405
{
406
  GimpParam *return_vals;
407
  gint nreturn_vals;
408
  gboolean success = TRUE;
409

410
  return_vals = gimp_run_procedure ("gimp-procedural-db-get-data",
411 412 413
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, identifier,
                                    GIMP_PDB_END);
414

415 416
  *bytes = 0;
  *data = NULL;
417

418 419 420
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
421
    {
422 423
      *bytes = return_vals[1].data.d_int32;
      *data = g_new (guint8, *bytes);
424 425 426
      memcpy (*data,
              return_vals[2].data.d_int8array,
              *bytes * sizeof (guint8));
427 428
    }

429
  gimp_destroy_params (return_vals, nreturn_vals);
430 431

  return success;
432
}
433

434 435 436 437 438 439 440 441 442 443 444
/**
 * gimp_procedural_db_get_data_size:
 * @identifier: The identifier associated with data.
 *
 * Returns size of data associated with the specified identifier.
 *
 * This procedure returns the size of any data which may have been
 * associated with the specified identifier. If no data has been
 * associated with the identifier, an error is returned.
 *
 * Returns: The number of bytes in the data.
445
 **/
446
gint
447
gimp_procedural_db_get_data_size (const gchar *identifier)
448
{
449
  GimpParam *return_vals;
450 451 452
  gint nreturn_vals;
  gint bytes = 0;

453
  return_vals = gimp_run_procedure ("gimp-procedural-db-get-data-size",
454 455 456
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, identifier,
                                    GIMP_PDB_END);
457

458
  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
459 460 461 462 463 464 465
    bytes = return_vals[1].data.d_int32;

  gimp_destroy_params (return_vals, nreturn_vals);

  return bytes;
}

466 467 468 469 470 471 472 473 474 475 476 477 478
/**
 * _gimp_procedural_db_set_data:
 * @identifier: The identifier associated with data.
 * @bytes: The number of bytes in the data.
 * @data: A byte array containing data.
 *
 * Associates the specified identifier with the supplied data.
 *
 * This procedure associates the supplied data with the provided
 * identifier. The data may be subsequently retrieved by a call to
 * 'procedural-db-get-data'.
 *
 * Returns: TRUE on success.
479
 **/
480
gboolean
481
_gimp_procedural_db_set_data (const gchar  *identifier,
482 483
                              gint          bytes,
                              const guint8 *data)
484
{
485
  GimpParam *return_vals;
486
  gint nreturn_vals;
487
  gboolean success = TRUE;
488

489
  return_vals = gimp_run_procedure ("gimp-procedural-db-set-data",
490 491 492 493 494
                                    &nreturn_vals,
                                    GIMP_PDB_STRING, identifier,
                                    GIMP_PDB_INT32, bytes,
                                    GIMP_PDB_INT8ARRAY, data,
                                    GIMP_PDB_END);
495

496 497
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

498
  gimp_destroy_params (return_vals, nreturn_vals);
499 500

  return success;
501
}