/*****************************************************************************/

/*
 *      dvdoptionswin.c -- REALmagic simple windowing application in GTK
 *
 *      Copyright (C) 2001 Sigma Designs
 *                    written by Pascal Cannenterre <pascal_cannenterre@sdesigns.com>
 *
 *      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 2 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, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*****************************************************************************/
#include "define.h"
#include "gtk_callbacks.h"
#include "interface.h"

/* include pixmaps */
#include "../pixmaps/REALmagic.xpm"
#include "../pixmaps/logo.xpm"


GtkItemFactoryEntry *menu_items_language = NULL;
GtkItemFactoryEntry *menu_items_subpicture = NULL;
static LanguageCodeStr lcstr[] = {
  { RM_LANGUAGECODE_ENGLISH, "/English" },
  { RM_LANGUAGECODE_FRENCH, "/French" },
  { RM_LANGUAGECODE_SPANISH, "/Spanish" },
  { RM_LANGUAGECODE_ITALIAN, "/Italian" },
  { RM_LANGUAGECODE_GERMAN, "/German" },
  { RM_LANGUAGECODE_DUTCH, "/Dutch" },
  { RM_LANGUAGECODE_PORTUGUESE, "/Portuguese" },
  { RM_LANGUAGECODE_CHINESE, "/Chinese" },
  { RM_LANGUAGECODE_JAPANESE, "/Japanese" },
  { RM_LANGUAGECODE_KOREAN, "/Korean" },
  { RM_LANGUAGECODE_VIETNAMESE, "/Vietnamese" },
  { RM_LANGUAGECODE_ORIGINAL, "/Original" },
  { RM_LANGUAGECODE_OTHERS,"/Others" },
  { RM_LANGUAGECODE_AUDIOFOLLOW,"/Audiofollow" },
};

static gchar * AudioCoding[] = {
  "Dolby Digital",
  NULL,
  "MPEG-1",
  "MPEG-2",
  "Digital",
  NULL,
  "DTS",
  "SDDS"
};

static gchar * AudioChannel[] = {
  "Mono",
  "Stereo 2.0",
  NULL,
  NULL,
  NULL,
  "5.1",
  NULL, 
  NULL,
};

gchar *languageCodeToStr(WORD code)
{
  guint i;
  guint tab_size = sizeof(lcstr) / sizeof(lcstr[0]); 

  for(i=0;i<tab_size;i++)
    {
      if(code == lcstr[i].code)
	return (lcstr[i].str);
    }
  return "/Unknown language";
}

