8113
|
1 /**
|
|
2 * @file roomlist.c Room List API
|
|
3 * @ingroup core
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
8146
|
7 * Gaim is the legal property of its developers, whose names are too numerous
|
|
8 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
9 * source distribution.
|
8113
|
10 *
|
|
11 * This program is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2 of the License, or
|
|
14 * (at your option) any later version.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 */
|
|
25
|
|
26 #include <glib.h>
|
|
27
|
|
28 #include "account.h"
|
|
29 #include "connection.h"
|
|
30 #include "debug.h"
|
|
31 #include "roomlist.h"
|
8199
|
32 #include "server.h"
|
8113
|
33
|
|
34
|
|
35 static GaimRoomlistUiOps *ops = NULL;
|
|
36
|
|
37 /**************************************************************************/
|
|
38 /** @name Room List API */
|
|
39 /**************************************************************************/
|
|
40 /*@{*/
|
|
41
|
8352
|
42 void gaim_roomlist_show_with_account(GaimAccount *account)
|
|
43 {
|
|
44 if (ops && ops->show_with_account)
|
|
45 ops->show_with_account(account);
|
|
46 }
|
|
47
|
8113
|
48 GaimRoomlist *gaim_roomlist_new(GaimAccount *account)
|
|
49 {
|
|
50 GaimRoomlist *list;
|
|
51
|
|
52 g_return_val_if_fail(account != NULL, NULL);
|
|
53
|
|
54 list = g_new0(GaimRoomlist, 1);
|
|
55 list->account = account;
|
|
56 list->rooms = NULL;
|
|
57 list->fields = NULL;
|
|
58 list->ref = 1;
|
|
59
|
10027
|
60 if (ops && ops->create)
|
|
61 ops->create(list);
|
8113
|
62
|
|
63 return list;
|
|
64 }
|
|
65
|
|
66 void gaim_roomlist_ref(GaimRoomlist *list)
|
|
67 {
|
|
68 g_return_if_fail(list != NULL);
|
|
69
|
|
70 list->ref++;
|
|
71 gaim_debug_misc("roomlist", "reffing list, ref count now %d\n", list->ref);
|
|
72 }
|
|
73
|
|
74 static void gaim_roomlist_room_destroy(GaimRoomlist *list, GaimRoomlistRoom *r)
|
|
75 {
|
|
76 GList *l, *j;
|
|
77
|
|
78 for (l = list->fields, j = r->fields; l && j; l = l->next, j = j->next) {
|
|
79 GaimRoomlistField *f = l->data;
|
|
80 if (f->type == GAIM_ROOMLIST_FIELD_STRING)
|
|
81 g_free(j->data);
|
|
82 }
|
|
83
|
|
84 g_list_free(r->fields);
|
|
85 g_free(r->name);
|
|
86 g_free(r);
|
|
87 }
|
|
88
|
|
89 static void gaim_roomlist_field_destroy(GaimRoomlistField *f)
|
|
90 {
|
|
91 g_free(f->label);
|
|
92 g_free(f->name);
|
|
93 g_free(f);
|
|
94 }
|
|
95
|
|
96 static void gaim_roomlist_destroy(GaimRoomlist *list)
|
|
97 {
|
|
98 GList *l;
|
|
99
|
|
100 gaim_debug_misc("roomlist", "destroying list %p\n", list);
|
|
101
|
|
102 if (ops && ops->destroy)
|
|
103 ops->destroy(list);
|
|
104
|
|
105 if (list->rooms) {
|
|
106 for (l = list->rooms; l; l = l->next) {
|
|
107 GaimRoomlistRoom *r = l->data;
|
|
108 gaim_roomlist_room_destroy(list, r);
|
|
109 }
|
|
110 g_list_free(list->rooms);
|
|
111 }
|
|
112
|
|
113 if (list->fields) {
|
|
114 for (l = list->fields; l; l = l->next) {
|
|
115 GaimRoomlistField *f = l->data;
|
|
116 gaim_roomlist_field_destroy(f);
|
|
117 }
|
|
118 g_list_free(list->fields);
|
|
119 }
|
|
120
|
|
121 g_free(list);
|
|
122 }
|
|
123
|
|
124 void gaim_roomlist_unref(GaimRoomlist *list)
|
|
125 {
|
|
126 g_return_if_fail(list != NULL);
|
|
127
|
|
128 list->ref--;
|
|
129
|
|
130 gaim_debug_misc("roomlist", "unreffing list, ref count now %d\n", list->ref);
|
|
131 if (list->ref == 0)
|
|
132 gaim_roomlist_destroy(list);
|
|
133 }
|
|
134
|
|
135 void gaim_roomlist_set_fields(GaimRoomlist *list, GList *fields)
|
|
136 {
|
|
137 g_return_if_fail(list != NULL);
|
|
138
|
|
139 list->fields = fields;
|
|
140
|
|
141 if (ops && ops->set_fields)
|
|
142 ops->set_fields(list, fields);
|
|
143 }
|
|
144
|
|
145 void gaim_roomlist_set_in_progress(GaimRoomlist *list, gboolean in_progress)
|
|
146 {
|
|
147 g_return_if_fail(list != NULL);
|
|
148
|
8199
|
149 list->in_progress = in_progress;
|
|
150
|
8113
|
151 if (ops && ops->in_progress)
|
|
152 ops->in_progress(list, in_progress);
|
|
153 }
|
|
154
|
8199
|
155 gboolean gaim_roomlist_get_in_progress(GaimRoomlist *list)
|
|
156 {
|
|
157 g_return_val_if_fail(list != NULL, FALSE);
|
|
158
|
|
159 return list->in_progress;
|
|
160 }
|
|
161
|
8113
|
162 void gaim_roomlist_room_add(GaimRoomlist *list, GaimRoomlistRoom *room)
|
|
163 {
|
|
164 g_return_if_fail(list != NULL);
|
|
165 g_return_if_fail(room != NULL);
|
|
166
|
|
167 list->rooms = g_list_append(list->rooms, room);
|
|
168
|
|
169 if (ops && ops->add_room)
|
|
170 ops->add_room(list, room);
|
|
171 }
|
|
172
|
|
173 GaimRoomlist *gaim_roomlist_get_list(GaimConnection *gc)
|
|
174 {
|
|
175 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
176
|
|
177 g_return_val_if_fail(gc != NULL, NULL);
|
|
178
|
|
179 if (gc->prpl != NULL)
|
|
180 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
181
|
|
182 if (prpl_info && prpl_info->roomlist_get_list)
|
|
183 return prpl_info->roomlist_get_list(gc);
|
|
184 return NULL;
|
|
185 }
|
|
186
|
|
187 void gaim_roomlist_cancel_get_list(GaimRoomlist *list)
|
|
188 {
|
|
189 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
190 GaimConnection *gc;
|
|
191
|
|
192 g_return_if_fail(list != NULL);
|
|
193
|
|
194 gc = gaim_account_get_connection(list->account);
|
|
195
|
|
196 g_return_if_fail(gc != NULL);
|
|
197
|
|
198 if (gc != NULL && gc->prpl != NULL)
|
|
199 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
200
|
|
201 if (prpl_info && prpl_info->roomlist_cancel)
|
|
202 prpl_info->roomlist_cancel(list);
|
|
203 }
|
|
204
|
8584
|
205 void gaim_roomlist_expand_category(GaimRoomlist *list, GaimRoomlistRoom *category)
|
8113
|
206 {
|
|
207 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
208 GaimConnection *gc;
|
|
209
|
|
210 g_return_if_fail(list != NULL);
|
8584
|
211 g_return_if_fail(category != NULL);
|
|
212 g_return_if_fail(category->type & GAIM_ROOMLIST_ROOMTYPE_CATEGORY);
|
8113
|
213
|
|
214 gc = gaim_account_get_connection(list->account);
|
|
215 g_return_if_fail(gc != NULL);
|
|
216
|
|
217 if (gc->prpl != NULL)
|
|
218 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
219
|
8584
|
220 if (prpl_info && prpl_info->roomlist_expand_category)
|
|
221 prpl_info->roomlist_expand_category(list, category);
|
8113
|
222 }
|
|
223
|
|
224 /*@}*/
|
|
225
|
|
226 /**************************************************************************/
|
|
227 /** @name Room API */
|
|
228 /**************************************************************************/
|
|
229 /*@{*/
|
|
230
|
|
231 GaimRoomlistRoom *gaim_roomlist_room_new(GaimRoomlistRoomType type, const gchar *name,
|
|
232 GaimRoomlistRoom *parent)
|
|
233 {
|
|
234 GaimRoomlistRoom *room;
|
|
235
|
|
236 g_return_val_if_fail(name != NULL, NULL);
|
|
237
|
|
238 room = g_new0(GaimRoomlistRoom, 1);
|
|
239 room->type = type;
|
|
240 room->name = g_strdup(name);
|
|
241 room->parent = parent;
|
|
242
|
|
243 return room;
|
|
244 }
|
|
245
|
|
246 void gaim_roomlist_room_add_field(GaimRoomlist *list, GaimRoomlistRoom *room, gconstpointer field)
|
|
247 {
|
|
248 GaimRoomlistField *f;
|
|
249
|
|
250 g_return_if_fail(list != NULL);
|
|
251 g_return_if_fail(room != NULL);
|
|
252 g_return_if_fail(list->fields != NULL);
|
|
253
|
|
254 if (!room->fields)
|
|
255 f = list->fields->data;
|
|
256 else
|
|
257 f = g_list_nth_data(list->fields, g_list_length(room->fields));
|
|
258
|
|
259 g_return_if_fail(f != NULL);
|
|
260
|
|
261 switch(f->type) {
|
|
262 case GAIM_ROOMLIST_FIELD_STRING:
|
|
263 room->fields = g_list_append(room->fields, g_strdup(field));
|
|
264 break;
|
|
265 case GAIM_ROOMLIST_FIELD_BOOL:
|
|
266 case GAIM_ROOMLIST_FIELD_INT:
|
|
267 room->fields = g_list_append(room->fields, GINT_TO_POINTER(field));
|
|
268 break;
|
|
269 }
|
|
270 }
|
|
271
|
8199
|
272 void gaim_roomlist_room_join(GaimRoomlist *list, GaimRoomlistRoom *room)
|
|
273 {
|
|
274 GHashTable *components;
|
|
275 GList *l, *j;
|
|
276 GaimConnection *gc;
|
|
277
|
|
278 g_return_if_fail(list != NULL);
|
|
279 g_return_if_fail(room != NULL);
|
|
280
|
|
281 gc = gaim_account_get_connection(list->account);
|
|
282 if (!gc)
|
|
283 return;
|
|
284
|
|
285 components = g_hash_table_new(g_str_hash, g_str_equal);
|
|
286
|
|
287 g_hash_table_replace(components, "name", room->name);
|
|
288 for (l = list->fields, j = room->fields; l && j; l = l->next, j = j->next) {
|
|
289 GaimRoomlistField *f = l->data;
|
|
290
|
|
291 g_hash_table_replace(components, f->name, j->data);
|
|
292 }
|
|
293
|
|
294 serv_join_chat(gc, components);
|
|
295
|
|
296 g_hash_table_destroy(components);
|
|
297 }
|
|
298
|
8113
|
299 /*@}*/
|
|
300
|
|
301 /**************************************************************************/
|
|
302 /** @name Room Field API */
|
|
303 /**************************************************************************/
|
|
304 /*@{*/
|
|
305
|
|
306 GaimRoomlistField *gaim_roomlist_field_new(GaimRoomlistFieldType type,
|
|
307 const gchar *label, const gchar *name,
|
|
308 gboolean hidden)
|
|
309 {
|
|
310 GaimRoomlistField *f;
|
|
311
|
|
312 g_return_val_if_fail(label != NULL, NULL);
|
|
313 g_return_val_if_fail(name != NULL, NULL);
|
|
314
|
|
315 f = g_new0(GaimRoomlistField, 1);
|
|
316
|
|
317 f->type = type;
|
|
318 f->label = g_strdup(label);
|
|
319 f->name = g_strdup(name);
|
|
320 f->hidden = hidden;
|
|
321
|
|
322 return f;
|
|
323 }
|
|
324
|
|
325 /*@}*/
|
|
326
|
|
327 /**************************************************************************/
|
|
328 /** @name UI Registration Functions */
|
|
329 /**************************************************************************/
|
|
330 /*@{*/
|
|
331
|
|
332
|
|
333 void gaim_roomlist_set_ui_ops(GaimRoomlistUiOps *ui_ops)
|
|
334 {
|
|
335 ops = ui_ops;
|
|
336 }
|
|
337
|
|
338 GaimRoomlistUiOps *gaim_roomlist_get_ui_ops(void)
|
|
339 {
|
|
340 return ops;
|
|
341 }
|
|
342
|
|
343 /*@}*/
|