add a graphics optio nto all print text function to not display emoticons and latex formulas in nicks. Fixes #4651
This commit is contained in:
parent
887b8d31b2
commit
6781600942
|
@ -704,7 +704,8 @@ class ChatControlBase(MessageControl, CommonCommands):
|
||||||
|
|
||||||
def print_conversation_line(self, text, kind, name, tim,
|
def print_conversation_line(self, text, kind, name, tim,
|
||||||
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
|
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
|
||||||
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False, xep0184_id = None):
|
count_as_new=True, subject=None, old_kind=None, xhtml=None, simple=False,
|
||||||
|
xep0184_id=None, graphics=True):
|
||||||
'''prints 'chat' type messages'''
|
'''prints 'chat' type messages'''
|
||||||
jid = self.contact.jid
|
jid = self.contact.jid
|
||||||
full_jid = self.get_full_jid()
|
full_jid = self.get_full_jid()
|
||||||
|
@ -714,7 +715,7 @@ class ChatControlBase(MessageControl, CommonCommands):
|
||||||
end = True
|
end = True
|
||||||
textview.print_conversation_line(text, jid, kind, name, tim,
|
textview.print_conversation_line(text, jid, kind, name, tim,
|
||||||
other_tags_for_name, other_tags_for_time, other_tags_for_text,
|
other_tags_for_name, other_tags_for_time, other_tags_for_text,
|
||||||
subject, old_kind, xhtml, simple=simple)
|
subject, old_kind, xhtml, simple=simple, graphics=graphics)
|
||||||
|
|
||||||
if xep0184_id is not None:
|
if xep0184_id is not None:
|
||||||
textview.show_xep0184_warning(xep0184_id)
|
textview.show_xep0184_warning(xep0184_id)
|
||||||
|
|
|
@ -945,7 +945,7 @@ class ConversationTextview(gobject.GObject):
|
||||||
helpers.launch_browser_mailer(kind, href)
|
helpers.launch_browser_mailer(kind, href)
|
||||||
|
|
||||||
|
|
||||||
def detect_and_print_special_text(self, otext, other_tags):
|
def detect_and_print_special_text(self, otext, other_tags, graphics=True):
|
||||||
'''detects special text (emots & links & formatting)
|
'''detects special text (emots & links & formatting)
|
||||||
prints normal text before any special text it founts,
|
prints normal text before any special text it founts,
|
||||||
then print special text (that happens many times until
|
then print special text (that happens many times until
|
||||||
|
@ -970,7 +970,8 @@ class ConversationTextview(gobject.GObject):
|
||||||
specials_limit = 100
|
specials_limit = 100
|
||||||
|
|
||||||
# basic: links + mail + formatting is always checked (we like that)
|
# basic: links + mail + formatting is always checked (we like that)
|
||||||
if gajim.config.get('emoticons_theme'): # search for emoticons & urls
|
if gajim.config.get('emoticons_theme') and graphics:
|
||||||
|
# search for emoticons & urls
|
||||||
iterator = gajim.interface.emot_and_basic_re.finditer(otext)
|
iterator = gajim.interface.emot_and_basic_re.finditer(otext)
|
||||||
else: # search for just urls + mail + formatting
|
else: # search for just urls + mail + formatting
|
||||||
iterator = gajim.interface.basic_pattern_re.finditer(otext)
|
iterator = gajim.interface.basic_pattern_re.finditer(otext)
|
||||||
|
@ -985,7 +986,7 @@ class ConversationTextview(gobject.GObject):
|
||||||
index = end # update index
|
index = end # update index
|
||||||
|
|
||||||
# now print it
|
# now print it
|
||||||
self.print_special_text(special_text, other_tags)
|
self.print_special_text(special_text, other_tags, graphics=graphics)
|
||||||
specials_limit -= 1
|
specials_limit -= 1
|
||||||
if specials_limit <= 0:
|
if specials_limit <= 0:
|
||||||
break
|
break
|
||||||
|
@ -996,7 +997,7 @@ class ConversationTextview(gobject.GObject):
|
||||||
|
|
||||||
return buffer_.get_end_iter()
|
return buffer_.get_end_iter()
|
||||||
|
|
||||||
def print_special_text(self, special_text, other_tags):
|
def print_special_text(self, special_text, other_tags, graphics=True):
|
||||||
'''is called by detect_and_print_special_text and prints
|
'''is called by detect_and_print_special_text and prints
|
||||||
special text (emots, links, formatting)'''
|
special text (emots, links, formatting)'''
|
||||||
tags = []
|
tags = []
|
||||||
|
@ -1014,7 +1015,7 @@ class ConversationTextview(gobject.GObject):
|
||||||
|
|
||||||
possible_emot_ascii_caps = special_text.upper() # emoticons keys are CAPS
|
possible_emot_ascii_caps = special_text.upper() # emoticons keys are CAPS
|
||||||
if gajim.config.get('emoticons_theme') and \
|
if gajim.config.get('emoticons_theme') and \
|
||||||
possible_emot_ascii_caps in gajim.interface.emoticons.keys():
|
possible_emot_ascii_caps in gajim.interface.emoticons.keys() and graphics:
|
||||||
# it's an emoticon
|
# it's an emoticon
|
||||||
emot_ascii = possible_emot_ascii_caps
|
emot_ascii = possible_emot_ascii_caps
|
||||||
end_iter = buffer_.get_end_iter()
|
end_iter = buffer_.get_end_iter()
|
||||||
|
@ -1090,7 +1091,7 @@ class ConversationTextview(gobject.GObject):
|
||||||
if not show_ascii_formatting_chars:
|
if not show_ascii_formatting_chars:
|
||||||
special_text = special_text[1:-1] # remove _ _
|
special_text = special_text[1:-1] # remove _ _
|
||||||
elif gajim.HAVE_LATEX and special_text.startswith('$$') and \
|
elif gajim.HAVE_LATEX and special_text.startswith('$$') and \
|
||||||
special_text.endswith('$$'):
|
special_text.endswith('$$') and graphics:
|
||||||
try:
|
try:
|
||||||
imagepath = latex.latex_to_image(special_text[2:-2])
|
imagepath = latex.latex_to_image(special_text[2:-2])
|
||||||
except LatexError, e:
|
except LatexError, e:
|
||||||
|
@ -1118,7 +1119,8 @@ class ConversationTextview(gobject.GObject):
|
||||||
# It's nothing special
|
# It's nothing special
|
||||||
if use_other_tags:
|
if use_other_tags:
|
||||||
end_iter = buffer_.get_end_iter()
|
end_iter = buffer_.get_end_iter()
|
||||||
buffer_.insert_with_tags_by_name(end_iter, special_text, *other_tags)
|
buffer_.insert_with_tags_by_name(end_iter, special_text,
|
||||||
|
*other_tags)
|
||||||
|
|
||||||
if len(tags) > 0:
|
if len(tags) > 0:
|
||||||
end_iter = buffer_.get_end_iter()
|
end_iter = buffer_.get_end_iter()
|
||||||
|
@ -1134,7 +1136,7 @@ class ConversationTextview(gobject.GObject):
|
||||||
|
|
||||||
def print_conversation_line(self, text, jid, kind, name, tim,
|
def print_conversation_line(self, text, jid, kind, name, tim,
|
||||||
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
|
other_tags_for_name=[], other_tags_for_time=[], other_tags_for_text=[],
|
||||||
subject=None, old_kind=None, xhtml=None, simple=False):
|
subject=None, old_kind=None, xhtml=None, simple=False, graphics=True):
|
||||||
'''prints 'chat' type messages'''
|
'''prints 'chat' type messages'''
|
||||||
buffer_ = self.tv.get_buffer()
|
buffer_ = self.tv.get_buffer()
|
||||||
buffer_.begin_user_action()
|
buffer_.begin_user_action()
|
||||||
|
@ -1215,7 +1217,7 @@ class ConversationTextview(gobject.GObject):
|
||||||
else:
|
else:
|
||||||
self.print_name(name, kind, other_tags_for_name)
|
self.print_name(name, kind, other_tags_for_name)
|
||||||
self.print_subject(subject)
|
self.print_subject(subject)
|
||||||
self.print_real_text(text, text_tags, name, xhtml)
|
self.print_real_text(text, text_tags, name, xhtml, graphics=graphics)
|
||||||
|
|
||||||
# scroll to the end of the textview
|
# scroll to the end of the textview
|
||||||
if at_the_end or kind == 'outgoing':
|
if at_the_end or kind == 'outgoing':
|
||||||
|
@ -1284,7 +1286,8 @@ class ConversationTextview(gobject.GObject):
|
||||||
buffer_.insert(end_iter, subject)
|
buffer_.insert(end_iter, subject)
|
||||||
self.print_empty_line()
|
self.print_empty_line()
|
||||||
|
|
||||||
def print_real_text(self, text, text_tags=[], name=None, xhtml=None):
|
def print_real_text(self, text, text_tags=[], name=None, xhtml=None,
|
||||||
|
graphics=True):
|
||||||
'''this adds normal and special text. call this to add text'''
|
'''this adds normal and special text. call this to add text'''
|
||||||
if xhtml:
|
if xhtml:
|
||||||
try:
|
try:
|
||||||
|
@ -1301,6 +1304,6 @@ class ConversationTextview(gobject.GObject):
|
||||||
text = '* ' + name + text[3:]
|
text = '* ' + name + text[3:]
|
||||||
text_tags.append('italic')
|
text_tags.append('italic')
|
||||||
# detect urls formatting and if the user has it on emoticons
|
# detect urls formatting and if the user has it on emoticons
|
||||||
self.detect_and_print_special_text(text, text_tags)
|
self.detect_and_print_special_text(text, text_tags, graphics=graphics)
|
||||||
|
|
||||||
# vim: se ts=3:
|
# vim: se ts=3:
|
||||||
|
|
|
@ -842,7 +842,8 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
|
||||||
small_attr, small_attr + ['restored_message'],
|
small_attr, small_attr + ['restored_message'],
|
||||||
small_attr + ['restored_message'], count_as_new=False, xhtml=xhtml)
|
small_attr + ['restored_message'], count_as_new=False, xhtml=xhtml)
|
||||||
|
|
||||||
def print_conversation(self, text, contact='', tim=None, xhtml=None):
|
def print_conversation(self, text, contact='', tim=None, xhtml=None,
|
||||||
|
graphics=True):
|
||||||
'''Print a line in the conversation:
|
'''Print a line in the conversation:
|
||||||
if contact is set: it's a message from someone or an info message (contact
|
if contact is set: it's a message from someone or an info message (contact
|
||||||
= 'info' in such a case)
|
= 'info' in such a case)
|
||||||
|
@ -905,7 +906,8 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
|
||||||
self.check_and_possibly_add_focus_out_line()
|
self.check_and_possibly_add_focus_out_line()
|
||||||
|
|
||||||
ChatControlBase.print_conversation_line(self, text, kind, contact, tim,
|
ChatControlBase.print_conversation_line(self, text, kind, contact, tim,
|
||||||
other_tags_for_name, [], other_tags_for_text, xhtml=xhtml)
|
other_tags_for_name, [], other_tags_for_text, xhtml=xhtml,
|
||||||
|
graphics=graphics)
|
||||||
|
|
||||||
def get_nb_unread(self):
|
def get_nb_unread(self):
|
||||||
type_events = ['printed_marked_gc_msg']
|
type_events = ['printed_marked_gc_msg']
|
||||||
|
@ -1203,7 +1205,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
|
||||||
'nick': nick,
|
'nick': nick,
|
||||||
'who': actor,
|
'who': actor,
|
||||||
'reason': reason }
|
'reason': reason }
|
||||||
self.print_conversation(s, 'info', tim=tim)
|
self.print_conversation(s, 'info', tim=tim, graphics=False)
|
||||||
if nick == self.nick and not gajim.config.get(
|
if nick == self.nick and not gajim.config.get(
|
||||||
'muc_autorejoin_on_kick'):
|
'muc_autorejoin_on_kick'):
|
||||||
self.autorejoin = False
|
self.autorejoin = False
|
||||||
|
@ -1217,7 +1219,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
|
||||||
'nick': nick,
|
'nick': nick,
|
||||||
'who': actor,
|
'who': actor,
|
||||||
'reason': reason }
|
'reason': reason }
|
||||||
self.print_conversation(s, 'info', tim=tim)
|
self.print_conversation(s, 'info', tim=tim, graphics=False)
|
||||||
if nick == self.nick:
|
if nick == self.nick:
|
||||||
self.autorejoin = False
|
self.autorejoin = False
|
||||||
elif '303' in statusCode: # Someone changed his or her nick
|
elif '303' in statusCode: # Someone changed his or her nick
|
||||||
|
@ -1277,23 +1279,23 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
|
||||||
# remove 'TEST'
|
# remove 'TEST'
|
||||||
os.remove(files[old_file])
|
os.remove(files[old_file])
|
||||||
os.rename(old_file, files[old_file])
|
os.rename(old_file, files[old_file])
|
||||||
self.print_conversation(s, 'info', tim)
|
self.print_conversation(s, 'info', tim=tim, graphics=False)
|
||||||
elif '321' in statusCode:
|
elif '321' in statusCode:
|
||||||
s = _('%(nick)s has been removed from the room (%(reason)s)') % {
|
s = _('%(nick)s has been removed from the room (%(reason)s)') % {
|
||||||
'nick': nick, 'reason': _('affiliation changed') }
|
'nick': nick, 'reason': _('affiliation changed') }
|
||||||
self.print_conversation(s, 'info', tim=tim)
|
self.print_conversation(s, 'info', tim=tim, graphics=False)
|
||||||
elif '322' in statusCode:
|
elif '322' in statusCode:
|
||||||
s = _('%(nick)s has been removed from the room (%(reason)s)') % {
|
s = _('%(nick)s has been removed from the room (%(reason)s)') % {
|
||||||
'nick': nick,
|
'nick': nick,
|
||||||
'reason': _('room configuration changed to members-only') }
|
'reason': _('room configuration changed to members-only') }
|
||||||
self.print_conversation(s, 'info', tim=tim)
|
self.print_conversation(s, 'info', tim=tim, graphics=False)
|
||||||
elif '332' in statusCode:
|
elif '332' in statusCode:
|
||||||
s = _('%(nick)s has been removed from the room (%(reason)s)') % {
|
s = _('%(nick)s has been removed from the room (%(reason)s)') % {
|
||||||
'nick': nick,
|
'nick': nick,
|
||||||
'reason': _('system shutdown') }
|
'reason': _('system shutdown') }
|
||||||
self.print_conversation(s, 'info', tim=tim)
|
self.print_conversation(s, 'info', tim=tim, graphics=False)
|
||||||
elif 'destroyed' in statusCode: # Room has been destroyed
|
elif 'destroyed' in statusCode: # Room has been destroyed
|
||||||
self.print_conversation(reason, 'info', tim)
|
self.print_conversation(reason, 'info', tim, graphics=False)
|
||||||
|
|
||||||
if len(gajim.events.get_events(self.account, jid=fake_jid,
|
if len(gajim.events.get_events(self.account, jid=fake_jid,
|
||||||
types=['pm'])) == 0:
|
types=['pm'])) == 0:
|
||||||
|
@ -1319,7 +1321,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
|
||||||
# Server changed our nick
|
# Server changed our nick
|
||||||
self.nick = nick
|
self.nick = nick
|
||||||
s = _('You are now known as %s') % nick
|
s = _('You are now known as %s') % nick
|
||||||
self.print_conversation(s, 'info', tim=tim)
|
self.print_conversation(s, 'info', tim=tim, graphics=False)
|
||||||
iter_ = self.add_contact_to_roster(nick, show, role, affiliation,
|
iter_ = self.add_contact_to_roster(nick, show, role, affiliation,
|
||||||
status, jid)
|
status, jid)
|
||||||
newly_created = True
|
newly_created = True
|
||||||
|
@ -1376,7 +1378,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
|
||||||
'affiliation': affiliation}
|
'affiliation': affiliation}
|
||||||
if reason:
|
if reason:
|
||||||
st += ' (%s)' % reason
|
st += ' (%s)' % reason
|
||||||
self.print_conversation(st, tim=tim)
|
self.print_conversation(st, tim=tim, graphics=False)
|
||||||
right_changed = True
|
right_changed = True
|
||||||
actual_role = self.get_role(nick)
|
actual_role = self.get_role(nick)
|
||||||
if role != actual_role:
|
if role != actual_role:
|
||||||
|
@ -1394,7 +1396,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
|
||||||
'nick': nick_jid, 'role': role}
|
'nick': nick_jid, 'role': role}
|
||||||
if reason:
|
if reason:
|
||||||
st += ' (%s)' % reason
|
st += ' (%s)' % reason
|
||||||
self.print_conversation(st, tim=tim)
|
self.print_conversation(st, tim=tim, graphics=False)
|
||||||
right_changed = True
|
right_changed = True
|
||||||
else:
|
else:
|
||||||
if gc_c.show == show and gc_c.status == status and \
|
if gc_c.show == show and gc_c.status == status and \
|
||||||
|
@ -1431,7 +1433,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
|
||||||
if st:
|
if st:
|
||||||
if status:
|
if status:
|
||||||
st += ' (' + status + ')'
|
st += ' (' + status + ')'
|
||||||
self.print_conversation(st, tim=tim)
|
self.print_conversation(st, tim=tim, graphics=False)
|
||||||
|
|
||||||
def add_contact_to_roster(self, nick, show, role, affiliation, status,
|
def add_contact_to_roster(self, nick, show, role, affiliation, status,
|
||||||
jid=''):
|
jid=''):
|
||||||
|
|
Loading…
Reference in New Issue