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



commit 2afa861dc26913a9d68e9f8f246a1735c7d31c7c
Author: Jiří Klimeš <jklimes redhat com>
Date:   Thu Apr 23 13:59:15 2015 +0200

    properties: use libnm-gtk password menu funcs for password (bgo #731891)
    
    Remove combo-boxes with password menu types.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=731891

 properties/Makefile.am       |    4 +-
 properties/nm-vpnc-dialog.ui |  188 ++++++++----------------------------------
 properties/nm-vpnc.c         |  189 +++++++++++++-----------------------------
 properties/tests/Makefile.am |    2 +
 4 files changed, 99 insertions(+), 284 deletions(-)
---
diff --git a/properties/Makefile.am b/properties/Makefile.am
index 506cae4..c4de949 100644
--- a/properties/Makefile.am
+++ b/properties/Makefile.am
@@ -16,6 +16,7 @@ libnm_vpnc_properties_la_CPPFLAGS = \
        $(GLIB_CFLAGS) \
        $(GTK_CFLAGS) \
        $(NM_CFLAGS) \
+       $(NMGTK_CFLAGS) \
        -I$(top_srcdir)/src \
        -DICONDIR=\""$(datadir)/pixmaps"\" \
        -DUIDIR=\""$(uidir)"\" \
@@ -25,7 +26,8 @@ libnm_vpnc_properties_la_CPPFLAGS = \
 
 libnm_vpnc_properties_la_LIBADD = \
        $(GTK_LIBS) \
-       $(NM_LIBS)
+       $(NM_LIBS) \
+       $(NMGTK_LIBS)
 
 libnm_vpnc_properties_la_LDFLAGS = \
         -avoid-version
diff --git a/properties/nm-vpnc-dialog.ui b/properties/nm-vpnc-dialog.ui
index b892413..e5a2ef6 100644
--- a/properties/nm-vpnc-dialog.ui
+++ b/properties/nm-vpnc-dialog.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.1 -->
+<!-- Generated with glade 3.18.3 -->
 <interface>
   <requires lib="gtk+" version="3.4"/>
   <object class="GtkAdjustment" id="adjustment1">
@@ -12,28 +12,6 @@
     <property name="can_focus">False</property>
     <property name="stock">gtk-preferences</property>
   </object>
-  <object class="GtkListStore" id="model1">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0"> </col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model2">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0"> </col>
-      </row>
-    </data>
-  </object>
   <object class="GtkBox" id="vpnc-vbox">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
@@ -74,44 +52,6 @@
                 <property name="row_spacing">6</property>
                 <property name="column_spacing">6</property>
                 <child>
-                  <object class="GtkComboBox" id="group_pass_type_combo">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="model">model1</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer1"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">4</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkComboBox" id="user_pass_type_combo">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="model">model2</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="renderer2"/>
-                      <attributes>
-                        <attribute name="text">0</attribute>
-                      </attributes>
-                    </child>
-                  </object>
-                  <packing>
-                    <property name="left_attach">2</property>
-                    <property name="top_attach">2</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
-                  </packing>
-                </child>
-                <child>
                   <object class="GtkCheckButton" id="show_passwords_checkbutton">
                     <property name="label" translatable="yes">Sho_w passwords</property>
                     <property name="use_action_appearance">False</property>
@@ -125,8 +65,6 @@
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">5</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -140,8 +78,6 @@ config: IPSec secret &lt;group_password&gt;</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">4</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -156,8 +92,6 @@ config: IPSec secret &lt;group_password&gt;</property>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">4</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -172,8 +106,6 @@ config: IPSec secret &lt;group_password&gt;</property>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">0</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -188,8 +120,6 @@ config: IPSec secret &lt;group_password&gt;</property>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">3</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -202,8 +132,6 @@ config: IPSec gateway &lt;gateway&gt;</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">0</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -216,8 +144,6 @@ config: IPSec ID &lt;group_name&gt;</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">3</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -232,8 +158,6 @@ config: IPSec ID &lt;group_name&gt;</property>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">2</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -247,8 +171,6 @@ config: Xauth password &lt;password&gt;</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">2</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -261,8 +183,6 @@ config: Xauth username &lt;user_name&gt;</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">1</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -277,8 +197,6 @@ config: Xauth username &lt;user_name&gt;</property>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">1</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -297,8 +215,7 @@ config: IKE Authmode hybrid</property>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">6</property>
-                    <property name="width">3</property>
-                    <property name="height">1</property>
+                    <property name="width">2</property>
                   </packing>
                 </child>
                 <child>
@@ -320,8 +237,6 @@ config: IKE Authmode hybrid</property>
                   <packing>
                     <property name="left_attach">0</property>
                     <property name="top_attach">7</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
@@ -334,28 +249,11 @@ config: CA-File</property>
                   <packing>
                     <property name="left_attach">1</property>
                     <property name="top_attach">7</property>
-                    <property name="width">1</property>
-                    <property name="height">1</property>
                   </packing>
                 </child>
                 <child>
                   <placeholder/>
                 </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
               </object>
             </child>
           </object>
@@ -398,6 +296,28 @@ config: CA-File</property>
       </packing>
     </child>
   </object>
+  <object class="GtkListStore" id="model1">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0"> </col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="model2">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0"> </col>
+      </row>
+    </data>
+  </object>
   <object class="GtkListStore" id="model3">
     <columns>
       <!-- column-name gchararray -->
@@ -442,6 +362,17 @@ config: CA-File</property>
       </row>
     </data>
   </object>
+  <object class="GtkListStore" id="model7">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0"> </col>
+      </row>
+    </data>
+  </object>
   <object class="GtkDialog" id="vpnc-advanced-dialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
@@ -531,8 +462,6 @@ config: CA-File</property>
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="top_attach">0</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -545,8 +474,6 @@ config: Domain &lt;domain&gt;</property>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="top_attach">0</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -566,8 +493,6 @@ config: Vendor &lt;cisco/netscreen&gt;</property>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="top_attach">2</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -582,8 +507,6 @@ config: Vendor &lt;cisco/netscreen&gt;</property>
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="top_attach">2</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -597,8 +520,6 @@ config: Vendor &lt;cisco/netscreen&gt;</property>
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="top_attach">3</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -611,8 +532,6 @@ config: Application version &lt;ASCII string&gt;</property>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="top_attach">3</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -686,8 +605,6 @@ config: DPD idle timeout (our side) 0</property>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="top_attach">6</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -701,8 +618,6 @@ config: DPD idle timeout (our side) 0</property>
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="top_attach">5</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -717,8 +632,6 @@ config: DPD idle timeout (our side) 0</property>
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="top_attach">4</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -732,8 +645,6 @@ config: DPD idle timeout (our side) 0</property>
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="top_attach">3</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -747,8 +658,6 @@ config: DPD idle timeout (our side) 0</property>
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="top_attach">2</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -766,8 +675,6 @@ config: Local Port &lt;0-65535&gt;</property>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="top_attach">5</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -787,8 +694,6 @@ config: Perfect Forward Secrecy &lt;nopfs/dh1/dh2/dh5/server&gt;</property>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="top_attach">4</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -808,8 +713,6 @@ config: IKE DH Group &lt;dh1/dh2/dh5&gt;</property>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="top_attach">3</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -829,8 +732,6 @@ config: NAT Traversal Mode &lt;natt/none/force-natt/cisco-udp&gt;</property>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="top_attach">2</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -850,8 +751,6 @@ config: nothing for Secure, 'Enable Single DES' for Weak, 'Enable no encryption'
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="top_attach">1</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -865,8 +764,6 @@ config: Interface name &lt;name&gt;</property>
                       <packing>
                         <property name="left_attach">1</property>
                         <property name="top_attach">0</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -880,8 +777,6 @@ config: Interface name &lt;name&gt;</property>
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="top_attach">1</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -895,8 +790,6 @@ config: Interface name &lt;name&gt;</property>
                       <packing>
                         <property name="left_attach">0</property>
                         <property name="top_attach">0</property>
-                        <property name="width">1</property>
-                        <property name="height">1</property>
                       </packing>
                     </child>
                     <child>
@@ -924,15 +817,4 @@ config: Interface name &lt;name&gt;</property>
       <action-widget response="0">apply_button</action-widget>
     </action-widgets>
   </object>
-  <object class="GtkListStore" id="model7">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0"> </col>
-      </row>
-    </data>
-  </object>
 </interface>
diff --git a/properties/nm-vpnc.c b/properties/nm-vpnc.c
index 19cff08..38b63ea 100644
--- a/properties/nm-vpnc.c
+++ b/properties/nm-vpnc.c
@@ -43,6 +43,7 @@
 #include <nm-setting-vpn.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-ip4-config.h>
+#include <nm-ui-utils.h>
 
 #include "nm-vpnc-service-defines.h"
 #include "nm-vpnc-helper.h"
@@ -56,10 +57,6 @@
 #define ENC_TYPE_WEAK   1
 #define ENC_TYPE_NONE   2
 
-#define PW_TYPE_SAVE   0
-#define PW_TYPE_ASK    1
-#define PW_TYPE_UNUSED 2
-
 #define NM_VPNC_LOCAL_PORT_DEFAULT 500
 
 /************** plugin class **************/
@@ -200,13 +197,9 @@ setup_password_widget (VpncPluginUiWidget *self,
                        gboolean new_connection)
 {
        VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
-       NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
        GtkWidget *widget;
        const char *value;
 
-       if (new_connection)
-               secret_flags = NM_SETTING_SECRET_FLAG_AGENT_OWNED;
-
        widget = (GtkWidget *) gtk_builder_get_object (priv->builder, entry_name);
        g_assert (widget);
        gtk_size_group_add_widget (priv->group, widget);
@@ -214,10 +207,7 @@ setup_password_widget (VpncPluginUiWidget *self,
        if (s_vpn) {
                value = nm_setting_vpn_get_secret (s_vpn, secret_name);
                gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
-               nm_setting_get_secret_flags (NM_SETTING (s_vpn), secret_name, &secret_flags, NULL);
        }
-       secret_flags &= ~(NM_SETTING_SECRET_FLAG_NOT_SAVED | NM_SETTING_SECRET_FLAG_NOT_REQUIRED);
-       g_object_set_data (G_OBJECT (widget), "flags", GUINT_TO_POINTER (secret_flags));
 
        g_signal_connect (widget, "changed", G_CALLBACK (stuff_changed_cb), self);
 }
@@ -241,48 +231,13 @@ show_toggled_cb (GtkCheckButton *button, VpncPluginUiWidget *self)
 }
 
 static void
-pw_type_changed_helper (VpncPluginUiWidget *self, GtkWidget *combo)
-{
-       VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
-       const char *entry = NULL;
-       GtkWidget *widget;
-
-       /* If the user chose "Not required", desensitize and clear the correct
-        * password entry.
-        */
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_pass_type_combo"));
-       if (combo == widget)
-               entry = "user_password_entry";
-       else {
-               widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "group_pass_type_combo"));
-               if (combo == widget)
-                       entry = "group_password_entry";
-       }
-       if (!entry)
-               return;
-
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, entry));
-       g_assert (widget);
-
-       switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) {
-       case PW_TYPE_ASK:
-       case PW_TYPE_UNUSED:
-               gtk_entry_set_text (GTK_ENTRY (widget), "");
-               gtk_widget_set_sensitive (widget, FALSE);
-               break;
-       default:
-               gtk_widget_set_sensitive (widget, TRUE);
-               break;
-       }
-}
-
-static void
-pw_type_combo_changed_cb (GtkWidget *combo, gpointer user_data)
+password_storage_changed_cb (GObject *entry,
+                             GParamSpec *pspec,
+                             gpointer user_data)
 {
        VpncPluginUiWidget *self = VPNC_PLUGIN_UI_WIDGET (user_data);
 
-       pw_type_changed_helper (self, combo);
-       stuff_changed_cb (combo, self);
+       stuff_changed_cb (NULL, self);
 }
 
 static const char *
