Index: capplets/network/gnome-network-preferences.glade =================================================================== --- capplets/network/gnome-network-preferences.glade (revision 7885) +++ capplets/network/gnome-network-preferences.glade (working copy) @@ -85,6 +85,25 @@ 18 + + True + True + <b>Use the s_ystem's proxy settings</b> + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + False + False + + + + True True @@ -95,6 +114,7 @@ False False True + system_radiobutton 0 @@ -126,7 +146,7 @@ False False True - none_radiobutton + system_radiobutton 0 @@ -669,7 +689,7 @@ False False True - none_radiobutton + system_radiobutton 0 Index: capplets/network/gnome-network-preferences.c =================================================================== --- capplets/network/gnome-network-preferences.c (revision 7885) +++ capplets/network/gnome-network-preferences.c (working copy) @@ -32,20 +32,12 @@ #include "capplet-util.h" #include "gconf-property-editor.h" -enum ProxyMode -{ - PROXYMODE_NONE, - PROXYMODE_MANUAL, - PROXYMODE_AUTO -}; +/* Novell extension */ +#define KEY_USE_SYSTEM_SETTINGS "/system/proxy/use_system_settings" /* string */ +#define VAL_USE_SYSTEM_SETTINGS_ONLY_IF_NOT_SET "only_if_mode_not_set" +#define VAL_USE_SYSTEM_SETTINGS_SYSTEM_VALUES "system_values" +#define VAL_USE_SYSTEM_SETTINGS_USER_VALUES "user_values" -static GEnumValue proxytype_values[] = { - { PROXYMODE_NONE, "PROXYMODE_NONE", "none"}, - { PROXYMODE_MANUAL, "PROXYMODE_MANUAL", "manual"}, - { PROXYMODE_AUTO, "PROXYMODE_AUTO", "auto"}, - { 0, NULL, NULL } -}; - #define USE_PROXY_KEY "/system/http_proxy/use_http_proxy" #define USE_SAME_PROXY_KEY "/system/http_proxy/use_same_proxy" #define HTTP_PROXY_HOST_KEY "/system/http_proxy/host" @@ -363,29 +355,40 @@ proxy_mode_radiobutton_clicked_cb (GtkWidget *widget, GladeXML *dialog) { - GSList *mode_group; - int mode; - GConfClient *client; - - 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 ("same_proxy_checkbutton"), - mode == PROXYMODE_MANUAL); - gtk_widget_set_sensitive (WID ("auto_box"), - mode == PROXYMODE_AUTO); + GConfClient *client; + gboolean manual_box_sensitive, auto_box_sensitive; + + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget))) + return; + client = gconf_client_get_default (); - gconf_client_set_bool (client, USE_PROXY_KEY, - mode == PROXYMODE_AUTO || mode == PROXYMODE_MANUAL, NULL); - g_object_unref (client); + manual_box_sensitive = auto_box_sensitive = FALSE; + + if (widget == WID ("system_radiobutton")) { + gconf_client_set_string (client, KEY_USE_SYSTEM_SETTINGS, VAL_USE_SYSTEM_SETTINGS_SYSTEM_VALUES, NULL); + } else if (widget == WID ("none_radiobutton")) { + gconf_client_set_string (client, KEY_USE_SYSTEM_SETTINGS, VAL_USE_SYSTEM_SETTINGS_USER_VALUES, NULL); + gconf_client_set_string (client, PROXY_MODE_KEY, "none", NULL); + gconf_client_set_bool (client, USE_PROXY_KEY, FALSE, NULL); + } else if (widget == WID ("manual_radiobutton")) { + manual_box_sensitive = TRUE; + + gconf_client_set_string (client, KEY_USE_SYSTEM_SETTINGS, VAL_USE_SYSTEM_SETTINGS_USER_VALUES, NULL); + gconf_client_set_string (client, PROXY_MODE_KEY, "manual", NULL); + gconf_client_set_bool (client, USE_PROXY_KEY, TRUE, NULL); + } else if (widget == WID ("auto_radiobutton")) { + auto_box_sensitive = TRUE; + + gconf_client_set_string (client, KEY_USE_SYSTEM_SETTINGS, VAL_USE_SYSTEM_SETTINGS_USER_VALUES, NULL); + gconf_client_set_string (client, PROXY_MODE_KEY, "auto", NULL); + gconf_client_set_bool (client, USE_PROXY_KEY, TRUE, NULL); + } + + gtk_widget_set_sensitive (WID ("manual_box"), manual_box_sensitive); + gtk_widget_set_sensitive (WID ("same_proxy_checkbutton"), manual_box_sensitive); + gtk_widget_set_sensitive (WID ("auto_box"), auto_box_sensitive); + + g_object_unref (client); } static void @@ -399,34 +401,96 @@ } } +static GtkWidget * +get_radio_for_mode (GladeXML *dialog, const char *mode_str) +{ + if (!mode_str) + return WID ("none_radiobutton"); + else if (strcmp (mode_str, "none") == 0) + return WID ("none_radiobutton"); + else if (strcmp (mode_str, "manual") == 0) + return WID ("manual_radiobutton"); + else if (strcmp (mode_str, "auto") == 0) + return WID ("auto_radiobutton"); + else + return WID ("none_radiobutton"); +} + static void +mode_set_initial_value (GladeXML *dialog, GConfClient *client) +{ + char *use_system_settings; + GConfValue *mode_value; + gboolean use_system_if_mode_not_set; + gboolean use_mode; + GtkWidget *radiobutton; + + radiobutton = NULL; + + use_system_settings = gconf_client_get_string (client, KEY_USE_SYSTEM_SETTINGS, NULL); + mode_value = gconf_client_get_without_default (client, PROXY_MODE_KEY, NULL); + + use_system_if_mode_not_set = FALSE; + use_mode = FALSE; + + if (!use_system_settings) + use_system_if_mode_not_set = TRUE; + else { + if (strcmp (use_system_settings, VAL_USE_SYSTEM_SETTINGS_ONLY_IF_NOT_SET) == 0) + use_system_if_mode_not_set = TRUE; + else if (strcmp (use_system_settings, VAL_USE_SYSTEM_SETTINGS_SYSTEM_VALUES) == 0) + radiobutton = WID ("system_radiobutton"); + else if (strcmp (use_system_settings, VAL_USE_SYSTEM_SETTINGS_USER_VALUES) == 0) + use_mode = TRUE; + + g_free (use_system_settings); + } + + if (use_system_if_mode_not_set) { + if (mode_value) + use_mode = TRUE; + else + radiobutton = WID ("system_radiobutton"); + } + + if (use_mode) { + if (!mode_value || mode_value->type != GCONF_VALUE_STRING) + radiobutton = WID ("none_radiobutton"); + else + radiobutton = get_radio_for_mode (dialog, gconf_value_get_string (mode_value)); + } + + if (radiobutton) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton), TRUE); + + if (mode_value) + gconf_value_free (mode_value); +} + +static void setup_dialog (GladeXML *dialog) { GConfPropertyEditor *peditor; GSList *mode_group; - GType mode_type = 0; GConfClient *client; gint port_value; - mode_type = g_enum_register_static ("NetworkPreferencesProxyType", - proxytype_values); /* There's a bug in peditors that cause them to not initialize the entry * correctly. */ client = gconf_client_get_default (); /* Hackety hack */ + gtk_label_set_use_markup (GTK_LABEL (GTK_BIN (WID ("system_radiobutton"))->child), TRUE); 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"))); + mode_set_initial_value (dialog, client); + mode_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (WID ("system_radiobutton"))); connect_sensitivity_signals (dialog, mode_group); - peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_select_radio_with_enum (NULL, - PROXY_MODE_KEY, mode_group, mode_type, - TRUE, NULL)); /* Use same proxy for all protocols */ peditor = GCONF_PROPERTY_EDITOR (gconf_peditor_new_boolean (NULL,