diff options
author | Thomas Haller <thaller@redhat.com> | 2015-09-11 12:24:56 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-09-11 13:40:46 +0200 |
commit | c29058d2386e6a0ee432595f489431fb601bd9c3 (patch) | |
tree | 144b264428e1df5ff259415ada050586c454c75f | |
parent | 6fddffa7d7a9065d33157fbbf90ad1c989c5fed7 (diff) | |
download | network-manager-applet-c29058d2386e6a0ee432595f489431fb601bd9c3.tar.gz |
libnma: refactor registering PopupMenuItemInfo in nma_utils_setup_password_storage()
-rw-r--r-- | src/libnm-gtk/nm-ui-utils.c | 69 | ||||
-rw-r--r-- | src/libnma/nma-ui-utils.c | 69 |
2 files changed, 52 insertions, 86 deletions
diff --git a/src/libnm-gtk/nm-ui-utils.c b/src/libnm-gtk/nm-ui-utils.c index a1522dc4..8b21d81c 100644 --- a/src/libnm-gtk/nm-ui-utils.c +++ b/src/libnm-gtk/nm-ui-utils.c @@ -758,6 +758,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, @@ -799,7 +820,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 " */ @@ -822,48 +842,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); diff --git a/src/libnma/nma-ui-utils.c b/src/libnma/nma-ui-utils.c index 6cf62157..081fc491 100644 --- a/src/libnma/nma-ui-utils.c +++ b/src/libnma/nma-ui-utils.c @@ -193,6 +193,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, @@ -234,7 +255,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 " */ @@ -257,48 +277,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); |