Simplify Facebook API soup session setup.
[pidgin-git.git] / finch / gntmenuutil.c
blob5dfca77d9f63d855129ccd83c0a4957befee643d
1 /*
2 * finch
4 * Finch is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
23 #include <internal.h>
24 #include "finch.h"
26 #include "gnt.h"
27 #include "gntmenu.h"
28 #include "gntmenuitem.h"
29 #include "gntmenuutil.h"
31 static void
32 context_menu_callback(GntMenuItem *item, gpointer data)
34 PurpleActionMenu *action = data;
35 if (action) {
36 void (*callback)(gpointer, gpointer);
37 callback = (void (*)(gpointer, gpointer))
38 purple_action_menu_get_callback(action);
39 if (callback) {
40 gpointer ctx = g_object_get_data(G_OBJECT(item), "menuctx");
41 callback(ctx, purple_action_menu_get_data(action));
46 void
47 finch_append_menu_action(GntMenu *menu, PurpleActionMenu *action, gpointer ctx)
49 GList *list;
50 GntMenuItem *item;
51 const gchar *label;
52 gchar *clean_label = NULL;
54 if (action == NULL)
55 return;
56 label = purple_action_menu_get_label(action);
58 if (strchr(label, '_') != NULL) {
59 clean_label = g_strdup(label);
60 purple_str_strip_char(clean_label, '_');
61 label = clean_label;
63 item = gnt_menuitem_new(label);
64 g_free(clean_label);
66 if (purple_action_menu_get_callback(action)) {
67 gnt_menuitem_set_callback(item, context_menu_callback, action);
68 g_object_set_data(G_OBJECT(item), "menuctx", ctx);
70 gnt_menu_add_item(menu, item);
72 list = purple_action_menu_get_children(action);
74 if (list) {
75 GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP);
76 gnt_menuitem_set_submenu(item, GNT_MENU(sub));
77 for (; list; list = g_list_delete_link(list, list))
78 finch_append_menu_action(GNT_MENU(sub), list->data, action);
79 purple_action_menu_set_children(action, NULL);
82 g_signal_connect_swapped(G_OBJECT(menu), "destroy",
83 G_CALLBACK(purple_action_menu_free), action);