pidgin/pidginstatusbox.c

Tue, 22 Feb 2022 19:38:45 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Tue, 22 Feb 2022 19:38:45 -0600
branch
gtk4
changeset 41527
4dff8cd4e9ea
parent 41337
a8b8e1703239
child 42199
adf6d358d438
permissions
-rw-r--r--

Convert PidginConversationWindow to GTK4

Testing Done:
Compiled and verified all the warnings/errors for `pidginconversationwindow.c` were gone.

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

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"
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
31
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
32 #define PRIMITIVE_FORMAT "primitive_%d"
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
33 #define SAVEDSTATUS_FORMAT "savedstatus_%lu"
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 typedef enum {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
36 PIDGIN_STATUS_BOX_TYPE_SEPARATOR,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
37 PIDGIN_STATUS_BOX_TYPE_PRIMITIVE,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
38 PIDGIN_STATUS_BOX_TYPE_POPULAR,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
39 PIDGIN_STATUS_BOX_TYPE_ACTION,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
40 PIDGIN_STATUS_BOX_NUM_TYPES
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
41 } PidginStatusBoxItemType;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
42
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
43 struct _PidginStatusBox {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
44 GtkBox parent;
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 GtkListStore *model;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
47 GtkWidget *combo;
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 /* This is used to flipback to the correct status when one of the actions
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
50 * items is selected.
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
51 */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
52 gchar *active_id;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
53 };
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
54
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
55 enum {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
56 ID_COLUMN,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
57 TYPE_COLUMN, /* PidginStatusBoxItemType */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
58 ICON_NAME_COLUMN,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
59 PRIMITIVE_COLUMN,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
60 TEXT_COLUMN,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
61 /* This value depends on TYPE_COLUMN. For POPULAR types, this is the
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
62 * creation time.
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
63 */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
64 DATA_COLUMN,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
65 EMBLEM_VISIBLE_COLUMN,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
66 NUM_COLUMNS
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
67 };
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
68
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
69 G_DEFINE_TYPE(PidginStatusBox, pidgin_status_box, GTK_TYPE_BOX)
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
70
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
71 /* This prototype is necessary so we can block this signal handler when we are
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
72 * manually updating the combobox.
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
73 */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
74 static void pidgin_status_box_combo_changed_cb(GtkComboBox *combo, gpointer user_data);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
75
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
76 /******************************************************************************
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
77 * Helpers
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
78 *****************************************************************************/
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
79 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
80 pidgin_status_box_update_to_status(PidginStatusBox *status_box,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
81 PurpleSavedStatus *status)
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
82 {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
83 gchar *id = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
84 gboolean set = FALSE;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
85 time_t creation_time = 0;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
86
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
87 /* Try to set the combo box to the saved status. */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
88 creation_time = purple_savedstatus_get_creation_time(status);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
89 id = g_strdup_printf(SAVEDSTATUS_FORMAT, creation_time);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
90
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
91 set = gtk_combo_box_set_active_id(GTK_COMBO_BOX(status_box->combo), id);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
92 g_free(id);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
93
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
94 /* If we failed to set via the savedstatus, fallback to the primitive. */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
95 if(!set) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
96 PurpleStatusPrimitive primitive;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
97
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
98 primitive = purple_savedstatus_get_primitive_type(status);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
99 id = g_strdup_printf(PRIMITIVE_FORMAT, primitive);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
100
41337
a8b8e1703239 Remove a dead assignment that scanbuild found
Gary Kramlich <grim@reaperworld.com>
parents: 41320
diff changeset
101 gtk_combo_box_set_active_id(GTK_COMBO_BOX(status_box->combo), id);
41320
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
102 g_free(id);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
103 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
104 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
105
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
106 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
107 pidgin_status_box_add(PidginStatusBox *status_box,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
108 PidginStatusBoxItemType type,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
109 PurpleStatusPrimitive primitive, const gchar *text,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
110 gpointer data)
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
111 {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
112 GtkTreeIter iter;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
113 gchar *id = NULL, *escaped_text = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
114 const gchar *icon_name = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
115 gboolean emblem_visible = FALSE;
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 escaped_text = g_markup_escape_text(text, -1);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
118
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
119 if(type == PIDGIN_STATUS_BOX_TYPE_POPULAR) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
120 PurpleSavedStatus *saved_status = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
121 time_t creation_time = GPOINTER_TO_INT(data);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
122
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
123 saved_status = purple_savedstatus_find_by_creation_time(creation_time);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
124
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
125 if(saved_status != NULL) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
126 id = g_strdup_printf(SAVEDSTATUS_FORMAT, creation_time);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
127
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
128 if(!purple_savedstatus_is_transient(saved_status)) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
129 emblem_visible = TRUE;
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 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
133
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
134 if(id == NULL && primitive != PURPLE_STATUS_UNSET) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
135 id = g_strdup_printf(PRIMITIVE_FORMAT, primitive);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
136 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
137
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
138 icon_name = pidgin_icon_name_from_status_primitive(primitive, NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
139
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
140 gtk_list_store_append(status_box->model, &iter);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
141 gtk_list_store_set(status_box->model, &iter,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
142 ID_COLUMN, id,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
143 TYPE_COLUMN, type,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
144 ICON_NAME_COLUMN, icon_name,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
145 PRIMITIVE_COLUMN, primitive,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
146 TEXT_COLUMN, escaped_text,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
147 DATA_COLUMN, data,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
148 EMBLEM_VISIBLE_COLUMN, emblem_visible,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
149 -1);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
150
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
151 g_free(escaped_text);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
152 g_free(id);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
153 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
154
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
155 static gboolean
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
156 pidgin_status_box_row_separator_func(GtkTreeModel *model, GtkTreeIter *iter,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
157 G_GNUC_UNUSED gpointer data)
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
158 {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
159 PidginStatusBoxItemType type;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
160
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
161 gtk_tree_model_get(model, iter, TYPE_COLUMN, &type, -1);
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 return type == PIDGIN_STATUS_BOX_TYPE_SEPARATOR;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
164 }
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 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
167 pidgin_status_box_add_separator(PidginStatusBox *status_box) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
168 GtkTreeIter iter;
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 gtk_list_store_append(status_box->model, &iter);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
171 gtk_list_store_set(status_box->model, &iter,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
172 TYPE_COLUMN, PIDGIN_STATUS_BOX_TYPE_SEPARATOR,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
173 -1);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
174 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
175
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
176 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
177 pidgin_status_box_update_saved_statuses(PidginStatusBox *status_box) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
178 GList *list, *cur;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
179
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
180 list = purple_savedstatuses_get_popular(6);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
181 if (list == NULL) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
182 /* Odd... oh well, nothing we can do about it. */
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
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
186 for(cur = list; cur != NULL; cur = cur->next) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
187 PurpleSavedStatus *saved = cur->data;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
188 GString *text = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
189 time_t creation_time;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
190
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
191 text = g_string_new(purple_savedstatus_get_title(saved));
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(!purple_savedstatus_is_transient(saved)) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
194 /*
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
195 * Transient statuses do not have a title, so the savedstatus
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
196 * API returns the message when purple_savedstatus_get_title() is
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
197 * called, so we don't need to get the message a second time.
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
198 */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
199 const gchar *message = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
200
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
201 message = purple_savedstatus_get_message(saved);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
202 if(message != NULL) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
203 gchar *stripped = purple_markup_strip_html(message);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
204
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
205 purple_util_chrreplace(stripped, '\n', ' ');
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
206 g_string_append_printf(text, " - %s", stripped);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
207 g_free(stripped);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
208 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
209 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
210
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
211 creation_time = purple_savedstatus_get_creation_time(saved);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
212 pidgin_status_box_add(status_box, PIDGIN_STATUS_BOX_TYPE_POPULAR,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
213 purple_savedstatus_get_primitive_type(saved),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
214 text->str, GINT_TO_POINTER(creation_time));
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
215
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
216 g_string_free(text, TRUE);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
217 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
218
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
219 g_list_free(list);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
220
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
221 pidgin_status_box_add_separator(status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
222 }
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 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
225 pidgin_status_box_populate(PidginStatusBox *status_box) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
226 pidgin_status_box_add(status_box, PIDGIN_STATUS_BOX_TYPE_PRIMITIVE,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
227 PURPLE_STATUS_AVAILABLE, _("Available"), NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
228 pidgin_status_box_add(status_box, PIDGIN_STATUS_BOX_TYPE_PRIMITIVE,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
229 PURPLE_STATUS_AWAY, _("Away"), NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
230 pidgin_status_box_add(status_box, PIDGIN_STATUS_BOX_TYPE_PRIMITIVE,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
231 PURPLE_STATUS_UNAVAILABLE, _("Do not disturb"),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
232 NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
233 pidgin_status_box_add(status_box, PIDGIN_STATUS_BOX_TYPE_PRIMITIVE,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
234 PURPLE_STATUS_INVISIBLE, _("Invisible"), NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
235 pidgin_status_box_add(status_box, PIDGIN_STATUS_BOX_TYPE_PRIMITIVE,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
236 PURPLE_STATUS_OFFLINE, _("Offline"), NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
237
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
238 pidgin_status_box_add_separator(status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
239
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
240 pidgin_status_box_update_saved_statuses(status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
241
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
242 pidgin_status_box_add(status_box, PIDGIN_STATUS_BOX_TYPE_ACTION,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
243 PURPLE_STATUS_UNSET, _("New Status..."),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
244 "new-status");
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
245 pidgin_status_box_add(status_box, PIDGIN_STATUS_BOX_TYPE_ACTION,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
246 PURPLE_STATUS_UNSET, _("Saved Statuses..."),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
247 "status-manager");
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
248 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
249
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
250 /******************************************************************************
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
251 * Callbacks
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
252 *****************************************************************************/
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
253 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
254 pidgin_status_box_combo_changed_cb(GtkComboBox *combo, gpointer user_data) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
255 PidginStatusBox *status_box = user_data;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
256 PidginStatusBoxItemType type;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
257 PurpleSavedStatus *saved_status = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
258 PurpleStatusPrimitive primitive;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
259 GtkTreeIter iter;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
260 gchar *id = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
261 gpointer data;
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 if(!gtk_combo_box_get_active_iter(combo, &iter)) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
264 return;
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
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
267 gtk_tree_model_get(GTK_TREE_MODEL(status_box->model), &iter,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
268 ID_COLUMN, &id,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
269 TYPE_COLUMN, &type,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
270 PRIMITIVE_COLUMN, &primitive,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
271 DATA_COLUMN, &data,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
272 -1);
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 if(type == PIDGIN_STATUS_BOX_TYPE_PRIMITIVE) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
275 saved_status = purple_savedstatus_find_transient_by_type_and_message(primitive, NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
276 if(saved_status == NULL) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
277 saved_status = purple_savedstatus_new(NULL, primitive);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
278 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
279 } else if(type == PIDGIN_STATUS_BOX_TYPE_POPULAR) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
280 time_t creation_time = GPOINTER_TO_INT(data);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
281
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
282 saved_status = purple_savedstatus_find_by_creation_time(creation_time);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
283 } else if(type == PIDGIN_STATUS_BOX_TYPE_ACTION) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
284 GApplication *application = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
285 const gchar *action_name = (const gchar *)data;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
286
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
287 application = g_application_get_default();
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
288
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
289 g_action_group_activate_action(G_ACTION_GROUP(application),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
290 action_name, NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
291
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
292 gtk_combo_box_set_active_id(combo, status_box->active_id);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
293 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
294
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
295 if(saved_status != NULL) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
296 if(saved_status != purple_savedstatus_get_current()) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
297 purple_savedstatus_activate(saved_status);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
298 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
299
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
300 g_free(status_box->active_id);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
301 status_box->active_id = id;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
302 } else {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
303 g_free(id);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
304 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
305 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
306
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
307 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
308 pidgin_status_box_savedstatus_changed_cb(PurpleSavedStatus *now,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
309 G_GNUC_UNUSED PurpleSavedStatus *old,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
310 gpointer data)
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
311 {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
312 PidginStatusBox *status_box = data;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
313
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
314 /* If we don't have a status, we have to bail. */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
315 if(now == NULL) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
316 return;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
317 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
318
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
319 pidgin_status_box_update_to_status(status_box, now);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
320 }
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 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
323 pidgin_status_box_savedstatus_updated_cb(G_GNUC_UNUSED PurpleSavedStatus *status,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
324 gpointer data)
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
325 {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
326 PidginStatusBox *status_box = data;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
327 PurpleSavedStatus *current = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
328 static gboolean getting_current = FALSE;
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 /* purple_status_get_current will create a new status if this is a brand
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
331 * new install or the setting wasn't found. This leads to this handler
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
332 * getting stuck in a loop until it segfaults because the stack smashed
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
333 * into the heap. Anyways, we use this static boolean to check when this
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
334 * function is called by purple_status_get_current so we can bail out and
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
335 * break the loop.
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
336 */
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
337 if(getting_current) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
338 return;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
339 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
340
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
341 gtk_list_store_clear(status_box->model);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
342 pidgin_status_box_populate(status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
343
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
344 getting_current = TRUE;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
345 current = purple_savedstatus_get_current();
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
346 pidgin_status_box_update_to_status(status_box, current);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
347 getting_current = FALSE;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
348 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
349
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
350 /******************************************************************************
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
351 * GObject Implementation
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
352 *****************************************************************************/
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
353 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
354 pidgin_status_box_finalize(GObject *obj) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
355 PidginStatusBox *status_box = PIDGIN_STATUS_BOX(obj);
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 purple_signals_disconnect_by_handle(status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
358
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
359 g_free(status_box->active_id);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
360
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
361 G_OBJECT_CLASS(pidgin_status_box_parent_class)->finalize(obj);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
362 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
363
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
364 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
365 pidgin_status_box_init(PidginStatusBox *status_box) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
366 gpointer handle;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
367
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
368 gtk_widget_init_template(GTK_WIDGET(status_box));
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
369
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
370 gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(status_box->combo),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
371 pidgin_status_box_row_separator_func,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
372 NULL, NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
373
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
374 pidgin_status_box_populate(status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
375
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
376 handle = purple_savedstatuses_get_handle();
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
377 purple_signal_connect(handle, "savedstatus-changed", status_box,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
378 G_CALLBACK(pidgin_status_box_savedstatus_changed_cb),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
379 status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
380 purple_signal_connect(handle, "savedstatus-added", status_box,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
381 G_CALLBACK(pidgin_status_box_savedstatus_updated_cb),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
382 status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
383 purple_signal_connect(handle, "savedstatus-deleted", status_box,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
384 G_CALLBACK(pidgin_status_box_savedstatus_updated_cb),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
385 status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
386 purple_signal_connect(handle, "savedstatus-modified", status_box,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
387 G_CALLBACK(pidgin_status_box_savedstatus_updated_cb),
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
388 status_box);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
389 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
390
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
391 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
392 pidgin_status_box_constructed(GObject *obj) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
393 PurpleSavedStatus *status = NULL;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
394
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
395 G_OBJECT_CLASS(pidgin_status_box_parent_class)->constructed(obj);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
396
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
397 status = purple_savedstatus_get_current();
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
398
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
399 pidgin_status_box_update_to_status(PIDGIN_STATUS_BOX(obj), status);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
400 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
401
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
402 static void
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
403 pidgin_status_box_class_init(PidginStatusBoxClass *klass) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
404 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
405 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
406
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
407 obj_class->finalize = pidgin_status_box_finalize;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
408 obj_class->constructed = pidgin_status_box_constructed;
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
409
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
410 gtk_widget_class_set_template_from_resource(
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
411 widget_class,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
412 "/im/pidgin/Pidgin3/Status/box.ui"
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
413 );
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
414
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
415 gtk_widget_class_bind_template_child(widget_class, PidginStatusBox,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
416 model);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
417 gtk_widget_class_bind_template_child(widget_class, PidginStatusBox,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
418 combo);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
419
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
420 gtk_widget_class_bind_template_callback(widget_class,
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
421 pidgin_status_box_combo_changed_cb);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
422 }
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
423
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
424 /******************************************************************************
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
425 * Public API
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
426 *****************************************************************************/
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
427 GtkWidget *
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
428 pidgin_status_box_new(void) {
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
429 return g_object_new(PIDGIN_TYPE_STATUS_BOX, NULL);
1695e758b590 Overhaul the status box
Gary Kramlich <grim@reaperworld.com>
parents:
diff changeset
430 }

mercurial