diff --git a/plugins/gtkgui/chat.py b/plugins/gtkgui/chat.py index 91a1649d6..dd5f71b4a 100644 --- a/plugins/gtkgui/chat.py +++ b/plugins/gtkgui/chat.py @@ -37,8 +37,8 @@ gtk.glade.textdomain(APP) GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade' -class chat: - """Class for tabbed chat window""" +class Chat: + """Class for chat/groupchat windows""" def __init__(self, plugin, account, widget_name): self.xml = gtk.glade.XML(GTKGUI_GLADE, widget_name, APP) self.notebook = self.xml.get_widget('chat_notebook') @@ -427,51 +427,86 @@ class chat: #we launch the correct application self.plugin.launch_browser_mailer(kind, word) - def print_special_text(self, text, jid, other_tag): + def detect_and_print_special_text(self, otext, jid, other_tag, print_all_special): + # nk 2 yann: when doing this in GC you have to pass sth and looks for + # xmls[Other-key-here] I believe :D conversation_textview = self.xmls[jid].get_widget('conversation_textview') conversation_buffer = conversation_textview.get_buffer() - # make it CAPS (emoticons keys are all CAPS) - possible_emot_ascii_caps = text.upper() - if possible_emot_ascii_caps in self.plugin.emoticons.keys(): - #it's an emoticon - emot_ascii = possible_emot_ascii_caps - print 'emoticon:', emot_ascii - end_iter = conversation_buffer.get_end_iter() - conversation_buffer.insert_pixbuf(end_iter, \ - self.plugin.emoticons[emot_ascii]) - return - elif text.startswith('mailto:'): - #it's a mail - tag = 'mail' - print tag - elif self.plugin.sth_at_sth_dot_sth_re.match(text): #returns match object - #or None - #it's a mail - tag = 'mail' - print tag - elif text.startswith('*') and text.endswith('*'): - #it's a bold text - tag = 'bold' - text = text[1:-1] # remove * * - elif text.startswith('/') and text.endswith('/'): - #it's an italic text - tag = 'italic' - text = text[1:-1] # remove / / - print tag - elif text.startswith('_') and text.endswith('_'): - #it's an underlined text - tag = 'underline' - text = text[1:-1] # remove _ _ - print tag - else: - #it's a url - tag = 'url' - print tag + # == DETECT SPECIAL TEXT == + start = 0 + end = 0 + index = 0 + #special_text = '' + + # basic: links + mail + formatting is always checked (we like that) + if self.plugin.config['useemoticons']: # search for emoticons & urls + iterator = self.plugin.emot_and_basic_re.finditer(otext) + else: # search for just urls + mail + formatting + iterator = self.plugin.basic_pattern_re.finditer(otext) + for match in iterator: + start, end = match.span() + special_text = otext[start:end] + if start != 0: + text_before_special_text = otext[index:start] + end_iter = conversation_buffer.get_end_iter() + if print_all_special: + conversation_buffer.insert_with_tags_by_name(end_iter, \ + text_before_special_text, other_tag) + else: + conversation_buffer.insert(end_iter, text_before_special_text) + if not print_all_special: + other_tag = '' + index = end # update index - end_iter = conversation_buffer.get_end_iter() - if tag in ['bold', 'italic', 'underline'] and other_tag: - conversation_buffer.insert_with_tags_by_name(end_iter, text,\ - other_tag, tag) - else: - conversation_buffer.insert_with_tags_by_name(end_iter, text, tag) + # == PRINT SPECIAL TEXT == + # make it CAPS (emoticons keys are all CAPS) + possible_emot_ascii_caps = special_text.upper() + if possible_emot_ascii_caps in self.plugin.emoticons.keys(): + #it's an emoticon + tag = None + emot_ascii = possible_emot_ascii_caps + print 'emoticon:', emot_ascii + end_iter = conversation_buffer.get_end_iter() + conversation_buffer.insert_pixbuf(end_iter, \ + self.plugin.emoticons[emot_ascii]) + #break # it used to be a return + elif special_text.startswith('mailto:'): + #it's a mail + tag = 'mail' + print tag + elif self.plugin.sth_at_sth_dot_sth_re.match(special_text): + #it's a mail + tag = 'mail' + print tag + elif special_text.startswith('*') and special_text.endswith('*'): + #it's a bold text + tag = 'bold' + special_text = special_text[1:-1] # remove * * + print tag + elif special_text.startswith('/') and special_text.endswith('/'): + #it's an italic text + tag = 'italic' + special_text = special_text[1:-1] # remove / / + print tag + elif special_text.startswith('_') and special_text.endswith('_'): + #it's an underlined text + tag = 'underline' + special_text = special_text[1:-1] # remove _ _ + print tag + else: + #it's a url + tag = 'url' + print tag + + end_iter = conversation_buffer.get_end_iter() + if tag is not None: + if tag in ['bold', 'italic', 'underline'] and other_tag: + conversation_buffer.insert_with_tags_by_name(end_iter,\ + special_text, other_tag, tag) + else: + conversation_buffer.insert_with_tags_by_name(end_iter,\ + special_text, tag) + + + return index, other_tag diff --git a/plugins/gtkgui/groupchat_window.py b/plugins/gtkgui/groupchat_window.py index d2b99acf4..fed8f2dc4 100644 --- a/plugins/gtkgui/groupchat_window.py +++ b/plugins/gtkgui/groupchat_window.py @@ -38,9 +38,10 @@ gtk.glade.textdomain(APP) GTKGUI_GLADE='plugins/gtkgui/gtkgui.glade' -class Groupchat_window(chat): +class Groupchat_window(Chat): + """Class for Groupchat window""" def __init__(self, room_jid, nick, plugin, account): - chat.__init__(self, plugin, account, 'groupchat_window') + Chat.__init__(self, plugin, account, 'groupchat_window') self.nicks = {} self.list_treeview = {} self.subjects = {} @@ -72,14 +73,14 @@ class Groupchat_window(chat): for room_jid in self.xmls: self.plugin.send('GC_STATUS', self.account, (self.nicks[room_jid], \ room_jid, 'offline', 'offline')) - chat.on_window_destroy(self, widget, 'gc') + Chat.on_window_destroy(self, widget, 'gc') def on_groupchat_window_focus_in_event(self, widget, event): """When window get focus""" - chat.on_chat_window_focus_in_event(self, widget, event) + Chat.on_chat_window_focus_in_event(self, widget, event) def on_chat_notebook_key_press_event(self, widget, event): - chat.on_chat_notebook_key_press_event(self, widget, event) + Chat.on_chat_notebook_key_press_event(self, widget, event) def get_role_iter(self, room_jid, role): model = self.list_treeview[room_jid].get_model() @@ -429,7 +430,7 @@ class Groupchat_window(chat): if dialog.get_response() != gtk.RESPONSE_YES: return - chat.remove_tab(self, jid, 'gc') + Chat.remove_tab(self, jid, 'gc') if len(self.xmls) > 0: self.plugin.send('GC_STATUS', self.account, (self.nicks[room_jid], \ room_jid, 'offline', 'offline')) @@ -441,7 +442,7 @@ class Groupchat_window(chat): self.names[room_jid] = room_jid.split('@')[0] self.xmls[room_jid] = gtk.glade.XML(GTKGUI_GLADE, 'gc_vbox', APP) self.childs[room_jid] = self.xmls[room_jid].get_widget('gc_vbox') - chat.new_tab(self, room_jid) + Chat.new_tab(self, room_jid) self.nicks[room_jid] = nick self.subjects[room_jid] = '' self.list_treeview[room_jid] = self.xmls[room_jid].\ diff --git a/plugins/gtkgui/gtkgui.py b/plugins/gtkgui/gtkgui.py index be04a6029..437d4e99f 100644 --- a/plugins/gtkgui/gtkgui.py +++ b/plugins/gtkgui/gtkgui.py @@ -692,7 +692,7 @@ class plugin: return False return True - def make_pattern(self): + def make_regexps(self): # regexp meta characters are: . ^ $ * + ? { } [ ] \ | ( ) # one escapes the metachars with \ # \S matches anything but ' ' '\t' '\n' '\r' '\f' and '\v' @@ -723,7 +723,20 @@ class plugin: #doesn't detect (it's a feature :P) * bold* *bold * * bold * test*bold* formatting = r'(? 0: del self.users[jid] @@ -126,7 +126,7 @@ class tabbed_chat_window(chat): self.names[user.jid] = user.name self.xmls[user.jid] = gtk.glade.XML(GTKGUI_GLADE, 'chats_vbox', APP) self.childs[user.jid] = self.xmls[user.jid].get_widget('chats_vbox') - chat.new_tab(self, user.jid) + Chat.new_tab(self, user.jid) self.users[user.jid] = user self.redraw_tab(user.jid) @@ -235,42 +235,19 @@ class tabbed_chat_window(chat): else: otext = ttext - start = 0 - end = 0 - index = 0 + # detect urls formatting and if the user has it on emoticons + index, other_tag = self.detect_and_print_special_text(otext, jid, tag, print_all_special) - if self.plugin.config['useemoticons']: # search for emoticons & urls - my_re = sre.compile(self.plugin.emot_and_basic_pattern, sre.IGNORECASE) - iterator = my_re.finditer(otext) - else: # search for just urls - my_re = sre.compile(self.plugin.basic_pattern, sre.IGNORECASE) - iterator = my_re.finditer(otext) - for match in iterator: - start, end = match.span() - special_text = otext[start:end] - if start != 0: - text_before_special_text = otext[index:start] - end_iter = conversation_buffer.get_end_iter() - if print_all_special: - conversation_buffer.insert_with_tags_by_name(end_iter, \ - text_before_special_text, tag) - else: - conversation_buffer.insert(end_iter, text_before_special_text) - if print_all_special: - self.print_special_text(special_text, jid, tag) - else: - self.print_special_text(special_text, jid, '') - index = end # update index - - #add the rest in the index and after + # add the rest of text located in the index and after end_iter = conversation_buffer.get_end_iter() if print_all_special: conversation_buffer.insert_with_tags_by_name(end_iter, \ - otext[index:], tag) + otext[index:], other_tag) else: conversation_buffer.insert(end_iter, otext[index:]) #scroll to the end of the textview + end_iter = conversation_buffer.get_end_iter() end_rect = conversation_textview.get_iter_location(end_iter) visible_rect = conversation_textview.get_visible_rect() end = False