
#include <list>
using namespace std;

#include <ocarina/button.h>
#include <libsaria/audio.h>

static list<GtkWidget *> play_buttons;
static list<GtkWidget *> pause_buttons;

static list<GtkWidget *> *get_buttons(button_list_t bttn_list)
{
	switch(bttn_list) {
		case PLAY_BUTTON_LIST:
			return &play_buttons;
		default:
			return &pause_buttons;
	}
}

void show_button_list(button_list_t bttn_list)
{
	list<GtkWidget *>::iterator it;
	list<GtkWidget *> *buttons = get_buttons(bttn_list);
	for (it = buttons->begin(); it != buttons->end(); it++)
		gtk_widget_show(*it);
}

void hide_button_list(button_list_t bttn_list)
{
	list<GtkWidget *>::iterator it;
	list<GtkWidget *> *buttons = get_buttons(bttn_list);
	for (it = buttons->begin(); it != buttons->end(); it++)
		gtk_widget_hide(*it);
}

static void on_click_play(GtkWidget *b, GdkEvent *e, gpointer d)
{
	libsaria::audio::play();
}

GtkWidget *make_play_button()
{
	GtkWidget *b = make_button(GTK_STOCK_MEDIA_PLAY,
				   on_click_play,
				   true);
	play_buttons.push_back(b);
	return b;
}

static void on_click_pause(GtkWidget *b, GdkEvent *e, gpointer d)
{
	libsaria::audio::pause();
}

GtkWidget *make_pause_button()
{
	GtkWidget *b = make_button(GTK_STOCK_MEDIA_PAUSE,
				   on_click_pause,
				   false);
	pause_buttons.push_back(b);
	return b;
}

static void on_click_stop(GtkWidget *b, GdkEvent *e, gpointer d)
{
	libsaria::audio::stop();
}

GtkWidget *make_stop_button()
{
	return make_button(GTK_STOCK_MEDIA_STOP,
			   on_click_stop, 
			   true);
}

static void on_click_rewind(GtkWidget *b, GdkEvent *e, gpointer d)
{
	libsaria::audio::seek(-5);
}

GtkWidget *make_rewind_button()
{
	return make_button(GTK_STOCK_MEDIA_REWIND,
			   on_click_rewind,
			   true);
}

static void on_click_forward(GtkWidget *b, GdkEvent *e, gpointer d)
{
	libsaria::audio::seek(5);
}

GtkWidget *make_forward_button()
{
	return make_button(GTK_STOCK_MEDIA_FORWARD,
			   on_click_forward,
			   true);
}
