finch/gntroomlist.c

Fri, 19 Aug 2022 01:00:48 -0500

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Fri, 19 Aug 2022 01:00:48 -0500
branch
gtk4
changeset 41564
661f4b3b8298
parent 41349
15aeaa1e84ec
child 41720
bcfc2c9e5213
permissions
-rw-r--r--

Fix leaks from GtkFileChooser results

The return value of `gtk_file_chooser_get_file` and `g_file_get_path` are both transfer full, so they must be freed.

Testing Done:
Compiled only.

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

39887
9c8f874c74a0 Clean up all of the license headers
Gary Kramlich <grim@reaperworld.com>
parents: 39759
diff changeset
1 /*
9c8f874c74a0 Clean up all of the license headers
Gary Kramlich <grim@reaperworld.com>
parents: 39759
diff changeset
2 * finch
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
3 *
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
4 * Finch is the legal property of its developers, whose names are too numerous
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
6 * source distribution.
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
7 *
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
11 * (at your option) any later version.
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
12 *
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
16 * GNU General Public License for more details.
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
17 *
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
21 */
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
22
40439
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 40359
diff changeset
23 #include <glib/gi18n-lib.h>
e9838d634d5e Make sure that internal.h can only be included by libpurple and split out some pieces to purpleprivate.h
Gary Kramlich <grim@reaperworld.com>
parents: 40359
diff changeset
24
40616
064ff9f4150a Don't allow libraries to include their own global header files.
Gary Kramlich <grim@reaperworld.com>
parents: 40511
diff changeset
25 #include <purple.h>
40511
ec08ac1f7d5f Fix Finch for the libgnt single header file
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
26
ec08ac1f7d5f Fix Finch for the libgnt single header file
Gary Kramlich <grim@reaperworld.com>
parents: 40439
diff changeset
27 #include <gnt.h>
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
28
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
29 #include "gntrequest.h"
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
30 #include "gntroomlist.h"
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
31
22147
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
32 #define PREF_ROOT "/finch/roomlist"
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
33
32218
f27b05250351 Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents: 27829
diff changeset
34
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
35 /* Yes, just one roomlist at a time. Let's not get greedy. Aight? */
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
36 struct _FinchRoomlist
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
37 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
38 GntWidget *window;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
39
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
40 GntWidget *accounts;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
41 GntWidget *tree;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
42 GntWidget *details;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
43
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
44 GntWidget *getlist;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
45 GntWidget *add;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
46 GntWidget *join;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
47 GntWidget *stop;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
48 GntWidget *close;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
49
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
50 PurpleAccount *account;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
51 PurpleRoomlist *roomlist;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
52 } froomlist;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
53
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
54 typedef struct _FinchRoomlist FinchRoomlist;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
55
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
56 static void
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
57 unset_roomlist(gpointer null)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
58 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
59 froomlist.window = NULL;
40977
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
60 g_clear_object(&froomlist.roomlist);
22169
bed812105128 Unset some stuff to make sure Sylar can't kill us.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22147
diff changeset
61 froomlist.account = NULL;
bed812105128 Unset some stuff to make sure Sylar can't kill us.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22147
diff changeset
62 froomlist.tree = NULL;
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
63 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
64
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
65 static void fl_stop(GntWidget *button, gpointer null)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
66 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
67 if (froomlist.roomlist &&
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
68 purple_roomlist_get_in_progress(froomlist.roomlist))
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
69 purple_roomlist_cancel_get_list(froomlist.roomlist);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
70 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
71
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
72 static void fl_get_list(GntWidget *button, gpointer null)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
73 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
74 PurpleAccount *account = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(froomlist.accounts));
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
75 PurpleConnection *gc = purple_account_get_connection(account);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
76
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
77 if (!gc)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
78 return;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
79
40977
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
80 g_clear_object(&froomlist.roomlist);
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
81 froomlist.roomlist = purple_roomlist_get_list(gc);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
82 gnt_box_give_focus_to_child(GNT_BOX(froomlist.window), froomlist.tree);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
83 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
84
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
85 static void fl_add_chat(GntWidget *button, gpointer null)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
86 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
87 char *name;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
88 PurpleRoomlistRoom *room = gnt_tree_get_selection_data(GNT_TREE(froomlist.tree));
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
89 PurpleConnection *gc = purple_account_get_connection(froomlist.account);
36544
1bf8b6ef5aea Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents: 36404
diff changeset
90 PurpleProtocol *protocol = NULL;
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
91
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
92 if (gc == NULL || room == NULL)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
93 return;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
94
36623
caaadef03507 Renamed purple_connection_get_protocol_info() to purple_connection_get_protocol()
Ankit Vani <a@nevitus.org>
parents: 36606
diff changeset
95 protocol = purple_connection_get_protocol(gc);
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
96
39901
253056947264 finch: Remove redundant checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39887
diff changeset
97 if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, ROOMLIST, room_serialize)) {
41028
943b2cb45314 Separate PurpleProtocolRoomlist into its own file and modernize it.
Gary Kramlich <grim@reaperworld.com>
parents: 40977
diff changeset
98 name = purple_protocol_roomlist_room_serialize(PURPLE_PROTOCOL_ROOMLIST(protocol), room);
39901
253056947264 finch: Remove redundant checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39887
diff changeset
99 } else {
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
100 name = g_strdup(purple_roomlist_room_get_name(room));
39901
253056947264 finch: Remove redundant checks.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39887
diff changeset
101 }
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
102
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
103 purple_blist_request_add_chat(froomlist.account, NULL, NULL, name);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
104
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
105 g_free(name);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
106 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
107
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
108 static void fl_close(GntWidget *button, gpointer null)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
109 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
110 gnt_widget_destroy(froomlist.window);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
111 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
112
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
113 static void
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
114 roomlist_activated(GntWidget *widget)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
115 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
116 PurpleRoomlistRoom *room = gnt_tree_get_selection_data(GNT_TREE(widget));
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
117 if (!room)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
118 return;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
119
41349
15aeaa1e84ec Rework the way roomlists work so we can more easily port them to GTK4
Gary Kramlich <grim@reaperworld.com>
parents: 41028
diff changeset
120 purple_roomlist_join_room(froomlist.roomlist, room);
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
121 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
122
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
123 static void
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
124 roomlist_selection_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
125 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
126 PurpleRoomlistRoom *room = current;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
127 GntTextView *tv = GNT_TEXT_VIEW(froomlist.details);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
128
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
129 gnt_text_view_clear(tv);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
130
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
131 if (!room)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
132 return;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
133
41349
15aeaa1e84ec Rework the way roomlists work so we can more easily port them to GTK4
Gary Kramlich <grim@reaperworld.com>
parents: 41028
diff changeset
134 gnt_text_view_append_text_with_flags(tv,
15aeaa1e84ec Rework the way roomlists work so we can more easily port them to GTK4
Gary Kramlich <grim@reaperworld.com>
parents: 41028
diff changeset
135 purple_roomlist_room_get_name(room),
15aeaa1e84ec Rework the way roomlists work so we can more easily port them to GTK4
Gary Kramlich <grim@reaperworld.com>
parents: 41028
diff changeset
136 GNT_TEXT_FLAG_BOLD);
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
137 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
138
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
139 static void
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
140 roomlist_account_changed(GntWidget *widget, gpointer old, gpointer current, gpointer null)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
141 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
142 if (froomlist.account == current) {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
143 return;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
144 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
145
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
146 froomlist.account = current;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
147 if (froomlist.roomlist) {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
148 if (purple_roomlist_get_in_progress(froomlist.roomlist))
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
149 purple_roomlist_cancel_get_list(froomlist.roomlist);
40977
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
150 g_clear_object(&froomlist.roomlist);
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
151 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
152
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
153 gnt_tree_remove_all(GNT_TREE(froomlist.tree));
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
154 gnt_widget_draw(froomlist.tree);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
155 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
156
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
157 static void
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
158 reset_account_list(PurpleAccount *account)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
159 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
160 GList *list;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
161 GntComboBox *accounts = GNT_COMBO_BOX(froomlist.accounts);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
162 gnt_combo_box_remove_all(accounts);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
163 for (list = purple_connections_get_all(); list; list = list->next) {
36544
1bf8b6ef5aea Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents: 36404
diff changeset
164 PurpleProtocol *protocol = NULL;
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
165 PurpleConnection *gc = list->data;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
166
36623
caaadef03507 Renamed purple_connection_get_protocol_info() to purple_connection_get_protocol()
Ankit Vani <a@nevitus.org>
parents: 36606
diff changeset
167 protocol = purple_connection_get_protocol(gc);
24863
68c109ca0089 Fix a crash that happens when accessing the roomlist for an account that's
Paul Aurich <darkrain42@pidgin.im>
parents: 22339
diff changeset
168 if (PURPLE_CONNECTION_IS_CONNECTED(gc) &&
39759
ea1401483849 Rename *_GET_*_IFACE to more standard *_GET_IFACE.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 37066
diff changeset
169 PURPLE_PROTOCOL_IMPLEMENTS(protocol, ROOMLIST, get_list)) {
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
170 PurpleAccount *account = purple_connection_get_account(gc);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
171 char *text = g_strdup_printf("%s (%s)",
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
172 purple_account_get_username(account),
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
173 purple_account_get_protocol_name(account));
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
174 gnt_combo_box_add_data(accounts, account, text);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
175 g_free(text);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
176 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
177 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
178 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
179
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
180 static void
22147
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
181 size_changed_cb(GntWidget *widget, int oldw, int oldh)
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
182 {
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
183 int w, h;
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
184 gnt_widget_get_size(widget, &w, &h);
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
185 purple_prefs_set_int(PREF_ROOT "/size/width", w);
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
186 purple_prefs_set_int(PREF_ROOT "/size/height", h);
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
187 }
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
188
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
189 static void
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
190 setup_roomlist(PurpleAccount *account)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
191 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
192 GntWidget *window, *tree, *hbox, *accounts;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
193 int iter;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
194 struct {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
195 const char *label;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
196 GCallback callback;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
197 GntWidget **widget;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
198 } buttons[] = {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
199 {_("Stop"), G_CALLBACK(fl_stop), &froomlist.stop},
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
200 {_("Get"), G_CALLBACK(fl_get_list), &froomlist.getlist},
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
201 {_("Add"), G_CALLBACK(fl_add_chat), &froomlist.add},
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
202 {_("Close"), G_CALLBACK(fl_close), &froomlist.close},
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
203 {NULL, NULL, NULL}
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
204 };
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
205
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
206 if (froomlist.window)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
207 return;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
208
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
209 froomlist.window = window = gnt_window_new();
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
210 g_object_set(G_OBJECT(window), "vertical", TRUE, NULL);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
211 gnt_box_set_pad(GNT_BOX(window), 0);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
212 gnt_box_set_title(GNT_BOX(window), _("Room List"));
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
213 gnt_box_set_alignment(GNT_BOX(window), GNT_ALIGN_MID);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
214
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
215 froomlist.accounts = accounts = gnt_combo_box_new();
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
216 reset_account_list(account);
22212
5389776ad09f Fix CID #380 by using an assigned variable.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22169
diff changeset
217 gnt_box_add_widget(GNT_BOX(window), accounts);
5389776ad09f Fix CID #380 by using an assigned variable.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22169
diff changeset
218 g_signal_connect(G_OBJECT(accounts), "selection-changed",
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
219 G_CALLBACK(roomlist_account_changed), NULL);
22212
5389776ad09f Fix CID #380 by using an assigned variable.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22169
diff changeset
220 froomlist.account = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(accounts));
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
221
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
222 froomlist.tree = tree = gnt_tree_new_with_columns(2);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
223 gnt_tree_set_show_title(GNT_TREE(tree), TRUE);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
224 g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(roomlist_activated), NULL);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
225 gnt_tree_set_column_titles(GNT_TREE(tree), _("Name"), "");
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
226 gnt_tree_set_show_separator(GNT_TREE(tree), FALSE);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
227 gnt_tree_set_col_width(GNT_TREE(tree), 1, 1);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
228 gnt_tree_set_column_resizable(GNT_TREE(tree), 1, FALSE);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
229 gnt_tree_set_search_column(GNT_TREE(tree), 0);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
230
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
231 gnt_box_add_widget(GNT_BOX(window), tree);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
232
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
233 froomlist.details = gnt_text_view_new();
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
234 gnt_text_view_set_flag(GNT_TEXT_VIEW(froomlist.details), GNT_TEXT_VIEW_TOP_ALIGN);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
235 gnt_box_add_widget(GNT_BOX(window), froomlist.details);
22147
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
236 gnt_widget_set_size(froomlist.details, -1, 8);
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
237
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
238 hbox = gnt_hbox_new(FALSE);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
239 gnt_box_add_widget(GNT_BOX(window), hbox);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
240
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
241 for (iter = 0; buttons[iter].label; iter++) {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
242 GntWidget *button = gnt_button_new(buttons[iter].label);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
243 gnt_box_add_widget(GNT_BOX(hbox), button);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
244 g_signal_connect(G_OBJECT(button), "activate", buttons[iter].callback, NULL);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
245 *buttons[iter].widget = button;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
246 gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(froomlist.details), button);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
247 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
248
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
249 g_signal_connect(G_OBJECT(tree), "selection-changed", G_CALLBACK(roomlist_selection_changed), NULL);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
250
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
251 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(unset_roomlist), NULL);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
252 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
253
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
254 static void
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
255 fl_show_with_account(PurpleAccount *account)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
256 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
257 setup_roomlist(account);
22147
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
258 g_signal_handlers_disconnect_matched(G_OBJECT(froomlist.window), G_SIGNAL_MATCH_FUNC,
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
259 0, 0, NULL, G_CALLBACK(size_changed_cb), NULL);
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
260 gnt_widget_show(froomlist.window);
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
261 gnt_screen_resize_widget(froomlist.window,
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
262 purple_prefs_get_int(PREF_ROOT "/size/width"),
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
263 purple_prefs_get_int(PREF_ROOT "/size/height"));
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
264 g_signal_connect(G_OBJECT(froomlist.window), "size_changed", G_CALLBACK(size_changed_cb), NULL);
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
265 gnt_window_present(froomlist.window);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
266 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
267
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
268 static void
40977
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
269 fl_destroy(G_GNUC_UNUSED gpointer data, GObject *list)
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
270 {
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
271 if (!froomlist.window) {
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
272 return;
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
273 }
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
274
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
275 if (G_OBJECT(froomlist.roomlist) == list) {
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
276 froomlist.roomlist = NULL;
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
277 gnt_tree_remove_all(GNT_TREE(froomlist.tree));
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
278 gnt_widget_draw(froomlist.tree);
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
279 }
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
280 }
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
281
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
282 static void
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
283 fl_create(PurpleRoomlist *list)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
284 {
40898
06e5a2a8f49a Replace purple_roomlist_[gs]et_ui_data with g_object_[gs]et_data
Gary Kramlich <grim@reaperworld.com>
parents: 40616
diff changeset
285 g_object_set_data(G_OBJECT(list), "finch-ui", &froomlist);
40977
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
286 g_object_weak_ref(G_OBJECT(list), (GWeakNotify)fl_destroy, NULL);
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
287 setup_roomlist(NULL);
40977
dd0f04c5d212 Cleanup RoomList UI ops
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 40898
diff changeset
288 g_set_object(&froomlist.roomlist, list);
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
289 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
290
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
291 static void
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
292 fl_set_fields(PurpleRoomlist *list, GList *fields)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
293 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
294 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
295
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
296 static void
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
297 fl_add_room(PurpleRoomlist *roomlist, PurpleRoomlistRoom *room)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
298 {
41349
15aeaa1e84ec Rework the way roomlists work so we can more easily port them to GTK4
Gary Kramlich <grim@reaperworld.com>
parents: 41028
diff changeset
299 gchar *category = NULL;
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
300 if (froomlist.roomlist != roomlist)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
301 return;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
302
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
303 gnt_tree_remove(GNT_TREE(froomlist.tree), room);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
304 gnt_tree_add_row_after(GNT_TREE(froomlist.tree), room,
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
305 gnt_tree_create_row(GNT_TREE(froomlist.tree),
41349
15aeaa1e84ec Rework the way roomlists work so we can more easily port them to GTK4
Gary Kramlich <grim@reaperworld.com>
parents: 41028
diff changeset
306 purple_roomlist_room_get_name(room), ""),
15aeaa1e84ec Rework the way roomlists work so we can more easily port them to GTK4
Gary Kramlich <grim@reaperworld.com>
parents: 41028
diff changeset
307 NULL, NULL);
15aeaa1e84ec Rework the way roomlists work so we can more easily port them to GTK4
Gary Kramlich <grim@reaperworld.com>
parents: 41028
diff changeset
308 gnt_tree_set_expanded(GNT_TREE(froomlist.tree), room, category == NULL);
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
309 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
310
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
311 static PurpleRoomlistUiOps ui_ops =
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
312 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
313 fl_show_with_account, /* void (*show_with_account)(PurpleAccount *account); **< Force the ui to pop up a dialog and get the list */
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
314 fl_create, /* void (*create)(PurpleRoomlist *list); **< A new list was created. */
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
315 fl_set_fields, /* void (*set_fields)(PurpleRoomlist *list, GList *fields); **< Sets the columns. */
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
316 fl_add_room, /* void (*add_room)(PurpleRoomlist *list, PurpleRoomlistRoom *room); **< Add a room to the list. */
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
317
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
318 NULL, /* void (*_purple_reserved1)(void); */
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
319 NULL, /* void (*_purple_reserved2)(void); */
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
320 NULL, /* void (*_purple_reserved3)(void); */
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
321 NULL /* void (*_purple_reserved4)(void); */
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
322 };
22147
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
323
22136
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
324 PurpleRoomlistUiOps *finch_roomlist_get_ui_ops(void)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
325 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
326 return &ui_ops;
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
327 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
328
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
329 void finch_roomlist_show_all(void)
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
330 {
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
331 purple_roomlist_show_with_account(NULL);
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
332 }
9db77fc00a0e Implementation of the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
diff changeset
333
22147
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
334 void finch_roomlist_init(void)
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
335 {
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
336 purple_prefs_add_none(PREF_ROOT);
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
337 purple_prefs_add_none(PREF_ROOT "/size");
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
338 purple_prefs_add_int(PREF_ROOT "/size/width", 60);
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
339 purple_prefs_add_int(PREF_ROOT "/size/height", 15);
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
340 }
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
341
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
342 void finch_roomlist_uninit(void)
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
343 {
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
344 }
08e54b0f86a3 Remember the size of the roomlist window. Handle the categories better.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 22146
diff changeset
345

mercurial