changeset 28076:c51d9e31ec22

merge of '375487659d7425062cb32079e5be08ac45951bd8' and '458e696572314f8fd2d259d40713ad955dd82581'
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 23 Aug 2009 03:32:19 +0000
parents 36c6601d650a (diff) 208f4d20ac5d (current diff)
children 3571b38c1a7e
files
diffstat 4 files changed, 50 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Aug 23 02:11:21 2009 +0000
+++ b/ChangeLog	Sun Aug 23 03:32:19 2009 +0000
@@ -4,6 +4,7 @@
 	libpurple:
 	* Fix --disable-avahi to actually disable it in configure, as opposed
 	  to just making the warning non-fatal.
+	* Sending custom smileys in MSN chats is now supported.
 
 	XMPP:
 	* Prompt the user before cancelling a presence subscription.
--- a/libpurple/protocols/msn/msn.c	Sun Aug 23 02:11:21 2009 +0000
+++ b/libpurple/protocols/msn/msn.c	Sun Aug 23 03:32:19 2009 +0000
@@ -89,6 +89,7 @@
 typedef struct
 {
 	char *smile;
+	PurpleSmiley *ps;
 	MsnObject *obj;
 } MsnEmoticon;
 
@@ -1082,12 +1083,10 @@
 	strobj = msn_object_to_string(obj);
 
 	if (current)
-		g_string_append_printf(current, "\t%s\t%s",
-				emoticon->smile, strobj);
+		g_string_append_printf(current, "\t%s\t%s", emoticon->smile, strobj);
 	else {
 		current = g_string_new("");
-		g_string_printf(current,"%s\t%s",
-					emoticon->smile, strobj);
+		g_string_printf(current, "%s\t%s", emoticon->smile, strobj);
 	}
 
 	g_free(strobj);
@@ -1145,6 +1144,7 @@
 
 		emoticon = g_new0(MsnEmoticon, 1);
 		emoticon->smile = g_strdup(purple_smiley_get_shortcut(smiley));
+		emoticon->ps = smiley;
 		emoticon->obj = msn_object_new_from_image(img,
 				purple_imgstore_get_filename(img),
 				username, MSN_OBJECT_EMOTICON);
