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:
Yann Leboulanger 2009-10-02 16:28:51 +02:00
parent 887b8d31b2
commit 6781600942
3 changed files with 32 additions and 26 deletions

View File

@ -704,7 +704,8 @@ class ChatControlBase(MessageControl, CommonCommands):
def print_conversation_line(self, text, kind, name, tim,
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'''
jid = self.contact.jid
full_jid = self.get_full_jid()
@ -714,7 +715,7 @@ class ChatControlBase(MessageControl, CommonCommands):
end = True
textview.print_conversation_line(text, jid, kind, name, tim,
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:
textview.show_xep0184_warning(xep0184_id)

View File

@ -945,7 +945,7 @@ class ConversationTextview(gobject.GObject):
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)
prints normal text before any special text it founts,
then print special text (that happens many times until
@ -970,7 +970,8 @@ class ConversationTextview(gobject.GObject):
specials_limit = 100
# 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)
else: # search for just urls + mail + formatting
iterator = gajim.interface.basic_pattern_re.finditer(otext)
@ -985,7 +986,7 @@ class ConversationTextview(gobject.GObject):
index = end # update index
# now print it
self.print_special_text(special_text, other_tags)
self.print_special_text(special_text, other_tags, graphics=graphics)
specials_limit -= 1
if specials_limit <= 0:
break
@ -996,7 +997,7 @@ class ConversationTextview(gobject.GObject):
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
special text (emots, links, formatting)'''
tags = []
@ -1014,7 +1015,7 @@ class ConversationTextview(gobject.GObject):
possible_emot_ascii_caps = special_text.upper() # emoticons keys are CAPS
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
emot_ascii = possible_emot_ascii_caps
end_iter = buffer_.get_end_iter()
@ -1090,7 +1091,7 @@ class ConversationTextview(gobject.GObject):
if not show_ascii_formatting_chars:
special_text = special_text[1:-1] # remove _ _
elif gajim.HAVE_LATEX and special_text.startswith('$$') and \
special_text.endswith('$$'):
special_text.endswith('$$') and graphics:
try:
imagepath = latex.latex_to_image(special_text[2:-2])
except LatexError, e:
@ -1118,7 +1119,8 @@ class ConversationTextview(gobject.GObject):
# It's nothing special
if use_other_tags:
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:
end_iter = buffer_.get_end_iter()
@ -1134,7 +1136,7 @@ class ConversationTextview(gobject.GObject):
def print_conversation_line(self, text, jid, kind, name, tim,
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'''
buffer_ = self.tv.get_buffer()
buffer_.begin_user_action()
@ -1215,7 +1217,7 @@ class ConversationTextview(gobject.GObject):
else:
self.print_name(name, kind, other_tags_for_name)
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
if at_the_end or kind == 'outgoing':
@ -1284,7 +1286,8 @@ class ConversationTextview(gobject.GObject):
buffer_.insert(end_iter, subject)
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'''
if xhtml:
try:
@ -1301,6 +1304,6 @@ class ConversationTextview(gobject.GObject):
text = '* ' + name + text[3:]
text_tags.append('italic')
# 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:

View File

@ -842,7 +842,8 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
small_attr, small_attr + ['restored_message'],
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:
if contact is set: it's a message from someone or an info message (contact
= 'info' in such a case)
@ -905,7 +906,8 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
self.check_and_possibly_add_focus_out_line()
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):
type_events = ['printed_marked_gc_msg']
@ -1203,7 +1205,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
'nick': nick,
'who': actor,
'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(
'muc_autorejoin_on_kick'):
self.autorejoin = False
@ -1217,7 +1219,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
'nick': nick,
'who': actor,
'reason': reason }
self.print_conversation(s, 'info', tim=tim)
self.print_conversation(s, 'info', tim=tim, graphics=False)
if nick == self.nick:
self.autorejoin = False
elif '303' in statusCode: # Someone changed his or her nick
@ -1277,23 +1279,23 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
# remove 'TEST'
os.remove(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:
s = _('%(nick)s has been removed from the room (%(reason)s)') % {
'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:
s = _('%(nick)s has been removed from the room (%(reason)s)') % {
'nick': nick,
'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:
s = _('%(nick)s has been removed from the room (%(reason)s)') % {
'nick': nick,
'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
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,
types=['pm'])) == 0:
@ -1319,7 +1321,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
# Server changed our nick
self.nick = 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,
status, jid)
newly_created = True
@ -1376,7 +1378,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
'affiliation': affiliation}
if reason:
st += ' (%s)' % reason
self.print_conversation(st, tim=tim)
self.print_conversation(st, tim=tim, graphics=False)
right_changed = True
actual_role = self.get_role(nick)
if role != actual_role:
@ -1394,7 +1396,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
'nick': nick_jid, 'role': role}
if reason:
st += ' (%s)' % reason
self.print_conversation(st, tim=tim)
self.print_conversation(st, tim=tim, graphics=False)
right_changed = True
else:
if gc_c.show == show and gc_c.status == status and \
@ -1431,7 +1433,7 @@ class GroupchatControl(ChatControlBase, GroupChatCommands):
if st:
if 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,
jid=''):