[Darlan & I]Improved BiDi support for banner text, popup with presence info and more status messages (kick, ban, change nick) fixes #7284 #7192

This commit is contained in:
Denis Fomin 2013-07-23 17:55:24 +04:00
parent e24f10bd78
commit c446150a7e
6 changed files with 37 additions and 31 deletions

View File

@ -46,6 +46,7 @@ from common import gajim
from common import helpers from common import helpers
from common import exceptions from common import exceptions
from common import ged from common import ged
from common import i18n
from message_control import MessageControl from message_control import MessageControl
from conversation_textview import ConversationTextview from conversation_textview import ConversationTextview
from message_textview import MessageTextView from message_textview import MessageTextView
@ -2154,9 +2155,10 @@ class ChatControl(ChatControlBase):
if self.resource: if self.resource:
name += '/' + self.resource name += '/' + self.resource
if self.TYPE_ID == message_control.TYPE_PM: if self.TYPE_ID == message_control.TYPE_PM:
name = _('%(nickname)s from group chat %(room_name)s') %\ name = i18n.direction_mark + _(
{'nickname': name, 'room_name': self.room_name} '%(nickname)s from group chat %(room_name)s') % \
name = GObject.markup_escape_text(name) {'nickname': name, 'room_name': self.room_name}
name = i18n.direction_mark + GObject.markup_escape_text(name)
# We know our contacts nick, but if another contact has the same nick # We know our contacts nick, but if another contact has the same nick
# in another account we need to also display the account. # in another account we need to also display the account.
@ -2169,10 +2171,11 @@ class ChatControl(ChatControlBase):
break break
for jid in gajim.contacts.get_jid_list(account): for jid in gajim.contacts.get_jid_list(account):
other_contact_ = \ other_contact_ = \
gajim.contacts.get_first_contact_from_jid(account, jid) gajim.contacts.get_first_contact_from_jid(account, jid)
if other_contact_.get_shown_name() == self.contact.get_shown_name(): if other_contact_.get_shown_name() == \
acct_info = ' (%s)' % \ self.contact.get_shown_name():
GObject.markup_escape_text(self.account) acct_info = i18n.direction_mark + ' (%s)' % \
GObject.markup_escape_text(self.account)
break break
status = contact.status status = contact.status
@ -2196,16 +2199,16 @@ class ChatControl(ChatControlBase):
chatstate = '' chatstate = ''
label_text = '<span %s>%s</span><span %s>%s %s</span>' \ label_text = '<span %s>%s</span><span %s>%s %s</span>' \
% (font_attrs, name, font_attrs_small, acct_info, chatstate) % (font_attrs, name, font_attrs_small, acct_info, chatstate)
if acct_info: if acct_info:
acct_info = ' ' + acct_info acct_info = i18n.direction_mark + ' ' + acct_info
label_tooltip = '%s%s %s' % (name, acct_info, chatstate) label_tooltip = '%s%s %s' % (name, acct_info, chatstate)
else: else:
# weight="heavy" size="x-large" # weight="heavy" size="x-large"
label_text = '<span %s>%s</span><span %s>%s</span>' % \ label_text = '<span %s>%s</span><span %s>%s</span>' % \
(font_attrs, name, font_attrs_small, acct_info) (font_attrs, name, font_attrs_small, acct_info)
if acct_info: if acct_info:
acct_info = ' ' + acct_info acct_info = i18n.direction_mark + ' ' + acct_info
label_tooltip = '%s%s' % (name, acct_info) label_tooltip = '%s%s' % (name, acct_info)
if status_escaped: if status_escaped:

View File

