progress-cmds.c 20.8 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
 *
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 3 of the License, or
7 8 9 10 11 12 13 14
 * (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
15
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16 17
 */

18
/* NOTE: This file is auto-generated by pdbgen.pl. */
19 20 21

#include "config.h"

22
#include <gegl.h>
23

24 25
#include <gdk-pixbuf/gdk-pixbuf.h>

26 27
#include "libgimpbase/gimpbase.h"

28 29 30
#include "pdb-types.h"

#include "core/gimp.h"
31
#include "core/gimpparamspecs.h"
32 33
#include "plug-in/gimpplugin-progress.h"
#include "plug-in/gimpplugin.h"
34
#include "plug-in/gimppluginmanager.h"
35

36 37
#include "gimppdb.h"
#include "gimpprocedure.h"
38
#include "internal-procs.h"
39

40

41
static GimpValueArray *
42
progress_init_invoker (GimpProcedure         *procedure,
43 44 45 46 47
                       Gimp                  *gimp,
                       GimpContext           *context,
                       GimpProgress          *progress,
                       const GimpValueArray  *args,
                       GError               **error)
48 49
{
  gboolean success = TRUE;
50
  const gchar *message;
51
  GimpObject *gdisplay;
52

53 54
  message = g_value_get_string (gimp_value_array_index (args, 0));
  gdisplay = gimp_value_get_display (gimp_value_array_index (args, 1), gimp);
55 56 57

  if (success)
    {
58
      GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
59 60

      if (plug_in && plug_in->open)
61 62
        {
          if (! gimp->no_interface)
63
            gimp_plug_in_progress_start (plug_in, message, gdisplay);
64 65 66 67 68
        }
      else
        success = FALSE;
    }

69 70
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
71 72
}

73
static GimpValueArray *
74
progress_update_invoker (GimpProcedure         *procedure,
75 76 77 78 79
                         Gimp                  *gimp,
                         GimpContext           *context,
                         GimpProgress          *progress,
                         const GimpValueArray  *args,
                         GError               **error)
80 81 82 83
{
  gboolean success = TRUE;
  gdouble percentage;

84
  percentage = g_value_get_double (gimp_value_array_index (args, 0));
85

86
  if (success)
87
    {
88
      GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
89 90

      if (plug_in && plug_in->open)
91 92
        {
          if (! gimp->no_interface)
93
            gimp_plug_in_progress_set_value (plug_in, percentage);
94 95 96
        }
      else
        success = FALSE;
97 98
    }

99 100
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
101 102
}

103
static GimpValueArray *
104
progress_pulse_invoker (GimpProcedure         *procedure,
105 106 107 108 109
                        Gimp                  *gimp,
                        GimpContext           *context,
                        GimpProgress          *progress,
                        const GimpValueArray  *args,
                        GError               **error)
110 111
{
  gboolean success = TRUE;
112
  GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
113 114

  if (plug_in && plug_in->open)
115 116
    {
      if (! gimp->no_interface)
117
        gimp_plug_in_progress_pulse (plug_in);
118 119 120
    }
  else
    success = FALSE;
121

122 123
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
124 125
}

126
static GimpValueArray *
127
progress_set_text_invoker (GimpProcedure         *procedure,
128 129 130 131 132
                           Gimp                  *gimp,
                           GimpContext           *context,
                           GimpProgress          *progress,
                           const GimpValueArray  *args,
                           GError               **error)
133 134
{
  gboolean success = TRUE;
135
  const gchar *message;
136

137
  message = g_value_get_string (gimp_value_array_index (args, 0));
138 139 140

  if (success)
    {
141
      GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
142 143

      if (plug_in && plug_in->open)
144 145
        {
          if (! gimp->no_interface)
146
            gimp_plug_in_progress_set_text (plug_in, message);
147 148 149 150 151
        }
      else
        success = FALSE;
    }

152 153
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
154 155
}

156
static GimpValueArray *
157
progress_end_invoker (GimpProcedure         *procedure,
158 159 160 161 162
                      Gimp                  *gimp,
                      GimpContext           *context,
                      GimpProgress          *progress,
                      const GimpValueArray  *args,
                      GError               **error)
163 164 165 166 167 168 169 170 171 172 173 174 175
{
  gboolean success = TRUE;
  GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;

  if (plug_in && plug_in->open)
    {
      GimpPlugInProcFrame *proc_frame = gimp_plug_in_get_proc_frame (plug_in);

      gimp_plug_in_progress_end (plug_in, proc_frame);
    }
  else
    success = FALSE;

176 177
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
178 179
}

180
static GimpValueArray *
181
progress_get_window_handle_invoker (GimpProcedure         *procedure,
182 183 184 185 186
                                    Gimp                  *gimp,
                                    GimpContext           *context,
                                    GimpProgress          *progress,
                                    const GimpValueArray  *args,
                                    GError               **error)
187 188
{
  gboolean success = TRUE;
189
  GimpValueArray *return_vals;
190 191
  gint32 window = 0;

192
  GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
193 194

  if (plug_in && plug_in->open)
195 196
    {
      if (! gimp->no_interface)
197
        window = gimp_plug_in_progress_get_window_id (plug_in);
198 199 200 201
    }
  else
    success = FALSE;

202 203
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
204 205

  if (success)
206
    g_value_set_int (gimp_value_array_index (return_vals, 1), window);
207

208
  return return_vals;
209 210
}

211
static GimpValueArray *
212
progress_install_invoker (GimpProcedure         *procedure,
213 214 215 216 217
                          Gimp                  *gimp,
                          GimpContext           *context,
                          GimpProgress          *progress,
                          const GimpValueArray  *args,
                          GError               **error)
218 219
{
  gboolean success = TRUE;
220
  const gchar *progress_callback;
221

222
  progress_callback = g_value_get_string (gimp_value_array_index (args, 0));
223 224 225

  if (success)
    {
226
      GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
227 228

      if (plug_in && plug_in->open)
229
        success = gimp_plug_in_progress_install (plug_in, progress_callback);
230 231 232 233
      else
        success = FALSE;
    }

234 235
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
236 237
}

238
static GimpValueArray *
239
progress_uninstall_invoker (GimpProcedure         *procedure,
240 241 242 243 244
                            Gimp                  *gimp,
                            GimpContext           *context,
                            GimpProgress          *progress,
                            const GimpValueArray  *args,
                            GError               **error)
245 246
{
  gboolean success = TRUE;
247
  const gchar *progress_callback;
248

249
  progress_callback = g_value_get_string (gimp_value_array_index (args, 0));
250 251 252

  if (success)
    {
253
      GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
254 255

      if (plug_in && plug_in->open)
256
        success = gimp_plug_in_progress_uninstall (plug_in, progress_callback);
257 258 259 260
      else
        success = FALSE;
    }

261 262
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
263 264
}

265
static GimpValueArray *
266
progress_cancel_invoker (GimpProcedure         *procedure,
267 268 269 270 271
                         Gimp                  *gimp,
                         GimpContext           *context,
                         GimpProgress          *progress,
                         const GimpValueArray  *args,
                         GError               **error)
272 273
{
  gboolean success = TRUE;
274
  const gchar *progress_callback;
275

276
  progress_callback = g_value_get_string (gimp_value_array_index (args, 0));
277 278 279

  if (success)
    {
280
      GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in;
281 282

      if (plug_in && plug_in->open)
283
        success = gimp_plug_in_progress_cancel (plug_in, progress_callback);
284 285 286 287
      else
        success = FALSE;
    }

288 289
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
290 291
}

292
void
293
register_progress_procs (GimpPDB *pdb)
294
{
295 296 297 298 299
  GimpProcedure *procedure;

  /*
   * gimp-progress-init
   */
300
  procedure = gimp_procedure_new (progress_init_invoker);
301 302
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-progress-init");
303 304 305 306 307 308 309 310 311 312 313 314
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-progress-init",
                                     "Initializes the progress bar for the current plug-in.",
                                     "Initializes the progress bar for the current plug-in. It is only valid to call this procedure from a plug-in.",
                                     "Spencer Kimball & Peter Mattis",
                                     "Spencer Kimball & Peter Mattis",
                                     "1995-1996",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("message",
                                                       "message",
                                                       "Message to use in the progress dialog",
315
                                                       FALSE, TRUE, FALSE,
316 317 318 319 320
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_display_id ("gdisplay",
                                                           "gdisplay",
321
                                                           "GimpDisplay to update progressbar in, or -1 for a separate window",
322 323
                                                           pdb->gimp, TRUE,
                                                           GIMP_PARAM_READWRITE));
324
  gimp_pdb_register_procedure (pdb, procedure);
325
  g_object_unref (procedure);
326 327 328 329

  /*
   * gimp-progress-update
   */
330
  procedure = gimp_procedure_new (progress_update_invoker);
331 332
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-progress-update");
333 334 335 336 337 338 339 340 341 342 343 344 345 346
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-progress-update",
                                     "Updates the progress bar for the current plug-in.",
                                     "Updates the progress bar for the current plug-in. It is only valid to call this procedure from a plug-in.",
                                     "Spencer Kimball & Peter Mattis",
                                     "Spencer Kimball & Peter Mattis",
                                     "1995-1996",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               g_param_spec_double ("percentage",
                                                    "percentage",
                                                    "Percentage of progress completed which must be between 0.0 and 1.0",
                                                    -G_MAXDOUBLE, G_MAXDOUBLE, 0,
                                                    GIMP_PARAM_READWRITE));
347
  gimp_pdb_register_procedure (pdb, procedure);
348
  g_object_unref (procedure);
349 350 351 352

  /*
   * gimp-progress-pulse
   */
353
  procedure = gimp_procedure_new (progress_pulse_invoker);
354 355
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-progress-pulse");
356 357 358
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-progress-pulse",
                                     "Pulses the progress bar for the current plug-in.",
359
                                     "Updates the progress bar for the current plug-in. It is only valid to call this procedure from a plug-in. Use this function instead of 'gimp-progress-update' if you cannot tell how much progress has been made. This usually causes the the progress bar to enter \"activity mode\", where a block bounces back and forth.",
360 361 362 363
                                     "Sven Neumann <sven@gimp.org>",
                                     "Sven Neumann",
                                     "2005",
                                     NULL);
