[network-manager-openvpn/jk/bgo731891-gui-password-types: 2/6] properties: use libnm-gtk password menu funcs for password (bgo #731891)



commit efe2a627c09e87087621ec9048733a4ce1f4650e
Author: Jiří Klimeš <jklimes redhat com>
Date:   Tue Apr 7 15:14:03 2015 +0200

    properties: use libnm-gtk password menu funcs for password (bgo #731891)
    
    Remove combobox with password menu types.

 properties/auth-helpers.c       |  108 +-------------------------------------
 properties/nm-openvpn-dialog.ui |   36 +------------
 2 files changed, 5 insertions(+), 139 deletions(-)
---
diff --git a/properties/auth-helpers.c b/properties/auth-helpers.c
index e18421c..5a50c86 100644
--- a/properties/auth-helpers.c
+++ b/properties/auth-helpers.c
@@ -44,10 +44,6 @@
 #include "src/nm-openvpn-service.h"
 #include "common/utils.h"
 
-#define PW_TYPE_SAVE   0
-#define PW_TYPE_ASK    1
-#define PW_TYPE_UNUSED 2
-
 #define BLOCK_HANDLER_ID "block-handler-id"
 
 static void
@@ -240,87 +236,6 @@ tls_setup (GtkBuilder *builder,
 }
 
 static void
-pw_type_combo_changed_cb (GtkWidget *combo, gpointer user_data)
-{
-       GtkWidget *entry = user_data;
-
-       /* If the user chose "Not required", desensitize and clear the correct
-        * password entry.
-        */
-       switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) {
-       case PW_TYPE_ASK:
-       case PW_TYPE_UNUSED:
-               gtk_entry_set_text (GTK_ENTRY (entry), "");
-               gtk_widget_set_sensitive (entry, FALSE);
-               break;
-       default:
-               gtk_widget_set_sensitive (entry, TRUE);
-               break;
-       }
-}
-
-static void
-init_one_pw_combo (GtkBuilder *builder,
-                   NMSettingVPN *s_vpn,
-                   const char *prefix,
-                   const char *secret_key,
-                   GtkWidget *entry_widget,
-                   ChangedCallback changed_cb,
-                   gpointer user_data)
-{
-       int active = -1;
-       GtkWidget *widget;
-       GtkListStore *store;
-       GtkTreeIter iter;
-       const char *value = NULL;
-       char *tmp;
-       guint32 default_idx = 1;
-       NMSettingSecretFlags pw_flags = NM_SETTING_SECRET_FLAG_NONE;
-
-       /* If there's already a password and the password type can't be found in
-        * the VPN settings, default to saving it.  Otherwise, always ask for it.
-        */
-       value = gtk_entry_get_text (GTK_ENTRY (entry_widget));
-       if (value && strlen (value))
-               default_idx = 0;
-
-       store = gtk_list_store_new (1, G_TYPE_STRING);
-       if (s_vpn)
-               nm_setting_get_secret_flags (NM_SETTING (s_vpn), secret_key, &pw_flags, NULL);
-
-       gtk_list_store_append (store, &iter);
-       gtk_list_store_set (store, &iter, 0, _("Saved"), -1);
-       if (   (active < 0)
-           && !(pw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED)
-           && !(pw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
-               active = PW_TYPE_SAVE;
-       }
-
-       gtk_list_store_append (store, &iter);
-       gtk_list_store_set (store, &iter, 0, _("Always Ask"), -1);
-       if ((active < 0) && (pw_flags & NM_SETTING_SECRET_FLAG_NOT_SAVED))
-               active = PW_TYPE_ASK;
-
-       gtk_list_store_append (store, &iter);
-       gtk_list_store_set (store, &iter, 0, _("Not Required"), -1);
-       if ((active < 0) && (pw_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED))
-               active = PW_TYPE_UNUSED;
-
-       tmp = g_strdup_printf ("%s_pass_type_combo", prefix);
-       widget = GTK_WIDGET (gtk_builder_get_object (builder, tmp));
-       g_assert (widget);
-       g_free (tmp);
-
-       gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
-       g_object_unref (store);
-       gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active < 0 ? default_idx : active);
-       pw_type_combo_changed_cb (widget, entry_widget);
-
-       g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (pw_type_combo_changed_cb), entry_widget);
-       g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (changed_cb), user_data);
-}
-
-static void
 pw_setup (GtkBuilder *builder,
           GtkSizeGroup *group,
           NMSettingVPN *s_vpn,
@@ -351,7 +266,8 @@ pw_setup (GtkBuilder *builder,
        gtk_size_group_add_widget (group, widget);
        g_signal_connect (widget, "changed", G_CALLBACK (changed_cb), user_data);
 
-       init_one_pw_combo (builder, s_vpn, prefix, NM_OPENVPN_KEY_PASSWORD, widget, changed_cb, user_data);
+       nma_utils_setup_password_storage (widget, 0, (NMSetting *) s_vpn, NM_OPENVPN_KEY_PASSWORD,
+                                         TRUE, FALSE);
 }
 
 void
@@ -732,25 +648,7 @@ update_pw (GtkBuilder *builder, const char *prefix, NMSettingVPN *s_vpn)
                nm_setting_vpn_add_secret (s_vpn, NM_OPENVPN_KEY_PASSWORD, str);
 
        /* Update password flags */
-       pw_flags = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget), "flags"));
-       pw_flags &= ~(NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED);
-
-       tmp = g_strdup_printf ("%s_pass_type_combo", prefix);
-       widget = GTK_WIDGET (gtk_builder_get_object (builder, tmp));
-       g_free (tmp);
-
-       switch (gtk_combo_box_get_active (GTK_COMBO_BOX (widget))) {
-       case PW_TYPE_SAVE:
-               break;
-       case PW_TYPE_UNUSED:
-               pw_flags |= NM_SETTING_SECRET_FLAG_NOT_REQUIRED;
-               break;
-       case PW_TYPE_ASK:
-       default:
-               pw_flags |= NM_SETTING_SECRET_FLAG_NOT_SAVED;
-               break;
-       }
-
+       pw_flags = nma_utils_menu_to_secret_flags (widget);
        nm_setting_set_secret_flags (NM_SETTING (s_vpn), NM_OPENVPN_KEY_PASSWORD, pw_flags, NULL);
 }
 
