[network-manager-openvpn/jk/tun-tap-device: 2/3] ui: allow specifying device type and a custom name for TUN/TAP devices



commit 6b02ef64a16e689fca283f755fcc476b63e2355e
Author: Jiří Klimeš <jklimes redhat com>
Date:   Mon Mar 24 15:56:45 2014 +0100

    ui: allow specifying device type and a custom name for TUN/TAP devices

 properties/auth-helpers.c       |   91 +++++++++++++++++++++++++++++------
 properties/nm-openvpn-dialog.ui |  101 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 164 insertions(+), 28 deletions(-)
---
diff --git a/properties/auth-helpers.c b/properties/auth-helpers.c
index 5c4578b..fc63869 100644
--- a/properties/auth-helpers.c
+++ b/properties/auth-helpers.c
@@ -949,6 +949,8 @@ static const char *advanced_keys[] = {
        NM_OPENVPN_KEY_TUNNEL_MTU,
        NM_OPENVPN_KEY_FRAGMENT_SIZE,
        NM_OPENVPN_KEY_TAP_DEV,
+       NM_OPENVPN_KEY_DEV,
+       NM_OPENVPN_KEY_DEV_TYPE,
        NM_OPENVPN_KEY_PROTO_TCP,
        NM_OPENVPN_KEY_PROXY_TYPE,
        NM_OPENVPN_KEY_PROXY_SERVER,
@@ -1006,11 +1008,11 @@ advanced_dialog_new_hash_from_connection (NMConnection *connection,
 }
 
 static void
-checkbox_toggled_update_spin_cb (GtkWidget *check, gpointer user_data)
+checkbox_toggled_update_widget_cb (GtkWidget *check, gpointer user_data)
 {
-       GtkWidget *spin = (GtkWidget*) user_data;
+       GtkWidget *widget = (GtkWidget*) user_data;
 
-       gtk_widget_set_sensitive (spin, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
+       gtk_widget_set_sensitive (widget, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check)));
 }
 
 static const char *
@@ -1261,6 +1263,9 @@ tls_auth_toggled_cb (GtkWidget *widget, gpointer user_data)
 #define PROXY_TYPE_HTTP  1
 #define PROXY_TYPE_SOCKS 2
 
+#define DEVICE_TYPE_IDX_TUN     0
+#define DEVICE_TYPE_IDX_TAP     1
+
 static void
 proxy_type_changed (GtkComboBox *combo, gpointer user_data)
 {
@@ -1329,8 +1334,9 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
        GtkBuilder *builder;
        GtkWidget *dialog = NULL;
        char *ui_file = NULL;
-       GtkWidget *widget, *combo, *spin;
+       GtkWidget *widget, *combo, *spin, *entry;
        const char *value, *value2;
+       const char *dev, *dev_type, *tap_dev;
        GtkListStore *store;
        GtkTreeIter iter;
        guint32 active = PROXY_TYPE_NONE;
@@ -1363,7 +1369,7 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
 
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "reneg_checkbutton"));
        spin = GTK_WIDGET (gtk_builder_get_object (builder, "reneg_spinbutton"));
-       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_spin_cb), spin);
+       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_widget_cb), spin);
 
        value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_RENEG_SECONDS);
        if (value && strlen (value)) {
@@ -1461,7 +1467,7 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
 
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "port_checkbutton"));
        spin = GTK_WIDGET (gtk_builder_get_object (builder, "port_spinbutton"));
-       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_spin_cb), spin);
+       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_widget_cb), spin);
 
        value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_PORT);
        if (value && strlen (value)) {
@@ -1488,7 +1494,7 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "tunmtu_checkbutton"));
        g_assert (widget);
        spin = GTK_WIDGET (gtk_builder_get_object (builder, "tunmtu_spinbutton"));
