/* ***********************IMPORTANT *********************************************
 *  Copyright (C) 2004-2007 Thierry Lagarde <tlagarde@users.sourceforge.net>
 *  This program 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.
 *
 *
 *                      ********************
 *
 *
 *  This program 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 Library General Public License for more details.
 *
 *
 *                      ********************
 *
 *
 * You are highly encouraged to send your changes to <tlagarde@users.sourceforge.net>
 * for possible incorporation into the main distribution.
 * By sending these changes to <tlagarde@users.sourceforge.net>,
 * it is assumed that you are offering <tlagarde@users.sourceforge.net>
 * the unlimited, non-exclusive right to reuse, modify, and relicense the code.
 *
 *
 *                      ********************
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **************************************************************************************/
#include <gtk/gtk.h>

#include "Root_Interface.h"
#include "Open_Save_Callbacks.h"
#include "Open_Save_Interface.h"
#include "Maemo.h"
#include "../Declaration_Constante.h"



void create_file_Save (void)
{

#ifndef         __MAEMO
	file_Save = gtk_file_chooser_dialog_new ("Save", NULL, GTK_FILE_CHOOSER_ACTION_SAVE, NULL);
	g_object_set (file_Save, "local-only", FALSE, "show-hidden", TRUE, NULL);
	file_Save_icon_pixbuf = gdk_pixbuf_new_from_file (PATH_ICONE "/AutoScan.png", NULL);
	if (file_Save_icon_pixbuf) {
		gtk_window_set_icon (GTK_WINDOW (file_Save), file_Save_icon_pixbuf);
		gdk_pixbuf_unref (file_Save_icon_pixbuf);
	}
#else
	GtkFileFilter *filter = NULL;
	GSList *filenames = NULL;

	filter = gtk_file_filter_new();
	gtk_file_filter_set_name(filter, "xml");
	gtk_file_filter_add_pattern(filter, "*.xml");

	file_Save = gtk_file_chooser_dialog_new_maemo(GTK_FILE_CHOOSER_ACTION_SAVE);
    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_Save),"/home/user");
	gtk_window_set_title(GTK_WINDOW(file_Save), "Save file");
	gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(file_Save), filter);
	gtk_widget_show_all(file_Save);
#endif

	gtk_window_set_type_hint (GTK_WINDOW (file_Save), GDK_WINDOW_TYPE_HINT_DIALOG);
	gtk_window_set_transient_for (GTK_WINDOW (file_Save), GTK_WINDOW (window_root));
	
	dialog_vbox1 = GTK_DIALOG (file_Save)->vbox;
	gtk_widget_show (dialog_vbox1);

	dialog_action_area_Save = GTK_DIALOG (file_Save)->action_area;
	gtk_widget_show (dialog_action_area_Save);
	gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area_Save), GTK_BUTTONBOX_END);

	button_Save_Cancel = gtk_button_new_from_stock ("gtk-cancel");
	gtk_widget_show (button_Save_Cancel);
	gtk_dialog_add_action_widget (GTK_DIALOG (file_Save), button_Save_Cancel, GTK_RESPONSE_CANCEL);
	GTK_WIDGET_SET_FLAGS (button_Save_Cancel, GTK_CAN_DEFAULT);

	button_Save = gtk_button_new_from_stock ("gtk-save");
	gtk_widget_show (button_Save);
	gtk_dialog_add_action_widget (GTK_DIALOG (file_Save), button_Save, GTK_RESPONSE_OK);
	GTK_WIDGET_SET_FLAGS (button_Save, GTK_CAN_DEFAULT);


	g_signal_connect ((gpointer) button_Save_Cancel, "clicked", G_CALLBACK (on_button_Save_Cancel_clicked), NULL);
	g_signal_connect ((gpointer) button_Save, "clicked", G_CALLBACK (on_button_Save_clicked), NULL);

	gtk_widget_grab_default (button_Save);




}




void create_file_Open (void)
{
#ifndef         __MAEMO
	GtkFileFilter *filter = NULL;
	
	filter = gtk_file_filter_new();
	gtk_file_filter_set_name(filter, "xml");
	gtk_file_filter_add_pattern(filter, "*.xml");
	
	file_Open = gtk_file_chooser_dialog_new ("Open", NULL, GTK_FILE_CHOOSER_ACTION_OPEN, NULL);
	gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(file_Open), filter);
	gtk_window_set_modal (GTK_WINDOW (file_Open), TRUE);
	g_object_set (file_Open, "local-only", FALSE, "show-hidden", TRUE, NULL);
	file_Open_icon_pixbuf = gdk_pixbuf_new_from_file ("/AutoScan.png", NULL);
	if (file_Open_icon_pixbuf) {
		gtk_window_set_icon (GTK_WINDOW (file_Open), file_Open_icon_pixbuf);
		gdk_pixbuf_unref (file_Open_icon_pixbuf);
	}
#else
	GtkFileFilter *filter = NULL;
	GSList *filenames = NULL;

	filter = gtk_file_filter_new();
	gtk_file_filter_set_name(filter, "xml");
	gtk_file_filter_add_pattern(filter, "*.xml");

	file_Open = gtk_file_chooser_dialog_new_maemo(GTK_FILE_CHOOSER_ACTION_OPEN);
    gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_Open),"/home/user");
	gtk_window_set_title(GTK_WINDOW(file_Open), "Open file");
	gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(file_Open), filter);
	gtk_widget_show_all(file_Open);
#endif

	gtk_window_set_type_hint (GTK_WINDOW (file_Open), GDK_WINDOW_TYPE_HINT_DIALOG);
	gtk_window_set_transient_for (GTK_WINDOW (file_Open), GTK_WINDOW (window_root));
	
	dialog_vbox1_Open = GTK_DIALOG (file_Open)->vbox;
	gtk_widget_show (dialog_vbox1_Open);

	dialog_action_area_Open = GTK_DIALOG (file_Open)->action_area;
	gtk_widget_show (dialog_action_area_Open);
	gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area_Open), GTK_BUTTONBOX_END);

	button_Open_Cancel = gtk_button_new_from_stock ("gtk-cancel");
	gtk_widget_show (button_Open_Cancel);
	gtk_dialog_add_action_widget (GTK_DIALOG (file_Open), button_Open_Cancel, GTK_RESPONSE_CANCEL);
	GTK_WIDGET_SET_FLAGS (button_Open_Cancel, GTK_CAN_DEFAULT);

	button_Open = gtk_button_new_from_stock ("gtk-open");
	gtk_widget_show (button_Open);
	gtk_dialog_add_action_widget (GTK_DIALOG (file_Open), button_Open, GTK_RESPONSE_OK);
	GTK_WIDGET_SET_FLAGS (button_Open, GTK_CAN_DEFAULT);
	g_signal_connect ((gpointer) file_Open, "destroy", G_CALLBACK (on_file_Open_destroy), NULL);
	g_signal_connect ((gpointer) button_Open_Cancel, "clicked", G_CALLBACK (on_button_Open_Cancel_clicked), NULL);
	g_signal_connect ((gpointer) button_Open, "clicked", G_CALLBACK (on_button_Open_clicked), NULL);

	gtk_widget_grab_default (button_Open);

}
