#include <gtk/gtk.h>
#include "mixer.h"

#ifndef EXIT_FAILURE
#define EXIT_FAILURE -1
#endif

gint delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
{
    gtk_main_quit();
    return FALSE;
}

static void play_src(GtkWidget *widget, gpointer data)
{ 
    start_channel ();
}

static void pause_src(GtkWidget *widget, gpointer data)
{
    pause_channel (); 
}

static void quit(void)
{
    quit_everything();
    gtk_main_quit();
}

int main( int argc, char *argv[])
{
    GtkWidget *window, *mainvbox;
    GtkWidget *control_buttons_hbox;
    GtkWidget *play_button, *pause_button;
    GtkWidget *quit_button;

    if (argc == 1)
    {
	g_print ("usage: %s <filename1> \n", argv[0]);
	exit(EXIT_FAILURE);
    }

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Tester");

    /* When the window is given the "delete_event" signal (this is given
     * by the window manager, usually by the "close" option, or on the
     * titlebar), we ask it to call the delete_event () function
     * as defined above. The data passed to the callback
     * function is NULL and is ignored in the callback function. */
    g_signal_connect (G_OBJECT (window), "delete_event",
		      G_CALLBACK (delete_event), NULL); 

    gtk_container_set_border_width (GTK_CONTAINER (window), 5);

    /* main vbox that will hold main hbox (needed so that quit button appears
     * below everything) */
    mainvbox = gtk_vbox_new (FALSE, 5);
    gtk_container_add (GTK_CONTAINER (window), mainvbox);

    play_button = gtk_button_new_with_label("play");
    g_signal_connect (G_OBJECT (play_button), "clicked",
	    G_CALLBACK (play_src), NULL);

    pause_button = gtk_button_new_with_label("pause");
    g_signal_connect (G_OBJECT (pause_button), "clicked",
	    G_CALLBACK (pause_src), NULL);

    /* create container for control buttons */
    control_buttons_hbox = gtk_hbox_new (TRUE, 5);
    gtk_box_pack_start (GTK_BOX (mainvbox), control_buttons_hbox,
	    FALSE, FALSE, 5);

    gtk_container_add (GTK_CONTAINER (control_buttons_hbox), play_button);
    gtk_container_add (GTK_CONTAINER (control_buttons_hbox), pause_button);

    gtk_widget_show (play_button);
    gtk_widget_show (pause_button);
    gtk_widget_show (control_buttons_hbox);

    /* create quit button */
    quit_button = gtk_button_new_with_label ("quit");
    g_signal_connect (G_OBJECT (quit_button), "clicked",
	    G_CALLBACK (quit), NULL);
    gtk_box_pack_start (GTK_BOX(mainvbox), quit_button, FALSE, FALSE, 5);

    gtk_widget_show (quit_button);
    gtk_widget_show (mainvbox);

    gtk_window_set_default_size (GTK_WINDOW (window), 100, 100);
    gtk_widget_show (window);

    init_mixer (argc, argv);

    gtk_main ();

    return 0;
}
