/* ***********************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 "Recherche_Callbacks.h"
#include "Recherche_Interface.h"
#include "../Declaration_Constante.h"
#include "Root_Interface.h"
#include "Combo.h"
#include "Maemo.h"

void create_window_Recherche (void)
{
	GSList   *radiobutton_Recherche_Mac_group = NULL;

#ifndef         __MAEMO
	window_Recherche = gtk_window_new (GTK_WINDOW_TOPLEVEL);
#else
	window_Recherche = gtk_window_new_maemo ();
#endif

	gtk_window_set_title (GTK_WINDOW (window_Recherche), "Search equipment");
	gtk_window_set_position (GTK_WINDOW (window_Recherche), GTK_WIN_POS_CENTER_ON_PARENT);
	gtk_window_set_transient_for (GTK_WINDOW (window_Recherche), GTK_WINDOW (window_root));
	gtk_window_set_modal (GTK_WINDOW (window_Recherche), TRUE);
	gtk_window_set_resizable (GTK_WINDOW (window_Recherche), FALSE);
	window_Recherche_icon_pixbuf = gdk_pixbuf_new_from_file (PATH_ICONE "/AutoScan.png", NULL);
	if (window_Recherche_icon_pixbuf) {
		gtk_window_set_icon (GTK_WINDOW (window_Recherche), window_Recherche_icon_pixbuf);
		gdk_pixbuf_unref (window_Recherche_icon_pixbuf);
	}

	vbox_Recherche = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox_Recherche);
	gtk_container_add (GTK_CONTAINER (window_Recherche), vbox_Recherche);
	gtk_container_set_border_width (GTK_CONTAINER (vbox_Recherche), 5);

	hbox_Recherche_Mac = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (hbox_Recherche_Mac);
	gtk_box_pack_start (GTK_BOX (vbox_Recherche), hbox_Recherche_Mac, TRUE, TRUE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (hbox_Recherche_Mac), 2);

	radiobutton_Recherche_Mac = gtk_radio_button_new_with_mnemonic (NULL, "By the Mac address");
	gtk_widget_show (radiobutton_Recherche_Mac);
	gtk_box_pack_start (GTK_BOX (hbox_Recherche_Mac), radiobutton_Recherche_Mac, FALSE, FALSE, 0);
	gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_Recherche_Mac), radiobutton_Recherche_Mac_group);
	radiobutton_Recherche_Mac_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_Recherche_Mac));
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton_Recherche_Mac), TRUE);

	entry_Recherche_Mac = gtk_entry_new ();
	gtk_widget_show (entry_Recherche_Mac);
	gtk_box_pack_start (GTK_BOX (hbox_Recherche_Mac), entry_Recherche_Mac, FALSE, TRUE, 10);

	hbox_Recherche_Ip = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (hbox_Recherche_Ip);
	gtk_box_pack_start (GTK_BOX (vbox_Recherche), hbox_Recherche_Ip, TRUE, TRUE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (hbox_Recherche_Ip), 2);

	radiobutton_Recherche_Ip = gtk_radio_button_new_with_mnemonic (NULL, "by the Ip address");
	gtk_widget_show (radiobutton_Recherche_Ip);
	gtk_box_pack_start (GTK_BOX (hbox_Recherche_Ip), radiobutton_Recherche_Ip, FALSE, FALSE, 0);
	gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_Recherche_Ip), radiobutton_Recherche_Mac_group);
	radiobutton_Recherche_Mac_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_Recherche_Ip));

	entry_Recherche_Ip = gtk_entry_new ();
	gtk_widget_show (entry_Recherche_Ip);
	gtk_box_pack_start (GTK_BOX (hbox_Recherche_Ip), entry_Recherche_Ip, FALSE, TRUE, 21);
	gtk_widget_set_sensitive (entry_Recherche_Ip, FALSE);

	hbox_Recherche_Hostname = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (hbox_Recherche_Hostname);
	gtk_box_pack_start (GTK_BOX (vbox_Recherche), hbox_Recherche_Hostname, TRUE, TRUE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (hbox_Recherche_Hostname), 2);

	radiobutton_Recherche_Hostname = gtk_radio_button_new_with_mnemonic (NULL, "by the hostname");
	gtk_widget_show (radiobutton_Recherche_Hostname);
	gtk_box_pack_start (GTK_BOX (hbox_Recherche_Hostname), radiobutton_Recherche_Hostname, FALSE, FALSE, 0);
	gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_Recherche_Hostname), radiobutton_Recherche_Mac_group);
	radiobutton_Recherche_Mac_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_Recherche_Hostname));

	entry_Recherche_Hostname = gtk_entry_new ();
	gtk_widget_show (entry_Recherche_Hostname);
	gtk_box_pack_start (GTK_BOX (hbox_Recherche_Hostname), entry_Recherche_Hostname, FALSE, TRUE, 20);
	gtk_widget_set_sensitive (entry_Recherche_Hostname, FALSE);

	hbox_Recherche_Port = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (hbox_Recherche_Port);
	gtk_box_pack_start (GTK_BOX (vbox_Recherche), hbox_Recherche_Port, TRUE, TRUE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (hbox_Recherche_Port), 2);

	radiobutton_Recherche_Port = gtk_radio_button_new_with_mnemonic (NULL, "by an open port");
	gtk_widget_show (radiobutton_Recherche_Port);
	gtk_box_pack_start (GTK_BOX (hbox_Recherche_Port), radiobutton_Recherche_Port, FALSE, FALSE, 0);
	gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_Recherche_Port), radiobutton_Recherche_Mac_group);
	radiobutton_Recherche_Mac_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_Recherche_Port));

	combobox_Recherche_Port = creation_combo (FALSE);
	creation_combo_liste_port ();
	gtk_widget_show (combobox_Recherche_Port);
	gtk_box_pack_start (GTK_BOX (hbox_Recherche_Port), combobox_Recherche_Port, FALSE, TRUE, 26);
	gtk_widget_set_sensitive (combobox_Recherche_Port, FALSE);

	hbox_Recherche_Bouton = gtk_hbox_new (FALSE, 0);
	gtk_widget_show (hbox_Recherche_Bouton);
	gtk_box_pack_start (GTK_BOX (vbox_Recherche), hbox_Recherche_Bouton, TRUE, TRUE, 0);

	button_Recherche_Close = gtk_button_new_from_stock ("gtk-close");
	gtk_widget_show (button_Recherche_Close);
	gtk_box_pack_end (GTK_BOX (hbox_Recherche_Bouton), button_Recherche_Close, FALSE, FALSE, 8);

	button_Recherche = gtk_button_new_from_stock ("gtk-find");
	gtk_widget_show (button_Recherche);
	gtk_box_pack_end (GTK_BOX (hbox_Recherche_Bouton), button_Recherche, FALSE, FALSE, 0);

	g_signal_connect ((gpointer) window_Recherche, "destroy", G_CALLBACK (on_window_Recherche_destroy), NULL);
	g_signal_connect ((gpointer) radiobutton_Recherche_Mac, "clicked", G_CALLBACK (on_radiobutton_Recherche_Mac_clicked), NULL);
	g_signal_connect ((gpointer) radiobutton_Recherche_Ip, "clicked", G_CALLBACK (on_radiobutton_Recherche_Ip_clicked), NULL);
	g_signal_connect ((gpointer) radiobutton_Recherche_Hostname, "clicked", G_CALLBACK (on_radiobutton_Recherche_Hostname_clicked), NULL);
	g_signal_connect ((gpointer) radiobutton_Recherche_Port, "clicked", G_CALLBACK (on_radiobutton_Recherche_Port_clicked), NULL);
	g_signal_connect ((gpointer) button_Recherche_Close, "clicked", G_CALLBACK (on_button_Recherche_Close_clicked), NULL);
	g_signal_connect ((gpointer) button_Recherche, "clicked", G_CALLBACK (on_button_Recherche_clicked), NULL);
}
