finch/gntmenuutil.c

Mon, 22 Aug 2022 22:05:55 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 22 Aug 2022 22:05:55 -0500
changeset 41514
a96768bacb59
parent 40621
406ff566ad57
permissions
-rw-r--r--

Create PurpleAuthorizationRequest and use it for notifications.

This replaces the old internal representation of authorization requests as well
as the UI's implementation of their own objects. Everything is now controlled
via PurpleAuthorizationRequest and the UI's display the notification for
interaction.

Testing Done:
Verified the notification and actions work in both finch and pidgin.

Reviewed at https://reviews.imfreedom.org/r/1613/

39887
9c8f874c74a0 Clean up all of the license headers
Gary Kramlich <grim@reaperworld.com>
parents: 39483
diff changeset
1 /*
9c8f874c74a0 Clean up all of the license headers
Gary Kramlich <grim@reaperworld.com>
parents: 39483
diff changeset
2 * finch
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
3 *
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
4 * 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
5 * 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
6 * source distribution.
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
7 *
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
8 * 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
9 * 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
10 * 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
11 * (at your option) any later version.
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
12 *
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
13 * 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
14 * 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
15 * 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
16 * 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
17 *
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
18 * 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
19 * 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
20 * 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
21 */
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
22
40616
064ff9f4150a Don't allow libraries to include their own global header files.
Gary Kramlich <grim@reaperworld.com>
parents: 40511
diff changeset
23 #include <glib.h>
064ff9f4150a Don't allow libraries to include their own global header files.
Gary Kramlich <grim@reaperworld.com>
parents: 40511
diff changeset
24
40439
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 39887
diff changeset
25 #include <purple.h>
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 39887
diff changeset
26
40511
ec08ac1f7d5f Fix Finch for the libgnt single header file
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
27 #include <gnt.h>
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
28
40621
406ff566ad57 Add missing self-referential #include.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40616
diff changeset
29 #include "gntmenuutil.h"
406ff566ad57 Add missing self-referential #include.
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40616
diff changeset
30
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
31 static void
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
32 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
33 {
39481
4db28449567d Rename PurpleMenuAction to PurpleActionMenu
Gary Kramlich <grim@reaperworld.com>
parents: 35918
diff changeset
34 PurpleActionMenu *action = data;
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
35 if (action) {
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
36 void (*callback)(gpointer, gpointer);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
37 callback = (void (*)(gpointer, gpointer))
39483
ab4728087d87 Rename purple_menu_action_* to purple_action_menu_*
Gary Kramlich <grim@reaperworld.com>
parents: 39481
diff changeset
38 purple_action_menu_get_callback(action);
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
39 if (callback) {
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
40 gpointer ctx = g_object_get_data(G_OBJECT(item), "menuctx");
39483
ab4728087d87 Rename purple_menu_action_* to purple_action_menu_*
Gary Kramlich <grim@reaperworld.com>
parents: 39481
diff changeset
41 callback(ctx, purple_action_menu_get_data(action));
32850
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
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
46 void
39481
4db28449567d Rename PurpleMenuAction to PurpleActionMenu
Gary Kramlich <grim@reaperworld.com>
parents: 35918
diff changeset
47 finch_append_menu_action(GntMenu *menu, PurpleActionMenu *action, gpointer ctx)
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
48 {
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
49 GList *list;
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
50 GntMenuItem *item;
35918
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
51 const gchar *label;
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
52 gchar *clean_label = NULL;
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
53
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
54 if (action == NULL)
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
55 return;
39483
ab4728087d87 Rename purple_menu_action_* to purple_action_menu_*
Gary Kramlich <grim@reaperworld.com>
parents: 39481
diff changeset
56 label = purple_action_menu_get_label(action);
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
57
35918
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
58 if (strchr(label, '_') != NULL) {
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
59 clean_label = g_strdup(label);
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
60 purple_str_strip_char(clean_label, '_');
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
61 label = clean_label;
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
62 }
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
63 item = gnt_menuitem_new(label);
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
64 g_free(clean_label);
3f84738fbc15 Finch: better UI for menus
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35494
diff changeset
65
39483
ab4728087d87 Rename purple_menu_action_* to purple_action_menu_*
Gary Kramlich <grim@reaperworld.com>
parents: 39481
diff changeset
66 if (purple_action_menu_get_callback(action)) {
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
67 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
68 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
69 }
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
70 gnt_menu_add_item(menu, item);
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
71
39483
ab4728087d87 Rename purple_menu_action_* to purple_action_menu_*
Gary Kramlich <grim@reaperworld.com>
parents: 39481
diff changeset
72 list = purple_action_menu_get_children(action);
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
73
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
74 if (list) {
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
75 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
76 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
77 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
78 finch_append_menu_action(GNT_MENU(sub), list->data, action);
39483
ab4728087d87 Rename purple_menu_action_* to purple_action_menu_*
Gary Kramlich <grim@reaperworld.com>
parents: 39481
diff changeset
79 purple_action_menu_set_children(action, NULL);
32850
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
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
82 g_signal_connect_swapped(G_OBJECT(menu), "destroy",
39483
ab4728087d87 Rename purple_menu_action_* to purple_action_menu_*
Gary Kramlich <grim@reaperworld.com>
parents: 39481
diff changeset
83 G_CALLBACK(purple_action_menu_free), action);
32850
79912ff55187 I should probably add these files, too...
Elliott Sales de Andrade <qulogic@pidgin.im>
parents:
diff changeset
84 }

mercurial