/* 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
 *
 * PikaImageProfileView
 * Copyright (C) 2006  Sven Neumann <sven@gimp.org>
 *
 * 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 <string.h>

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

#include "libpikaconfig/pikaconfig.h"
#include "libpikacolor/pikacolor.h"
#include "libpikabase/pikabase.h"
#include "libpikawidgets/pikawidgets.h"

#include "widgets-types.h"

#include "core/pikaimage.h"
#include "core/pikaimage-color-profile.h"

#include "pikaimageprofileview.h"

#include "pika-intl.h"


static void   pika_image_profile_view_update (PikaImageParasiteView *view);


G_DEFINE_TYPE (PikaImageProfileView,
               pika_image_profile_view, PIKA_TYPE_IMAGE_PARASITE_VIEW)

#define parent_class pika_image_profile_view_parent_class


static void
pika_image_profile_view_class_init (PikaImageProfileViewClass *klass)
{
  PikaImageParasiteViewClass *view_class;

  view_class = PIKA_IMAGE_PARASITE_VIEW_CLASS (klass);

  view_class->update = pika_image_profile_view_update;
}

static void
pika_image_profile_view_init (PikaImageProfileView *view)
{
  GtkWidget *scrolled_window;
  GtkWidget *profile_view;

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                  GTK_POLICY_AUTOMATIC,
                                  GTK_POLICY_AUTOMATIC);
  gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 2);
  gtk_box_pack_start (GTK_BOX (view), scrolled_window, TRUE, TRUE, 0);
  gtk_widget_show (scrolled_window);

  profile_view = pika_color_profile_view_new ();
  gtk_container_add (GTK_CONTAINER (scrolled_window), profile_view);
  gtk_widget_show (profile_view);

  view->profile_view = PIKA_COLOR_PROFILE_VIEW (profile_view);
}


/*  public functions  */

GtkWidget *
pika_image_profile_view_new (PikaImage *image)
{
  g_return_val_if_fail (PIKA_IS_IMAGE (image), NULL);

  return g_object_new (PIKA_TYPE_IMAGE_PROFILE_VIEW,
                       "image",    image,
                       "parasite", PIKA_ICC_PROFILE_PARASITE_NAME,
                       NULL);
}


/*  private functions  */

static void
pika_image_profile_view_update (PikaImageParasiteView *view)
{
  PikaImageProfileView *profile_view = PIKA_IMAGE_PROFILE_VIEW (view);
  PikaImage            *image;
  PikaColorManaged     *managed;
  PikaColorProfile     *profile;

  image   = pika_image_parasite_view_get_image (view);
  managed = PIKA_COLOR_MANAGED (image);

  profile = pika_color_managed_get_color_profile (managed);

  pika_color_profile_view_set_profile (profile_view->profile_view, profile);
}
