/dev/tomkiewicz/new-smileys: a062d17b15e7: Remote smileys: recei...

Tomasz Wasilczyk twasilczyk at pidgin.im
Fri Apr 4 19:29:18 EDT 2014


Changeset: a062d17b15e753e4e5b9a89c15d6a161f9f0d04a
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-05 01:29 +0200
Branch:	 default
URL: https://hg.pidgin.im/dev/tomkiewicz/new-smileys/rev/a062d17b15e7

Description:

Remote smileys: receive them with MSN

diffstat:

 libpurple/conversation.c      |  25 +++++++++++++++++++++
 libpurple/conversation.h      |   5 ++++
 libpurple/protocols/msn/msg.c |  50 +++++++++++++++++++++++++-----------------
 3 files changed, 60 insertions(+), 20 deletions(-)

diffs (139 lines):

diff --git a/libpurple/conversation.c b/libpurple/conversation.c
--- a/libpurple/conversation.c
+++ b/libpurple/conversation.c
@@ -991,6 +991,31 @@ purple_conversation_add_remote_smiley(Pu
 	return rsmiley;
 }
 
+PurpleRemoteSmiley *
+purple_conversation_get_remote_smiley(PurpleConversation *conv,
+	const gchar *shortcut)
+{
+	PurpleConversationPrivate *priv = PURPLE_CONVERSATION_GET_PRIVATE(conv);
+	PurpleSmiley *smiley;
+
+	g_return_val_if_fail(priv != NULL, NULL);
+	g_return_val_if_fail(shortcut != NULL, NULL);
+	g_return_val_if_fail(shortcut[0] != '\0', NULL);
+
+	if (priv->remote_smileys == NULL)
+		return NULL;
+
+	smiley = purple_smiley_list_get_by_shortcut(
+		priv->remote_smileys, shortcut);
+	if (smiley && !PURPLE_IS_REMOTE_SMILEY(smiley)) {
+		purple_debug_warning("conversation", "Invalid type of smiley "
+			"stored in remote smileys list");
+		return NULL;
+	}
+
+	return PURPLE_REMOTE_SMILEY(smiley);
+}
+
 PurpleSmileyList *
 purple_conversation_get_remote_smileys(PurpleConversation *conv)
 {
diff --git a/libpurple/conversation.h b/libpurple/conversation.h
--- a/libpurple/conversation.h
+++ b/libpurple/conversation.h
@@ -679,6 +679,11 @@ PurpleRemoteSmiley *
 purple_conversation_add_remote_smiley(PurpleConversation *conv,
 	const gchar *shortcut);
 
+/* use it only, if you cannot store purple_conversation_add_remote_smiley output or control its ref */
+PurpleRemoteSmiley *
+purple_conversation_get_remote_smiley(PurpleConversation *conv,
+	const gchar *shortcut);
+
 PurpleSmileyList *
 purple_conversation_get_remote_smileys(PurpleConversation *conv);
 
diff --git a/libpurple/protocols/msn/msg.c b/libpurple/protocols/msn/msg.c
--- a/libpurple/protocols/msn/msg.c
+++ b/libpurple/protocols/msn/msg.c
@@ -896,29 +896,33 @@ msn_p2p_msg(MsnCmdProc *cmdproc, MsnMess
 		purple_debug_warning("msn", "P2P message failed to parse.\n");
 }
 
-#if 0
 static void
-got_emoticon(MsnSlpCall *slpcall,
-			 const guchar *data, gsize size)
+got_emoticon(MsnSlpCall *slpcall, const guchar *data, gsize size)
 {
 	PurpleConversation *conv;
+	PurpleRemoteSmiley *smiley;
 	MsnSwitchBoard *swboard;
+	const gchar *shortcut;
 
 	swboard = slpcall->slplink->swboard;
 	conv = swboard->conv;
+	shortcut = slpcall->data_info;
 
-	if (conv) {
-		/* FIXME: it would be better if we wrote the data as we received it
-		   instead of all at once, calling write multiple times and
-		   close once at the very end
-		 */
-		purple_conversation_custom_smiley_write(conv, slpcall->data_info, data, size);
-		purple_conversation_custom_smiley_close(conv, slpcall->data_info );
-	}
-	if (purple_debug_is_verbose())
-		purple_debug_info("msn", "Got smiley: %s\n", slpcall->data_info);
+	purple_debug_info("msn", "got smiley: %s", shortcut);
+
+	if (!conv)
+		return;
+
+	smiley = purple_conversation_get_remote_smiley(conv, shortcut);
+	g_return_if_fail(smiley);
+
+	/* FIXME: it would be better if we wrote the data as we received it
+	 * instead of all at once, calling write multiple times and close once
+	 * at the very end.
+	 */
+	purple_remote_smiley_write(smiley, data, size);
+	purple_remote_smiley_close(smiley);
 }
-#endif
 
 void msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
 {
@@ -954,6 +958,8 @@ void msn_emoticon_msg(MsnCmdProc *cmdpro
 	g_free(body_str);
 
 	for (tok = 0; tok < 9; tok += 2) {
+		PurpleRemoteSmiley *smiley;
+
 		if (tokens[tok] == NULL || tokens[tok + 1] == NULL) {
 			break;
 		}
@@ -984,18 +990,22 @@ void msn_emoticon_msg(MsnCmdProc *cmdpro
 		/* If the conversation doesn't exist then this is a custom smiley
 		 * used in the first message in a MSN conversation: we need to create
 		 * the conversation now, otherwise the custom smiley won't be shown.
-		 * This happens because every GtkIMHtml has its own smiley tree: if
-		 * the conversation doesn't exist then we cannot associate the new
-		 * smiley with its GtkIMHtml widget. */
+		 * This happens because every PurpleConversation has its own smiley
+		 * tree: if the conversation doesn't exist then we cannot associate
+		 * the new smiley with its PurpleConversation. */
 		if (!conv) {
 			conv = PURPLE_CONVERSATION(purple_im_conversation_new(session->account, who));
 		}
 
-#if 0
-		if (purple_conversation_custom_smiley_add(conv, smile, "sha1", sha1, TRUE)) {
+		smiley = purple_conversation_add_remote_smiley(conv, smile);
+		if (smiley) { /* if not - it was already present */
+			/* TODO: cache lookup by "sha1" */
+
+			/* XXX: maybe handle end_cb and smiley download failures? */
+			/* TODO: BUG: only emoticons from the first message are being received, others are not */
+			purple_debug_info("msn", "requesting smiley: %s", smile);
 			msn_slplink_request_object(slplink, smile, got_emoticon, NULL, obj);
 		}
-#endif
 
 		msn_object_destroy(obj, FALSE);
 		obj =   NULL;



More information about the Commits mailing list