/* PIKA - Photo and Image Kooker Application
 * a rebranding of The GNU Image Manipulation Program (created with heckimp)
 * A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
 *
 * Original copyright, applying to most contents (license remains unchanged): 
 * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
 *
 * 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 3 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, see <https://www.gnu.org/licenses/>.
 */

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

#include "config.h"

#include "stamp-pdbgen.h"

#include <gegl.h>

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

#include "libpikabase/pikabase.h"

#include "pdb-types.h"

#include "core/pika.h"
#include "core/pikaimage-undo.h"
#include "core/pikaimage.h"
#include "core/pikaparamspecs.h"
#include "plug-in/pikaplugin-cleanup.h"
#include "plug-in/pikaplugin.h"
#include "plug-in/pikapluginmanager.h"

#include "pikapdb.h"
#include "pikaprocedure.h"
#include "internal-procs.h"


static PikaValueArray *
image_undo_group_start_invoker (PikaProcedure         *procedure,
                                Pika                  *pika,
                                PikaContext           *context,
                                PikaProgress          *progress,
                                const PikaValueArray  *args,
                                GError               **error)
{
  gboolean success = TRUE;
  PikaImage *image;

  image = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      PikaPlugIn  *plug_in   = pika->plug_in_manager->current_plug_in;
      const gchar *undo_desc = NULL;

      if (plug_in)
        {
          success = pika_plug_in_cleanup_undo_group_start (plug_in, image);

          if (success)
            undo_desc = pika_plug_in_get_undo_desc (plug_in);
        }

      if (success)
        pika_image_undo_group_start (image, PIKA_UNDO_GROUP_MISC, undo_desc);
    }

  return pika_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

static PikaValueArray *
image_undo_group_end_invoker (PikaProcedure         *procedure,
                              Pika                  *pika,
                              PikaContext           *context,
                              PikaProgress          *progress,
                              const PikaValueArray  *args,
                              GError               **error)
{
  gboolean success = TRUE;
  PikaImage *image;

  image = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      PikaPlugIn *plug_in = pika->plug_in_manager->current_plug_in;

      if (plug_in)
        success = pika_plug_in_cleanup_undo_group_end (plug_in, image);

      if (success)
        pika_image_undo_group_end (image);
    }

  return pika_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
}

static PikaValueArray *
image_undo_is_enabled_invoker (PikaProcedure         *procedure,
                               Pika                  *pika,
                               PikaContext           *context,
                               PikaProgress          *progress,
                               const PikaValueArray  *args,
                               GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaImage *image;
  gboolean enabled = FALSE;

  image = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
      enabled = pika_image_undo_is_enabled (image);
    }

  return_vals = pika_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    g_value_set_boolean (pika_value_array_index (return_vals, 1), enabled);

  return return_vals;
}

static PikaValueArray *
image_undo_disable_invoker (PikaProcedure         *procedure,
                            Pika                  *pika,
                            PikaContext           *context,
                            PikaProgress          *progress,
                            const PikaValueArray  *args,
                            GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaImage *image;
  gboolean disabled = FALSE;

  image = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
    #if 0
      PikaPlugIn *plug_in = pika->plug_in_manager->current_plug_in;

      if (plug_in)
        success = pika_plug_in_cleanup_undo_disable (plug_in, image);
    #endif

      if (success)
        disabled = pika_image_undo_disable (image);
    }

  return_vals = pika_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    g_value_set_boolean (pika_value_array_index (return_vals, 1), disabled);

  return return_vals;
}

static PikaValueArray *
image_undo_enable_invoker (PikaProcedure         *procedure,
                           Pika                  *pika,
                           PikaContext           *context,
                           PikaProgress          *progress,
                           const PikaValueArray  *args,
                           GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaImage *image;
  gboolean enabled = FALSE;

  image = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
    #if 0
      PikaPlugIn *plug_in = pika->plug_in_manager->current_plug_in;

      if (plug_in)
        success = pika_plug_in_cleanup_undo_enable (plug_in, image);
    #endif

      if (success)
        enabled = pika_image_undo_enable (image);
    }

  return_vals = pika_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    g_value_set_boolean (pika_value_array_index (return_vals, 1), enabled);

  return return_vals;
}

static PikaValueArray *
image_undo_freeze_invoker (PikaProcedure         *procedure,
                           Pika                  *pika,
                           PikaContext           *context,
                           PikaProgress          *progress,
                           const PikaValueArray  *args,
                           GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaImage *image;
  gboolean frozen = FALSE;

  image = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
    #if 0
      PikaPlugIn *plug_in = pika->plug_in_manager->current_plug_in;

      if (plug_in)
        success = pika_plug_in_cleanup_undo_freeze (plug_in, image);
    #endif

      if (success)
        frozen = pika_image_undo_freeze (image);
    }

  return_vals = pika_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    g_value_set_boolean (pika_value_array_index (return_vals, 1), frozen);

  return return_vals;
}

static PikaValueArray *
image_undo_thaw_invoker (PikaProcedure         *procedure,
                         Pika                  *pika,
                         PikaContext           *context,
                         PikaProgress          *progress,
                         const PikaValueArray  *args,
                         GError               **error)
{
  gboolean success = TRUE;
  PikaValueArray *return_vals;
  PikaImage *image;
  gboolean thawed = FALSE;

  image = g_value_get_object (pika_value_array_index (args, 0));

  if (success)
    {
    #if 0
      PikaPlugIn *plug_in = pika->plug_in_manager->current_plug_in;

      if (plug_in)
        success = pika_plug_in_cleanup_undo_thaw (plug_in, image);
    #endif

      if (success)
        thawed = pika_image_undo_thaw (image);
    }

  return_vals = pika_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);

  if (success)
    g_value_set_boolean (pika_value_array_index (return_vals, 1), thawed);

  return return_vals;
}

