Frameworks/libpurple.framework/Versions/2.10.12r8d2874a79747/Headers/imgstore.h
branchadium-1.5.11
changeset 6014 fcb71cb71a3d
parent 5941 307f53385811
parent 6013 f8d0dc659e3f
child 6016 325e2ab3406f
equal deleted inserted replaced
5941:307f53385811 6014:fcb71cb71a3d
     1 /**
       
     2  * @file imgstore.h IM Image Store API
       
     3  * @ingroup core
       
     4  * @see @ref imgstore-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_IMGSTORE_H_
       
    28 #define _PURPLE_IMGSTORE_H_
       
    29 
       
    30 #include <glib.h>
       
    31 
       
    32 /**
       
    33  * A set of utility functions that provide a reference-counted immutable
       
    34  * wrapper around an image's data and filename.  These functions do not
       
    35  * cache any data to disk.
       
    36  */
       
    37 typedef struct _PurpleStoredImage PurpleStoredImage;
       
    38 
       
    39 #ifdef __cplusplus
       
    40 extern "C" {
       
    41 #endif
       
    42 
       
    43 /**
       
    44  * Create a new PurpleStoredImage.
       
    45  *
       
    46  * Despite the name of this function, the image is NOT added to the image
       
    47  * store and no ID is assigned.  If you need to reference the image by an
       
    48  * ID, use purple_imgstore_add_with_id() instead.
       
    49  *
       
    50  * The caller owns a reference to this image and must dereference it with
       
    51  * purple_imgstore_unref() for it to be freed.
       
    52  *
       
    53  * @param data      Pointer to the image data, which the imgstore will take
       
    54  *                  ownership of and free as appropriate.  If you want a
       
    55  *                  copy of the data, make it before calling this function.
       
    56  * @param size      Image data's size.
       
    57  * @param filename  Filename associated with image.  This is for your
       
    58  *                  convenience.  It could be the full path to the
       
    59  *                  image or, more commonly, the filename of the image
       
    60  *                  without any directory information.  It can also be
       
    61  *                  NULL, if you don't need to keep track of a filename.
       
    62  *
       
    63  * @return The stored image, or NULL if the image was not added (because of
       
    64  *         empty data or size).
       
    65  */
       
    66 PurpleStoredImage *
       
    67 purple_imgstore_add(gpointer data, size_t size, const char *filename);
       
    68 
       
    69 /**
       
    70  * Create a PurpleStoredImage using purple_imgstore_add() by reading the
       
    71  * given filename from disk.
       
    72  *
       
    73  * The image is not added to the image store and no ID is assigned.  If you
       
    74  * need to reference the image by an ID, use purple_imgstore_add_with_id()
       
    75  * instead.
       
    76  *
       
    77  * The caller owns a reference to this image and must dereference it with
       
    78  * purple_imgstore_unref() for it to be freed.
       
    79  *
       
    80  * @param path  The path to the image.
       
    81  *
       
    82  * @return The stored image, or NULL if the image was not added (because of
       
    83  *         empty data or size).
       
    84  *
       
    85  * @since 2.5.0
       
    86  */
       
    87 PurpleStoredImage *
       
    88 purple_imgstore_new_from_file(const char *path);
       
    89 
       
    90 /**
       
    91  * Create a PurpleStoredImage using purple_imgstore_add() and add the
       
    92  * image to the image store.  A unique ID will be assigned to the image.
       
    93  *
       
    94  * The caller owns a reference to the image and must dereference it with
       
    95  * purple_imgstore_unref() or purple_imgstore_unref_by_id() for it to be
       
    96  * freed.
       
    97  *
       
    98  * @param data      Pointer to the image data, which the imgstore will take
       
    99  *                  ownership of and free as appropriate.  If you want a
       
   100  *                  copy of the data, make it before calling this function.
       
   101  * @param size      Image data's size.
       
   102  * @param filename  Filename associated with image.  This is for your
       
   103  *                  convenience.  It could be the full path to the
       
   104  *                  image or, more commonly, the filename of the image
       
   105  *                  without any directory information.  It can also be
       
   106  *                  NULL, if you don't need to keep track of a filename.
       
   107  *
       
   108  * @return ID for the image.  This is a unique number that can be used
       
   109  *         within libpurple to reference the image.  0 is returned if the
       
   110  *         image was not added (because of empty data or size).
       
   111  */
       
   112 int purple_imgstore_add_with_id(gpointer data, size_t size, const char *filename);
       
   113 
       
   114 /**
       
   115  * Retrieve an image from the store. The caller does not own a
       
   116  * reference to the image.
       
   117  *
       
   118  * @param id The ID for the image.
       
   119  *
       
   120  * @return A pointer to the requested image, or NULL if it was not found.
       
   121  */
       
   122 PurpleStoredImage *purple_imgstore_find_by_id(int id);
       
   123 
       
   124 /**
       
   125  * Retrieves a pointer to the image's data.
       
   126  *
       
   127  * @param img The Image.
       
   128  *
       
   129  * @return A pointer to the data, which must not
       
   130  *         be freed or modified.
       
   131  */
       
   132 gconstpointer purple_imgstore_get_data(PurpleStoredImage *img);
       
   133 
       
   134 /**
       
   135  * Retrieves the length of the image's data.
       
   136  *
       
   137  * @param img The Image.
       
   138  *
       
   139  * @return The size of the data that the pointer returned by
       
   140  *         purple_imgstore_get_data points to.
       
   141  */
       
   142 size_t purple_imgstore_get_size(PurpleStoredImage *img);
       
   143 
       
   144 /**
       
   145  * Retrieves a pointer to the image's filename.
       
   146  *
       
   147  * @param img The image.
       
   148  *
       
   149  * @return A pointer to the filename, which must not
       
   150  *         be freed or modified.
       
   151  */
       
   152 const char *purple_imgstore_get_filename(const PurpleStoredImage *img);
       
   153 
       
   154 /**
       
   155  * Looks at the magic numbers of the image data (the first few bytes)
       
   156  * and returns an extension corresponding to the image's file type.
       
   157  *
       
   158  * @param img The image.
       
   159  *
       
   160  * @return The image's extension (for example "png") or "icon"
       
   161  *         if unknown.
       
   162  */
       
   163 const char *purple_imgstore_get_extension(PurpleStoredImage *img);
       
   164 
       
   165 /**
       
   166  * Increment the reference count.
       
   167  *
       
   168  * @param img The image.
       
   169  *
       
   170  * @return @a img
       
   171  */
       
   172 PurpleStoredImage *
       
   173 purple_imgstore_ref(PurpleStoredImage *img);
       
   174 
       
   175 /**
       
   176  * Decrement the reference count.
       
   177  *
       
   178  * If the reference count reaches zero, the image will be freed.
       
   179  *
       
   180  * @param img The image.
       
   181  *
       
   182  * @return @a img or @c NULL if the reference count reached zero.
       
   183  */
       
   184 PurpleStoredImage *
       
   185 purple_imgstore_unref(PurpleStoredImage *img);
       
   186 
       
   187 /**
       
   188  * Increment the reference count using an ID.
       
   189  *
       
   190  * This is a convience wrapper for purple_imgstore_find_by_id() and
       
   191  * purple_imgstore_ref(), so if you have a PurpleStoredImage, it'll
       
   192  * be more efficient to call purple_imgstore_ref() directly.
       
   193  *
       
   194  * @param id The ID for the image.
       
   195  */
       
   196 void purple_imgstore_ref_by_id(int id);
       
   197 
       
   198 /**
       
   199  * Decrement the reference count using an ID.
       
   200  *
       
   201  * This is a convience wrapper for purple_imgstore_find_by_id() and
       
   202  * purple_imgstore_unref(), so if you have a PurpleStoredImage, it'll
       
   203  * be more efficient to call purple_imgstore_unref() directly.
       
   204  *
       
   205  * @param id The ID for the image.
       
   206  */
       
   207 void purple_imgstore_unref_by_id(int id);
       
   208 
       
   209 /**
       
   210  * Returns the image store subsystem handle.
       
   211  *
       
   212  * @return The subsystem handle.
       
   213  */
       
   214 void *purple_imgstore_get_handle(void);
       
   215 
       
   216 /**
       
   217  * Initializes the image store subsystem.
       
   218  */
       
   219 void purple_imgstore_init(void);
       
   220 
       
   221 /**
       
   222  * Uninitializes the image store subsystem.
       
   223  */
       
   224 void purple_imgstore_uninit(void);
       
   225 
       
   226 #ifdef __cplusplus
       
   227 }
       
   228 #endif
       
   229 
       
   230 #endif /* _PURPLE_IMGSTORE_H_ */