[network-manager-applet/nma-1-0] libnma: refactor registering PopupMenuItemInfo in nma_utils_setup_password_storage()



commit b6dcbd0f05f7a0f4345f118a36c4550d0e1a5abd
Author: Thomas Haller <thaller redhat com>
Date:   Fri Sep 11 12:24:56 2015 +0200

    libnma: refactor registering PopupMenuItemInfo in nma_utils_setup_password_storage()
    
    (cherry picked from commit c29058d2386e6a0ee432595f489431fb601bd9c3)

 src/libnm-gtk/nm-ui-utils.c |   69 ++++++++++++++++--------------------------
 1 files changed, 26 insertions(+), 43 deletions(-)
---
diff --git a/src/libnm-gtk/nm-ui-utils.c b/src/libnm-gtk/nm-ui-utils.c
index 2e8c191..5185e7c 100644
--- a/src/libnm-gtk/nm-ui-utils.c
+++ b/src/libnm-gtk/nm-ui-utils.c
@@ -760,6 +760,27 @@ activate_menu_item_cb (GtkMenuItem *menuitem, gpointer user_data)
 }
 
 static void
+popup_menu_item_info_register (GtkWidget *item,
+                               NMSetting *setting,
+                               const char *password_flags_name,
+                               MenuItem item_number,
+                               GtkWidget *passwd_entry)
+{
+       PopupMenuItemInfo *info;
+
+       info = g_slice_new0 (PopupMenuItemInfo);
+       info->setting = setting ? g_object_ref (setting) : NULL;
+       info->password_flags_name = password_flags_name;
+       info->item_number = item_number;
+       info->passwd_entry = passwd_entry;
+
+       g_signal_connect_data (item, "activate",
+                              G_CALLBACK (activate_menu_item_cb),
+                              info,
+                              (GClosureNotify) popup_menu_item_info_destroy, 0);
+}
+
+static void
 icon_release_cb (GtkEntry *entry,
                  GtkEntryIconPosition position,
                  GdkEventButton *event,
@@ -801,7 +822,6 @@ nma_utils_setup_password_storage (GtkWidget *passwd_entry,
        GtkWidget *item[4];
        GSList *group;
        MenuItem idx;
-       PopupMenuItemInfo *info;
        NMSettingSecretFlags secret_flags;
 
        /* Whether entry should be sensitive if "always-ask" is active " */
@@ -824,48 +844,11 @@ nma_utils_setup_password_storage (GtkWidget *passwd_entry,
        if (with_not_required)
                gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), item[3]);
 
-       info = g_slice_new0 (PopupMenuItemInfo);
-       info->setting = setting ? g_object_ref (setting) : NULL;
-       info->password_flags_name = password_flags_name;
-       info->item_number = ITEM_STORAGE_USER;
-       info->passwd_entry = passwd_entry;
-       g_signal_connect_data (item[0], "activate",
-                              G_CALLBACK (activate_menu_item_cb),
-                              info,
-                              (GClosureNotify) popup_menu_item_info_destroy, 0);
-
-       info = g_slice_new0 (PopupMenuItemInfo);
-       info->setting = setting ? g_object_ref (setting) : NULL;
-       info->password_flags_name = password_flags_name;
-       info->item_number = ITEM_STORAGE_SYSTEM;
-       info->passwd_entry = passwd_entry;
-       g_signal_connect_data (item[1], "activate",
-                              G_CALLBACK (activate_menu_item_cb),
-                              info,
-                              (GClosureNotify) popup_menu_item_info_destroy, 0);
-
-       info = g_slice_new0 (PopupMenuItemInfo);
-       info->setting = setting ? g_object_ref (setting) : NULL;
-       info->password_flags_name = password_flags_name;
-       info->item_number = ITEM_STORAGE_ASK;
-       info->passwd_entry = passwd_entry;
-       g_signal_connect_data (item[2], "activate",
-                              G_CALLBACK (activate_menu_item_cb),
-                              info,
-                              (GClosureNotify) popup_menu_item_info_destroy, 0);
-
-
-       if (with_not_required) {
-               info = g_slice_new0 (PopupMenuItemInfo);
-               info->setting = setting ? g_object_ref (setting) : NULL;
-               info->password_flags_name = password_flags_name;
-               info->item_number = ITEM_STORAGE_UNUSED;
-               info->passwd_entry = passwd_entry;
-               g_signal_connect_data (item[3], "activate",
-                                      G_CALLBACK (activate_menu_item_cb),
-                                      info,
-                                      (GClosureNotify) popup_menu_item_info_destroy, 0);
-       }
+       popup_menu_item_info_register (item[0], setting, password_flags_name, ITEM_STORAGE_USER, 
passwd_entry);
+       popup_menu_item_info_register (item[1], setting, password_flags_name, ITEM_STORAGE_SYSTEM, 
passwd_entry);
+       popup_menu_item_info_register (item[2], setting, password_flags_name, ITEM_STORAGE_ASK, passwd_entry);
+       if (with_not_required)
+               popup_menu_item_info_register (item[3], setting, password_flags_name, ITEM_STORAGE_UNUSED, 
passwd_entry);
 
        g_signal_connect (passwd_entry, "icon-release", G_CALLBACK (icon_release_cb), popup_menu);
        gtk_menu_attach_to_widget (GTK_MENU (popup_menu), passwd_entry, NULL);


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