3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #ifndef _PURPLE_IMAGE_H_
23 #define _PURPLE_IMAGE_H_
27 * @section_id: libpurple-image
28 * @short_description: implementation-independent image data container
31 * #PurpleImage object is a container for raw image data. It doesn't manipulate
32 * image data, just stores it in its binary format - png, jpeg etc. Thus, it's
33 * totally independent from the UI.
35 * This class also provides certain file-related features, like: friendly
36 * filenames (not necessarily real filename for displaying); remote images
37 * (which data is not yet loaded) or guessing file format from its header.
40 #include <glib-object.h>
42 typedef struct _PurpleImage PurpleImage
;
43 typedef struct _PurpleImageClass PurpleImageClass
;
45 #define PURPLE_TYPE_IMAGE (purple_image_get_type())
46 #define PURPLE_IMAGE(smiley) (G_TYPE_CHECK_INSTANCE_CAST((smiley), PURPLE_TYPE_IMAGE, PurpleImage))
47 #define PURPLE_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_IMAGE, PurpleImageClass))
48 #define PURPLE_IS_IMAGE(smiley) (G_TYPE_CHECK_INSTANCE_TYPE((smiley), PURPLE_TYPE_IMAGE))
49 #define PURPLE_IS_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_IMAGE))
50 #define PURPLE_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_IMAGE, PurpleImageClass))
55 * An image data container.
66 * Base class for #PurpleImage objects.
68 struct _PurpleImageClass
71 GObjectClass parent_class
;
73 void (*purple_reserved1
)(void);
74 void (*purple_reserved2
)(void);
75 void (*purple_reserved3
)(void);
76 void (*purple_reserved4
)(void);
82 * purple_image_get_type:
84 * Returns: the #GType for an image.
87 purple_image_get_type(void);
90 * purple_image_new_from_file:
91 * @path: the path to the image file.
92 * @be_eager: %TRUE, if file should be loaded now, %FALSE when needed.
94 * Loads an image file as a new #PurpleImage object. The @path must exists, be
95 * readable and should point to a valid image file. If you don't set @be_eager
96 * parameter, there will be a risk that file will be removed from disk before
97 * you access its data.
99 * Returns: the new #PurpleImage.
102 purple_image_new_from_file(const gchar
*path
, gboolean be_eager
);
105 * purple_image_new_from_data:
106 * @data: the pointer to the image data buffer.
107 * @length: the length of @data.
109 * Creates a new #PurpleImage object with contents of @data buffer.
111 * The @data buffer is owned by #PurpleImage object, so you might want
112 * to #g_memdup it first.
114 * Returns: the new #PurpleImage.
117 purple_image_new_from_data(gpointer data
, gsize length
);
122 * @path: destination of a saved image file.
124 * Saves an @image to the disk.
126 * Returns: %TRUE if succeeded, %FALSE otherwise.
129 purple_image_save(PurpleImage
*image
, const gchar
*path
);
132 * purple_image_get_path:
135 * Returns the physical path of the @image file. It is set only, if the @image is
136 * really backed by an existing file. In the other case it returns %NULL.
138 * Returns: the physical path of the @image, or %NULL.
141 purple_image_get_path(PurpleImage
*image
);
144 * purple_image_is_ready:
147 * Checks, if the @image data is ready to be displayed. Remote image data may
148 * not be accessible at the moment, so you should check it before using
149 * #purple_image_get_data. If the image is not ready yet, you may wait for
150 * #PurpleImage::ready signal.
152 * Returns: %TRUE, if the @image is ready.
155 purple_image_is_ready(PurpleImage
*image
);
158 * purple_image_has_failed:
161 * Checks, if the @image has failed to load its data. It can be caused either by
162 * a remote failure (and #purple_image_transfer_failed call) or local file being
163 * removed (see #purple_image_new_from_file).
165 * Returns: %TRUE, if the @image has failed to load.
168 purple_image_has_failed(PurpleImage
*image
);
171 * purple_image_get_size:
174 * Returns the size of @image's data.
176 * Returns: the size of data, or 0 in case of failure.
179 purple_image_get_size(PurpleImage
*image
);
182 * purple_image_get_data:
185 * Returns the pointer to the buffer containing image data.
187 * Returns: (transfer none): the @image data.
190 purple_image_get_data(PurpleImage
*image
);
193 * purple_image_get_extension:
196 * Guesses the @image format based on its contents.
198 * Returns: (transfer none): the file extension suitable for @image format.
201 purple_image_get_extension(PurpleImage
*image
);
204 * purple_image_get_mimetype:
207 * Guesses the @image mime-type based on its contents.
209 * Returns: (transfer none): the mime-type suitable for @image format.
212 purple_image_get_mimetype(PurpleImage
*image
);
215 * purple_image_generate_filename:
218 * Calculates almost-unique filename by computing checksum from file contents
219 * and appending a suitable extension. You should not assume the checksum
220 * is SHA-1, because it may change in the future.
222 * Returns: (transfer none): the generated file name.
225 purple_image_generate_filename(PurpleImage
*image
);
228 * purple_image_set_friendly_filename:
230 * @filename: the friendly filename.
232 * Sets the "friendly filename" for the @image. This don't have to be a real
233 * name, because it's used for displaying or as a default file name when the
234 * user wants to save the @image to the disk.
236 * The provided @filename may either be a full path, or contain
237 * filesystem-unfriendly characters, because it will be reformatted.
240 purple_image_set_friendly_filename(PurpleImage
*image
, const gchar
*filename
);
243 * purple_image_get_friendly_filename:
246 * Returns the "friendly filename" for the @image, to be displayed or used as
247 * a default name when saving a file to the disk.
248 * See #purple_image_set_friendly_filename.
250 * If the friendly filename was not set, it will be generated with
251 * #purple_image_generate_filename.
253 * Returns: (transfer none): the friendly filename.
256 purple_image_get_friendly_filename(PurpleImage
*image
);
259 * purple_image_transfer_new:
261 * Creates a new remote image, with a possibility to load data with
262 * #purple_image_transfer_write and #purple_image_transfer_close. In case of
263 * failure, you should call #urple_image_transfer_failed.
265 * Returns: the new image object.
268 purple_image_transfer_new(void);
271 * purple_image_transfer_write:
273 * @data: the incoming data buffer.
274 * @length: the length of @data.
276 * Adds a chunk of data to the internal receive buffer. Called when receiving
280 purple_image_transfer_write(PurpleImage
*image
, gconstpointer data
,
284 * purple_image_transfer_close:
287 * Marks a remote @image as ready to be displayed. Called when finishing
288 * transfer of remote file. You may call this only once for a certain @image.
291 purple_image_transfer_close(PurpleImage
*image
);
294 * purple_image_transfer_failed:
297 * Marks a remote @image as failed to transfer. Called on error in remote file
298 * transfer. You may call this only once for a certain @image.
301 purple_image_transfer_failed(PurpleImage
*image
);
305 #endif /* _PURPLE_IMAGE_H_ */