@@ -1167,7 +1167,7 @@
 
 	smileys = msn_msg_grab_emoticons(msg->body, username);
 	while (smileys) {
-		smile = (MsnEmoticon*)smileys->data;
+		smile = (MsnEmoticon *)smileys->data;
 		emoticons = msn_msg_emoticon_add(emoticons, smile);
 		msn_emoticon_destroy(smile);
 		smileys = g_slist_delete_link(smileys, smileys);
@@ -1718,13 +1718,19 @@
 {
 	PurpleAccount *account;
 	MsnSession *session;
+	const char *username;
 	MsnSwitchBoard *swboard;
 	MsnMessage *msg;
 	char *msgformat;
 	char *msgtext;
+	size_t msglen;
+	MsnEmoticon *smile;
+	GSList *smileys;
+	GString *emoticons = NULL;
 
 	account = purple_connection_get_account(gc);
 	session = gc->proto_data;
+	username = purple_account_get_username(account);
 	swboard = msn_session_find_swboard_with_id(session, id);
 
 	if (swboard == NULL)
@@ -1736,8 +1742,9 @@
 	swboard->flag |= MSN_SB_FLAG_IM;
 
 	msn_import_html(message, &msgformat, &msgtext);
-
-	if (strlen(msgtext) + strlen(msgformat) + strlen(VERSION) > 1564)
+	msglen = strlen(msgtext);
+
+	if ((msglen == 0) || (msglen + strlen(msgformat) + strlen(VERSION) > 1564))
 	{
 		g_free(msgformat);
 		g_free(msgtext);
@@ -1747,6 +1754,29 @@
 
 	msg = msn_message_new_plain(msgtext);
 	msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat);
+
+	smileys = msn_msg_grab_emoticons(msg->body, username);
+	while (smileys) {
+		smile = (MsnEmoticon *)smileys->data;
+		emoticons = msn_msg_emoticon_add(emoticons, smile);
+		if (purple_conv_custom_smiley_add(swboard->conv, smile->smile,
+		                                  "sha1", purple_smiley_get_checksum(smile->ps),
+		                                  FALSE)) {
+			gconstpointer data;
+			size_t len;
+			data = purple_smiley_get_data(smile->ps, &len);
+			purple_conv_custom_smiley_write(swboard->conv, smile->smile, data, len);
+			purple_conv_custom_smiley_close(swboard->conv, smile->smile);
+		}
+		msn_emoticon_destroy(smile);
+		smileys = g_slist_delete_link(smileys, smileys);
+	}
+
+	if (emoticons) {
+		msn_send_emoticons(swboard, emoticons);
+		g_string_free(emoticons, TRUE);
+	}
+
 	msn_switchboard_send_msg(swboard, msg, FALSE);
 	msn_message_destroy(msg);
 
--- a/libpurple/smiley.c	Sun Aug 23 02:11:21 2009 +0000
+++ b/libpurple/smiley.c	Sun Aug 23 03:32:19 2009 +0000
@@ -80,7 +80,7 @@
  * XML descriptor file layout                                                 *
  ******************************************************************************
  *
- * Althought we are creating the profile XML structure here, now we
+ * Although we are creating the profile XML structure here, now we
  * won't handle it.
  * So, we just add one profile named "default" that has no associated
  * account elements, and have only the smiley_set that will contain
@@ -163,14 +163,14 @@
 }
 
 static xmlnode *
-smileys_to_xmlnode()
+smileys_to_xmlnode(void)
 {
 	xmlnode *root_node, *profile_node, *smileyset_node;
 
 	root_node = xmlnode_new(XML_ROOT_TAG);
 	xmlnode_set_attrib(root_node, "version", "1.0");
 
-	/* See the top comment's above to understand why initial tag elements
+	/* See the top comments above to understand why initial tag elements
 	 * are not being considered by now. */
 	profile_node = xmlnode_new(XML_PROFILE_TAG);
 	if (profile_node) {
@@ -188,7 +188,7 @@
 }
 
 static void
-sync_smileys()
+sync_smileys(void)
 {
 	xmlnode *root_node;
 	char *data;
@@ -216,7 +216,7 @@
 }
 
 static void
-purple_smileys_save()
+purple_smileys_save(void)
 {
 	if (save_timer == 0)
 		save_timer = purple_timeout_add_seconds(5, save_smileys_cb, NULL);
@@ -248,7 +248,7 @@
 }
 
 static void
-purple_smileys_load()
+purple_smileys_load(void)
 {
 	xmlnode *root_node, *profile_node;
 	xmlnode *smileyset_node = NULL;
@@ -262,7 +262,7 @@
 	if (root_node == NULL)
 		return;
 
-	/* See the top comment's above to understand why initial tag elements
+	/* See the top comments above to understand why initial tag elements
 	 * are not being considered by now. */
 	profile_node = xmlnode_get_child(root_node, XML_PROFILE_TAG);
 	if (profile_node)
@@ -456,7 +456,7 @@
 }
 
 /*********************************************************************
- * Other Stuff                                                             *
+ * Other Stuff                                                       *
  *********************************************************************/
 
 static char *get_file_full_path(const char *filename)
@@ -876,7 +876,7 @@
 }
 
 void
-purple_smileys_init()
+purple_smileys_init(void)
 {
 	smiley_shortcut_index = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
 	smiley_checksum_index = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
@@ -887,7 +887,7 @@
 }
 
 void
-purple_smileys_uninit()
+purple_smileys_uninit(void)
 {
 	if (save_timer != 0) {
 		purple_timeout_remove(save_timer);
--- a/libpurple/smiley.h	Sun Aug 23 02:11:21 2009 +0000
+++ b/libpurple/smiley.h	Sun Aug 23 03:32:19 2009 +0000
@@ -95,7 +95,7 @@
 purple_smiley_new_from_file(const char *shortcut, const char *filepath);
 
 /**
- * Destroys the custom smiley and release the associated resources.
+ * Destroys the custom smiley and releases the associated resources.
  *
  * @param smiley    The custom smiley.
  */
@@ -183,7 +183,7 @@
  * If the custom smiley has data and the file exists in the cache, this
  * will return a full path to the cached file.
  *
- * In general, it is not appropriate to be poking in the file cached
+ * In general, it is not appropriate to be poking in the file cache
  * directly.  If you find yourself wanting to use this function, think
  * very long and hard about it, and then don't.
  *