Remove useless comparison
[pidgin-git.git] / libpurple / smiley.h
blob73202bda47de3f500eacc3c6c98ee1f07f70713d
1 /**
2 * @file smiley.h Smiley API
3 * @ingroup core
4 * @since 2.5.0
5 */
7 /* purple
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
29 #ifndef _PURPLE_SMILEY_H_
30 #define _PURPLE_SMILEY_H_
32 #include <glib-object.h>
34 #include "imgstore.h"
35 #include "util.h"
37 /**
38 * A custom smiley.
39 * This contains everything Purple will ever need to know about a custom smiley.
40 * Everything.
42 * PurpleSmiley is a GObject.
44 typedef struct _PurpleSmiley PurpleSmiley;
45 typedef struct _PurpleSmileyClass PurpleSmileyClass;
47 #define PURPLE_TYPE_SMILEY (purple_smiley_get_type ())
48 #define PURPLE_SMILEY(smiley) (G_TYPE_CHECK_INSTANCE_CAST ((smiley), PURPLE_TYPE_SMILEY, PurpleSmiley))
49 #define PURPLE_SMILEY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PURPLE_TYPE_SMILEY, PurpleSmileyClass))
50 #define PURPLE_IS_SMILEY(smiley) (G_TYPE_CHECK_INSTANCE_TYPE ((smiley), PURPLE_TYPE_SMILEY))
51 #define PURPLE_IS_SMILEY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_TYPE_SMILEY))
52 #define PURPLE_SMILEY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_TYPE_SMILEY, PurpleSmileyClass))
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
58 /**************************************************************************/
59 /** @name Custom Smiley API */
60 /**************************************************************************/
61 /*@{*/
63 /**
64 * GObject-fu.
65 * @internal.
67 GType purple_smiley_get_type(void);
69 /**
70 * Creates a new custom smiley from a PurpleStoredImage.
72 * If a custom smiley with the given shortcut already exists, it
73 * will be automaticaly returned.
75 * @param img The image associated with the smiley.
76 * @param shortcut The associated shortcut (e.g. "(homer)").
78 * @return The custom smiley.
80 PurpleSmiley *
81 purple_smiley_new(PurpleStoredImage *img, const char *shortcut);
83 /**
84 * Creates a new custom smiley, reading the image data from a file.
86 * If a custom smiley with the given shortcut already exists, it
87 * will be automaticaly returned.
89 * @param shortcut The associated shortcut (e.g. "(homer)").
90 * @param filepath The image file.
92 * @return The custom smiley.
94 PurpleSmiley *
95 purple_smiley_new_from_file(const char *shortcut, const char *filepath);
97 /**
98 * Destroys the custom smiley and releases the associated resources.
100 * @param smiley The custom smiley.
102 void
103 purple_smiley_delete(PurpleSmiley *smiley);
106 * Changes the custom smiley's shortcut.
108 * @param smiley The custom smiley.
109 * @param shortcut The new shortcut. A custom smiley with this shortcut
110 * cannot already be in use.
112 * @return TRUE if the shortcut was changed. FALSE otherwise.
114 gboolean
115 purple_smiley_set_shortcut(PurpleSmiley *smiley, const char *shortcut);
118 * Changes the custom smiley's image data.
120 * @param smiley The custom smiley.
121 * @param smiley_data The custom smiley data, which the smiley code
122 * takes ownership of and will free.
123 * @param smiley_data_len The length of the data in @a smiley_data.
125 void
126 purple_smiley_set_data(PurpleSmiley *smiley, guchar *smiley_data,
127 size_t smiley_data_len);
130 * Returns the custom smiley's associated shortcut (e.g. "(homer)").
132 * @param smiley The custom smiley.
134 * @return The shortcut.
136 const char *purple_smiley_get_shortcut(const PurpleSmiley *smiley);
139 * Returns the custom smiley data's checksum.
141 * @param smiley The custom smiley.
143 * @return The checksum.
145 const char *purple_smiley_get_checksum(const PurpleSmiley *smiley);
148 * Returns the PurpleStoredImage with the reference counter incremented.
150 * The returned PurpleStoredImage reference counter must be decremented
151 * when the caller is done using it.
153 * @param smiley The custom smiley.
155 * @return A PurpleStoredImage.
157 PurpleStoredImage *purple_smiley_get_stored_image(const PurpleSmiley *smiley);
160 * Returns the custom smiley's data.
162 * @param smiley The custom smiley.
163 * @param len If not @c NULL, the length of the image data returned
164 * will be set in the location pointed to by this.
166 * @return A pointer to the custom smiley data.
168 gconstpointer purple_smiley_get_data(const PurpleSmiley *smiley, size_t *len);
171 * Returns an extension corresponding to the custom smiley's file type.
173 * @param smiley The custom smiley.
175 * @return The custom smiley's extension, "icon" if unknown, or @c NULL if
176 * the image data has disappeared.
178 const char *purple_smiley_get_extension(const PurpleSmiley *smiley);
181 * Returns a full path to an custom smiley.
183 * If the custom smiley has data and the file exists in the cache, this
184 * will return a full path to the cached file.
186 * In general, it is not appropriate to be poking in the file cache
187 * directly. If you find yourself wanting to use this function, think
188 * very long and hard about it, and then don't.
190 * Think some more.
192 * @param smiley The custom smiley.
194 * @return A full path to the file, or @c NULL under various conditions.
195 * The caller should use g_free to free the returned string.
197 char *purple_smiley_get_full_path(PurpleSmiley *smiley);
199 /*@}*/
202 /**************************************************************************/
203 /** @name Custom Smiley Subsystem API */
204 /**************************************************************************/
205 /*@{*/
208 * Returns a list of all custom smileys. The caller is responsible for freeing
209 * the list.
211 * @return A list of all custom smileys.
213 GList *
214 purple_smileys_get_all(void);
217 * Returns a custom smiley given its shortcut.
219 * @param shortcut The custom smiley's shortcut.
221 * @return The custom smiley if found, or @c NULL if not found.
223 PurpleSmiley *
224 purple_smileys_find_by_shortcut(const char *shortcut);
227 * Returns a custom smiley given its checksum.
229 * @param checksum The custom smiley's checksum.
231 * @return The custom smiley if found, or @c NULL if not found.
233 PurpleSmiley *
234 purple_smileys_find_by_checksum(const char *checksum);
237 * Returns the directory used to store custom smiley cached files.
239 * The default directory is PURPLEDIR/custom_smiley.
241 * @return The directory in which to store custom smileys cached files.
243 const char *purple_smileys_get_storing_dir(void);
246 * Initializes the custom smiley subsystem.
248 void purple_smileys_init(void);
251 * Uninitializes the custom smiley subsystem.
253 void purple_smileys_uninit(void);
255 /*@}*/
257 #ifdef __cplusplus
259 #endif
261 #endif /* _PURPLE_SMILEY_H_ */