2002-04-22 17:49:22 +00:00
|
|
|
|
|
|
|
/* gnome-network-preferences.c: network preferences capplet
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Sun Microsystems Inc.
|
|
|
|
*
|
|
|
|
* Written by: Mark McLoughlin <mark@skynet.ie>
|
|
|
|
*
|
|
|
|
* 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, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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 HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <libgnome/libgnome.h>
|
|
|
|
#include <gconf/gconf-client.h>
|
|
|
|
#include <glade/glade.h>
|
2002-07-10 16:37:46 +00:00
|
|
|
#include <libgnomevfs/gnome-vfs-uri.h>
|
2002-04-22 17:49:22 +00:00
|
|
|
|
|
|
|
#include "capplet-util.h"
|
|
|
|
#include "gconf-property-editor.h"
|
|
|
|
|
2002-10-25 21:09:09 +00:00
|
|
|
enum ProxyMode
|
|
|
|
{
|
|
|
|
PROXYMODE_NONE,
|
|
|
|
PROXYMODE_MANUAL,
|
|
|
|
PROXYMODE_AUTO
|
|
|
|
};
|
|
|
|
|
|
|
|
static GEnumValue proxytype_values[] = {
|
|
|
|
{ PROXYMODE_NONE, "PROXYMODE_NONE", "none"},
|
|
|
|
{ PROXYMODE_MANUAL, "PROXYMODE_MANUAL", "manual"},
|
|
|
|
{ PROXYMODE_AUTO, "PROXYMODE_AUTO", "auto"},
|
|
|
|
{ 0, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
2002-05-08 22:12:25 +00:00
|
|
|
#define USE_PROXY_KEY "/system/http_proxy/use_http_proxy"
|
2002-10-25 21:09:09 +00:00
|
|
|
#define HTTP_PROXY_HOST_KEY "/system/http_proxy/host"
|
|
|
|
#define HTTP_PROXY_PORT_KEY "/system/http_proxy/port"
|
|
|
|
#define HTTP_USE_AUTH_KEY "/system/http_proxy/use_authentication"
|
|
|
|
#define HTTP_AUTH_USER_KEY "/system/http_proxy/authentication_user"
|
|
|
|
#define HTTP_AUTH_PASSWD_KEY "/system/http_proxy/authentication_password"
|
|
|
|
#define PROXY_MODE_KEY "/system/proxy/mode"
|
|
|
|
#define SECURE_PROXY_HOST_KEY "/system/proxy/secure_host"
|
|
|
|
#define SECURE_PROXY_PORT_KEY "/system/proxy/secure_port"
|
|
|
|
#define FTP_PROXY_HOST_KEY "/system/proxy/ftp_host"
|
|
|
|
#define FTP_PROXY_PORT_KEY "/system/proxy/ftp_port"
|
|
|
|
#define SOCKS_PROXY_HOST_KEY "/system/proxy/socks_host"
|
|
|
|
#define SOCKS_PROXY_PORT_KEY "/system/proxy/socks_port"
|
|
|
|
#define PROXY_AUTOCONFIG_URL_KEY "/system/proxy/autoconfig_url"
|
|
|
|
|
|
|
|
static GtkWidget *details_dialog = NULL;
|
2002-04-22 17:49:22 +00:00
|
|
|
|
|
|
|
static void
|
2002-05-09 17:40:48 +00:00
|
|
|
cb_dialog_response (GtkDialog *dialog, gint response_id)
|
2002-04-22 17:49:22 +00:00
|
|
|
{
|
2002-05-27 02:54:19 +00:00
|
|
|
if (response_id == GTK_RESPONSE_HELP)
|
|
|
|
capplet_help (GTK_WINDOW (dialog),
|
2004-02-12 14:23:03 +00:00
|
|
|
"user-guide.xml",
|
2002-05-29 04:14:29 +00:00
|
|
|
"goscustdesk-50");
|
2002-05-27 02:54:19 +00:00
|
|
|
else
|
2002-04-22 17:49:22 +00:00
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
|
2002-10-25 21:09:09 +00:00
|
|
|
static void
|
|
|
|
cb_details_dialog_response (GtkDialog *dialog, gint response_id)
|
|
|
|
{
|
|
|
|
if (response_id == GTK_RESPONSE_HELP)
|
|
|
|
capplet_help (GTK_WINDOW (dialog),
|
2004-02-12 14:23:03 +00:00
|
|
|
"user-guide.xml",
|
2002-10-25 21:09:09 +00:00
|
|
|
"goscustdesk-50");
|
|
|
|
else {
|
|
|
|
gtk_widget_destroy (GTK_WIDGET (dialog));
|
|
|
|
details_dialog = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cb_use_auth_toggled (GtkToggleButton *toggle,
|
|
|
|
GtkWidget *table)
|
|
|
|
{
|
|
|
|
gtk_widget_set_sensitive (table, toggle->active);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cb_http_details_button_clicked (GtkWidget *button,
|
|
|
|
GtkWidget *parent)
|
|
|
|
{
|
|
|
|
GladeXML *dialog;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GConfPropertyEditor *peditor;
|
|
|
|
|
|
|
|
if (details_dialog != NULL) {
|
|
|
|
gtk_window_present (GTK_WINDOW (details_dialog));
|
|
|
|
gtk_widget_grab_focus (details_dialog);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog = glade_xml_new (GNOMECC_DATA_DIR "/interfaces/gnome-network-preferences.glade",
|
|
|
|
"details_dialog", NULL);
|
|
|
|
|
|
|
|
details_dialog = widget = WID ("details_dialog");
|
|
|
|
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (widget), GTK_WINDOW (parent));
|
|
|
|
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (GTK_BIN (WID ("use_auth_checkbutton"))->child), TRUE);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (WID ("use_auth_checkbutton")),
|
|
|
|
"toggled",
|
|
|
|
G_CALLBACK (cb_use_auth_toggled),
|
|
|
|
WID ("auth_table"));
|
|
|
|
|
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_boolean (
|
|
|
|
NULL, HTTP_USE_AUTH_KEY, WID ("use_auth_checkbutton"),
|
|
|
|
NULL));
|
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
|
|
|
|
NULL, HTTP_AUTH_USER_KEY, WID ("username_entry"),
|
|
|
|
NULL));
|
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
|
|
|
|
NULL, HTTP_AUTH_PASSWD_KEY, WID ("password_entry"),
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
g_signal_connect (widget, "response",
|
|
|
|
G_CALLBACK (cb_details_dialog_response), NULL);
|
|
|
|
|
2003-07-20 00:44:41 +00:00
|
|
|
capplet_set_icon (widget, "gnome-network-capplet.png");
|
2002-10-25 21:09:09 +00:00
|
|
|
|
|
|
|
gtk_widget_show_all (widget);
|
|
|
|
}
|
|
|
|
|
2002-07-10 16:37:46 +00:00
|
|
|
static GConfValue *
|
|
|
|
extract_proxy_host (GConfPropertyEditor *peditor, const GConfValue *orig)
|
|
|
|
{
|
|
|
|
char const *entered_text = gconf_value_get_string (orig);
|
|
|
|
GConfValue *res = NULL;
|
|
|
|
|
|
|
|
if (entered_text != NULL) {
|
|
|
|
GnomeVFSURI *uri = gnome_vfs_uri_new (entered_text);
|
|
|
|
if (uri != NULL) {
|
|
|
|
char const *host = gnome_vfs_uri_get_host_name (uri);
|
|
|
|
if (host != NULL) {
|
|
|
|
res = gconf_value_new (GCONF_VALUE_STRING);
|
|
|
|
gconf_value_set_string (res, host);
|
|
|
|
}
|
|
|
|
gnome_vfs_uri_unref (uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res != NULL)
|
|
|
|
return res;
|
|
|
|
return gconf_value_copy (orig);
|
|
|
|
}
|
|
|
|
|
2002-10-25 21:09:09 +00:00
|
|
|
static void
|
|
|
|
proxy_mode_radiobutton_clicked_cb (GtkWidget *widget,
|
|
|
|
GladeXML *dialog)
|
|
|
|
{
|
|
|
|
GSList *mode_group;
|
|
|
|
int mode;
|
2003-03-04 16:13:43 +00:00
|
|
|
GConfClient *client;
|
2002-10-25 21:09:09 +00:00
|
|
|
|
|
|
|
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
mode_group = g_slist_copy (gtk_radio_button_get_group
|
|
|
|
(GTK_RADIO_BUTTON (WID ("none_radiobutton"))));
|
|
|
|
mode_group = g_slist_reverse (mode_group);
|
|
|
|
mode = g_slist_index (mode_group, widget);
|
|
|
|
g_slist_free (mode_group);
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (WID ("manual_box"),
|
|
|
|
mode == PROXYMODE_MANUAL);
|
|
|
|
gtk_widget_set_sensitive (WID ("auto_box"),
|
|
|
|
mode == PROXYMODE_AUTO);
|
2003-03-04 16:13:43 +00:00
|
|
|
client = gconf_client_get_default ();
|
|
|
|
gconf_client_set_bool (client, USE_PROXY_KEY,
|
|
|
|
mode == PROXYMODE_AUTO || mode == PROXYMODE_MANUAL, NULL);
|
|
|
|
g_object_unref (client);
|
2002-10-25 21:09:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
connect_sensitivity_signals (GladeXML *dialog, GSList *mode_group)
|
|
|
|
{
|
|
|
|
for (; mode_group != NULL; mode_group = mode_group->next)
|
|
|
|
{
|
|
|
|
g_signal_connect (G_OBJECT (mode_group->data), "clicked",
|
|
|
|
G_CALLBACK(proxy_mode_radiobutton_clicked_cb),
|
|
|
|
dialog);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-22 17:49:22 +00:00
|
|
|
static void
|
|
|
|
setup_dialog (GladeXML *dialog)
|
|
|
|
{
|
|
|
|
GConfPropertyEditor *peditor;
|
2002-10-25 21:09:09 +00:00
|
|
|
GSList *mode_group;
|
|
|
|
GType mode_type = 0;
|
2003-08-27 18:50:43 +00:00
|
|
|
GConfClient *client;
|
|
|
|
gint port_value;
|
2002-10-25 21:09:09 +00:00
|
|
|
|
|
|
|
mode_type = g_enum_register_static ("NetworkPreferencesProxyType",
|
|
|
|
proxytype_values);
|
2002-04-22 17:49:22 +00:00
|
|
|
|
2003-08-27 18:50:43 +00:00
|
|
|
/* There's a bug in peditors that cause them to not initialize the entry
|
|
|
|
* correctly. */
|
|
|
|
client = gconf_client_get_default ();
|
|
|
|
|
2002-10-25 21:09:09 +00:00
|
|
|
/* Hackety hack */
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (GTK_BIN (WID ("none_radiobutton"))->child), TRUE);
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (GTK_BIN (WID ("manual_radiobutton"))->child), TRUE);
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (GTK_BIN (WID ("auto_radiobutton"))->child), TRUE);
|
|
|
|
|
|
|
|
/* Mode */
|
|
|
|
mode_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (WID ("none_radiobutton")));
|
|
|
|
connect_sensitivity_signals (dialog, mode_group);
|
2002-04-22 17:49:22 +00:00
|
|
|
|
2002-10-25 21:09:09 +00:00
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_select_radio_with_enum (NULL,
|
|
|
|
PROXY_MODE_KEY, mode_group, mode_type,
|
|
|
|
TRUE, NULL));
|
|
|
|
|
|
|
|
/* Http */
|
2003-08-27 18:50:43 +00:00
|
|
|
port_value = gconf_client_get_int (client, HTTP_PROXY_PORT_KEY, NULL);
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (WID ("http_port_spinbutton")), (gdouble) port_value);
|
2002-04-22 17:49:22 +00:00
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
|
2002-10-25 21:09:09 +00:00
|
|
|
NULL, HTTP_PROXY_HOST_KEY, WID ("http_host_entry"),
|
2002-07-10 16:37:46 +00:00
|
|
|
"conv-from-widget-cb", extract_proxy_host,
|
|
|
|
NULL));
|
2002-10-25 21:09:09 +00:00
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
|
|
|
|
NULL, HTTP_PROXY_PORT_KEY, WID ("http_port_spinbutton"),
|
|
|
|
NULL));
|
|
|
|
g_signal_connect (G_OBJECT (WID ("details_button")),
|
|
|
|
"clicked",
|
|
|
|
G_CALLBACK (cb_http_details_button_clicked),
|
|
|
|
WID ("network_dialog"));
|
2002-04-22 17:49:22 +00:00
|
|
|
|
2002-10-25 21:09:09 +00:00
|
|
|
/* Secure */
|
2003-08-27 18:50:43 +00:00
|
|
|
port_value = gconf_client_get_int (client, SECURE_PROXY_PORT_KEY, NULL);
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (WID ("secure_port_spinbutton")), (gdouble) port_value);
|
2002-10-25 21:09:09 +00:00
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
|
|
|
|
NULL, SECURE_PROXY_HOST_KEY, WID ("secure_host_entry"),
|
|
|
|
"conv-from-widget-cb", extract_proxy_host,
|
|
|
|
NULL));
|
2002-04-22 17:49:22 +00:00
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
|
2002-10-25 21:09:09 +00:00
|
|
|
NULL, SECURE_PROXY_PORT_KEY, WID ("secure_port_spinbutton"),
|
|
|
|
NULL));
|
2002-04-22 17:49:22 +00:00
|
|
|
|
2002-10-25 21:09:09 +00:00
|
|
|
/* Ftp */
|
2003-08-27 18:50:43 +00:00
|
|
|
port_value = gconf_client_get_int (client, FTP_PROXY_PORT_KEY, NULL);
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (WID ("ftp_port_spinbutton")), (gdouble) port_value);
|
2002-10-25 21:09:09 +00:00
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
|
|
|
|
NULL, FTP_PROXY_HOST_KEY, WID ("ftp_host_entry"),
|
|
|
|
"conv-from-widget-cb", extract_proxy_host,
|
|
|
|
NULL));
|
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
|
|
|
|
NULL, FTP_PROXY_PORT_KEY, WID ("ftp_port_spinbutton"),
|
|
|
|
NULL));
|
2002-04-22 17:49:22 +00:00
|
|
|
|
2002-10-25 21:09:09 +00:00
|
|
|
/* Socks */
|
2003-08-27 18:50:43 +00:00
|
|
|
port_value = gconf_client_get_int (client, SOCKS_PROXY_PORT_KEY, NULL);
|
|
|
|
gtk_spin_button_set_value (GTK_SPIN_BUTTON (WID ("socks_port_spinbutton")), (gdouble) port_value);
|
2002-04-22 17:49:22 +00:00
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
|
2002-10-25 21:09:09 +00:00
|
|
|
NULL, SOCKS_PROXY_HOST_KEY, WID ("socks_host_entry"),
|
|
|
|
"conv-from-widget-cb", extract_proxy_host,
|
|
|
|
NULL));
|
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_integer (
|
|
|
|
NULL, SOCKS_PROXY_PORT_KEY, WID ("socks_port_spinbutton"),
|
|
|
|
NULL));
|
2002-04-22 17:49:22 +00:00
|
|
|
|
2002-10-25 21:09:09 +00:00
|
|
|
/* Autoconfiguration */
|
2002-04-22 17:49:22 +00:00
|
|
|
peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_string (
|
2002-10-25 21:09:09 +00:00
|
|
|
NULL, PROXY_AUTOCONFIG_URL_KEY, WID ("autoconfig_entry"),
|
|
|
|
NULL));
|
2002-04-22 17:49:22 +00:00
|
|
|
|
|
|
|
g_signal_connect (WID ("network_dialog"), "response",
|
2002-05-09 17:40:48 +00:00
|
|
|
G_CALLBACK (cb_dialog_response), NULL);
|
2002-04-22 17:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char **argv)
|
|
|
|
{
|
|
|
|
GladeXML *dialog;
|
|
|
|
GConfClient *client;
|
2002-07-10 16:37:46 +00:00
|
|
|
GtkWidget *widget;
|
2002-04-22 17:49:22 +00:00
|
|
|
|
|
|
|
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
|
|
|
|
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
|
|
textdomain (GETTEXT_PACKAGE);
|
|
|
|
|
2002-05-26 16:11:37 +00:00
|
|
|
gnome_program_init ("gnome-network-preferences", VERSION,
|
|
|
|
LIBGNOMEUI_MODULE,
|
2002-04-22 17:49:22 +00:00
|
|
|
argc, argv, GNOME_PARAM_NONE);
|
|
|
|
|
|
|
|
client = gconf_client_get_default ();
|
|
|
|
gconf_client_add_dir (client, "/system/gnome-vfs",
|
|
|
|
GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
|
2003-02-05 07:04:56 +00:00
|
|
|
gconf_client_add_dir (client, "/system/http_proxy",
|
|
|
|
GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
|
|
|
|
gconf_client_add_dir (client, "/system/proxy",
|
|
|
|
GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
|
2002-04-22 17:49:22 +00:00
|
|
|
|
|
|
|
dialog = glade_xml_new (GNOMECC_DATA_DIR "/interfaces/gnome-network-preferences.glade",
|
|
|
|
"network_dialog", NULL);
|
|
|
|
|
|
|
|
setup_dialog (dialog);
|
2002-07-10 16:37:46 +00:00
|
|
|
widget = WID ("network_dialog");
|
2004-04-15 18:32:22 +00:00
|
|
|
capplet_set_icon (widget, "stock_proxy");
|
2002-07-10 16:37:46 +00:00
|
|
|
gtk_widget_show_all (widget);
|
2002-04-22 17:49:22 +00:00
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
g_object_unref (client);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|