[network-manager-applet: 5/20] libnm-gtk/editor: make NMSetting optional in password storage functions



commit 0eae20ad791105f7c552fbb82e4edb93bac14480
Author: Jiří Klimeš <jklimes redhat com>
Date:   Thu Apr 9 12:18:32 2015 +0200

    libnm-gtk/editor: make NMSetting optional in password storage functions
    
    And allow passing secret flags instead of the setting. This may be more
    convenient in some cases.

 src/libnm-gtk/nm-ui-utils.c               |   57 +++++++++++++++--------------
 src/libnm-gtk/nm-ui-utils.h               |    9 +++--
 src/wireless-security/eap-method-leap.c   |    5 ++-
 src/wireless-security/eap-method-simple.c |    5 ++-
 src/wireless-security/eap-method-tls.c    |    5 ++-
 src/wireless-security/ws-leap.c           |    5 ++-
 src/wireless-security/ws-wep-key.c        |    6 ++--
 src/wireless-security/ws-wpa-psk.c        |    6 ++--
 8 files changed, 53 insertions(+), 45 deletions(-)
---
diff --git a/src/libnm-gtk/nm-ui-utils.c b/src/libnm-gtk/nm-ui-utils.c
index dbbc50e..99782af 100644
--- a/src/libnm-gtk/nm-ui-utils.c
+++ b/src/libnm-gtk/nm-ui-utils.c
@@ -673,22 +673,28 @@ icon_release_cb (GtkEntry *entry,
 
 /**
  * nma_utils_setup_password_storage:
- * @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)
+ * @initial_flags: initial secret flags to setup password menu from
+ * @setting: #NMSetting containing the password, or NULL
+ * @password_flags_name: name of the secret flags (like psk-flags), or NULL
  *
  * Adds a secondary icon and creates a popup menu for password entry.
+ * The active menu item is set up according to initial_flags, or
+ * from @setting/@password_flags_name (if they are not NULL).
+ * If the @setting/@password_flags_name are not NULL, secret flags will
+ * be automatically updated in the setting when menu is changed.
  */
 void
-nma_utils_setup_password_storage (NMSetting *setting,
-                                  GtkWidget *passwd_entry,
+nma_utils_setup_password_storage (GtkWidget *passwd_entry,
+                                  NMSettingSecretFlags initial_flags,
+                                  NMSetting *setting,
                                   const char *password_flags_name)
 {
        GtkWidget *popup_menu;
        GtkWidget *item1, *item2;
        GSList *group;
        PopupMenuItemInfo *info;
+       NMSettingSecretFlags secret_flags;
 
        gtk_entry_set_icon_from_icon_name (GTK_ENTRY (passwd_entry), GTK_ENTRY_ICON_SECONDARY, 
"document-save");
        popup_menu = gtk_menu_new ();
@@ -728,47 +734,45 @@ nma_utils_setup_password_storage (NMSetting *setting,
        gtk_menu_attach_to_widget (GTK_MENU (popup_menu), passwd_entry, NULL);
 
        /* Initialize active item for password-storage popup menu */
-       if (setting) {
-               NMSettingSecretFlags secret_flags = NM_SETTING_SECRET_FLAG_NONE;
+       if (setting && password_flags_name)
                nm_setting_get_secret_flags (setting, password_flags_name, &secret_flags, NULL);
+       else
+               secret_flags = initial_flags;
 
-               if (secret_flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED)
-                       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item1), TRUE);
-               else {
-                       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item2), TRUE);
-                       /* Use different icon for system-storage */
-                       change_password_storage_icon (passwd_entry, 2);
-               }
-       } else {
+       if (secret_flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED)
                gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item1), TRUE);
