/* 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 Spencer Kimball and Peter Mattis
 *
 * pikaopendialog.c
 * Copyright (C) 2015 Jehan <jehan@girinstud.io>
 *
 * 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/>.
 */

#include "config.h"

#include <gegl.h>
#include <gtk/gtk.h>

#include "libpikabase/pikabase.h"
#include "libpikawidgets/pikawidgets.h"

#include "widgets-types.h"

#include "core/pika.h"
#include "core/pikaimage.h"

#include "pikahelp-ids.h"
#include "pikaopendialog.h"

#include "pika-intl.h"


/*  local function prototypes  */

static void   pika_open_dialog_dispose (GObject *object);


G_DEFINE_TYPE (PikaOpenDialog, pika_open_dialog,
               PIKA_TYPE_FILE_DIALOG)

#define parent_class pika_open_dialog_parent_class


/*  private functions  */

static void
pika_open_dialog_class_init (PikaOpenDialogClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

  object_class->dispose = pika_open_dialog_dispose;
}

static void
pika_open_dialog_init (PikaOpenDialog *dialog)
{
}

static void
pika_open_dialog_dispose (GObject *object)
{
  pika_open_dialog_set_image (PIKA_OPEN_DIALOG (object), NULL, FALSE);

  G_OBJECT_CLASS (parent_class)->dispose (object);
}


/*  public functions  */

GtkWidget *
pika_open_dialog_new (Pika *pika)
{
  g_return_val_if_fail (PIKA_IS_PIKA (pika), NULL);

  return g_object_new (PIKA_TYPE_OPEN_DIALOG,
                       "pika",                  pika,
                       "title",                 _("Open Image"),
                       "role",                  "pika-file-open",
                       "help-id",               PIKA_HELP_FILE_OPEN,
                       "ok-button-label",       _("_Open"),

                       "automatic-label",       _("Automatically Detected"),
                       "automatic-help-id",     PIKA_HELP_FILE_OPEN_BY_EXTENSION,

                       "action",                GTK_FILE_CHOOSER_ACTION_OPEN,
                       "file-procs",            PIKA_FILE_PROCEDURE_GROUP_OPEN,
                       "file-procs-all-images", PIKA_FILE_PROCEDURE_GROUP_NONE,
                       "file-filter-label",     NULL,
                       NULL);
}

void
pika_open_dialog_set_image (PikaOpenDialog *dialog,
                            PikaImage      *image,
                            gboolean        open_as_layers)
{
  PikaFileDialog *file_dialog;

  g_return_if_fail (PIKA_IS_OPEN_DIALOG (dialog));
  g_return_if_fail (image == NULL || PIKA_IS_IMAGE (image));

  file_dialog = PIKA_FILE_DIALOG (dialog);

  g_set_weak_pointer (&file_dialog->image, image);

  dialog->open_as_layers = open_as_layers;
}
