2 * @file blist.h Buddy List API
4 * @see @ref blist-signals
9 * Purple is the legal property of its developers, whose names are too numerous
10 * to list here. Please refer to the COPYRIGHT file distributed with this
11 * source distribution.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
27 #ifndef _PURPLE_BLIST_H_
28 #define _PURPLE_BLIST_H_
30 /* I can't believe I let ChipX86 inspire me to write good code. -Sean */
34 /** @copydoc _PurpleBuddyList */
35 typedef struct _PurpleBuddyList PurpleBuddyList;
36 /** @copydoc _PurpleBlistUiOps */
37 typedef struct _PurpleBlistUiOps PurpleBlistUiOps;
38 /** @copydoc _PurpleBlistNode */
39 typedef struct _PurpleBlistNode PurpleBlistNode;
41 /** @copydoc _PurpleChat */
42 typedef struct _PurpleChat PurpleChat;
43 /** @copydoc _PurpleGroup */
44 typedef struct _PurpleGroup PurpleGroup;
45 /** @copydoc _PurpleContact */
46 typedef struct _PurpleContact PurpleContact;
47 /** @copydoc _PurpleBuddy */
48 typedef struct _PurpleBuddy PurpleBuddy;
50 /**************************************************************************/
52 /**************************************************************************/
55 PURPLE_BLIST_GROUP_NODE,
56 PURPLE_BLIST_CONTACT_NODE,
57 PURPLE_BLIST_BUDDY_NODE,
58 PURPLE_BLIST_CHAT_NODE,
59 PURPLE_BLIST_OTHER_NODE
61 } PurpleBlistNodeType;
63 #define PURPLE_BLIST_NODE_IS_CHAT(n) (purple_blist_node_get_type(n) == PURPLE_BLIST_CHAT_NODE)
64 #define PURPLE_BLIST_NODE_IS_BUDDY(n) (purple_blist_node_get_type(n) == PURPLE_BLIST_BUDDY_NODE)
65 #define PURPLE_BLIST_NODE_IS_CONTACT(n) (purple_blist_node_get_type(n) == PURPLE_BLIST_CONTACT_NODE)
66 #define PURPLE_BLIST_NODE_IS_GROUP(n) (purple_blist_node_get_type(n) == PURPLE_BLIST_GROUP_NODE)
68 #define PURPLE_BUDDY_IS_ONLINE(b) \
69 ((b) != NULL && purple_account_is_connected(purple_buddy_get_account(b)) && \
70 purple_presence_is_online(purple_buddy_get_presence(b)))
74 PURPLE_BLIST_NODE_FLAG_NO_SAVE = 1 << 0 /**< node should not be saved with the buddy list */
76 } PurpleBlistNodeFlags;
81 #define PURPLE_BLIST_NODE(obj) ((PurpleBlistNode *)(obj))
83 #define PURPLE_BLIST_NODE_HAS_FLAG(b, f) (purple_blist_node_get_flags((PurpleBlistNode*)(b)) & (f))
84 #define PURPLE_BLIST_NODE_SHOULD_SAVE(b) (! PURPLE_BLIST_NODE_HAS_FLAG(b, PURPLE_BLIST_NODE_FLAG_NO_SAVE))
86 #define PURPLE_BLIST_NODE_NAME(n) (purple_blist_node_get_type(n) == PURPLE_BLIST_CHAT_NODE ? purple_chat_get_name((PurpleChat*)n) : \
87 purple_blist_node_get_type(n) == PURPLE_BLIST_BUDDY_NODE ? purple_buddy_get_name((PurpleBuddy*)n) : NULL)
92 #define PURPLE_GROUP(obj) ((PurpleGroup *)(obj))
97 #define PURPLE_CONTACT(obj) ((PurpleContact *)(obj))
102 #define PURPLE_BUDDY(obj) ((PurpleBuddy *)(obj))
107 #define PURPLE_CHAT(obj) ((PurpleChat *)(obj))
110 #include "buddyicon.h"
113 /**************************************************************************/
114 /* Data Structures */
115 /**************************************************************************/
117 #if !(defined PURPLE_HIDE_STRUCTS) || (defined _PURPLE_BLIST_C_)
120 * A Buddy list node. This can represent a group, a buddy, or anything else.
121 * This is a base class for PurpleBuddy, PurpleContact, PurpleGroup, and for
122 * anything else that wants to put itself in the buddy list. */
123 struct _PurpleBlistNode {
124 PurpleBlistNodeType type; /**< The type of node this is */
125 PurpleBlistNode *prev; /**< The sibling before this buddy. */
126 PurpleBlistNode *next; /**< The sibling after this buddy. */
127 PurpleBlistNode *parent; /**< The parent of this node */
128 PurpleBlistNode *child; /**< The child of this node */
129 GHashTable *settings; /**< per-node settings */
130 void *ui_data; /**< The UI can put data here. */
131 PurpleBlistNodeFlags flags; /**< The buddy flags */
135 * A buddy. This contains everything Purple will ever need to know about someone on the buddy list. Everything.
137 struct _PurpleBuddy {
138 PurpleBlistNode node; /**< The node that this buddy inherits from */
139 char *name; /**< The name of the buddy. */
140 char *alias; /**< The user-set alias of the buddy */
141 char *server_alias; /**< The server-specified alias of the buddy. (i.e. MSN "Friendly Names") */
142 void *proto_data; /**< This allows the prpl to associate whatever data it wants with a buddy */
143 PurpleBuddyIcon *icon; /**< The buddy icon. */
144 PurpleAccount *account; /**< the account this buddy belongs to */
145 PurplePresence *presence;
149 * A contact. This contains everything Purple will ever need to know about a contact.
151 struct _PurpleContact {
152 PurpleBlistNode node; /**< The node that this contact inherits from. */
153 char *alias; /**< The user-set alias of the contact */
154 int totalsize; /**< The number of buddies in this contact */
155 int currentsize; /**< The number of buddies in this contact corresponding to online accounts */
156 int online; /**< The number of buddies in this contact who are currently online */
157 PurpleBuddy *priority; /**< The "top" buddy for this contact */
158 gboolean priority_valid; /**< Is priority valid? */
163 * A group. This contains everything Purple will ever need to know about a group.
165 struct _PurpleGroup {
166 PurpleBlistNode node; /**< The node that this group inherits from */
167 char *name; /**< The name of this group. */
168 int totalsize; /**< The number of chats and contacts in this group */
169 int currentsize; /**< The number of chats and contacts in this group corresponding to online accounts */
170 int online; /**< The number of chats and contacts in this group who are currently online */
174 * A chat. This contains everything Purple needs to put a chat room in the
178 PurpleBlistNode node; /**< The node that this chat inherits from */
179 char *alias; /**< The display name of this chat. */
180 GHashTable *components; /**< the stuff the protocol needs to know to join the chat */
181 PurpleAccount *account; /**< The account this chat is attached to */
187 struct _PurpleBuddyList {
188 PurpleBlistNode *root; /**< The first node in the buddy list */
189 GHashTable *buddies; /**< Every buddy in this list */
190 void *ui_data; /**< UI-specific data. */
193 #endif /* PURPLE_HIDE_STRUCTS && PURPLE_BLIST_STRUCTS */
196 * Buddy list UI operations.
198 * Any UI representing a buddy list must assign a filled-out PurpleBlistUiOps
199 * structure to the buddy list core.
201 struct _PurpleBlistUiOps
203 void (*new_list)(PurpleBuddyList *list); /**< Sets UI-specific data on a buddy list. */
204 void (*new_node)(PurpleBlistNode *node); /**< Sets UI-specific data on a node. */
205 void (*show)(PurpleBuddyList *list); /**< The core will call this when it's finished doing its core stuff */
206 void (*update)(PurpleBuddyList *list,
207 PurpleBlistNode *node); /**< This will update a node in the buddy list. */
208 void (*remove)(PurpleBuddyList *list,
209 PurpleBlistNode *node); /**< This removes a node from the list */
210 void (*destroy)(PurpleBuddyList *list); /**< When the list is destroyed, this is called to destroy the UI. */
211 void (*set_visible)(PurpleBuddyList *list,
212 gboolean show); /**< Hides or unhides the buddy list */
213 void (*request_add_buddy)(PurpleAccount *account, const char *username,
214 const char *group, const char *alias);
215 void (*request_add_chat)(PurpleAccount *account, PurpleGroup *group,
216 const char *alias, const char *name);
217 void (*request_add_group)(void);
220 * This is called when a node has been modified and should be saved.
222 * Implementation of this UI op is OPTIONAL. If not implemented, it will
223 * be set to a fallback function that saves data to blist.xml like in
224 * previous libpurple versions.
226 * @attrib node The node which has been modified.
230 void (*save_node)(PurpleBlistNode *node);
233 * Called when a node is about to be removed from the buddy list.
234 * The UI op should update the relevant data structures to remove this
235 * node (for example, removing a buddy from the group this node is in).
237 * Implementation of this UI op is OPTIONAL. If not implemented, it will
238 * be set to a fallback function that saves data to blist.xml like in
239 * previous libpurple versions.
241 * @attrib node The node which has been modified.
244 void (*remove_node)(PurpleBlistNode *node);
247 * Called to save all the data for an account. If the UI sets this,
248 * the callback must save the privacy and buddy list data for an account.
249 * If the account is NULL, save the data for all accounts.
251 * Implementation of this UI op is OPTIONAL. If not implemented, it will
252 * be set to a fallback function that saves data to blist.xml like in
253 * previous libpurple versions.
255 * @attrib account The account whose data to save. If NULL, save all data
259 void (*save_account)(PurpleAccount *account);
261 void (*_purple_reserved1)(void);
268 /**************************************************************************/
269 /** @name Buddy List API */
270 /**************************************************************************/
274 * Creates a new buddy list
276 * @return The new buddy list.
277 * @deprecated In 3.0.0, this will be handled by purple_blist_init()
279 PurpleBuddyList *purple_blist_new(void);
282 * Sets the main buddy list.
284 * @param blist The buddy list you want to use.
285 * @deprecated In 3.0.0, this will be handled by purple_blist_init()
287 void purple_set_blist(PurpleBuddyList *blist);
290 * Returns the main buddy list.
292 * @return The main buddy list.
294 PurpleBuddyList *purple_get_blist(void);
297 * Returns the root node of the main buddy list.
299 * @return The root node.
301 PurpleBlistNode *purple_blist_get_root(void);
304 * Returns a list of every buddy in the list. Use of this function is
305 * discouraged if you do not actually need every buddy in the list. Use
306 * purple_find_buddies instead.
308 * @return A list of every buddy in the list. Caller is responsible for
311 * @see purple_find_buddies
314 GSList *purple_blist_get_buddies(void);
317 * Returns the UI data for the list.
319 * @return The UI data for the list.
323 gpointer purple_blist_get_ui_data(void);
326 * Sets the UI data for the list.
328 * @param ui_data The UI data for the list.
332 void purple_blist_set_ui_data(gpointer ui_data);
335 * Returns the next node of a given node. This function is to be used to iterate
336 * over the tree returned by purple_get_blist.
338 * @param node A node.
339 * @param offline Whether to include nodes for offline accounts
340 * @return The next node
341 * @see purple_blist_node_get_parent
342 * @see purple_blist_node_get_first_child
343 * @see purple_blist_node_get_sibling_next
344 * @see purple_blist_node_get_sibling_prev
346 PurpleBlistNode *purple_blist_node_next(PurpleBlistNode *node, gboolean offline);
349 * Returns the parent node of a given node.
351 * @param node A node.
352 * @return The parent node.
354 * @see purple_blist_node_get_first_child
355 * @see purple_blist_node_get_sibling_next
356 * @see purple_blist_node_get_sibling_prev
357 * @see purple_blist_node_next
359 PurpleBlistNode *purple_blist_node_get_parent(PurpleBlistNode *node);
362 * Returns the the first child node of a given node.
364 * @param node A node.
365 * @return The child node.
367 * @see purple_blist_node_get_parent
368 * @see purple_blist_node_get_sibling_next
369 * @see purple_blist_node_get_sibling_prev
370 * @see purple_blist_node_next
372 PurpleBlistNode *purple_blist_node_get_first_child(PurpleBlistNode *node);
375 * Returns the sibling node of a given node.
377 * @param node A node.
378 * @return The sibling node.
380 * @see purple_blist_node_get_parent
381 * @see purple_blist_node_get_first_child
382 * @see purple_blist_node_get_sibling_prev
383 * @see purple_blist_node_next
385 PurpleBlistNode *purple_blist_node_get_sibling_next(PurpleBlistNode *node);
388 * Returns the previous sibling node of a given node.
390 * @param node A node.
391 * @return The sibling node.
393 * @see purple_blist_node_get_parent
394 * @see purple_blist_node_get_first_child
395 * @see purple_blist_node_get_sibling_next
396 * @see purple_blist_node_next
398 PurpleBlistNode *purple_blist_node_get_sibling_prev(PurpleBlistNode *node);
401 * Returns the UI data of a given node.
403 * @param node The node.
404 * @return The UI data.
407 gpointer purple_blist_node_get_ui_data(const PurpleBlistNode *node);
410 * Sets the UI data of a given node.
412 * @param node The node.
413 * @param ui_data The UI data.
417 void purple_blist_node_set_ui_data(PurpleBlistNode *node, gpointer ui_data);
420 * Shows the buddy list, creating a new one if necessary.
422 void purple_blist_show(void);
426 * Destroys the buddy list window.
428 * @deprecated The UI is responsible for cleaning up the
429 * PurpleBuddyList->ui_data. purple_blist_uninit() will free the
430 * PurpleBuddyList* itself.
432 void purple_blist_destroy(void);
435 * Hides or unhides the buddy list.
437 * @param show Whether or not to show the buddy list
439 void purple_blist_set_visible(gboolean show);
442 * Updates a buddy's status.
444 * This should only be called from within Purple.
446 * @param buddy The buddy whose status has changed.
447 * @param old_status The status from which we are changing.
449 void purple_blist_update_buddy_status(PurpleBuddy *buddy, PurpleStatus *old_status);
452 * Updates a node's custom icon.
454 * @param node The PurpleBlistNode whose custom icon has changed.
458 void purple_blist_update_node_icon(PurpleBlistNode *node);
460 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_BLIST_C_)
462 * Updates a buddy's icon.
464 * @param buddy The buddy whose buddy icon has changed
465 * @deprecated Use purple_blist_update_node_icon() instead.
467 void purple_blist_update_buddy_icon(PurpleBuddy *buddy);
471 * Renames a buddy in the buddy list.
473 * @param buddy The buddy whose name will be changed.
474 * @param name The new name of the buddy.
476 void purple_blist_rename_buddy(PurpleBuddy *buddy, const char *name);
479 * Aliases a contact in the buddy list.
481 * @param contact The contact whose alias will be changed.
482 * @param alias The contact's alias.
484 void purple_blist_alias_contact(PurpleContact *contact, const char *alias);
487 * Aliases a buddy in the buddy list.
489 * @param buddy The buddy whose alias will be changed.
490 * @param alias The buddy's alias.
492 void purple_blist_alias_buddy(PurpleBuddy *buddy, const char *alias);
495 * Sets the server-sent alias of a buddy in the buddy list.
496 * PRPLs should call serv_got_alias() instead of this.
498 * @param buddy The buddy whose alias will be changed.
499 * @param alias The buddy's "official" alias.
501 void purple_blist_server_alias_buddy(PurpleBuddy *buddy, const char *alias);
504 * Aliases a chat in the buddy list.
506 * @param chat The chat whose alias will be changed.
507 * @param alias The chat's new alias.
509 void purple_blist_alias_chat(PurpleChat *chat, const char *alias);
514 * @param group The group to rename
515 * @param name The new name
517 void purple_blist_rename_group(PurpleGroup *group, const char *name);
520 * Creates a new chat for the buddy list
522 * @param account The account this chat will get added to
523 * @param alias The alias of the new chat
524 * @param components The info the prpl needs to join the chat. The
525 * hash function should be g_str_hash() and the
526 * equal function should be g_str_equal().
527 * @return A newly allocated chat
529 PurpleChat *purple_chat_new(PurpleAccount *account, const char *alias, GHashTable *components);
534 * @param chat The chat to destroy
536 void purple_chat_destroy(PurpleChat *chat);
539 * Adds a new chat to the buddy list.
541 * The chat will be inserted right after node or appended to the end
542 * of group if node is NULL. If both are NULL, the buddy will be added to
545 * @param chat The new chat who gets added
546 * @param group The group to add the new chat to.
547 * @param node The insertion point
549 void purple_blist_add_chat(PurpleChat *chat, PurpleGroup *group, PurpleBlistNode *node);
552 * Creates a new buddy.
554 * This function only creates the PurpleBuddy. Use purple_blist_add_buddy
555 * to add the buddy to the list and purple_account_add_buddy to sync up
558 * @param account The account this buddy will get added to
559 * @param name The name of the new buddy
560 * @param alias The alias of the new buddy (or NULL if unaliased)
561 * @return A newly allocated buddy
563 * @see purple_account_add_buddy
564 * @see purple_blist_add_buddy
566 PurpleBuddy *purple_buddy_new(PurpleAccount *account, const char *name, const char *alias);
571 * @param buddy The buddy to destroy
573 void purple_buddy_destroy(PurpleBuddy *buddy);
576 * Sets a buddy's icon.
578 * This should only be called from within Purple. You probably want to
579 * call purple_buddy_icon_set_data().
581 * @param buddy The buddy.
582 * @param icon The buddy icon.
584 * @see purple_buddy_icon_set_data()
586 void purple_buddy_set_icon(PurpleBuddy *buddy, PurpleBuddyIcon *icon);
589 * Returns a buddy's account.
591 * @param buddy The buddy.
593 * @return The account
595 PurpleAccount *purple_buddy_get_account(const PurpleBuddy *buddy);
598 * Returns a buddy's name
600 * @param buddy The buddy.
604 const char *purple_buddy_get_name(const PurpleBuddy *buddy);
607 * Returns a buddy's icon.
609 * @param buddy The buddy.
611 * @return The buddy icon.
613 PurpleBuddyIcon *purple_buddy_get_icon(const PurpleBuddy *buddy);
616 * Returns a buddy's protocol-specific data.
618 * This should only be called from the associated prpl.
620 * @param buddy The buddy.
621 * @return The protocol data.
623 * @see purple_buddy_set_protocol_data()
626 gpointer purple_buddy_get_protocol_data(const PurpleBuddy *buddy);
629 * Sets a buddy's protocol-specific data.
631 * This should only be called from the associated prpl.
633 * @param buddy The buddy.
634 * @param data The data.
636 * @see purple_buddy_get_protocol_data()
639 void purple_buddy_set_protocol_data(PurpleBuddy *buddy, gpointer data);
642 * Returns a buddy's contact.
644 * @param buddy The buddy.
646 * @return The buddy's contact.
648 PurpleContact *purple_buddy_get_contact(PurpleBuddy *buddy);
651 * Returns a buddy's presence.
653 * @param buddy The buddy.
655 * @return The buddy's presence.
657 PurplePresence *purple_buddy_get_presence(const PurpleBuddy *buddy);
660 * Adds a new buddy to the buddy list.
662 * The buddy will be inserted right after node or prepended to the
663 * group if node is NULL. If both are NULL, the buddy will be added to
664 * the "Buddies" group.
666 * @param buddy The new buddy who gets added
667 * @param contact The optional contact to place the buddy in.
668 * @param group The group to add the new buddy to.
669 * @param node The insertion point. Pass in NULL to add the node as
670 * the first child in the given group.
672 void purple_blist_add_buddy(PurpleBuddy *buddy, PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node);
675 * Creates a new group
677 * You can't have more than one group with the same name. Sorry. If you pass
678 * this the name of a group that already exists, it will return that group.
680 * @param name The name of the new group
681 * @return A new group struct
683 PurpleGroup *purple_group_new(const char *name);
688 * @param group The group to destroy
690 void purple_group_destroy(PurpleGroup *group);
693 * Adds a new group to the buddy list.
695 * The new group will be inserted after insert or prepended to the list if
698 * @param group The group
699 * @param node The insertion point
701 void purple_blist_add_group(PurpleGroup *group, PurpleBlistNode *node);
704 * Creates a new contact
706 * @return A new contact struct
708 PurpleContact *purple_contact_new(void);
713 * @param contact The contact to destroy
715 void purple_contact_destroy(PurpleContact *contact);
718 * Adds a new contact to the buddy list.
720 * The new contact will be inserted after insert or prepended to the list if
723 * @param contact The contact
724 * @param group The group to add the contact to
725 * @param node The insertion point
727 void purple_blist_add_contact(PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node);
730 * Merges two contacts
732 * All of the buddies from source will be moved to target
734 * @param source The contact to merge
735 * @param node The place to merge to (a buddy or contact)
737 void purple_blist_merge_contact(PurpleContact *source, PurpleBlistNode *node);
740 * Returns the highest priority buddy for a given contact.
742 * @param contact The contact
743 * @return The highest priority buddy
745 PurpleBuddy *purple_contact_get_priority_buddy(PurpleContact *contact);
747 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_BLIST_C_)
749 * Sets the alias for a contact.
751 * @param contact The contact
752 * @param alias The alias to set, or NULL to unset
754 * @deprecated Use purple_blist_alias_contact() instead.
756 void purple_contact_set_alias(PurpleContact *contact, const char *alias);
760 * Gets the alias for a contact.
762 * @param contact The contact
763 * @return The alias, or NULL if it is not set.
765 const char *purple_contact_get_alias(PurpleContact *contact);
768 * Determines whether an account owns any buddies in a given contact
770 * @param contact The contact to search through.
771 * @param account The account.
773 * @return TRUE if there are any buddies from account in the contact, or FALSE otherwise.
775 gboolean purple_contact_on_account(PurpleContact *contact, PurpleAccount *account);
778 * Invalidates the priority buddy so that the next call to
779 * purple_contact_get_priority_buddy recomputes it.
781 * @param contact The contact
783 void purple_contact_invalidate_priority_buddy(PurpleContact *contact);
786 * Removes a buddy from the buddy list and frees the memory allocated to it.
787 * This doesn't actually try to remove the buddy from the server list.
789 * @param buddy The buddy to be removed
791 * @see purple_account_remove_buddy
793 void purple_blist_remove_buddy(PurpleBuddy *buddy);
796 * Removes a contact, and any buddies it contains, and frees the memory
797 * allocated to it. This calls purple_blist_remove_buddy and therefore
798 * doesn't remove the buddies from the server list.
800 * @param contact The contact to be removed
802 * @see purple_blist_remove_buddy
804 void purple_blist_remove_contact(PurpleContact *contact);
807 * Removes a chat from the buddy list and frees the memory allocated to it.
809 * @param chat The chat to be removed
811 void purple_blist_remove_chat(PurpleChat *chat);
814 * Removes a group from the buddy list and frees the memory allocated to it and to
817 * @param group The group to be removed
819 void purple_blist_remove_group(PurpleGroup *group);
822 * Returns the alias of a buddy.
824 * @param buddy The buddy whose name will be returned.
825 * @return The alias (if set), server alias (if set),
828 const char *purple_buddy_get_alias_only(PurpleBuddy *buddy);
831 * Gets the server alias for a buddy.
833 * @param buddy The buddy whose name will be returned
834 * @return The server alias, or NULL if it is not set.
836 const char *purple_buddy_get_server_alias(PurpleBuddy *buddy);
839 * Returns the correct name to display for a buddy, taking the contact alias
840 * into account. In order of precedence: the buddy's alias; the buddy's
841 * contact alias; the buddy's server alias; the buddy's user name.
843 * @param buddy The buddy whose name will be returned
844 * @return The appropriate name or alias, or NULL.
847 const char *purple_buddy_get_contact_alias(PurpleBuddy *buddy);
849 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_BLIST_C_)
851 * Returns the correct alias for this user, ignoring server aliases. Used
852 * when a user-recognizable name is required. In order: buddy's alias; buddy's
853 * contact alias; buddy's user name.
855 * @param buddy The buddy whose alias will be returned.
856 * @return The appropriate name or alias.
857 * @deprecated Try purple_buddy_get_alias(), if server aliases are okay.
859 const char *purple_buddy_get_local_alias(PurpleBuddy *buddy);
863 * Returns the correct name to display for a buddy. In order of precedence:
864 * the buddy's alias; the buddy's server alias; the buddy's contact alias;
865 * the buddy's user name.
867 * @param buddy The buddy whose name will be returned.
868 * @return The appropriate name or alias, or NULL
870 const char *purple_buddy_get_alias(PurpleBuddy *buddy);
873 * Returns the local alias for the buddy, or @c NULL if none exists.
875 * @param buddy The buddy
876 * @return The local alias for the buddy
880 const char *purple_buddy_get_local_buddy_alias(PurpleBuddy *buddy);
883 * Returns the correct name to display for a blist chat.
885 * @param chat The chat whose name will be returned.
886 * @return The alias (if set), or first component value.
888 const char *purple_chat_get_name(PurpleChat *chat);
891 * Finds the buddy struct given a name and an account
893 * @param account The account this buddy belongs to
894 * @param name The buddy's name
895 * @return The buddy or NULL if the buddy does not exist
897 PurpleBuddy *purple_find_buddy(PurpleAccount *account, const char *name);
900 * Finds the buddy struct given a name, an account, and a group
902 * @param account The account this buddy belongs to
903 * @param name The buddy's name
904 * @param group The group to look in
905 * @return The buddy or NULL if the buddy does not exist in the group
907 PurpleBuddy *purple_find_buddy_in_group(PurpleAccount *account, const char *name,
911 * Finds all PurpleBuddy structs given a name and an account
913 * @param account The account this buddy belongs to
914 * @param name The buddy's name (or NULL to return all buddies for the account)
916 * @return A GSList of buddies (which must be freed), or NULL if the buddy doesn't exist
918 GSList *purple_find_buddies(PurpleAccount *account, const char *name);
922 * Finds a group by name
924 * @param name The group's name
925 * @return The group or NULL if the group does not exist
927 PurpleGroup *purple_find_group(const char *name);
930 * Finds a chat by name.
932 * @param account The chat's account.
933 * @param name The chat's name.
935 * @return The chat, or @c NULL if the chat does not exist.
937 PurpleChat *purple_blist_find_chat(PurpleAccount *account, const char *name);
940 * Returns the group of which the chat is a member.
942 * @param chat The chat.
944 * @return The parent group, or @c NULL if the chat is not in a group.
946 PurpleGroup *purple_chat_get_group(PurpleChat *chat);
949 * Returns the account the chat belongs to.
951 * @param chat The chat.
953 * @return The account the chat belongs to.
957 PurpleAccount *purple_chat_get_account(PurpleChat *chat);
960 * Get a hashtable containing information about a chat.
962 * @param chat The chat.
964 * @constreturn The hashtable.
968 GHashTable *purple_chat_get_components(PurpleChat *chat);
971 * Returns the group of which the buddy is a member.
973 * @param buddy The buddy
974 * @return The group or NULL if the buddy is not in a group
976 PurpleGroup *purple_buddy_get_group(PurpleBuddy *buddy);
980 * Returns a list of accounts that have buddies in this group
984 * @return A GSList of accounts (which must be freed), or NULL if the group
987 GSList *purple_group_get_accounts(PurpleGroup *g);
990 * Determines whether an account owns any buddies in a given group
992 * @param g The group to search through.
993 * @param account The account.
995 * @return TRUE if there are any buddies in the group, or FALSE otherwise.
997 gboolean purple_group_on_account(PurpleGroup *g, PurpleAccount *account);
1000 * Returns the name of a group.
1002 * @param group The group.
1004 * @return The name of the group.
1006 const char *purple_group_get_name(PurpleGroup *group);
1009 * Called when an account connects. Tells the UI to update all the
1012 * @param account The account
1014 void purple_blist_add_account(PurpleAccount *account);
1018 * Called when an account disconnects. Sets the presence of all the buddies to 0
1019 * and tells the UI to update them.
1021 * @param account The account
1023 void purple_blist_remove_account(PurpleAccount *account);
1027 * Determines the total size of a group
1029 * @param group The group
1030 * @param offline Count buddies in offline accounts
1031 * @return The number of buddies in the group
1033 int purple_blist_get_group_size(PurpleGroup *group, gboolean offline);
1036 * Determines the number of online buddies in a group
1038 * @param group The group
1039 * @return The number of online buddies in the group, or 0 if the group is NULL
1041 int purple_blist_get_group_online_count(PurpleGroup *group);
1045 /****************************************************************************************/
1046 /** @name Buddy list file management API */
1047 /****************************************************************************************/
1050 * Loads the buddy list from ~/.purple/blist.xml.
1052 void purple_blist_load(void);
1055 * Schedule a save of the blist.xml file. This is used by the privacy
1056 * API whenever the privacy settings are changed. If you make a change
1057 * to blist.xml using one of the functions in the buddy list API, then
1058 * the buddy list is saved automatically, so you should not need to
1061 void purple_blist_schedule_save(void);
1064 * Requests from the user information needed to add a buddy to the
1067 * @param account The account the buddy is added to.
1068 * @param username The username of the buddy.
1069 * @param group The name of the group to place the buddy in.
1070 * @param alias The optional alias for the buddy.
1072 void purple_blist_request_add_buddy(PurpleAccount *account, const char *username,
1073 const char *group, const char *alias);
1076 * Requests from the user information needed to add a chat to the
1079 * @param account The account the buddy is added to.
1080 * @param group The optional group to add the chat to.
1081 * @param alias The optional alias for the chat.
1082 * @param name The required chat name.
1084 void purple_blist_request_add_chat(PurpleAccount *account, PurpleGroup *group,
1085 const char *alias, const char *name);
1088 * Requests from the user information needed to add a group to the
1091 void purple_blist_request_add_group(void);
1094 * Associates a boolean with a node in the buddy list
1096 * @param node The node to associate the data with
1097 * @param key The identifier for the data
1098 * @param value The value to set
1100 void purple_blist_node_set_bool(PurpleBlistNode *node, const char *key, gboolean value);
1103 * Retrieves a named boolean setting from a node in the buddy list
1105 * @param node The node to retrieve the data from
1106 * @param key The identifier of the data
1108 * @return The value, or FALSE if there is no setting
1110 gboolean purple_blist_node_get_bool(PurpleBlistNode *node, const char *key);
1113 * Associates an integer with a node in the buddy list
1115 * @param node The node to associate the data with
1116 * @param key The identifier for the data
1117 * @param value The value to set
1119 void purple_blist_node_set_int(PurpleBlistNode *node, const char *key, int value);
1122 * Retrieves a named integer setting from a node in the buddy list
1124 * @param node The node to retrieve the data from
1125 * @param key The identifier of the data
1127 * @return The value, or 0 if there is no setting
1129 int purple_blist_node_get_int(PurpleBlistNode *node, const char *key);
1132 * Associates a string with a node in the buddy list
1134 * @param node The node to associate the data with
1135 * @param key The identifier for the data
1136 * @param value The value to set
1138 void purple_blist_node_set_string(PurpleBlistNode *node, const char *key,
1142 * Retrieves a named string setting from a node in the buddy list
1144 * @param node The node to retrieve the data from
1145 * @param key The identifier of the data
1147 * @return The value, or NULL if there is no setting
1149 const char *purple_blist_node_get_string(PurpleBlistNode *node, const char *key);
1152 * Removes a named setting from a blist node
1154 * @param node The node from which to remove the setting
1155 * @param key The name of the setting
1157 void purple_blist_node_remove_setting(PurpleBlistNode *node, const char *key);
1160 * Set the flags for the given node. Setting a node's flags will overwrite
1161 * the old flags, so if you want to save them, you must first call
1162 * purple_blist_node_get_flags and modify that appropriately.
1164 * @param node The node on which to set the flags.
1165 * @param flags The flags to set. This is a bitmask.
1167 void purple_blist_node_set_flags(PurpleBlistNode *node, PurpleBlistNodeFlags flags);
1170 * Get the current flags on a given node.
1172 * @param node The node from which to get the flags.
1174 * @return The flags on the node. This is a bitmask.
1176 PurpleBlistNodeFlags purple_blist_node_get_flags(PurpleBlistNode *node);
1179 * Get the type of a given node.
1181 * @param node The node.
1183 * @return The type of the node.
1187 PurpleBlistNodeType purple_blist_node_get_type(PurpleBlistNode *node);
1192 * Retrieves the extended menu items for a buddy list node.
1193 * @param n The blist node for which to obtain the extended menu items.
1194 * @return A list of PurpleMenuAction items, as harvested by the
1195 * blist-node-extended-menu signal.
1197 GList *purple_blist_node_get_extended_menu(PurpleBlistNode *n);
1199 /**************************************************************************/
1200 /** @name UI Registration Functions */
1201 /**************************************************************************/
1205 * Sets the UI operations structure to be used for the buddy list.
1207 * @param ops The ops struct.
1209 void purple_blist_set_ui_ops(PurpleBlistUiOps *ops);
1212 * Returns the UI operations structure to be used for the buddy list.
1214 * @return The UI operations structure.
1216 PurpleBlistUiOps *purple_blist_get_ui_ops(void);
1220 /**************************************************************************/
1221 /** @name Buddy List Subsystem */
1222 /**************************************************************************/
1226 * Returns the handle for the buddy list subsystem.
1228 * @return The buddy list subsystem handle.
1230 void *purple_blist_get_handle(void);
1233 * Initializes the buddy list subsystem.
1235 void purple_blist_init(void);
1238 * Uninitializes the buddy list subsystem.
1240 void purple_blist_uninit(void);
1248 #endif /* _PURPLE_BLIST_H_ */