pidgin/pidginstatusbox.c

Thu, 12 Oct 2023 22:31:22 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Thu, 12 Oct 2023 22:31:22 -0500
changeset 42352
1c53950f9052
parent 42199
adf6d358d438
child 42450
bd1327c022d4
permissions
-rw-r--r--

Migrate from GtkFileChooserNative to GtkFileDialog

Testing Done:
Compiled, and opened a few dialogs from the demo protocol.

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

41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
1 /*
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
2 * Pidgin - Internet Messenger
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
4 *
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
5 * Pidgin is the legal property of its developers, whose names are too numerous
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
7 * source distribution.
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
8 *
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
12 * (at your option) any later version.
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
13 *
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
17 * GNU General Public License for more details.
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
18 *
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
21 */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
22
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
23 #include <glib/gi18n-lib.h>
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
24
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
25 #include <gtk/gtk.h>
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
26
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
27 #include <purple.h>
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
28
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
29 #include "pidginstatusbox.h"
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
30 #include "pidginiconname.h"
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
31 #include "pidginstatusdisplay.h"
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
33 #define SAVEDSTATUS_FORMAT "savedstatus_%lu"
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
34
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
35 struct _PidginStatusBox {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 GtkBox parent;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
38 GtkWidget *button;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
39 PidginStatusDisplay *display;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
40 GtkPopover *popover;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
42 GMenu *primitives;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
43 GMenu *saved_statuses;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
44 GList *custom_widgets;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
45 };
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
46
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 G_DEFINE_TYPE(PidginStatusBox, pidgin_status_box, GTK_TYPE_BOX)
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
48
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
49 /******************************************************************************
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 * Helpers
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 *****************************************************************************/
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
52 static GtkWidget *
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
53 pidgin_status_box_make_primitive_widget(const char *action, const char *id) {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
54 GtkWidget *button = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
55 GtkWidget *display = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
56 PurpleStatusPrimitive primitive = PURPLE_STATUS_UNSET;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
58 primitive = purple_primitive_get_type_from_id(id);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
59 display = pidgin_status_display_new_for_primitive(primitive);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
61 button = gtk_button_new();
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
62 gtk_widget_add_css_class(button, "flat");
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
63 gtk_button_set_child(GTK_BUTTON(button), display);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
65 gtk_actionable_set_action_name(GTK_ACTIONABLE(button), action);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
66 gtk_actionable_set_action_target(GTK_ACTIONABLE(button),
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
67 (const char *)G_VARIANT_TYPE_INT32,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
68 primitive);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
70 return button;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 static void
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
74 pidgin_status_box_populate_primitives(PidginStatusBox *status_box) {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
75 GtkPopoverMenu *popover = GTK_POPOVER_MENU(status_box->popover);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
76 GMenuModel *menu = G_MENU_MODEL(status_box->primitives);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
77 gint n_items = 0;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
79 n_items = g_menu_model_get_n_items(menu);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
80 for(gint index = 0; index < n_items; index++) {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
81 GtkWidget *button = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
82 char *action = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
83 char *target = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
84 char *custom_id = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
85
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
86 g_menu_model_get_item_attribute(menu, index, G_MENU_ATTRIBUTE_ACTION,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
87 "s", &action);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
88 g_menu_model_get_item_attribute(menu, index, G_MENU_ATTRIBUTE_TARGET,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
89 "s", &target);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
90 g_menu_model_get_item_attribute(menu, index, "custom", "s", &custom_id);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
91
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
92 button = pidgin_status_box_make_primitive_widget(action, target);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
93 gtk_popover_menu_add_child(popover, button, custom_id);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
95 g_free(action);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
96 g_free(target);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
97 g_free(custom_id);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
98 }
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
99 }
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
101 static char *
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
102 pidgin_status_box_make_savedstatus_widget(PurpleSavedStatus *saved_status,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
103 GtkWidget **widget)
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
104 {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
105 GtkWidget *button = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
106 GtkWidget *display = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
107 time_t creation_time = 0;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
109 display = pidgin_status_display_new_for_saved_status(saved_status);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
110
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
111 if(!purple_savedstatus_is_transient(saved_status)) {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
112 GtkWidget *image = gtk_image_new_from_icon_name("document-save");
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
113 gtk_widget_set_halign(image, GTK_ALIGN_END);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
114 gtk_widget_set_hexpand(image, TRUE);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
115 gtk_box_append(GTK_BOX(display), image);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
116 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
117
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
118 button = gtk_button_new();
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
119 gtk_widget_add_css_class(button, "flat");
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
120 gtk_button_set_child(GTK_BUTTON(button), display);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
122 creation_time = purple_savedstatus_get_creation_time(saved_status);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
123 gtk_actionable_set_action_name(GTK_ACTIONABLE(button), "status.set-saved");
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
124 gtk_actionable_set_action_target(GTK_ACTIONABLE(button),
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
125 (const char *)G_VARIANT_TYPE_INT64,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
126 creation_time);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
127 *widget = button;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
129 return g_strdup_printf(SAVEDSTATUS_FORMAT, creation_time);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
130 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
131
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
132 static void
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
133 pidgin_status_box_populate_saved_statuses(PidginStatusBox *status_box)
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
134 {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
135 GtkPopoverMenu *popover_menu = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
136 GMenu *menu = NULL;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137 GList *list, *cur;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139 list = purple_savedstatuses_get_popular(6);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 if (list == NULL) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 /* Odd... oh well, nothing we can do about it. */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 return;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
145 popover_menu = GTK_POPOVER_MENU(status_box->popover);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
146 menu = status_box->saved_statuses;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 for(cur = list; cur != NULL; cur = cur->next) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 PurpleSavedStatus *saved = cur->data;
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
149 GtkWidget *widget = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
150 char *id = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
151 GMenuItem *item = NULL;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
153 id = pidgin_status_box_make_savedstatus_widget(saved, &widget);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
154 item = g_menu_item_new(NULL, NULL);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
155 g_menu_item_set_attribute(item, "custom", "s", id);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
156 g_menu_append_item(menu, item);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
157 gtk_popover_menu_add_child(popover_menu, widget, id);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
158 status_box->custom_widgets = g_list_prepend(status_box->custom_widgets,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
159 widget);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
161 g_free(id);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
162 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
163
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 g_list_free(list);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
165 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
166
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 /******************************************************************************
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 * Callbacks
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
169 *****************************************************************************/
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
170 static void
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
171 pidgin_status_box_set_primitive(G_GNUC_UNUSED GSimpleAction *action,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
172 GVariant *parameter, gpointer data)
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
173 {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
174 PidginStatusBox *status_box = data;
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175 PurpleSavedStatus *saved_status = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 PurpleStatusPrimitive primitive;
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
177
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
178 gtk_menu_button_popdown(GTK_MENU_BUTTON(status_box->button));
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
180 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_INT32)) {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
181 g_critical("status.set-primitive action parameter is of incorrect type %s",
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
182 g_variant_get_type_string(parameter));
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
183 return;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
184 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
185
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
186 primitive = g_variant_get_int32(parameter);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
188 saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, NULL);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
189 if(saved_status == NULL) {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
190 saved_status = purple_savedstatus_new(NULL, primitive);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
192
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
193 if(saved_status != NULL) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194 if(saved_status != purple_savedstatus_get_current()) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195 purple_savedstatus_activate(saved_status);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 }
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
197 }
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
198 }
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
200 static void
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
201 pidgin_status_box_set_saved_status(G_GNUC_UNUSED GSimpleAction *action,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
202 GVariant *parameter, gpointer data)
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
203 {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
204 PidginStatusBox *status_box = data;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
205 PurpleSavedStatus *saved_status = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
206 time_t creation_time = 0;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
207
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
208 gtk_menu_button_popdown(GTK_MENU_BUTTON(status_box->button));
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
209
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
210 if(!g_variant_is_of_type(parameter, G_VARIANT_TYPE_INT64)) {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
211 g_critical("status.set-saved action parameter is of incorrect type %s",
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
212 g_variant_get_type_string(parameter));
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
213 return;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
214 }
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
215
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
216 creation_time = (time_t)g_variant_get_int64(parameter);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
217 saved_status = purple_savedstatus_find_by_creation_time(creation_time);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
218
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
219 if(saved_status != NULL) {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
220 if(saved_status != purple_savedstatus_get_current()) {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
221 purple_savedstatus_activate(saved_status);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
222 }
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
223 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
224 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
226 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
227 pidgin_status_box_savedstatus_changed_cb(PurpleSavedStatus *now,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
228 G_GNUC_UNUSED PurpleSavedStatus *old,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229 gpointer data)
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230 {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231 PidginStatusBox *status_box = data;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233 /* If we don't have a status, we have to bail. */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 if(now == NULL) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235 return;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
238 pidgin_status_display_set_saved_status(status_box->display, now);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
239 }
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
240
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
241 static void
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
242 pidgin_status_box_remove_custom_widget(GtkWidget *widget, gpointer user_data) {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
243 GtkPopoverMenu *popover_menu = user_data;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
244
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
245 gtk_popover_menu_remove_child(popover_menu, widget);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
249 pidgin_status_box_savedstatus_updated_cb(G_GNUC_UNUSED PurpleSavedStatus *status,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 gpointer data)
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251 {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252 PidginStatusBox *status_box = data;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
254 g_list_foreach(status_box->custom_widgets,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
255 (GFunc)pidgin_status_box_remove_custom_widget,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
256 status_box->popover);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
257 g_clear_list(&status_box->custom_widgets, NULL);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
258 g_menu_remove_all(status_box->saved_statuses);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
260 pidgin_status_box_populate_saved_statuses(status_box);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
261 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
262
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
263 /******************************************************************************
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
264 * GObject Implementation
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
265 *****************************************************************************/
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
266 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
267 pidgin_status_box_finalize(GObject *obj) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
268 PidginStatusBox *status_box = PIDGIN_STATUS_BOX(obj);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270 purple_signals_disconnect_by_handle(status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
272 g_clear_list(&status_box->custom_widgets, NULL);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
273
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
274 G_OBJECT_CLASS(pidgin_status_box_parent_class)->finalize(obj);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
277 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
278 pidgin_status_box_init(PidginStatusBox *status_box) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 gpointer handle;
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
280 GSimpleActionGroup *action_group = NULL;
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
281 GActionEntry actions[] = {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
282 {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
283 .name = "set-primitive",
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
284 .activate = pidgin_status_box_set_primitive,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
285 .parameter_type = (const char *)G_VARIANT_TYPE_INT32,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
286 }, {
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
287 .name = "set-saved",
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
288 .activate = pidgin_status_box_set_saved_status,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
289 .parameter_type = (const char *)G_VARIANT_TYPE_INT64,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
290 },
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
291 };
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
292
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
293 gtk_widget_init_template(GTK_WIDGET(status_box));
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
294
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
295 action_group = g_simple_action_group_new();
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
296 g_action_map_add_action_entries(G_ACTION_MAP(action_group),
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
297 actions, G_N_ELEMENTS(actions),
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
298 status_box);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
299 gtk_widget_insert_action_group(GTK_WIDGET(status_box), "status",
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
300 G_ACTION_GROUP(action_group));
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
302 status_box->popover = gtk_menu_button_get_popover(GTK_MENU_BUTTON(status_box->button));
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
303 gtk_popover_set_has_arrow(status_box->popover, FALSE);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
304
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
305 pidgin_status_box_populate_primitives(status_box);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
306 pidgin_status_box_populate_saved_statuses(status_box);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
307
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 handle = purple_savedstatuses_get_handle();
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 purple_signal_connect(handle, "savedstatus-changed", status_box,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 G_CALLBACK(pidgin_status_box_savedstatus_changed_cb),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311 status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312 purple_signal_connect(handle, "savedstatus-added", status_box,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313 G_CALLBACK(pidgin_status_box_savedstatus_updated_cb),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314 status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315 purple_signal_connect(handle, "savedstatus-deleted", status_box,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316 G_CALLBACK(pidgin_status_box_savedstatus_updated_cb),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317 status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318 purple_signal_connect(handle, "savedstatus-modified", status_box,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319 G_CALLBACK(pidgin_status_box_savedstatus_updated_cb),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320 status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
321 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
322
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324 pidgin_status_box_constructed(GObject *obj) {
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
325 PidginStatusBox *status_box = PIDGIN_STATUS_BOX(obj);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
326 PurpleSavedStatus *status = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328 G_OBJECT_CLASS(pidgin_status_box_parent_class)->constructed(obj);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
329
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
330 status = purple_savedstatus_get_current();
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
331 pidgin_status_display_set_saved_status(status_box->display, status);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
333
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
335 pidgin_status_box_class_init(PidginStatusBoxClass *klass) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
336 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
337 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339 obj_class->finalize = pidgin_status_box_finalize;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340 obj_class->constructed = pidgin_status_box_constructed;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342 gtk_widget_class_set_template_from_resource(
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343 widget_class,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 "/im/pidgin/Pidgin3/Status/box.ui"
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345 );
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
346
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
347 gtk_widget_class_bind_template_child(widget_class, PidginStatusBox,
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
348 button);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
349 gtk_widget_class_bind_template_child(widget_class, PidginStatusBox,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
350 display);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351 gtk_widget_class_bind_template_child(widget_class, PidginStatusBox,
42199
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
352 primitives);
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
353 gtk_widget_class_bind_template_child(widget_class, PidginStatusBox,
adf6d358d438 Convert PidginStatusBox to a GtkMenuButton
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41337
diff changeset
354 saved_statuses);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
356
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
357 /******************************************************************************
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358 * Public API
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359 *****************************************************************************/
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
360 GtkWidget *
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
361 pidgin_status_box_new(void) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
362 return g_object_new(PIDGIN_TYPE_STATUS_BOX, NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
363 }

mercurial