[network-manager-openvpn] properties: add GUI support for comp-lzo "no" and "adaptive"



commit f3ec272521ce7788c03c93f8f3baf99d33b167d8
Author: Thomas Haller <thaller redhat com>
Date:   Sat Feb 4 13:47:03 2017 +0100

    properties: add GUI support for comp-lzo "no" and "adaptive"
    
    openvpn and the rest of the plugin already supports all for possible
    options for the comp-lzo setting:
      0) option unspecified
      1) "yes"
      2) "adaptive"
      3) "no"
    
    The GUI however only supported a boolean checkbox, which mapped to
    the choices 0) (option unspecified) and 1) ("yes"). Obviously, it was
    unable to express the other two choices.
    
    Especially problematic is that the GUI previously would wrongly coerce
    option 3) ("no") to option 0) (unspecified). That is wrong because it
    breaks the setup when the server enables compression. A more correct way
    for the GUI would be to map all unsupported options to "yes".
    
    Instead of doing that, just expose all supported comp-lzo options in the
    GUI.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=778123

 properties/auth-helpers.c       |   77 +++++++++++++++++++++++++++++++--------
 properties/nm-openvpn-dialog.ui |   50 +++++++++++++++++++++-----
 2 files changed, 102 insertions(+), 25 deletions(-)
---
diff --git a/properties/auth-helpers.c b/properties/auth-helpers.c
index 4d1e1ce..3cac2ef 100644
--- a/properties/auth-helpers.c
+++ b/properties/auth-helpers.c
@@ -38,6 +38,41 @@
 
 #define BLOCK_HANDLER_ID "block-handler-id"
 
+/*****************************************************************************/
+
+static const char *comp_lzo_values[] = {
+       "adaptive",
+       "yes",
+       "no-by-default",
+       NULL,
+};
+
+static const char *
+comp_lzo_values_conf_coerce (const char *value_conf)
+{
+       if (!value_conf || nm_streq (value_conf, "no"))
+               return NULL;
+       if (nm_streq (value_conf, "yes"))
+               return "yes";
+       if (nm_streq (value_conf, "no-by-default"))
+               return "no-by-default";
+       return "adaptive";
+}
+
+static const char *
+comp_lzo_values_conf_to_display (const char *value_conf)
+{
+       if (nm_streq (value_conf, "yes"))
+               return "yes";
+       if (nm_streq (value_conf, "no-by-default"))
+               return "no";
+       if (nm_streq (value_conf, "adaptive"))
+               return "adaptive";
+       g_return_val_if_reached ("adaptive");
+}
+
+/*****************************************************************************/
+
 static void
 show_password (GtkToggleButton *togglebutton, GtkEntry *password_entry)
 {
@@ -1559,7 +1594,7 @@ _hash_get_boolean (GHashTable *hash,
        return nm_streq0 (value, "yes");
 }
 
-static void
+static GtkToggleButton *
 _builder_init_toggle_button (GtkBuilder *builder,
                              const char *widget_name,
                              gboolean active_state)
@@ -1567,9 +1602,10 @@ _builder_init_toggle_button (GtkBuilder *builder,
        GtkToggleButton *widget;
 
        widget = (GtkToggleButton *) gtk_builder_get_object (builder, widget_name);
-       g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget));
+       g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (widget), NULL);
 
        gtk_toggle_button_set_active (widget, active_state);
+       return widget;
 }
 
 static void
@@ -1623,6 +1659,7 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
        const char *dev, *dev_type, *tap_dev;
        GtkListStore *store;
        GtkTreeIter iter;
+       guint i;
        guint32 active;
        guint32 pw_flags = NM_SETTING_SECRET_FLAG_NONE;
        GError *error = NULL;
@@ -1750,13 +1787,23 @@ advanced_dialog_new (GHashTable *hash, const char *contype)
                                           _nm_utils_ascii_str_to_int64 (value, 10, 0, 65535, 1300));
 
 
