/dev/tomkiewicz/new-smileys: db721872a325: Remote smileys: displ...

Tomasz Wasilczyk twasilczyk at pidgin.im
Fri Apr 4 10:32:30 EDT 2014


Changeset: db721872a325b1e7623bc86d910446f108fdef57
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-04 16:32 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/db721872a325

Description:

Remote smileys: display them

diffstat:

 libpurple/imgstore.c |  30 ++++++++++++++++++++++--------
 libpurple/imgstore.h |   3 +++
 pidgin/gtkconv.c     |  14 ++++++++++----
 3 files changed, 35 insertions(+), 12 deletions(-)

diffs (91 lines):

diff --git a/libpurple/imgstore.c b/libpurple/imgstore.c
--- a/libpurple/imgstore.c
+++ b/libpurple/imgstore.c
@@ -83,10 +83,23 @@ purple_imgstore_new_from_file(const char
 int
 purple_imgstore_new_with_id(gpointer data, size_t size, const char *filename)
 {
-	PurpleStoredImage *img = purple_imgstore_new(data, size, filename);
-	if (!img) {
-		return 0;
-	}
+	PurpleStoredImage *image;
+	int id;
+
+	image = purple_imgstore_new(data, size, filename);
+	id = purple_imgstore_add_with_id(image);
+	purple_imgstore_unref(image);
+
+	return id;
+}
+
+int
+purple_imgstore_add_with_id(PurpleStoredImage *image)
+{
+	g_return_val_if_fail(image != NULL, 0);
+
+	if (image->id != 0)
+		return image->id;
 
 	/*
 	 * Use the next unused id number.  We do it in a loop on the
@@ -94,12 +107,13 @@ purple_imgstore_new_with_id(gpointer dat
 	 * table still contains entries from the first time around.
 	 */
 	do {
-		img->id = ++nextid;
-	} while (img->id == 0 || g_hash_table_lookup(imgstore, &(img->id)) != NULL);
+		image->id = ++nextid;
+	} while (image->id == 0 || g_hash_table_lookup(imgstore, &(image->id)) != NULL);
 
-	g_hash_table_insert(imgstore, &(img->id), img);
+	purple_imgstore_ref(image);
+	g_hash_table_insert(imgstore, &(image->id), image);
 
-	return img->id;
+	return image->id;
 }
 
 PurpleStoredImage *purple_imgstore_find_by_id(int id)
diff --git a/libpurple/imgstore.h b/libpurple/imgstore.h
--- a/libpurple/imgstore.h
+++ b/libpurple/imgstore.h
@@ -148,6 +148,9 @@ purple_imgstore_new_from_file(const char
  */
 int purple_imgstore_new_with_id(gpointer data, size_t size, const char *filename);
 
+int
+purple_imgstore_add_with_id(PurpleStoredImage *image);
+
 /**
  * purple_imgstore_find_by_id:
  * @id: The ID for the image.
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -6590,15 +6590,21 @@ pidgin_conv_write_smiley(GString *out, P
 	const gchar *proto_name = _proto_name;
 #endif
 	gchar *escaped_shortcut;
+	const gchar *path = purple_smiley_get_path(smiley);
 
 	escaped_shortcut = g_markup_escape_text(
 		purple_smiley_get_shortcut(smiley), -1);
 
-	if (purple_smiley_is_ready(smiley)) {
-		/* XXX: purple_smiley_get_path(smiley) may be NULL
-		 * (for remote smileys) */
+	if (purple_smiley_is_ready(smiley) && path) {
 		g_string_append_printf(out, "<img alt=\"%s\" src=\"%s\" />",
-			escaped_shortcut, purple_smiley_get_path(smiley));
+			escaped_shortcut, path);
+	} else if (purple_smiley_is_ready(smiley) && !path) {
+		PurpleStoredImage *img = purple_smiley_get_image(smiley);
+		int imgid = purple_imgstore_add_with_id(img);
+
+		g_string_append_printf(out, "<img alt=\"%s\" src=\""
+			PURPLE_STORED_IMAGE_PROTOCOL "%d\" />",
+			escaped_shortcut, imgid);
 	} else {
 		/* TODO: remove this background, maybe put something into css file? */
 		g_string_append_printf(out,



More information about the Commits mailing list