364
  gimp_pdb_register_procedure (pdb, procedure);
365
  g_object_unref (procedure);
366 367 368 369

  /*
   * gimp-progress-set-text
   */
370
  procedure = gimp_procedure_new (progress_set_text_invoker);
371 372
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-progress-set-text");
373 374 375
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-progress-set-text",
                                     "Changes the text in the progress bar for the current plug-in.",
376
                                     "This function changes the text in the progress bar for the current plug-in. Unlike 'gimp-progress-init' it does not change the displayed value.",
377 378 379 380 381 382 383 384
                                     "Sven Neumann <sven@gimp.org>",
                                     "Sven Neumann",
                                     "2005",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("message",
                                                       "message",
                                                       "Message to use in the progress dialog",
385
                                                       FALSE, TRUE, FALSE,
386 387
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
388
  gimp_pdb_register_procedure (pdb, procedure);
389
  g_object_unref (procedure);
390

391 392 393 394
  /*
   * gimp-progress-end
   */
  procedure = gimp_procedure_new (progress_end_invoker);
395 396
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-progress-end");
397 398 399 400 401 402 403 404 405 406 407
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-progress-end",
                                     "Ends the progress bar for the current plug-in.",
                                     "Ends the progress display for the current plug-in. Most plug-ins don't need to call this, they just exit when the work is done. It is only valid to call this procedure from a plug-in.",
                                     "Sven Neumann <sven@gimp.org>",
                                     "Sven Neumann",
                                     "2007",
                                     NULL);
  gimp_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