GtkWidget * create_Langage_frame(void)
{
  GtkWidget *frame;
  GtkWidget *table;
  GtkItemFactory *item_factory1, *item_factory2;
  GtkWidget *label1, *label2;
  GtkWidget *menu_audio_language;
  GtkWidget *menu_sp_language;
  guint i, nmenu_items_language;
  gint nmenu_items_sp;

  frame = gtk_frame_new(NULL);
  gtk_frame_set_label( GTK_FRAME(frame), "Languages" );
  gtk_frame_set_label_align( GTK_FRAME(frame), 0.5, 0.0); 
  gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_ETCHED_OUT);

  table = gtk_table_new (2, 2, FALSE);
  gtk_widget_show (table);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_container_set_border_width (GTK_CONTAINER (table), 5);
  
  retrieveInfo_dvd(&Info);
  
  if(Info.bAudioStreamTotal != 0)
    {
      nmenu_items_language = Info.bAudioStreamTotal;
      menu_items_language = g_new(GtkItemFactoryEntry, nmenu_items_language);
      
      for(i=0;i<nmenu_items_language;i++)
	{
	  if( (Info.AudioStreamAvailable[i] == 1) && (Info.AudioStreamLangage[i] != 0) )
	    menu_items_language[i].path = 
	      g_strconcat(languageCodeToStr(Info.AudioStreamLangage[i]),
			  " ", AudioCoding[(Info.AudioStreamCodingMode[i])],
			  " ", AudioChannel[(Info.AudioStreamChannel[i])], 
			  NULL);
	  else
	    menu_items_language[i].path = "/Not Available"; 
	  
	  menu_items_language[i].accelerator = NULL;
	  menu_items_language[i].callback = audioStreamChange_cb;
	  menu_items_language[i].callback_action = i;
	  menu_items_language[i].item_type = NULL;
	}
    }
  else
    {
      nmenu_items_language = 1;
      menu_items_language = g_new(GtkItemFactoryEntry, nmenu_items_language);
      
      menu_items_language[0].path = "/Not Available";
      menu_items_language[0].accelerator = NULL;
      menu_items_language[0].callback = NULL;
      menu_items_language[0].callback_action = 0;
      menu_items_language[0].item_type = NULL; 
    }

  item_factory1 = gtk_item_factory_new (GTK_TYPE_OPTION_MENU, "<Audio>", 
				       NULL);
  gtk_item_factory_create_items (item_factory1, nmenu_items_language, menu_items_language, NULL);
  
  menu_audio_language = gtk_item_factory_get_widget (item_factory1, "<Audio>");
  
  gtk_widget_ref(menu_audio_language);
  gtk_object_set_data_full (GTK_OBJECT (frame), "menu_audio_language", menu_audio_language,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show(menu_audio_language);

  label1 = gtk_label_new( "Audio" );
  gtk_widget_show(label1);
  
  if(Info.bSPStreamTotal != 0)
    {
     nmenu_items_sp = Info.bSPStreamTotal+2;
     menu_items_subpicture = g_new(GtkItemFactoryEntry, nmenu_items_sp );
      
      for(i=0;i<Info.bSPStreamTotal;i++)
	{
	  if( (Info.SPStreamAvailable[i] == 1) && (Info.SPStreamLangage[i] != 0) )
	    menu_items_subpicture[i].path = languageCodeToStr(Info.SPStreamLangage[i]);
	  else
	    menu_items_subpicture[i].path = "/Not Available";
	  
	  menu_items_subpicture[i].accelerator = NULL;
	  menu_items_subpicture[i].callback = spStreamChange_cb;
	  menu_items_subpicture[i].callback_action = i;
	  menu_items_subpicture[i].item_type = NULL;
	}
      i = Info.bSPStreamTotal;
      menu_items_subpicture[i].path = "/Audio Follow";
      menu_items_subpicture[i].accelerator = NULL;
      menu_items_subpicture[i].callback = spStreamChange_cb;
      menu_items_subpicture[i].callback_action = RM_LANGUAGECODE_AUDIOFOLLOW;
      menu_items_subpicture[i].item_type = NULL;
      i++;
      menu_items_subpicture[i].path = "/None";
      menu_items_subpicture[i].accelerator = NULL;
      menu_items_subpicture[i].callback = spStreamChange_cb;
      menu_items_subpicture[i].callback_action = SUBTITLEOFF;
      menu_items_subpicture[i].item_type = NULL;
      
    }
  else
    {
      nmenu_items_sp = 1;
      menu_items_subpicture = g_new(GtkItemFactoryEntry, nmenu_items_sp);
      
      menu_items_subpicture[0].path = "/Not Available";
      menu_items_subpicture[0].accelerator = NULL;
      menu_items_subpicture[0].callback = NULL;
      menu_items_subpicture[0].callback_action = 0;
      menu_items_subpicture[0].item_type = NULL; 
    }

  item_factory2 = gtk_item_factory_new (GTK_TYPE_OPTION_MENU, "<Subtitles>", 
					NULL);
  
  gtk_item_factory_create_items (item_factory2, nmenu_items_sp, menu_items_subpicture, NULL);
  
  menu_sp_language = gtk_item_factory_get_widget (item_factory2, "<Subtitles>");

  gtk_widget_ref(menu_sp_language);
  gtk_object_set_data_full (GTK_OBJECT (frame), "menu_sp_language", menu_sp_language,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show(menu_sp_language);

  label2 = gtk_label_new( "Subtitles" );
  gtk_widget_show(label2);
  
  gtk_table_attach (GTK_TABLE (table), label1, 0, 1, 1, 2,
		    (GtkAttachOptions) (GTK_FILL),
		    (GtkAttachOptions) (GTK_FILL), 0, 0);
  
  gtk_table_attach (GTK_TABLE (table), label2, 1, 2, 1, 2,
		    (GtkAttachOptions) (GTK_FILL),
		    (GtkAttachOptions) (GTK_FILL), 0, 0);

  gtk_table_attach (GTK_TABLE (table), menu_audio_language, 0, 1, 0, 1,
		    (GtkAttachOptions) (GTK_EXPAND|GTK_FILL|GTK_SHRINK),
		    (GtkAttachOptions) (GTK_FILL), 0, 0);
  
  gtk_table_attach (GTK_TABLE (table), menu_sp_language, 1, 2, 0, 1,
		    (GtkAttachOptions) (GTK_EXPAND|GTK_FILL|GTK_SHRINK),
		    (GtkAttachOptions) (GTK_FILL), 0, 0);

  
  
  return frame;
}

GtkWidget * create_dvd_content_frame(void)
{
  GtkWidget *frame;
  GtkWidget *table;
  GtkWidget *language_frame;
  
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_NONE);
  
  table = gtk_table_new (1, 1, FALSE);
  gtk_widget_show (table);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_container_set_border_width (GTK_CONTAINER (table), 0);  
  
  language_frame = create_Langage_frame();
  gtk_widget_ref (language_frame);
  gtk_object_set_data_full (GTK_OBJECT (frame), "language_frame", language_frame,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (language_frame);
  gtk_table_attach (GTK_TABLE (table), language_frame, 0, 1, 0, 1,
		    GTK_FILL|GTK_EXPAND|GTK_SHRINK,
		    GTK_FILL, 5, 5);
  GTK_WIDGET_UNSET_FLAGS (language_frame, GTK_CAN_FOCUS);
  

  return frame;
}

static GtkRadioFrameEntry dvdregion_entry[] = {
  {"Region 1", "radioREGION1",
   GTK_SIGNAL_FUNC (switch_dvdregion_cb),
   GUINT_TO_POINTER(1)},
  {"Region 2", "radioREGION2",
   GTK_SIGNAL_FUNC (switch_dvdregion_cb),
   GUINT_TO_POINTER(2)},
  {"Region 3", "radioREGION3",
   GTK_SIGNAL_FUNC (switch_dvdregion_cb),
   GUINT_TO_POINTER(3)},
  {"Region 4", "radioREGION4",
   GTK_SIGNAL_FUNC (switch_dvdregion_cb),
   GUINT_TO_POINTER(4)},
  {"Region 5", "radioREGION5",
   GTK_SIGNAL_FUNC (switch_dvdregion_cb),
   GUINT_TO_POINTER(5)},
  {"Region 6", "radioREGION6",
   GTK_SIGNAL_FUNC (switch_dvdregion_cb),
   GUINT_TO_POINTER(6)},
};

static GtkRadioFrameEntry dvdpglevel_entry[] = {
  {"Unlimited", "radioUNLIMITED",
   GTK_SIGNAL_FUNC (switch_dvdpglevel_cb),
   GINT_TO_POINTER(-1)},
  {"G", "radioG",
   GTK_SIGNAL_FUNC (switch_dvdpglevel_cb),
   GINT_TO_POINTER(0)},
  {"Level 2", "radioLEVEL2",
   GTK_SIGNAL_FUNC (switch_dvdpglevel_cb),
   GINT_TO_POINTER(1)},
  {"PG", "radioPG",
   GTK_SIGNAL_FUNC (switch_dvdpglevel_cb),
   GINT_TO_POINTER(2)},
  {"PG-13", "radioPG13",
   GTK_SIGNAL_FUNC (switch_dvdpglevel_cb),
   GINT_TO_POINTER(3)},
  {"Level 5", "radioLEVEL5",
   GTK_SIGNAL_FUNC (switch_dvdpglevel_cb),
   GINT_TO_POINTER(4)},
  {"R", "radioR",
   GTK_SIGNAL_FUNC (switch_dvdpglevel_cb),
   GINT_TO_POINTER(5)},
  {"NC-17", "radioNC17",
   GTK_SIGNAL_FUNC (switch_dvdpglevel_cb),
   GINT_TO_POINTER(6)},
  {"Level 8", "radioLEVEL8",
   GTK_SIGNAL_FUNC (switch_dvdpglevel_cb),
   GINT_TO_POINTER(7)},
};

static GtkRadioFrameEntry aspect_4_3_entry[] = {
  {"Normal", "radioNORMAL",
   GTK_SIGNAL_FUNC (switch_aspect_mode_cb),
   GUINT_TO_POINTER(FMPV_VIDEOASPECT_4x3_4x3_NORMAL)},
  {"Zoom Off", "radioZOOMOFF",
   GTK_SIGNAL_FUNC (switch_aspect_mode_cb),
   GUINT_TO_POINTER(FMPV_VIDEOASPECT_4x3_16x9_ZOOM_OFF)},
  {"Zoom On", "radioZOOMON",
   GTK_SIGNAL_FUNC (switch_aspect_mode_cb),
   GUINT_TO_POINTER(FMPV_VIDEOASPECT_4x3_16x9_ZOOM_ON)},
};

static GtkRadioFrameEntry aspect_16_9_entry[] = {
  {"Wide", "radioWIDE",
   GTK_SIGNAL_FUNC (switch_aspect_mode_cb),
   GUINT_TO_POINTER(FMPV_VIDEOASPECT_16x9_16x9_NORMAL)},
  {"Letterbox", "radioLETTERBOX",
   GTK_SIGNAL_FUNC (switch_aspect_mode_cb),
   GUINT_TO_POINTER(FMPV_VIDEOASPECT_16x9_4x3_LETTERBOX)},
  {"Pan & Scan", "radioPANSCAN",
   GTK_SIGNAL_FUNC (switch_aspect_mode_cb),
   GUINT_TO_POINTER(FMPV_VIDEOASPECT_16x9_4x3_PANSCAN)},
};

/* static GtkRadioFrameEntry tv_format_entry[] = { */
/*   {"4:3", "radio4x3", */
/*    GTK_SIGNAL_FUNC (switch_tv_format_cb), */
/*    GUINT_TO_POINTER(TV_4x3)}, */
/*   {"16:9", "radio16x9", */
/*    GTK_SIGNAL_FUNC (switch_tv_format_cb), */
/*    GUINT_TO_POINTER(TV_16x9)}, */
/* }; */

GtkWidget * create_aspect_ratio_frame(void)
{
  GtkWidget *frame;
  GtkWidget *table;
  GtkWidget *aspect_4_3_frame, *aspect_16_9_frame;
  
  frame = gtk_frame_new(NULL);
  gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_NONE);

  table = gtk_table_new (2, 1, FALSE);
  gtk_widget_show (table);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_container_set_border_width (GTK_CONTAINER (table), 0);

  aspect_4_3_frame = create_radio_frame(3, aspect_4_3_entry, 
					"Ratio is 4:3", FALSE);
  gtk_widget_ref (aspect_4_3_frame);
  gtk_object_set_data_full (GTK_OBJECT (frame), "aspect_4_3_frame", aspect_4_3_frame,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (aspect_4_3_frame);
  gtk_table_attach (GTK_TABLE (table), aspect_4_3_frame, 0, 1, 0, 1,
		    GTK_FILL|GTK_EXPAND|GTK_SHRINK,
		    GTK_FILL, 0, 0);
  GTK_WIDGET_UNSET_FLAGS (aspect_4_3_frame, GTK_CAN_FOCUS);
  
  aspect_16_9_frame = create_radio_frame(3, aspect_16_9_entry, 
					 "Ratio is 16:9", FALSE);
  gtk_widget_ref (aspect_16_9_frame);
  gtk_object_set_data_full (GTK_OBJECT (frame), "aspect_16_9_frame", aspect_16_9_frame,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (aspect_16_9_frame);
  gtk_table_attach (GTK_TABLE (table), aspect_16_9_frame, 0, 1, 1, 2,
		    GTK_FILL|GTK_EXPAND|GTK_SHRINK,
		    GTK_FILL, 0, 0);
  GTK_WIDGET_UNSET_FLAGS (aspect_4_3_frame, GTK_CAN_FOCUS);
  

  return frame;
}

GtkWidget * create_pglevel_frame(void)
{
  GtkWidget *frame;
  GtkWidget *table;
  GtkWidget *label_passwd;
  GtkWidget *entry_passwd, *button_enter;
  GtkWidget *pglevel_frame;
  
  frame = gtk_frame_new(NULL);
  // gtk_frame_set_label( GTK_FRAME(frame), "Parental Level Change" );
  // gtk_frame_set_label_align( GTK_FRAME(frame), 0.5, 0.0); 
  gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_NONE);

  table = gtk_table_new (2, 3, FALSE);
  gtk_widget_show (table);
  gtk_container_add (GTK_CONTAINER (frame), table);
  gtk_container_set_border_width (GTK_CONTAINER (table), 0);
  
  label_passwd = gtk_label_new ("Password:");
  gtk_label_set_justify (GTK_LABEL (label_passwd), 
			 GTK_JUSTIFY_CENTER);
  gtk_table_attach (GTK_TABLE (table), label_passwd, 0, 1, 0, 1,
		    GTK_FILL,
		    GTK_FILL, 0, 0); 
  gtk_widget_show(label_passwd);

  entry_passwd = gtk_entry_new();
  gtk_entry_set_max_length(GTK_ENTRY(entry_passwd),DVD_PGLEVEL_PASSWD_MAX_LENGTH);
  gtk_widget_ref(entry_passwd);
  gtk_object_set_data_full (GTK_OBJECT (frame), "entry_passwd", entry_passwd,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_entry_set_editable(GTK_ENTRY(entry_passwd),TRUE); 
  
  gtk_table_attach (GTK_TABLE (table), entry_passwd, 1, 2, 0, 1,
		    GTK_FILL|GTK_EXPAND|GTK_SHRINK,
		    GTK_FILL, 2, 0);
  gtk_widget_show(entry_passwd);
  
  button_enter = gtk_button_new_with_label("Enter");
  gtk_widget_ref (button_enter);
  gtk_object_set_data_full (GTK_OBJECT (frame), "button_enter", button_enter,
			    (GtkDestroyNotify) gtk_widget_unref);
  
  gtk_table_attach (GTK_TABLE (table), button_enter, 2, 3, 0, 1,
		    GTK_FILL,
		    GTK_FILL, 0, 0);
  gtk_widget_show (button_enter);
  
  pglevel_frame =  create_radio_frame(9, dvdpglevel_entry, 
				      NULL, TRUE);
  gtk_widget_ref(pglevel_frame);
  gtk_object_set_data_full (GTK_OBJECT (frame), "pglevel_frame", pglevel_frame,
			    (GtkDestroyNotify) gtk_widget_unref);
  gtk_table_attach (GTK_TABLE (table), pglevel_frame, 0, 3, 1, 2,
		    GTK_FILL|GTK_EXPAND|GTK_SHRINK,
		    GTK_FILL, 2, 0);
  GTK_WIDGET_UNSET_FLAGS (pglevel_frame, GTK_CAN_FOCUS);
  gtk_widget_show(pglevel_frame);

  gtk_signal_connect (GTK_OBJECT (button_enter), "clicked",
		      GTK_SIGNAL_FUNC (dvdpglevel_passwd_cb),
		      entry_passwd);
  
  return frame;
}

void get_dvd_options_window()
{
  GtkAccelGroup *accel_group;
  GtkWidget *vbox1, *hbuttonbox1;
  GtkWidget *logo_REALmagic;
  GtkWidget *dvd_content_frame, *aspect_frame, 
    *pglevel_frame, *dvdregion_frame;
  GtkWidget *notebook, *label_notebook_page;
  /* GtkWidget *tv_format_frame; */
  
  guint Refresh_key, OK_key, Cancel_key;
  GtkWidget *Refresh, *OK, *Cancel;
  DvdPlayingStatus dvd_status;
  

  if (GUI.dvd_options!= NULL && GUI.dvd_options->window != NULL)
    {
      gdk_window_show(GUI.dvd_options->window);
      gdk_window_raise(GUI.dvd_options->window);
    }
  else
    {
      accel_group = gtk_accel_group_new ();
      
      GUI.dvd_options = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_widget_realize(GUI.dvd_options);

      gtk_window_set_title (GTK_WINDOW (GUI.dvd_options), _("Configuration"));
      gtk_window_set_position (GTK_WINDOW (GUI.dvd_options), GTK_WIN_POS_CENTER);
      gtk_window_set_policy (GTK_WINDOW (GUI.dvd_options), FALSE, FALSE, TRUE);

      vbox1 = gtk_vbox_new (FALSE, 0);
      gtk_widget_show (vbox1);
      gtk_container_add (GTK_CONTAINER (GUI.dvd_options), vbox1);
      gtk_container_set_border_width (GTK_CONTAINER (GUI.dvd_options), 5);
      
      notebook = gtk_notebook_new ();
      gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
      gtk_box_pack_start (GTK_BOX (vbox1), notebook, TRUE, FALSE, 0 );
      gtk_widget_show(notebook);
      
      dvd_content_frame = create_dvd_content_frame();
      gtk_widget_ref(dvd_content_frame);
      gtk_object_set_data_full (GTK_OBJECT (GUI.dvd_options), "dvd_content_frame", dvd_content_frame,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show(dvd_content_frame);
      label_notebook_page = gtk_label_new ("DVD Content");
      gtk_notebook_append_page (GTK_NOTEBOOK (notebook), dvd_content_frame, label_notebook_page);
      
      
      aspect_frame = create_aspect_ratio_frame();
      gtk_widget_ref(aspect_frame);
      gtk_object_set_data_full (GTK_OBJECT (GUI.dvd_options), "aspect_frame", aspect_frame,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show(aspect_frame);
      label_notebook_page = gtk_label_new ("Aspect Ratio");
      gtk_notebook_append_page (GTK_NOTEBOOK (notebook), aspect_frame, label_notebook_page);
      

      pglevel_frame = create_pglevel_frame();
      gtk_widget_ref(pglevel_frame);
      gtk_object_set_data_full (GTK_OBJECT (GUI.dvd_options), "pglevel_frame", pglevel_frame,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show(pglevel_frame);
      label_notebook_page = gtk_label_new ("Parental Level");
      gtk_notebook_append_page (GTK_NOTEBOOK (notebook), pglevel_frame, label_notebook_page);
      
      dvdregion_frame = create_radio_frame(6, dvdregion_entry, 
					   NULL, TRUE);
      gtk_widget_ref(dvdregion_frame);
      gtk_object_set_data_full (GTK_OBJECT (GUI.dvd_options), "dvdregion_frame", dvdregion_frame,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show(dvdregion_frame);
      label_notebook_page = gtk_label_new ("Region Code");
      gtk_notebook_append_page (GTK_NOTEBOOK (notebook), dvdregion_frame, label_notebook_page);

      gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 0);

      /* tv_format_frame = create_radio_frame(2, tv_format_entry,  */
/* 					   "TV format", TRUE); */
/*       gtk_widget_ref (tv_format_frame); */
/*       gtk_object_set_data_full (GTK_OBJECT (GUI.dvd_options), "tv_format_frame", tv_format_frame, */
/* 				(GtkDestroyNotify) gtk_widget_unref); */
/*       gtk_widget_show (tv_format_frame); */
/*       gtk_table_attach (GTK_TABLE (table), tv_format_frame, 0, 1, 1, 3, */
/* 			GTK_FILL|GTK_EXPAND, */
/* 			GTK_FILL|GTK_EXPAND, 5, 5); */
/*       GTK_WIDGET_UNSET_FLAGS (tv_format_frame, GTK_CAN_FOCUS); */

      
      
      logo_REALmagic = create_pixmap (GUI.dvd_options, logo_xpm);
      gtk_box_pack_start (GTK_BOX (vbox1), logo_REALmagic , TRUE, FALSE, 0 );
      gtk_widget_ref (logo_REALmagic);
      gtk_object_set_data_full (GTK_OBJECT (GUI.dvd_options), "logo_REALmagic", logo_REALmagic,
			    (GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (logo_REALmagic);

      hbuttonbox1 = gtk_hbutton_box_new ();
      gtk_widget_ref (hbuttonbox1);
      gtk_object_set_data_full (GTK_OBJECT (GUI.dvd_options), "hbuttonbox1", hbuttonbox1,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (hbuttonbox1);
      gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, TRUE, FALSE,10);
      gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_SPREAD);
      
      OK = gtk_button_new_with_label ("");
      OK_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (OK)->child),
					_("_OK"));
      gtk_widget_add_accelerator (OK, "clicked", accel_group,
				  OK_key, GDK_MOD1_MASK, 0);
      gtk_widget_ref (OK);
      gtk_object_set_data_full (GTK_OBJECT (GUI.dvd_options), "OK", OK,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (OK);
      
      gtk_container_add (GTK_CONTAINER (hbuttonbox1), OK);
      gtk_widget_add_accelerator (OK, "clicked", accel_group,
				  GDK_K, GDK_MOD1_MASK,
				  GTK_ACCEL_VISIBLE);
      
      
      Refresh = gtk_button_new_with_label ("");
      Refresh_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (Refresh)->child),
					   _("_Refresh"));
      gtk_widget_add_accelerator (Refresh, "clicked", accel_group,
				  Refresh_key, GDK_MOD1_MASK, 0);
      gtk_widget_ref (Refresh);
      gtk_object_set_data_full (GTK_OBJECT (GUI.dvd_options), "Refresh", Refresh,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (Refresh);
      // gtk_widget_hide (Refresh);

      gtk_container_add (GTK_CONTAINER (hbuttonbox1), Refresh);
      gtk_widget_add_accelerator (Refresh, "clicked", accel_group,
				  GDK_R, GDK_MOD1_MASK,
				  GTK_ACCEL_VISIBLE);

      Cancel = gtk_button_new_with_label ("");
      Cancel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (Cancel)->child),
					   _("_Cancel"));
      gtk_widget_add_accelerator (Cancel, "clicked", accel_group,
				  Cancel_key, GDK_MOD1_MASK, 0);
      gtk_widget_ref (Cancel);
      gtk_object_set_data_full (GTK_OBJECT (GUI.dvd_options), "Cancel", Cancel,
				(GtkDestroyNotify) gtk_widget_unref);
      gtk_widget_show (Cancel);
      gtk_container_add (GTK_CONTAINER (hbuttonbox1), Cancel);
      gtk_widget_add_accelerator (Cancel, "clicked", accel_group,
				  GDK_C, GDK_MOD1_MASK,
				  GTK_ACCEL_VISIBLE);
      
      gtk_signal_connect(GTK_OBJECT (GUI.dvd_options), "delete_event",
			 GTK_SIGNAL_FUNC (dvd_options_Cancel_clicked),
			 (gpointer)&dvd_status );
      
      gtk_signal_connect(GTK_OBJECT (GUI.dvd_options), "destroy",
			 GTK_SIGNAL_FUNC (dvd_options_Cancel_clicked),
			 (gpointer)&dvd_status );
      
      gtk_signal_connect(GTK_OBJECT (Refresh), "clicked",
			 GTK_SIGNAL_FUNC (refresh_dvd_options),
			 GTK_WIDGET(GUI.dvd_options));
      
      gtk_signal_connect(GTK_OBJECT (Cancel), "clicked",
			 GTK_SIGNAL_FUNC (dvd_options_Cancel_clicked),
			 (gpointer)&dvd_status );
      
      gtk_signal_connect (GTK_OBJECT (OK), "clicked",
			  GTK_SIGNAL_FUNC (dvd_options_Ok_clicked),
			  NULL); // save_options
      
      gtk_window_add_accel_group (GTK_WINDOW (GUI.dvd_options), accel_group);
      set_window_icon(GUI.dvd_options,REALmagic_xpm);
      
      saveCurrentDvdStatus(&dvd_status);
      
      gtk_widget_show(GUI.dvd_options);
      refresh_dvd_options(NULL,GUI.dvd_options);
    }
}
