/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
#include <gtk/gtk.h>
#include "eggassistant.h"
#include "eggassistantpage.h"

static void
on_title_change (GtkCheckButton *button, EggAssistantPage *page)
{
  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
    egg_assistant_page_set_title (page, "This is a title");
  else
    egg_assistant_page_set_title (page, NULL);
}

static void
on_icon_change (GtkCheckButton *button, EggAssistantPage *page)
{
  GdkPixbuf *pixbuf;

  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
    {
      pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_new (),
					 GTK_STOCK_OPEN,
					 48, 0, NULL);
      egg_assistant_page_set_header_image (page, pixbuf);
      g_object_unref (pixbuf);
    }
  else
    egg_assistant_page_set_header_image (page, NULL);
}

static void
on_watermark_change (GtkCheckButton *button, EggAssistantPage *page)
{
  GdkPixbuf *pixbuf;

  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
    {
      pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_new (),
					 GTK_STOCK_OPEN,
					 48, 0, NULL);
      egg_assistant_page_set_watermark (page, pixbuf);
      g_object_unref (pixbuf);
    }
  else
    egg_assistant_page_set_watermark (page, NULL);
}

static GtkWidget*
create_page (GtkWidget *other_page)
{
  GtkWidget *ref, *page, *box, *check;
  gchar *str;

  page = egg_assistant_page_new ("FU", NULL, NULL);
  box = gtk_vbox_new (FALSE, 12);

  ref = (other_page) ? other_page : page;

  check = gtk_check_button_new_with_label ("Header image");
  gtk_box_pack_start (GTK_BOX (box), check, FALSE, FALSE, 0);
  g_signal_connect (G_OBJECT (check), "toggled", G_CALLBACK (on_icon_change), ref);

  check = gtk_check_button_new_with_label ("Watermark");
  gtk_box_pack_start (GTK_BOX (box), check, FALSE, FALSE, 0);
  g_signal_connect (G_OBJECT (check), "toggled", G_CALLBACK (on_watermark_change), ref);

  check = gtk_check_button_new_with_label ("Title");
  gtk_box_pack_start (GTK_BOX (box), check, FALSE, FALSE, 0);
  g_signal_connect (G_OBJECT (check), "toggled", G_CALLBACK (on_title_change), ref);

  gtk_container_add (GTK_CONTAINER (page), box);

  return page;
}

gint
forward (gint n, gpointer data)
{
  g_print ("moving from page %i to page %i\n", n, n + 1);

  return ++n;
}

int
main (int argc, char *argv[])
{
  GtkWidget *assistant, *page;

  gtk_init (&argc, &argv);

  assistant = egg_assistant_new (NULL);

  /* create pages */
  page = create_page (NULL);
  gtk_widget_show_all (page);
  egg_assistant_append_page (EGG_ASSISTANT (assistant),
			     EGG_ASSISTANT_PAGE (page));

  page = create_page (NULL);
  gtk_widget_show_all (page);
  egg_assistant_prepend_page (EGG_ASSISTANT (assistant),
			      EGG_ASSISTANT_PAGE (page));

  page = create_page (NULL);
  gtk_widget_show_all (page);
  egg_assistant_insert_page (EGG_ASSISTANT (assistant),
			     EGG_ASSISTANT_PAGE (page), 1);

  egg_assistant_set_forward_page_func (EGG_ASSISTANT (assistant), forward, NULL);
  egg_assistant_set_buttons_sensitive (EGG_ASSISTANT (assistant), TRUE, TRUE, TRUE);

  gtk_dialog_run (GTK_DIALOG (assistant));
  gtk_widget_destroy (assistant);

  return 0;
}
