Frameworks/libpurple.framework/Versions/0.6.2/Headers/blist.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 2571 Frameworks/libpurple.framework/Versions/0.6.0/Headers/blist.h@75fb8ee8f2e6
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
     1 /**
     2  * @file blist.h Buddy List API
     3  * @ingroup core
     4  * @see @ref blist-signals
     5  */
     6 
     7 /* purple
     8  *
     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.
    12  *
    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.
    17  *
    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.
    22  *
    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
    26  */
    27 #ifndef _PURPLE_BLIST_H_
    28 #define _PURPLE_BLIST_H_
    29 
    30 /* I can't believe I let ChipX86 inspire me to write good code. -Sean */
    31 
    32 #include <glib.h>
    33 
    34 /** @copydoc _PurpleBuddyList */
    35 typedef struct _PurpleBuddyList PurpleBuddyList;
    36 /** @copydoc _PurpleBlistUiOps */
    37 typedef struct _PurpleBlistUiOps PurpleBlistUiOps;
    38 /** @copydoc _PurpleBlistNode */
    39 typedef struct _PurpleBlistNode PurpleBlistNode;
    40 
    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;
    49 
    50 /**************************************************************************/
    51 /* Enumerations                                                           */
    52 /**************************************************************************/
    53 typedef enum
    54 {
    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
    60 
    61 } PurpleBlistNodeType;
    62 
    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)
    67 
    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)))
    71 
    72 typedef enum
    73 {
    74 	PURPLE_BLIST_NODE_FLAG_NO_SAVE      = 1 << 0 /**< node should not be saved with the buddy list */
    75 
    76 } PurpleBlistNodeFlags;
    77 
    78 /**
    79  * @since 2.6.0
    80  */
    81 #define PURPLE_BLIST_NODE(obj) ((PurpleBlistNode *)(obj))
    82 
    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))
    85 
    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)
    88 
    89 /**
    90  * @since 2.6.0
    91  */
    92 #define PURPLE_GROUP(obj) ((PurpleGroup *)(obj))
    93 
    94 /**
    95  * @since 2.6.0
    96  */
    97 #define PURPLE_CONTACT(obj) ((PurpleContact *)(obj))
    98 
    99 /**
   100  * @since 2.6.0
   101  */
   102 #define PURPLE_BUDDY(obj) ((PurpleBuddy *)(obj))
   103 
   104 /**
   105  * @since 2.6.0
   106  */
   107 #define PURPLE_CHAT(obj) ((PurpleChat *)(obj))
   108 
   109 #include "account.h"
   110 #include "buddyicon.h"
   111 #include "status.h"
   112 
   113 /**************************************************************************/
   114 /* Data Structures                                                        */
   115 /**************************************************************************/
   116 
   117 #if !(defined PURPLE_HIDE_STRUCTS) || (defined _PURPLE_BLIST_C_)
   118 
   119 /**
   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                */
   132 };
   133 
   134 /**
   135  * A buddy.  This contains everything Purple will ever need to know about someone on the buddy list.  Everything.
   136  */
   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;
   146 };
   147 
   148 /**
   149  * A contact.  This contains everything Purple will ever need to know about a contact.
   150  */
   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? */
   159 };
   160 
   161 
   162 /**
   163  * A group.  This contains everything Purple will ever need to know about a group.
   164  */
   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 */
   171 };
   172 
   173 /**
   174  * A chat.  This contains everything Purple needs to put a chat room in the
   175  * buddy list.
   176  */
   177 struct _PurpleChat {
   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 */
   182 };
   183 
   184 /**
   185  * The Buddy List
   186  */
   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. */
   191 };
   192 
   193 #endif /* PURPLE_HIDE_STRUCTS && PURPLE_BLIST_STRUCTS */
   194 
   195 /**
   196  * Buddy list UI operations.
   197  *
   198  * Any UI representing a buddy list must assign a filled-out PurpleBlistUiOps
   199  * structure to the buddy list core.
   200  */
   201 struct _PurpleBlistUiOps
   202 {
   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);
   218 
   219 	/**
   220 	 * This is called when a node has been modified and should be saved.
   221 	 *
   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.
   225 	 *
   226 	 * @attrib node    The node which has been modified.
   227 	 *
   228 	 * @since 2.6.0.
   229 	 */
   230 	void (*save_node)(PurpleBlistNode *node);
   231 
   232 	/**
   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).
   236 	 *
   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.
   240 	 *
   241 	 * @attrib node  The node which has been modified.
   242 	 * @since 2.6.0.
   243 	 */
   244 	void (*remove_node)(PurpleBlistNode *node);
   245 
   246 	/**
   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.
   250 	 *
   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.
   254 	 *
   255 	 * @attrib account  The account whose data to save. If NULL, save all data
   256 	 *                  for all accounts.
   257 	 * @since 2.6.0.
   258 	 */
   259 	void (*save_account)(PurpleAccount *account);
   260 
   261 	void (*_purple_reserved1)(void);
   262 };
   263 
   264 #ifdef __cplusplus
   265 extern "C" {
   266 #endif
   267 
   268 /**************************************************************************/
   269 /** @name Buddy List API                                                  */
   270 /**************************************************************************/
   271 /*@{*/
   272 
   273 /**
   274  * Creates a new buddy list
   275  *
   276  * @return The new buddy list.
   277  * @deprecated In 3.0.0, this will be handled by purple_blist_init()
   278  */
   279 PurpleBuddyList *purple_blist_new(void);
   280 
   281 /**
   282  * Sets the main buddy list.
   283  *
   284  * @param blist The buddy list you want to use.
   285  * @deprecated In 3.0.0, this will be handled by purple_blist_init()
   286  */
   287 void purple_set_blist(PurpleBuddyList *blist);
   288 
   289 /**
   290  * Returns the main buddy list.
   291  *
   292  * @return The main buddy list.
   293  */
   294 PurpleBuddyList *purple_get_blist(void);
   295 
   296 /**
   297  * Returns the root node of the main buddy list.
   298  *
   299  * @return The root node.
   300  */
   301 PurpleBlistNode *purple_blist_get_root(void);
   302 
   303 /**
   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.
   307  *
   308  * @return A list of every buddy in the list. Caller is responsible for
   309  *         freeing the list.
   310  *
   311  * @see purple_find_buddies
   312  * @since 2.6.0
   313  */
   314 GSList *purple_blist_get_buddies(void);
   315 
   316 /**
   317  * Returns the UI data for the list.
   318  *
   319  * @return The UI data for the list.
   320  *
   321  * @since 2.6.0
   322  */
   323 gpointer purple_blist_get_ui_data(void);
   324 
   325 /**
   326  * Sets the UI data for the list.
   327  *
   328  * @param ui_data The UI data for the list.
   329  *
   330  * @since 2.6.0
   331  */
   332 void purple_blist_set_ui_data(gpointer ui_data);
   333 
   334 /**
   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.
   337  *
   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
   345  */
   346 PurpleBlistNode *purple_blist_node_next(PurpleBlistNode *node, gboolean offline);
   347 
   348 /**
   349  * Returns the parent node of a given node.
   350  *
   351  * @param node A node.
   352  * @return  The parent node.
   353  * @since 2.4.0
   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
   358  */
   359 PurpleBlistNode *purple_blist_node_get_parent(PurpleBlistNode *node);
   360 
   361 /**
   362  * Returns the the first child node of a given node.
   363  *
   364  * @param node A node.
   365  * @return  The child node.
   366  * @since 2.4.0
   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
   371  */
   372 PurpleBlistNode *purple_blist_node_get_first_child(PurpleBlistNode *node);
   373 
   374 /**
   375  * Returns the sibling node of a given node.
   376  *
   377  * @param node A node.
   378  * @return  The sibling node.
   379  * @since 2.4.0
   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
   384  */
   385 PurpleBlistNode *purple_blist_node_get_sibling_next(PurpleBlistNode *node);
   386 
   387 /**
   388  * Returns the previous sibling node of a given node.
   389  *
   390  * @param node A node.
   391  * @return  The sibling node.
   392  * @since 2.4.0
   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
   397  */
   398 PurpleBlistNode *purple_blist_node_get_sibling_prev(PurpleBlistNode *node);
   399 
   400 /**
   401  * Returns the UI data of a given node.
   402  *
   403  * @param node The node.
   404  * @return The UI data.
   405  * @since 2.6.0
   406  */
   407 gpointer purple_blist_node_get_ui_data(const PurpleBlistNode *node);
   408 
   409 /**
   410  * Sets the UI data of a given node.
   411  *
   412  * @param node The node.
   413  * @param ui_data The UI data.
   414  *
   415  * @since 2.6.0
   416  */
   417 void purple_blist_node_set_ui_data(PurpleBlistNode *node, gpointer ui_data);
   418 
   419 /**
   420  * Shows the buddy list, creating a new one if necessary.
   421  */
   422 void purple_blist_show(void);
   423 
   424 
   425 /**
   426  * Destroys the buddy list window.
   427  *
   428  * @deprecated The UI is responsible for cleaning up the
   429  *             PurpleBuddyList->ui_data. purple_blist_uninit() will free the
   430  *             PurpleBuddyList* itself.
   431  */
   432 void purple_blist_destroy(void);
   433 
   434 /**
   435  * Hides or unhides the buddy list.
   436  *
   437  * @param show   Whether or not to show the buddy list
   438  */
   439 void purple_blist_set_visible(gboolean show);
   440 
   441 /**
   442  * Updates a buddy's status.
   443  *
   444  * This should only be called from within Purple.
   445  *
   446  * @param buddy      The buddy whose status has changed.
   447  * @param old_status The status from which we are changing.
   448  */
   449 void purple_blist_update_buddy_status(PurpleBuddy *buddy, PurpleStatus *old_status);
   450 
   451 /**
   452  * Updates a node's custom icon.
   453  *
   454  * @param node  The PurpleBlistNode whose custom icon has changed.
   455  *
   456  * @since 2.5.0
   457  */
   458 void purple_blist_update_node_icon(PurpleBlistNode *node);
   459 
   460 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_BLIST_C_)
   461 /**
   462  * Updates a buddy's icon.
   463  *
   464  * @param buddy  The buddy whose buddy icon has changed
   465  * @deprecated Use purple_blist_update_node_icon() instead.
   466  */
   467 void purple_blist_update_buddy_icon(PurpleBuddy *buddy);
   468 #endif
   469 
   470 /**
   471  * Renames a buddy in the buddy list.
   472  *
   473  * @param buddy  The buddy whose name will be changed.
   474  * @param name   The new name of the buddy.
   475  */
   476 void purple_blist_rename_buddy(PurpleBuddy *buddy, const char *name);
   477 
   478 /**
   479  * Aliases a contact in the buddy list.
   480  *
   481  * @param contact The contact whose alias will be changed.
   482  * @param alias   The contact's alias.
   483  */
   484 void purple_blist_alias_contact(PurpleContact *contact, const char *alias);
   485 
   486 /**
   487  * Aliases a buddy in the buddy list.
   488  *
   489  * @param buddy  The buddy whose alias will be changed.
   490  * @param alias  The buddy's alias.
   491  */
   492 void purple_blist_alias_buddy(PurpleBuddy *buddy, const char *alias);
   493 
   494 /**
   495  * Sets the server-sent alias of a buddy in the buddy list.
   496  * PRPLs should call serv_got_alias() instead of this.
   497  *
   498  * @param buddy  The buddy whose alias will be changed.
   499  * @param alias  The buddy's "official" alias.
   500  */
   501 void purple_blist_server_alias_buddy(PurpleBuddy *buddy, const char *alias);
   502 
   503 /**
   504  * Aliases a chat in the buddy list.
   505  *
   506  * @param chat  The chat whose alias will be changed.
   507  * @param alias The chat's new alias.
   508  */
   509 void purple_blist_alias_chat(PurpleChat *chat, const char *alias);
   510 
   511 /**
   512  * Renames a group
   513  *
   514  * @param group  The group to rename
   515  * @param name   The new name
   516  */
   517 void purple_blist_rename_group(PurpleGroup *group, const char *name);
   518 
   519 /**
   520  * Creates a new chat for the buddy list
   521  *
   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
   528  */
   529 PurpleChat *purple_chat_new(PurpleAccount *account, const char *alias, GHashTable *components);
   530 
   531 /**
   532  * Destroys a chat
   533  *
   534  * @param chat       The chat to destroy
   535  */
   536 void purple_chat_destroy(PurpleChat *chat);
   537 
   538 /**
   539  * Adds a new chat to the buddy list.
   540  *
   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
   543  * the "Chats" group.
   544  *
   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
   548  */
   549 void purple_blist_add_chat(PurpleChat *chat, PurpleGroup *group, PurpleBlistNode *node);
   550 
   551 /**
   552  * Creates a new buddy.
   553  *
   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
   556  * with the server.
   557  *
   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
   562  *
   563  * @see purple_account_add_buddy
   564  * @see purple_blist_add_buddy
   565  */
   566 PurpleBuddy *purple_buddy_new(PurpleAccount *account, const char *name, const char *alias);
   567 
   568 /**
   569  * Destroys a buddy
   570  *
   571  * @param buddy     The buddy to destroy
   572  */
   573 void purple_buddy_destroy(PurpleBuddy *buddy);
   574 
   575 /**
   576  * Sets a buddy's icon.
   577  *
   578  * This should only be called from within Purple. You probably want to
   579  * call purple_buddy_icon_set_data().
   580  *
   581  * @param buddy The buddy.
   582  * @param icon  The buddy icon.
   583  *
   584  * @see purple_buddy_icon_set_data()
   585  */
   586 void purple_buddy_set_icon(PurpleBuddy *buddy, PurpleBuddyIcon *icon);
   587 
   588 /**
   589  * Returns a buddy's account.
   590  *
   591  * @param buddy The buddy.
   592  *
   593  * @return The account
   594  */
   595 PurpleAccount *purple_buddy_get_account(const PurpleBuddy *buddy);
   596 
   597 /**
   598  * Returns a buddy's name
   599  *
   600  * @param buddy The buddy.
   601  *
   602  * @return The name.
   603  */
   604 const char *purple_buddy_get_name(const PurpleBuddy *buddy);
   605 
   606 /**
   607  * Returns a buddy's icon.
   608  *
   609  * @param buddy The buddy.
   610  *
   611  * @return The buddy icon.
   612  */
   613 PurpleBuddyIcon *purple_buddy_get_icon(const PurpleBuddy *buddy);
   614 
   615 /**
   616  * Returns a buddy's protocol-specific data.
   617  *
   618  * This should only be called from the associated prpl.
   619  *
   620  * @param buddy The buddy.
   621  * @return      The protocol data.
   622  *
   623  * @see purple_buddy_set_protocol_data()
   624  * @since 2.6.0
   625  */
   626 gpointer purple_buddy_get_protocol_data(const PurpleBuddy *buddy);
   627 
   628 /**
   629  * Sets a buddy's protocol-specific data.
   630  *
   631  * This should only be called from the associated prpl.
   632  *
   633  * @param buddy The buddy.
   634  * @param data  The data.
   635  *
   636  * @see purple_buddy_get_protocol_data()
   637  * @since 2.6.0
   638  */
   639 void purple_buddy_set_protocol_data(PurpleBuddy *buddy, gpointer data);
   640 
   641 /**
   642  * Returns a buddy's contact.
   643  *
   644  * @param buddy The buddy.
   645  *
   646  * @return The buddy's contact.
   647  */
   648 PurpleContact *purple_buddy_get_contact(PurpleBuddy *buddy);
   649 
   650 /**
   651  * Returns a buddy's presence.
   652  *
   653  * @param buddy The buddy.
   654  *
   655  * @return The buddy's presence.
   656  */
   657 PurplePresence *purple_buddy_get_presence(const PurpleBuddy *buddy);
   658 
   659 /**
   660  * Adds a new buddy to the buddy list.
   661  *
   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.
   665  *
   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.
   671  */
   672 void purple_blist_add_buddy(PurpleBuddy *buddy, PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node);
   673 
   674 /**
   675  * Creates a new group
   676  *
   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.
   679  *
   680  * @param name   The name of the new group
   681  * @return       A new group struct
   682 */
   683 PurpleGroup *purple_group_new(const char *name);
   684 
   685 /**
   686  * Destroys a group
   687  *
   688  * @param group  The group to destroy
   689 */
   690 void purple_group_destroy(PurpleGroup *group);
   691 
   692 /**
   693  * Adds a new group to the buddy list.
   694  *
   695  * The new group will be inserted after insert or prepended to the list if
   696  * node is NULL.
   697  *
   698  * @param group  The group
   699  * @param node   The insertion point
   700  */
   701 void purple_blist_add_group(PurpleGroup *group, PurpleBlistNode *node);
   702 
   703 /**
   704  * Creates a new contact
   705  *
   706  * @return       A new contact struct
   707  */
   708 PurpleContact *purple_contact_new(void);
   709 
   710 /**
   711  * Destroys a contact
   712  *
   713  * @param contact  The contact to destroy
   714  */
   715 void purple_contact_destroy(PurpleContact *contact);
   716 
   717 /**
   718  * Adds a new contact to the buddy list.
   719  *
   720  * The new contact will be inserted after insert or prepended to the list if
   721  * node is NULL.
   722  *
   723  * @param contact The contact
   724  * @param group   The group to add the contact to
   725  * @param node    The insertion point
   726  */
   727 void purple_blist_add_contact(PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node);
   728 
   729 /**
   730  * Merges two contacts
   731  *
   732  * All of the buddies from source will be moved to target
   733  *
   734  * @param source  The contact to merge
   735  * @param node    The place to merge to (a buddy or contact)
   736  */
   737 void purple_blist_merge_contact(PurpleContact *source, PurpleBlistNode *node);
   738 
   739 /**
   740  * Returns the highest priority buddy for a given contact.
   741  *
   742  * @param contact  The contact
   743  * @return The highest priority buddy
   744  */
   745 PurpleBuddy *purple_contact_get_priority_buddy(PurpleContact *contact);
   746 
   747 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_BLIST_C_)
   748 /**
   749  * Sets the alias for a contact.
   750  *
   751  * @param contact  The contact
   752  * @param alias    The alias to set, or NULL to unset
   753  *
   754  * @deprecated Use purple_blist_alias_contact() instead.
   755  */
   756 void purple_contact_set_alias(PurpleContact *contact, const char *alias);
   757 #endif
   758 
   759 /**
   760  * Gets the alias for a contact.
   761  *
   762  * @param contact  The contact
   763  * @return  The alias, or NULL if it is not set.
   764  */
   765 const char *purple_contact_get_alias(PurpleContact *contact);
   766 
   767 /**
   768  * Determines whether an account owns any buddies in a given contact
   769  *
   770  * @param contact  The contact to search through.
   771  * @param account  The account.
   772  *
   773  * @return TRUE if there are any buddies from account in the contact, or FALSE otherwise.
   774  */
   775 gboolean purple_contact_on_account(PurpleContact *contact, PurpleAccount *account);
   776 
   777 /**
   778  * Invalidates the priority buddy so that the next call to
   779  * purple_contact_get_priority_buddy recomputes it.
   780  *
   781  * @param contact  The contact
   782  */
   783 void purple_contact_invalidate_priority_buddy(PurpleContact *contact);
   784 
   785 /**
   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.
   788  *
   789  * @param buddy   The buddy to be removed
   790  *
   791  * @see purple_account_remove_buddy
   792  */
   793 void purple_blist_remove_buddy(PurpleBuddy *buddy);
   794 
   795 /**
   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.
   799  *
   800  * @param contact The contact to be removed
   801  *
   802  * @see purple_blist_remove_buddy
   803  */
   804 void purple_blist_remove_contact(PurpleContact *contact);
   805 
   806 /**
   807  * Removes a chat from the buddy list and frees the memory allocated to it.
   808  *
   809  * @param chat   The chat to be removed
   810  */
   811 void purple_blist_remove_chat(PurpleChat *chat);
   812 
   813 /**
   814  * Removes a group from the buddy list and frees the memory allocated to it and to
   815  * its children
   816  *
   817  * @param group   The group to be removed
   818  */
   819 void purple_blist_remove_group(PurpleGroup *group);
   820 
   821 /**
   822  * Returns the alias of a buddy.
   823  *
   824  * @param buddy   The buddy whose name will be returned.
   825  * @return        The alias (if set), server alias (if set),
   826  *                or NULL.
   827  */
   828 const char *purple_buddy_get_alias_only(PurpleBuddy *buddy);
   829 
   830 /**
   831  * Gets the server alias for a buddy.
   832  *
   833  * @param buddy  The buddy whose name will be returned
   834  * @return  The server alias, or NULL if it is not set.
   835  */
   836 const char *purple_buddy_get_server_alias(PurpleBuddy *buddy);
   837 
   838 /**
   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.
   842  *
   843  * @param buddy  The buddy whose name will be returned
   844  * @return       The appropriate name or alias, or NULL.
   845  *
   846  */
   847 const char *purple_buddy_get_contact_alias(PurpleBuddy *buddy);
   848 
   849 #if !(defined PURPLE_DISABLE_DEPRECATED) || (defined _PURPLE_BLIST_C_)
   850 /**
   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.
   854  *
   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.
   858  */
   859 const char *purple_buddy_get_local_alias(PurpleBuddy *buddy);
   860 #endif
   861 
   862 /**
   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.
   866  *
   867  * @param buddy   The buddy whose name will be returned.
   868  * @return        The appropriate name or alias, or NULL
   869  */
   870 const char *purple_buddy_get_alias(PurpleBuddy *buddy);
   871 
   872 /**
   873  * Returns the local alias for the buddy, or @c NULL if none exists.
   874  *
   875  * @param buddy  The buddy
   876  * @return       The local alias for the buddy
   877  *
   878  * @since 2.6.0
   879  */
   880 const char *purple_buddy_get_local_buddy_alias(PurpleBuddy *buddy);
   881 
   882 /**
   883  * Returns the correct name to display for a blist chat.
   884  *
   885  * @param chat   The chat whose name will be returned.
   886  * @return       The alias (if set), or first component value.
   887  */
   888 const char *purple_chat_get_name(PurpleChat *chat);
   889 
   890 /**
   891  * Finds the buddy struct given a name and an account
   892  *
   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
   896  */
   897 PurpleBuddy *purple_find_buddy(PurpleAccount *account, const char *name);
   898 
   899 /**
   900  * Finds the buddy struct given a name, an account, and a group
   901  *
   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
   906  */
   907 PurpleBuddy *purple_find_buddy_in_group(PurpleAccount *account, const char *name,
   908 		PurpleGroup *group);
   909 
   910 /**
   911  * Finds all PurpleBuddy structs given a name and an account
   912  *
   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)
   915  *
   916  * @return        A GSList of buddies (which must be freed), or NULL if the buddy doesn't exist
   917  */
   918 GSList *purple_find_buddies(PurpleAccount *account, const char *name);
   919 
   920 
   921 /**
   922  * Finds a group by name
   923  *
   924  * @param name    The group's name
   925  * @return        The group or NULL if the group does not exist
   926  */
   927 PurpleGroup *purple_find_group(const char *name);
   928 
   929 /**
   930  * Finds a chat by name.
   931  *
   932  * @param account The chat's account.
   933  * @param name    The chat's name.
   934  *
   935  * @return The chat, or @c NULL if the chat does not exist.
   936  */
   937 PurpleChat *purple_blist_find_chat(PurpleAccount *account, const char *name);
   938 
   939 /**
   940  * Returns the group of which the chat is a member.
   941  *
   942  * @param chat The chat.
   943  *
   944  * @return The parent group, or @c NULL if the chat is not in a group.
   945  */
   946 PurpleGroup *purple_chat_get_group(PurpleChat *chat);
   947 
   948 /**
   949  * Returns the account the chat belongs to.
   950  *
   951  * @param chat  The chat.
   952  *
   953  * @return  The account the chat belongs to.
   954  *
   955  * @since 2.4.0
   956  */
   957 PurpleAccount *purple_chat_get_account(PurpleChat *chat);
   958 
   959 /**
   960  * Get a hashtable containing information about a chat.
   961  *
   962  * @param chat  The chat.
   963  *
   964  * @constreturn  The hashtable.
   965  *
   966  * @since 2.4.0
   967  */
   968 GHashTable *purple_chat_get_components(PurpleChat *chat);
   969 
   970 /**
   971  * Returns the group of which the buddy is a member.
   972  *
   973  * @param buddy   The buddy
   974  * @return        The group or NULL if the buddy is not in a group
   975  */
   976 PurpleGroup *purple_buddy_get_group(PurpleBuddy *buddy);
   977 
   978 
   979 /**
   980  * Returns a list of accounts that have buddies in this group
   981  *
   982  * @param g The group
   983  *
   984  * @return A GSList of accounts (which must be freed), or NULL if the group
   985  *         has no accounts.
   986  */
   987 GSList *purple_group_get_accounts(PurpleGroup *g);
   988 
   989 /**
   990  * Determines whether an account owns any buddies in a given group
   991  *
   992  * @param g       The group to search through.
   993  * @param account The account.
   994  *
   995  * @return TRUE if there are any buddies in the group, or FALSE otherwise.
   996  */
   997 gboolean purple_group_on_account(PurpleGroup *g, PurpleAccount *account);
   998 
   999 /**
  1000  * Returns the name of a group.
  1001  *
  1002  * @param group The group.
  1003  *
  1004  * @return The name of the group.
  1005  */
  1006 const char *purple_group_get_name(PurpleGroup *group);
  1007 
  1008 /**
  1009  * Called when an account connects.  Tells the UI to update all the
  1010  * buddies.
  1011  *
  1012  * @param account   The account
  1013  */
  1014 void purple_blist_add_account(PurpleAccount *account);
  1015 
  1016 
  1017 /**
  1018  * Called when an account disconnects.  Sets the presence of all the buddies to 0
  1019  * and tells the UI to update them.
  1020  *
  1021  * @param account   The account
  1022  */
  1023 void purple_blist_remove_account(PurpleAccount *account);
  1024 
  1025 
  1026 /**
  1027  * Determines the total size of a group
  1028  *
  1029  * @param group  The group
  1030  * @param offline Count buddies in offline accounts
  1031  * @return The number of buddies in the group
  1032  */
  1033 int purple_blist_get_group_size(PurpleGroup *group, gboolean offline);
  1034 
  1035 /**
  1036  * Determines the number of online buddies in a group
  1037  *
  1038  * @param group The group
  1039  * @return The number of online buddies in the group, or 0 if the group is NULL
  1040  */
  1041 int purple_blist_get_group_online_count(PurpleGroup *group);
  1042 
  1043 /*@}*/
  1044 
  1045 /****************************************************************************************/
  1046 /** @name Buddy list file management API                                                */
  1047 /****************************************************************************************/
  1048 
  1049 /**
  1050  * Loads the buddy list from ~/.purple/blist.xml.
  1051  */
  1052 void purple_blist_load(void);
  1053 
  1054 /**
  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
  1059  * call this.
  1060  */
  1061 void purple_blist_schedule_save(void);
  1062 
  1063 /**
  1064  * Requests from the user information needed to add a buddy to the
  1065  * buddy list.
  1066  *
  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.
  1071  */
  1072 void purple_blist_request_add_buddy(PurpleAccount *account, const char *username,
  1073 								  const char *group, const char *alias);
  1074 
  1075 /**
  1076  * Requests from the user information needed to add a chat to the
  1077  * buddy list.
  1078  *
  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.
  1083  */
  1084 void purple_blist_request_add_chat(PurpleAccount *account, PurpleGroup *group,
  1085 								 const char *alias, const char *name);
  1086 
  1087 /**
  1088  * Requests from the user information needed to add a group to the
  1089  * buddy list.
  1090  */
  1091 void purple_blist_request_add_group(void);
  1092 
  1093 /**
  1094  * Associates a boolean with a node in the buddy list
  1095  *
  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
  1099  */
  1100 void purple_blist_node_set_bool(PurpleBlistNode *node, const char *key, gboolean value);
  1101 
  1102 /**
  1103  * Retrieves a named boolean setting from a node in the buddy list
  1104  *
  1105  * @param node  The node to retrieve the data from
  1106  * @param key   The identifier of the data
  1107  *
  1108  * @return The value, or FALSE if there is no setting
  1109  */
  1110 gboolean purple_blist_node_get_bool(PurpleBlistNode *node, const char *key);
  1111 
  1112 /**
  1113  * Associates an integer with a node in the buddy list
  1114  *
  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
  1118  */
  1119 void purple_blist_node_set_int(PurpleBlistNode *node, const char *key, int value);
  1120 
  1121 /**
  1122  * Retrieves a named integer setting from a node in the buddy list
  1123  *
  1124  * @param node  The node to retrieve the data from
  1125  * @param key   The identifier of the data
  1126  *
  1127  * @return The value, or 0 if there is no setting
  1128  */
  1129 int purple_blist_node_get_int(PurpleBlistNode *node, const char *key);
  1130 
  1131 /**
  1132  * Associates a string with a node in the buddy list
  1133  *
  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
  1137  */
  1138 void purple_blist_node_set_string(PurpleBlistNode *node, const char *key,
  1139 		const char *value);
  1140 
  1141 /**
  1142  * Retrieves a named string setting from a node in the buddy list
  1143  *
  1144  * @param node  The node to retrieve the data from
  1145  * @param key   The identifier of the data
  1146  *
  1147  * @return The value, or NULL if there is no setting
  1148  */
  1149 const char *purple_blist_node_get_string(PurpleBlistNode *node, const char *key);
  1150 
  1151 /**
  1152  * Removes a named setting from a blist node
  1153  *
  1154  * @param node  The node from which to remove the setting
  1155  * @param key   The name of the setting
  1156  */
  1157 void purple_blist_node_remove_setting(PurpleBlistNode *node, const char *key);
  1158 
  1159 /**
  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.
  1163  *
  1164  * @param node  The node on which to set the flags.
  1165  * @param flags The flags to set.  This is a bitmask.
  1166  */
  1167 void purple_blist_node_set_flags(PurpleBlistNode *node, PurpleBlistNodeFlags flags);
  1168 
  1169 /**
  1170  * Get the current flags on a given node.
  1171  *
  1172  * @param node The node from which to get the flags.
  1173  *
  1174  * @return The flags on the node.  This is a bitmask.
  1175  */
  1176 PurpleBlistNodeFlags purple_blist_node_get_flags(PurpleBlistNode *node);
  1177 
  1178 /**
  1179  * Get the type of a given node.
  1180  *
  1181  * @param node The node.
  1182  *
  1183  * @return The type of the node.
  1184  *
  1185  * @since 2.1.0
  1186  */
  1187 PurpleBlistNodeType purple_blist_node_get_type(PurpleBlistNode *node);
  1188 
  1189 /*@}*/
  1190 
  1191 /**
  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.
  1196  */
  1197 GList *purple_blist_node_get_extended_menu(PurpleBlistNode *n);
  1198 
  1199 /**************************************************************************/
  1200 /** @name UI Registration Functions                                       */
  1201 /**************************************************************************/
  1202 /*@{*/
  1203 
  1204 /**
  1205  * Sets the UI operations structure to be used for the buddy list.
  1206  *
  1207  * @param ops The ops struct.
  1208  */
  1209 void purple_blist_set_ui_ops(PurpleBlistUiOps *ops);
  1210 
  1211 /**
  1212  * Returns the UI operations structure to be used for the buddy list.
  1213  *
  1214  * @return The UI operations structure.
  1215  */
  1216 PurpleBlistUiOps *purple_blist_get_ui_ops(void);
  1217 
  1218 /*@}*/
  1219 
  1220 /**************************************************************************/
  1221 /** @name Buddy List Subsystem                                            */
  1222 /**************************************************************************/
  1223 /*@{*/
  1224 
  1225 /**
  1226  * Returns the handle for the buddy list subsystem.
  1227  *
  1228  * @return The buddy list subsystem handle.
  1229  */
  1230 void *purple_blist_get_handle(void);
  1231 
  1232 /**
  1233  * Initializes the buddy list subsystem.
  1234  */
  1235 void purple_blist_init(void);
  1236 
  1237 /**
  1238  * Uninitializes the buddy list subsystem.
  1239  */
  1240 void purple_blist_uninit(void);
  1241 
  1242 /*@}*/
  1243 
  1244 #ifdef __cplusplus
  1245 }
  1246 #endif
  1247 
  1248 #endif /* _PURPLE_BLIST_H_ */