[network-manager-applet/jk/password-icon-1-0: 9/10] libnm-gtk: add nma_utils_menu_to_secret_flags() for getting secret flags



commit eed2387d555cb1d76aa1b7b47dced12742c0dcf8
Author: Jiří Klimeš <jklimes redhat com>
Date:   Tue Apr 7 18:29:46 2015 +0200

    libnm-gtk: add nma_utils_menu_to_secret_flags() for getting secret flags
    
    The function converts active menu item to secret flags and return them.

 src/libnm-gtk/nm-ui-utils.c |   45 +++++++++++++++++++++++++++++++++++++++++++
 src/libnm-gtk/nm-ui-utils.h |    1 +
 2 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/src/libnm-gtk/nm-ui-utils.c b/src/libnm-gtk/nm-ui-utils.c
index ed78227..c5e1ff7 100644
--- a/src/libnm-gtk/nm-ui-utils.c
+++ b/src/libnm-gtk/nm-ui-utils.c
@@ -840,6 +840,51 @@ nma_utils_setup_password_storage (GtkWidget *passwd_entry,
 }
 
 /**
+ * nma_utils_menu_to_secret_flags:
+ * @passwd_entry: password #GtkEntry which the password icon/menu is attached to
+ *
+ * Returns secret flags corresponding to the selected password storage menu
+ * in the attached icon
+ *
+ * Returns: secret flags corresponding to the active item in password menu
+ */
+NMSettingSecretFlags
+nma_utils_menu_to_secret_flags (GtkWidget *passwd_entry)
+{
+       GList *menu_list, *iter;
+       GtkWidget *menu = NULL;
+       NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE;
+
+       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)) {
+                       menu = iter->data;
+                       break;
+               }
+       }
+
+       /* Translate password popup memu to secret flags */
+       if (menu) {
+               MenuItem idx;
+               GList *list;
+               int i, length;
+
+               list = gtk_container_get_children (GTK_CONTAINER (menu));
+               length = g_list_length (list);
+               for (i = 0; i < length; i++) {
+                       if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (list->data))) {
+                               idx =  (MenuItem) i;
+                               break;
+                       }
+                       list = g_list_next (list);
+               }
+
+               flags = menu_item_to_secret_flags (idx);
+       }
+       return flags;
+}
+
+/**
  * nma_utils_update_password_storage:
  * @passwd_entry: #GtkEntry with the password
  * @secret_flags: secret flags to set
diff --git a/src/libnm-gtk/nm-ui-utils.h b/src/libnm-gtk/nm-ui-utils.h
index aa03c7a..9db1795 100644
--- a/src/libnm-gtk/nm-ui-utils.h
+++ b/src/libnm-gtk/nm-ui-utils.h
@@ -46,6 +46,7 @@ void nma_utils_setup_password_storage (GtkWidget *passwd_entry,
                                        NMSetting *setting,
                                        const char *password_flags_name,
                                        gboolean with_not_required);
+NMSettingSecretFlags nma_utils_menu_to_secret_flags (GtkWidget *passwd_entry);
 void nma_utils_update_password_storage (GtkWidget *passwd_entry,
                                         NMSettingSecretFlags secret_flags,
                                         NMSetting *setting,


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