[network-manager-vpnc/nm-0-9-6: 12/16] ui: add an GUI configuration for "Local Port" (bgo #567122) (rh #710545)



commit 3091f40d6d246e52f262e6a93cb71acd20706c77
Author: JiÅÃ KlimeÅ <jklimes redhat com>
Date:   Mon Sep 17 12:40:02 2012 +0200

    ui: add an GUI configuration for "Local Port" (bgo #567122) (rh #710545)
    
    It seems that some Cisco VPN concentrators require clients to use port 500.
    By adding the spinbutton for local port we allow user to easily configure
    local port to 500 (and other desired values too).

 properties/nm-vpnc-dialog.ui |   43 ++++++++++++++++++++++++++++++++++++++-
 properties/nm-vpnc.c         |   45 +++++++++++++++++++++++++++++++----------
 2 files changed, 75 insertions(+), 13 deletions(-)
---
diff --git a/properties/nm-vpnc-dialog.ui b/properties/nm-vpnc-dialog.ui
index 4421877..168782e 100644
--- a/properties/nm-vpnc-dialog.ui
+++ b/properties/nm-vpnc-dialog.ui
@@ -1,6 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.22"/>
+  <object class="GtkAdjustment" id="adjustment1">
+    <property name="lower">0</property>
+    <property name="upper">65535</property>
+    <property name="value">0</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
   <object class="GtkImage" id="image1">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -438,6 +445,38 @@ config: Perfect Forward Secrecy &lt;nopfs/dh1/dh2/dh5/server&gt;</property>
                       </packing>
                     </child>
                     <child>
+                      <object class="GtkLabel" id="local_port_label">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">_Local port:</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">local_port_spinbutton</property>
+                      </object>
+                      <packing>
+                        <property name="top_attach">4</property>
+                        <property name="bottom_attach">5</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkSpinButton" id="local_port_spinbutton">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="width_chars">5</property>
+                        <property name="adjustment">adjustment1</property>
+                        <property name="climb_rate">1</property>
+                        <property name="numeric">True</property>
+                        <property name="tooltip_text" translatable="yes">Local ISAKMP port to use (0 means random port; 500 is vpnc's default)
+config: Local Port &lt;0-65535&gt;</property>
+                      </object>
+                      <packing>
+                        <property name="left_attach">1</property>
+                        <property name="right_attach">2</property>
+                        <property name="top_attach">4</property>
+                        <property name="bottom_attach">5</property>
+                      </packing>
+                    </child>
+                    <child>
                       <object class="GtkCheckButton" id="disable_dpd_checkbutton">
                         <property name="label" translatable="yes">Disable Dead _Peer Detection</property>
                         <property name="visible">True</property>
@@ -452,8 +491,8 @@ config: DPD idle timeout (our side) 0</property>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="right_attach">2</property>
-                        <property name="top_attach">4</property>
-                        <property name="bottom_attach">5</property>
+                        <property name="top_attach">5</property>
+                        <property name="bottom_attach">6</property>
                       </packing>
                     </child>
                     <child>
diff --git a/properties/nm-vpnc.c b/properties/nm-vpnc.c
index 14d01cd..16eff50 100644
--- a/properties/nm-vpnc.c
+++ b/properties/nm-vpnc.c
@@ -188,6 +188,14 @@ hybrid_toggled_cb (GtkWidget *widget, gpointer user_data)
 }
 
 static void
+spinbutton_changed_cb (GtkWidget *widget, gpointer user_data)
+{
+	gtk_spin_button_update (GTK_SPIN_BUTTON (widget));
+
+	stuff_changed_cb (widget, user_data);
+}
+
+static void
 setup_password_widget (VpncPluginUiWidget *self,
                        const char *entry_name,
                        NMSettingVPN *s_vpn,
@@ -675,6 +683,25 @@ init_plugin_ui (VpncPluginUiWidget *self,
 	gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active < 0 ? 1 : active);
 	g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (stuff_changed_cb), self);
 
+	/* Local Port */
+	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "local_port_spinbutton"));
+	g_return_val_if_fail (widget != NULL, FALSE);
+	gtk_size_group_add_widget (priv->group, GTK_WIDGET (widget));
+	if (s_vpn) {
+		value = nm_setting_vpn_get_data_item (s_vpn, NM_VPNC_KEY_LOCAL_PORT);
+		if (value) {
+			long int tmp;
+
+			errno = 0;
+			tmp = strtol (value, NULL, 10);
+			if (errno != 0 || tmp < 0 || tmp > 65535)
+				tmp = 0;
+			widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "local_port_spinbutton"));
+			gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget), (gdouble) tmp);
+		}
+	}
+	g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (spinbutton_changed_cb), self);
+
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "disable_dpd_checkbutton"));
 	g_return_val_if_fail (widget != NULL, FALSE);
 	if (s_vpn) {
@@ -866,9 +893,10 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
 {
 	VpncPluginUiWidget *self = VPNC_PLUGIN_UI_WIDGET (iface);
 	VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
-	NMSettingVPN *s_vpn, *s_vpn_orig;
+	NMSettingVPN *s_vpn;
 	GtkWidget *widget;
 	char *str;
+	guint32 port;
 	GtkTreeModel *model;
 	GtkTreeIter iter;
 
@@ -959,6 +987,11 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
 	} else
 		nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_PERFECT_FORWARD, NM_VPNC_PFS_SERVER);
 
+	/* Local port */
+	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "local_port_spinbutton"));
+	port = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (widget));
+	nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_LOCAL_PORT, g_strdup_printf ("%d", port));
+
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "disable_dpd_checkbutton"));
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
 		nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_DPD_IDLE_TIMEOUT, "0");
@@ -990,16 +1023,6 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
 	                   NM_VPNC_KEY_SECRET,
 	                   NM_VPNC_KEY_SECRET_TYPE);
 
-	/* Local Port is not in GUI (yet?). So when present in the connection,
-	 * copy it from the old VPN setting to the new one to preserve it.
-	 */
-	s_vpn_orig = nm_connection_get_setting_vpn (connection);
-	if (s_vpn_orig) {
-		const char *local_port = nm_setting_vpn_get_data_item (s_vpn_orig, NM_VPNC_KEY_LOCAL_PORT);
-		if (local_port && strlen (local_port))
-			nm_setting_vpn_add_data_item (s_vpn, NM_VPNC_KEY_LOCAL_PORT, local_port);
-	}
-
 	/* hybrid auth */
 	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "hybrid_checkbutton"));
 	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]