-       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_spin_cb), spin);
+       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_widget_cb), spin);
 
        value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_TUNNEL_MTU);
        if (value && strlen (value)) {
@@ -1513,7 +1519,7 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
 
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "fragment_checkbutton"));
        spin = GTK_WIDGET (gtk_builder_get_object (builder, "fragment_spinbutton"));
-       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_spin_cb), spin);
+       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_widget_cb), spin);
 
        value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_FRAGMENT_SIZE);
        if (value && strlen (value)) {
@@ -1560,10 +1566,50 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
        }
 
-       value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_TAP_DEV);
-       if (value && !strcmp (value, "yes")) {
-               widget = GTK_WIDGET (gtk_builder_get_object (builder, "tap_checkbutton"));
+       /* Populate device-related widgets */
+       dev =      g_hash_table_lookup (hash, NM_OPENVPN_KEY_DEV);
+       dev_type = g_hash_table_lookup (hash, NM_OPENVPN_KEY_DEV_TYPE);
+       tap_dev =  g_hash_table_lookup (hash, NM_OPENVPN_KEY_TAP_DEV);
+
+       /* Look at the legacy 'tap-dev' property */
+       if (!dev_type && tap_dev && !strcmp (tap_dev, "yes"))
+               dev_type = "tap";
+
+       widget = GTK_WIDGET (gtk_builder_get_object (builder, "dev_type_checkbutton"));
+       combo = GTK_WIDGET (gtk_builder_get_object (builder, "dev_type_combo"));
+       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_widget_cb), 
combo);
+       active = DEVICE_TYPE_IDX_TUN;
+       if (dev_type) {
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+
+               if (!g_strcmp0 (dev_type, "tap"))
+                       active = DEVICE_TYPE_IDX_TAP;
+               gtk_widget_set_sensitive (combo, TRUE);
+       } else {
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+
+               gtk_widget_set_sensitive (combo, FALSE);
+       }
+       store = gtk_list_store_new (1, G_TYPE_STRING);
+       gtk_list_store_append (store, &iter);
+       gtk_list_store_set (store, &iter, 0, _("TUN"), -1);
+       gtk_list_store_append (store, &iter);
+       gtk_list_store_set (store, &iter, 0, _("TAP"), -1);
+       gtk_combo_box_set_model (GTK_COMBO_BOX (combo), GTK_TREE_MODEL (store));
+       g_object_unref (store);
+       gtk_combo_box_set_active (GTK_COMBO_BOX (combo), active);
+
+       widget = GTK_WIDGET (gtk_builder_get_object (builder, "dev_checkbutton"));
+       entry = GTK_WIDGET (gtk_builder_get_object (builder, "dev_entry"));
+       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_widget_cb), 
entry);
+       if (dev && dev[0] != '\0') {
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
+               gtk_entry_set_text (GTK_ENTRY (entry), dev);
+               gtk_widget_set_sensitive (entry, TRUE);
+       } else {
+               gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
+               gtk_entry_set_text (GTK_ENTRY (entry), dev_type ? dev_type : "tun");
+               gtk_widget_set_sensitive (entry, FALSE);
        }
 
        value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_REMOTE_RANDOM);
@@ -1579,7 +1625,7 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "keysize_checkbutton"));
        g_assert (widget);
        spin = GTK_WIDGET (gtk_builder_get_object (builder, "keysize_spinbutton"));
-       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_spin_cb), spin);
+       g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (checkbox_toggled_update_widget_cb), spin);
 
        value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_KEYSIZE);
        if (value && strlen (value)) {
@@ -1804,9 +1850,24 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
                g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_PROTO_TCP), g_strdup ("yes"));
 