@ -29,6 +29,7 @@ from common import atom
from common import nec from common import nec
from common import helpers from common import helpers
from common import gajim from common import gajim
from common import i18n
import nbxmpp import nbxmpp
from common import dataforms from common import dataforms
from common import exceptions from common import exceptions
@ -2368,25 +2369,23 @@ class NotificationEvent(nec.NetworkIncomingEvent):
self.popup_timeout = gajim.config.get('notification_timeout') self.popup_timeout = gajim.config.get('notification_timeout')
nick = i18n.direction_mark + gajim.get_name_from_jid(account, self.jid)
if event == 'status_change': if event == 'status_change':
self.popup_title = _('%(nick)s Changed Status') % \ self.popup_title = _('%(nick)s Changed Status') % \
{'nick': gajim.get_name_from_jid(account, self.jid)} {'nick': nick}
self.popup_text = _('%(nick)s is now %(status)s') % \ self.popup_text = _('%(nick)s is now %(status)s') % \
{'nick': gajim.get_name_from_jid(account, self.jid),\ {'nick': nick, 'status': helpers.get_uf_show(pres_obj.show)}
'status': helpers.get_uf_show(pres_obj.show)}
if pres_obj.status: if pres_obj.status:
self.popup_text = self.popup_text + " : " + pres_obj.status self.popup_text = self.popup_text + " : " + pres_obj.status
self.popup_event_type = _('Contact Changed Status') self.popup_event_type = _('Contact Changed Status')
elif event == 'contact_connected': elif event == 'contact_connected':
self.popup_title = _('%(nickname)s Signed In') % \ self.popup_title = _('%(nickname)s Signed In') % {'nickname': nick}
{'nickname': gajim.get_name_from_jid(account, self.jid)}
self.popup_text = '' self.popup_text = ''
if pres_obj.status: if pres_obj.status:
self.popup_text = pres_obj.status self.popup_text = pres_obj.status
self.popup_event_type = _('Contact Signed In') self.popup_event_type = _('Contact Signed In')
elif event == 'contact_disconnected': elif event == 'contact_disconnected':
self.popup_title = _('%(nickname)s Signed Out') % \ self.popup_title = _('%(nickname)s Signed Out') % {'nickname': nick}
{'nickname': gajim.get_name_from_jid(account, self.jid)}
self.popup_text = '' self.popup_text = ''
if pres_obj.status: if pres_obj.status:
self.popup_text = pres_obj.status self.popup_text = pres_obj.status

View File

@ -27,6 +27,9 @@ import os
from common import defs from common import defs
import unicodedata import unicodedata
# May be changed after GTK is imported
direction_mark = u'\u200F'
def paragraph_direction_mark(text): def paragraph_direction_mark(text):
""" """
Determine paragraph writing direction according to Determine paragraph writing direction according to

View File

@ -1309,10 +1309,7 @@ class ConversationTextview(GObject.GObject):
direction_mark = i18n.paragraph_direction_mark(text) direction_mark = i18n.paragraph_direction_mark(text)
# don't apply direction mark if it's status message # don't apply direction mark if it's status message
if kind == 'status': if kind == 'status':
if Gtk.Widget.get_default_direction() == gtk.TextDirectionLTR: direction_mark = i18n.direction_mark
direction_mark = u'\u200E'
else:
direction_mark = u'\u200F'
if current_print_time == 'always' and kind != 'info' and not simple: if current_print_time == 'always' and kind != 'info' and not simple:
timestamp_str = self.get_time_to_show(tim) timestamp_str = self.get_time_to_show(tim)
timestamp = time.strftime(timestamp_str, tim) timestamp = time.strftime(timestamp_str, tim)

View File

@ -209,6 +209,8 @@ warnings.resetwarnings()
if os.name == 'nt': if os.name == 'nt':
warnings.filterwarnings(action='ignore') warnings.filterwarnings(action='ignore')
if Gtk.Widget.get_default_direction() == Gtk.TextDirection.LTR:
i18n.direction_mark = u'\u200E'
pritext = '' pritext = ''
from common import exceptions from common import exceptions

View File