@@ -301,66 +256,38 @@ secret_flags_to_pw_type (NMSettingVPN *s_vpn, const char *key)
 }
 
 static void
-init_one_pw_combo (VpncPluginUiWidget *self,
-                   NMSettingVPN *s_vpn,
-                   const char *combo_name,
-                   const char *secret_key,
-                   const char *type_key,
-                   const char *entry_name)
+init_password_icon (VpncPluginUiWidget *self,
+                    NMSettingVPN *s_vpn,
+                    const char *secret_key,
+                    const char *type_key,
+                    const char *entry_name)
 {
        VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
-       int active = -1;
-       GtkWidget *widget;
-       GtkListStore *store;
-       GtkTreeIter iter;
-       const char *value = NULL;
-       guint32 default_idx = 1;
-
-       /* 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.
-        */
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, entry_name));
-       g_assert (widget);
-       value = gtk_entry_get_text (GTK_ENTRY (widget));
-       if (value && strlen (value))
-               default_idx = 0;
-
-       store = gtk_list_store_new (1, G_TYPE_STRING);
-       if (s_vpn) {
-               value = secret_flags_to_pw_type (s_vpn, secret_key);
-               if (!value)
-                       value = nm_setting_vpn_get_data_item (s_vpn, type_key);
-       }
+       GtkWidget *entry;
+       const char *value;
+       const char *flags = NULL;
 
