[network-manager-pptp/nm-1-0] properties: use libnm-gtk password menu funcs for password (bgo #731891)
- From: Jiří Klimeš <jklimes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-pptp/nm-1-0] properties: use libnm-gtk password menu funcs for password (bgo #731891)
- Date: Thu, 9 Jul 2015 11:30:47 +0000 (UTC)
commit 0aee0d4da26f28dd2b42d50fb3bb790f57f54dd9
Author: Jiří Klimeš <jklimes redhat com>
Date: Fri Apr 24 10:45:27 2015 +0200
properties: use libnm-gtk password menu funcs for password (bgo #731891)
Remove combo-box with password menu types.
https://bugzilla.gnome.org/show_bug.cgi?id=731891
(cherry picked from commit 8d3448d6d0b4863974d4a16ee85ec0bf28d5b6a7)
properties/Makefile.am | 4 +-
properties/nm-pptp-dialog.ui | 26 --------
properties/nm-pptp.c | 136 +++++++++++++-----------------------------
3 files changed, 44 insertions(+), 122 deletions(-)
---
diff --git a/properties/Makefile.am b/properties/Makefile.am
index b2f3672..8c2bd96 100644
--- a/properties/Makefile.am
+++ b/properties/Makefile.am
@@ -18,6 +18,7 @@ libnm_pptp_properties_la_CFLAGS = \
$(GLIB_CFLAGS) \
$(GTK_CFLAGS) \
$(NM_CFLAGS) \
+ $(NMGTK_CFLAGS) \
-DICONDIR=\""$(datadir)/pixmaps"\" \
-DUIDIR=\""$(uidir)"\" \
-DLOCALEDIR=\""$(datadir)/locale"\" \
@@ -26,7 +27,8 @@ libnm_pptp_properties_la_CFLAGS = \
libnm_pptp_properties_la_LIBADD = \
$(GTK_LIBS) \
- $(NM_LIBS)
+ $(NM_LIBS) \
+ $(NMGTK_LIBS)
libnm_pptp_properties_la_LDFLAGS = \
-avoid-version
diff --git a/properties/nm-pptp-dialog.ui b/properties/nm-pptp-dialog.ui
index 9d4ec8c..df1db20 100644
--- a/properties/nm-pptp-dialog.ui
+++ b/properties/nm-pptp-dialog.ui
@@ -608,23 +608,6 @@ config: domain <domain></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">1</property>
- </packing>
- </child>
- <child>
<object class="GtkEntry" id="user_password_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -689,15 +672,6 @@ config: user <name></property>
<property name="top_attach">2</property>
</packing>
</child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
</object>
</child>
</object>
diff --git a/properties/nm-pptp.c b/properties/nm-pptp.c
index 4f4a349..8ea28c2 100644
--- a/properties/nm-pptp.c
+++ b/properties/nm-pptp.c
@@ -40,6 +40,7 @@
#include <nm-setting-vpn.h>
#include <nm-setting-connection.h>
#include <nm-setting-ip4-config.h>
+#include <nm-ui-utils.h>
#include "src/nm-pptp-service.h"
#include "nm-pptp.h"
@@ -50,10 +51,6 @@
#define PPTP_PLUGIN_DESC _("Compatible with Microsoft and other PPTP VPN servers.")
#define PPTP_PLUGIN_SERVICE NM_DBUS_SERVICE_PPTP
-#define PW_TYPE_SAVE 0
-#define PW_TYPE_ASK 1
-#define PW_TYPE_UNUSED 2
-
typedef void (*ChangedCallback) (GtkWidget *widget, gpointer user_data);
/************** plugin class **************/
@@ -220,14 +217,9 @@ setup_password_widget (PptpPluginUiWidget *self,
gboolean new_connection)
{
PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
- NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
GtkWidget *widget;
const char *value;
- /* Default to agent-owned for new connections */
- 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);
@@ -235,10 +227,7 @@ setup_password_widget (PptpPluginUiWidget *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);
}
@@ -258,87 +247,47 @@ show_toggled_cb (GtkCheckButton *button, PptpPluginUiWidget *self)
}
static void
-pw_type_combo_changed_cb (GtkWidget *combo, gpointer user_data)
+password_storage_changed_cb (GObject *entry,
+ GParamSpec *pspec,
+ gpointer user_data)
{
PptpPluginUiWidget *self = PPTP_PLUGIN_UI_WIDGET (user_data);
- PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
- GtkWidget *entry;
- entry = GTK_WIDGET (gtk_builder_get_object (priv->builder, "user_password_entry"));
- g_assert (entry);
-
- /* 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;
- }
-
- stuff_changed_cb (combo, self);
+ stuff_changed_cb (NULL, self);
}
static void
-init_one_pw_combo (PptpPluginUiWidget *self,
- NMSettingVPN *s_vpn,
- const char *combo_name,
- const char *secret_key,
- const char *entry_name)
+init_password_icon (PptpPluginUiWidget *self,
+ NMSettingVPN *s_vpn,
+ const char *secret_key,
+ const char *entry_name)
{
PptpPluginUiWidgetPrivate *priv = PPTP_PLUGIN_UI_WIDGET_GET_PRIVATE (self);
- int active = -1;
- GtkWidget *widget;
- GtkListStore *store;
- GtkTreeIter iter;
+ GtkWidget *entry;
const char *value = NULL;
- 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.
*/
- 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;
+ entry = GTK_WIDGET (gtk_builder_get_object (priv->builder, entry_name));
+ g_assert (entry);
- store = gtk_list_store_new (1, G_TYPE_STRING);
+ nma_utils_setup_password_storage (entry, 0, (NMSetting *) s_vpn, secret_key,
+ TRUE, FALSE);
+
+ /* If there's no password and no flags in the setting,
+ * initialize flags as "always-ask".
+ */
if (s_vpn)
nm_setting_get_secret_flags (NM_SETTING (s_vpn), secret_key, &pw_flags, NULL);
+ value = gtk_entry_get_text (GTK_ENTRY (entry));
+ if ((!value || !*value) && (pw_flags == NM_SETTING_SECRET_FLAG_NONE))
+ nma_utils_update_password_storage (entry, NM_SETTING_SECRET_FLAG_NOT_SAVED,
+ (NMSetting *) s_vpn, secret_key);
- 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;
-
- 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_combo_changed_cb (widget, self);
- 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 gboolean
@@ -404,11 +353,10 @@ init_plugin_ui (PptpPluginUiWidget *self, NMConnection *connection, GError **err
NM_PPTP_KEY_PASSWORD,
priv->new_connection);
- init_one_pw_combo (self,
- s_vpn,
- "user_pass_type_combo",
- NM_PPTP_KEY_PASSWORD,
- "user_password_entry");
+ init_password_icon (self,
+ s_vpn,
+ NM_PPTP_KEY_PASSWORD,
+ "user_password_entry");
return TRUE;
}
@@ -434,32 +382,25 @@ static void
save_password_and_flags (NMSettingVPN *s_vpn,
GtkBuilder *builder,
const char *entry_name,
- const char *combo_name,
const char *secret_key)
{
- NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
+ NMSettingSecretFlags flags;
const char *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);
break;
- case PW_TYPE_UNUSED:
- flags |= NM_SETTING_SECRET_FLAG_NOT_REQUIRED;
- break;
- case PW_TYPE_ASK:
default:
- flags |= NM_SETTING_SECRET_FLAG_NOT_SAVED;
break;
}
@@ -501,7 +442,6 @@ update_connection (NMVpnPluginUiWidgetInterface *iface,
save_password_and_flags (s_vpn,
priv->builder,
"user_password_entry",
- "user_pass_type_combo",
NM_PPTP_KEY_PASSWORD);
/* Domain */
@@ -599,6 +539,12 @@ dispose (GObject *object)
{
PptpPluginUiWidget *plugin = PPTP_PLUGIN_UI_WIDGET (object);
PptpPluginUiWidgetPrivate *priv = PPTP_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);
if (priv->group)
g_object_unref (priv->group);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]