changeset 27012:af4a4ebc6441

Add a utlity function purple_markup_is_rtl Use this function to check for RTL text in messages. Fixes #9261.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 03 Jun 2009 17:04:05 +0000
parents f2ca52166a0d
children 1b47eb4abf96
files ChangeLog ChangeLog.API libpurple/util.c libpurple/util.h pidgin/gtkconv.c pidgin/plugins/convcolors.c
diffstat 6 files changed, 48 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Wed Jun 03 15:50:08 2009 +0000
+++ b/ChangeLog	Wed Jun 03 17:04:05 2009 +0000
@@ -82,6 +82,7 @@
 	  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
--- a/ChangeLog.API	Wed Jun 03 15:50:08 2009 +0000
+++ b/ChangeLog.API	Wed Jun 03 17:04:05 2009 +0000
@@ -36,6 +36,7 @@
 		* 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
--- a/libpurple/util.c	Wed Jun 03 15:50:08 2009 +0000
+++ b/libpurple/util.c	Wed Jun 03 17:04:05 2009 +0000
@@ -1041,6 +1041,35 @@
 	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)
--- a/libpurple/util.h	Wed Jun 03 15:50:08 2009 +0000
+++ b/libpurple/util.h	Wed Jun 03 17:04:05 2009 +0000
@@ -579,6 +579,16 @@
  */
 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);
 
 /*@}*/
 
--- a/pidgin/gtkconv.c	Wed Jun 03 15:50:08 2009 +0000
+++ b/pidgin/gtkconv.c	Wed Jun 03 17:04:05 2009 +0000
@@ -5629,38 +5629,6 @@
 #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 @@
 	}
 
 	/* 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);
--- a/pidgin/plugins/convcolors.c	Wed Jun 03 15:50:08 2009 +0000
+++ b/pidgin/plugins/convcolors.c	Wed Jun 03 17:04:05 2009 +0000
@@ -101,6 +101,7 @@
 	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 @@
 	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 @@
 	}
 
 	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>"