-       widget = GTK_WIDGET (gtk_builder_get_object (builder, "tap_checkbutton"));
-       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
-               g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_TAP_DEV), g_strdup ("yes"));
+       widget = GTK_WIDGET (gtk_builder_get_object (builder, "dev_type_checkbutton"));
+       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+               int device_type;
+
+               widget = GTK_WIDGET (gtk_builder_get_object (builder, "dev_type_combo"));
+               device_type = gtk_combo_box_get_active (GTK_COMBO_BOX (widget));
+               g_hash_table_insert (hash,
+                                    g_strdup (NM_OPENVPN_KEY_DEV_TYPE),
+                                    g_strdup (device_type == DEVICE_TYPE_IDX_TUN ? "tun" : "tap"));
+       }
+
+       widget = GTK_WIDGET (gtk_builder_get_object (builder, "dev_checkbutton"));
+       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
+               widget = GTK_WIDGET (gtk_builder_get_object (builder, "dev_entry"));
+               value = gtk_entry_get_text (GTK_ENTRY (widget));
+               if (value && value[0] != '\0')
+                       g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_DEV), g_strdup (value));
+       }
 
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "remote_random_checkbutton"));
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
diff --git a/properties/nm-openvpn-dialog.ui b/properties/nm-openvpn-dialog.ui
index c8a8a67..d1b62d3 100644
--- a/properties/nm-openvpn-dialog.ui
+++ b/properties/nm-openvpn-dialog.ui
@@ -315,16 +315,48 @@ config: proto tcp-client | udp</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkCheckButton" id="tap_checkbutton">
-                    <property name="label" translatable="yes">Use a TA_P device</property>
+                  <object class="GtkHBox" id="hbox7">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">False</property>
-                    <property name="use_action_appearance">False</property>
-                    <property name="use_underline">True</property>
-                    <property name="draw_indicator">True</property>
-                    <property name="tooltip_text" translatable="yes">Use TAP virtual network device instead 
of TUN.
-config: dev tap | tun</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkCheckButton" id="dev_type_checkbutton">
+                        <property name="label" translatable="yes">Set virtual device ty_pe 
(TUN/TAP):</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_indicator">True</property>
+                        <property name="tooltip_text" translatable="yes">Explicitly set virtual device type 
(TUN/TAP). When not given, the type is determined by device name.
+config: dev-type tun | tap</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkComboBox" id="dev_type_combo">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="model">model4</property>
+                        <property name="tooltip_text" translatable="yes">Explicitly set virtual device type 
(TUN/TAP). When not given, the type is determined by device name.
+config: dev-type tun | tap</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="renderer10"/>
+                          <attributes>
+                            <attribute name="text">0</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
                   </object>
                   <packing>
                     <property name="expand">False</property>
@@ -333,6 +365,49 @@ config: dev tap | tun</property>
                   </packing>
                 </child>
                 <child>
+                  <object class="GtkHBox" id="hbox8">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkCheckButton" id="dev_checkbutton">
+                        <property name="label" translatable="yes">Use custom TUN/TAP _device name:</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
+                        <property name="draw_indicator">True</property>
+                        <property name="tooltip_text" translatable="yes">Use custom name for TUN/TAP virtual 
device (instead of default "tun" or "tap").
+config: dev &lt;name&gt;</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkEntry" id="dev_entry">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="tooltip_text" translatable="yes">Use custom name for TUN/TAP virtual 
device (instead of default "tun" or "tap").
+config: dev &lt;name&gt;</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">5</property>
+                  </packing>
+                </child>
+                <child>
                   <object class="GtkHBox" id="hbox4">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
@@ -376,7 +451,7 @@ config: tun-mtu</property>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
-                    <property name="position">5</property>
+                    <property name="position">6</property>
                   </packing>
                 </child>
                 <child>
@@ -423,7 +498,7 @@ config: fragment</property>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
-                    <property name="position">6</property>
+                    <property name="position">7</property>
                   </packing>
                 </child>
                 <child>
@@ -441,7 +516,7 @@ config: mssfix</property>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
-                    <property name="position">7</property>
+                    <property name="position">8</property>
                   </packing>
                 </child>
                 <child>
@@ -459,7 +534,7 @@ config: remote-random</property>
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
-                    <property name="position">8</property>
+                    <property name="position">9</property>
                   </packing>
                 </child>
               </object>


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