comparison finch/gntmenuutil.c @ 32819:2c6510167895 default tip

propagate from branch 'im.pidgin.pidgin.2.x.y' (head 3315c5dfbd0ad16511bdcf865e5b07c02d07df24) to branch 'im.pidgin.pidgin' (head cbd1eda6bcbf0565ae7766396bb8f6f419cb6a9a)
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 02 Jun 2012 02:30:49 +0000
parents 30a92ba1c39f
children
comparison
equal deleted inserted replaced
32818:01ff09d4a463 32819:2c6510167895
1 /**
2 * @file gntmenuutil.c GNT Menu Utility Functions
3 * @ingroup finch
4 */
5
6 /* finch
7 *
8 * Finch is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
25 */
26
27 #include <internal.h>
28 #include "finch.h"
29
30 #include "gnt.h"
31 #include "gntmenu.h"
32 #include "gntmenuitem.h"
33 #include "gntmenuutil.h"
34
35 static void
36 context_menu_callback(GntMenuItem *item, gpointer data)
37 {
38 PurpleMenuAction *action = data;
39 if (action) {
40 void (*callback)(gpointer, gpointer);
41 callback = (void (*)(gpointer, gpointer))
42 purple_menu_action_get_callback(action);
43 if (callback) {
44 gpointer ctx = g_object_get_data(G_OBJECT(item), "menuctx");
45 callback(ctx, purple_menu_action_get_data(action));
46 }
47 }
48 }
49
50 void
51 gnt_append_menu_action(GntMenu *menu, PurpleMenuAction *action, gpointer ctx)
52 {
53 GList *list;
54 GntMenuItem *item;
55
56 if (action == NULL)
57 return;
58
59 item = gnt_menuitem_new(purple_menu_action_get_label(action));
60 if (purple_menu_action_get_callback(action)) {
61 gnt_menuitem_set_callback(item, context_menu_callback, action);
62 g_object_set_data(G_OBJECT(item), "menuctx", ctx);
63 }
64 gnt_menu_add_item(menu, item);
65
66 list = purple_menu_action_get_children(action);
67
68 if (list) {
69 GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP);
70 gnt_menuitem_set_submenu(item, GNT_MENU(sub));
71 for (; list; list = g_list_delete_link(list, list))
72 gnt_append_menu_action(GNT_MENU(sub), list->data, action);
73 purple_menu_action_set_children(action, NULL);
74 }
75
76 g_signal_connect_swapped(G_OBJECT(menu), "destroy",
77 G_CALLBACK(purple_menu_action_free), action);
78 }
79