finch/gntmenuutil.c

Thu, 07 Feb 2019 01:57:11 -0500

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Thu, 07 Feb 2019 01:57:11 -0500
changeset 39427
603dec76dd4a
parent 35918
3f84738fbc15
child 39481
4db28449567d
permissions
-rw-r--r--

Add fallback for talkatu.

32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
1 /* finch
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
2 *
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
3 * Finch is the legal property of its developers, whose names are too numerous
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
5 * source distribution.
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
6 *
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
10 * (at your option) any later version.
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
11 *
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
15 * GNU General Public License for more details.
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
16 *
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
20 */
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
21
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
22 #include <internal.h>
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
23 #include "finch.h"
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
24
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
25 #include "gnt.h"
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
26 #include "gntmenu.h"
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
27 #include "gntmenuitem.h"
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
28 #include "gntmenuutil.h"
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
29
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
30 static void
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
31 context_menu_callback(GntMenuItem *item, gpointer data)
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
32 {
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
33 PurpleMenuAction *action = data;
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
34 if (action) {
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
35 void (*callback)(gpointer, gpointer);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
36 callback = (void (*)(gpointer, gpointer))
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
37 purple_menu_action_get_callback(action);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
38 if (callback) {
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
39 gpointer ctx = g_object_get_data(G_OBJECT(item), "menuctx");
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
40 callback(ctx, purple_menu_action_get_data(action));
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
41 }
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
42 }
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
43 }
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
44
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
45 void
35494
e631108a5464 Fix namespace issues in libgnt and finch.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
46 finch_append_menu_action(GntMenu *menu, PurpleMenuAction *action, gpointer ctx)
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
47 {
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
48 GList *list;
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
49 GntMenuItem *item;
35918
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
50 const gchar *label;
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
51 gchar *clean_label = NULL;
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
52
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
53 if (action == NULL)
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
54 return;
35918
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
55 label = purple_menu_action_get_label(action);
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
56
35918
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
57 if (strchr(label, '_') != NULL) {
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
58 clean_label = g_strdup(label);
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
59 purple_str_strip_char(clean_label, '_');
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
60 label = clean_label;
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
61 }
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
62 item = gnt_menuitem_new(label);
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
63 g_free(clean_label);
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
64
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
65 if (purple_menu_action_get_callback(action)) {
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
66 gnt_menuitem_set_callback(item, context_menu_callback, action);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
67 g_object_set_data(G_OBJECT(item), "menuctx", ctx);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
68 }
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
69 gnt_menu_add_item(menu, item);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
70
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
71 list = purple_menu_action_get_children(action);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
72
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
73 if (list) {
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
74 GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
75 gnt_menuitem_set_submenu(item, GNT_MENU(sub));
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
76 for (; list; list = g_list_delete_link(list, list))
35494
e631108a5464 Fix namespace issues in libgnt and finch.
Ankit Vani <a@nevitus.org>
parents: 35454
diff changeset
77 finch_append_menu_action(GNT_MENU(sub), list->data, action);
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
78 purple_menu_action_set_children(action, NULL);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
79 }
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
80
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
81 g_signal_connect_swapped(G_OBJECT(menu), "destroy",
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
82 G_CALLBACK(purple_menu_action_free), action);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
83 }

mercurial