Sat, 08 Sep 2007 03:09:35 +0000
The FSF changed its address a while ago; our files were out of date.
This is a quick update done with a for loop, find, and sed.
| 8113 | 1 | /** |
| 2 | * @file roomlist.c Room List API | |
| 3 | * @ingroup core | |
| 4 | * | |
| 15884 | 5 | * purple |
| 8113 | 6 | * |
| 15884 | 7 | * Purple is the legal property of its developers, whose names are too numerous |
|
8146
4961c9c5fd61
[gaim-migrate @ 8854]
John Silvestri <john.silvestri@gmail.com>
parents:
8113
diff
changeset
|
8 | * to list here. Please refer to the COPYRIGHT file distributed with this |
|
4961c9c5fd61
[gaim-migrate @ 8854]
John Silvestri <john.silvestri@gmail.com>
parents:
8113
diff
changeset
|
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 | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18265
diff
changeset
|
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 8113 | 24 | */ |
| 25 | ||
| 26 | #include <glib.h> | |
| 27 | ||
|
18265
9f26190d7f46
Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
28 | #include "internal.h" |
|
9f26190d7f46
Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
29 | |
| 8113 | 30 | #include "account.h" |
| 31 | #include "connection.h" | |
| 32 | #include "debug.h" | |
| 33 | #include "roomlist.h" | |
| 8199 | 34 | #include "server.h" |
| 8113 | 35 | |
| 36 | ||
| 15884 | 37 | static PurpleRoomlistUiOps *ops = NULL; |
| 8113 | 38 | |
| 39 | /**************************************************************************/ | |
| 40 | /** @name Room List API */ | |
| 41 | /**************************************************************************/ | |
| 42 | /*@{*/ | |
| 43 | ||
| 15884 | 44 | void purple_roomlist_show_with_account(PurpleAccount *account) |
| 8352 | 45 | { |
| 46 | if (ops && ops->show_with_account) | |
| 47 | ops->show_with_account(account); | |
| 48 | } | |
| 49 | ||
| 15884 | 50 | PurpleRoomlist *purple_roomlist_new(PurpleAccount *account) |
| 8113 | 51 | { |
| 15884 | 52 | PurpleRoomlist *list; |
| 8113 | 53 | |
| 54 | g_return_val_if_fail(account != NULL, NULL); | |
| 55 | ||
| 15884 | 56 | list = g_new0(PurpleRoomlist, 1); |
| 8113 | 57 | list->account = account; |
| 58 | list->rooms = NULL; | |
| 59 | list->fields = NULL; | |
| 60 | list->ref = 1; | |
| 61 | ||
| 10027 | 62 | if (ops && ops->create) |
| 63 | ops->create(list); | |
| 8113 | 64 | |
| 65 | return list; | |
| 66 | } | |
| 67 | ||
| 15884 | 68 | void purple_roomlist_ref(PurpleRoomlist *list) |
| 8113 | 69 | { |
| 70 | g_return_if_fail(list != NULL); | |
| 71 | ||
| 72 | list->ref++; | |
| 15884 | 73 | purple_debug_misc("roomlist", "reffing list, ref count now %d\n", list->ref); |
| 8113 | 74 | } |
| 75 | ||
| 15884 | 76 | static void purple_roomlist_room_destroy(PurpleRoomlist *list, PurpleRoomlistRoom *r) |
| 8113 | 77 | { |
| 78 | GList *l, *j; | |
| 79 | ||
| 80 | for (l = list->fields, j = r->fields; l && j; l = l->next, j = j->next) { | |
| 15884 | 81 | PurpleRoomlistField *f = l->data; |
| 82 | if (f->type == PURPLE_ROOMLIST_FIELD_STRING) | |
| 8113 | 83 | g_free(j->data); |
| 84 | } | |
| 85 | ||
| 86 | g_list_free(r->fields); | |
| 87 | g_free(r->name); | |
| 88 | g_free(r); | |
| 89 | } | |
| 90 | ||
| 15884 | 91 | static void purple_roomlist_field_destroy(PurpleRoomlistField *f) |
| 8113 | 92 | { |
| 93 | g_free(f->label); | |
| 94 | g_free(f->name); | |
| 95 | g_free(f); | |
| 96 | } | |
| 97 | ||
| 15884 | 98 | static void purple_roomlist_destroy(PurpleRoomlist *list) |
| 8113 | 99 | { |
| 100 | GList *l; | |
| 101 | ||
| 15884 | 102 | purple_debug_misc("roomlist", "destroying list %p\n", list); |
| 8113 | 103 | |
| 104 | if (ops && ops->destroy) | |
| 105 | ops->destroy(list); | |
| 106 | ||
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12250
diff
changeset
|
107 | for (l = list->rooms; l; l = l->next) { |
| 15884 | 108 | PurpleRoomlistRoom *r = l->data; |
| 109 | purple_roomlist_room_destroy(list, r); | |
| 8113 | 110 | } |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12250
diff
changeset
|
111 | g_list_free(list->rooms); |
| 8113 | 112 | |
| 15884 | 113 | g_list_foreach(list->fields, (GFunc)purple_roomlist_field_destroy, NULL); |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12250
diff
changeset
|
114 | g_list_free(list->fields); |
| 8113 | 115 | |
| 116 | g_free(list); | |
| 117 | } | |
| 118 | ||
| 15884 | 119 | void purple_roomlist_unref(PurpleRoomlist *list) |
| 8113 | 120 | { |
| 121 | g_return_if_fail(list != NULL); | |
|
12250
5b14301dd1ec
[gaim-migrate @ 14552]
Richard Laager <rlaager@pidgin.im>
parents:
10027
diff
changeset
|
122 | g_return_if_fail(list->ref > 0); |
| 8113 | 123 | |
| 124 | list->ref--; | |
| 125 | ||
| 15884 | 126 | purple_debug_misc("roomlist", "unreffing list, ref count now %d\n", list->ref); |
| 8113 | 127 | if (list->ref == 0) |
| 15884 | 128 | purple_roomlist_destroy(list); |
| 8113 | 129 | } |
| 130 | ||
| 15884 | 131 | void purple_roomlist_set_fields(PurpleRoomlist *list, GList *fields) |
| 8113 | 132 | { |
| 133 | g_return_if_fail(list != NULL); | |
| 134 | ||
| 135 | list->fields = fields; | |
| 136 | ||
| 137 | if (ops && ops->set_fields) | |
| 138 | ops->set_fields(list, fields); | |
| 139 | } | |
| 140 | ||
| 15884 | 141 | void purple_roomlist_set_in_progress(PurpleRoomlist *list, gboolean in_progress) |
| 8113 | 142 | { |
| 143 | g_return_if_fail(list != NULL); | |
| 144 | ||
| 8199 | 145 | list->in_progress = in_progress; |
| 146 | ||
| 8113 | 147 | if (ops && ops->in_progress) |
| 148 | ops->in_progress(list, in_progress); | |
| 149 | } | |
| 150 | ||
| 15884 | 151 | gboolean purple_roomlist_get_in_progress(PurpleRoomlist *list) |
| 8199 | 152 | { |
| 153 | g_return_val_if_fail(list != NULL, FALSE); | |
| 154 | ||
| 155 | return list->in_progress; | |
| 156 | } | |
| 157 | ||
| 15884 | 158 | void purple_roomlist_room_add(PurpleRoomlist *list, PurpleRoomlistRoom *room) |
| 8113 | 159 | { |
| 160 | g_return_if_fail(list != NULL); | |
| 161 | g_return_if_fail(room != NULL); | |
| 162 | ||
| 163 | list->rooms = g_list_append(list->rooms, room); | |
| 164 | ||
| 165 | if (ops && ops->add_room) | |
| 166 | ops->add_room(list, room); | |
| 167 | } | |
| 168 | ||
| 15884 | 169 | PurpleRoomlist *purple_roomlist_get_list(PurpleConnection *gc) |
| 8113 | 170 | { |
| 15884 | 171 | PurplePluginProtocolInfo *prpl_info = NULL; |
| 8113 | 172 | |
| 173 | g_return_val_if_fail(gc != NULL, NULL); | |
| 174 | ||
| 175 | if (gc->prpl != NULL) | |
| 15884 | 176 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
| 8113 | 177 | |
| 178 | if (prpl_info && prpl_info->roomlist_get_list) | |
| 179 | return prpl_info->roomlist_get_list(gc); | |
| 180 | return NULL; | |
| 181 | } | |
| 182 | ||
| 15884 | 183 | void purple_roomlist_cancel_get_list(PurpleRoomlist *list) |
| 8113 | 184 | { |
| 15884 | 185 | PurplePluginProtocolInfo *prpl_info = NULL; |
| 186 | PurpleConnection *gc; | |
| 8113 | 187 | |
| 188 | g_return_if_fail(list != NULL); | |
| 189 | ||
| 15884 | 190 | gc = purple_account_get_connection(list->account); |
| 8113 | 191 | |
| 192 | g_return_if_fail(gc != NULL); | |
| 193 | ||
| 194 | if (gc != NULL && gc->prpl != NULL) | |
| 15884 | 195 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
| 8113 | 196 | |
| 197 | if (prpl_info && prpl_info->roomlist_cancel) | |
| 198 | prpl_info->roomlist_cancel(list); | |
| 199 | } | |
| 200 | ||
| 15884 | 201 | void purple_roomlist_expand_category(PurpleRoomlist *list, PurpleRoomlistRoom *category) |
| 8113 | 202 | { |
| 15884 | 203 | PurplePluginProtocolInfo *prpl_info = NULL; |
| 204 | PurpleConnection *gc; | |
| 8113 | 205 | |
| 206 | g_return_if_fail(list != NULL); | |
| 8584 | 207 | g_return_if_fail(category != NULL); |
| 15884 | 208 | g_return_if_fail(category->type & PURPLE_ROOMLIST_ROOMTYPE_CATEGORY); |
| 8113 | 209 | |
| 15884 | 210 | gc = purple_account_get_connection(list->account); |
| 8113 | 211 | g_return_if_fail(gc != NULL); |
| 212 | ||
| 213 | if (gc->prpl != NULL) | |
| 15884 | 214 | prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(gc->prpl); |
| 8113 | 215 | |
| 8584 | 216 | if (prpl_info && prpl_info->roomlist_expand_category) |
| 217 | prpl_info->roomlist_expand_category(list, category); | |
| 8113 | 218 | } |
| 219 | ||
| 220 | /*@}*/ | |
| 221 | ||
| 222 | /**************************************************************************/ | |
| 223 | /** @name Room API */ | |
| 224 | /**************************************************************************/ | |
| 225 | /*@{*/ | |
| 226 | ||
| 15884 | 227 | PurpleRoomlistRoom *purple_roomlist_room_new(PurpleRoomlistRoomType type, const gchar *name, |
| 228 | PurpleRoomlistRoom *parent) | |
| 8113 | 229 | { |
| 15884 | 230 | PurpleRoomlistRoom *room; |
| 8113 | 231 | |
| 232 | g_return_val_if_fail(name != NULL, NULL); | |
| 233 | ||
| 15884 | 234 | room = g_new0(PurpleRoomlistRoom, 1); |
| 8113 | 235 | room->type = type; |
| 236 | room->name = g_strdup(name); | |
| 237 | room->parent = parent; | |
| 238 | ||
| 239 | return room; | |
| 240 | } | |
| 241 | ||
| 15884 | 242 | void purple_roomlist_room_add_field(PurpleRoomlist *list, PurpleRoomlistRoom *room, gconstpointer field) |
| 8113 | 243 | { |
| 15884 | 244 | PurpleRoomlistField *f; |
| 8113 | 245 | |
| 246 | g_return_if_fail(list != NULL); | |
| 247 | g_return_if_fail(room != NULL); | |
| 248 | g_return_if_fail(list->fields != NULL); | |
| 249 | ||
| 250 | if (!room->fields) | |
| 251 | f = list->fields->data; | |
| 252 | else | |
| 253 | f = g_list_nth_data(list->fields, g_list_length(room->fields)); | |
| 254 | ||
| 255 | g_return_if_fail(f != NULL); | |
| 256 | ||
| 257 | switch(f->type) { | |
| 15884 | 258 | case PURPLE_ROOMLIST_FIELD_STRING: |
| 8113 | 259 | room->fields = g_list_append(room->fields, g_strdup(field)); |
| 260 | break; | |
| 15884 | 261 | case PURPLE_ROOMLIST_FIELD_BOOL: |
| 262 | case PURPLE_ROOMLIST_FIELD_INT: | |
| 8113 | 263 | room->fields = g_list_append(room->fields, GINT_TO_POINTER(field)); |
| 264 | break; | |
| 265 | } | |
| 266 | } | |
| 267 | ||
| 15884 | 268 | void purple_roomlist_room_join(PurpleRoomlist *list, PurpleRoomlistRoom *room) |
| 8199 | 269 | { |
| 270 | GHashTable *components; | |
| 271 | GList *l, *j; | |
| 15884 | 272 | PurpleConnection *gc; |
| 8199 | 273 | |
| 274 | g_return_if_fail(list != NULL); | |
| 275 | g_return_if_fail(room != NULL); | |
| 276 | ||
| 15884 | 277 | gc = purple_account_get_connection(list->account); |
| 8199 | 278 | if (!gc) |
| 279 | return; | |
| 280 | ||
| 281 | components = g_hash_table_new(g_str_hash, g_str_equal); | |
| 282 | ||
| 283 | g_hash_table_replace(components, "name", room->name); | |
| 284 | for (l = list->fields, j = room->fields; l && j; l = l->next, j = j->next) { | |
| 15884 | 285 | PurpleRoomlistField *f = l->data; |
| 8199 | 286 | |
| 287 | g_hash_table_replace(components, f->name, j->data); | |
| 288 | } | |
| 289 | ||
| 290 | serv_join_chat(gc, components); | |
| 291 | ||
| 292 | g_hash_table_destroy(components); | |
| 293 | } | |
| 294 | ||
| 8113 | 295 | /*@}*/ |
| 296 | ||
| 297 | /**************************************************************************/ | |
| 298 | /** @name Room Field API */ | |
| 299 | /**************************************************************************/ | |
| 300 | /*@{*/ | |
| 301 | ||
| 15884 | 302 | PurpleRoomlistField *purple_roomlist_field_new(PurpleRoomlistFieldType type, |
| 8113 | 303 | const gchar *label, const gchar *name, |
| 304 | gboolean hidden) | |
| 305 | { | |
| 15884 | 306 | PurpleRoomlistField *f; |
| 8113 | 307 | |
| 308 | g_return_val_if_fail(label != NULL, NULL); | |
| 309 | g_return_val_if_fail(name != NULL, NULL); | |
| 310 | ||
| 15884 | 311 | f = g_new0(PurpleRoomlistField, 1); |
| 8113 | 312 | |
| 313 | f->type = type; | |
| 314 | f->label = g_strdup(label); | |
| 315 | f->name = g_strdup(name); | |
| 316 | f->hidden = hidden; | |
| 317 | ||
| 318 | return f; | |
| 319 | } | |
| 320 | ||
| 321 | /*@}*/ | |
| 322 | ||
| 323 | /**************************************************************************/ | |
| 324 | /** @name UI Registration Functions */ | |
| 325 | /**************************************************************************/ | |
| 326 | /*@{*/ | |
| 327 | ||
| 328 | ||
| 15884 | 329 | void purple_roomlist_set_ui_ops(PurpleRoomlistUiOps *ui_ops) |
| 8113 | 330 | { |
| 331 | ops = ui_ops; | |
| 332 | } | |
| 333 | ||
| 15884 | 334 | PurpleRoomlistUiOps *purple_roomlist_get_ui_ops(void) |
| 8113 | 335 | { |
| 336 | return ops; | |
| 337 | } | |
| 338 | ||
| 339 | /*@}*/ |