/* ***********************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.
 **************************************************************************************/
#ifdef         __CONSOLE_ENABLE

#include <gtk/gtk.h>
#include <vte/vte.h>

#include "Root_Interface.h"
#include "Console.h"
#include "../Modules.h"
#include "../Equipement.h"
#include "../Debug.h"


GtkWidget *Creation_Console (gchar * Commande)
{
	GtkWidget *hbox = NULL;
	GtkWidget *term_widget = NULL;
	GtkWidget *scrolled_window_terminal = NULL;
	pid_t     Pid_Commande;
	char     *arguments[3];

	arguments[0] = Commande;
	arguments[1] = Equipement_Selectionner->Adresse_Ip_Char;
	arguments[2] = NULL;

	hbox = gtk_hbox_new (FALSE, 0);
	gtk_box_set_spacing (GTK_BOX (hbox), 2);
	gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
	gtk_container_add (GTK_CONTAINER (viewport_Modules), hbox);
	gtk_widget_show (hbox);

	scrolled_window_terminal = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window_terminal), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
	gtk_widget_show (scrolled_window_terminal);
	term_widget = (GtkWidget *) vte_terminal_new ();
	vte_terminal_set_emulation (term_widget, "xterm");
	vte_terminal_set_mouse_autohide (term_widget, TRUE);
	vte_terminal_reset (term_widget, TRUE, TRUE);


	Pid_Commande = vte_terminal_fork_command (term_widget, Commande, arguments, NULL, NULL, TRUE, TRUE, TRUE);

	gtk_widget_show (term_widget);
	gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window_terminal), term_widget);
	gtk_box_pack_start (GTK_BOX (hbox), scrolled_window_terminal, TRUE, TRUE, 0);
	return hbox;
}

#endif
