Merged pidgin/main into default
[pidgin-git.git] / libpurple / buddylist.h
bloba3a8e9a2a160121850835f6c162c93cf10c581c4
1 /* purple
3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
5 * source distribution.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #ifndef _PURPLE_BUDDY_LIST_H_
23 #define _PURPLE_BUDDY_LIST_H_
24 /**
25 * SECTION:buddylist
26 * @section_id: libpurple-buddylist
27 * @short_description: <filename>buddylist.h</filename>
28 * @title: Buddy List API
29 * @see_also: <link linkend="chapter-signals-blist">Buddy List signals</link>
32 /* I can't believe I let ChipX86 inspire me to write good code. -Sean */
34 #include "buddy.h"
36 #define PURPLE_TYPE_BUDDY_LIST (purple_buddy_list_get_type())
37 #define PURPLE_BUDDY_LIST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_BUDDY_LIST, PurpleBuddyList))
38 #define PURPLE_BUDDY_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_BUDDY_LIST, PurpleBuddyListClass))
39 #define PURPLE_IS_BUDDY_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_BUDDY_LIST))
40 #define PURPLE_IS_BUDDY_LIST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_BUDDY_LIST))
41 #define PURPLE_BUDDY_LIST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_BUDDY_LIST, PurpleBuddyListClass))
43 typedef struct _PurpleBuddyList PurpleBuddyList;
44 typedef struct _PurpleBuddyListClass PurpleBuddyListClass;
46 #define PURPLE_TYPE_BLIST_UI_OPS (purple_blist_ui_ops_get_type())
48 typedef struct _PurpleBlistUiOps PurpleBlistUiOps;
50 #define PURPLE_BLIST_DEFAULT_GROUP_NAME _("Buddies")
52 #include "chat.h"
54 /**************************************************************************/
55 /* Data Structures */
56 /**************************************************************************/
57 /**
58 * PurpleBuddyList:
59 * @root: The first node in the buddy list
60 * @ui_data: The UI data associated with this buddy list. This is a convenience
61 * field provided to the UIs -- it is not used by the libpurple core.
63 * The Buddy List
65 struct _PurpleBuddyList {
66 GObject gparent;
68 /*< public >*/
69 PurpleBlistNode *root;
70 gpointer ui_data;
73 struct _PurpleBuddyListClass {
74 GObjectClass gparent_class;
76 /*< private >*/
77 void (*_purple_reserved1)(void);
78 void (*_purple_reserved2)(void);
79 void (*_purple_reserved3)(void);
80 void (*_purple_reserved4)(void);
83 /**
84 * PurpleBlistUiOps:
85 * @new_list: Sets UI-specific data on a buddy list.
86 * @new_node: Sets UI-specific data on a node.
87 * @show: The core will call this when it's finished doing its core
88 * stuff
89 * @update: This will update a node in the buddy list.
90 * @remove: This removes a node from the list
91 * @destroy: When the list is destroyed, this is called to destroy the UI.
92 * @set_visible: Hides or unhides the buddy list
93 * @save_node: This is called when a node has been modified and should be
94 * saved.
95 * <sbr/>Implementation of this UI op is
96 * <emphasis>OPTIONAL</emphasis>. If not implemented, it will be
97 * set to a fallback function that saves data to
98 * <filename>blist.xml</filename> like in previous libpurple
99 * versions.
100 * <sbr/>@node: The node which has been modified.
101 * @remove_node: Called when a node is about to be removed from the buddy list.
102 * The UI op should update the relevant data structures to remove
103 * this node (for example, removing a buddy from the group this
104 * node is in).
105 * <sbr/>Implementation of this UI op is
106 * <emphasis>OPTIONAL</emphasis>. If not implemented,
107 * it will be set to a fallback function that saves data to
108 * <filename>blist.xml</filename> like in previous libpurple
109 * versions.
110 * <sbr/>@node: The node which has been modified.
111 * @save_account: Called to save all the data for an account. If the UI sets
112 * this, the callback must save the privacy and buddy list data
113 * for an account. If the account is %NULL, save the data for all
114 * accounts.
115 * <sbr/>Implementation of this UI op is
116 * <emphasis>OPTIONAL</emphasis>. If not implemented, it will be
117 * set to a fallback function that saves data to
118 * <filename>blist.xml</filename> like in previous
119 * libpurple versions.
120 * <sbr/>@account: The account whose data to save. If %NULL,
121 * save all data for all accounts.
123 * Buddy list UI operations.
125 * Any UI representing a buddy list must assign a filled-out PurpleBlistUiOps
126 * structure to the buddy list core.
128 struct _PurpleBlistUiOps
130 void (*new_list)(PurpleBuddyList *list);
131 void (*new_node)(PurpleBlistNode *node);
132 void (*show)(PurpleBuddyList *list);
133 void (*update)(PurpleBuddyList *list, PurpleBlistNode *node);
134 void (*remove)(PurpleBuddyList *list, PurpleBlistNode *node);
135 void (*destroy)(PurpleBuddyList *list);
136 void (*set_visible)(PurpleBuddyList *list, gboolean show);
138 void (*request_add_buddy)(PurpleAccount *account, const char *username,
139 const char *group, const char *alias);
141 void (*request_add_chat)(PurpleAccount *account, PurpleGroup *group,
142 const char *alias, const char *name);
144 void (*request_add_group)(void);
146 void (*save_node)(PurpleBlistNode *node);
147 void (*remove_node)(PurpleBlistNode *node);
149 void (*save_account)(PurpleAccount *account);
151 /*< private >*/
152 void (*_purple_reserved1)(void);
153 void (*_purple_reserved2)(void);
154 void (*_purple_reserved3)(void);
155 void (*_purple_reserved4)(void);
158 G_BEGIN_DECLS
160 /**************************************************************************/
161 /* Buddy List API */
162 /**************************************************************************/
165 * purple_buddy_list_get_type:
167 * Returns: The #GType for the #PurpleBuddyList object.
169 GType purple_buddy_list_get_type(void);
172 * purple_blist_get_buddy_list:
174 * Returns the main buddy list.
176 * Returns: The main buddy list.
178 PurpleBuddyList *purple_blist_get_buddy_list(void);
181 * purple_blist_get_root:
183 * Returns the root node of the main buddy list.
185 * Returns: The root node.
187 PurpleBlistNode *purple_blist_get_root(void);
190 * purple_blist_get_buddies:
192 * Returns a list of every buddy in the list. Use of this function is
193 * discouraged if you do not actually need every buddy in the list. Use
194 * purple_blist_find_buddies instead.
196 * See purple_blist_find_buddies().
198 * Returns: (element-type PurpleBlistNode) (transfer container): A list of every
199 * buddy in the list.
201 GSList *purple_blist_get_buddies(void);
204 * purple_blist_get_ui_data:
206 * Returns the UI data for the list.
208 * Returns: The UI data for the list.
210 gpointer purple_blist_get_ui_data(void);
213 * purple_blist_set_ui_data:
214 * @ui_data: The UI data for the list.
216 * Sets the UI data for the list.
218 void purple_blist_set_ui_data(gpointer ui_data);
221 * purple_blist_show:
223 * Shows the buddy list, creating a new one if necessary.
225 void purple_blist_show(void);
228 * purple_blist_set_visible:
229 * @show: Whether or not to show the buddy list
231 * Hides or unhides the buddy list.
233 void purple_blist_set_visible(gboolean show);
236 * purple_blist_update_buddies_cache:
237 * @buddy: The buddy whose name will be changed.
238 * @new_name: The new name of the buddy.
240 * Updates the buddies hash table when a buddy has been renamed. This only
241 * updates the cache, the caller is responsible for the actual renaming of
242 * the buddy after updating the cache.
244 void purple_blist_update_buddies_cache(PurpleBuddy *buddy, const char *new_name);
247 * purple_blist_update_groups_cache:
248 * @group: The group whose name will be changed.
249 * @new_name: The new name of the group.
251 * Updates the groups hash table when a group has been renamed. This only
252 * updates the cache, the caller is responsible for the actual renaming of
253 * the group after updating the cache.
255 void purple_blist_update_groups_cache(PurpleGroup *group, const char *new_name);
258 * purple_blist_add_chat:
259 * @chat: The new chat who gets added
260 * @group: The group to add the new chat to.
261 * @node: The insertion point
263 * Adds a new chat to the buddy list.
265 * The chat will be inserted right after node or appended to the end
266 * of group if node is NULL. If both are NULL, the buddy will be added to
267 * the "Chats" group.
269 void purple_blist_add_chat(PurpleChat *chat, PurpleGroup *group, PurpleBlistNode *node);
272 * purple_blist_add_buddy:
273 * @buddy: The new buddy who gets added
274 * @contact: The optional contact to place the buddy in.
275 * @group: The group to add the new buddy to.
276 * @node: The insertion point. Pass in NULL to add the node as
277 * the first child in the given group.
279 * Adds a new buddy to the buddy list.
281 * The buddy will be inserted right after node or prepended to the
282 * group if node is NULL. If both are NULL, the buddy will be added to
283 * the default group.
285 void purple_blist_add_buddy(PurpleBuddy *buddy, PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node);
288 * purple_blist_add_group:
289 * @group: The group
290 * @node: The insertion point
292 * Adds a new group to the buddy list.
294 * The new group will be inserted after insert or prepended to the list if
295 * node is NULL.
297 void purple_blist_add_group(PurpleGroup *group, PurpleBlistNode *node);
300 * purple_blist_add_contact:
301 * @contact: The contact
302 * @group: The group to add the contact to
303 * @node: The insertion point
305 * Adds a new contact to the buddy list.
307 * The new contact will be inserted after insert or prepended to the list if
308 * node is NULL.
310 void purple_blist_add_contact(PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node);
313 * purple_blist_remove_buddy:
314 * @buddy: The buddy to be removed
316 * Removes a buddy from the buddy list and frees the memory allocated to it.
317 * This doesn't actually try to remove the buddy from the server list.
319 * See purple_account_remove_buddy().
321 void purple_blist_remove_buddy(PurpleBuddy *buddy);
324 * purple_blist_remove_contact:
325 * @contact: The contact to be removed
327 * Removes a contact, and any buddies it contains, and frees the memory
328 * allocated to it. This calls purple_blist_remove_buddy and therefore
329 * doesn't remove the buddies from the server list.
331 * See purple_blist_remove_buddy().
333 void purple_blist_remove_contact(PurpleContact *contact);
336 * purple_blist_remove_chat:
337 * @chat: The chat to be removed
339 * Removes a chat from the buddy list and frees the memory allocated to it.
341 void purple_blist_remove_chat(PurpleChat *chat);
344 * purple_blist_remove_group:
345 * @group: The group to be removed
347 * Removes a group from the buddy list and frees the memory allocated to it and to
348 * its children
350 void purple_blist_remove_group(PurpleGroup *group);
353 * purple_blist_find_buddy:
354 * @account: The account this buddy belongs to
355 * @name: The buddy's name
357 * Finds the buddy struct given a name and an account
359 * Returns: The buddy or NULL if the buddy does not exist
361 PurpleBuddy *purple_blist_find_buddy(PurpleAccount *account, const char *name);
364 * purple_blist_find_buddy_in_group:
365 * @account: The account this buddy belongs to
366 * @name: The buddy's name
367 * @group: The group to look in
369 * Finds the buddy struct given a name, an account, and a group
371 * Returns: The buddy or NULL if the buddy does not exist in the group
373 PurpleBuddy *purple_blist_find_buddy_in_group(PurpleAccount *account, const char *name,
374 PurpleGroup *group);
377 * purple_blist_find_buddies:
378 * @account: The account this buddy belongs to
379 * @name: The buddy's name (or NULL to return all buddies for the account)
381 * Finds all PurpleBuddy structs given a name and an account
383 * Returns: (element-type PurpleBuddy) (transfer container): %NULL if the buddy
384 * doesn't exist, or a GSList of PurpleBuddy structs.
386 GSList *purple_blist_find_buddies(PurpleAccount *account, const char *name);
389 * purple_blist_find_group:
390 * @name: The group's name
392 * Finds a group by name
394 * Returns: The group or NULL if the group does not exist
396 PurpleGroup *purple_blist_find_group(const char *name);
399 * purple_blist_get_default_group:
401 * Finds or creates default group.
403 * Returns: The default group.
405 PurpleGroup *purple_blist_get_default_group(void);
408 * purple_blist_find_chat:
409 * @account: The chat's account.
410 * @name: The chat's name.
412 * Finds a chat by name.
414 * Returns: The chat, or %NULL if the chat does not exist.
416 PurpleChat *purple_blist_find_chat(PurpleAccount *account, const char *name);
419 * purple_blist_add_account:
420 * @account: The account
422 * Called when an account connects. Tells the UI to update all the
423 * buddies.
425 void purple_blist_add_account(PurpleAccount *account);
428 * purple_blist_remove_account:
429 * @account: The account
431 * Called when an account disconnects. Sets the presence of all the buddies to 0
432 * and tells the UI to update them.
434 void purple_blist_remove_account(PurpleAccount *account);
436 /****************************************************************************************/
437 /* Buddy list file management API */
438 /****************************************************************************************/
441 * purple_blist_schedule_save:
443 * Schedule a save of the <filename>blist.xml</filename> file. This is used by
444 * the account API whenever the privacy settings are changed. If you make a
445 * change to <filename>blist.xml</filename> using one of the functions in the
446 * buddy list API, then the buddy list is saved automatically, so you should not
447 * need to call this.
449 void purple_blist_schedule_save(void);
452 * purple_blist_request_add_buddy:
453 * @account: The account the buddy is added to.
454 * @username: The username of the buddy.
455 * @group: The name of the group to place the buddy in.
456 * @alias: The optional alias for the buddy.
458 * Requests from the user information needed to add a buddy to the
459 * buddy list.
461 void purple_blist_request_add_buddy(PurpleAccount *account, const char *username,
462 const char *group, const char *alias);
465 * purple_blist_request_add_chat:
466 * @account: The account the buddy is added to.
467 * @group: The optional group to add the chat to.
468 * @alias: The optional alias for the chat.
469 * @name: The required chat name.
471 * Requests from the user information needed to add a chat to the
472 * buddy list.
474 void purple_blist_request_add_chat(PurpleAccount *account, PurpleGroup *group,
475 const char *alias, const char *name);
478 * purple_blist_request_add_group:
480 * Requests from the user information needed to add a group to the
481 * buddy list.
483 void purple_blist_request_add_group(void);
485 /**************************************************************************/
486 /* UI Registration Functions */
487 /**************************************************************************/
490 * purple_blist_ui_ops_get_type:
492 * Returns: The #GType for the #PurpleBlistUiOps boxed structure.
494 GType purple_blist_ui_ops_get_type(void);
497 * purple_blist_set_ui_ops:
498 * @ops: The ops struct.
500 * Sets the UI operations structure to be used for the buddy list.
502 void purple_blist_set_ui_ops(PurpleBlistUiOps *ops);
505 * purple_blist_get_ui_ops:
507 * Returns the UI operations structure to be used for the buddy list.
509 * Returns: The UI operations structure.
511 PurpleBlistUiOps *purple_blist_get_ui_ops(void);
513 /**************************************************************************/
514 /* Buddy List Subsystem */
515 /**************************************************************************/
518 * purple_blist_get_handle:
520 * Returns the handle for the buddy list subsystem.
522 * Returns: The buddy list subsystem handle.
524 void *purple_blist_get_handle(void);
527 * purple_blist_init:
529 * Initializes the buddy list subsystem.
531 void purple_blist_init(void);
534 * purple_blist_boot:
536 * Loads the buddy list.
538 * You shouldn't call this. purple_core_init() will do it for you.
540 void purple_blist_boot(void);
543 * purple_blist_uninit:
545 * Uninitializes the buddy list subsystem.
547 void purple_blist_uninit(void);
549 G_END_DECLS
551 #endif /* _PURPLE_BUDDY_LIST_H_ */