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
|
|
42 GaimRoomlist *gaim_roomlist_new(GaimAccount *account)
|
|
43 {
|
|
44 GaimRoomlist *list;
|
|
45
|
|
46 g_return_val_if_fail(account != NULL, NULL);
|
|
47
|
|
48 list = g_new0(GaimRoomlist, 1);
|
|
49 list->account = account;
|
|
50 list->rooms = NULL;
|
|
51 list->fields = NULL;
|
|
52 list->ref = 1;
|
|
53
|
|
54 if (ops && ops->new)
|
|
55 ops->new(list);
|
|
56
|
|
57 return list;
|
|
58 }
|
|
59
|
|
60 void gaim_roomlist_ref(GaimRoomlist *list)
|
|
61 {
|
|
62 g_return_if_fail(list != NULL);
|
|
63
|
|
64 list->ref++;
|
|
65 gaim_debug_misc("roomlist", "reffing list, ref count now %d\n", list->ref);
|
|
66 }
|
|
67
|
|
68 static void gaim_roomlist_room_destroy(GaimRoomlist *list, GaimRoomlistRoom *r)
|
|
69 {
|
|
70 GList *l, *j;
|
|
71
|
|
72 for (l = list->fields, j = r->fields; l && j; l = l->next, j = j->next) {
|
|
73 GaimRoomlistField *f = l->data;
|
|
74 if (f->type == GAIM_ROOMLIST_FIELD_STRING)
|
|
75 g_free(j->data);
|
|
76 }
|
|
77
|
|
78 g_list_free(r->fields);
|
|
79 g_free(r->name);
|
|
80 g_free(r);
|
|
81 }
|
|
82
|
|
83 static void gaim_roomlist_field_destroy(GaimRoomlistField *f)
|
|
84 {
|
|
85 g_free(f->label);
|
|
86 g_free(f->name);
|
|
87 g_free(f);
|
|
88 }
|
|
89
|
|
90 static void gaim_roomlist_destroy(GaimRoomlist *list)
|
|
91 {
|
|
92 GList *l;
|
|
93
|
|
94 gaim_debug_misc("roomlist", "destroying list %p\n", list);
|
|
95
|
|
96 if (ops && ops->destroy)
|
|
97 ops->destroy(list);
|
|
98
|
|
99 if (list->rooms) {
|
|
100 for (l = list->rooms; l; l = l->next) {
|
|
101 GaimRoomlistRoom *r = l->data;
|
|
102 gaim_roomlist_room_destroy(list, r);
|
|
103 }
|
|
104 g_list_free(list->rooms);
|
|
105 }
|
|
106
|
|
107 if (list->fields) {
|
|
108 for (l = list->fields; l; l = l->next) {
|
|
109 GaimRoomlistField *f = l->data;
|
|
110 gaim_roomlist_field_destroy(f);
|
|
111 }
|
|
112 g_list_free(list->fields);
|
|
113 }
|
|
114
|
|
115 g_free(list);
|
|
116 }
|
|
117
|
|
118 void gaim_roomlist_unref(GaimRoomlist *list)
|
|
119 {
|
|
120 g_return_if_fail(list != NULL);
|
|
121
|
|
122 list->ref--;
|
|
123
|
|
124 gaim_debug_misc("roomlist", "unreffing list, ref count now %d\n", list->ref);
|
|
125 if (list->ref == 0)
|
|
126 gaim_roomlist_destroy(list);
|
|
127 }
|
|
128
|
|
129 void gaim_roomlist_set_fields(GaimRoomlist *list, GList *fields)
|
|
130 {
|
|
131 g_return_if_fail(list != NULL);
|
|
132
|
|
133 list->fields = fields;
|
|
134
|
|
135 if (ops && ops->set_fields)
|
|
136 ops->set_fields(list, fields);
|
|
137 }
|
|
138
|
|
139 void gaim_roomlist_set_in_progress(GaimRoomlist *list, gboolean in_progress)
|
|
140 {
|
|
141 g_return_if_fail(list != NULL);
|
|
142
|
8199
|
143 list->in_progress = in_progress;
|
|
144
|
8113
|
145 if (ops && ops->in_progress)
|
|
146 ops->in_progress(list, in_progress);
|
|
147 }
|
|
148
|
8199
|
149 gboolean gaim_roomlist_get_in_progress(GaimRoomlist *list)
|
|
150 {
|
|
151 g_return_val_if_fail(list != NULL, FALSE);
|
|
152
|
|
153 return list->in_progress;
|
|
154 }
|
|
155
|
8113
|
156 void gaim_roomlist_room_add(GaimRoomlist *list, GaimRoomlistRoom *room)
|
|
157 {
|
|
158 g_return_if_fail(list != NULL);
|
|
159 g_return_if_fail(room != NULL);
|
|
160
|
|
161 list->rooms = g_list_append(list->rooms, room);
|
|
162
|
|
163 if (ops && ops->add_room)
|
|
164 ops->add_room(list, room);
|
|
165 }
|
|
166
|
|
167 gboolean gaim_roomlist_is_possible(GaimConnection *gc)
|
|
168 {
|
|
169 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
170
|
|
171 g_return_val_if_fail(gc != NULL, FALSE);
|
|
172
|
|
173 if (gc->prpl != NULL)
|
|
174 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
175
|
|
176 if (prpl_info && prpl_info->roomlist_get_list)
|
|
177 return TRUE;
|
|
178 return FALSE;
|
|
179 }
|
|
180
|
|
181 GaimRoomlist *gaim_roomlist_get_list(GaimConnection *gc)
|
|
182 {
|
|
183 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
184
|
|
185 g_return_val_if_fail(gc != NULL, NULL);
|
|
186
|
|
187 if (gc->prpl != NULL)
|
|
188 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
189
|
|
190 if (prpl_info && prpl_info->roomlist_get_list)
|
|
191 return prpl_info->roomlist_get_list(gc);
|
|
192 return NULL;
|
|
193 }
|
|
194
|
|
195 void gaim_roomlist_cancel_get_list(GaimRoomlist *list)
|
|
196 {
|
|
197 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
198 GaimConnection *gc;
|
|
199
|
|
200 g_return_if_fail(list != NULL);
|
|
201
|
|
202 gc = gaim_account_get_connection(list->account);
|
|
203
|
|
204 g_return_if_fail(gc != NULL);
|
|
205
|
|
206 if (gc != NULL && gc->prpl != NULL)
|
|
207 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
208
|
|
209 if (prpl_info && prpl_info->roomlist_cancel)
|
|
210 prpl_info->roomlist_cancel(list);
|
|
211 }
|
|
212
|
|
213 void gaim_roomlist_expand_catagory(GaimRoomlist *list, GaimRoomlistRoom *catagory)
|
|
214 {
|
|
215 GaimPluginProtocolInfo *prpl_info = NULL;
|
|
216 GaimConnection *gc;
|
|
217
|
|
218 g_return_if_fail(list != NULL);
|
|
219 g_return_if_fail(catagory != NULL);
|
|
220 g_return_if_fail(catagory->type & GAIM_ROOMLIST_ROOMTYPE_CATAGORY);
|
|
221
|
|
222 gc = gaim_account_get_connection(list->account);
|
|
223 g_return_if_fail(gc != NULL);
|
|
224
|
|
225 if (gc->prpl != NULL)
|
|
226 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
|
|
227
|
|
228 if (prpl_info && prpl_info->roomlist_expand_catagory)
|
|
229 prpl_info->roomlist_expand_catagory(list, catagory);
|
|
230 }
|
|
231
|
|
232 /*@}*/
|
|
233
|
|
234 /**************************************************************************/
|
|
235 /** @name Room API */
|
|
236 /**************************************************************************/
|
|
237 /*@{*/
|
|
238
|
|
239 GaimRoomlistRoom *gaim_roomlist_room_new(GaimRoomlistRoomType type, const gchar *name,
|
|
240 GaimRoomlistRoom *parent)
|
|
241 {
|
|
242 GaimRoomlistRoom *room;
|
|
243
|
|
244 g_return_val_if_fail(name != NULL, NULL);
|
|
245
|
|
246 room = g_new0(GaimRoomlistRoom, 1);
|
|
247 room->type = type;
|
|
248 room->name = g_strdup(name);
|
|
249 room->parent = parent;
|
|
250
|
|
251 return room;
|
|
252 }
|
|
253
|
|
254 void gaim_roomlist_room_add_field(GaimRoomlist *list, GaimRoomlistRoom *room, gconstpointer field)
|
|
255 {
|
|
256 GaimRoomlistField *f;
|
|
257
|
|
258 g_return_if_fail(list != NULL);
|
|
259 g_return_if_fail(room != NULL);
|
|
260 g_return_if_fail(list->fields != NULL);
|
|
261
|
|
262 if (!room->fields)
|
|
263 f = list->fields->data;
|
|
264 else
|
|
265 f = g_list_nth_data(list->fields, g_list_length(room->fields));
|
|
266
|
|
267 g_return_if_fail(f != NULL);
|
|
268
|
|
269 switch(f->type) {
|
|
270 case GAIM_ROOMLIST_FIELD_STRING:
|
|
271 room->fields = g_list_append(room->fields, g_strdup(field));
|
|
272 break;
|
|
273 case GAIM_ROOMLIST_FIELD_BOOL:
|
|
274 case GAIM_ROOMLIST_FIELD_INT:
|
|
275 room->fields = g_list_append(room->fields, GINT_TO_POINTER(field));
|
|
276 break;
|
|
277 }
|
|
278 }
|
|
279
|
8199
|
280 void gaim_roomlist_room_join(GaimRoomlist *list, GaimRoomlistRoom *room)
|
|
281 {
|
|
282 GHashTable *components;
|
|
283 GList *l, *j;
|
|
284 GaimConnection *gc;
|
|
285
|
|
286 g_return_if_fail(list != NULL);
|
|
287 g_return_if_fail(room != NULL);
|
|
288
|
|
289 gc = gaim_account_get_connection(list->account);
|
|
290 if (!gc)
|
|
291 return;
|
|
292
|
|
293 components = g_hash_table_new(g_str_hash, g_str_equal);
|
|
294
|
|
295 g_hash_table_replace(components, "name", room->name);
|
|
296 for (l = list->fields, j = room->fields; l && j; l = l->next, j = j->next) {
|
|
297 GaimRoomlistField *f = l->data;
|
|
298
|
|
299 g_hash_table_replace(components, f->name, j->data);
|
|
300 }
|
|
301
|
|
302 serv_join_chat(gc, components);
|
|
303
|
|
304 g_hash_table_destroy(components);
|
|
305 }
|
|
306
|
8113
|
307 /*@}*/
|
|
308
|
|
309 /**************************************************************************/
|
|
310 /** @name Room Field API */
|
|
311 /**************************************************************************/
|
|
312 /*@{*/
|
|
313
|
|
314 GaimRoomlistField *gaim_roomlist_field_new(GaimRoomlistFieldType type,
|
|
315 const gchar *label, const gchar *name,
|
|
316 gboolean hidden)
|
|
317 {
|
|
318 GaimRoomlistField *f;
|
|
319
|
|
320 g_return_val_if_fail(label != NULL, NULL);
|
|
321 g_return_val_if_fail(name != NULL, NULL);
|
|
322
|
|
323 f = g_new0(GaimRoomlistField, 1);
|
|
324
|
|
325 f->type = type;
|
|
326 f->label = g_strdup(label);
|
|
327 f->name = g_strdup(name);
|
|
328 f->hidden = hidden;
|
|
329
|
|
330 return f;
|
|
331 }
|
|
332
|
|
333 /*@}*/
|
|
334
|
|
335 /**************************************************************************/
|
|
336 /** @name UI Registration Functions */
|
|
337 /**************************************************************************/
|
|
338 /*@{*/
|
|
339
|
|
340
|
|
341 void gaim_roomlist_set_ui_ops(GaimRoomlistUiOps *ui_ops)
|
|
342 {
|
|
343 ops = ui_ops;
|
|
344 }
|
|
345
|
|
346 GaimRoomlistUiOps *gaim_roomlist_get_ui_ops(void)
|
|
347 {
|
|
348 return ops;
|
|
349 }
|
|
350
|
|
351 /*@}*/
|