Mercurial > pidgin
changeset 32005:3b2ceeb8883b
Hide-a-PurpleMenuAction.
author | masca@cpw.pidgin.im |
---|---|
date | Thu, 01 Sep 2011 04:23:42 +0000 |
parents | 39d69f5bf146 |
children | f31dc7349961 |
files | ChangeLog.API finch/gntblist.c libpurple/util.c libpurple/util.h pidgin/gtkutils.c |
diffstat | 5 files changed, 170 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog.API Tue Aug 30 22:07:19 2011 +0000 +++ b/ChangeLog.API Thu Sep 01 04:23:42 2011 +0000 @@ -8,6 +8,13 @@ * purple_notify_searchresult_column_is_visible * purple_notify_searchresult_column_set_visible * purple_notify_user_info_prepend_pair_plaintext + * purple_menu_action_get_callback + * purple_menu_action_get_children + * purple_menu_action_get_data + * purple_menu_action_set_label + * purple_menu_action_set_data + * purple_menu_action_set_callback + * purple_menu_action_set_children * purple_request_field_get_tooltip * purple_request_field_group_get_fields_list * purple_request_field_set_tooltip @@ -90,6 +97,7 @@ purple_util_fetch_url_request_len, insetad. * PurpleConnectionUiOps.report_disconnect_reason * struct _GtkIMHtmlFontDetail + * struct _PurpleMenuAction * struct _PurplePounce * struct _PurpleRequestField * struct _PurpleRoomlist
--- a/finch/gntblist.c Tue Aug 30 22:07:19 2011 +0000 +++ b/finch/gntblist.c Thu Sep 01 04:23:42 2011 +0000 @@ -1078,9 +1078,10 @@ PurpleBlistNode *node = ggblist->cnode; if (action) { void (*callback)(PurpleBlistNode *, gpointer); - callback = (void (*)(PurpleBlistNode *, gpointer))action->callback; + callback = (void (*)(PurpleBlistNode *, gpointer)) + purple_menu_action_get_callback(action); if (callback) - callback(node, action->data); + callback(node, purple_menu_action_get_data(action)); else return; } @@ -1095,15 +1096,17 @@ if (action == NULL) return; - item = gnt_menuitem_new(action->label); - if (action->callback) + item = gnt_menuitem_new(purple_menu_action_get_label(action)); + if (purple_menu_action_get_callback(action)) gnt_menuitem_set_callback(GNT_MENU_ITEM(item), context_menu_callback, action); gnt_menu_add_item(menu, GNT_MENU_ITEM(item)); - if (action->children) { + list = purple_menu_action_get_children(action); + + if (list) { GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP); gnt_menuitem_set_submenu(item, GNT_MENU(sub)); - for (list = action->children; list; list = list->next) + for (; list; list = list->next) gnt_append_menu_action(GNT_MENU(sub), list->data, action); } } @@ -1123,7 +1126,7 @@ PurpleMenuAction *act = (PurpleMenuAction *) list->data; if (!act) continue; - act->data = node; + purple_menu_action_set_data(act, node); gnt_append_menu_action(menu, act, NULL); g_signal_connect_swapped(G_OBJECT(menu), "destroy", G_CALLBACK(purple_menu_action_free), act); @@ -1216,7 +1219,7 @@ autojoin_toggled(GntMenuItem *item, gpointer data) { PurpleMenuAction *action = data; - purple_blist_node_set_bool(action->data, "gnt-autojoin", + purple_blist_node_set_bool(purple_menu_action_get_data(action), "gnt-autojoin", gnt_menuitem_check_get_checked(GNT_MENU_ITEM_CHECK(item))); } @@ -1224,7 +1227,8 @@ create_chat_menu(GntMenu *menu, PurpleChat *chat) { PurpleMenuAction *action = purple_menu_action_new(_("Auto-join"), NULL, chat, NULL); - GntMenuItem *check = gnt_menuitem_check_new(action->label); + GntMenuItem *check = gnt_menuitem_check_new( + purple_menu_action_get_label(action)); gnt_menuitem_check_set_checked(GNT_MENU_ITEM_CHECK(check), purple_blist_node_get_bool((PurpleBlistNode*)chat, "gnt-autojoin")); gnt_menu_add_item(menu, check);
--- a/libpurple/util.c Tue Aug 30 22:07:19 2011 +0000 +++ b/libpurple/util.c Thu Sep 01 04:23:42 2011 +0000 @@ -73,6 +73,14 @@ PurpleAccount *account; }; +struct _PurpleMenuAction +{ + char *label; + PurpleCallback callback; + gpointer data; + GList *children; +}; + static char *custom_user_dir = NULL; static char *user_dir = NULL; @@ -98,6 +106,62 @@ g_free(act); } +char * purple_menu_action_get_label(const PurpleMenuAction *act) +{ + g_return_val_if_fail(act != NULL, NULL); + + return act->label; +} + +PurpleCallback purple_menu_action_get_callback(const PurpleMenuAction *act) +{ + g_return_val_if_fail(act != NULL, NULL); + + return act->callback; +} + +gpointer purple_menu_action_get_data(const PurpleMenuAction *act) +{ + g_return_val_if_fail(act != NULL, NULL); + + return act->data; +} + +GList* purple_menu_action_get_children(const PurpleMenuAction *act) +{ + g_return_val_if_fail(act != NULL, NULL); + + return act->children; +} + +void purple_menu_action_set_label(PurpleMenuAction *act, char *label) +{ + g_return_if_fail(act != NULL); + + act-> label = label; +} + +void purple_menu_action_set_callback(PurpleMenuAction *act, PurpleCallback callback) +{ + g_return_if_fail(act != NULL); + + act->callback = callback; +} + +void purple_menu_action_set_data(PurpleMenuAction *act, gpointer data) +{ + g_return_if_fail(act != NULL); + + act->data = data; +} + +void purple_menu_action_set_children(PurpleMenuAction *act, GList *children) +{ + g_return_if_fail(act != NULL); + + act->children = children; +} + void purple_util_init(void) {
--- a/libpurple/util.h Tue Aug 30 22:07:19 2011 +0000 +++ b/libpurple/util.h Thu Sep 01 04:23:42 2011 +0000 @@ -51,14 +51,6 @@ extern "C" { #endif -struct _PurpleMenuAction -{ - char *label; - PurpleCallback callback; - gpointer data; - GList *children; -}; - typedef char *(*PurpleInfoFieldFormatCallback)(const char *field, size_t len); /** @@ -96,6 +88,74 @@ void purple_menu_action_free(PurpleMenuAction *act); /** + * Returns the label of the PurpleMenuAction. + * + * @param act The PurpleMenuAction. + * + * @return The label string. + */ +char * purple_menu_action_get_label(const PurpleMenuAction *act); + +/** + * Returns the callback of the PurpleMenuAction. + * + * @param act The PurpleMenuAction. + * + * @return The callback function. + */ +PurpleCallback purple_menu_action_get_callback(const PurpleMenuAction *act); + +/** + * Returns the data stored in the PurpleMenuAction. + * + * @param act The PurpleMenuAction. + * + * @return The data. + */ +gpointer purple_menu_action_get_data(const PurpleMenuAction *act); + +/** + * Returns the children of the PurpleMenuAction. + * + * @param act The PurpleMenuAction. + * + * @return The GList of children. + */ +GList* purple_menu_action_get_children(const PurpleMenuAction *act); + +/** + * Set the label to the PurpleMenuAction. + * + * @param act The menu action. + * @param label The label for the menu action. + */ +void purple_menu_action_set_label(PurpleMenuAction *act, char *label); + +/** + * Set the callback that will be used by the PurpleMenuAction. + * + * @param act The menu action. + * @param callback The callback. + */ +void purple_menu_action_set_callback(PurpleMenuAction *act, PurpleCallback callback); + +/** + * Set the label to the PurpleMenuAction. + * + * @param act The menu action. + * @param data The data used by this PurpleMenuAction + */ +void purple_menu_action_set_data(PurpleMenuAction *act, gpointer data); + +/** + * Set the children of the PurpleMenuAction. + * + * @param act The menu action. + * @param children The PurpleMenuAtion children + */ +void purple_menu_action_set_children(PurpleMenuAction *act, GList *children); + +/** * Set the appropriate presence values for the currently playing song. * * @param title The title of the song, @c NULL to unset the value.
--- a/pidgin/gtkutils.c Tue Aug 30 22:07:19 2011 +0000 +++ b/pidgin/gtkutils.c Thu Sep 01 04:23:42 2011 +0000 @@ -1816,21 +1816,27 @@ gpointer object) { GtkWidget *menuitem; + GList *list; if (act == NULL) { return pidgin_separator(menu); } - if (act->children == NULL) { - menuitem = gtk_menu_item_new_with_mnemonic(act->label); - - if (act->callback != NULL) { + list = purple_menu_action_get_children(act); + menuitem = gtk_menu_item_new_with_mnemonic(purple_menu_action_get_label(act)); + + if (list == NULL) { + PurpleCallback callback; + + callback = purple_menu_action_get_callback(act); + + if (callback != NULL) { g_object_set_data(G_OBJECT(menuitem), "purplecallback", - act->callback); + callback); g_object_set_data(G_OBJECT(menuitem), "purplecallbackdata", - act->data); + purple_menu_action_get_data(act)); g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(menu_action_cb), object); @@ -1844,7 +1850,6 @@ GtkWidget *submenu = NULL; GtkAccelGroup *group; - menuitem = gtk_menu_item_new_with_mnemonic(act->label); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); submenu = gtk_menu_new(); @@ -1852,19 +1857,20 @@ group = gtk_menu_get_accel_group(GTK_MENU(menu)); if (group) { - char *path = g_strdup_printf("%s/%s", GTK_MENU_ITEM(menuitem)->accel_path, act->label); + char *path = g_strdup_printf("%s/%s", GTK_MENU_ITEM(menuitem)->accel_path, + purple_menu_action_get_label(act)); gtk_menu_set_accel_path(GTK_MENU(submenu), path); g_free(path); gtk_menu_set_accel_group(GTK_MENU(submenu), group); } - for (l = act->children; l; l = l->next) { + for (l = list; l; l = l->next) { PurpleMenuAction *act = (PurpleMenuAction *)l->data; pidgin_append_menu_action(submenu, act, object); } - g_list_free(act->children); - act->children = NULL; + g_list_free(list); + purple_menu_action_set_children(act, NULL); } purple_menu_action_free(act); return menuitem;