comparison libpurple/buddyicon.h @ 16375:391a79778f89

Rework the buddy icon subsystem to use the imgstore subsystem, and modify the imgstore subsystem to not require IDs for everything.
author Richard Laager <rlaager@wiktel.com>
date Tue, 24 Apr 2007 03:57:07 +0000
parents c9b4ff420140
children e0c9a46b459f
comparison
equal deleted inserted replaced
16374:2a19bbc743ed 16375:391a79778f89
27 27
28 typedef struct _PurpleBuddyIcon PurpleBuddyIcon; 28 typedef struct _PurpleBuddyIcon PurpleBuddyIcon;
29 29
30 #include "account.h" 30 #include "account.h"
31 #include "blist.h" 31 #include "blist.h"
32 #include "imgstore.h"
32 #include "prpl.h" 33 #include "prpl.h"
33 34
34 #ifdef __cplusplus 35 #ifdef __cplusplus
35 extern "C" { 36 extern "C" {
36 #endif 37 #endif
42 /** @name Buddy Icon API */ 43 /** @name Buddy Icon API */
43 /**************************************************************************/ 44 /**************************************************************************/
44 /*@{*/ 45 /*@{*/
45 46
46 /** 47 /**
47 * Create a buddy icon structure and populate it. 48 * Creates a new buddy icon structure and populate it.
48 * 49 *
49 * If the buddy icon already exists, you'll get a reference to that structure, 50 * If the buddy icon already exists, you'll get a reference to that structure,
50 * which will have been updated with the data supplied. 51 * which will have been updated with the data supplied.
51 * 52 *
52 * @param account The account the user is on. 53 * @param account The account the user is on.
53 * @param username The username the icon belongs to. 54 * @param username The username the icon belongs to.
54 * @param protocol_icon_data The buddy icon data received over the wire. 55 * @param icon_data The buddy icon data.
55 * @param protocol_icon_len The length of the data in @a protocol_icon_data. 56 * @param icon_len The buddy icon length.
56 * @param custom_icon_data The data for a custom buddy icon set by the user. 57 *
57 * @param custom_icon_len The length of the data in @a custom_icon-data. 58 * @return The buddy icon structure.
58 * @return The buddy icon structure, referenced for you. If you don't 59 */
59 * want the reference, then call purple_buddy_icon_unref(). However, 60 PurpleBuddyIcon *purple_buddy_icon_new(PurpleAccount *account, const char *username,
60 * you may want to use purple_buddy_icon_set_for_user() instead. 61 void *icon_data, size_t icon_len);
61 */
62 PurpleBuddyIcon *
63 purple_buddy_icon_new(PurpleAccount *account, const char *username,
64 void *protocol_icon_data, size_t protocol_icon_len,
65 void *custom_icon_data, size_t custom_icon_len);
66 62
67 /** 63 /**
68 * Increments the reference count on a buddy icon. 64 * Increments the reference count on a buddy icon.
69 * 65 *
70 * @param icon The buddy icon. 66 * @param icon The buddy icon.
88 * Updates every instance of this icon. 84 * Updates every instance of this icon.
89 * 85 *
90 * @param icon The buddy icon. 86 * @param icon The buddy icon.
91 */ 87 */
92 void purple_buddy_icon_update(PurpleBuddyIcon *icon); 88 void purple_buddy_icon_update(PurpleBuddyIcon *icon);
93
94 /**
95 * Sets the buddy icon's data for a custom icon set by the user.
96 *
97 * @param icon The buddy icon.
98 * @param data The buddy icon data for the custom icon set by the user.
99 * @param len The length of the data in @a data.
100 */
101 void purple_buddy_icon_set_custom_data(PurpleBuddyIcon *icon, guchar *data, size_t len);
102 89
103 /** 90 /**
104 * Sets the buddy icon's data that was received over the wire. 91 * Sets the buddy icon's data that was received over the wire.
105 * 92 *
106 * @param icon The buddy icon. 93 * @param icon The buddy icon.
107 * @param data The buddy icon data received over the wire. 94 * @param data The buddy icon data received over the wire.
108 * @param len The length of the data in @a data. 95 * @param len The length of the data in @a data.
109 */ 96 */
110 void purple_buddy_icon_set_protocol_data(PurpleBuddyIcon *icon, guchar *data, size_t len); 97 void purple_buddy_icon_set_data(PurpleBuddyIcon *icon, guchar *data, size_t len);
111 98
112 /** 99 /**
113 * Returns the buddy icon's account. 100 * Returns the buddy icon's account.
114 * 101 *
115 * @param icon The buddy icon. 102 * @param icon The buddy icon.
127 */ 114 */
128 const char *purple_buddy_icon_get_username(const PurpleBuddyIcon *icon); 115 const char *purple_buddy_icon_get_username(const PurpleBuddyIcon *icon);
129 116
130 /** 117 /**
131 * Returns the buddy icon's data. 118 * Returns the buddy icon's data.
132 *
133 * This will return the data for a custom icon, if one has been set by the
134 * user. Otherwise, it will return the protocol data, if available. If
135 * no data is available (which can happen if you're holding on to a
136 * reference to an icon and the protocol and/or custom icon(s) are deleted
137 * under you), it will return @c NULL.
138 * 119 *
139 * @param icon The buddy icon. 120 * @param icon The buddy icon.
140 * @param len If not @c NULL, the length of the icon data returned will be 121 * @param len If not @c NULL, the length of the icon data returned will be
141 * set in the location pointed to by this. 122 * set in the location pointed to by this.
142 * 123 *
143 * @return The icon data. 124 * @return A pointer to the icon data.
144 */ 125 */
145 const guchar *purple_buddy_icon_get_data(const PurpleBuddyIcon *icon, size_t *len); 126 gconstpointer purple_buddy_icon_get_data(const PurpleBuddyIcon *icon, size_t *len);
146 127
147 /** 128 /**
148 * Returns an extension corresponding to the buddy icon's file type. 129 * Returns an extension corresponding to the buddy icon's file type.
149 * 130 *
150 * This will return the type of a custom icon, if one has been set by the 131 * @param icon The buddy icon.
151 * user. Otherwise, it will return the type of the protocol icon, if 132 *
152 * available. If no data is available (which can happen if you're holding on 133 * @return The icon's extension, "icon" if unknown, or @c NULL if
153 * to a reference to an icon and the protocol and/or custom icon(s) are deleted 134 * the image data has disappeared.
154 * under you), it will return @c NULL. 135 */
155 * 136 const char *purple_buddy_icon_get_extension(const PurpleBuddyIcon *icon);
156 * @param icon The buddy icon.
157 *
158 * @return The icon's extension, or "icon" if unknown.
159 */
160 const char *purple_buddy_icon_get_type(const PurpleBuddyIcon *icon);
161 137
162 /*@}*/ 138 /*@}*/
163 139
164 /**************************************************************************/ 140 /**************************************************************************/
165 /** @name Buddy Icon Subsystem API */ 141 /** @name Buddy Icon Subsystem API */
190 */ 166 */
191 PurpleBuddyIcon * 167 PurpleBuddyIcon *
192 purple_buddy_icons_find(PurpleAccount *account, const char *username); 168 purple_buddy_icons_find(PurpleAccount *account, const char *username);
193 169
194 /** 170 /**
171 * Returns a boolean indicating if a given contact has a custom buddy icon.
172 *
173 * @param contact The contact
174 *
175 * @return A boolean indicating if @a contact has a custom buddy icon.
176 */
177 gboolean
178 purple_buddy_icons_has_custom_icon(PurpleContact *contact);
179
180 /**
181 * Returns the custom buddy icon image for a contact.
182 *
183 * This function deals with loading the icon from the cache, if
184 * needed, so it should be called in any case where you want the
185 * appropriate icon.
186 *
187 * @param contact The contact
188 *
189 * @return The custom buddy icon image.
190 */
191 PurpleStoredImage *
192 purple_buddy_icons_find_custom_icon(PurpleContact *contact);
193
194 /**
195 * Sets a custom buddy icon for a user.
196 *
197 * This function will deal with saving a record of the icon,
198 * caching the data, etc.
199 *
200 * @param contact The contact for which to set a custom icon.
201 * @param icon_data The image data of the icon.
202 * @param icon_len The length of the data in @a icon_data.
203 */
204 void
205 purple_buddy_icons_set_custom_icon(PurpleContact *contact,
206 guchar *icon_data, size_t icon_len);
207
208 /**
195 * Sets whether or not buddy icon caching is enabled. 209 * Sets whether or not buddy icon caching is enabled.
196 * 210 *
197 * @param caching TRUE of buddy icon caching should be enabled, or 211 * @param caching TRUE of buddy icon caching should be enabled, or
198 * FALSE otherwise. 212 * FALSE otherwise.
199 */ 213 */