[network-manager-applet/jk/password-icon-1-0: 3/17] libnm-gtk/editor: change nma_utils_setup_password_storage() to take NMSetting
- From: Jiří Klimeš <jklimes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/jk/password-icon-1-0: 3/17] libnm-gtk/editor: change nma_utils_setup_password_storage() to take NMSetting
- Date: Fri, 24 Apr 2015 12:15:57 +0000 (UTC)
commit 9d8662390de3bc3b726cc1dfea4021db4f894b19
Author: Jiří Klimeš <jklimes redhat com>
Date: Wed Apr 1 10:32:46 2015 +0200
libnm-gtk/editor: change nma_utils_setup_password_storage() to take NMSetting
It is more straightforward and it will be easier to use in VPN plugins.
src/libnm-gtk/nm-ui-utils.c | 39 +++++++++++++++-------------
src/libnm-gtk/nm-ui-utils.h | 3 +-
src/wireless-security/eap-method-leap.c | 5 +++-
src/wireless-security/eap-method-simple.c | 5 +++-
src/wireless-security/eap-method-tls.c | 2 +-
src/wireless-security/ws-leap.c | 2 +-
src/wireless-security/ws-wep-key.c | 8 ++++-
src/wireless-security/ws-wpa-psk.c | 8 ++++-
8 files changed, 44 insertions(+), 28 deletions(-)
---
diff --git a/src/libnm-gtk/nm-ui-utils.c b/src/libnm-gtk/nm-ui-utils.c
index d3f9e43..dbbc50e 100644
--- a/src/libnm-gtk/nm-ui-utils.c
+++ b/src/libnm-gtk/nm-ui-utils.c
@@ -611,8 +611,7 @@ change_password_storage_icon (GtkWidget *passwd_entry, int number)
}
typedef struct {
- NMConnection *connection;
- const char *setting_name;
+ NMSetting *setting;
const char *password_flags_name;
int item_number;
GtkWidget *passwd_entry;
@@ -621,6 +620,10 @@ typedef struct {
static void
popup_menu_item_info_destroy (gpointer data)
{
+ PopupMenuItemInfo *info = (PopupMenuItemInfo *) data;
+
+ if (info->setting)
+ g_object_unref (info->setting);
g_slice_free (PopupMenuItemInfo, data);
}
@@ -628,13 +631,12 @@ static void
activate_menu_item_cb (GtkMenuItem *menuitem, gpointer user_data)
{
PopupMenuItemInfo *info = (PopupMenuItemInfo *) user_data;
- NMSetting *setting;
NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
/* Get current secret flags */
- setting = nm_connection_get_setting_by_name (info->connection, info->setting_name);
- if (setting)
- nm_setting_get_secret_flags (setting, info->password_flags_name, &secret_flags, NULL);
+ if (info->setting)
+ nm_setting_get_secret_flags (info->setting, info->password_flags_name,
+ &secret_flags, NULL);
/* Update password flags according to the password-storage popup menu */
if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menuitem))) {
@@ -644,8 +646,9 @@ activate_menu_item_cb (GtkMenuItem *menuitem, gpointer user_data)
secret_flags &= ~NM_SETTING_SECRET_FLAG_AGENT_OWNED;
/* Update the secret flags */
- if (setting)
- nm_setting_set_secret_flags (setting, info->password_flags_name, secret_flags, NULL);
+ if (info->setting)
+ nm_setting_set_secret_flags (info->setting, info->password_flags_name,
+ secret_flags, NULL);
/* Change icon */
change_password_storage_icon (info->passwd_entry, info->item_number);
@@ -670,8 +673,7 @@ icon_release_cb (GtkEntry *entry,
/**
* nma_utils_setup_password_storage:
- * @connection: an #NMConnection
- * @setting_name: name of the setting containing the password
+ * @setting: #NMSetting containing the password
* @passwd_entry: password #GtkEntry which the icon is attached to
* @password_flags_name: name of the storage flags for password
* (like psk-flags)
@@ -679,8 +681,7 @@ icon_release_cb (GtkEntry *entry,
* Adds a secondary icon and creates a popup menu for password entry.
*/
void
-nma_utils_setup_password_storage (NMConnection *connection,
- const char *setting_name,
+nma_utils_setup_password_storage (NMSetting *setting,
GtkWidget *passwd_entry,
const char *password_flags_name)
{
@@ -688,7 +689,6 @@ nma_utils_setup_password_storage (NMConnection *connection,
GtkWidget *item1, *item2;
GSList *group;
PopupMenuItemInfo *info;
- NMSetting *setting;
gtk_entry_set_icon_from_icon_name (GTK_ENTRY (passwd_entry), GTK_ENTRY_ICON_SECONDARY,
"document-save");
popup_menu = gtk_menu_new ();
@@ -701,9 +701,11 @@ nma_utils_setup_password_storage (NMConnection *connection,
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item1);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item2);
+ if (setting)
+ g_object_ref (setting);
+
info = g_slice_new0 (PopupMenuItemInfo);
- info->connection = connection;
- info->setting_name = setting_name;
+ info->setting = setting;
info->password_flags_name = password_flags_name;
info->item_number = 1;
info->passwd_entry = passwd_entry;
@@ -713,8 +715,7 @@ nma_utils_setup_password_storage (NMConnection *connection,
(GClosureNotify) popup_menu_item_info_destroy, 0);
info = g_slice_new0 (PopupMenuItemInfo);
- info->connection = connection;
- info->setting_name = setting_name;
+ info->setting = setting;
info->password_flags_name = password_flags_name;
info->item_number = 2;
info->passwd_entry = passwd_entry;
@@ -727,7 +728,6 @@ nma_utils_setup_password_storage (NMConnection *connection,
gtk_menu_attach_to_widget (GTK_MENU (popup_menu), passwd_entry, NULL);
/* Initialize active item for password-storage popup menu */
- setting = nm_connection_get_setting_by_name (connection, setting_name);
if (setting) {
NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
nm_setting_get_secret_flags (setting, password_flags_name, &secret_flags, NULL);
@@ -763,6 +763,9 @@ nma_utils_update_password_storage (NMSetting *setting,
GList *menu_list, *iter;
GtkWidget *menu = NULL;
+ if (!setting)
+ return;
+
/* Update secret flags (WEP_KEY_FLAGS, PSK_FLAGS, ...) in the security setting */
nm_setting_set_secret_flags (setting, password_flags_name, secret_flags, NULL);
diff --git a/src/libnm-gtk/nm-ui-utils.h b/src/libnm-gtk/nm-ui-utils.h
index a3e7e99..e03f20a 100644
--- a/src/libnm-gtk/nm-ui-utils.h
+++ b/src/libnm-gtk/nm-ui-utils.h
@@ -41,8 +41,7 @@ char **nma_utils_disambiguate_device_names (NMDevice **devices,
int num_devices);
char *nma_utils_get_connection_device_name (NMConnection *connection);
-void nma_utils_setup_password_storage (NMConnection *connection,
- const char *setting_name,
+void nma_utils_setup_password_storage (NMSetting *setting,
GtkWidget *passwd_entry,
const char *password_flags_name);
void nma_utils_update_password_storage (NMSetting *setting,
diff --git a/src/wireless-security/eap-method-leap.c b/src/wireless-security/eap-method-leap.c
index f89754f..2f15a17 100644
--- a/src/wireless-security/eap-method-leap.c
+++ b/src/wireless-security/eap-method-leap.c
@@ -175,6 +175,7 @@ eap_method_leap_new (WirelessSecurity *ws_parent,
EAPMethodLEAP *method;
EAPMethod *parent;
GtkWidget *widget;
+ NMSetting8021x *s_8021x = NULL;
parent = eap_method_init (sizeof (EAPMethodLEAP),
validate,
@@ -221,7 +222,9 @@ eap_method_leap_new (WirelessSecurity *ws_parent,
ws_parent);
/* Create password-storage popup menu for password entry under entry's secondary icon */
- nma_utils_setup_password_storage (connection, NM_SETTING_802_1X_SETTING_NAME, widget,
parent->password_flags_name);
+ if (connection)
+ s_8021x = nm_connection_get_setting_802_1x (connection);
+ nma_utils_setup_password_storage ((NMSetting *) s_8021x, widget, parent->password_flags_name);
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "show_checkbutton_eapleap"));
g_assert (widget);
diff --git a/src/wireless-security/eap-method-simple.c b/src/wireless-security/eap-method-simple.c
index cb869f6..3134da8 100644
--- a/src/wireless-security/eap-method-simple.c
+++ b/src/wireless-security/eap-method-simple.c
@@ -281,6 +281,7 @@ eap_method_simple_new (WirelessSecurity *ws_parent,
EAPMethod *parent;
EAPMethodSimple *method;
GtkWidget *widget;
+ NMSetting8021x *s_8021x = NULL;
parent = eap_method_init (sizeof (EAPMethodSimple),
validate,
@@ -329,7 +330,9 @@ eap_method_simple_new (WirelessSecurity *ws_parent,
ws_parent);
/* Create password-storage popup menu for password entry under entry's secondary icon */
- nma_utils_setup_password_storage (connection, NM_SETTING_802_1X_SETTING_NAME, widget,
parent->password_flags_name);
+ if (connection)
+ s_8021x = nm_connection_get_setting_802_1x (connection);
+ nma_utils_setup_password_storage ((NMSetting *) s_8021x, widget, parent->password_flags_name);
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "eap_password_always_ask"));
g_assert (widget);
diff --git a/src/wireless-security/eap-method-tls.c b/src/wireless-security/eap-method-tls.c
index 332b921..0bf3fd2 100644
--- a/src/wireless-security/eap-method-tls.c
+++ b/src/wireless-security/eap-method-tls.c
@@ -488,7 +488,7 @@ eap_method_tls_new (WirelessSecurity *ws_parent,
ws_parent);
/* Create password-storage popup menu for password entry under entry's secondary icon */
- nma_utils_setup_password_storage (connection, NM_SETTING_802_1X_SETTING_NAME, widget,
parent->password_flags_name);
+ nma_utils_setup_password_storage ((NMSetting *) s_8021x, widget, parent->password_flags_name);
widget = GTK_WIDGET (gtk_builder_get_object (parent->builder, "show_checkbutton_eaptls"));
g_assert (widget);
diff --git a/src/wireless-security/ws-leap.c b/src/wireless-security/ws-leap.c
index aaf53f1..4254c88 100644
--- a/src/wireless-security/ws-leap.c
+++ b/src/wireless-security/ws-leap.c
@@ -174,7 +174,7 @@ ws_leap_new (NMConnection *connection, gboolean secrets_only)
sec);
/* Create password-storage popup menu for password entry under entry's secondary icon */
- nma_utils_setup_password_storage (connection, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, widget,
sec->password_flags_name);
+ nma_utils_setup_password_storage ((NMSetting *) wsec, widget, sec->password_flags_name);
if (wsec)
update_secrets (WIRELESS_SECURITY (sec), connection);
diff --git a/src/wireless-security/ws-wep-key.c b/src/wireless-security/ws-wep-key.c
index 3743526..4d82d99 100644
--- a/src/wireless-security/ws-wep-key.c
+++ b/src/wireless-security/ws-wep-key.c
@@ -189,7 +189,8 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection)
/* Update secret flags and popup when editing the connection */
if (sec->editing_connection)
- nma_utils_update_password_storage (NM_SETTING (s_wsec), secret_flags, passwd_entry,
sec->password_flags_name);
+ nma_utils_update_password_storage (NM_SETTING (s_wsec), secret_flags,
+ passwd_entry, sec->password_flags_name);
}
static void
@@ -240,6 +241,7 @@ ws_wep_key_new (NMConnection *connection,
WirelessSecurityWEPKey *sec;
GtkWidget *widget;
NMSettingWirelessSecurity *s_wsec = NULL;
+ NMSetting *setting = NULL;
guint8 default_key_idx = 0;
gboolean is_adhoc = adhoc_create;
gboolean is_shared_key = FALSE;
@@ -266,7 +268,9 @@ ws_wep_key_new (NMConnection *connection,
gtk_entry_set_width_chars (GTK_ENTRY (widget), 28);
/* Create password-storage popup menu for password entry under entry's secondary icon */
- nma_utils_setup_password_storage (connection, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, widget,
sec->password_flags_name);
+ if (connection)
+ setting = (NMSetting *) nm_connection_get_setting_wireless_security (connection);
+ nma_utils_setup_password_storage (setting, widget, sec->password_flags_name);
if (connection) {
NMSettingWireless *s_wireless;
diff --git a/src/wireless-security/ws-wpa-psk.c b/src/wireless-security/ws-wpa-psk.c
index 494bbae..048a017 100644
--- a/src/wireless-security/ws-wpa-psk.c
+++ b/src/wireless-security/ws-wpa-psk.c
@@ -130,7 +130,8 @@ fill_connection (WirelessSecurity *parent, NMConnection *connection)
/* Update secret flags and popup when editing the connection */
if (wpa_psk->editing_connection)
- nma_utils_update_password_storage (NM_SETTING (s_wireless_sec), secret_flags, passwd_entry,
wpa_psk->password_flags_name);
+ nma_utils_update_password_storage (NM_SETTING (s_wireless_sec), secret_flags,
+ passwd_entry, wpa_psk->password_flags_name);
wireless_security_clear_ciphers (connection);
if (is_adhoc) {
@@ -167,6 +168,7 @@ ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only)
{
WirelessSecurity *parent;
WirelessSecurityWPAPSK *sec;
+ NMSetting *setting = NULL;
GtkWidget *widget;
parent = wireless_security_init (sizeof (WirelessSecurityWPAPSK),
@@ -194,7 +196,9 @@ ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only)
gtk_entry_set_width_chars (GTK_ENTRY (widget), 28);
/* Create password-storage popup menu for password entry under entry's secondary icon */
- nma_utils_setup_password_storage (connection, NM_SETTING_WIRELESS_SECURITY_SETTING_NAME, widget,
sec->password_flags_name);
+ if (connection)
+ setting = (NMSetting *) nm_connection_get_setting_wireless_security (connection);
+ nma_utils_setup_password_storage (setting, widget, sec->password_flags_name);
/* Fill secrets, if any */
if (connection)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]