diff --git a/properties/nm-openvpn-dialog.ui b/properties/nm-openvpn-dialog.ui
index 58a3dbf..bed692c 100644
--- a/properties/nm-openvpn-dialog.ui
+++ b/properties/nm-openvpn-dialog.ui
@@ -377,6 +377,7 @@ config: auth-user-pass</property>
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="top_attach">1</property>
+                            <property name="width">2</property>
                           </packing>
                         </child>
                         <child>
@@ -457,23 +458,6 @@ config: auth-user-pass</property>
                             <property name="width">2</property>
                           </packing>
                         </child>
-                        <child>
-                          <object class="GtkComboBox" id="pw_pass_type_combo">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="model">liststore1</property>
-                            <child>
-                              <object class="GtkCellRendererText" id="renderer7"/>
-                              <attributes>
-                                <attribute name="text">0</attribute>
-                              </attributes>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="left_attach">2</property>
-                            <property name="top_attach">1</property>
-                          </packing>
-                        </child>
                       </object>
                       <packing>
                         <property name="position">1</property>
@@ -592,6 +576,7 @@ config: auth-user-pass</property>
                           <packing>
                             <property name="left_attach">1</property>
                             <property name="top_attach">1</property>
+                            <property name="width">2</property>
                           </packing>
                         </child>
                         <child>
@@ -692,23 +677,6 @@ config: auth-user-pass</property>
                             <property name="width">2</property>
                           </packing>
                         </child>
-                        <child>
-                          <object class="GtkComboBox" id="pw_tls_pass_type_combo">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="model">liststore2</property>
-                            <child>
-                              <object class="GtkCellRendererText" id="renderer8"/>
-                              <attributes>
-                                <attribute name="text">0</attribute>
-                              </attributes>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="left_attach">2</property>
-                            <property name="top_attach">1</property>
-                          </packing>
-                        </child>
                       </object>
                       <packing>
                         <property name="position">2</property>


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