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

/*
 *      playlist.c -- playlist for MPEG files and RTSP URLs
 *
 *      Copyright (C) 2001-2002 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/playlist.xpm"

gboolean gtk_playlistwin_hide(GtkWidget *widget, gpointer data)
{
  GtkWidget * playlist_check = NULL;
  playlist_check = gtk_item_factory_get_widget ( GUI.item_factory, "/View/Playlist");
  
  if(playlist_check != NULL)
    gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (playlist_check), FALSE);

  gtk_widget_hide(GUI.playlistwin);

  G_MESSAGE("Delete-Event send on playlistwin !!");
  
  return TRUE;
}

GtkWidget *create_playlistwin(void)
{
  GtkWidget *vbox, *hbuttonbox;
  GtkWidget *scrolled_window, *clist;
  GtkWidget *button_add, *button_clear, 
    *button_clear_selected, *button_hide_show,
    *button_load, *button_save;
  
  // gchar *titles[3] = { "Filename", "Stream Type", "Length" };
  
  gchar *titles[1] = { "Filename" };  
  
  GUI.playlistwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(GUI.playlistwin),
		       g_strconcat(GTKPLAYERNAME, "'s Playlist", NULL) );
  gtk_window_set_policy(GTK_WINDOW(GUI.playlistwin),
			TRUE, TRUE, TRUE);
  /* gtk_signal_connect_object(GTK_OBJECT(GUI.playlistwin), */
/* 			    "destroy-event", */
/* 			    GTK_SIGNAL_FUNC(gtk_widget_hide), */
/* 			    GTK_OBJECT(GUI.playlistwin)); */
  
  gtk_signal_connect(GTK_OBJECT(GUI.playlistwin),
		     "delete-event",
		     GTK_SIGNAL_FUNC(gtk_playlistwin_hide),
		     NULL);
  
  vbox = gtk_vbox_new(FALSE, 5);
  gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
  gtk_container_add(GTK_CONTAINER(GUI.playlistwin), vbox);
  gtk_widget_show(vbox);
  
  /* Create a scrolled window to pack the CList widget into */
  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
				  GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
  
  gtk_box_pack_start(GTK_BOX(vbox), scrolled_window, TRUE, TRUE, 0);
  gtk_widget_show (scrolled_window);

  /* Create the CList. For this example we use 2 columns */
  // clist = gtk_clist_new_with_titles( 3, titles);
  clist = gtk_clist_new_with_titles( 1, titles);
  gtk_widget_ref (clist);
  gtk_object_set_data_full (GTK_OBJECT (GUI.playlistwin), "playlist", clist,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_clist_set_selection_mode(GTK_CLIST(clist),
			       GTK_SELECTION_EXTENDED);
  gtk_clist_set_shadow_type (GTK_CLIST(clist), GTK_SHADOW_IN);
  
  gtk_signal_connect(GTK_OBJECT(clist), "select_row",
		     GTK_SIGNAL_FUNC(selection_made),
		     NULL);
  
  /*   gtk_signal_connect(GTK_OBJECT(clist), "unselect_row", */
  /* 		     GTK_SIGNAL_FUNC(unselection_made), */
  /* 		     NULL); */
  
  // gtk_clist_set_column_width (GTK_CLIST(clist), 0, 250);
  /* Add the CList widget to the vertical box and show it. */
  gtk_container_add(GTK_CONTAINER(scrolled_window), clist);
  gtk_widget_show(clist);
    
  
    hbuttonbox = gtk_hbutton_box_new();
    gtk_widget_show(hbuttonbox);
    gtk_box_pack_start(GTK_BOX(vbox), hbuttonbox, FALSE, TRUE, 0);
    gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox), 
			       GTK_BUTTONBOX_SPREAD);
    
    button_add = gtk_button_new_with_label("Add");
    button_clear_selected = gtk_button_new_with_label("Remove");
    button_clear = gtk_button_new_with_label("Remove All");
    button_load = gtk_button_new_with_label("Load list");
    button_save = gtk_button_new_with_label("Save list");
    button_hide_show = gtk_button_new_with_label("Hide/Show Titles");
    
    gtk_container_add (GTK_CONTAINER (hbuttonbox), button_add);
    gtk_container_add (GTK_CONTAINER (hbuttonbox), button_clear_selected);
    gtk_container_add (GTK_CONTAINER (hbuttonbox), button_clear);
    gtk_container_add (GTK_CONTAINER (hbuttonbox), button_load);
    gtk_container_add (GTK_CONTAINER (hbuttonbox), button_save);
    gtk_container_add (GTK_CONTAINER (hbuttonbox), button_hide_show);

    /* Connect our callbacks to the three buttons */
    gtk_signal_connect_object(GTK_OBJECT(button_add), "clicked",
			      GTK_SIGNAL_FUNC(button_add_clicked),
			      (gpointer) clist);
    gtk_signal_connect_object(GTK_OBJECT(button_clear_selected), "clicked",
			      GTK_SIGNAL_FUNC(button_clear_selected_clicked),
			      (gpointer) clist);
    gtk_signal_connect_object(GTK_OBJECT(button_clear), "clicked",
			      GTK_SIGNAL_FUNC(button_clear_clicked),
			      (gpointer) clist);
    gtk_signal_connect_object(GTK_OBJECT(button_load), "clicked",
			      GTK_SIGNAL_FUNC(load_playlist_file_clicked_cb),
			      NULL);
    gtk_signal_connect_object(GTK_OBJECT(button_save), "clicked",
			      GTK_SIGNAL_FUNC(save_playlist_file_clicked_cb),
			      NULL);
    gtk_signal_connect_object(GTK_OBJECT(button_hide_show), "clicked",
			      GTK_SIGNAL_FUNC(button_hide_show_clicked),
			      (gpointer) clist);
    
    gtk_widget_show(button_add);
    gtk_widget_show(button_clear_selected);
    gtk_widget_show(button_clear);
    gtk_widget_show(button_load);
    gtk_widget_show(button_save);
    gtk_widget_show(button_hide_show);
    gtk_widget_hide(button_hide_show);

    set_window_icon(GUI.playlistwin, playlist_xpm);
    
    return(GUI.playlistwin);
}
