
#include <version.h>
#include <ocarina/callback.h>
#include <ocarina/gtk.h>
#include <ocarina/body.h>
#include <ocarina/settings.h>
#include <ocarina/footer.h>
#include <ocarina/window.h>
#include <ocarina/library.h>

#include <libsaria/libsaria.h>
#include <libsaria/controls.h>
#include <libsaria/print.h>
#include <libsaria/idle.h>

static gboolean ocarina_idle(gpointer data)
{
	if (libsaria_idle_task() == 0)
		return FALSE; /* There are no idle events left */
	return TRUE; /* Process remaining idle events */
}

void ocarina_idle_add()
{
	g_idle_add(ocarina_idle, NULL);
}

void ocarina_init(int argc, char **argv)
{
	GtkWidget *vbox = gtk_vbox_new(FALSE, 0);

	window_init();
	window_title("Ocarina " + vers_str());
	window_icon("images/ocarina.png");

	box_pack_start(vbox, get_tabs(),        TRUE,  TRUE,  0);
	box_pack_start(vbox, get_tiny_footer(), FALSE, FALSE, 0);
	gtk_widget_show(vbox);
	window_add(vbox);

	library_init();
	settings_init();
}

void ocarina_quit()
{
	gtk_main_quit();
}

int main(int argc, char **argv)
{
	println("Ocarina " + vers_str());

	libsaria_init(argc, argv);
	setup_callbacks();
	gtk_init(&argc, &argv);
	ocarina_init(argc, argv);

	if (argc > 1)
		libsaria_load(argv[1]);

	gtk_main();
	libsaria_quit();
	return 0;
}
