/* ***********************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 "Update_Callbacks.h"
#include "Update_Interface.h"
#include "../Gconf.h"
#include "../Debug.h"

void on_radiobutton_Update_clicked (GtkButton * button, gpointer user_data)
{
	DEBUG_ACTION_USER();
	gtk_widget_set_sensitive (spinbutton_Update_Port, FALSE);
	gtk_widget_set_sensitive (entry_Update_Proxy, FALSE);
	gtk_widget_set_sensitive (entry_Update_URL, FALSE);
}


void on_radiobutton_Update_Proxy_clicked (GtkButton * button, gpointer user_data)
{
	DEBUG_ACTION_USER();
	gtk_widget_set_sensitive (spinbutton_Update_Port, TRUE);
	gtk_widget_set_sensitive (entry_Update_Proxy, TRUE);
	gtk_widget_set_sensitive (entry_Update_URL, FALSE);
}


void on_radiobutton_Update_Auto_clicked (GtkButton * button, gpointer user_data)
{
	DEBUG_ACTION_USER();
	gtk_widget_set_sensitive (spinbutton_Update_Port, FALSE);
	gtk_widget_set_sensitive (entry_Update_Proxy, FALSE);
	gtk_widget_set_sensitive (entry_Update_URL, TRUE);
}


void on_checkbutton_Update_Auth_clicked (GtkButton * button, gpointer user_data)
{
	DEBUG_ACTION_USER();
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
		gtk_widget_set_sensitive (entry_Update_User, TRUE);
		gtk_widget_set_sensitive (entry_Update_Password, TRUE);
	}
	else {
		gtk_widget_set_sensitive (entry_Update_User, FALSE);
		gtk_widget_set_sensitive (entry_Update_Password, FALSE);
	}
}


void on_button_Update_Save_clicked (GtkButton * button, gpointer user_data)
{
	DEBUG_ACTION_USER();
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radiobutton_Update))) {
		Enregistrement_Info_Conf_Char ("/system/proxy/mode", "none");
		Enregistrement_Info_Conf_Bool ("/system/http_proxy/use_http_proxy", FALSE);
	}
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radiobutton_Update_Proxy))) {
		Enregistrement_Info_Conf_Char ("/system/proxy/mode", "manual");
		Enregistrement_Info_Conf_Bool ("/system/http_proxy/use_http_proxy", TRUE);
	}
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radiobutton_Update_Auto))) {
		Enregistrement_Info_Conf_Char ("/system/proxy/mode", "auto");
		Enregistrement_Info_Conf_Bool ("/system/http_proxy/use_http_proxy", TRUE);
	}
	Enregistrement_Info_Conf_Char ("/system/http_proxy/host", (gchar *) gtk_entry_get_text (GTK_ENTRY (entry_Update_Proxy)));
	Enregistrement_Info_Conf_Char ("/system/proxy/autoconfig_url", (gchar *) gtk_entry_get_text (GTK_ENTRY (entry_Update_URL)));
	Enregistrement_Info_Conf_Char ("/system/http_proxy/authentication_user", (gchar *) gtk_entry_get_text (GTK_ENTRY (entry_Update_User)));
	Enregistrement_Info_Conf_Char ("/system/http_proxy/authentication_password", (gchar *) gtk_entry_get_text (GTK_ENTRY (entry_Update_Password)));
	Enregistrement_Info_Conf_Int ("/system/http_proxy/port", (gint) gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinbutton_Update_Port)));
	Enregistrement_Info_Conf_Bool ("/system/http_proxy/use_authentication", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton_Update_Auth)));
	gtk_main_quit ();
	exit(0);
}