-       /* the UI currently only supports "--comp-lzo yes" or omitting the "--comp-lzo"
-        * flag.
-        *
-        * Internally, we also support "--comp-lzo [adaptive]" and "--comp-lzo no"
-        * which have different meaning for openvpn. */
-       value = g_hash_table_lookup (hash, NM_OPENVPN_KEY_COMP_LZO);
-       _builder_init_toggle_button (builder, "lzo_checkbutton", NM_IN_STRSET (value, "yes", "adaptive"));
+       value = comp_lzo_values_conf_coerce (g_hash_table_lookup (hash, NM_OPENVPN_KEY_COMP_LZO));
+       widget = GTK_WIDGET (_builder_init_toggle_button (builder, "lzo_checkbutton", value != NULL));
+       combo = GTK_WIDGET (gtk_builder_get_object (builder, "lzo_combo"));
+       store = gtk_list_store_new (1, G_TYPE_STRING);
+       active = 0;
+       for (i = 0; comp_lzo_values[i]; i++) {
+               gtk_list_store_append (store, &iter);
+               gtk_list_store_set (store, &iter,
+                                   0, comp_lzo_values_conf_to_display (comp_lzo_values[i]),
+                                   -1);
+               if (nm_streq (comp_lzo_values[i], value ?: "adaptive"))
+                       active = i;
+       }
+       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);
+       g_object_bind_property (widget, "active", combo, "sensitive", G_BINDING_SYNC_CREATE);
 
        _builder_init_toggle_button (builder, "mssfix_checkbutton", _hash_get_boolean (hash, 
NM_OPENVPN_KEY_MSSFIX));
        _builder_init_toggle_button (builder, "float_checkbutton", _hash_get_boolean (hash, 
NM_OPENVPN_KEY_FLOAT));
@@ -1949,6 +1996,7 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
        GtkBuilder *builder;
        const char *contype = NULL;
        const char *value;
+       int active;
        int proxy_type = PROXY_TYPE_NONE;
        GtkTreeModel *model;
        GtkTreeIter iter;
@@ -2056,13 +2104,10 @@ advanced_dialog_new_hash_from_dialog (GtkWidget *dialog, GError **error)
 
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "lzo_checkbutton"));
        if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget))) {
-               /* we only have a checkbox, which we either map to "--comp-lzo yes" or
-                * no "--comp-lzo" flag. In the UI, we cannot express "--comp-lzo [adaptive]"
-                * or "--comp-lzo no".
-                *
-                * Note that "--comp-lzo no" must be encoded as "comp-lzo=no-by-default" (bgo#769177).
-                */
-               g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_COMP_LZO), g_strdup ("yes"));
+               combo = GTK_WIDGET (gtk_builder_get_object (builder, "lzo_combo"));
+               active = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
+               if (active >= 0 && active < G_N_ELEMENTS (comp_lzo_values))
+                       g_hash_table_insert (hash, g_strdup (NM_OPENVPN_KEY_COMP_LZO), g_strdup 
(comp_lzo_values[active]));
        }
 
        widget = GTK_WIDGET (gtk_builder_get_object (builder, "mssfix_checkbutton"));
diff --git a/properties/nm-openvpn-dialog.ui b/properties/nm-openvpn-dialog.ui
index b2ca176..f0dd55c 100644
--- a/properties/nm-openvpn-dialog.ui
+++ b/properties/nm-openvpn-dialog.ui
@@ -1242,17 +1242,49 @@ config: reneg-sec</property>
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkCheckButton" id="lzo_checkbutton">
-                    <property name="label" translatable="yes">Use L_ZO data compression</property>
-                    <property name="use_action_appearance">False</property>
+                  <object class="GtkBox" id="hbox11">
                     <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">False</property>
-                    <property name="tooltip_text" translatable="yes">Use fast LZO compression.
+                    <property name="can_focus">False</property>
+                    <property name="spacing">6</property>
+                    <child>
+                      <object class="GtkCheckButton" id="lzo_checkbutton">
+                        <property name="label" translatable="yes">Use L_ZO data compression</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="tooltip_text" translatable="yes">Use fast LZO compression.
 config: comp-lzo</property>
-                    <property name="use_underline">True</property>
-                    <property name="xalign">0</property>
-                    <property name="draw_indicator">True</property>
+                        <property name="use_underline">True</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</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="lzo_combo">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="tooltip_text" translatable="yes">Select the LZO data compression 
mode.
+config: comp-lzo</property>
+                        <property name="model">model4</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="renderer13"/>
+                          <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>


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