From c26e14518ea66491dba2c2dcf356bbab865f68ef Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 12 Jul 2012 14:07:54 +0100 Subject: [PATCH] network: Split the proxy parts from the .c and .ui file A source file with 4k lines of code is not understandable, and the glade file was becoming quite a challenge for glade. To add more features we need to split things up just to keep them maintainable. This is the first patch that just splits out the proxy bits. Other device types will follow in the next few days. --- panels/network/Makefile.am | 6 +- panels/network/cc-network-panel.c | 351 ++++-------------------- panels/network/net-device.c | 4 +- panels/network/net-object.c | 20 ++ panels/network/net-object.h | 17 +- panels/network/net-proxy.c | 388 +++++++++++++++++++++++++++ panels/network/net-proxy.h | 59 +++++ panels/network/network-proxy.ui | 427 ++++++++++++++++++++++++++++++ panels/network/network.ui | 415 ----------------------------- po/POTFILES.in | 2 + 10 files changed, 974 insertions(+), 715 deletions(-) create mode 100644 panels/network/net-proxy.c create mode 100644 panels/network/net-proxy.h create mode 100644 panels/network/network-proxy.ui diff --git a/panels/network/Makefile.am b/panels/network/Makefile.am index 23e812d78..93da733bb 100644 --- a/panels/network/Makefile.am +++ b/panels/network/Makefile.am @@ -22,6 +22,8 @@ libnetwork_la_SOURCES = \ net-device.h \ net-vpn.c \ net-vpn.h \ + net-proxy.c \ + net-proxy.h \ panel-cell-renderer-mode.c \ panel-cell-renderer-mode.h \ panel-cell-renderer-security.c \ @@ -37,7 +39,9 @@ libnetwork_la_LIBADD = $(PANEL_LIBS) $(NETWORK_PANEL_LIBS) $(NETWORK_MANAGER_LIB libnetwork_la_LDFLAGS = $(PANEL_LDFLAGS) uidir = $(pkgdatadir)/ui -dist_ui_DATA = network.ui +dist_ui_DATA = \ + network-proxy.ui \ + network.ui @INTLTOOL_DESKTOP_RULE@ diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c index 0d000de84..c7a335fd8 100644 --- a/panels/network/cc-network-panel.c +++ b/panels/network/cc-network-panel.c @@ -47,6 +47,7 @@ #include "net-object.h" #include "net-device.h" +#include "net-proxy.h" #include "net-vpn.h" #include "panel-common.h" @@ -73,7 +74,6 @@ typedef enum { struct _CcNetworkPanelPrivate { GCancellable *cancellable; - GSettings *proxy_settings; GtkBuilder *builder; NMClient *client; NMRemoteSettings *remote_settings; @@ -197,8 +197,6 @@ cc_network_panel_dispose (GObject *object) { CcNetworkPanelPrivate *priv = CC_NETWORK_PANEL (object)->priv; - g_clear_object (&priv->proxy_settings); - if (priv->cancellable != NULL) g_cancellable_cancel (priv->cancellable); @@ -263,59 +261,6 @@ cc_network_panel_class_finalize (CcNetworkPanelClass *klass) { } -static void -check_wpad_warning (CcNetworkPanel *panel) -{ - GtkWidget *widget; - gchar *autoconfig_url = NULL; - GString *string = NULL; - gboolean ret = FALSE; - guint mode; - - string = g_string_new (""); - - /* check we're using 'Automatic' */ - mode = g_settings_get_enum (panel->priv->proxy_settings, "mode"); - if (mode != 2) - goto out; - - /* see if the PAC is blank */ - autoconfig_url = g_settings_get_string (panel->priv->proxy_settings, - "autoconfig-url"); - ret = autoconfig_url == NULL || - autoconfig_url[0] == '\0'; - if (!ret) - goto out; - - g_string_append (string, ""); - - /* TRANSLATORS: this is when the use leaves the PAC textbox blank */ - g_string_append (string, _("Web Proxy Autodiscovery is used when a Configuration URL is not provided.")); - - g_string_append (string, "\n"); - - /* TRANSLATORS: WPAD is bad: if you enable it on an untrusted - * network, then anyone else on that network can tell your - * machine that it should proxy all of your web traffic - * through them. */ - g_string_append (string, _("This is not recommended for untrusted public networks.")); - g_string_append (string, ""); -out: - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "label_proxy_warning")); - gtk_label_set_markup (GTK_LABEL (widget), string->str); - g_free (autoconfig_url); - g_string_free (string, TRUE); -} - -static void -panel_settings_changed (GSettings *settings, - const gchar *key, - CcNetworkPanel *panel) -{ - check_wpad_warning (panel); -} - static NetObject * get_selected_object (CcNetworkPanel *panel) { @@ -339,117 +284,6 @@ get_selected_object (CcNetworkPanel *panel) return object; } -static void -panel_proxy_mode_combo_setup_widgets (CcNetworkPanel *panel, guint value) -{ - GtkWidget *widget; - - /* hide or show the PAC text box */ - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "heading_proxy_url")); - gtk_widget_set_visible (widget, value == 2); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "entry_proxy_url")); - gtk_widget_set_visible (widget, value == 2); - - /* hide or show the manual entry text boxes */ - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "heading_proxy_http")); - gtk_widget_set_visible (widget, value == 1); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "entry_proxy_http")); - gtk_widget_set_visible (widget, value == 1); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "spinbutton_proxy_http")); - gtk_widget_set_visible (widget, value == 1); - - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "heading_proxy_https")); - gtk_widget_set_visible (widget, value == 1); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "entry_proxy_https")); - gtk_widget_set_visible (widget, value == 1); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "spinbutton_proxy_https")); - gtk_widget_set_visible (widget, value == 1); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "heading_proxy_ftp")); - gtk_widget_set_visible (widget, value == 1); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "entry_proxy_ftp")); - gtk_widget_set_visible (widget, value == 1); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "spinbutton_proxy_ftp")); - gtk_widget_set_visible (widget, value == 1); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "heading_proxy_socks")); - gtk_widget_set_visible (widget, value == 1); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "entry_proxy_socks")); - gtk_widget_set_visible (widget, value == 1); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "spinbutton_proxy_socks")); - gtk_widget_set_visible (widget, value == 1); - - /* perhaps show the wpad warning */ - check_wpad_warning (panel); -} - -static void -panel_proxy_mode_combo_changed_cb (GtkWidget *widget, CcNetworkPanel *panel) -{ - gboolean ret; - gint value; - GtkTreeIter iter; - GtkTreeModel *model; - - /* no selection */ - ret = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter); - if (!ret) - return; - - /* get entry */ - model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); - gtk_tree_model_get (model, &iter, - 1, &value, - -1); - - /* set */ - g_settings_set_enum (panel->priv->proxy_settings, "mode", value); - - /* hide or show the correct widgets */ - panel_proxy_mode_combo_setup_widgets (panel, value); -} - -static void -panel_set_value_for_combo (CcNetworkPanel *panel, GtkComboBox *combo_box, gint value) -{ - gboolean ret; - gint value_tmp; - GtkTreeIter iter; - GtkTreeModel *model; - - /* get entry */ - model = gtk_combo_box_get_model (combo_box); - ret = gtk_tree_model_get_iter_first (model, &iter); - if (!ret) - return; - - /* try to make the UI match the setting */ - do { - gtk_tree_model_get (model, &iter, - 1, &value_tmp, - -1); - if (value == value_tmp) { - gtk_combo_box_set_active_iter (combo_box, &iter); - break; - } - } while (gtk_tree_model_iter_next (model, &iter)); - - /* hide or show the correct widgets */ - panel_proxy_mode_combo_setup_widgets (panel, value); -} - static void select_first_device (CcNetworkPanel *panel) { @@ -2376,6 +2210,41 @@ nm_device_refresh_vpn_ui (CcNetworkPanel *panel, NetVpn *vpn) net_vpn_get_password (vpn)); } +static void +panel_set_notebook_page_for_object (CcNetworkPanel *panel, NetObject *object) +{ + CcNetworkPanelPrivate *priv = panel->priv; + const gchar *id_tmp; + const gchar *needle; + GList *l; + GList *panels; + GtkNotebook *notebook; + GtkWidget *widget; + guint i = 0; + + /* find the widget in the notebook that matches the object ID */ + needle = net_object_get_id (object); + notebook = GTK_NOTEBOOK (gtk_builder_get_object (priv->builder, + "notebook_types")); + panels = gtk_container_get_children (GTK_CONTAINER (notebook)); + for (l = panels; l != NULL; l = l->next) { + widget = GTK_WIDGET (l->data); + id_tmp = g_object_get_data (G_OBJECT (widget), "NetObject::id"); + if (g_strcmp0 (needle, id_tmp) == 0) { + gtk_notebook_set_current_page (notebook, i); + + /* object is deletable? */ + widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, + "remove_toolbutton")); + gtk_widget_set_sensitive (widget, + net_object_get_removable (object)); + break; + } + i++; + } + g_list_free (panels); +} + static gboolean refresh_ui_idle (gpointer data) { @@ -2399,42 +2268,12 @@ refresh_ui_idle (gpointer data) object = get_selected_object (panel); - /* this is the proxy settings device */ - if (object == NULL) { - - /* set header to something sane */ - widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, - "image_proxy_device")); - gtk_image_set_from_icon_name (GTK_IMAGE (widget), - "preferences-system-network", - GTK_ICON_SIZE_DIALOG); - widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, - "label_proxy_device")); - gtk_label_set_label (GTK_LABEL (widget), - _("Proxy")); - widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, - "label_proxy_status")); - gtk_label_set_label (GTK_LABEL (widget), ""); - - widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, - "notebook_types")); - gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 2); - - /* hide the switch until we get some more detail in the mockup */ - widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, - "device_proxy_off_switch")); - if (widget != NULL) - gtk_widget_hide (widget); - - /* we shoulnd't be able to delete the proxy device */ - widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, - "remove_toolbutton")); - gtk_widget_set_sensitive (widget, FALSE); - goto out; - } + /* do we have a new-style NetObject-style panel widget */ + panel_set_notebook_page_for_object (panel, object); /* VPN */ if (NET_IS_VPN (object)) { + nm_device_refresh_vpn_ui (panel, NET_VPN (object)); /* we're able to remove the VPN connection */ @@ -2482,20 +2321,35 @@ panel_add_proxy_device (CcNetworkPanel *panel) gchar *title; GtkListStore *liststore_devices; GtkTreeIter iter; + NetProxy *proxy; + GtkWidget *widget; + GtkNotebook *notebook; + GtkSizeGroup *size_group; + /* add proxy to notebook */ + proxy = net_proxy_new (); + notebook = GTK_NOTEBOOK (gtk_builder_get_object (panel->priv->builder, + "notebook_types")); + size_group = GTK_SIZE_GROUP (gtk_builder_get_object (panel->priv->builder, + "sizegroup1")); + net_object_add_to_notebook (NET_OBJECT (proxy), + notebook, + size_group); + + /* add proxy to device list */ liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder, "liststore_devices")); title = g_strdup_printf ("%s", _("Network proxy")); - gtk_list_store_append (liststore_devices, &iter); gtk_list_store_set (liststore_devices, &iter, PANEL_DEVICES_COLUMN_ICON, "preferences-system-network", PANEL_DEVICES_COLUMN_TITLE, title, PANEL_DEVICES_COLUMN_SORT, "9", - PANEL_DEVICES_COLUMN_OBJECT, NULL, + PANEL_DEVICES_COLUMN_OBJECT, proxy, -1); g_free (title); + g_object_unref (proxy); } static void @@ -3678,9 +3532,6 @@ cc_network_panel_init (CcNetworkPanel *panel) { DBusGConnection *bus = NULL; GError *error = NULL; - gint value; - GSettings *settings_tmp; - GtkAdjustment *adjustment; GtkCellRenderer *renderer; GtkComboBox *combobox; GtkStyleContext *context; @@ -3703,90 +3554,6 @@ cc_network_panel_init (CcNetworkPanel *panel) panel->priv->cancellable = g_cancellable_new (); - panel->priv->proxy_settings = g_settings_new ("org.gnome.system.proxy"); - g_signal_connect (panel->priv->proxy_settings, - "changed", - G_CALLBACK (panel_settings_changed), - panel); - - /* explicitly set this to false as the panel has no way of - * linking the http and https proxies them together */ - g_settings_set_boolean (panel->priv->proxy_settings, - "use-same-proxy", - FALSE); - - /* actions */ - value = g_settings_get_enum (panel->priv->proxy_settings, "mode"); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "combobox_proxy_mode")); - panel_set_value_for_combo (panel, GTK_COMBO_BOX (widget), value); - g_signal_connect (widget, "changed", - G_CALLBACK (panel_proxy_mode_combo_changed_cb), - panel); - - /* bind the proxy values */ - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "entry_proxy_url")); - g_settings_bind (panel->priv->proxy_settings, "autoconfig-url", - widget, "text", - G_SETTINGS_BIND_DEFAULT); - - /* bind the HTTP proxy values */ - settings_tmp = g_settings_get_child (panel->priv->proxy_settings, "http"); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "entry_proxy_http")); - g_settings_bind (settings_tmp, "host", - widget, "text", - G_SETTINGS_BIND_DEFAULT); - adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder, - "adjustment_proxy_port_http")); - g_settings_bind (settings_tmp, "port", - adjustment, "value", - G_SETTINGS_BIND_DEFAULT); - g_object_unref (settings_tmp); - - /* bind the HTTPS proxy values */ - settings_tmp = g_settings_get_child (panel->priv->proxy_settings, "https"); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "entry_proxy_https")); - g_settings_bind (settings_tmp, "host", - widget, "text", - G_SETTINGS_BIND_DEFAULT); - adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder, - "adjustment_proxy_port_https")); - g_settings_bind (settings_tmp, "port", - adjustment, "value", - G_SETTINGS_BIND_DEFAULT); - g_object_unref (settings_tmp); - - /* bind the FTP proxy values */ - settings_tmp = g_settings_get_child (panel->priv->proxy_settings, "ftp"); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "entry_proxy_ftp")); - g_settings_bind (settings_tmp, "host", - widget, "text", - G_SETTINGS_BIND_DEFAULT); - adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder, - "adjustment_proxy_port_ftp")); - g_settings_bind (settings_tmp, "port", - adjustment, "value", - G_SETTINGS_BIND_DEFAULT); - g_object_unref (settings_tmp); - - /* bind the SOCKS proxy values */ - settings_tmp = g_settings_get_child (panel->priv->proxy_settings, "socks"); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "entry_proxy_socks")); - g_settings_bind (settings_tmp, "host", - widget, "text", - G_SETTINGS_BIND_DEFAULT); - adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (panel->priv->builder, - "adjustment_proxy_port_socks")); - g_settings_bind (settings_tmp, "port", - adjustment, "value", - G_SETTINGS_BIND_DEFAULT); - g_object_unref (settings_tmp); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "treeview_devices")); panel_add_devices_columns (panel, GTK_TREE_VIEW (widget)); @@ -3841,7 +3608,6 @@ cc_network_panel_init (CcNetworkPanel *panel) panel, NULL); - renderer = panel_cell_renderer_mode_new (); gtk_cell_renderer_set_padding (renderer, 4, 0); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), @@ -3896,10 +3662,6 @@ cc_network_panel_init (CcNetworkPanel *panel) "device_vpn_off_switch")); g_signal_connect (widget, "notify::active", G_CALLBACK (device_off_toggled), panel); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, - "device_proxy_off_switch")); - g_signal_connect (widget, "notify::active", - G_CALLBACK (device_off_toggled), panel); g_signal_connect (panel->priv->client, "notify::wireless-enabled", G_CALLBACK (wireless_enabled_toggled), panel); @@ -3917,7 +3679,6 @@ cc_network_panel_init (CcNetworkPanel *panel) g_signal_connect (widget, "clicked", G_CALLBACK (stop_hotspot), panel); - widget = GTK_WIDGET (gtk_builder_get_object (panel->priv->builder, "button_wired_options")); g_signal_connect (widget, "clicked", diff --git a/panels/network/net-device.c b/panels/network/net-device.c index bcb725329..911744d28 100644 --- a/panels/network/net-device.c +++ b/panels/network/net-device.c @@ -91,7 +91,9 @@ NetDevice * net_device_new (void) { NetDevice *device; - device = g_object_new (NET_TYPE_DEVICE, NULL); + device = g_object_new (NET_TYPE_DEVICE, + "removable", TRUE, + NULL); return NET_DEVICE (device); } diff --git a/panels/network/net-object.c b/panels/network/net-object.c index 817ce9cf2..deba1cffc 100644 --- a/panels/network/net-object.c +++ b/panels/network/net-object.c @@ -110,6 +110,26 @@ net_object_set_title (NetObject *object, const gchar *title) object->priv->title = g_strdup (title); } +GtkWidget * +net_object_add_to_notebook (NetObject *object, + GtkNotebook *notebook, + GtkSizeGroup *heading_size_group) +{ + GtkWidget *widget; + NetObjectClass *klass = NET_OBJECT_GET_CLASS (object); + if (klass->add_to_notebook != NULL) { + widget = klass->add_to_notebook (object, + notebook, + heading_size_group); + g_object_set_data_full (G_OBJECT (widget), + "NetObject::id", + g_strdup (object->priv->id), + g_free); + return widget; + } + return NULL; +} + /** * net_object_get_property: **/ diff --git a/panels/network/net-object.h b/panels/network/net-object.h index 95184618a..ad8c22cca 100644 --- a/panels/network/net-object.h +++ b/panels/network/net-object.h @@ -23,6 +23,7 @@ #define __NET_OBJECT_H #include +#include G_BEGIN_DECLS @@ -45,9 +46,16 @@ struct _NetObject struct _NetObjectClass { - GObjectClass parent_class; - void (* changed) (NetObject *object); - void (* removed) (NetObject *object); + GObjectClass parent_class; + + /* vtable */ + GtkWidget *(*add_to_notebook) (NetObject *object, + GtkNotebook *notebook, + GtkSizeGroup *heading_size_group); + + /* signal */ + void (* changed) (NetObject *object); + void (* removed) (NetObject *object); }; GType net_object_get_type (void); @@ -60,6 +68,9 @@ void net_object_set_title (NetObject *object, const gchar *title); void net_object_emit_changed (NetObject *object); void net_object_emit_removed (NetObject *object); +GtkWidget *net_object_add_to_notebook (NetObject *object, + GtkNotebook *notebook, + GtkSizeGroup *heading_size_group); gboolean net_object_get_removable (NetObject *object); void net_object_set_removable (NetObject *object, gboolean removable); diff --git a/panels/network/net-proxy.c b/panels/network/net-proxy.c new file mode 100644 index 000000000..6fd238825 --- /dev/null +++ b/panels/network/net-proxy.c @@ -0,0 +1,388 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2011-2012 Richard Hughes + * + * Licensed under the GNU General Public License Version 2 + * + * 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, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include +#include +#include + +#include "net-proxy.h" + +#define NET_PROXY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NET_TYPE_PROXY, NetProxyPrivate)) + +struct _NetProxyPrivate +{ + GSettings *settings; + GtkBuilder *builder; +}; + +G_DEFINE_TYPE (NetProxy, net_proxy, NET_TYPE_OBJECT) + +static void +check_wpad_warning (NetProxy *proxy) +{ + GtkWidget *widget; + gchar *autoconfig_url = NULL; + GString *string = NULL; + gboolean ret = FALSE; + guint mode; + + string = g_string_new (""); + + /* check we're using 'Automatic' */ + mode = g_settings_get_enum (proxy->priv->settings, "mode"); + if (mode != 2) + goto out; + + /* see if the PAC is blank */ + autoconfig_url = g_settings_get_string (proxy->priv->settings, + "autoconfig-url"); + ret = autoconfig_url == NULL || + autoconfig_url[0] == '\0'; + if (!ret) + goto out; + + g_string_append (string, ""); + + /* TRANSLATORS: this is when the use leaves the PAC textbox blank */ + g_string_append (string, _("Web Proxy Autodiscovery is used when a Configuration URL is not provided.")); + + g_string_append (string, "\n"); + + /* TRANSLATORS: WPAD is bad: if you enable it on an untrusted + * network, then anyone else on that network can tell your + * machine that it should proxy all of your web traffic + * through them. */ + g_string_append (string, _("This is not recommended for untrusted public networks.")); + g_string_append (string, ""); +out: + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "label_proxy_warning")); + gtk_label_set_markup (GTK_LABEL (widget), string->str); + g_free (autoconfig_url); + g_string_free (string, TRUE); +} + +static void +settings_changed_cb (GSettings *settings, + const gchar *key, + NetProxy *proxy) +{ + check_wpad_warning (proxy); +} + +static void +panel_proxy_mode_combo_setup_widgets (NetProxy *proxy, guint value) +{ + GtkWidget *widget; + + /* hide or show the PAC text box */ + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "heading_proxy_url")); + gtk_widget_set_visible (widget, value == 2); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "entry_proxy_url")); + gtk_widget_set_visible (widget, value == 2); + + /* hide or show the manual entry text boxes */ + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "heading_proxy_http")); + gtk_widget_set_visible (widget, value == 1); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "entry_proxy_http")); + gtk_widget_set_visible (widget, value == 1); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "spinbutton_proxy_http")); + gtk_widget_set_visible (widget, value == 1); + + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "heading_proxy_https")); + gtk_widget_set_visible (widget, value == 1); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "entry_proxy_https")); + gtk_widget_set_visible (widget, value == 1); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "spinbutton_proxy_https")); + gtk_widget_set_visible (widget, value == 1); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "heading_proxy_ftp")); + gtk_widget_set_visible (widget, value == 1); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "entry_proxy_ftp")); + gtk_widget_set_visible (widget, value == 1); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "spinbutton_proxy_ftp")); + gtk_widget_set_visible (widget, value == 1); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "heading_proxy_socks")); + gtk_widget_set_visible (widget, value == 1); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "entry_proxy_socks")); + gtk_widget_set_visible (widget, value == 1); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "spinbutton_proxy_socks")); + gtk_widget_set_visible (widget, value == 1); + + /* perhaps show the wpad warning */ + check_wpad_warning (proxy); +} + +static void +panel_set_value_for_combo (NetProxy *proxy, GtkComboBox *combo_box, gint value) +{ + gboolean ret; + gint value_tmp; + GtkTreeIter iter; + GtkTreeModel *model; + + /* get entry */ + model = gtk_combo_box_get_model (combo_box); + ret = gtk_tree_model_get_iter_first (model, &iter); + if (!ret) + return; + + /* try to make the UI match the setting */ + do { + gtk_tree_model_get (model, &iter, + 1, &value_tmp, + -1); + if (value == value_tmp) { + gtk_combo_box_set_active_iter (combo_box, &iter); + break; + } + } while (gtk_tree_model_iter_next (model, &iter)); + + /* hide or show the correct widgets */ + panel_proxy_mode_combo_setup_widgets (proxy, value); +} + +static void +panel_proxy_mode_combo_changed_cb (GtkWidget *widget, NetProxy *proxy) +{ + gboolean ret; + gint value; + GtkTreeIter iter; + GtkTreeModel *model; + + /* no selection */ + ret = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter); + if (!ret) + return; + + /* get entry */ + model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); + gtk_tree_model_get (model, &iter, + 1, &value, + -1); + + /* set */ + g_settings_set_enum (proxy->priv->settings, "mode", value); + + /* hide or show the correct widgets */ + panel_proxy_mode_combo_setup_widgets (proxy, value); +} + +static GtkWidget * +net_proxy_add_to_notebook (NetObject *object, + GtkNotebook *notebook, + GtkSizeGroup *heading_size_group) +{ + GtkWidget *widget; + GtkWindow *window; + NetProxy *proxy = NET_PROXY (object); + + /* add widgets to size group */ + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "heading_proxy_method")); + gtk_size_group_add_widget (heading_size_group, widget); + + /* reparent */ + window = GTK_WINDOW (gtk_builder_get_object (proxy->priv->builder, + "window_tmp")); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "grid5")); + g_object_ref (widget); + gtk_container_remove (GTK_CONTAINER (window), widget); + gtk_notebook_append_page (notebook, widget, NULL); + g_object_unref (widget); + return widget; +} + +static void +net_proxy_finalize (GObject *object) +{ + NetProxy *proxy = NET_PROXY (object); + NetProxyPrivate *priv = proxy->priv; + + g_clear_object (&priv->settings); + g_clear_object (&priv->builder); + + G_OBJECT_CLASS (net_proxy_parent_class)->finalize (object); +} + +static void +net_proxy_class_init (NetProxyClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NetObjectClass *parent_class = NET_OBJECT_CLASS (klass); + + object_class->finalize = net_proxy_finalize; + parent_class->add_to_notebook = net_proxy_add_to_notebook; + g_type_class_add_private (klass, sizeof (NetProxyPrivate)); +} + +static void +net_proxy_init (NetProxy *proxy) +{ + GError *error = NULL; + gint value; + GSettings *settings_tmp; + GtkAdjustment *adjustment; + GtkWidget *widget; + + proxy->priv = NET_PROXY_GET_PRIVATE (proxy); + + proxy->priv->builder = gtk_builder_new (); + gtk_builder_add_from_file (proxy->priv->builder, + GNOMECC_UI_DIR "/network-proxy.ui", + &error); + if (error != NULL) { + g_warning ("Could not load interface file: %s", error->message); + g_error_free (error); + return; + } + + proxy->priv->settings = g_settings_new ("org.gnome.system.proxy"); + g_signal_connect (proxy->priv->settings, + "changed", + G_CALLBACK (settings_changed_cb), + proxy); + + /* explicitly set this to false as the panel has no way of + * linking the http and https proxies them together */ + g_settings_set_boolean (proxy->priv->settings, + "use-same-proxy", + FALSE); + + /* actions */ + value = g_settings_get_enum (proxy->priv->settings, "mode"); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "combobox_proxy_mode")); + panel_set_value_for_combo (proxy, GTK_COMBO_BOX (widget), value); + g_signal_connect (widget, "changed", + G_CALLBACK (panel_proxy_mode_combo_changed_cb), + proxy); + + /* bind the proxy values */ + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "entry_proxy_url")); + g_settings_bind (proxy->priv->settings, "autoconfig-url", + widget, "text", + G_SETTINGS_BIND_DEFAULT); + + /* bind the HTTP proxy values */ + settings_tmp = g_settings_get_child (proxy->priv->settings, "http"); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "entry_proxy_http")); + g_settings_bind (settings_tmp, "host", + widget, "text", + G_SETTINGS_BIND_DEFAULT); + adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (proxy->priv->builder, + "adjustment_proxy_port_http")); + g_settings_bind (settings_tmp, "port", + adjustment, "value", + G_SETTINGS_BIND_DEFAULT); + g_object_unref (settings_tmp); + + /* bind the HTTPS proxy values */ + settings_tmp = g_settings_get_child (proxy->priv->settings, "https"); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "entry_proxy_https")); + g_settings_bind (settings_tmp, "host", + widget, "text", + G_SETTINGS_BIND_DEFAULT); + adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (proxy->priv->builder, + "adjustment_proxy_port_https")); + g_settings_bind (settings_tmp, "port", + adjustment, "value", + G_SETTINGS_BIND_DEFAULT); + g_object_unref (settings_tmp); + + /* bind the FTP proxy values */ + settings_tmp = g_settings_get_child (proxy->priv->settings, "ftp"); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "entry_proxy_ftp")); + g_settings_bind (settings_tmp, "host", + widget, "text", + G_SETTINGS_BIND_DEFAULT); + adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (proxy->priv->builder, + "adjustment_proxy_port_ftp")); + g_settings_bind (settings_tmp, "port", + adjustment, "value", + G_SETTINGS_BIND_DEFAULT); + g_object_unref (settings_tmp); + + /* bind the SOCKS proxy values */ + settings_tmp = g_settings_get_child (proxy->priv->settings, "socks"); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "entry_proxy_socks")); + g_settings_bind (settings_tmp, "host", + widget, "text", + G_SETTINGS_BIND_DEFAULT); + adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (proxy->priv->builder, + "adjustment_proxy_port_socks")); + g_settings_bind (settings_tmp, "port", + adjustment, "value", + G_SETTINGS_BIND_DEFAULT); + g_object_unref (settings_tmp); + + /* set header to something sane */ + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "image_proxy_device")); + gtk_image_set_from_icon_name (GTK_IMAGE (widget), + "preferences-system-network", + GTK_ICON_SIZE_DIALOG); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "label_proxy_device")); + gtk_label_set_label (GTK_LABEL (widget), + _("Proxy")); + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "label_proxy_status")); + gtk_label_set_label (GTK_LABEL (widget), ""); + + /* hide the switch until we get some more detail in the mockup */ + widget = GTK_WIDGET (gtk_builder_get_object (proxy->priv->builder, + "device_proxy_off_switch")); + if (widget != NULL) + gtk_widget_hide (widget); +} + +NetProxy * +net_proxy_new (void) +{ + NetProxy *proxy; + proxy = g_object_new (NET_TYPE_PROXY, + "removable", FALSE, + "id", "proxy", + NULL); + return NET_PROXY (proxy); +} diff --git a/panels/network/net-proxy.h b/panels/network/net-proxy.h new file mode 100644 index 000000000..5eece5b29 --- /dev/null +++ b/panels/network/net-proxy.h @@ -0,0 +1,59 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- + * + * Copyright (C) 2011-2012 Richard Hughes + * + * Licensed under the GNU General Public License Version 2 + * + * 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, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __NET_PROXY_H +#define __NET_PROXY_H + +#include + +#include "net-object.h" + +G_BEGIN_DECLS + +#define NET_TYPE_PROXY (net_proxy_get_type ()) +#define NET_PROXY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), NET_TYPE_PROXY, NetProxy)) +#define NET_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NET_TYPE_PROXY, NetProxyClass)) +#define NET_IS_PROXY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NET_TYPE_PROXY)) +#define NET_IS_PROXY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), NET_TYPE_PROXY)) +#define NET_PROXY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), NET_TYPE_PROXY, NetProxyClass)) + +typedef struct _NetProxyPrivate NetProxyPrivate; +typedef struct _NetProxy NetProxy; +typedef struct _NetProxyClass NetProxyClass; + +struct _NetProxy +{ + NetObject parent; + NetProxyPrivate *priv; +}; + +struct _NetProxyClass +{ + NetObjectClass parent_class; +}; + +GType net_proxy_get_type (void); +NetProxy *net_proxy_new (void); + +G_END_DECLS + +#endif /* __NET_PROXY_H */ + diff --git a/panels/network/network-proxy.ui b/panels/network/network-proxy.ui new file mode 100644 index 000000000..310c68972 --- /dev/null +++ b/panels/network/network-proxy.ui @@ -0,0 +1,427 @@ + + + + + 65535 + 1 + + + 65535 + 1 + + + 65535 + 1 + + + 65535 + 1 + + + + + + + + + + + None + 0 + + + Manual + 1 + + + Automatic + 2 + + + + + False + + + True + False + start + 12 + 10 + 6 + + + True + False + end + start + 1 + 48 + preferences-system-network + 6 + + + 0 + 0 + 1 + 1 + + + + + True + False + start + True + 3 + + + True + False + 0 + Proxy + end + + + + + + + False + False + 0 + + + + + True + False + 0 + Not connected + + + False + False + 1 + + + + + 1 + 0 + 1 + 1 + + + + + True + False + end + start + + + False + True + True + end + start + + + + + 2 + 0 + 1 + 1 + + + + + True + False + 1 + _Method + True + combobox_proxy_mode + + + + 0 + 1 + 1 + 1 + + + + + True + False + 0 + 1 + liststore_proxy_method + + + 1 + 1 + 2 + 1 + + + + + True + False + 1 + _Configuration URL + True + entry_proxy_url + + + + 0 + 2 + 1 + 1 + + + + + True + True + + True + + + 1 + 2 + 2 + 1 + + + + + True + False + 1 + _HTTP Proxy + True + entry_proxy_http + + + + 0 + 3 + 1 + 1 + + + + + True + False + 1 + H_TTPS Proxy + True + entry_proxy_https + + + + 0 + 4 + 1 + 1 + + + + + True + False + 1 + _FTP Proxy + True + entry_proxy_ftp + + + + 0 + 5 + 1 + 1 + + + + + True + False + 1 + _Socks Host + True + entry_proxy_socks + + + + 0 + 6 + 1 + 1 + + + + + True + False + 0 + WPAD warning... + True + 50 + + + 0 + 7 + 3 + 1 + + + + + True + True + + True + + + 1 + 3 + 1 + 1 + + + + + True + True + + 1 + True + adjustment_proxy_port_http + + + 2 + 3 + 1 + 1 + + + + + True + True + + True + + + 1 + 4 + 1 + 1 + + + + + True + True + + True + + + 1 + 5 + 1 + 1 + + + + + True + True + + True + + + 1 + 6 + 1 + 1 + + + + + True + True + + 1 + True + adjustment_proxy_port_https + + + 2 + 4 + 1 + 1 + + + + + True + True + + 1 + True + adjustment_proxy_port_ftp + + + 2 + 5 + 1 + 1 + + + + + True + True + + 1 + True + adjustment_proxy_port_socks + + + 2 + 6 + 1 + 1 + + + + + + + + + + + + diff --git a/panels/network/network.ui b/panels/network/network.ui index 8ee15cf54..60f23b5b2 100644 --- a/panels/network/network.ui +++ b/panels/network/network.ui @@ -1931,414 +1931,6 @@ - - True - False - 12 - 6 - - - True - False - start - 10 - 6 - - - True - False - end - start - 1 - 48 - preferences-system-network - 6 - - - 0 - 0 - 1 - 1 - - - - - True - False - start - True - 3 - - - True - False - 0 - Proxy - end - - - - - - - False - False - 0 - - - - - True - False - 0 - Not connected - - - False - False - 1 - - - - - 1 - 0 - 1 - 1 - - - - - True - False - end - start - - - False - True - True - end - start - False - - - - - 2 - 0 - 1 - 1 - - - - - True - False - 1 - _Method - True - combobox_proxy_mode - - - - 0 - 1 - 1 - 1 - - - - - True - False - liststore_proxy_method - - - 1 - 1 - 2 - 1 - - - - - True - False - 1 - _Configuration URL - True - entry_proxy_url - - - - 0 - 2 - 1 - 1 - - - - - True - True - - True - - - 1 - 2 - 2 - 1 - - - - - True - False - 1 - _HTTP Proxy - True - entry_proxy_http - - - - 0 - 3 - 1 - 1 - - - - - True - False - 1 - H_TTPS Proxy - True - entry_proxy_https - - - - 0 - 4 - 1 - 1 - - - - - True - False - 1 - _FTP Proxy - True - entry_proxy_ftp - - - - 0 - 5 - 1 - 1 - - - - - True - False - 1 - _Socks Host - True - entry_proxy_socks - - - - 0 - 6 - 1 - 1 - - - - - True - False - 0 - WPAD warning... - True - 50 - - - 0 - 7 - 3 - 1 - - - - - True - True - - True - - - 1 - 3 - 1 - 1 - - - - - True - True - - 1 - True - adjustment_proxy_port_http - - - HTTP Port - - - - - 2 - 3 - 1 - 1 - - - - - True - True - - True - - - 1 - 4 - 1 - 1 - - - - - True - True - - True - - - 1 - 5 - 1 - 1 - - - - - True - True - - True - - - 1 - 6 - 1 - 1 - - - - - True - True - - 1 - True - adjustment_proxy_port_https - - - HTTPS Port - - - - - 2 - 4 - 1 - 1 - - - - - True - True - - 1 - True - adjustment_proxy_port_ftp - - - FTP Port - - - - - 2 - 5 - 1 - 1 - - - - - True - True - - 1 - True - adjustment_proxy_port_socks - - - Socks Port - - - - - 2 - 6 - 1 - 1 - - - - - False - True - 0 - - - - - 2 - @@ -2392,13 +1984,6 @@ - - - - - - - diff --git a/po/POTFILES.in b/po/POTFILES.in index b38410ede..59c346da3 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -41,6 +41,8 @@ panels/network/cc-network-panel.c panels/network/gnome-network-panel.desktop.in.in [type: gettext/glade]panels/network/network.ui panels/network/panel-common.c +panels/network/net-proxy.c +[type: gettext/glade]panels/network/network-proxy.ui panels/online-accounts/cc-online-accounts-add-account-dialog.c panels/online-accounts/cc-online-accounts-panel.c panels/online-accounts/gnome-online-accounts-panel.desktop.in.in