Tue, 20 Jan 2004 02:51:14 +0000
[gaim-migrate @ 8854]
"
(16:36:05) Me: Hi Sean
(16:36:21) Me: Mind if I e-mail you a little COPYRIGHT related diff?
(16:37:17) Sean: Yes, I do!
(16:37:22) Sean: How dare you consider e-mailing me patches?
(16:37:26) Sean: seriously, now.
(16:37:32) Me:
(16:38:42) Me: Look at my webcam:
[URL to patch, now attached to this message]
(16:43:03) Sean: Have Luke commit it for me
(16:43:17) Sean: I won't be around until late tomorrow night.
(16:46:53) Me: ahh, k
It's a pretty straightforward deal - I think I mentioned this the other
day: .[c|h] files in src/ should have the generic copyright. Also,
giving Marc Mulcahy credit for the accessibility stuff.
Cheers,
John [Silvestri]"
except that i'd already given Marc credit
committer: Luke Schierer <lschiere@pidgin.im>
| 8113 | 1 | /** |
| 2 | * @file roomlist.c Room List API | |
| 3 | * @ingroup core | |
| 4 | * | |
| 5 | * gaim | |
| 6 | * | |
|
8146
4961c9c5fd61
[gaim-migrate @ 8854]
John Silvestri <john.silvestri@gmail.com>
parents:
8113
diff
changeset
|
7 | * Gaim is the legal property of its developers, whose names are too numerous |
|
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 | |
| 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" | |
| 32 | ||
| 33 | ||
| 34 | static GaimRoomlistUiOps *ops = NULL; | |
| 35 | ||
| 36 | /**************************************************************************/ | |
| 37 | /** @name Room List API */ | |
| 38 | /**************************************************************************/ | |
| 39 | /*@{*/ | |
| 40 | ||
| 41 | GaimRoomlist *gaim_roomlist_new(GaimAccount *account) | |
| 42 | { | |
| 43 | GaimRoomlist *list; | |
| 44 | ||
| 45 | g_return_val_if_fail(account != NULL, NULL); | |
| 46 | ||
| 47 | list = g_new0(GaimRoomlist, 1); | |
| 48 | list->account = account; | |
| 49 | list->rooms = NULL; | |
| 50 | list->fields = NULL; | |
| 51 | list->ref = 1; | |
| 52 | ||
| 53 | if (ops && ops->new) | |
| 54 | ops->new(list); | |
| 55 | ||
| 56 | return list; | |
| 57 | } | |
| 58 | ||
| 59 | void gaim_roomlist_ref(GaimRoomlist *list) | |
| 60 | { | |
| 61 | g_return_if_fail(list != NULL); | |
| 62 | ||
| 63 | list->ref++; | |
| 64 | gaim_debug_misc("roomlist", "reffing list, ref count now %d\n", list->ref); | |
| 65 | } | |
| 66 | ||
| 67 | static void gaim_roomlist_room_destroy(GaimRoomlist *list, GaimRoomlistRoom *r) | |
| 68 | { | |
| 69 | GList *l, *j; | |
| 70 | ||
| 71 | for (l = list->fields, j = r->fields; l && j; l = l->next, j = j->next) { | |
| 72 | GaimRoomlistField *f = l->data; | |
| 73 | if (f->type == GAIM_ROOMLIST_FIELD_STRING) | |
| 74 | g_free(j->data); | |
| 75 | } | |
| 76 | ||
| 77 | g_list_free(r->fields); | |
| 78 | g_free(r->name); | |
| 79 | g_free(r); | |
| 80 | } | |
| 81 | ||
| 82 | static void gaim_roomlist_field_destroy(GaimRoomlistField *f) | |
| 83 | { | |
| 84 | g_free(f->label); | |
| 85 | g_free(f->name); | |
| 86 | g_free(f); | |
| 87 | } | |
| 88 | ||
| 89 | static void gaim_roomlist_destroy(GaimRoomlist *list) | |
| 90 | { | |
| 91 | GList *l; | |
| 92 | ||
| 93 | gaim_debug_misc("roomlist", "destroying list %p\n", list); | |
| 94 | ||
| 95 | if (ops && ops->destroy) | |
| 96 | ops->destroy(list); | |
| 97 | ||
| 98 | if (list->rooms) { | |
| 99 | for (l = list->rooms; l; l = l->next) { | |
| 100 | GaimRoomlistRoom *r = l->data; | |
| 101 | gaim_roomlist_room_destroy(list, r); | |
| 102 | } | |
| 103 | g_list_free(list->rooms); | |
| 104 | } | |
| 105 | ||
| 106 | if (list->fields) { | |
| 107 | for (l = list->fields; l; l = l->next) { | |
| 108 | GaimRoomlistField *f = l->data; | |
| 109 | gaim_roomlist_field_destroy(f); | |
| 110 | } | |
| 111 | g_list_free(list->fields); | |
| 112 | } | |
| 113 | ||
| 114 | g_free(list); | |
| 115 | } | |
| 116 | ||
| 117 | void gaim_roomlist_unref(GaimRoomlist *list) | |
| 118 | { | |
| 119 | g_return_if_fail(list != NULL); | |
| 120 | ||
| 121 | list->ref--; | |
| 122 | ||
| 123 | gaim_debug_misc("roomlist", "unreffing list, ref count now %d\n", list->ref); | |
| 124 | if (list->ref == 0) | |
| 125 | gaim_roomlist_destroy(list); | |
| 126 | } | |
| 127 | ||
| 128 | void gaim_roomlist_set_fields(GaimRoomlist *list, GList *fields) | |
| 129 | { | |
| 130 | g_return_if_fail(list != NULL); | |
| 131 | ||
| 132 | list->fields = fields; | |
| 133 | ||
| 134 | if (ops && ops->set_fields) | |
| 135 | ops->set_fields(list, fields); | |
| 136 | } | |
| 137 | ||
| 138 | void gaim_roomlist_set_in_progress(GaimRoomlist *list, gboolean in_progress) | |
| 139 | { | |
| 140 | g_return_if_fail(list != NULL); | |
| 141 | ||
| 142 | if (ops && ops->in_progress) | |
| 143 | ops->in_progress(list, in_progress); | |
| 144 | } | |
| 145 | ||
| 146 | void gaim_roomlist_room_add(GaimRoomlist *list, GaimRoomlistRoom *room) | |
| 147 | { | |
| 148 | g_return_if_fail(list != NULL); | |
| 149 | g_return_if_fail(room != NULL); | |
| 150 | ||
| 151 | list->rooms = g_list_append(list->rooms, room); | |
| 152 | ||
| 153 | if (ops && ops->add_room) | |
| 154 | ops->add_room(list, room); | |
| 155 | } | |
| 156 | ||
| 157 | gboolean gaim_roomlist_is_possible(GaimConnection *gc) | |
| 158 | { | |
| 159 | GaimPluginProtocolInfo *prpl_info = NULL; | |
| 160 | ||
| 161 | g_return_val_if_fail(gc != NULL, FALSE); | |
| 162 | ||
| 163 | if (gc->prpl != NULL) | |
| 164 | prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 165 | ||
| 166 | if (prpl_info && prpl_info->roomlist_get_list) | |
| 167 | return TRUE; | |
| 168 | return FALSE; | |
| 169 | } | |
| 170 | ||
| 171 | GaimRoomlist *gaim_roomlist_get_list(GaimConnection *gc) | |
| 172 | { | |
| 173 | GaimPluginProtocolInfo *prpl_info = NULL; | |
| 174 | ||
| 175 | g_return_val_if_fail(gc != NULL, NULL); | |
| 176 | ||
| 177 | if (gc->prpl != NULL) | |
| 178 | prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 179 | ||
| 180 | if (prpl_info && prpl_info->roomlist_get_list) | |
| 181 | return prpl_info->roomlist_get_list(gc); | |
| 182 | return NULL; | |
| 183 | } | |
| 184 | ||
| 185 | void gaim_roomlist_cancel_get_list(GaimRoomlist *list) | |
| 186 | { | |
| 187 | GaimPluginProtocolInfo *prpl_info = NULL; | |
| 188 | GaimConnection *gc; | |
| 189 | ||
| 190 | g_return_if_fail(list != NULL); | |
| 191 | ||
| 192 | gc = gaim_account_get_connection(list->account); | |
| 193 | ||
| 194 | g_return_if_fail(gc != NULL); | |
| 195 | ||
| 196 | if (gc != NULL && gc->prpl != NULL) | |
| 197 | prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 198 | ||
| 199 | if (prpl_info && prpl_info->roomlist_cancel) | |
| 200 | prpl_info->roomlist_cancel(list); | |
| 201 | } | |
| 202 | ||
| 203 | void gaim_roomlist_expand_catagory(GaimRoomlist *list, GaimRoomlistRoom *catagory) | |
| 204 | { | |
| 205 | GaimPluginProtocolInfo *prpl_info = NULL; | |
| 206 | GaimConnection *gc; | |
| 207 | ||
| 208 | g_return_if_fail(list != NULL); | |
| 209 | g_return_if_fail(catagory != NULL); | |
| 210 | g_return_if_fail(catagory->type & GAIM_ROOMLIST_ROOMTYPE_CATAGORY); | |
| 211 | ||
| 212 | gc = gaim_account_get_connection(list->account); | |
| 213 | g_return_if_fail(gc != NULL); | |
| 214 | ||
| 215 | if (gc->prpl != NULL) | |
| 216 | prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); | |
| 217 | ||
| 218 | if (prpl_info && prpl_info->roomlist_expand_catagory) | |
| 219 | prpl_info->roomlist_expand_catagory(list, catagory); | |
| 220 | } | |
| 221 | ||
| 222 | /*@}*/ | |
| 223 | ||
| 224 | /**************************************************************************/ | |
| 225 | /** @name Room API */ | |
| 226 | /**************************************************************************/ | |
| 227 | /*@{*/ | |
| 228 | ||
| 229 | GaimRoomlistRoom *gaim_roomlist_room_new(GaimRoomlistRoomType type, const gchar *name, | |
| 230 | GaimRoomlistRoom *parent) | |
| 231 | { | |
| 232 | GaimRoomlistRoom *room; | |
| 233 | ||
| 234 | g_return_val_if_fail(name != NULL, NULL); | |
| 235 | ||
| 236 | room = g_new0(GaimRoomlistRoom, 1); | |
| 237 | room->type = type; | |
| 238 | room->name = g_strdup(name); | |
| 239 | room->parent = parent; | |
| 240 | ||
| 241 | return room; | |
| 242 | } | |
| 243 | ||
| 244 | void gaim_roomlist_room_add_field(GaimRoomlist *list, GaimRoomlistRoom *room, gconstpointer field) | |
| 245 | { | |
| 246 | GaimRoomlistField *f; | |
| 247 | ||
| 248 | g_return_if_fail(list != NULL); | |
| 249 | g_return_if_fail(room != NULL); | |
| 250 | g_return_if_fail(list->fields != NULL); | |
| 251 | ||
| 252 | if (!room->fields) | |
| 253 | f = list->fields->data; | |
| 254 | else | |
| 255 | f = g_list_nth_data(list->fields, g_list_length(room->fields)); | |
| 256 | ||
| 257 | g_return_if_fail(f != NULL); | |
| 258 | ||
| 259 | switch(f->type) { | |
| 260 | case GAIM_ROOMLIST_FIELD_STRING: | |
| 261 | room->fields = g_list_append(room->fields, g_strdup(field)); | |
| 262 | break; | |
| 263 | case GAIM_ROOMLIST_FIELD_BOOL: | |
| 264 | case GAIM_ROOMLIST_FIELD_INT: | |
| 265 | room->fields = g_list_append(room->fields, GINT_TO_POINTER(field)); | |
| 266 | break; | |
| 267 | } | |
| 268 | } | |
| 269 | ||
| 270 | /*@}*/ | |
| 271 | ||
| 272 | /**************************************************************************/ | |
| 273 | /** @name Room Field API */ | |
| 274 | /**************************************************************************/ | |
| 275 | /*@{*/ | |
| 276 | ||
| 277 | GaimRoomlistField *gaim_roomlist_field_new(GaimRoomlistFieldType type, | |
| 278 | const gchar *label, const gchar *name, | |
| 279 | gboolean hidden) | |
| 280 | { | |
| 281 | GaimRoomlistField *f; | |
| 282 | ||
| 283 | g_return_val_if_fail(label != NULL, NULL); | |
| 284 | g_return_val_if_fail(name != NULL, NULL); | |
| 285 | ||
| 286 | f = g_new0(GaimRoomlistField, 1); | |
| 287 | ||
| 288 | f->type = type; | |
| 289 | f->label = g_strdup(label); | |
| 290 | f->name = g_strdup(name); | |
| 291 | f->hidden = hidden; | |
| 292 | ||
| 293 | return f; | |
| 294 | } | |
| 295 | ||
| 296 | /*@}*/ | |
| 297 | ||
| 298 | /**************************************************************************/ | |
| 299 | /** @name UI Registration Functions */ | |
| 300 | /**************************************************************************/ | |
| 301 | /*@{*/ | |
| 302 | ||
| 303 | ||
| 304 | void gaim_roomlist_set_ui_ops(GaimRoomlistUiOps *ui_ops) | |
| 305 | { | |
| 306 | ops = ui_ops; | |
| 307 | } | |
| 308 | ||
| 309 | GaimRoomlistUiOps *gaim_roomlist_get_ui_ops(void) | |
| 310 | { | |
| 311 | return ops; | |
| 312 | } | |
| 313 | ||
| 314 | /*@}*/ |