Mercurial > pidgin
annotate src/roomlist.c @ 14060:81648c6aa918
[gaim-migrate @ 16678]
Show timestamps (or not) in conversations.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Wed, 09 Aug 2006 06:23:18 +0000 |
parents | 8bda65b88e49 |
children |
rev | line source |
---|---|
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 | |
14035 | 105 for (l = list->rooms; l; l = l->next) { |
106 GaimRoomlistRoom *r = l->data; | |
107 gaim_roomlist_room_destroy(list, r); | |
8113 | 108 } |
14035 | 109 g_list_free(list->rooms); |
8113 | 110 |
14035 | 111 g_list_foreach(list->fields, (GFunc)gaim_roomlist_field_destroy, NULL); |
112 g_list_free(list->fields); | |
8113 | 113 |
114 g_free(list); | |
115 } | |
116 | |
117 void gaim_roomlist_unref(GaimRoomlist *list) | |
118 { | |
119 g_return_if_fail(list != NULL); | |
12250
5e2a365af01b
[gaim-migrate @ 14552]
Richard Laager <rlaager@wiktel.com>
parents:
10027
diff
changeset
|
120 g_return_if_fail(list->ref > 0); |
8113 | 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 GaimRoomlist *gaim_roomlist_get_list(GaimConnection *gc) | |
168 { | |
169 GaimPluginProtocolInfo *prpl_info = NULL; | |
170 | |
171 g_return_val_if_fail(gc != NULL, NULL); | |
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 prpl_info->roomlist_get_list(gc); | |
178 return NULL; | |
179 } | |
180 | |
181 void gaim_roomlist_cancel_get_list(GaimRoomlist *list) | |
182 { | |
183 GaimPluginProtocolInfo *prpl_info = NULL; | |
184 GaimConnection *gc; | |
185 | |
186 g_return_if_fail(list != NULL); | |
187 | |
188 gc = gaim_account_get_connection(list->account); | |
189 | |
190 g_return_if_fail(gc != NULL); | |
191 | |
192 if (gc != NULL && gc->prpl != NULL) | |
193 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
194 | |
195 if (prpl_info && prpl_info->roomlist_cancel) | |
196 prpl_info->roomlist_cancel(list); | |
197 } | |
198 | |
8584 | 199 void gaim_roomlist_expand_category(GaimRoomlist *list, GaimRoomlistRoom *category) |
8113 | 200 { |
201 GaimPluginProtocolInfo *prpl_info = NULL; | |
202 GaimConnection *gc; | |
203 | |
204 g_return_if_fail(list != NULL); | |
8584 | 205 g_return_if_fail(category != NULL); |
206 g_return_if_fail(category->type & GAIM_ROOMLIST_ROOMTYPE_CATEGORY); | |
8113 | 207 |
208 gc = gaim_account_get_connection(list->account); | |
209 g_return_if_fail(gc != NULL); | |
210 | |
211 if (gc->prpl != NULL) | |
212 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
213 | |
8584 | 214 if (prpl_info && prpl_info->roomlist_expand_category) |
215 prpl_info->roomlist_expand_category(list, category); | |
8113 | 216 } |
217 | |
218 /*@}*/ | |
219 | |
220 /**************************************************************************/ | |
221 /** @name Room API */ | |
222 /**************************************************************************/ | |
223 /*@{*/ | |
224 | |
225 GaimRoomlistRoom *gaim_roomlist_room_new(GaimRoomlistRoomType type, const gchar *name, | |
226 GaimRoomlistRoom *parent) | |
227 { | |
228 GaimRoomlistRoom *room; | |
229 | |
230 g_return_val_if_fail(name != NULL, NULL); | |
231 | |
232 room = g_new0(GaimRoomlistRoom, 1); | |
233 room->type = type; | |
234 room->name = g_strdup(name); | |
235 room->parent = parent; | |
236 | |
237 return room; | |
238 } | |
239 | |
240 void gaim_roomlist_room_add_field(GaimRoomlist *list, GaimRoomlistRoom *room, gconstpointer field) | |
241 { | |
242 GaimRoomlistField *f; | |
243 | |
244 g_return_if_fail(list != NULL); | |
245 g_return_if_fail(room != NULL); | |
246 g_return_if_fail(list->fields != NULL); | |
247 | |
248 if (!room->fields) | |
249 f = list->fields->data; | |
250 else | |
251 f = g_list_nth_data(list->fields, g_list_length(room->fields)); | |
252 | |
253 g_return_if_fail(f != NULL); | |
254 | |
255 switch(f->type) { | |
256 case GAIM_ROOMLIST_FIELD_STRING: | |
257 room->fields = g_list_append(room->fields, g_strdup(field)); | |
258 break; | |
259 case GAIM_ROOMLIST_FIELD_BOOL: | |
260 case GAIM_ROOMLIST_FIELD_INT: | |
261 room->fields = g_list_append(room->fields, GINT_TO_POINTER(field)); | |
262 break; | |
263 } | |
264 } | |
265 | |
8199 | 266 void gaim_roomlist_room_join(GaimRoomlist *list, GaimRoomlistRoom *room) |
267 { | |
268 GHashTable *components; | |
269 GList *l, *j; | |
270 GaimConnection *gc; | |
271 | |
272 g_return_if_fail(list != NULL); | |
273 g_return_if_fail(room != NULL); | |
274 | |
275 gc = gaim_account_get_connection(list->account); | |
276 if (!gc) | |
277 return; | |
278 | |
279 components = g_hash_table_new(g_str_hash, g_str_equal); | |
280 | |
281 g_hash_table_replace(components, "name", room->name); | |
282 for (l = list->fields, j = room->fields; l && j; l = l->next, j = j->next) { | |
283 GaimRoomlistField *f = l->data; | |
284 | |
285 g_hash_table_replace(components, f->name, j->data); | |
286 } | |
287 | |
288 serv_join_chat(gc, components); | |
289 | |
290 g_hash_table_destroy(components); | |
291 } | |
292 | |
8113 | 293 /*@}*/ |
294 | |
295 /**************************************************************************/ | |
296 /** @name Room Field API */ | |
297 /**************************************************************************/ | |
298 /*@{*/ | |
299 | |
300 GaimRoomlistField *gaim_roomlist_field_new(GaimRoomlistFieldType type, | |
301 const gchar *label, const gchar *name, | |
302 gboolean hidden) | |
303 { | |
304 GaimRoomlistField *f; | |
305 | |
306 g_return_val_if_fail(label != NULL, NULL); | |
307 g_return_val_if_fail(name != NULL, NULL); | |
308 | |
309 f = g_new0(GaimRoomlistField, 1); | |
310 | |
311 f->type = type; | |
312 f->label = g_strdup(label); | |
313 f->name = g_strdup(name); | |
314 f->hidden = hidden; | |
315 | |
316 return f; | |
317 } | |
318 | |
319 /*@}*/ | |
320 | |
321 /**************************************************************************/ | |
322 /** @name UI Registration Functions */ | |
323 /**************************************************************************/ | |
324 /*@{*/ | |
325 | |
326 | |
327 void gaim_roomlist_set_ui_ops(GaimRoomlistUiOps *ui_ops) | |
328 { | |
329 ops = ui_ops; | |
330 } | |
331 | |
332 GaimRoomlistUiOps *gaim_roomlist_get_ui_ops(void) | |
333 { | |
334 return ops; | |
335 } | |
336 | |
337 /*@}*/ |