From b5e7e50e14608a8ba5fc69642eaf107841d7f506 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Fri, 21 Jul 2017 14:39:27 -0300 Subject: network: Update VPN section The last remaining network device to be updated is the VPN device, and this patch is the result of this effort. The changes were mostly towards cleaning up and removing unecessary code. By removing the info labels, many getters were removed as well. In order to achieve a listbox-like UI, a couple of UI refactorings. https://bugzilla.gnome.org/show_bug.cgi?id=785581 --- panels/network/cc-network-panel.c | 30 ++++ panels/network/net-vpn.c | 141 ++------------- panels/network/net-vpn.h | 2 + panels/network/network-vpn.ui | 363 +++++--------------------------------- panels/network/network.ui | 43 ++++- 5 files changed, 133 insertions(+), 446 deletions(-) diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c index 072c6198f..ad019a380 100644 --- a/panels/network/cc-network-panel.c +++ b/panels/network/cc-network-panel.c @@ -65,6 +65,7 @@ struct _CcNetworkPanel GtkWidget *box_proxy; GtkWidget *box_vpn; GtkWidget *box_wired; + GtkWidget *empty_listbox; /* wireless dialog stuff */ CmdlineOperation arg_operation; @@ -382,6 +383,28 @@ handle_argv (CcNetworkPanel *panel) g_debug ("Could not handle argv operation, no matching device yet?"); } +/* HACK: this function is basically a workaround. We don't have a single + * listbox in the VPN section, thus we need to track the separators and the + * stub row manually. + */ +static void +update_vpn_section (CcNetworkPanel *self) +{ + guint i, n_vpns; + + for (i = 0, n_vpns = 0; i < self->devices->len; i++) { + NetObject *net_object = g_ptr_array_index (self->devices, i); + + if (!NET_IS_VPN (net_object)) + continue; + + net_vpn_set_show_separator (NET_VPN (net_object), n_vpns > 0); + n_vpns++; + } + + gtk_widget_set_visible (self->empty_listbox, n_vpns == 0); +} + static GtkWidget * add_device_stack (CcNetworkPanel *self, NetObject *object) { @@ -504,6 +527,9 @@ panel_remove_device (CcNetworkPanel *panel, NMDevice *device) return; g_ptr_array_remove (panel->devices, object); + + /* update vpn widgets */ + update_vpn_section (panel); } static void @@ -663,6 +689,9 @@ panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection) g_ptr_array_add (panel->devices, net_vpn); g_free (title); + + /* update vpn widgets */ + update_vpn_section (panel); } static void @@ -788,6 +817,7 @@ cc_network_panel_class_init (CcNetworkPanelClass *klass) gtk_widget_class_bind_template_child (widget_class, CcNetworkPanel, box_proxy); gtk_widget_class_bind_template_child (widget_class, CcNetworkPanel, box_vpn); gtk_widget_class_bind_template_child (widget_class, CcNetworkPanel, box_wired); + gtk_widget_class_bind_template_child (widget_class, CcNetworkPanel, empty_listbox); gtk_widget_class_bind_template_child (widget_class, CcNetworkPanel, sizegroup); gtk_widget_class_bind_template_callback (widget_class, create_connection_cb); diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c index a2e6905be..47b7391a9 100644 --- a/panels/network/net-vpn.c +++ b/panels/network/net-vpn.c @@ -51,6 +51,16 @@ enum { G_DEFINE_TYPE (NetVpn, net_vpn, NET_TYPE_OBJECT) +void +net_vpn_set_show_separator (NetVpn *self, + gboolean show_separator) +{ + GtkWidget *separator; + + separator = GTK_WIDGET (gtk_builder_get_object (self->priv->builder, "separator")); + gtk_widget_set_visible (separator, show_separator); +} + static void connection_vpn_state_changed_cb (NMVpnConnection *connection, NMVpnConnectionState state, @@ -136,98 +146,6 @@ net_vpn_get_state (NetVpn *vpn) return nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (priv->connection)); } -/* VPN parameters can be found at: - * http://git.gnome.org/browse/network-manager-openvpn/tree/src/nm-openvpn-service.h - * http://git.gnome.org/browse/network-manager-vpnc/tree/src/nm-vpnc-service.h - * http://git.gnome.org/browse/network-manager-pptp/tree/src/nm-pptp-service.h - * http://git.gnome.org/browse/network-manager-openconnect/tree/src/nm-openconnect-service.h - * http://git.gnome.org/browse/network-manager-openswan/tree/src/nm-openswan-service.h - * See also 'properties' directory in these plugins. - */ -static const gchar * -get_vpn_key_gateway (const char *vpn_type) -{ - if (g_strcmp0 (vpn_type, "openvpn") == 0) return "remote"; - if (g_strcmp0 (vpn_type, "vpnc") == 0) return "IPSec gateway"; - if (g_strcmp0 (vpn_type, "pptp") == 0) return "gateway"; - if (g_strcmp0 (vpn_type, "openconnect") == 0) return "gateway"; - if (g_strcmp0 (vpn_type, "openswan") == 0) return "right"; - return ""; -} - -static const gchar * -get_vpn_key_group (const char *vpn_type) -{ - if (g_strcmp0 (vpn_type, "openvpn") == 0) return ""; - if (g_strcmp0 (vpn_type, "vpnc") == 0) return "IPSec ID"; - if (g_strcmp0 (vpn_type, "pptp") == 0) return ""; - if (g_strcmp0 (vpn_type, "openconnect") == 0) return ""; - if (g_strcmp0 (vpn_type, "openswan") == 0) return ""; - return ""; -} - -static const gchar * -get_vpn_key_username (const char *vpn_type) -{ - if (g_strcmp0 (vpn_type, "openvpn") == 0) return "username"; - if (g_strcmp0 (vpn_type, "vpnc") == 0) return "Xauth username"; - if (g_strcmp0 (vpn_type, "pptp") == 0) return "user"; - if (g_strcmp0 (vpn_type, "openconnect") == 0) return "username"; - if (g_strcmp0 (vpn_type, "openswan") == 0) return "leftxauthusername"; - return ""; -} - -static const gchar * -get_vpn_key_group_password (const char *vpn_type) -{ - if (g_strcmp0 (vpn_type, "openvpn") == 0) return ""; - if (g_strcmp0 (vpn_type, "vpnc") == 0) return "Xauth password"; - if (g_strcmp0 (vpn_type, "pptp") == 0) return ""; - if (g_strcmp0 (vpn_type, "openconnect") == 0) return ""; - if (g_strcmp0 (vpn_type, "openswan") == 0) return ""; - return ""; -} - -static const gchar * -net_vpn_get_gateway (NetVpn *vpn) -{ - NetVpnPrivate *priv = vpn->priv; - const gchar *key; - - key = get_vpn_key_gateway (priv->service_type); - return nm_setting_vpn_get_data_item (nm_connection_get_setting_vpn (priv->connection), key); -} - -static const gchar * -net_vpn_get_id (NetVpn *vpn) -{ - NetVpnPrivate *priv = vpn->priv; - const gchar *key; - - key = get_vpn_key_group (priv->service_type); - return nm_setting_vpn_get_data_item (nm_connection_get_setting_vpn (priv->connection), key); -} - -static const gchar * -net_vpn_get_username (NetVpn *vpn) -{ - NetVpnPrivate *priv = vpn->priv; - const gchar *key; - - key = get_vpn_key_username (priv->service_type); - return nm_setting_vpn_get_data_item (nm_connection_get_setting_vpn (priv->connection), key); -} - -static const gchar * -net_vpn_get_password (NetVpn *vpn) -{ - NetVpnPrivate *priv = vpn->priv; - const gchar *key; - - key = get_vpn_key_group_password (priv->service_type); - return nm_setting_vpn_get_data_item (nm_connection_get_setting_vpn (priv->connection), key); -} - static void vpn_proxy_delete (NetObject *object) { @@ -245,10 +163,6 @@ vpn_proxy_add_to_stack (NetObject *object, NetVpn *vpn = NET_VPN (object); /* add widgets to size group */ - widget = GTK_WIDGET (gtk_builder_get_object (vpn->priv->builder, - "heading_group_password")); - gtk_size_group_add_widget (heading_size_group, widget); - widget = GTK_WIDGET (gtk_builder_get_object (vpn->priv->builder, "vbox9")); gtk_stack_add_named (stack, widget, net_object_get_id (object)); @@ -260,7 +174,6 @@ nm_device_refresh_vpn_ui (NetVpn *vpn) { GtkWidget *widget; GtkWidget *sw; - const gchar *status; NetVpnPrivate *priv = vpn->priv; const GPtrArray *acs; NMActiveConnection *a; @@ -269,10 +182,6 @@ nm_device_refresh_vpn_ui (NetVpn *vpn) gchar *title; NMClient *client; - sw = GTK_WIDGET (gtk_builder_get_object (priv->builder, - "device_off_switch")); - gtk_widget_set_visible (sw, TRUE); - /* update title */ widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "label_device")); @@ -318,40 +227,12 @@ nm_device_refresh_vpn_ui (NetVpn *vpn) } } - widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, - "label_status")); - status = panel_vpn_state_to_localized_string (state); - gtk_label_set_label (GTK_LABEL (widget), status); priv->updating_device = TRUE; + sw = GTK_WIDGET (gtk_builder_get_object (priv->builder, "device_off_switch")); gtk_switch_set_active (GTK_SWITCH (sw), state != NM_VPN_CONNECTION_STATE_FAILED && state != NM_VPN_CONNECTION_STATE_DISCONNECTED); priv->updating_device = FALSE; - - /* service type */ - panel_set_device_widget_details (vpn->priv->builder, - "service_type", - vpn->priv->service_type); - - /* gateway */ - panel_set_device_widget_details (vpn->priv->builder, - "gateway", - net_vpn_get_gateway (vpn)); - - /* groupname */ - panel_set_device_widget_details (vpn->priv->builder, - "group_name", - net_vpn_get_id (vpn)); - - /* username */ - panel_set_device_widget_details (vpn->priv->builder, - "username", - net_vpn_get_username (vpn)); - - /* password */ - panel_set_device_widget_details (vpn->priv->builder, - "group_password", - net_vpn_get_password (vpn)); } static void diff --git a/panels/network/net-vpn.h b/panels/network/net-vpn.h index 6ca1910e8..adcf8ad75 100644 --- a/panels/network/net-vpn.h +++ b/panels/network/net-vpn.h @@ -52,6 +52,8 @@ struct _NetVpnClass }; GType net_vpn_get_type (void); +void net_vpn_set_show_separator (NetVpn *self, + gboolean show_separator); G_END_DECLS diff --git a/panels/network/network-vpn.ui b/panels/network/network-vpn.ui index 7a3fab4fc..3fb080abf 100644 --- a/panels/network/network-vpn.ui +++ b/panels/network/network-vpn.ui @@ -1,268 +1,46 @@ - - True + + True + False + True + vertical + + + + False - 12 - 6 + horizontal + + + + + + + True + True + none - + True - False - start - 10 - 6 - - - True - False - 1 - VPN Type - label_service_type - - - - 0 - 1 - 1 - 1 - - - - - True - False - 1 - Gateway - label_gateway - - - - 0 - 2 - 1 - 1 - - - - - True - False - 1 - Group Name - label_group_name - - - - 0 - 3 - 1 - 1 - - - - - True - False - 1 - Group Password - label_group_password - - - - 0 - 4 - 1 - 1 - - + True + False - + True False - 1 - Username - label_username - - - - 0 - 5 - 1 - 1 - - - - - True - True - 0 - openvpn - True - - - 1 - 1 - 2 - 1 - - - - - True - True - 0 - AA:BB:CC:DD:55:66:77:88 - end - 24 - True - - - 1 - 2 - 2 - 1 - - - - - True - True - 0 - SEKRIT - True - - - 1 - 3 - 2 - 1 - - - - - True - True - 0 - ********** - True - - - 1 - 4 - 2 - 1 - - - - - True - True - 0 - smithy - True - - - 1 - 5 - 2 - 1 - - - - - True - False - end start + 12 + 12 - - - - - 2 - 0 - 1 - 1 - - - - - True - False - True - 6 - - + True False - end - start - 1 - 48 - network-vpn - 6 - - - False - True - 0 - - - - - True - False - start + 0 + end True - - - True - False - 0 - VPN - end - - - - - - - False - False - 0 - - - - - True - False - 0 - Not connected - - - False - False - 1 - - - - True - True - 1 - @@ -276,80 +54,35 @@ - - False - True - 2 - - - - 0 - 0 - 3 - 1 - - - - - True - True - 0 - - - - - True - False - - - True - True - True - end - end - True - True - True - - + True - False - emblem-system-symbolic - 1 - - - - - Options… + True + True + True + + + + True + False + emblem-system-symbolic + + + + + Options… + + - - False - True - end - 0 - - - True - True - 1 - - - - - - - - - + diff --git a/panels/network/network.ui b/panels/network/network.ui index 52691fa7a..d287734a5 100644 --- a/panels/network/network.ui +++ b/panels/network/network.ui @@ -72,10 +72,11 @@ - + True False vertical + 6 @@ -111,6 +112,46 @@ + + + True + False + + + True + False + vertical + + + + + True + True + none + + + True + True + False + + + True + False + True + 16 + 0 + end + Not set up + + + + + + + + + + -- cgit v1.2.1