libpurple/image.c

Sun, 09 Jul 2017 19:42:11 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Sun, 09 Jul 2017 19:42:11 -0500
changeset 38575
9ba990f8a102
parent 38568
9463c7db20fa
child 38576
09ad2b3bbd02
permissions
-rw-r--r--

Refactor the way we generate image filenames and make it not depend on a file extension.

35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
1 /* purple
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
2 *
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
3 * Purple is the legal property of its developers, whose names are too numerous
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
5 * source distribution.
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
6 *
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
10 * (at your option) any later version.
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
11 *
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
15 * GNU General Public License for more details.
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
16 *
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
20 */
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
21
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
22 #include "internal.h"
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
23 #include "glibcompat.h"
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
24
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
25 #include "debug.h"
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
26 #include "image.h"
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
27
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
28 #define PURPLE_IMAGE_GET_PRIVATE(obj) \
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
29 (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_IMAGE, PurpleImagePrivate))
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
30
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
31 typedef struct {
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
32 gchar *path;
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
33
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
34 GBytes *contents;
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
35
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
36 const gchar *extension;
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
37 const gchar *mime;
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
38 gchar *gen_filename;
35829
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
39 gchar *friendly_filename;
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
40 } PurpleImagePrivate;
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
41
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
42 enum {
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
43 PROP_0,
38567
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
44 PROP_PATH,
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
45 PROP_CONTENTS,
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
46 PROP_SIZE,
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
47 PROP_LAST
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
48 };
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
49
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
50 static GParamSpec *properties[PROP_LAST];
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
51
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
52 /******************************************************************************
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
53 * Helpers
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
54 ******************************************************************************/
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
55 static void
38567
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
56 _purple_image_set_path(PurpleImage *image, const gchar *path) {
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
57 PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
58
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
59 g_free(priv->path);
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
60
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
61 priv->path = g_strdup(path);
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
62 }
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
63
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
64 static void
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
65 _purple_image_set_contents(PurpleImage *image, GBytes *bytes) {
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
66 PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
67
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
68 if(priv->contents)
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
69 g_bytes_unref(priv->contents);
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
70
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
71 priv->contents = (bytes) ? g_bytes_ref(bytes) : NULL;
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
72 }
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
73
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
74 /******************************************************************************
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
75 * Object stuff
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
76 ******************************************************************************/
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
77 G_DEFINE_TYPE_WITH_PRIVATE(PurpleImage, purple_image, G_TYPE_OBJECT);
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
78
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
79 static void
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
80 purple_image_init(PurpleImage *image) {
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
81 }
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
82
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
83 static void
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
84 purple_image_finalize(GObject *obj) {
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
85 PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(obj);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
86
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
87 if(priv->contents)
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
88 g_bytes_unref(priv->contents);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
89
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
90 g_free(priv->path);
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
91 g_free(priv->gen_filename);
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
92 g_free(priv->friendly_filename);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
93
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
94 G_OBJECT_CLASS(purple_image_parent_class)->finalize(obj);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
95 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
96
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
97 static void
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
98 purple_image_set_property(GObject *obj, guint param_id,
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
99 const GValue *value, GParamSpec *pspec)
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
100 {
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
101 PurpleImage *image = PURPLE_IMAGE(obj);
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
102
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
103 switch (param_id) {
38567
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
104 case PROP_PATH:
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
105 _purple_image_set_path(image, g_value_get_string(value));
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
106 break;
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
107 case PROP_CONTENTS:
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
108 _purple_image_set_contents(image, g_value_get_boxed(value));
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
109 break;
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
110 default:
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
111 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
112 break;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
113 }
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
114 }
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
115
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
116 static void
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
117 purple_image_get_property(GObject *obj, guint param_id, GValue *value,
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
118 GParamSpec *pspec)
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
119 {
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
120 PurpleImage *image = PURPLE_IMAGE(obj);
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
121
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
122 switch (param_id) {
38567
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
123 case PROP_PATH:
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
124 g_value_set_string(value, purple_image_get_path(image));
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
125 break;
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
126 case PROP_CONTENTS:
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
127 g_value_set_boxed(value, purple_image_get_contents(image));
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
128 break;
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
129 case PROP_SIZE:
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 38295
diff changeset
130 g_value_set_uint64(value, purple_image_get_data_size(image));
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
131 break;
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
132 default:
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
133 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
134 break;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
135 }
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
136 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
137
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
138 static void
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
139 purple_image_class_init(PurpleImageClass *klass) {
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
140 GObjectClass *gobj_class = G_OBJECT_CLASS(klass);
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
141
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
142 gobj_class->finalize = purple_image_finalize;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
143 gobj_class->get_property = purple_image_get_property;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
144 gobj_class->set_property = purple_image_set_property;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
145
38567
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
146 properties[PROP_PATH] = g_param_spec_string(
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
147 "path",
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
148 "path",
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
149 "The filepath for the image if one was provided",
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
150 NULL,
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
151 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
152 );
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
153
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
154 properties[PROP_CONTENTS] = g_param_spec_boxed(
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
155 "contents",
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
156 "contents",
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
157 "The contents of the image stored in a GBytes",
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
158 G_TYPE_BYTES,
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
159 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
160 );
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
161
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
162 properties[PROP_SIZE] = g_param_spec_uint64(
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
163 "size",
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
164 "size",
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
165 "The size of the image in bytes",
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
166 0,
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
167 G_MAXUINT64,
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
168 0,
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
169 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
170 );
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
171
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
172 g_object_class_install_properties(gobj_class, PROP_LAST, properties);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
173 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
174
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
175 /******************************************************************************
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
176 * API
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
177 ******************************************************************************/
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
178 PurpleImage *
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
179 purple_image_new_from_bytes(GBytes *bytes) {
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
180 return g_object_new(
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
181 PURPLE_TYPE_IMAGE,
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
182 "contents", bytes,
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
183 NULL
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
184 );
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
185 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
186
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
187 PurpleImage *
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
188 purple_image_new_from_file(const gchar *path, GError **error) {
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
189 PurpleImage *image = NULL;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
190 GBytes *bytes = NULL;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
191 gchar *contents = NULL;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
192 gsize length = 0;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
193
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
194 if(!g_file_get_contents(path, &contents, &length, error)) {
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
195 return NULL;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
196 }
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
197
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
198 bytes = g_bytes_new_take(contents, length);
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
199
38568
9463c7db20fa Set the path on the image for purple_image_new_from_file, update/add some tests
Gary Kramlich <grim@reaperworld.com>
parents: 38567
diff changeset
200 image = g_object_new(
9463c7db20fa Set the path on the image for purple_image_new_from_file, update/add some tests
Gary Kramlich <grim@reaperworld.com>
parents: 38567
diff changeset
201 PURPLE_TYPE_IMAGE,
9463c7db20fa Set the path on the image for purple_image_new_from_file, update/add some tests
Gary Kramlich <grim@reaperworld.com>
parents: 38567
diff changeset
202 "contents", bytes,
9463c7db20fa Set the path on the image for purple_image_new_from_file, update/add some tests
Gary Kramlich <grim@reaperworld.com>
parents: 38567
diff changeset
203 "path", path,
9463c7db20fa Set the path on the image for purple_image_new_from_file, update/add some tests
Gary Kramlich <grim@reaperworld.com>
parents: 38567
diff changeset
204 NULL
9463c7db20fa Set the path on the image for purple_image_new_from_file, update/add some tests
Gary Kramlich <grim@reaperworld.com>
parents: 38567
diff changeset
205 );
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
206
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
207 g_bytes_unref(bytes);
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
208
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
209 return image;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
210 }
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
211
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
212 PurpleImage *
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
213 purple_image_new_from_data(const guint8 *data, gsize length) {
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
214 PurpleImage *image;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
215 GBytes *bytes = NULL;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
216
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
217 bytes = g_bytes_new(data, length);
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
218
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
219 image = purple_image_new_from_bytes(bytes);
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
220
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
221 g_bytes_unref(bytes);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
222
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
223 return image;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
224 }
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
225
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
226 PurpleImage *
38294
5a797c987eb2 Rename purple_image_new_from_data_take to purple_image_new_take_data
Gary Kramlich <grim@reaperworld.com>
parents: 38293
diff changeset
227 purple_image_new_take_data(guint8 *data, gsize length) {
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
228 PurpleImage *image;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
229 GBytes *bytes = NULL;
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
230
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
231 bytes = g_bytes_new_take(data, length);
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
232
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
233 image = purple_image_new_from_bytes(bytes);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
234
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
235 g_bytes_unref(bytes);
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
236
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
237 return image;
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
238 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
239
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
240 gboolean
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
241 purple_image_save(PurpleImage *image, const gchar *path) {
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
242 PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
35846
07dabf3c0022 PurpleImage: purple_image_get_data should return const buffer
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35843
diff changeset
243 gconstpointer data;
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
244 gsize len;
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
245 gboolean succ;
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
246
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
247 g_return_val_if_fail(priv != NULL, FALSE);
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
248 g_return_val_if_fail(path != NULL, FALSE);
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
249 g_return_val_if_fail(path[0] != '\0', FALSE);
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
250
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
251 data = purple_image_get_data(image);
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 38295
diff changeset
252 len = purple_image_get_data_size(image);
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
253
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
254 g_return_val_if_fail(data != NULL, FALSE);
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
255 g_return_val_if_fail(len > 0, FALSE);
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
256
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
257 succ = purple_util_write_data_to_file_absolute(path, data, len);
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
258 if (succ && priv->path == NULL)
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
259 priv->path = g_strdup(path);
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
260
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
261 return succ;
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
262 }
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
263
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
264 GBytes *
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
265 purple_image_get_contents(const PurpleImage *image) {
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
266 PurpleImagePrivate *priv = NULL;
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
267
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
268 g_return_val_if_fail(PURPLE_IS_IMAGE(image), NULL);
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
269
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
270 priv = PURPLE_IMAGE_GET_PRIVATE(image);
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
271
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
272 if(priv->contents)
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
273 return g_bytes_ref(priv->contents);
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
274
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
275 return NULL;
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
276 }
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
277
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
278 const gchar *
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
279 purple_image_get_path(PurpleImage *image) {
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
280 PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
281
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
282 g_return_val_if_fail(priv != NULL, NULL);
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
283
38567
277d8f0ec6f8 This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked
Gary Kramlich <grim@reaperworld.com>
parents: 38298
diff changeset
284 return priv->path ? priv->path : purple_image_generate_filename(image);
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
285 }
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
286
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
287 gsize
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 38295
diff changeset
288 purple_image_get_data_size(PurpleImage *image) {
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
289 PurpleImagePrivate *priv;
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
290
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
291 g_return_val_if_fail(PURPLE_IS_IMAGE(image), 0);
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
292
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
293 priv = PURPLE_IMAGE_GET_PRIVATE(image);
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
294
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
295 if(priv->contents)
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
296 return g_bytes_get_size(priv->contents);
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
297
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
298 return 0;
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
299 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
300
35846
07dabf3c0022 PurpleImage: purple_image_get_data should return const buffer
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35843
diff changeset
301 gconstpointer
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
302 purple_image_get_data(PurpleImage *image) {
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
303 PurpleImagePrivate *priv = NULL;
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
304
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
305 g_return_val_if_fail(PURPLE_IS_IMAGE(image), NULL);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
306
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
307 priv = PURPLE_IMAGE_GET_PRIVATE(image);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
308
38281
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
309 if(priv->contents)
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
310 return g_bytes_get_data(priv->contents, NULL);
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
311
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
312 return NULL;
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
313 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
314
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
315 const gchar *
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
316 purple_image_get_extension(PurpleImage *image) {
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
317 PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
35846
07dabf3c0022 PurpleImage: purple_image_get_data should return const buffer
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35843
diff changeset
318 gconstpointer data;
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
319
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
320 g_return_val_if_fail(priv != NULL, NULL);
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
321
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
322 if (priv->extension)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
323 return priv->extension;
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
324
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 38295
diff changeset
325 if (purple_image_get_data_size(image) < 4)
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
326 return NULL;
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
327
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
328 data = purple_image_get_data(image);
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
329 g_assert(data != NULL);
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
330
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
331 if (memcmp(data, "GIF8", 4) == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
332 return priv->extension = "gif";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
333 if (memcmp(data, "\xff\xd8\xff", 3) == 0) /* 4th may be e0 through ef */
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
334 return priv->extension = "jpg";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
335 if (memcmp(data, "\x89PNG", 4) == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
336 return priv->extension = "png";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
337 if (memcmp(data, "MM", 2) == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
338 return priv->extension = "tif";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
339 if (memcmp(data, "II", 2) == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
340 return priv->extension = "tif";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
341 if (memcmp(data, "BM", 2) == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
342 return priv->extension = "bmp";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
343 if (memcmp(data, "\x00\x00\x01\x00", 4) == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
344 return priv->extension = "ico";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
345
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
346 return NULL;
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
347 }
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
348
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
349 const gchar *
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
350 purple_image_get_mimetype(PurpleImage *image) {
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
351 PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
352 const gchar *ext = purple_image_get_extension(image);
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
353
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
354 g_return_val_if_fail(priv != NULL, NULL);
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
355
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
356 if (priv->mime)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
357 return priv->mime;
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
358
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
359 g_return_val_if_fail(ext != NULL, NULL);
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
360
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
361 if (g_strcmp0(ext, "gif") == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
362 return priv->mime = "image/gif";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
363 if (g_strcmp0(ext, "jpg") == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
364 return priv->mime = "image/jpeg";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
365 if (g_strcmp0(ext, "png") == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
366 return priv->mime = "image/png";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
367 if (g_strcmp0(ext, "tif") == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
368 return priv->mime = "image/tiff";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
369 if (g_strcmp0(ext, "bmp") == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
370 return priv->mime = "image/bmp";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
371 if (g_strcmp0(ext, "ico") == 0)
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
372 return priv->mime = "image/vnd.microsoft.icon";
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
373
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
374 return NULL;
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
375 }
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
376
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
377 const gchar *
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
378 purple_image_generate_filename(PurpleImage *image) {
38575
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
379 PurpleImagePrivate *priv = NULL;
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
380 GString *str = NULL;
35846
07dabf3c0022 PurpleImage: purple_image_get_data should return const buffer
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35843
diff changeset
381 gconstpointer data;
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
382 gsize len;
38575
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
383 const gchar *ext = NULL;
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
384 gchar *checksum;
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
385
38575
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
386 g_return_val_if_fail(PURPLE_IS_IMAGE(image), NULL);
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
387
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
388 priv = PURPLE_IMAGE_GET_PRIVATE(image);
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
389
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
390 if (priv->gen_filename)
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
391 return priv->gen_filename;
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
392
38575
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
393 /* grab the image's data and size of that data */
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
394 data = purple_image_get_data(image);
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 38295
diff changeset
395 len = purple_image_get_data_size(image);
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
396
38575
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
397 /* create a checksum of it and use it as the start of our filename */
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
398 checksum = g_compute_checksum_for_data(G_CHECKSUM_SHA1, data, len);
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
399 str = g_string_new(checksum);
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
400 g_free(checksum);
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
401
38575
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
402 /* if the image has a known format, set the extension appropriately */
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
403 ext = purple_image_get_extension(image);
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
404 if(ext != NULL)
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
405 g_string_append_printf(str, ".%s", ext);
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
406
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
407 /* free the string but store the result */
9ba990f8a102 Refactor the way we generate image filenames and make it not depend on a file extension.
Gary Kramlich <grim@reaperworld.com>
parents: 38568
diff changeset
408 priv->gen_filename = g_string_free(str, FALSE);
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
409
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
410 return priv->gen_filename;
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
411 }
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
412
35819
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35809
diff changeset
413 void
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
414 purple_image_set_friendly_filename(PurpleImage *image, const gchar *filename) {
35829
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
415 PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
416 gchar *newname;
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
417 const gchar *escaped;
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
418
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
419 g_return_if_fail(priv != NULL);
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
420
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
421 newname = g_path_get_basename(filename);
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
422 escaped = purple_escape_filename(newname);
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
423 g_free(newname);
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
424 newname = NULL;
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
425
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
426 if (g_strcmp0(escaped, "") == 0 || g_strcmp0(escaped, ".") == 0 ||
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
427 g_strcmp0(escaped, G_DIR_SEPARATOR_S) == 0 ||
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
428 g_strcmp0(escaped, "/") == 0 || g_strcmp0(escaped, "\\") == 0)
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
429 {
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
430 escaped = NULL;
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
431 }
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
432
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
433 g_free(priv->friendly_filename);
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
434 priv->friendly_filename = g_strdup(escaped);
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
435 }
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
436
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
437 const gchar *
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
438 purple_image_get_friendly_filename(PurpleImage *image) {
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
439 PurpleImagePrivate *priv = NULL;
35829
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
440
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
441 g_return_val_if_fail(PURPLE_IS_IMAGE(image), NULL);
35829
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
442
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
443 priv = PURPLE_IMAGE_GET_PRIVATE(image);
35829
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
444
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
445 if(priv->friendly_filename) {
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
446 return priv->friendly_filename;
35829
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
447 }
268931512478 imgstore: unref oscar
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35819
diff changeset
448
38295
8344bea0b9c7 Follow what the documentation says for purple_image_get_friendly_filename and generate it if it is not set
Gary Kramlich <grim@reaperworld.com>
parents: 38294
diff changeset
449 return purple_image_generate_filename(image);
35819
cc375b914104 imgstore: remove refs from gg prpl
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35809
diff changeset
450 }
38298
f0a8f63f9312 rename purple_image_get_size to purple_image_get_data_size and deal with the fallout
Gary Kramlich <grim@reaperworld.com>
parents: 38295
diff changeset
451

mercurial