This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked

Mon, 05 Jun 2017 20:51:11 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Mon, 05 Jun 2017 20:51:11 -0500
changeset 38567
277d8f0ec6f8
parent 38341
3da74e727e78
child 38568
9463c7db20fa

This should fix up https://github.com/tieto/sipe/issues/147 as paths for smileys were overlooked

libpurple/image.c file | annotate | diff | comparison | revisions
libpurple/smiley.c file | annotate | diff | comparison | revisions
libpurple/tests/test_smiley.c file | annotate | diff | comparison | revisions
--- a/libpurple/image.c	Thu Jun 01 19:59:58 2017 -0500
+++ b/libpurple/image.c	Mon Jun 05 20:51:11 2017 -0500
@@ -41,6 +41,7 @@
 
 enum {
 	PROP_0,
+	PROP_PATH,
 	PROP_CONTENTS,
 	PROP_SIZE,
 	PROP_LAST
@@ -52,6 +53,15 @@
  * Helpers
  ******************************************************************************/
 static void
+_purple_image_set_path(PurpleImage *image, const gchar *path) {
+	PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
+
+	g_free(priv->path);
+
+	priv->path = g_strdup(path);
+}
+
+static void
 _purple_image_set_contents(PurpleImage *image, GBytes *bytes) {
 	PurpleImagePrivate *priv = PURPLE_IMAGE_GET_PRIVATE(image);
 
@@ -91,6 +101,9 @@
 	PurpleImage *image = PURPLE_IMAGE(obj);
 
 	switch (param_id) {
+		case PROP_PATH:
+			_purple_image_set_path(image, g_value_get_string(value));
+			break;
 		case PROP_CONTENTS:
 			_purple_image_set_contents(image, g_value_get_boxed(value));
 			break;
@@ -107,6 +120,9 @@
 	PurpleImage *image = PURPLE_IMAGE(obj);
 
 	switch (param_id) {
+		case PROP_PATH:
+			g_value_set_string(value, purple_image_get_path(image));
+			break;
 		case PROP_CONTENTS:
 			g_value_set_boxed(value, purple_image_get_contents(image));
 			break;
@@ -127,6 +143,14 @@
 	gobj_class->get_property = purple_image_get_property;
 	gobj_class->set_property = purple_image_set_property;
 
+	properties[PROP_PATH] = g_param_spec_string(
+		"path",
+		"path",
+		"The filepath for the image if one was provided",
+		NULL,
+		G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS
+	);
+
 	properties[PROP_CONTENTS] = g_param_spec_boxed(
 		"contents",
 		"contents",
@@ -252,7 +276,7 @@
 
 	g_return_val_if_fail(priv != NULL, NULL);
 
-	return priv->path;
+	return priv->path ? priv->path : purple_image_generate_filename(image);
 }
 
 gsize
--- a/libpurple/smiley.c	Thu Jun 01 19:59:58 2017 -0500
+++ b/libpurple/smiley.c	Mon Jun 05 20:51:11 2017 -0500
@@ -146,6 +146,7 @@
 
 	smiley = g_object_new(
 		PURPLE_TYPE_SMILEY,
+		"path", path,
 		"contents", bytes,
 		"shortcut", shortcut,
 		NULL
--- a/libpurple/tests/test_smiley.c	Thu Jun 01 19:59:58 2017 -0500
+++ b/libpurple/tests/test_smiley.c	Mon Jun 05 20:51:11 2017 -0500
@@ -55,6 +55,7 @@
  *****************************************************************************/
 static void
 _test_smiley(PurpleSmiley *smiley,
+             const gchar *path,
              const guint8 *edata,
              gsize elen,
              const gchar *ext,
@@ -84,9 +85,14 @@
 	);
 	g_assert_cmpstr(purple_smiley_get_shortcut(smiley), ==, shortcut);
 
+	g_assert_cmpstr(purple_image_get_path(PURPLE_IMAGE(smiley)), ==, path);
+
 	g_object_unref(G_OBJECT(smiley));
 }
 
+/******************************************************************************
+ * Tests
+ *****************************************************************************/
 static void
 test_smiley_new_from_data(void) {
 	PurpleSmiley *smiley = purple_smiley_new_from_data(
@@ -97,6 +103,7 @@
 
 	_test_smiley(
 		smiley,
+		purple_image_generate_filename(PURPLE_IMAGE(smiley)),
 		test_image_data,
 		test_image_data_len,
 		"png",
@@ -118,17 +125,19 @@
 	g_assert_no_error(error);
 
 	g_file_get_contents(path, &edata, &elen, &error);
-	g_free(path);
 	g_assert_no_error(error);
 
 	_test_smiley(
 		smiley,
+		path,
 		(guint8 *)edata,
 		elen,
 		"png",
 		"image/png",
 		"^_^"
 	);
+
+	g_free(path);
 }
 
 /******************************************************************************

mercurial