+       else {
+               gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item2), TRUE);
+               /* Use different icon for system-storage */
+               change_password_storage_icon (passwd_entry, 2);
        }
 }
 
 /**
  * nma_utils_update_password_storage:
- * @setting: #NMSetting containing the password
- * @secret_flags: secret flags to use
  * @passwd_entry: #GtkEntry with the password
- * @password_flags_name: name of the storage flags for password
- *   (like psk-flags)
+ * @secret_flags: secret flags to set
+ * @setting: #NMSetting containing the password, or NULL
+ * @password_flags_name: name of the secret flags (like psk-flags), or NULL
+ *
+ * Updates secret flags in the password storage popup menu and also
+ * in the @setting (if @setting and @password_flags_name are not NULL).
  *
- * Updates secret flags and the storage popup menu.
  */
 void
-nma_utils_update_password_storage (NMSetting *setting,
+nma_utils_update_password_storage (GtkWidget *passwd_entry,
                                    NMSettingSecretFlags secret_flags,
-                                   GtkWidget *passwd_entry,
+                                   NMSetting *setting,
                                    const char *password_flags_name)
 {
        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);
+       if (setting && password_flags_name)
+               nm_setting_set_secret_flags (setting, password_flags_name, secret_flags, NULL);
 
+       /* Update password-storage popup menu to reflect secret flags */
        menu_list = gtk_menu_get_for_attach_widget (passwd_entry);
        for (iter = menu_list; iter; iter = g_list_next (iter)) {
                if (g_object_get_data (G_OBJECT (iter->data), PASSWORD_STORAGE_MENU_TAG)) {
@@ -777,7 +781,6 @@ nma_utils_update_password_storage (NMSetting *setting,
                }
        }
 
-       /* Update password-storage popup menu to reflect secret flags */
        if (menu) {
                GtkRadioMenuItem *item, *item_user, *item_system;
                GSList *group;
diff --git a/src/libnm-gtk/nm-ui-utils.h b/src/libnm-gtk/nm-ui-utils.h
index e03f20a..b2ca452 100644
--- a/src/libnm-gtk/nm-ui-utils.h
+++ b/src/libnm-gtk/nm-ui-utils.h
@@ -41,12 +41,13 @@ 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 (NMSetting *setting,
-                                       GtkWidget *passwd_entry,
+void nma_utils_setup_password_storage (GtkWidget *passwd_entry,
+                                       NMSettingSecretFlags initial_flags,
+                                       NMSetting *setting,
                                        const char *password_flags_name);
-void nma_utils_update_password_storage (NMSetting *setting,
+void nma_utils_update_password_storage (GtkWidget *passwd_entry,
                                         NMSettingSecretFlags secret_flags,
-                                        GtkWidget *passwd_entry,
+                                        NMSetting *setting,
                                         const char *password_flags_name);
 
 #endif /* NMA_UI_UTILS_H */
diff --git a/src/wireless-security/eap-method-leap.c b/src/wireless-security/eap-method-leap.c
index 2e6cf80..edf12eb 100644
--- a/src/wireless-security/eap-method-leap.c
+++ b/src/wireless-security/eap-method-leap.c
@@ -99,7 +99,8 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
                GtkWidget *passwd_entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, 
"eap_leap_password_entry"));
                g_assert (passwd_entry);
 
-               nma_utils_update_password_storage (NM_SETTING (s_8021x), flags, passwd_entry, 
parent->password_flags_name);
+               nma_utils_update_password_storage (passwd_entry, flags,
+                                                  NM_SETTING (s_8021x), parent->password_flags_name);
        }
 }
 
@@ -223,7 +224,7 @@ eap_method_leap_new (WirelessSecurity *ws_parent,
        /* Create password-storage popup menu for password entry under entry's secondary icon */
        if (connection)
                s_8021x = nm_connection_get_setting_802_1x (connection);
-       nma_utils_setup_password_storage ((NMSetting *) s_8021x, widget, parent->password_flags_name);
+       nma_utils_setup_password_storage (widget, 0, (NMSetting *) s_8021x, 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 7f65c1b..7a09099 100644
--- a/src/wireless-security/eap-method-simple.c
+++ b/src/wireless-security/eap-method-simple.c
@@ -160,7 +160,8 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
                GtkWidget *passwd_entry = GTK_WIDGET (gtk_builder_get_object (parent->builder, 
"eap_simple_password_entry"));
                g_assert (passwd_entry);
 
-               nma_utils_update_password_storage (NM_SETTING (s_8021x), flags, passwd_entry, 
parent->password_flags_name);
+               nma_utils_update_password_storage (passwd_entry, flags,
+                                                  NM_SETTING (s_8021x), parent->password_flags_name);
        }
 }
 
@@ -330,7 +331,7 @@ eap_method_simple_new (WirelessSecurity *ws_parent,
        /* Create password-storage popup menu for password entry under entry's secondary icon */
        if (connection)
                s_8021x = nm_connection_get_setting_802_1x (connection);
-       nma_utils_setup_password_storage ((NMSetting *) s_8021x, widget, parent->password_flags_name);
+       nma_utils_setup_password_storage (widget, 0, (NMSetting *) s_8021x, 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 91b36c2..1828cc1 100644
--- a/src/wireless-security/eap-method-tls.c
+++ b/src/wireless-security/eap-method-tls.c
@@ -180,7 +180,8 @@ fill_connection (EAPMethod *parent, NMConnection *connection, NMSettingSecretFla
 
        /* Update secret flags and popup when editing the connection */
        if (method->editing_connection) {
-               nma_utils_update_password_storage (NM_SETTING (s_8021x), flags, passwd_entry, 
parent->password_flags_name);
+               nma_utils_update_password_storage (passwd_entry, flags,
+                                                  NM_SETTING (s_8021x), parent->password_flags_name);
        }
 
        /* TLS client certificate */
@@ -485,7 +486,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 ((NMSetting *) s_8021x, widget, parent->password_flags_name);
+       nma_utils_setup_password_storage (widget, 0, (NMSetting *) s_8021x, 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 234cb68..d192c30 100644
--- a/src/wireless-security/ws-leap.c
+++ b/src/wireless-security/ws-leap.c
@@ -116,7 +116,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_wireless_sec), secret_flags, passwd_entry, 
sec->password_flags_name);
+               nma_utils_update_password_storage (passwd_entry, secret_flags,
+                                                  NM_SETTING (s_wireless_sec), sec->password_flags_name);
 }
 
 static void
@@ -173,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 ((NMSetting *) wsec, widget, sec->password_flags_name);
+       nma_utils_setup_password_storage (widget, 0, (NMSetting *) wsec, 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 941d479..c1b87ef 100644
--- a/src/wireless-security/ws-wep-key.c
+++ b/src/wireless-security/ws-wep-key.c
@@ -186,8 +186,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 (passwd_entry, secret_flags,
+                                                  NM_SETTING (s_wsec), sec->password_flags_name);
 }
 
 static void
@@ -267,7 +267,7 @@ ws_wep_key_new (NMConnection *connection,
        /* Create password-storage popup menu for password entry under entry's secondary icon */
        if (connection)
                setting = (NMSetting *) nm_connection_get_setting_wireless_security (connection);
-       nma_utils_setup_password_storage (setting, widget, sec->password_flags_name);
+       nma_utils_setup_password_storage (widget, 0, setting, 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 f5c1f13..9ee97e7 100644
--- a/src/wireless-security/ws-wpa-psk.c
+++ b/src/wireless-security/ws-wpa-psk.c
@@ -129,8 +129,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 (passwd_entry, secret_flags,
+                                                  NM_SETTING (s_wireless_sec), wpa_psk->password_flags_name);
 
        wireless_security_clear_ciphers (connection);
        if (is_adhoc) {
@@ -197,7 +197,7 @@ ws_wpa_psk_new (NMConnection *connection, gboolean secrets_only)
        /* Create password-storage popup menu for password entry under entry's secondary icon */
        if (connection)
                setting = (NMSetting *) nm_connection_get_setting_wireless_security (connection);
-       nma_utils_setup_password_storage (setting, widget, sec->password_flags_name);
+       nma_utils_setup_password_storage (widget, 0, setting, sec->password_flags_name);
 
        /* Fill secrets, if any */
        if (connection)


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