Sun, 01 Sep 2013 14:24:24 +0530
Renamed some prpl stuff to protocol stuff.
Renamed /plugins/prpl prefs to /protocols
| 8113 | 1 | /** |
| 2 | * @file roomlist.c Room List API | |
| 3 | * @ingroup core | |
|
20147
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
4 | */ |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
5 | |
|
66f05a854eee
applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
6 | /* purple |
| 8113 | 7 | * |
| 15884 | 8 | * 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
|
9 | * 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
|
10 | * source distribution. |
| 8113 | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify | |
| 13 | * it under the terms of the GNU General Public License as published by | |
| 14 | * the Free Software Foundation; either version 2 of the License, or | |
| 15 | * (at your option) any later version. | |
| 16 | * | |
| 17 | * This program is distributed in the hope that it will be useful, | |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 | * GNU General Public License for more details. | |
| 21 | * | |
| 22 | * You should have received a copy of the GNU General Public License | |
| 23 | * 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
|
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 8113 | 25 | */ |
| 26 | ||
|
18265
9f26190d7f46
Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
27 | #include "internal.h" |
|
9f26190d7f46
Move the define in internal.h instead.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
15884
diff
changeset
|
28 | |
| 8113 | 29 | #include "account.h" |
| 30 | #include "connection.h" | |
| 31 | #include "debug.h" | |
| 32 | #include "roomlist.h" | |
| 8199 | 33 | #include "server.h" |
| 8113 | 34 | |
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
35 | /** |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
36 | * Represents a list of rooms for a given connection on a given protocol. |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
37 | */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
38 | struct _PurpleRoomlist { |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
39 | PurpleAccount *account; /**< The account this list belongs to. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
40 | GList *fields; /**< The fields. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
41 | GList *rooms; /**< The list of rooms. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
42 | gboolean in_progress; /**< The listing is in progress. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
43 | gpointer ui_data; /**< UI private data. */ |
|
36637
9b0109ae118d
Renamed some prpl stuff to protocol stuff.
Ankit Vani <a@nevitus.org>
parents:
36630
diff
changeset
|
44 | gpointer proto_data; /** Protocol private data. */ |
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
45 | guint ref; /**< The reference count. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
46 | }; |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
47 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
48 | /** |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
49 | * Represents a room. |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
50 | */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
51 | struct _PurpleRoomlistRoom { |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
52 | PurpleRoomlistRoomType type; /**< The type of room. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
53 | gchar *name; /**< The name of the room. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
54 | GList *fields; /**< Other fields. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
55 | PurpleRoomlistRoom *parent; /**< The parent room, or NULL. */ |
|
36637
9b0109ae118d
Renamed some prpl stuff to protocol stuff.
Ankit Vani <a@nevitus.org>
parents:
36630
diff
changeset
|
56 | gboolean expanded_once; /**< A flag the UI uses to avoid multiple expand protocol cbs. */ |
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
57 | }; |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
58 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
59 | /** |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
60 | * A field a room might have. |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
61 | */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
62 | struct _PurpleRoomlistField { |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
63 | PurpleRoomlistFieldType type; /**< The type of field. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
64 | gchar *label; /**< The i18n user displayed name of the field. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
65 | gchar *name; /**< The internal name of the field. */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
66 | gboolean hidden; /**< Hidden? */ |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
67 | }; |
| 8113 | 68 | |
| 15884 | 69 | static PurpleRoomlistUiOps *ops = NULL; |
| 8113 | 70 | |
| 71 | /**************************************************************************/ | |
| 72 | /** @name Room List API */ | |
| 73 | /**************************************************************************/ | |
| 74 | /*@{*/ | |
| 75 | ||
| 15884 | 76 | void purple_roomlist_show_with_account(PurpleAccount *account) |
| 8352 | 77 | { |
| 78 | if (ops && ops->show_with_account) | |
| 79 | ops->show_with_account(account); | |
| 80 | } | |
| 81 | ||
| 15884 | 82 | PurpleRoomlist *purple_roomlist_new(PurpleAccount *account) |
| 8113 | 83 | { |
| 15884 | 84 | PurpleRoomlist *list; |
| 8113 | 85 | |
| 86 | g_return_val_if_fail(account != NULL, NULL); | |
| 87 | ||
| 15884 | 88 | list = g_new0(PurpleRoomlist, 1); |
| 8113 | 89 | list->account = account; |
| 90 | list->rooms = NULL; | |
| 91 | list->fields = NULL; | |
| 92 | list->ref = 1; | |
| 93 | ||
| 10027 | 94 | if (ops && ops->create) |
| 95 | ops->create(list); | |
| 8113 | 96 | |
| 97 | return list; | |
| 98 | } | |
| 99 | ||
| 15884 | 100 | void purple_roomlist_ref(PurpleRoomlist *list) |
| 8113 | 101 | { |
| 102 | g_return_if_fail(list != NULL); | |
| 103 | ||
| 104 | list->ref++; | |
| 15884 | 105 | purple_debug_misc("roomlist", "reffing list, ref count now %d\n", list->ref); |
| 8113 | 106 | } |
| 107 | ||
| 15884 | 108 | static void purple_roomlist_room_destroy(PurpleRoomlist *list, PurpleRoomlistRoom *r) |
| 8113 | 109 | { |
| 110 | GList *l, *j; | |
| 111 | ||
| 112 | for (l = list->fields, j = r->fields; l && j; l = l->next, j = j->next) { | |
| 15884 | 113 | PurpleRoomlistField *f = l->data; |
| 114 | if (f->type == PURPLE_ROOMLIST_FIELD_STRING) | |
| 8113 | 115 | g_free(j->data); |
| 116 | } | |
| 117 | ||
| 118 | g_list_free(r->fields); | |
| 119 | g_free(r->name); | |
| 120 | g_free(r); | |
| 121 | } | |
| 122 | ||
| 15884 | 123 | static void purple_roomlist_field_destroy(PurpleRoomlistField *f) |
| 8113 | 124 | { |
| 125 | g_free(f->label); | |
| 126 | g_free(f->name); | |
| 127 | g_free(f); | |
| 128 | } | |
| 129 | ||
| 15884 | 130 | static void purple_roomlist_destroy(PurpleRoomlist *list) |
| 8113 | 131 | { |
| 132 | GList *l; | |
| 133 | ||
| 15884 | 134 | purple_debug_misc("roomlist", "destroying list %p\n", list); |
| 8113 | 135 | |
| 136 | if (ops && ops->destroy) | |
| 137 | ops->destroy(list); | |
| 138 | ||
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12250
diff
changeset
|
139 | for (l = list->rooms; l; l = l->next) { |
| 15884 | 140 | PurpleRoomlistRoom *r = l->data; |
| 141 | purple_roomlist_room_destroy(list, r); | |
| 8113 | 142 | } |
|
14097
0c340861ab79
[gaim-migrate @ 16638]
Mark Doliner <markdoliner@pidgin.im>
parents:
12250
diff
changeset
|
143 | g_list_free(list->rooms); |
| 8113 | 144 | |
| 15884 | 145 | 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
|
146 | g_list_free(list->fields); |
| 8113 | 147 | |
| 148 | g_free(list); | |
| 149 | } | |
| 150 | ||
| 15884 | 151 | void purple_roomlist_unref(PurpleRoomlist *list) |
| 8113 | 152 | { |
| 153 | g_return_if_fail(list != NULL); | |
|
12250
5b14301dd1ec
[gaim-migrate @ 14552]
Richard Laager <rlaager@pidgin.im>
parents:
10027
diff
changeset
|
154 | g_return_if_fail(list->ref > 0); |
| 8113 | 155 | |
| 156 | list->ref--; | |
| 157 | ||
| 15884 | 158 | purple_debug_misc("roomlist", "unreffing list, ref count now %d\n", list->ref); |
| 8113 | 159 | if (list->ref == 0) |
| 15884 | 160 | purple_roomlist_destroy(list); |
| 8113 | 161 | } |
| 162 | ||
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
163 | PurpleAccount *purple_roomlist_get_account(PurpleRoomlist *list) |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
164 | { |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
165 | g_return_val_if_fail(list != NULL, NULL); |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
166 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
167 | return list->account; |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
168 | } |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
169 | |
| 15884 | 170 | void purple_roomlist_set_fields(PurpleRoomlist *list, GList *fields) |
| 8113 | 171 | { |
| 172 | g_return_if_fail(list != NULL); | |
| 173 | ||
| 174 | list->fields = fields; | |
| 175 | ||
| 176 | if (ops && ops->set_fields) | |
| 177 | ops->set_fields(list, fields); | |
| 178 | } | |
| 179 | ||
| 15884 | 180 | void purple_roomlist_set_in_progress(PurpleRoomlist *list, gboolean in_progress) |
| 8113 | 181 | { |
| 182 | g_return_if_fail(list != NULL); | |
| 183 | ||
| 8199 | 184 | list->in_progress = in_progress; |
| 185 | ||
| 8113 | 186 | if (ops && ops->in_progress) |
| 187 | ops->in_progress(list, in_progress); | |
| 188 | } | |
| 189 | ||
| 15884 | 190 | gboolean purple_roomlist_get_in_progress(PurpleRoomlist *list) |
| 8199 | 191 | { |
| 192 | g_return_val_if_fail(list != NULL, FALSE); | |
| 193 | ||
| 194 | return list->in_progress; | |
| 195 | } | |
| 196 | ||
| 15884 | 197 | void purple_roomlist_room_add(PurpleRoomlist *list, PurpleRoomlistRoom *room) |
| 8113 | 198 | { |
| 199 | g_return_if_fail(list != NULL); | |
| 200 | g_return_if_fail(room != NULL); | |
| 201 | ||
| 202 | list->rooms = g_list_append(list->rooms, room); | |
| 203 | ||
| 204 | if (ops && ops->add_room) | |
| 205 | ops->add_room(list, room); | |
| 206 | } | |
| 207 | ||
| 15884 | 208 | PurpleRoomlist *purple_roomlist_get_list(PurpleConnection *gc) |
| 8113 | 209 | { |
|
36544
1bf8b6ef5aea
Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents:
36376
diff
changeset
|
210 | PurpleProtocol *protocol = NULL; |
| 8113 | 211 | |
| 212 | g_return_val_if_fail(gc != NULL, NULL); | |
|
24863
68c109ca0089
Fix a crash that happens when accessing the roomlist for an account that's
Paul Aurich <darkrain42@pidgin.im>
parents:
24814
diff
changeset
|
213 | g_return_val_if_fail(PURPLE_CONNECTION_IS_CONNECTED(gc), NULL); |
| 8113 | 214 | |
|
36623
caaadef03507
Renamed purple_connection_get_protocol_info() to purple_connection_get_protocol()
Ankit Vani <a@nevitus.org>
parents:
36606
diff
changeset
|
215 | protocol = purple_connection_get_protocol(gc); |
|
22390
d22357d5c7ba
Kill off gc->prpl in the core everywhere but connection.c (when the struct
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22134
diff
changeset
|
216 | |
|
36630
ff356949df25
Refactored the rest of libpurple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents:
36623
diff
changeset
|
217 | if(protocol) |
|
36606
9fe2d65fe1a7
Use the purple_protocol_iface_* API instead of protocol->function()
Ankit Vani <a@nevitus.org>
parents:
36544
diff
changeset
|
218 | return purple_protocol_iface_roomlist_get_list(protocol, gc); |
|
22390
d22357d5c7ba
Kill off gc->prpl in the core everywhere but connection.c (when the struct
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22134
diff
changeset
|
219 | |
| 8113 | 220 | return NULL; |
| 221 | } | |
| 222 | ||
| 15884 | 223 | void purple_roomlist_cancel_get_list(PurpleRoomlist *list) |
| 8113 | 224 | { |
|
36544
1bf8b6ef5aea
Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents:
36376
diff
changeset
|
225 | PurpleProtocol *protocol = NULL; |
| 15884 | 226 | PurpleConnection *gc; |
| 8113 | 227 | |
| 228 | g_return_if_fail(list != NULL); | |
| 229 | ||
| 15884 | 230 | gc = purple_account_get_connection(list->account); |
| 8113 | 231 | |
| 232 | g_return_if_fail(gc != NULL); | |
| 233 | ||
|
22390
d22357d5c7ba
Kill off gc->prpl in the core everywhere but connection.c (when the struct
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22134
diff
changeset
|
234 | if(gc) |
|
36623
caaadef03507
Renamed purple_connection_get_protocol_info() to purple_connection_get_protocol()
Ankit Vani <a@nevitus.org>
parents:
36606
diff
changeset
|
235 | protocol = purple_connection_get_protocol(gc); |
|
22390
d22357d5c7ba
Kill off gc->prpl in the core everywhere but connection.c (when the struct
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22134
diff
changeset
|
236 | |
|
36630
ff356949df25
Refactored the rest of libpurple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents:
36623
diff
changeset
|
237 | if(protocol) |
|
36606
9fe2d65fe1a7
Use the purple_protocol_iface_* API instead of protocol->function()
Ankit Vani <a@nevitus.org>
parents:
36544
diff
changeset
|
238 | purple_protocol_iface_roomlist_cancel(protocol, list); |
| 8113 | 239 | } |
| 240 | ||
| 15884 | 241 | void purple_roomlist_expand_category(PurpleRoomlist *list, PurpleRoomlistRoom *category) |
| 8113 | 242 | { |
|
36544
1bf8b6ef5aea
Renamed PurplePluginProtocolInfo to PurpleProtocol
Ankit Vani <a@nevitus.org>
parents:
36376
diff
changeset
|
243 | PurpleProtocol *protocol = NULL; |
| 15884 | 244 | PurpleConnection *gc; |
| 8113 | 245 | |
| 246 | g_return_if_fail(list != NULL); | |
| 8584 | 247 | g_return_if_fail(category != NULL); |
| 15884 | 248 | g_return_if_fail(category->type & PURPLE_ROOMLIST_ROOMTYPE_CATEGORY); |
| 8113 | 249 | |
| 15884 | 250 | gc = purple_account_get_connection(list->account); |
| 8113 | 251 | g_return_if_fail(gc != NULL); |
| 252 | ||
|
22390
d22357d5c7ba
Kill off gc->prpl in the core everywhere but connection.c (when the struct
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22134
diff
changeset
|
253 | if(gc) |
|
36623
caaadef03507
Renamed purple_connection_get_protocol_info() to purple_connection_get_protocol()
Ankit Vani <a@nevitus.org>
parents:
36606
diff
changeset
|
254 | protocol = purple_connection_get_protocol(gc); |
|
22390
d22357d5c7ba
Kill off gc->prpl in the core everywhere but connection.c (when the struct
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
22134
diff
changeset
|
255 | |
|
36630
ff356949df25
Refactored the rest of libpurple to use the new protocol API
Ankit Vani <a@nevitus.org>
parents:
36623
diff
changeset
|
256 | if(protocol) |
|
36606
9fe2d65fe1a7
Use the purple_protocol_iface_* API instead of protocol->function()
Ankit Vani <a@nevitus.org>
parents:
36544
diff
changeset
|
257 | purple_protocol_iface_roomlist_expand_category(protocol, list, category); |
| 8113 | 258 | } |
| 259 | ||
|
22134
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
260 | GList * purple_roomlist_get_fields(PurpleRoomlist *list) |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
261 | { |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
262 | return list->fields; |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
263 | } |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
264 | |
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
265 | gpointer purple_roomlist_get_proto_data(PurpleRoomlist *list) |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
266 | { |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
267 | g_return_val_if_fail(list != NULL, NULL); |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
268 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
269 | return list->proto_data; |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
270 | } |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
271 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
272 | void purple_roomlist_set_proto_data(PurpleRoomlist *list, gpointer proto_data) |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
273 | { |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
274 | g_return_if_fail(list != NULL); |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
275 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
276 | list->proto_data = proto_data; |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
277 | } |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
278 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
279 | gpointer purple_roomlist_get_ui_data(PurpleRoomlist *list) |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
280 | { |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
281 | g_return_val_if_fail(list != NULL, NULL); |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
282 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
283 | return list->ui_data; |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
284 | } |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
285 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
286 | void purple_roomlist_set_ui_data(PurpleRoomlist *list, gpointer ui_data) |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
287 | { |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
288 | g_return_if_fail(list != NULL); |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
289 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
290 | list->ui_data = ui_data; |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
291 | } |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
292 | |
| 8113 | 293 | /*@}*/ |
| 294 | ||
| 295 | /**************************************************************************/ | |
| 296 | /** @name Room API */ | |
| 297 | /**************************************************************************/ | |
| 298 | /*@{*/ | |
| 299 | ||
| 15884 | 300 | PurpleRoomlistRoom *purple_roomlist_room_new(PurpleRoomlistRoomType type, const gchar *name, |
| 301 | PurpleRoomlistRoom *parent) | |
| 8113 | 302 | { |
| 15884 | 303 | PurpleRoomlistRoom *room; |
| 8113 | 304 | |
| 305 | g_return_val_if_fail(name != NULL, NULL); | |
| 306 | ||
| 15884 | 307 | room = g_new0(PurpleRoomlistRoom, 1); |
| 8113 | 308 | room->type = type; |
| 309 | room->name = g_strdup(name); | |
| 310 | room->parent = parent; | |
| 311 | ||
| 312 | return room; | |
| 313 | } | |
| 314 | ||
| 15884 | 315 | void purple_roomlist_room_add_field(PurpleRoomlist *list, PurpleRoomlistRoom *room, gconstpointer field) |
| 8113 | 316 | { |
| 15884 | 317 | PurpleRoomlistField *f; |
| 8113 | 318 | |
| 319 | g_return_if_fail(list != NULL); | |
| 320 | g_return_if_fail(room != NULL); | |
| 321 | g_return_if_fail(list->fields != NULL); | |
| 322 | ||
|
24814
9e3c1c3b4123
Add a comment to clarify code I initially thought was broken.
Richard Laager <rlaager@pidgin.im>
parents:
22390
diff
changeset
|
323 | /* If this is the first call for this room, grab the first field in |
|
9e3c1c3b4123
Add a comment to clarify code I initially thought was broken.
Richard Laager <rlaager@pidgin.im>
parents:
22390
diff
changeset
|
324 | * the Roomlist's fields. Otherwise, grab the field that is one |
|
9e3c1c3b4123
Add a comment to clarify code I initially thought was broken.
Richard Laager <rlaager@pidgin.im>
parents:
22390
diff
changeset
|
325 | * more than the number of fields already present for the room. |
|
9e3c1c3b4123
Add a comment to clarify code I initially thought was broken.
Richard Laager <rlaager@pidgin.im>
parents:
22390
diff
changeset
|
326 | * (This works because g_list_nth_data() is zero-indexed and |
|
9e3c1c3b4123
Add a comment to clarify code I initially thought was broken.
Richard Laager <rlaager@pidgin.im>
parents:
22390
diff
changeset
|
327 | * g_list_length() is one-indexed.) */ |
| 8113 | 328 | if (!room->fields) |
| 329 | f = list->fields->data; | |
| 330 | else | |
| 331 | f = g_list_nth_data(list->fields, g_list_length(room->fields)); | |
| 332 | ||
| 333 | g_return_if_fail(f != NULL); | |
| 334 | ||
| 335 | switch(f->type) { | |
| 15884 | 336 | case PURPLE_ROOMLIST_FIELD_STRING: |
| 8113 | 337 | room->fields = g_list_append(room->fields, g_strdup(field)); |
| 338 | break; | |
| 15884 | 339 | case PURPLE_ROOMLIST_FIELD_BOOL: |
| 340 | case PURPLE_ROOMLIST_FIELD_INT: | |
| 8113 | 341 | room->fields = g_list_append(room->fields, GINT_TO_POINTER(field)); |
| 342 | break; | |
| 343 | } | |
| 344 | } | |
| 345 | ||
| 15884 | 346 | void purple_roomlist_room_join(PurpleRoomlist *list, PurpleRoomlistRoom *room) |
| 8199 | 347 | { |
| 348 | GHashTable *components; | |
| 349 | GList *l, *j; | |
| 15884 | 350 | PurpleConnection *gc; |
| 8199 | 351 | |
| 352 | g_return_if_fail(list != NULL); | |
| 353 | g_return_if_fail(room != NULL); | |
| 354 | ||
| 15884 | 355 | gc = purple_account_get_connection(list->account); |
| 8199 | 356 | if (!gc) |
| 357 | return; | |
| 358 | ||
| 359 | components = g_hash_table_new(g_str_hash, g_str_equal); | |
| 360 | ||
| 361 | g_hash_table_replace(components, "name", room->name); | |
| 362 | for (l = list->fields, j = room->fields; l && j; l = l->next, j = j->next) { | |
| 15884 | 363 | PurpleRoomlistField *f = l->data; |
| 8199 | 364 | |
| 365 | g_hash_table_replace(components, f->name, j->data); | |
| 366 | } | |
| 367 | ||
| 368 | serv_join_chat(gc, components); | |
| 369 | ||
| 370 | g_hash_table_destroy(components); | |
| 371 | } | |
| 372 | ||
|
22134
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
373 | PurpleRoomlistRoomType purple_roomlist_room_get_type(PurpleRoomlistRoom *room) |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
374 | { |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
375 | return room->type; |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
376 | } |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
377 | |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
378 | const char * purple_roomlist_room_get_name(PurpleRoomlistRoom *room) |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
379 | { |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
380 | return room->name; |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
381 | } |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
382 | |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
383 | PurpleRoomlistRoom * purple_roomlist_room_get_parent(PurpleRoomlistRoom *room) |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
384 | { |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
385 | return room->parent; |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
386 | } |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
387 | |
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
388 | gboolean purple_roomlist_room_get_expanded_once(PurpleRoomlistRoom *room) |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
389 | { |
|
32237
d5398bd73913
Fix two compile warnings. Did I do that? I totally didn't notice. My bad.
Mark Doliner <markdoliner@pidgin.im>
parents:
32218
diff
changeset
|
390 | g_return_val_if_fail(room != NULL, FALSE); |
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
391 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
392 | return room->expanded_once; |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
393 | } |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
394 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
395 | void purple_roomlist_room_set_expanded_once(PurpleRoomlistRoom *room, gboolean expanded_once) |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
396 | { |
|
32237
d5398bd73913
Fix two compile warnings. Did I do that? I totally didn't notice. My bad.
Mark Doliner <markdoliner@pidgin.im>
parents:
32218
diff
changeset
|
397 | g_return_if_fail(room != NULL); |
|
32218
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
398 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
399 | room->expanded_once = expanded_once; |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
400 | } |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
401 | |
|
f27b05250351
Some struct hiding. What a pain.
Mark Doliner <markdoliner@pidgin.im>
parents:
28981
diff
changeset
|
402 | GList *purple_roomlist_room_get_fields(PurpleRoomlistRoom *room) |
|
22134
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
403 | { |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
404 | return room->fields; |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
405 | } |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
406 | |
| 8113 | 407 | /*@}*/ |
| 408 | ||
| 409 | /**************************************************************************/ | |
| 410 | /** @name Room Field API */ | |
| 411 | /**************************************************************************/ | |
| 412 | /*@{*/ | |
| 413 | ||
| 15884 | 414 | PurpleRoomlistField *purple_roomlist_field_new(PurpleRoomlistFieldType type, |
| 8113 | 415 | const gchar *label, const gchar *name, |
| 416 | gboolean hidden) | |
| 417 | { | |
| 15884 | 418 | PurpleRoomlistField *f; |
| 8113 | 419 | |
| 420 | g_return_val_if_fail(label != NULL, NULL); | |
| 421 | g_return_val_if_fail(name != NULL, NULL); | |
| 422 | ||
| 15884 | 423 | f = g_new0(PurpleRoomlistField, 1); |
| 8113 | 424 | |
| 425 | f->type = type; | |
| 426 | f->label = g_strdup(label); | |
| 427 | f->name = g_strdup(name); | |
| 428 | f->hidden = hidden; | |
| 429 | ||
| 430 | return f; | |
| 431 | } | |
| 432 | ||
|
22134
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
433 | PurpleRoomlistFieldType purple_roomlist_field_get_type(PurpleRoomlistField *field) |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
434 | { |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
435 | return field->type; |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
436 | } |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
437 | |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
438 | const char * purple_roomlist_field_get_label(PurpleRoomlistField *field) |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
439 | { |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
440 | return field->label; |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
441 | } |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
442 | |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
443 | gboolean purple_roomlist_field_get_hidden(PurpleRoomlistField *field) |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
444 | { |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
445 | return field->hidden; |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
446 | } |
|
692ceed9d307
A list of accessor functions to the roomlist API.
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
20147
diff
changeset
|
447 | |
| 8113 | 448 | /*@}*/ |
| 449 | ||
| 450 | /**************************************************************************/ | |
| 451 | /** @name UI Registration Functions */ | |
| 452 | /**************************************************************************/ | |
| 453 | /*@{*/ | |
| 454 | ||
| 455 | ||
| 15884 | 456 | void purple_roomlist_set_ui_ops(PurpleRoomlistUiOps *ui_ops) |
| 8113 | 457 | { |
| 458 | ops = ui_ops; | |
| 459 | } | |
| 460 | ||
| 15884 | 461 | PurpleRoomlistUiOps *purple_roomlist_get_ui_ops(void) |
| 8113 | 462 | { |
| 463 | return ops; | |
| 464 | } | |
| 465 | ||
| 466 | /*@}*/ |