pidgin: eb1889b8: Add a utlity function purple_markup_is_r...

sadrul at pidgin.im sadrul at pidgin.im
Wed Jun 3 13:00:38 EDT 2009


-----------------------------------------------------------------
Revision: eb1889b8b74257cf008b6848b18344354cb8d02e
Ancestor: 0ccc5bec4e4a170360657766b31024248e1303ff
Author: sadrul at pidgin.im
Date: 2009-06-03T17:04:05
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/eb1889b8b74257cf008b6848b18344354cb8d02e

Modified files:
        ChangeLog ChangeLog.API libpurple/util.c libpurple/util.h
        pidgin/gtkconv.c pidgin/plugins/convcolors.c

ChangeLog: 

Add a utlity function purple_markup_is_rtl

Use this function to check for RTL text in messages. Fixes #9261.

-------------- next part --------------
============================================================
--- ChangeLog	996520af674f2b26da61e7d6e00c79f7cafee04f
+++ ChangeLog	4395db40e46c5dd89ffcae56f624eddce2301f69
@@ -82,6 +82,7 @@ version 2.6.0 (??/??/2009):
 	  rejoin.
 	* Always set unseen-count and unseen-state on conversations.
 	  (Joshua Stein)
+	* Fix a bug in 'Conversation Colors' plugin for RTL messages.
 
 	Finch:
 	* The hardware cursor is updated correctly. This will be useful
============================================================
--- ChangeLog.API	2f99b4086363cf19921f6ba2495ee84f2143097c
+++ ChangeLog.API	4d73dec8b0061eac0c5c850d9b72aa3a525ca241
@@ -36,6 +36,7 @@ version 2.6.0 (??/??/2009):
 		* purple_global_proxy_set_info
 		* purple_group_destroy
 		* purple_log_get_activity_score
+		* purple_markup_is_rtl
 		* purple_network_force_online
 		* purple_network_set_stun_server
 		* purple_network_set_turn_server
============================================================
--- libpurple/util.c	170a4c10aa88e6c499b8579b628135213d21215c
+++ libpurple/util.c	163214ee10eee990bb7736e0902eeb4eada9e92e
@@ -1041,6 +1041,35 @@ purple_markup_get_css_property(const gch
 	return ret;
 }
 
+gboolean purple_markup_is_rtl(const char *html)
+{
+	GData *attributes;
+	const gchar *start, *end;
+	gboolean res = FALSE;
+
+	if (purple_markup_find_tag("span", html, &start, &end, &attributes))
+	{
+		/* tmp is a member of attributes and is free with g_datalist_clear call */
+		const char *tmp = g_datalist_get_data(&attributes, "dir");
+		if (tmp && !g_ascii_strcasecmp(tmp, "RTL"))
+			res = TRUE;
+		if (!res)
+		{
+			tmp = g_datalist_get_data(&attributes, "style");
+			if (tmp)
+			{
+				char *tmp2 = purple_markup_get_css_property(tmp, "direction");
+				if (tmp2 && !g_ascii_strcasecmp(tmp2, "RTL"))
+					res = TRUE;
+				g_free(tmp2);
+			}
+
+		}
+		g_datalist_clear(&attributes);
+	}
+	return res;
+}
+
 gboolean
 purple_markup_find_tag(const char *needle, const char *haystack,
 					 const char **start, const char **end, GData **attributes)
============================================================
--- libpurple/util.h	3ba17977e67ef1cc6b586aeae723156f91fae4cf
+++ libpurple/util.h	8bb1a61e0826ad7b0cd3dc7dd526620006e8a926
@@ -579,6 +579,16 @@ char * purple_markup_get_css_property(co
  */
 char * purple_markup_get_css_property(const gchar *style, const gchar *opt);
 
+/**
+ * Check if the given HTML contains RTL text.
+ *
+ * @param html  The HTML text.
+ *
+ * @return  TRUE if the text contains RTL text, FALSE otherwise.
+ *
+ * @since 2.6.0
+ */
+gboolean purple_markup_is_rtl(const char *html);
 
 /*@}*/
 
============================================================
--- pidgin/gtkconv.c	cde7a70d6f70701569303757f52e3bb578dadfe0
+++ pidgin/gtkconv.c	6f3fa4345eeb0bb541478ed5ee08f2ab56723e11
@@ -5629,38 +5629,6 @@ str_embed_direction_chars(char **str)
 #endif
 }
 
-/* Returns true if the given HTML contains RTL text */
-static gboolean
-html_is_rtl(const char *html)
-{
-	GData *attributes;
-	const gchar *start, *end;
-	gboolean res = FALSE;
-
-	if (purple_markup_find_tag("span", html, &start, &end, &attributes))
-	{
-		/* tmp is a member of attributes and is free with g_datalist_clear call */
-		const char *tmp = g_datalist_get_data(&attributes, "dir");
-		if (tmp && !g_ascii_strcasecmp(tmp, "RTL"))
-			res = TRUE;
-		if (!res)
-		{
-			tmp = g_datalist_get_data(&attributes, "style");
-			if (tmp)
-			{
-				char *tmp2 = purple_markup_get_css_property(tmp, "direction");
-				if (tmp2 && !g_ascii_strcasecmp(tmp2, "RTL"))
-					res = TRUE;
-				g_free(tmp2);
-			}
-
-		}
-		g_datalist_clear(&attributes);
-	}
-	return res;
-}
-
-
 static void
 pidgin_conv_write_conv(PurpleConversation *conv, const char *name, const char *alias,
 						const char *message, PurpleMessageFlags flags,
@@ -5822,7 +5790,7 @@ pidgin_conv_write_conv(PurpleConversatio
 	}
 
 	/* Bi-Directional support - set timestamp direction using unicode characters */
-	is_rtl_message = html_is_rtl(message);
+	is_rtl_message = purple_markup_is_rtl(message);
 	/* Enforce direction only if message is RTL - doesn't effect LTR users */
 	if (is_rtl_message)
 		str_embed_direction_chars(&mdate);
============================================================
--- pidgin/plugins/convcolors.c	4e6f1e870aaf364602741d886ff3f1dfa3aa8030
+++ pidgin/plugins/convcolors.c	0123c7830bce787a14d68809b533f61e27c37ead
@@ -101,6 +101,7 @@ displaying_msg(PurpleAccount *account, c
 	gboolean bold, italic, underline;
 	int f;
 	const char *color;
+	gboolean rtl = FALSE;
 
 	for (i = 0; formats[i].prefix; i++)
 		if (flags & formats[i].flag)
@@ -126,6 +127,7 @@ displaying_msg(PurpleAccount *account, c
 	bold = (f & FONT_BOLD);
 	italic = (f & FONT_ITALIC);
 	underline = (f & FONT_UNDERLINE);
+	rtl = purple_markup_is_rtl(*displaying);
 
 	if (purple_prefs_get_bool(PREF_IGNORE))
 	{
@@ -156,11 +158,13 @@ displaying_msg(PurpleAccount *account, c
 	}
 
 	t = *displaying;
-	*displaying = g_strdup_printf("%s%s%s%s%s%s%s",
+	*displaying = g_strdup_printf("%s%s%s%s%s%s%s%s%s",
 						bold ? "<B>" : "</B>",
 						italic ? "<I>" : "</I>",
 						underline ? "<U>" : "</U>",
-						t, 
+						rtl ? "<SPAN style=\"direction:rtl;text-align:right;\">" : "",
+						t,
+						rtl ? "</SPAN>" : "",
 						bold ? "</B>" : "<B>",
 						italic ? "</I>" : "<I>",
 						underline ? "</U>" : "<U>"


More information about the Commits mailing list