Frameworks/libpurple.framework/Versions/0.6.2/Headers/smiley.h
author Zachary West <zacw@adium.im>
Fri Aug 21 13:25:11 2009 -0700 (2009-08-21)
changeset 2592 e8d15275025e
parent 2069 Frameworks/libpurple.framework/Versions/0.6.0/Headers/smiley.h@1346acdb9a2b
permissions -rw-r--r--
im.pidgin.adium.1-4 at 267c6165e02e34318a1823960bd04c0639952f73
     1 /**
     2  * @file smiley.h Smiley API
     3  * @ingroup core
     4  * @since 2.5.0
     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  */
    28 
    29 #ifndef _PURPLE_SMILEY_H_
    30 #define _PURPLE_SMILEY_H_
    31 
    32 #include <glib-object.h>
    33 
    34 #include "imgstore.h"
    35 #include "util.h"
    36 
    37 /**
    38  * A custom smiley.
    39  * This contains everything Purple will ever need to know about a custom smiley.
    40  * Everything.
    41  *
    42  * PurpleSmiley is a GObject.
    43  */
    44 typedef struct _PurpleSmiley        PurpleSmiley;
    45 typedef struct _PurpleSmileyClass   PurpleSmileyClass;
    46 
    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))
    53 
    54 #ifdef __cplusplus
    55 extern "C" {
    56 #endif
    57 
    58 /**************************************************************************/
    59 /** @name Custom Smiley API                                               */
    60 /**************************************************************************/
    61 /*@{*/
    62 
    63 /**
    64  * GObject-fu.
    65  * @internal.
    66  */
    67 GType purple_smiley_get_type(void);
    68 
    69 /**
    70  * Creates a new custom smiley from a PurpleStoredImage.
    71  *
    72  * If a custom smiley with the given shortcut already exists, it
    73  * will be automaticaly returned.
    74  *
    75  * @param img         The image associated with the smiley.
    76  * @param shortcut    The associated shortcut (e.g. "(homer)").
    77  *
    78  * @return The custom smiley.
    79  */
    80 PurpleSmiley *
    81 purple_smiley_new(PurpleStoredImage *img, const char *shortcut);
    82 
    83 /**
    84  * Creates a new custom smiley, reading the image data from a file.
    85  *
    86  * If a custom smiley with the given shortcut already exists, it
    87  * will be automaticaly returned.
    88  *
    89  * @param shortcut           The associated shortcut (e.g. "(homer)").
    90  * @param filepath           The image file.
    91  *
    92  * @return The custom smiley.
    93  */
    94 PurpleSmiley *
    95 purple_smiley_new_from_file(const char *shortcut, const char *filepath);
    96 
    97 /**
    98  * Destroys the custom smiley and release the associated resources.
    99  *
   100  * @param smiley    The custom smiley.
   101  */
   102 void
   103 purple_smiley_delete(PurpleSmiley *smiley);
   104 
   105 /**
   106  * Changes the custom smiley's shortcut.
   107  *
   108  * @param smiley    The custom smiley.
   109  * @param shortcut  The new shortcut. A custom smiley with this shortcut
   110  *                  cannot already be in use.
   111  *
   112  * @return TRUE if the shortcut was changed. FALSE otherwise.
   113  */
   114 gboolean
   115 purple_smiley_set_shortcut(PurpleSmiley *smiley, const char *shortcut);
   116 
   117 /**
   118  * Changes the custom smiley's image data.
   119  *
   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.
   124  */
   125 void
   126 purple_smiley_set_data(PurpleSmiley *smiley, guchar *smiley_data,
   127                                            size_t smiley_data_len);
   128 
   129 /**
   130  * Returns the custom smiley's associated shortcut (e.g. "(homer)").
   131  *
   132  * @param smiley   The custom smiley.
   133  *
   134  * @return The shortcut.
   135  */
   136 const char *purple_smiley_get_shortcut(const PurpleSmiley *smiley);
   137 
   138 /**
   139  * Returns the custom smiley data's checksum.
   140  *
   141  * @param smiley   The custom smiley.
   142  *
   143  * @return The checksum.
   144  */
   145 const char *purple_smiley_get_checksum(const PurpleSmiley *smiley);
   146 
   147 /**
   148  * Returns the PurpleStoredImage with the reference counter incremented.
   149  *
   150  * The returned PurpleStoredImage reference counter must be decremented
   151  * when the caller is done using it.
   152  *
   153  * @param smiley   The custom smiley.
   154  *
   155  * @return A PurpleStoredImage.
   156  */
   157 PurpleStoredImage *purple_smiley_get_stored_image(const PurpleSmiley *smiley);
   158 
   159 /**
   160  * Returns the custom smiley's data.
   161  *
   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.
   165  *
   166  * @return A pointer to the custom smiley data.
   167  */
   168 gconstpointer purple_smiley_get_data(const PurpleSmiley *smiley, size_t *len);
   169 
   170 /**
   171  * Returns an extension corresponding to the custom smiley's file type.
   172  *
   173  * @param smiley  The custom smiley.
   174  *
   175  * @return The custom smiley's extension, "icon" if unknown, or @c NULL if
   176  *         the image data has disappeared.
   177  */
   178 const char *purple_smiley_get_extension(const PurpleSmiley *smiley);
   179 
   180 /**
   181  * Returns a full path to an custom smiley.
   182  *
   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.
   185  *
   186  * In general, it is not appropriate to be poking in the file cached
   187  * directly.  If you find yourself wanting to use this function, think
   188  * very long and hard about it, and then don't.
   189  *
   190  * Think some more.
   191  *
   192  * @param smiley  The custom smiley.
   193  *
   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.
   196  */
   197 char *purple_smiley_get_full_path(PurpleSmiley *smiley);
   198 
   199 /*@}*/
   200 
   201 
   202 /**************************************************************************/
   203 /** @name Custom Smiley Subsystem API                                     */
   204 /**************************************************************************/
   205 /*@{*/
   206 
   207 /**
   208  * Returns a list of all custom smileys. The caller is responsible for freeing
   209  * the list.
   210  *
   211  * @return A list of all custom smileys.
   212  */
   213 GList *
   214 purple_smileys_get_all(void);
   215 
   216 /**
   217  * Returns a custom smiley given its shortcut.
   218  *
   219  * @param shortcut The custom smiley's shortcut.
   220  *
   221  * @return The custom smiley if found, or @c NULL if not found.
   222  */
   223 PurpleSmiley *
   224 purple_smileys_find_by_shortcut(const char *shortcut);
   225 
   226 /**
   227  * Returns a custom smiley given its checksum.
   228  *
   229  * @param checksum The custom smiley's checksum.
   230  *
   231  * @return The custom smiley if found, or @c NULL if not found.
   232  */
   233 PurpleSmiley *
   234 purple_smileys_find_by_checksum(const char *checksum);
   235 
   236 /**
   237  * Returns the directory used to store custom smiley cached files.
   238  *
   239  * The default directory is PURPLEDIR/custom_smiley.
   240  *
   241  * @return The directory in which to store custom smileys cached files.
   242  */
   243 const char *purple_smileys_get_storing_dir(void);
   244 
   245 /**
   246  * Initializes the custom smiley subsystem.
   247  */
   248 void purple_smileys_init(void);
   249 
   250 /**
   251  * Uninitializes the custom smiley subsystem.
   252  */
   253 void purple_smileys_uninit(void);
   254 
   255 /*@}*/
   256 
   257 #ifdef __cplusplus
   258 }
   259 #endif
   260 
   261 #endif /* _PURPLE_SMILEY_H_ */
   262