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

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

namespace ocarina
{

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

	void idle_add()
	{
		g_idle_add(idle, NULL);
	}

	void init(int argc, char **argv)
	{
		window_init("Ocarina " + vers_str(), "images/ocarina.png");
		window_add(get_tabs());
		ocarina::library::init();
		settings_init();
	}

	void 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::audio::load(argv[1]);

	gtk_main();
	libsaria::quit();
	return 0;
}