-       gtk_list_store_append (store, &iter);
-       gtk_list_store_set (store, &iter, 0, _("Saved"), -1);
-       if ((active < 0) && value) {
-               if (!strcmp (value, NM_VPNC_PW_TYPE_SAVE))
-                       active = 0;
-       }
+       entry = GTK_WIDGET (gtk_builder_get_object (priv->builder, entry_name));
+       g_assert (entry);
 
-       gtk_list_store_append (store, &iter);
-       gtk_list_store_set (store, &iter, 0, _("Always Ask"), -1);
-       if ((active < 0) && value) {
-               if (!strcmp (value, NM_VPNC_PW_TYPE_ASK))
-                       active = 1;
-       }
+       nma_utils_setup_password_storage (entry, 0, (NMSetting *) s_vpn, secret_key,
+                                         TRUE, FALSE);
 
-       gtk_list_store_append (store, &iter);
-       gtk_list_store_set (store, &iter, 0, _("Not Required"), -1);
-       if ((active < 0) && value) {
-               if (!strcmp (value, NM_VPNC_PW_TYPE_UNUSED))
-                       active = 2;
+       /* If there's no password and no flags in the setting,
+        * initialize flags as "always-ask".
+        */
+       if (s_vpn) {
+               flags = secret_flags_to_pw_type (s_vpn, secret_key);
+               if (!flags || !strcmp (flags, NM_VPNC_PW_TYPE_SAVE))
+                       flags = nm_setting_vpn_get_data_item (s_vpn, type_key);
        }
+       value = gtk_entry_get_text (GTK_ENTRY (entry));
+       if ((!value || !*value) && !flags)
+               nma_utils_update_password_storage (entry, NM_SETTING_SECRET_FLAG_NOT_SAVED,
+                                                  (NMSetting *) s_vpn, secret_key);
 
-       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, combo_name));
-       g_assert (widget);
-       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_changed_helper (self, widget);
-
-       g_signal_connect (G_OBJECT (widget), "changed", G_CALLBACK (pw_type_combo_changed_cb), self);
+       g_signal_connect (entry, "notify::secondary-icon-name",
+                         G_CALLBACK (password_storage_changed_cb), self);
 }
 
 static void
