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
|
|
60 if (ops && ops->new)
|
|
61 ops->new(list);
|
|
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 gboolean gaim_roomlist_is_possible(GaimConnection *gc)
|
|
174 {
|
|
175 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
176
|
|
177 g_return_val_if_fail(gc != NULL, FALSE);
|
|
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 TRUE;
|
|
184 return FALSE;
|
|
185 }
|
|
186
|
|
187 GaimRoomlist *gaim_roomlist_get_list(GaimConnection *gc)
|
|
188 {
|
|
189 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
190
|
|
191 g_return_val_if_fail(gc != NULL, NULL);
|
|
192
|
|
193 if (gc->prpl != NULL)
|
|
194 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
195
|
|
196 if (prpl_info && prpl_info->roomlist_get_list)
|
|
197 return prpl_info->roomlist_get_list(gc);
|
|
198 return NULL;
|
|
199 }
|
|
200
|
|
201 void gaim_roomlist_cancel_get_list(GaimRoomlist *list)
|
|
202 {
|
|
203 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
204 GaimConnection *gc;
|
|
205
|
|
206 g_return_if_fail(list != NULL);
|
|
207
|
|
208 gc = gaim_account_get_connection(list->account);
|
|
209
|
|
210 g_return_if_fail(gc != NULL);
|
|
211
|
|
212 if (gc != NULL && gc->prpl != NULL)
|
|
213 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
214
|
|
215 if (prpl_info && prpl_info->roomlist_cancel)
|
|
216 prpl_info->roomlist_cancel(list);
|
|
217 }
|
|
218
|
8584
|
219 void gaim_roomlist_expand_category(GaimRoomlist *list, GaimRoomlistRoom *category)
|
8113
|
220 {
|
|
221 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
222 GaimConnection *gc;
|
|
223
|
|
224 g_return_if_fail(list != NULL);
|
8584
|
225 g_return_if_fail(category != NULL);
|
|
226 g_return_if_fail(category->type & GAIM_ROOMLIST_ROOMTYPE_CATEGORY);
|
8113
|
227
|
|
228 gc = gaim_account_get_connection(list->account);
|
|
229 g_return_if_fail(gc != NULL);
|
|
230
|
|
231 if (gc->prpl != NULL)
|
|
232 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
233
|
8584
|
234 if (prpl_info && prpl_info->roomlist_expand_category)
|
|
235 prpl_info->roomlist_expand_category(list, category);
|
8113
|
236 }
|
|
237
|
|
238 /*@}*/
|
|
239
|
|
240 /**************************************************************************/
|
|
241 /** @name Room API */
|
|
242 /**************************************************************************/
|
|
243 /*@{*/
|
|
244
|
|
245 GaimRoomlistRoom *gaim_roomlist_room_new(GaimRoomlistRoomType type, const gchar *name,
|
|
246 GaimRoomlistRoom *parent)
|
|
247 {
|
|
248 GaimRoomlistRoom *room;
|
|
249
|
|
250 g_return_val_if_fail(name != NULL, NULL);
|
|
251
|
|
252 room = g_new0(GaimRoomlistRoom, 1);
|
|
253 room->type = type;
|
|
254 room->name = g_strdup(name);
|
|
255 room->parent = parent;
|
|
256
|
|
257 return room;
|
|
258 }
|
|
259
|
|
260 void gaim_roomlist_room_add_field(GaimRoomlist *list, GaimRoomlistRoom *room, gconstpointer field)
|
|
261 {
|
|
262 GaimRoomlistField *f;
|
|
263
|
|
264 g_return_if_fail(list != NULL);
|
|
265 g_return_if_fail(room != NULL);
|
|
266 g_return_if_fail(list->fields != NULL);
|
|
267
|
|
268 if (!room->fields)
|
|
269 f = list->fields->data;
|
|
270 else
|
|
271 f = g_list_nth_data(list->fields, g_list_length(room->fields));
|
|
272
|
|
273 g_return_if_fail(f != NULL);
|
|
274
|
|
275 switch(f->type) {
|
|
276 case GAIM_ROOMLIST_FIELD_STRING:
|
|
277 room->fields = g_list_append(room->fields, g_strdup(field));
|
|
278 break;
|
|
279 case GAIM_ROOMLIST_FIELD_BOOL:
|
|
280 case GAIM_ROOMLIST_FIELD_INT:
|
|
281 room->fields = g_list_append(room->fields, GINT_TO_POINTER(field));
|
|
282 break;
|
|
283 }
|
|
284 }
|
|
285
|
8199
|
286 void gaim_roomlist_room_join(GaimRoomlist *list, GaimRoomlistRoom *room)
|
|
287 {
|
|
288 GHashTable *components;
|
|
289 GList *l, *j;
|
|
290 GaimConnection *gc;
|
|
291
|
|
292 g_return_if_fail(list != NULL);
|
|
293 g_return_if_fail(room != NULL);
|
|
294
|
|
295 gc = gaim_account_get_connection(list->account);
|
|
296 if (!gc)
|
|
297 return;
|
|
298
|
|
299 components = g_hash_table_new(g_str_hash, g_str_equal);
|
|
300
|
|
301 g_hash_table_replace(components, "name", room->name);
|
|
302 for (l = list->fields, j = room->fields; l && j; l = l->next, j = j->next) {
|
|
303 GaimRoomlistField *f = l->data;
|
|
304
|
|
305 g_hash_table_replace(components, f->name, j->data);
|
|
306 }
|
|
307
|
|
308 serv_join_chat(gc, components);
|
|
309
|
|
310 g_hash_table_destroy(components);
|
|
311 }
|
|
312
|
8113
|
313 /*@}*/
|
|
314
|
|
315 /**************************************************************************/
|
|
316 /** @name Room Field API */
|
|
317 /**************************************************************************/
|
|
318 /*@{*/
|
|
319
|
|
320 GaimRoomlistField *gaim_roomlist_field_new(GaimRoomlistFieldType type,
|
|
321 const gchar *label, const gchar *name,
|
|
322 gboolean hidden)
|
|
323 {
|
|
324 GaimRoomlistField *f;
|
|
325
|
|
326 g_return_val_if_fail(label != NULL, NULL);
|
|
327 g_return_val_if_fail(name != NULL, NULL);
|
|
328
|
|
329 f = g_new0(GaimRoomlistField, 1);
|
|
330
|
|
331 f->type = type;
|
|
332 f->label = g_strdup(label);
|
|
333 f->name = g_strdup(name);
|
|
334 f->hidden = hidden;
|
|
335
|
|
336 return f;
|
|
337 }
|
|
338
|
|
339 /*@}*/
|
|
340
|
|
341 /**************************************************************************/
|
|
342 /** @name UI Registration Functions */
|
|
343 /**************************************************************************/
|
|
344 /*@{*/
|
|
345
|
|
346
|
|
347 void gaim_roomlist_set_ui_ops(GaimRoomlistUiOps *ui_ops)
|
|
348 {
|
|
349 ops = ui_ops;
|
|
350 }
|
|
351
|
|
352 GaimRoomlistUiOps *gaim_roomlist_get_ui_ops(void)
|
|
353 {
|
|
354 return ops;
|
|
355 }
|
|
356
|
|
357 /*@}*/
|