void
register_image_undo_procs (PikaPDB *pdb)
{
  PikaProcedure *procedure;

  /*
   * pika-image-undo-group-start
   */
  procedure = pika_procedure_new (image_undo_group_start_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-image-undo-group-start");
  pika_procedure_set_static_help (procedure,
                                  "Starts a group undo.",
                                  "This function is used to start a group undo--necessary for logically combining two or more undo operations into a single operation. This call must be used in conjunction with a 'pika-image-undo-group-end' call.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1997");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("image",
                                                      "image",
                                                      "The ID of the image in which to open an undo group",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-image-undo-group-end
   */
  procedure = pika_procedure_new (image_undo_group_end_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-image-undo-group-end");
  pika_procedure_set_static_help (procedure,
                                  "Finish a group undo.",
                                  "This function must be called once for each 'pika-image-undo-group-start' call that is made.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1997");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("image",
                                                      "image",
                                                      "The ID of the image in which to close an undo group",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-image-undo-is-enabled
   */
  procedure = pika_procedure_new (image_undo_is_enabled_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-image-undo-is-enabled");
  pika_procedure_set_static_help (procedure,
                                  "Check if the image's undo stack is enabled.",
                                  "This procedure checks if the image's undo stack is currently enabled or disabled. This is useful when several plug-ins or scripts call each other and want to check if their caller has already used 'pika-image-undo-disable' or 'pika-image-undo-freeze'.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Rapha\xc3\xabl Quinet <raphael@gimp.org>",
                                         "Rapha\xc3\xabl Quinet",
                                         "1999");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("image",
                                                      "image",
                                                      "The image",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_boolean ("enabled",
                                                         "enabled",
                                                         "TRUE if undo is enabled for this image",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-image-undo-disable
   */
  procedure = pika_procedure_new (image_undo_disable_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-image-undo-disable");
  pika_procedure_set_static_help (procedure,
                                  "Disable the image's undo stack.",
                                  "This procedure disables the image's undo stack, allowing subsequent operations to ignore their undo steps. This is generally called in conjunction with 'pika-image-undo-enable' to temporarily disable an image undo stack. This is advantageous because saving undo steps can be time and memory intensive.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("image",
                                                      "image",
                                                      "The image",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_boolean ("disabled",
                                                         "disabled",
                                                         "TRUE if the image undo has been disabled",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-image-undo-enable
   */
  procedure = pika_procedure_new (image_undo_enable_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-image-undo-enable");
  pika_procedure_set_static_help (procedure,
                                  "Enable the image's undo stack.",
                                  "This procedure enables the image's undo stack, allowing subsequent operations to store their undo steps. This is generally called in conjunction with 'pika-image-undo-disable' to temporarily disable an image undo stack.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Spencer Kimball & Peter Mattis",
                                         "Spencer Kimball & Peter Mattis",
                                         "1995-1996");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("image",
                                                      "image",
                                                      "The image",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_boolean ("enabled",
                                                         "enabled",
                                                         "TRUE if the image undo has been enabled",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-image-undo-freeze
   */
  procedure = pika_procedure_new (image_undo_freeze_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-image-undo-freeze");
  pika_procedure_set_static_help (procedure,
                                  "Freeze the image's undo stack.",
                                  "This procedure freezes the image's undo stack, allowing subsequent operations to ignore their undo steps. This is generally called in conjunction with 'pika-image-undo-thaw' to temporarily disable an image undo stack. This is advantageous because saving undo steps can be time and memory intensive. 'pika-image-undo-freeze' / 'pika-image-undo-thaw' and 'pika-image-undo-disable' / 'pika-image-undo-enable' differ in that the former does not free up all undo steps when undo is thawed, so is more suited to interactive in-situ previews. It is important in this case that the image is back to the same state it was frozen in before thawing, else 'undo' behavior is undefined.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Adam D. Moss",
                                         "Adam D. Moss",
                                         "1999");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("image",
                                                      "image",
                                                      "The image",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_boolean ("frozen",
                                                         "frozen",
                                                         "TRUE if the image undo has been frozen",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);

  /*
   * pika-image-undo-thaw
   */
  procedure = pika_procedure_new (image_undo_thaw_invoker);
  pika_object_set_static_name (PIKA_OBJECT (procedure),
                               "pika-image-undo-thaw");
  pika_procedure_set_static_help (procedure,
                                  "Thaw the image's undo stack.",
                                  "This procedure thaws the image's undo stack, allowing subsequent operations to store their undo steps. This is generally called in conjunction with 'pika-image-undo-freeze' to temporarily freeze an image undo stack. 'pika-image-undo-thaw' does NOT free the undo stack as 'pika-image-undo-enable' does, so is suited for situations where one wishes to leave the undo stack in the same state in which one found it despite non-destructively playing with the image in the meantime. An example would be in-situ plug-in previews. Balancing freezes and thaws and ensuring image consistency is the responsibility of the caller.",
                                  NULL);
  pika_procedure_set_static_attribution (procedure,
                                         "Adam D. Moss",
                                         "Adam D. Moss",
                                         "1999");
  pika_procedure_add_argument (procedure,
                               pika_param_spec_image ("image",
                                                      "image",
                                                      "The image",
                                                      FALSE,
                                                      PIKA_PARAM_READWRITE));
  pika_procedure_add_return_value (procedure,
                                   g_param_spec_boolean ("thawed",
                                                         "thawed",
                                                         "TRUE if the image undo has been thawed",
                                                         FALSE,
                                                         PIKA_PARAM_READWRITE));
  pika_pdb_register_procedure (pdb, procedure);
  g_object_unref (procedure);
}