@@ -536,18 +463,16 @@ init_plugin_ui (VpncPluginUiWidget *self,
                               NM_VPNC_KEY_SECRET,
                               new_connection);
 
-       init_one_pw_combo (self,
-                          s_vpn,
-                          "user_pass_type_combo",
-                          NM_VPNC_KEY_XAUTH_PASSWORD,
-                          NM_VPNC_KEY_XAUTH_PASSWORD_TYPE,
-                          "user_password_entry");
-       init_one_pw_combo (self,
-                          s_vpn,
-                          "group_pass_type_combo",
-                          NM_VPNC_KEY_SECRET,
-                          NM_VPNC_KEY_SECRET_TYPE,
-                          "group_password_entry");
+       init_password_icon (self,
+                           s_vpn,
+                           NM_VPNC_KEY_XAUTH_PASSWORD,
+                           NM_VPNC_KEY_XAUTH_PASSWORD_TYPE,
+                           "user_password_entry");
+       init_password_icon (self,
+                           s_vpn,
+                           NM_VPNC_KEY_SECRET,
+                           NM_VPNC_KEY_SECRET_TYPE,
+                           "group_password_entry");
 
        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_entry"));
        g_return_val_if_fail (widget != NULL, FALSE);
@@ -858,36 +783,32 @@ static void
 save_one_password (NMSettingVPN *s_vpn,
                    GtkBuilder *builder,
                    const char *entry_name,
-                   const char *combo_name,
                    const char *secret_key,
                    const char *type_key)
 {
-       NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
+       NMSettingSecretFlags flags;
        const char *data_val = NULL, *password;
        GtkWidget *entry;
-       GtkWidget *combo;
 
-       /* Grab original password flags */
+       /* Get secret flags */
        entry = GTK_WIDGET (gtk_builder_get_object (builder, entry_name));
-       flags = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (entry), "flags"));
+       flags = nma_utils_menu_to_secret_flags (entry);
 
