#include <gtk/gtk.h>

gboolean
gqs_delete_event (GtkWidget *widget,
		  gpointer user_data)
{
	gtk_main_quit ();
	return FALSE;
}

GtkWidget *
gqs_window_new ()
{
	GtkWidget *window;
	
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	
	gtk_widget_set_events (window, GDK_KEY_PRESS_MASK);
	
	g_signal_connect (G_OBJECT (window), "delete-event",
			  G_CALLBACK (gqs_delete_event), NULL);
	return window;
}

void
gqs_open_image (GtkWidget *window, const gchar *image_file)
{
	GtkWidget *image;
	image = gtk_image_new_from_file (image_file);
	gtk_container_add (GTK_CONTAINER (window), image);
	gtk_widget_show_all (image);
}

int
main (int argc, gchar **argv)
{
	GtkWidget *window;
	gchar *basename;
	
	gtk_init (&argc, &argv);

	if (argc < 2)
		return 0;
		
	window = gqs_window_new ();
	gqs_open_image (window, argv[1]);

       	basename = g_path_get_basename (argv[1]);
	gtk_window_set_title (GTK_WINDOW (window),
			      basename);
	g_free (basename);

	gtk_widget_show (window);

	gtk_main ();

	return 0;
}
