libpurple/purpleimage.c

Thu, 07 Aug 2025 21:32:18 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Thu, 07 Aug 2025 21:32:18 -0500
changeset 43300
0604c6839974
parent 43071
libpurple/image.c@071588186662
permissions
-rw-r--r--

Clean up and modernize PurpleImage

Testing Done:
Ran the tests under valgrind and called in the turtles.

Reviewed at https://reviews.imfreedom.org/r/4074/

42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
1 /*
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
2 * Purple - Internet Messaging Library
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
3 * Copyright (C) Pidgin Developers <devel@pidgin.im>
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
4 *
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
5 * Purple is the legal property of its developers, whose names are too numerous
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
6 * to list here. Please refer to the COPYRIGHT file distributed with this
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
7 * source distribution.
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
8 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
9 * This library is free software; you can redistribute it and/or modify it
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
10 * under the terms of the GNU General Public License as published by the Free
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
11 * Software Foundation; either version 2 of the License, or (at your option)
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
12 * any later version.
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
13 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
14 * This library is distributed in the hope that it will be useful, but WITHOUT
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
17 * more details.
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
18 *
42594
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
19 * You should have received a copy of the GNU General Public License along with
eddde70cedd8 Create a test for verifying license headers and correct the ones that were wrong
Gary Kramlich <grim@reaperworld.com>
parents: 42584
diff changeset
20 * this library; if not, see <https://www.gnu.org/licenses/>.
35800
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
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
23 #include <birb.h>
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
24
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
25 #include "purpleimage.h"
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
26
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
27 struct _PurpleImage {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
28 GObject parent;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
29
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
30 char *filename;
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
31
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
32 GBytes *contents;
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
33 };
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
34
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
35 enum {
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
36 PROP_0,
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
37 PROP_CONTENTS,
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
38 PROP_DATA,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
39 PROP_FILENAME,
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
40 PROP_SIZE,
42584
687260353985 Make signal and property enums and initializers consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41960
diff changeset
41 N_PROPERTIES,
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
42 };
42584
687260353985 Make signal and property enums and initializers consistent
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 41960
diff changeset
43 static GParamSpec *properties[N_PROPERTIES] = {NULL, };
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
44
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
45 /******************************************************************************
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
46 * Helpers
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
47 *****************************************************************************/
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
48 static void
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
49 purple_image_set_filename(PurpleImage *image, const char *filename) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
50 g_return_if_fail(PURPLE_IS_IMAGE(image));
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
51
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
52 if(g_set_str(&image->filename, filename)) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
53 g_object_notify_by_pspec(G_OBJECT(image), properties[PROP_FILENAME]);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
54 }
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
55 }
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
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 static void
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
58 purple_image_set_contents(PurpleImage *image, GBytes *contents) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
59 g_return_if_fail(PURPLE_IS_IMAGE(image));
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
60
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
61 if(image->contents != contents) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
62 GObject *obj = G_OBJECT(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
63
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
64 g_clear_pointer(&image->contents, g_bytes_unref);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
65 if(contents != NULL) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
66 image->contents = g_bytes_ref(contents);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
67 }
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
68
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
69 g_object_freeze_notify(obj);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
70 g_object_notify_by_pspec(G_OBJECT(image), properties[PROP_CONTENTS]);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
71 g_object_notify_by_pspec(G_OBJECT(image), properties[PROP_DATA]);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
72 g_object_notify_by_pspec(G_OBJECT(image), properties[PROP_SIZE]);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
73 g_object_thaw_notify(obj);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
74 }
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
75 }
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
76
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 /******************************************************************************
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
78 * GObject Implementation
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
79 *****************************************************************************/
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
80 G_DEFINE_FINAL_TYPE(PurpleImage, purple_image, G_TYPE_OBJECT);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
81
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
82 static void
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
83 purple_image_finalize(GObject *obj) {
39545
77379050b5f7 Use G_DECLARE* for PurpleImage and drop private macro.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38576
diff changeset
84 PurpleImage *image = PURPLE_IMAGE(obj);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
85
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
86 g_clear_pointer(&image->contents, g_bytes_unref);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
87 g_clear_pointer(&image->filename, g_free);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
88
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
89 G_OBJECT_CLASS(purple_image_parent_class)->finalize(obj);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
90 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
91
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
92 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
93 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
94 GParamSpec *pspec)
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
95 {
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
96 PurpleImage *image = PURPLE_IMAGE(obj);
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
97 gsize size = 0;
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
df274be2afa2 A bunch more hack and slash with a bit more design on the fly
Gary Kramlich <grim@reaperworld.com>
parents: 38278
diff changeset
99 switch (param_id) {
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
100 case PROP_CONTENTS:
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
101 g_value_set_boxed(value, purple_image_get_contents(image));
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
102 break;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
103 case PROP_DATA:
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
104 g_value_set_pointer(value,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
105 (gpointer)purple_image_get_data(image, NULL));
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
106 break;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
107 case PROP_FILENAME:
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
108 g_value_set_string(value, purple_image_get_filename(image));
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
109 break;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
110 case PROP_SIZE:
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
111 purple_image_get_data(image, &size);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
112 g_value_set_uint64(value, size);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
113 break;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
114 default:
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
115 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
116 break;
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
117 }
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
118 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
119
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
120 static void
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
121 purple_image_set_property(GObject *obj, guint param_id, const GValue *value,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
122 GParamSpec *pspec)
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
123 {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
124 PurpleImage *image = PURPLE_IMAGE(obj);
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
125
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
126 switch (param_id) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
127 case PROP_FILENAME:
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
128 purple_image_set_filename(image, g_value_get_string(value));
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
129 break;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
130 case PROP_CONTENTS:
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
131 purple_image_set_contents(image, g_value_get_boxed(value));
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
132 break;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
133 default:
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
134 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
135 break;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
136 }
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
137 }
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
138
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
139 static void
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
140 purple_image_init(G_GNUC_UNUSED PurpleImage *image) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
141 }
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
142
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
143 static void
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
144 purple_image_class_init(PurpleImageClass *klass) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
145 GObjectClass *obj_class = G_OBJECT_CLASS(klass);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
146
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
147 obj_class->finalize = purple_image_finalize;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
148 obj_class->get_property = purple_image_get_property;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
149 obj_class->set_property = purple_image_set_property;
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
150
42656
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
151 /**
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
152 * PurpleImage:contents:
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
153 *
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
154 * The contents of the image.
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
155 *
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
156 * Since: 3.0
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
157 */
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
158 properties[PROP_CONTENTS] = g_param_spec_boxed(
43071
071588186662 Remove nick and blurb from libpurple properties
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42767
diff changeset
159 "contents", NULL, NULL,
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
160 G_TYPE_BYTES,
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
161 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS |
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
162 G_PARAM_EXPLICIT_NOTIFY);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
163
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
164 /**
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
165 * PurpleImage:data:
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
166 *
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
167 * The raw image data.
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
168 *
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
169 * Generally the [property@Image:contents] property should be used, but if
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
170 * just the data is necessary this saves a step.
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
171 *
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
172 * Since: 3.0
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
173 */
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
174 properties[PROP_DATA] = g_param_spec_pointer(
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
175 "data", NULL, NULL,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
176 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
177
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
178 /**
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
179 * PurpleImage:filename:
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
180 *
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
181 * The filename for the image if one was provided.
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
182 *
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
183 * Since: 3.0
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
184 */
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
185 properties[PROP_FILENAME] = g_param_spec_string(
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
186 "filename", NULL, NULL,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
187 NULL,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
188 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS |
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
189 G_PARAM_EXPLICIT_NOTIFY);
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
190
42656
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
191 /**
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
192 * PurpleImage:size:
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
193 *
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
194 * The size of the image in bytes.
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
195 *
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
196 * Since: 3.0
df9aafbae930 Add a doc-check unit test to libpurple and fix the issues it has found
Gary Kramlich <grim@reaperworld.com>
parents: 42594
diff changeset
197 */
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
198 properties[PROP_SIZE] = g_param_spec_uint64(
43071
071588186662 Remove nick and blurb from libpurple properties
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42767
diff changeset
199 "size", NULL, NULL,
071588186662 Remove nick and blurb from libpurple properties
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42767
diff changeset
200 0, G_MAXUINT64, 0,
071588186662 Remove nick and blurb from libpurple properties
Elliott Sales de Andrade <quantum.analyst@gmail.com>
parents: 42767
diff changeset
201 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
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
202
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
203 g_object_class_install_properties(obj_class, N_PROPERTIES, properties);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
204 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
205
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
206 /******************************************************************************
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
207 * Public API
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
208 *****************************************************************************/
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
209 GBytes *
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
210 purple_image_get_contents(PurpleImage *image) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
211 g_return_val_if_fail(PURPLE_IS_IMAGE(image), NULL);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
212
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
213 return image->contents;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
214 }
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
215
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
216 gconstpointer
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
217 purple_image_get_data(PurpleImage *image, gsize *size) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
218 g_return_val_if_fail(PURPLE_IS_IMAGE(image), NULL);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
219
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
220 if(image->contents != NULL) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
221 return g_bytes_get_data(image->contents, size);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
222 }
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
223
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
224 return NULL;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
225 }
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
226
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
227 const char *
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
228 purple_image_get_filename(PurpleImage *image) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
229 g_return_val_if_fail(PURPLE_IS_IMAGE(image), NULL);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
230
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
231 return image->filename;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
232 }
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
233
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
234 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
235 purple_image_new_from_bytes(GBytes *bytes) {
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
236 g_return_val_if_fail(bytes != NULL, NULL);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
237
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
238 return g_object_new(
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
239 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
240 "contents", bytes,
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
241 NULL);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
242 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
243
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
244 PurpleImage *
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
245 purple_image_new_from_data(gconstpointer data, gsize size) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
246 PurpleImage *image = NULL;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
247 GBytes *contents = NULL;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
248
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
249 g_return_val_if_fail(data != NULL, NULL);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
250 g_return_val_if_fail(size > 0, NULL);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
251
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
252 contents = g_bytes_new(data, size);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
253
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
254 image = g_object_new(
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
255 PURPLE_TYPE_IMAGE,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
256 "contents", contents,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
257 NULL);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
258
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
259 g_bytes_unref(contents);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
260
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
261 return image;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
262 }
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
263
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
264 PurpleImage *
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
265 purple_image_new_from_filename(const char *filename, GError **error) {
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
266 PurpleImage *image = NULL;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
267 GBytes *bytes = NULL;
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
268 GError *local_error = NULL;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
269 char *contents = NULL;
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
270 gsize length = 0;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
271
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
272 if(!g_file_get_contents(filename, &contents, &length, &local_error)) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
273 g_propagate_error(error, local_error);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
274
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
275 return NULL;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
276 }
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
278 bytes = g_bytes_new_take(contents, length);
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
279
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
280 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
281 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
282 "contents", bytes,
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
283 "filename", filename,
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
284 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
285 );
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
286
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
287 g_bytes_unref(bytes);
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
288
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
289 return image;
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
290 }
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
291
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
292 PurpleImage *
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
293 purple_image_new_from_resource(const char *path, GError **error) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
294 PurpleImage *image = NULL;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
295 GBytes *contents = NULL;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
296 GError *local_error = NULL;
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
297
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
298 g_return_val_if_fail(!birb_str_is_empty(path), NULL);
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
299
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
300 contents = g_resources_lookup_data(path, G_RESOURCE_LOOKUP_FLAGS_NONE,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
301 &local_error);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
302
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
303 if(local_error != NULL) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
304 g_clear_pointer(&contents, g_bytes_unref);
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
305
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
306 g_propagate_error(error, local_error);
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
307
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
308 return NULL;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
309 }
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
310
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
311 image = g_object_new(
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
312 PURPLE_TYPE_IMAGE,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
313 "contents", contents,
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
314 NULL);
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
315
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
316 g_clear_pointer(&contents, g_bytes_unref);
38277
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
317
061e91dd78d4 first pass at cleaning up PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 36049
diff changeset
318 return image;
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
319 }
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
320
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
321 gboolean
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
322 purple_image_save(PurpleImage *image, const char *filename, GError **error) {
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
323 gconstpointer data = NULL;
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
324 gsize size = 0;
35809
6dd40b244ce3 PurpleImage: convert buddyicon.c
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35806
diff changeset
325
39545
77379050b5f7 Use G_DECLARE* for PurpleImage and drop private macro.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38576
diff changeset
326 g_return_val_if_fail(PURPLE_IS_IMAGE(image), FALSE);
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
327 g_return_val_if_fail(!birb_str_is_empty(filename), FALSE);
35800
2c21828e7442 PurpleImage: initial implementation
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
diff changeset
328
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
329 data = g_bytes_get_data(image->contents, &size);
39545
77379050b5f7 Use G_DECLARE* for PurpleImage and drop private macro.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 38576
diff changeset
330
43300
0604c6839974 Clean up and modernize PurpleImage
Gary Kramlich <grim@reaperworld.com>
parents: 43071
diff changeset
331 return g_file_set_contents(filename, data, size, error);
35801
9cdf2c4d5a7a PurpleImage: extension and mime type retrieval
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35800
diff changeset
332 }

mercurial