-       /* And set new ones based on the type combo */
-       combo = GTK_WIDGET (gtk_builder_get_object (builder, combo_name));
-       switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) {
-       case PW_TYPE_SAVE:
+       /* Save password and convert flags to legacy data items */
+       switch (flags) {
+       case NM_SETTING_SECRET_FLAG_NONE:
+       case NM_SETTING_SECRET_FLAG_AGENT_OWNED:
                password = gtk_entry_get_text (GTK_ENTRY (entry));
                if (password && strlen (password))
                        nm_setting_vpn_add_secret (s_vpn, secret_key, password);
                data_val = NM_VPNC_PW_TYPE_SAVE;
                break;
-       case PW_TYPE_UNUSED:
+       case NM_SETTING_SECRET_FLAG_NOT_REQUIRED:
                data_val = NM_VPNC_PW_TYPE_UNUSED;
-               flags |= NM_SETTING_SECRET_FLAG_NOT_REQUIRED;
                break;
-       case PW_TYPE_ASK:
+       case NM_SETTING_SECRET_FLAG_NOT_SAVED:
        default:
                data_val = NM_VPNC_PW_TYPE_ASK;
-               flags |= NM_SETTING_SECRET_FLAG_NOT_SAVED;
                break;
        }
 
@@ -1030,7 +951,6 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
        save_one_password (s_vpn,
                           priv->builder,
                           "user_password_entry",
-                          "user_pass_type_combo",
                           NM_VPNC_KEY_XAUTH_PASSWORD,
                           NM_VPNC_KEY_XAUTH_PASSWORD_TYPE);
 
@@ -1038,7 +958,6 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
        save_one_password (s_vpn,
                           priv->builder,
                           "group_password_entry",
-                          "group_pass_type_combo",
                           NM_VPNC_KEY_SECRET,
                           NM_VPNC_KEY_SECRET_TYPE);
 
@@ -1127,6 +1046,16 @@ dispose (GObject *object)
 {
        VpncPluginUiWidget *plugin = VPNC_PLUGIN_UI_WIDGET (object);
        VpncPluginUiWidgetPrivate *priv = VPNC_PLUGIN_UI_WIDGET_GET_PRIVATE (plugin);
+       GtkWidget *widget;
+
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_password_entry"));
+       g_signal_handlers_disconnect_by_func (G_OBJECT (widget),
+                                             (GCallback) password_storage_changed_cb,
+                                             plugin);
+       widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "group_password_entry"));
+       g_signal_handlers_disconnect_by_func (G_OBJECT (widget),
+                                             (GCallback) password_storage_changed_cb,
+                                             plugin);
 
        if (priv->group)
                g_object_unref (priv->group);
diff --git a/properties/tests/Makefile.am b/properties/tests/Makefile.am
index 25229e9..d2d43f6 100644
--- a/properties/tests/Makefile.am
+++ b/properties/tests/Makefile.am
@@ -9,6 +9,7 @@ test_import_export_CPPFLAGS = \
        $(GLIB_CFLAGS) \
        $(GTK_CFLAGS) \
        $(NM_CFLAGS) \
+       $(NMGTK_CFLAGS) \
        $(DBUS_CFLAGS)
 
 test_import_export_LDADD = \
@@ -16,6 +17,7 @@ test_import_export_LDADD = \
        $(GTK_LIBS) \
        $(DBUS_LIBS) \
        $(NM_LIBS) \
+       $(NMGTK_LIBS) \
        $(top_builddir)/properties/libnm-vpnc-properties.la
 
 if WITH_TESTS


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