A patch to fix some Bidi-text issues in Gaim2

It has been 2 years since I reported bug #1121620 to the Gaim Bug Tracker. I expected that someone will resolve it for Gaim 2.0 but the issue was ignored. A friend told me last week that he doesn't like Gaim because of it's bad Hebrew support in MSN Messenger protocol. I decided that this itch just got too itchy to ignore. So, I looked into it during the weekend and realized I know how to fix it, and so I wrote this patch.

This patch doesn't only fix the problem described in bug #1121620 but also resolves the problems with displaying RTL messages on Gaim's IMHtml Widget.

Before my patch MSN conversation used to look like this:

Notice that the direction of the text was automatically (and correctly) detected in the text input field on the bottom. However, the conversation window displays all lines aligned to the left and the text direction is always LTR - therefore RTL text which includes embedded English words (LTR) becomes unreadable because the words are displayed in the wrong order.

The MSN Messenger user will also see the text displayed using the wrong alignment and the wrong direction:

The patch above will fix all these issues. After patching your Gaim, the above conversation will look like this:

And the MSN Messenger user will see the text displayed correctly:

The Code

Writing the patch was a little tricky - some of the code in there may seem like an ugly hack and there's probably a better way of doing some things. But that's the best I could do with my basic knowledge in GTK and Gaim API.

In this patch I implemented the following:

* Added support for [SPAN dir="rtl"] tag in the parser of the IMHtml Widget. (AFAIK this HTML tag is deprecated, but most browsers implement it and it beats coding CSS support)

* Added text direction detection to outgoing messages and send it with the correct SPAN tag.

* Added support for the "RL=1" flag in Messenger protocol implementation, both in sending and receiving messages.

* Fixed some display issues: Insert RLM and RLE Unicode characters to the conversation display according to the expected alignment and direction.


Now timestamps will show up on the right side:

in the screenshot:
Hebrew alias + English text
Hebrew alias + Hebrew text
English alias + English text
English alias + Hebrew text


Who will start the next war on Israel

It's almost funny to read that some people from Tehran think that Israel will be first one to attack Iran when they live in the only country in the world who has an elected president who constantly calls for the destruction of another country while insisting on their undisputable right to develop Nuclear energy for peaceful needs (..... can you do 1 plus 1 ?).

In addition Hezbollah, who brought the war on Lebanon, receives arms, training, financial support and commands from Iran. This organization which tries to disguise itself as a local and legitimate resistance organization is nothing but a wing of the Iranian army.

Dear roozbeh , how can teach me about war when only few months ago Iranian missiles where flying over my parents heads in my own home town?

Here is my scenario for the war with Iran:

Iran will continue to develop it's "peaceful" Nuclear Energy capabilities.
In a time of a year or two Iran will conduct it's first nuclear bomb experiment.
Iran's President Mahmoud Ahmadinejad will call, once again, for the destruction of Israel and America. The US may launch a massive air strike against Iran's nuclear facilities. The US will not invade Iran while still being involved in the Iraqi mess. Iran will respond by launching conventional war-heads on Haifa and Tel-Aviv and by initiating terror attacks in the lebanese border using the Hezbollah. Israel will not retaliate and will be ordered by US and UN to hold back (Exactly what happened during the first Gulf War when Iraq launched missiles against targets in Saudi Arabia and Israel). Israel may start bombing Hezbollah targets in lebanon again.
Iran's nuclear capability will not be destroyed by the attack because most of their facilities are underground and scattered all over Iran. Iran will have the ability to launch tactic war heads. In the end we will have a small-scaled version of the Cold War against Iran. Iran will not use it's nuclear weapons knowing that Israel probably has the same capabilities.
Iran will start to develop war-heads interception systems like the systems being developed by Israel and the US.

I hope roozebeh can sleep better tonight.