/*
This file is part of Gnome Photo Printer.

    Gnome Photo Printer is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Gnome Photo Printer is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Gnome Photo Printer; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <stdio.h>
#include <stdlib.h>
#include <gnome.h>
#include <glade/glade.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libgnomevfs/gnome-vfs.h>
#include <libgnomeprint/gnome-print.h>
#include <libgnomeprint/gnome-print-job.h>
#include <libgnomeprintui/gnome-print-dialog.h>
#include "gpp_print.h"
#include "gpp_functions.h"
#include "gpp_widget.h"
#include "gpp_callbacks.h"
#include "gpp.h"

/* Load the Glade File and build the Widget */
GtkWidget *
gpp_build_widget (gchar * file)
{
	GladeXML *all;
	GtkWidget *window;
	GtkWidget *treeview;
	
	GtkCellRenderer *textrenderer;
	GtkTreeViewColumn *column;

	/* Load Glade file */
	all = glade_xml_new (file, NULL, NULL);
	window = glade_xml_get_widget (all, "window");
	
	/* Create the TreeView */
	treeview = glade_xml_get_widget(all, "treeview");
	gtk_tree_view_set_model(GTK_TREE_VIEW(treeview),gpp_definition->file_names);
	
	textrenderer = gtk_cell_renderer_text_new();
	column = gtk_tree_view_column_new_with_attributes("File",textrenderer,"text",0,NULL);
	g_object_set(column,"resizable",TRUE,"clickable",TRUE,"reorderable",TRUE,NULL);
	
	gtk_tree_view_append_column(GTK_TREE_VIEW(treeview),column);
	gpp_definition->treeview=GTK_TREE_VIEW(treeview);

	/* bind Signals for Callbacks */
	glade_xml_signal_connect (all, "window_destroy",
				  G_CALLBACK (func_gpp_quit));
	glade_xml_signal_connect (all, "cancel_button_clicked",
				  G_CALLBACK (func_gpp_quit));
	glade_xml_signal_connect (all, "preview_button_clicked",
				  G_CALLBACK (func_gpp_preview));
	glade_xml_signal_connect (all, "print_button_clicked",
				  G_CALLBACK (func_gpp_print));
	glade_xml_signal_connect (all, "remove_button_clicked",
				  G_CALLBACK (func_gpp_remove));		

	/* bind Signals for Layout Callbacks */
	glade_xml_signal_connect (all, "layout_1_clicked",
				  G_CALLBACK (func_gpp_layout_1));
	glade_xml_signal_connect (all, "layout_2_clicked",
				  G_CALLBACK (func_gpp_layout_2));
	glade_xml_signal_connect (all, "layout_3_clicked",
				  G_CALLBACK (func_gpp_layout_3));
	glade_xml_signal_connect (all, "layout_4_clicked",
				  G_CALLBACK (func_gpp_layout_4));
	glade_xml_signal_connect (all, "layout_5_clicked",
				  G_CALLBACK (func_gpp_layout_5));
	glade_xml_signal_connect (all, "layout_6_clicked",
				  G_CALLBACK (func_gpp_layout_6));
				  			  
	/* bind Signals for Image Callbacks */
	glade_xml_signal_connect (all, "image_1_clicked",G_CALLBACK(func_gpp_image_1));
	glade_xml_signal_connect (all, "image_2_clicked",G_CALLBACK(func_gpp_image_2));
	
	/* bind Signals for DND */
	gtk_drag_dest_set (GTK_WIDGET (window), GTK_DEST_DEFAULT_ALL,
			   target_table, 1, GDK_ACTION_COPY);
	gtk_signal_connect (GTK_OBJECT (window), "drag_data_received",
			    GTK_SIGNAL_FUNC (drag_received), NULL);

	return window;
}

GtkWidget *
gpp_printer_selector_new ()
{
	return GTK_WIDGET (gnome_printer_selector_new (gpp_config));
}

GtkWidget *
gpp_paper_selector_new ()
{
	return GTK_WIDGET (gnome_paper_selector_new (gpp_config));
}