@ -49,6 +49,7 @@ from common import gajim
from common import helpers from common import helpers
from common import dataforms from common import dataforms
from common import ged from common import ged
from common import i18n
from chat_control import ChatControl from chat_control import ChatControl
from chat_control import ChatControlBase from chat_control import ChatControlBase
@ -1523,7 +1524,8 @@ class GroupchatControl(ChatControlBase):
affiliation = 'none' affiliation = 'none'
newly_created = False newly_created = False
nick_jid = obj.nick nick = i18n.direction_mark + obj.nick
nick_jid = nick
# Set to true if role or affiliation have changed # Set to true if role or affiliation have changed
right_changed = False right_changed = False
@ -1566,10 +1568,10 @@ class GroupchatControl(ChatControlBase):
if '307' in obj.status_code: if '307' in obj.status_code:
if obj.actor is None: # do not print 'kicked by None' if obj.actor is None: # do not print 'kicked by None'
s = _('%(nick)s has been kicked: %(reason)s') % { s = _('%(nick)s has been kicked: %(reason)s') % {
'nick': obj.nick, 'reason': obj.reason} 'nick': nick, 'reason': obj.reason}
else: else:
s = _('%(nick)s has been kicked by %(who)s: ' s = _('%(nick)s has been kicked by %(who)s: '
'%(reason)s') % {'nick': obj.nick, 'who': obj.actor, '%(reason)s') % {'nick': nick, 'who': obj.actor,
'reason': obj.reason} 'reason': obj.reason}
self.print_conversation(s, 'info', graphics=False) self.print_conversation(s, 'info', graphics=False)
if obj.nick == self.nick and not gajim.config.get( if obj.nick == self.nick and not gajim.config.get(
@ -1578,10 +1580,10 @@ class GroupchatControl(ChatControlBase):
elif '301' in obj.status_code: elif '301' in obj.status_code:
if obj.actor is None: # do not print 'banned by None' if obj.actor is None: # do not print 'banned by None'
s = _('%(nick)s has been banned: %(reason)s') % { s = _('%(nick)s has been banned: %(reason)s') % {
'nick': obj.nick, 'reason': obj.reason} 'nick': nick, 'reason': obj.reason}
else: else:
s = _('%(nick)s has been banned by %(who)s: ' s = _('%(nick)s has been banned by %(who)s: '
'%(reason)s') % {'nick': obj.nick, 'who': obj.actor, '%(reason)s') % {'nick': nick, 'who': obj.actor,
'reason': obj.reason} 'reason': obj.reason}
self.print_conversation(s, 'info', graphics=False) self.print_conversation(s, 'info', graphics=False)
if obj.nick == self.nick: if obj.nick == self.nick:
@ -1608,7 +1610,7 @@ class GroupchatControl(ChatControlBase):
ctrl.no_autonegotiation = False ctrl.no_autonegotiation = False
else: else:
s = _('%(nick)s is now known as %(new_nick)s') % { s = _('%(nick)s is now known as %(new_nick)s') % {
'nick': obj.nick, 'new_nick': obj.new_nick} 'nick': nick, 'new_nick': obj.new_nick}
tv = self.conv_textview tv = self.conv_textview
if obj.nick in tv.last_received_message_marks: if obj.nick in tv.last_received_message_marks:
tv.last_received_message_marks[obj.new_nick] = \ tv.last_received_message_marks[obj.new_nick] = \
@ -1662,18 +1664,18 @@ class GroupchatControl(ChatControlBase):
self.print_conversation(s, 'info', graphics=False) self.print_conversation(s, 'info', graphics=False)
elif '321' in obj.status_code: elif '321' in obj.status_code:
s = _('%(nick)s has been removed from the room ' s = _('%(nick)s has been removed from the room '
'(%(reason)s)') % { 'nick': obj.nick, '(%(reason)s)') % { 'nick': nick,
'reason': _('affiliation changed') } 'reason': _('affiliation changed') }
self.print_conversation(s, 'info', graphics=False) self.print_conversation(s, 'info', graphics=False)
elif '322' in obj.status_code: elif '322' in obj.status_code:
s = _('%(nick)s has been removed from the room ' s = _('%(nick)s has been removed from the room '
'(%(reason)s)') % { 'nick': obj.nick, '(%(reason)s)') % { 'nick': nick,
'reason': _('room configuration changed to ' 'reason': _('room configuration changed to '
'members-only') } 'members-only') }
self.print_conversation(s, 'info', graphics=False) self.print_conversation(s, 'info', graphics=False)
elif '332' in obj.status_code: elif '332' in obj.status_code:
s = _('%(nick)s has been removed from the room ' s = _('%(nick)s has been removed from the room '
'(%(reason)s)') % {'nick': obj.nick, '(%(reason)s)') % {'nick': nick,
'reason': _('system shutdown') } 'reason': _('system shutdown') }
self.print_conversation(s, 'info', graphics=False) self.print_conversation(s, 'info', graphics=False)
# Room has been destroyed. # Room has been destroyed.
@ -1707,7 +1709,7 @@ class GroupchatControl(ChatControlBase):
if '210' in obj.status_code: if '210' in obj.status_code:
# Server changed our nick # Server changed our nick
self.nick = obj.nick self.nick = obj.nick
s = _('You are now known as %s') % obj.nick s = _('You are now known as %s') % nick
self.print_conversation(s, 'info', graphics=False) self.print_conversation(s, 'info', graphics=False)
iter_ = self.add_contact_to_roster(obj.nick, obj.show, role, iter_ = self.add_contact_to_roster(obj.nick, obj.show, role,
affiliation, obj.status, obj.real_jid) affiliation, obj.status, obj.real_jid)