408 409 410
  /*
   * gimp-progress-get-window-handle
   */
411
  procedure = gimp_procedure_new (progress_get_window_handle_invoker);
412 413
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-progress-get-window-handle");
414 415 416 417 418 419 420 421 422 423 424 425 426 427
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-progress-get-window-handle",
                                     "Returns the native window ID of the toplevel window this plug-in's progress is displayed in.",
                                     "This function returns the native window ID of the toplevel window this plug-in\'s progress is displayed in.",
                                     "Michael Natterer <mitch@gimp.org>",
                                     "Michael Natterer",
                                     "2004",
                                     NULL);
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_int32 ("window",
                                                          "window",
                                                          "The progress bar's toplevel window",
                                                          G_MININT32, G_MAXINT32, 0,
                                                          GIMP_PARAM_READWRITE));
428
  gimp_pdb_register_procedure (pdb, procedure);
429
  g_object_unref (procedure);
430 431 432 433

  /*
   * gimp-progress-install
   */
434
  procedure = gimp_procedure_new (progress_install_invoker);
435 436
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-progress-install");
437 438 439 440 441 442 443 444 445 446 447 448
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-progress-install",
                                     "Installs a progress callback for the current plug-in.",
                                     "This function installs a temporary PDB procedure which will handle all progress calls made by this plug-in and any procedure it calls. Calling this function multiple times simply replaces the old progress callbacks.",
                                     "Michael Natterer <mitch@gimp.org>",
                                     "Michael Natterer",
                                     "2004",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("progress-callback",
                                                       "progress callback",
                                                       "The callback PDB proc to call",
449
                                                       FALSE, FALSE, TRUE,
450 451
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
452
  gimp_pdb_register_procedure (pdb, procedure);
453
  g_object_unref (procedure);
454 455 456 457

  /*
   * gimp-progress-uninstall
   */
458
  procedure = gimp_procedure_new (progress_uninstall_invoker);
459 460
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-progress-uninstall");
461 462 463
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-progress-uninstall",
                                     "Uninstalls the progress callback for the current plug-in.",
464
                                     "This function uninstalls any progress callback installed with 'gimp-progress-install' before.",
465 466 467 468 469 470 471 472
                                     "Michael Natterer <mitch@gimp.org>",
                                     "Michael Natterer",
                                     "2004",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("progress-callback",
                                                       "progress callback",
                                                       "The name of the callback registered for this progress",
473
                                                       FALSE, FALSE, TRUE,
474 475
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
476
  gimp_pdb_register_procedure (pdb, procedure);
477
  g_object_unref (procedure);
478 479 480 481

  /*
   * gimp-progress-cancel
   */
482
  procedure = gimp_procedure_new (progress_cancel_invoker);
483 484
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-progress-cancel");
485 486 487 488 489 490 491 492 493 494 495 496
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-progress-cancel",
                                     "Cancels a running progress.",
                                     "This function cancels the currently running progress.",
                                     "Michael Natterer <mitch@gimp.org>",
                                     "Michael Natterer",
                                     "2004",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("progress-callback",
                                                       "progress callback",
                                                       "The name of the callback registered for this progress",
497
                                                       FALSE, FALSE, TRUE,
498 499
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
500
  gimp_pdb_register_procedure (pdb, procedure);
501
  g_object_unref (procedure);
502
}