| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | import gtk |
|---|
| 18 | import pango |
|---|
| 19 | import gobject |
|---|
| 20 | import time |
|---|
| 21 | import os |
|---|
| 22 | import tooltips |
|---|
| 23 | import dialogs |
|---|
| 24 | import locale |
|---|
| 25 | |
|---|
| 26 | import gtkgui_helpers |
|---|
| 27 | from common import gajim |
|---|
| 28 | from common import helpers |
|---|
| 29 | from calendar import timegm |
|---|
| 30 | from common.fuzzyclock import FuzzyClock |
|---|
| 31 | |
|---|
| 32 | from htmltextview import HtmlTextView |
|---|
| 33 | from common.exceptions import GajimGeneralException |
|---|
| 34 | |
|---|
| 35 | class ConversationTextview: |
|---|
| 36 | Â Â Â Â '''Class for the conversation textview (where user reads already said messages) |
|---|
| 37 | Â Â Â Â for chat/groupchat windows''' |
|---|
| 38 | Â Â Â Â |
|---|
| 39 | Â Â Â Â path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps', 'muc_separator.png') |
|---|
| 40 | Â Â Â Â FOCUS_OUT_LINE_PIXBUF = gtk.gdk.pixbuf_new_from_file(path_to_file) |
|---|
| 41 | |
|---|
| 42 |     def __init__(self, account, used_in_history_window = False): |
|---|
| 43 | Â Â Â Â Â Â Â Â '''if used_in_history_window is True, then we do not show |
|---|
| 44 | Â Â Â Â Â Â Â Â Clear menuitem in context menu''' |
|---|
| 45 | Â Â Â Â Â Â Â Â self.used_in_history_window = used_in_history_window |
|---|
| 46 | Â Â Â Â Â Â Â Â |
|---|
| 47 | Â Â Â Â Â Â Â Â |
|---|
| 48 | Â Â Â Â Â Â Â Â self.tv = HtmlTextView() |
|---|
| 49 | Â Â Â Â Â Â Â Â self.tv.html_hyperlink_handler = self.html_hyperlink_handler |
|---|
| 50 | |
|---|
| 51 | Â Â Â Â Â Â Â Â |
|---|
| 52 | Â Â Â Â Â Â Â Â self.tv.set_border_width(1) |
|---|
| 53 | Â Â Â Â Â Â Â Â self.tv.set_accepts_tab(True) |
|---|
| 54 | Â Â Â Â Â Â Â Â self.tv.set_editable(False) |
|---|
| 55 | Â Â Â Â Â Â Â Â self.tv.set_cursor_visible(False) |
|---|
| 56 | Â Â Â Â Â Â Â Â self.tv.set_wrap_mode(gtk.WRAP_WORD_CHAR) |
|---|
| 57 | Â Â Â Â Â Â Â Â self.tv.set_left_margin(2) |
|---|
| 58 | Â Â Â Â Â Â Â Â self.tv.set_right_margin(2) |
|---|
| 59 | Â Â Â Â Â Â Â Â self.handlers = {} |
|---|
| 60 | |
|---|
| 61 | Â Â Â Â Â Â Â Â |
|---|
| 62 | Â Â Â Â Â Â Â Â id = self.tv.connect('motion_notify_event', |
|---|
| 63 | Â Â Â Â Â Â Â Â Â Â Â Â self.on_textview_motion_notify_event) |
|---|
| 64 | Â Â Â Â Â Â Â Â self.handlers[id] = self.tv |
|---|
| 65 | Â Â Â Â Â Â Â Â id = self.tv.connect('populate_popup', self.on_textview_populate_popup) |
|---|
| 66 | Â Â Â Â Â Â Â Â self.handlers[id] = self.tv |
|---|
| 67 | Â Â Â Â Â Â Â Â id = self.tv.connect('button_press_event', |
|---|
| 68 | Â Â Â Â Â Â Â Â Â Â Â Â self.on_textview_button_press_event) |
|---|
| 69 | Â Â Â Â Â Â Â Â self.handlers[id] = self.tv |
|---|
| 70 | |
|---|
| 71 | Â Â Â Â Â Â Â Â self.account = account |
|---|
| 72 | Â Â Â Â Â Â Â Â self.change_cursor = None |
|---|
| 73 | Â Â Â Â Â Â Â Â self.last_time_printout = 0 |
|---|
| 74 | |
|---|
| 75 | Â Â Â Â Â Â Â Â font = pango.FontDescription(gajim.config.get('conversation_font')) |
|---|
| 76 | Â Â Â Â Â Â Â Â self.tv.modify_font(font) |
|---|
| 77 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 78 | Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 79 | Â Â Â Â Â Â Â Â buffer.create_mark('end', end_iter, False) |
|---|
| 80 | |
|---|
| 81 | Â Â Â Â Â Â Â Â self.tagIn = buffer.create_tag('incoming') |
|---|
| 82 | Â Â Â Â Â Â Â Â color = gajim.config.get('inmsgcolor') |
|---|
| 83 | Â Â Â Â Â Â Â Â self.tagIn.set_property('foreground', color) |
|---|
| 84 | Â Â Â Â Â Â Â Â self.tagOut = buffer.create_tag('outgoing') |
|---|
| 85 | Â Â Â Â Â Â Â Â color = gajim.config.get('outmsgcolor') |
|---|
| 86 | Â Â Â Â Â Â Â Â self.tagOut.set_property('foreground', color) |
|---|
| 87 | Â Â Â Â Â Â Â Â self.tagStatus = buffer.create_tag('status') |
|---|
| 88 | Â Â Â Â Â Â Â Â color = gajim.config.get('statusmsgcolor') |
|---|
| 89 | Â Â Â Â Â Â Â Â self.tagStatus.set_property('foreground', color) |
|---|
| 90 | |
|---|
| 91 | Â Â Â Â Â Â Â Â colors = gajim.config.get('gc_nicknames_colors') |
|---|
| 92 | Â Â Â Â Â Â Â Â colors = colors.split(':') |
|---|
| 93 |         for color in xrange(len(colors)): |
|---|
| 94 | Â Â Â Â Â Â Â Â Â Â Â Â tagname = 'gc_nickname_color_'Â + str(color) |
|---|
| 95 | Â Â Â Â Â Â Â Â Â Â Â Â tag = buffer.create_tag(tagname) |
|---|
| 96 | Â Â Â Â Â Â Â Â Â Â Â Â color = colors[color] |
|---|
| 97 | Â Â Â Â Â Â Â Â Â Â Â Â tag.set_property('foreground', color) |
|---|
| 98 | |
|---|
| 99 | Â Â Â Â Â Â Â Â tag = buffer.create_tag('marked') |
|---|
| 100 | Â Â Â Â Â Â Â Â color = gajim.config.get('markedmsgcolor') |
|---|
| 101 | Â Â Â Â Â Â Â Â tag.set_property('foreground', color) |
|---|
| 102 | Â Â Â Â Â Â Â Â tag.set_property('weight', pango.WEIGHT_BOLD) |
|---|
| 103 | |
|---|
| 104 | Â Â Â Â Â Â Â Â tag = buffer.create_tag('time_sometimes') |
|---|
| 105 | Â Â Â Â Â Â Â Â tag.set_property('foreground', 'darkgrey') |
|---|
| 106 | Â Â Â Â Â Â Â Â tag.set_property('scale', pango.SCALE_SMALL) |
|---|
| 107 | Â Â Â Â Â Â Â Â tag.set_property('justification', gtk.JUSTIFY_CENTER) |
|---|
| 108 | |
|---|
| 109 | Â Â Â Â Â Â Â Â tag = buffer.create_tag('small') |
|---|
| 110 | Â Â Â Â Â Â Â Â tag.set_property('scale', pango.SCALE_SMALL) |
|---|
| 111 | |
|---|
| 112 | Â Â Â Â Â Â Â Â tag = buffer.create_tag('restored_message') |
|---|
| 113 | Â Â Â Â Â Â Â Â color = gajim.config.get('restored_messages_color') |
|---|
| 114 | Â Â Â Â Â Â Â Â tag.set_property('foreground', color) |
|---|
| 115 | |
|---|
| 116 | Â Â Â Â Â Â Â Â self.tagURL = buffer.create_tag('url') |
|---|
| 117 | Â Â Â Â Â Â Â Â color = gajim.config.get('urlmsgcolor') |
|---|
| 118 | Â Â Â Â Â Â Â Â self.tagURL.set_property('foreground', color) |
|---|
| 119 | Â Â Â Â Â Â Â Â self.tagURL.set_property('underline', pango.UNDERLINE_SINGLE) |
|---|
| 120 | Â Â Â Â Â Â Â Â id = self.tagURL.connect('event', self.hyperlink_handler, 'url') |
|---|
| 121 | Â Â Â Â Â Â Â Â self.handlers[id] = self.tagURL |
|---|
| 122 | |
|---|
| 123 | Â Â Â Â Â Â Â Â self.tagMail = buffer.create_tag('mail') |
|---|
| 124 | Â Â Â Â Â Â Â Â self.tagMail.set_property('foreground', color) |
|---|
| 125 | Â Â Â Â Â Â Â Â self.tagMail.set_property('underline', pango.UNDERLINE_SINGLE) |
|---|
| 126 | Â Â Â Â Â Â Â Â id = self.tagMail.connect('event', self.hyperlink_handler, 'mail') |
|---|
| 127 | Â Â Â Â Â Â Â Â self.handlers[id] = self.tagMail |
|---|
| 128 | |
|---|
| 129 | Â Â Â Â Â Â Â Â tag = buffer.create_tag('bold') |
|---|
| 130 | Â Â Â Â Â Â Â Â tag.set_property('weight', pango.WEIGHT_BOLD) |
|---|
| 131 | |
|---|
| 132 | Â Â Â Â Â Â Â Â tag = buffer.create_tag('italic') |
|---|
| 133 | Â Â Â Â Â Â Â Â tag.set_property('style', pango.STYLE_ITALIC) |
|---|
| 134 | |
|---|
| 135 | Â Â Â Â Â Â Â Â tag = buffer.create_tag('underline') |
|---|
| 136 | Â Â Â Â Â Â Â Â tag.set_property('underline', pango.UNDERLINE_SINGLE) |
|---|
| 137 | |
|---|
| 138 | Â Â Â Â Â Â Â Â buffer.create_tag('focus-out-line', justification = gtk.JUSTIFY_CENTER) |
|---|
| 139 | |
|---|
| 140 | Â Â Â Â Â Â Â Â self.allow_focus_out_line = True |
|---|
| 141 | Â Â Â Â Â Â Â Â |
|---|
| 142 | Â Â Â Â Â Â Â Â self.focus_out_end_iter_offset = None |
|---|
| 143 | |
|---|
| 144 | Â Â Â Â Â Â Â Â self.line_tooltip = tooltips.BaseTooltip() |
|---|
| 145 | Â Â Â Â Â Â Â Â |
|---|
| 146 | Â Â Â Â Â Â Â Â self.tv.focus_out_line_pixbuf = ConversationTextview.FOCUS_OUT_LINE_PIXBUF |
|---|
| 147 | |
|---|
| 148 |     def del_handlers(self): |
|---|
| 149 |         for i in self.handlers.keys(): |
|---|
| 150 |             if self.handlers[i].handler_is_connected(i): |
|---|
| 151 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[i].disconnect(i) |
|---|
| 152 |         del self.handlers |
|---|
| 153 | Â Â Â Â Â Â Â Â self.tv.destroy() |
|---|
| 154 | Â Â Â Â Â Â Â Â |
|---|
| 155 | Â Â Â Â Â Â Â Â |
|---|
| 156 | Â Â Â Â |
|---|
| 157 |     def update_tags(self): |
|---|
| 158 | Â Â Â Â Â Â Â Â self.tagIn.set_property('foreground', gajim.config.get('inmsgcolor')) |
|---|
| 159 | Â Â Â Â Â Â Â Â self.tagOut.set_property('foreground', gajim.config.get('outmsgcolor')) |
|---|
| 160 | Â Â Â Â Â Â Â Â self.tagStatus.set_property('foreground', |
|---|
| 161 | Â Â Â Â Â Â Â Â Â Â Â Â gajim.config.get('statusmsgcolor')) |
|---|
| 162 | Â Â Â Â Â Â Â Â self.tagURL.set_property('foreground', gajim.config.get('urlmsgcolor')) |
|---|
| 163 | Â Â Â Â Â Â Â Â self.tagMail.set_property('foreground', gajim.config.get('urlmsgcolor')) |
|---|
| 164 | |
|---|
| 165 |     def at_the_end(self): |
|---|
| 166 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 167 | Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 168 | Â Â Â Â Â Â Â Â end_rect = self.tv.get_iter_location(end_iter) |
|---|
| 169 | Â Â Â Â Â Â Â Â visible_rect = self.tv.get_visible_rect() |
|---|
| 170 |         if end_rect.y <= (visible_rect.y + visible_rect.height): |
|---|
| 171 |             return True |
|---|
| 172 |         return False |
|---|
| 173 | |
|---|
| 174 |     def scroll_to_end(self): |
|---|
| 175 | Â Â Â Â Â Â Â Â parent = self.tv.get_parent() |
|---|
| 176 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 177 | Â Â Â Â Â Â Â Â end_mark = buffer.get_mark('end') |
|---|
| 178 |         if not end_mark: |
|---|
| 179 |             return False |
|---|
| 180 | Â Â Â Â Â Â Â Â self.tv.scroll_to_mark(end_mark, 0, True, 0, 1) |
|---|
| 181 | Â Â Â Â Â Â Â Â adjustment = parent.get_hadjustment() |
|---|
| 182 | Â Â Â Â Â Â Â Â adjustment.set_value(0) |
|---|
| 183 |         return False |
|---|
| 184 | |
|---|
| 185 |     def bring_scroll_to_end(self, diff_y = 0): |
|---|
| 186 | Â Â Â Â Â Â Â Â ''' scrolls to the end of textview if end is not visible ''' |
|---|
| 187 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 188 | Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 189 | Â Â Â Â Â Â Â Â end_rect = self.tv.get_iter_location(end_iter) |
|---|
| 190 | Â Â Â Â Â Â Â Â visible_rect = self.tv.get_visible_rect() |
|---|
| 191 | Â Â Â Â Â Â Â Â |
|---|
| 192 |         if end_rect.y >= (visible_rect.y + visible_rect.height + diff_y): |
|---|
| 193 | Â Â Â Â Â Â Â Â Â Â Â Â gobject.idle_add(self.scroll_to_end_iter) |
|---|
| 194 | |
|---|
| 195 |     def scroll_to_end_iter(self): |
|---|
| 196 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 197 | Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 198 |         if not end_iter: |
|---|
| 199 |             return False |
|---|
| 200 | Â Â Â Â Â Â Â Â self.tv.scroll_to_iter(end_iter, 0, False, 1, 1) |
|---|
| 201 |         return False |
|---|
| 202 | |
|---|
| 203 |     def show_focus_out_line(self): |
|---|
| 204 |         if not self.allow_focus_out_line: |
|---|
| 205 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 206 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 207 | Â Â Â Â Â Â Â Â Â Â Â Â return |
|---|
| 208 | |
|---|
| 209 | Â Â Â Â Â Â Â Â print_focus_out_line = False |
|---|
| 210 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 211 | |
|---|
| 212 |         if self.focus_out_end_iter_offset is None: |
|---|
| 213 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 214 | Â Â Â Â Â Â Â Â Â Â Â Â print_focus_out_line = True |
|---|
| 215 | |
|---|
| 216 | Â Â Â Â Â Â Â Â else: |
|---|
| 217 |             if self.focus_out_end_iter_offset != buffer.get_end_iter().\ |
|---|
| 218 | Â Â Â Â Â Â Â Â Â Â Â Â get_offset(): |
|---|
| 219 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 220 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 221 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 222 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 223 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â print_focus_out_line = True |
|---|
| 224 | |
|---|
| 225 |         if print_focus_out_line and buffer.get_char_count() > 0: |
|---|
| 226 | Â Â Â Â Â Â Â Â Â Â Â Â buffer.begin_user_action() |
|---|
| 227 | |
|---|
| 228 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 229 |             if self.focus_out_end_iter_offset is not None: |
|---|
| 230 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â end_iter_for_previous_line = buffer.get_iter_at_offset( |
|---|
| 231 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.focus_out_end_iter_offset) |
|---|
| 232 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â begin_iter_for_previous_line = end_iter_for_previous_line.copy() |
|---|
| 233 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 234 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â begin_iter_for_previous_line.backward_chars(2) |
|---|
| 235 | |
|---|
| 236 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 237 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â buffer.delete(begin_iter_for_previous_line, |
|---|
| 238 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â end_iter_for_previous_line) |
|---|
| 239 | |
|---|
| 240 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 241 | Â Â Â Â Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 242 | Â Â Â Â Â Â Â Â Â Â Â Â buffer.insert(end_iter, '\n') |
|---|
| 243 | Â Â Â Â Â Â Â Â Â Â Â Â buffer.insert_pixbuf(end_iter, |
|---|
| 244 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ConversationTextview.FOCUS_OUT_LINE_PIXBUF) |
|---|
| 245 | |
|---|
| 246 | Â Â Â Â Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 247 | Â Â Â Â Â Â Â Â Â Â Â Â before_img_iter = end_iter.copy() |
|---|
| 248 | Â Â Â Â Â Â Â Â Â Â Â Â before_img_iter.backward_char() |
|---|
| 249 | Â Â Â Â Â Â Â Â Â Â Â Â buffer.apply_tag_by_name('focus-out-line', before_img_iter, end_iter) |
|---|
| 250 | |
|---|
| 251 | Â Â Â Â Â Â Â Â Â Â Â Â self.allow_focus_out_line = False |
|---|
| 252 | |
|---|
| 253 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 254 | Â Â Â Â Â Â Â Â Â Â Â Â self.focus_out_end_iter_offset = buffer.get_end_iter().get_offset() |
|---|
| 255 | |
|---|
| 256 | Â Â Â Â Â Â Â Â Â Â Â Â buffer.end_user_action() |
|---|
| 257 | |
|---|
| 258 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 259 | Â Â Â Â Â Â Â Â Â Â Â Â gobject.idle_add(self.scroll_to_end) |
|---|
| 260 | |
|---|
| 261 |     def show_line_tooltip(self): |
|---|
| 262 | Â Â Â Â Â Â Â Â pointer = self.tv.get_pointer() |
|---|
| 263 | Â Â Â Â Â Â Â Â x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer[0], |
|---|
| 264 | Â Â Â Â Â Â Â Â Â Â Â Â pointer[1]) |
|---|
| 265 | Â Â Â Â Â Â Â Â tags = self.tv.get_iter_at_location(x, y).get_tags() |
|---|
| 266 | Â Â Â Â Â Â Â Â tag_table = self.tv.get_buffer().get_tag_table() |
|---|
| 267 | Â Â Â Â Â Â Â Â over_line = False |
|---|
| 268 |         for tag in tags: |
|---|
| 269 |             if tag == tag_table.lookup('focus-out-line'): |
|---|
| 270 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â over_line = True |
|---|
| 271 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â break |
|---|
| 272 |         if over_line and not self.line_tooltip.win: |
|---|
| 273 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 274 | Â Â Â Â Â Â Â Â Â Â Â Â position = self.tv.window.get_origin() |
|---|
| 275 | Â Â Â Â Â Â Â Â Â Â Â Â self.line_tooltip.show_tooltip(_('Text below this line is what has ' |
|---|
| 276 | Â Â Â Â Â Â Â Â Â Â Â Â 'been said since the last time you paid attention to this group chat'), 8, position[1] + pointer[1]) |
|---|
| 277 | |
|---|
| 278 |     def on_textview_motion_notify_event(self, widget, event): |
|---|
| 279 | Â Â Â Â Â Â Â Â '''change the cursor to a hand when we are over a mail or an url''' |
|---|
| 280 | Â Â Â Â Â Â Â Â pointer_x, pointer_y, spam = self.tv.window.get_pointer() |
|---|
| 281 | Â Â Â Â Â Â Â Â x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer_x, |
|---|
| 282 | Â Â Â Â Â Â Â Â Â Â Â Â pointer_y) |
|---|
| 283 | Â Â Â Â Â Â Â Â tags = self.tv.get_iter_at_location(x, y).get_tags() |
|---|
| 284 |         if self.change_cursor: |
|---|
| 285 | Â Â Â Â Â Â Â Â Â Â Â Â self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor( |
|---|
| 286 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â gtk.gdk.Cursor(gtk.gdk.XTERM)) |
|---|
| 287 | Â Â Â Â Â Â Â Â Â Â Â Â self.change_cursor = None |
|---|
| 288 | Â Â Â Â Â Â Â Â tag_table = self.tv.get_buffer().get_tag_table() |
|---|
| 289 | Â Â Â Â Â Â Â Â over_line = False |
|---|
| 290 |         for tag in tags: |
|---|
| 291 |             if tag in (tag_table.lookup('url'), tag_table.lookup('mail')): |
|---|
| 292 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor( |
|---|
| 293 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â gtk.gdk.Cursor(gtk.gdk.HAND2)) |
|---|
| 294 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.change_cursor = tag |
|---|
| 295 |             elif tag == tag_table.lookup('focus-out-line'): |
|---|
| 296 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â over_line = True |
|---|
| 297 | |
|---|
| 298 |         if self.line_tooltip.timeout != 0: |
|---|
| 299 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 300 |             if not over_line: |
|---|
| 301 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.line_tooltip.hide_tooltip() |
|---|
| 302 |         if over_line and not self.line_tooltip.win: |
|---|
| 303 | Â Â Â Â Â Â Â Â Â Â Â Â self.line_tooltip.timeout = gobject.timeout_add(500, |
|---|
| 304 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.show_line_tooltip) |
|---|
| 305 | Â Â Â Â Â Â Â Â Â Â Â Â self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor( |
|---|
| 306 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)) |
|---|
| 307 | Â Â Â Â Â Â Â Â Â Â Â Â self.change_cursor = tag |
|---|
| 308 | |
|---|
| 309 |     def clear(self, tv = None): |
|---|
| 310 | Â Â Â Â Â Â Â Â '''clear text in the textview''' |
|---|
| 311 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 312 | Â Â Â Â Â Â Â Â start, end = buffer.get_bounds() |
|---|
| 313 | Â Â Â Â Â Â Â Â buffer.delete(start, end) |
|---|
| 314 | Â Â Â Â Â Â Â Â self.focus_out_end_iter_offset = None |
|---|
| 315 | |
|---|
| 316 |     def visit_url_from_menuitem(self, widget, link): |
|---|
| 317 | Â Â Â Â Â Â Â Â '''basically it filters out the widget instance''' |
|---|
| 318 | Â Â Â Â Â Â Â Â helpers.launch_browser_mailer('url', link) |
|---|
| 319 | |
|---|
| 320 |     def on_textview_populate_popup(self, textview, menu): |
|---|
| 321 | Â Â Â Â Â Â Â Â '''we override the default context menu and we prepend Clear |
|---|
| 322 | Â Â Â Â Â Â Â Â (only if used_in_history_window is False) |
|---|
| 323 | Â Â Â Â Â Â Â Â and if we have sth selected we show a submenu with actions on the phrase |
|---|
| 324 | Â Â Â Â Â Â Â Â (see on_conversation_textview_button_press_event)''' |
|---|
| 325 | |
|---|
| 326 | Â Â Â Â Â Â Â Â separator_menuitem_was_added = False |
|---|
| 327 |         if not self.used_in_history_window: |
|---|
| 328 | Â Â Â Â Â Â Â Â Â Â Â Â item = gtk.SeparatorMenuItem() |
|---|
| 329 | Â Â Â Â Â Â Â Â Â Â Â Â menu.prepend(item) |
|---|
| 330 | Â Â Â Â Â Â Â Â Â Â Â Â separator_menuitem_was_added = True |
|---|
| 331 | |
|---|
| 332 | Â Â Â Â Â Â Â Â Â Â Â Â item = gtk.ImageMenuItem(gtk.STOCK_CLEAR) |
|---|
| 333 | Â Â Â Â Â Â Â Â Â Â Â Â menu.prepend(item) |
|---|
| 334 | Â Â Â Â Â Â Â Â Â Â Â Â id = item.connect('activate', self.clear) |
|---|
| 335 | Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = item |
|---|
| 336 | |
|---|
| 337 |         if self.selected_phrase: |
|---|
| 338 |             if not separator_menuitem_was_added: |
|---|
| 339 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â item = gtk.SeparatorMenuItem() |
|---|
| 340 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â menu.prepend(item) |
|---|
| 341 | |
|---|
| 342 | Â Â Â Â Â Â Â Â Â Â Â Â self.selected_phrase = helpers.reduce_chars_newlines( |
|---|
| 343 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.selected_phrase, 25, 2) |
|---|
| 344 | Â Â Â Â Â Â Â Â Â Â Â Â item = gtk.MenuItem(_('_Actions for "%s"') % self.selected_phrase) |
|---|
| 345 | Â Â Â Â Â Â Â Â Â Â Â Â menu.prepend(item) |
|---|
| 346 | Â Â Â Â Â Â Â Â Â Â Â Â submenu = gtk.Menu() |
|---|
| 347 | Â Â Â Â Â Â Â Â Â Â Â Â item.set_submenu(submenu) |
|---|
| 348 | |
|---|
| 349 | Â Â Â Â Â Â Â Â Â Â Â Â always_use_en = gajim.config.get('always_english_wikipedia') |
|---|
| 350 |             if always_use_en: |
|---|
| 351 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â link = 'http://en.wikipedia.org/wiki/Special:Search?search=%s'\ |
|---|
| 352 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â % self.selected_phrase |
|---|
| 353 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 354 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â link = 'http://%s.wikipedia.org/wiki/Special:Search?search=%s'\ |
|---|
| 355 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â % (gajim.LANG, self.selected_phrase) |
|---|
| 356 | Â Â Â Â Â Â Â Â Â Â Â Â item = gtk.MenuItem(_('Read _Wikipedia Article')) |
|---|
| 357 | Â Â Â Â Â Â Â Â Â Â Â Â id = item.connect('activate', self.visit_url_from_menuitem, link) |
|---|
| 358 | Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = item |
|---|
| 359 | Â Â Â Â Â Â Â Â Â Â Â Â submenu.append(item) |
|---|
| 360 | |
|---|
| 361 | Â Â Â Â Â Â Â Â Â Â Â Â item = gtk.MenuItem(_('Look it up in _Dictionary')) |
|---|
| 362 | Â Â Â Â Â Â Â Â Â Â Â Â dict_link = gajim.config.get('dictionary_url') |
|---|
| 363 |             if dict_link == 'WIKTIONARY': |
|---|
| 364 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 365 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â always_use_en = gajim.config.get('always_english_wiktionary') |
|---|
| 366 |                 if always_use_en: |
|---|
| 367 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â link = 'http://en.wiktionary.org/wiki/Special:Search?search=%s'\ |
|---|
| 368 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â % self.selected_phrase |
|---|
| 369 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 370 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â link = 'http://%s.wiktionary.org/wiki/Special:Search?search=%s'\ |
|---|
| 371 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â % (gajim.LANG, self.selected_phrase) |
|---|
| 372 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â id = item.connect('activate', self.visit_url_from_menuitem, link) |
|---|
| 373 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = item |
|---|
| 374 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 375 |                 if dict_link.find('%s') == -1: |
|---|
| 376 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 377 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â item = gtk.MenuItem(_('Dictionary URL is missing an "%s" and it is not WIKTIONARY')) |
|---|
| 378 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â item.set_property('sensitive', False) |
|---|
| 379 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 380 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â link = dict_link % self.selected_phrase |
|---|
| 381 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â id = item.connect('activate', self.visit_url_from_menuitem, |
|---|
| 382 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â link) |
|---|
| 383 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = item |
|---|
| 384 | Â Â Â Â Â Â Â Â Â Â Â Â submenu.append(item) |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | Â Â Â Â Â Â Â Â Â Â Â Â search_link = gajim.config.get('search_engine') |
|---|
| 388 |             if search_link.find('%s') == -1: |
|---|
| 389 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 390 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â item = gtk.MenuItem(_('Web Search URL is missing an "%s"')) |
|---|
| 391 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â item.set_property('sensitive', False) |
|---|
| 392 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 393 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â item = gtk.MenuItem(_('Web _Search for it')) |
|---|
| 394 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â link =Â search_link % self.selected_phrase |
|---|
| 395 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â id = item.connect('activate', self.visit_url_from_menuitem, link) |
|---|
| 396 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = item |
|---|
| 397 | Â Â Â Â Â Â Â Â Â Â Â Â submenu.append(item) |
|---|
| 398 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 399 | Â Â Â Â Â Â Â Â Â Â Â Â item = gtk.MenuItem(_('Open as _Link')) |
|---|
| 400 | Â Â Â Â Â Â Â Â Â Â Â Â id = item.connect('activate', self.visit_url_from_menuitem, link) |
|---|
| 401 | Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = item |
|---|
| 402 | Â Â Â Â Â Â Â Â Â Â Â Â submenu.append(item) |
|---|
| 403 | |
|---|
| 404 | Â Â Â Â Â Â Â Â menu.show_all() |
|---|
| 405 | |
|---|
| 406 |     def on_textview_button_press_event(self, widget, event): |
|---|
| 407 | Â Â Â Â Â Â Â Â |
|---|
| 408 | Â Â Â Â Â Â Â Â |
|---|
| 409 | Â Â Â Â Â Â Â Â self.selected_phrase = ''Â |
|---|
| 410 | |
|---|
| 411 |         if event.button != 3: |
|---|
| 412 |             return False |
|---|
| 413 | |
|---|
| 414 | Â Â Â Â Â Â Â Â x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, |
|---|
| 415 | Â Â Â Â Â Â Â Â Â Â Â Â int(event.x), int(event.y)) |
|---|
| 416 | Â Â Â Â Â Â Â Â iter = self.tv.get_iter_at_location(x, y) |
|---|
| 417 | Â Â Â Â Â Â Â Â tags = iter.get_tags() |
|---|
| 418 | |
|---|
| 419 | |
|---|
| 420 |         if tags: |
|---|
| 421 |             for tag in tags: |
|---|
| 422 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â tag_name = tag.get_property('name') |
|---|
| 423 |                 if tag_name in ('url', 'mail'): |
|---|
| 424 |                     return True |
|---|
| 425 | |
|---|
| 426 | Â Â Â Â Â Â Â Â |
|---|
| 427 | Â Â Â Â Â Â Â Â |
|---|
| 428 | Â Â Â Â Â Â Â Â |
|---|
| 429 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 430 | Â Â Â Â Â Â Â Â return_val = buffer.get_selection_bounds() |
|---|
| 431 |         if return_val: |
|---|
| 432 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 433 | Â Â Â Â Â Â Â Â Â Â Â Â start_sel, finish_sel = return_val[0], return_val[1] |
|---|
| 434 | Â Â Â Â Â Â Â Â Â Â Â Â self.selected_phrase = buffer.get_text(start_sel, finish_sel).decode('utf-8') |
|---|
| 435 | |
|---|
| 436 |     def on_open_link_activate(self, widget, kind, text): |
|---|
| 437 | Â Â Â Â Â Â Â Â helpers.launch_browser_mailer(kind, text) |
|---|
| 438 | |
|---|
| 439 |     def on_copy_link_activate(self, widget, text): |
|---|
| 440 | Â Â Â Â Â Â Â Â clip = gtk.clipboard_get() |
|---|
| 441 | Â Â Â Â Â Â Â Â clip.set_text(text) |
|---|
| 442 | |
|---|
| 443 |     def on_start_chat_activate(self, widget, jid): |
|---|
| 444 | Â Â Â Â Â Â Â Â gajim.interface.roster.new_chat_from_jid(self.account, jid) |
|---|
| 445 | |
|---|
| 446 |     def on_join_group_chat_menuitem_activate(self, widget, room_jid): |
|---|
| 447 |         if 'join_gc' in gajim.interface.instances[self.account]: |
|---|
| 448 | Â Â Â Â Â Â Â Â Â Â Â Â instance = gajim.interface.instances[self.account]['join_gc'] |
|---|
| 449 | Â Â Â Â Â Â Â Â Â Â Â Â instance.xml.get_widget('room_jid_entry').set_text(room_jid) |
|---|
| 450 | Â Â Â Â Â Â Â Â Â Â Â Â gajim.interface.instances[self.account]['join_gc'].window.present() |
|---|
| 451 | Â Â Â Â Â Â Â Â else: |
|---|
| 452 | Â Â Â Â Â Â Â Â Â Â Â Â try: |
|---|
| 453 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â gajim.interface.instances[self.account]['join_gc'] = \ |
|---|
| 454 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dialogs.JoinGroupchatWindow(self.account, room_jid) |
|---|
| 455 |             except GajimGeneralException: |
|---|
| 456 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â pass |
|---|
| 457 | |
|---|
| 458 |     def on_add_to_roster_activate(self, widget, jid): |
|---|
| 459 | Â Â Â Â Â Â Â Â dialogs.AddNewContactWindow(self.account, jid) |
|---|
| 460 | |
|---|
| 461 |     def make_link_menu(self, event, kind, text): |
|---|
| 462 | Â Â Â Â Â Â Â Â xml = gtkgui_helpers.get_glade('chat_context_menu.glade') |
|---|
| 463 | Â Â Â Â Â Â Â Â menu = xml.get_widget('chat_context_menu') |
|---|
| 464 | Â Â Â Â Â Â Â Â childs = menu.get_children() |
|---|
| 465 |         if kind == 'url': |
|---|
| 466 | Â Â Â Â Â Â Â Â Â Â Â Â id = childs[0].connect('activate', self.on_copy_link_activate, text) |
|---|
| 467 | Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = childs[0] |
|---|
| 468 | Â Â Â Â Â Â Â Â Â Â Â Â id = childs[1].connect('activate', self.on_open_link_activate, kind, text) |
|---|
| 469 | Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = childs[1] |
|---|
| 470 | Â Â Â Â Â Â Â Â Â Â Â Â childs[2].hide() |
|---|
| 471 | Â Â Â Â Â Â Â Â Â Â Â Â childs[3].hide() |
|---|
| 472 | Â Â Â Â Â Â Â Â Â Â Â Â childs[4].hide() |
|---|
| 473 | Â Â Â Â Â Â Â Â Â Â Â Â childs[5].hide() |
|---|
| 474 | Â Â Â Â Â Â Â Â Â Â Â Â childs[6].hide() |
|---|
| 475 | Â Â Â Â Â Â Â Â Â Â Â Â childs[7].hide() |
|---|
| 476 | Â Â Â Â Â Â Â Â else: |
|---|
| 477 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 478 | Â Â Â Â Â Â Â Â Â Â Â Â join_group_chat_menuitem = xml.get_widget('join_group_chat_menuitem') |
|---|
| 479 | Â Â Â Â Â Â Â Â Â Â Â Â muc_icon = gajim.interface.roster.load_icon('muc_active') |
|---|
| 480 |             if muc_icon: |
|---|
| 481 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â join_group_chat_menuitem.set_image(muc_icon) |
|---|
| 482 | |
|---|
| 483 | Â Â Â Â Â Â Â Â Â Â Â Â text = text.lower() |
|---|
| 484 | Â Â Â Â Â Â Â Â Â Â Â Â id = childs[2].connect('activate', self.on_copy_link_activate, text) |
|---|
| 485 | Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = childs[2] |
|---|
| 486 | Â Â Â Â Â Â Â Â Â Â Â Â id = childs[3].connect('activate', self.on_open_link_activate, kind, text) |
|---|
| 487 | Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = childs[3] |
|---|
| 488 | Â Â Â Â Â Â Â Â Â Â Â Â id = childs[5].connect('activate', self.on_start_chat_activate, text) |
|---|
| 489 | Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = childs[5] |
|---|
| 490 | Â Â Â Â Â Â Â Â Â Â Â Â id = childs[6].connect('activate', |
|---|
| 491 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.on_join_group_chat_menuitem_activate, text) |
|---|
| 492 | Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = childs[6] |
|---|
| 493 | |
|---|
| 494 | Â Â Â Â Â Â Â Â Â Â Â Â allow_add = False |
|---|
| 495 | Â Â Â Â Â Â Â Â Â Â Â Â c = gajim.contacts.get_first_contact_from_jid(self.account, text) |
|---|
| 496 |             if c and not gajim.contacts.is_pm_from_contact(self.account, c): |
|---|
| 497 |                 if _('Not in Roster') in c.groups: |
|---|
| 498 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â allow_add = True |
|---|
| 499 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 500 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â allow_add = True |
|---|
| 501 | |
|---|
| 502 |             if allow_add: |
|---|
| 503 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â id = childs[7].connect('activate', self.on_add_to_roster_activate, text) |
|---|
| 504 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.handlers[id] = childs[7] |
|---|
| 505 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â childs[7].show() |
|---|
| 506 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 507 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â childs[7].hide() |
|---|
| 508 | |
|---|
| 509 | Â Â Â Â Â Â Â Â Â Â Â Â childs[0].hide() |
|---|
| 510 | Â Â Â Â Â Â Â Â Â Â Â Â childs[1].hide() |
|---|
| 511 | |
|---|
| 512 | Â Â Â Â Â Â Â Â menu.popup(None, None, None, event.button, event.time) |
|---|
| 513 | |
|---|
| 514 |     def hyperlink_handler(self, texttag, widget, event, iter, kind): |
|---|
| 515 |         if event.type == gtk.gdk.BUTTON_PRESS: |
|---|
| 516 | Â Â Â Â Â Â Â Â Â Â Â Â begin_iter = iter.copy() |
|---|
| 517 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 518 |             while not begin_iter.begins_tag(texttag): |
|---|
| 519 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â begin_iter.backward_char() |
|---|
| 520 | Â Â Â Â Â Â Â Â Â Â Â Â end_iter = iter.copy() |
|---|
| 521 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 522 |             while not end_iter.ends_tag(texttag): |
|---|
| 523 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â end_iter.forward_char() |
|---|
| 524 | Â Â Â Â Â Â Â Â Â Â Â Â word = self.tv.get_buffer().get_text(begin_iter, end_iter).decode('utf-8') |
|---|
| 525 |             if event.button == 3: |
|---|
| 526 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.make_link_menu(event, kind, word) |
|---|
| 527 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 528 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 529 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â helpers.launch_browser_mailer(kind, word) |
|---|
| 530 | |
|---|
| 531 |     def html_hyperlink_handler(self, texttag, widget, event, iter, kind, href): |
|---|
| 532 |         if event.type == gtk.gdk.BUTTON_PRESS: |
|---|
| 533 |             if event.button == 3: |
|---|
| 534 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.make_link_menu(event, kind, href) |
|---|
| 535 |                 return True |
|---|
| 536 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 537 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 538 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â helpers.launch_browser_mailer(kind, href) |
|---|
| 539 | |
|---|
| 540 | |
|---|
| 541 |     def detect_and_print_special_text(self, otext, other_tags): |
|---|
| 542 | Â Â Â Â Â Â Â Â '''detects special text (emots & links & formatting) |
|---|
| 543 | Â Â Â Â Â Â Â Â prints normal text before any special text it founts, |
|---|
| 544 | Â Â Â Â Â Â Â Â then print special text (that happens many times until |
|---|
| 545 | Â Â Â Â Â Â Â Â last special text is printed) and then returns the index |
|---|
| 546 | Â Â Â Â Â Â Â Â after *last* special text, so we can print it in |
|---|
| 547 | Â Â Â Â Â Â Â Â print_conversation_line()''' |
|---|
| 548 | |
|---|
| 549 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 550 | |
|---|
| 551 | Â Â Â Â Â Â Â Â start = 0 |
|---|
| 552 | Â Â Â Â Â Â Â Â end = 0 |
|---|
| 553 | Â Â Â Â Â Â Â Â index = 0 |
|---|
| 554 | |
|---|
| 555 | Â Â Â Â Â Â Â Â |
|---|
| 556 |         if gajim.config.get('emoticons_theme'): |
|---|
| 557 | Â Â Â Â Â Â Â Â Â Â Â Â iterator = gajim.interface.emot_and_basic_re.finditer(otext) |
|---|
| 558 | Â Â Â Â Â Â Â Â else: |
|---|
| 559 | Â Â Â Â Â Â Â Â Â Â Â Â iterator = gajim.interface.basic_pattern_re.finditer(otext) |
|---|
| 560 |         for match in iterator: |
|---|
| 561 | Â Â Â Â Â Â Â Â Â Â Â Â start, end = match.span() |
|---|
| 562 | Â Â Â Â Â Â Â Â Â Â Â Â special_text = otext[start:end] |
|---|
| 563 |             if start != 0: |
|---|
| 564 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â text_before_special_text = otext[index:start] |
|---|
| 565 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 566 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 567 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â buffer.insert_with_tags_by_name(end_iter, |
|---|
| 568 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â text_before_special_text, *other_tags) |
|---|
| 569 | Â Â Â Â Â Â Â Â Â Â Â Â index = end |
|---|
| 570 | |
|---|
| 571 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 572 | Â Â Â Â Â Â Â Â Â Â Â Â self.print_special_text(special_text, other_tags) |
|---|
| 573 | |
|---|
| 574 |         return index |
|---|
| 575 | |
|---|
| 576 |     def print_special_text(self, special_text, other_tags): |
|---|
| 577 | Â Â Â Â Â Â Â Â '''is called by detect_and_print_special_text and prints |
|---|
| 578 | Â Â Â Â Â Â Â Â special text (emots, links, formatting)''' |
|---|
| 579 | Â Â Â Â Â Â Â Â tags = [] |
|---|
| 580 | Â Â Â Â Â Â Â Â use_other_tags = True |
|---|
| 581 | Â Â Â Â Â Â Â Â show_ascii_formatting_chars = \ |
|---|
| 582 | Â Â Â Â Â Â Â Â Â Â Â Â gajim.config.get('show_ascii_formatting_chars') |
|---|
| 583 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 584 | |
|---|
| 585 | Â Â Â Â Â Â Â Â possible_emot_ascii_caps = special_text.upper() |
|---|
| 586 |         if gajim.config.get('emoticons_theme') and \ |
|---|
| 587 |         possible_emot_ascii_caps in gajim.interface.emoticons.keys(): |
|---|
| 588 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 589 | Â Â Â Â Â Â Â Â Â Â Â Â emot_ascii = possible_emot_ascii_caps |
|---|
| 590 | Â Â Â Â Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 591 | Â Â Â Â Â Â Â Â Â Â Â Â anchor = buffer.create_child_anchor(end_iter) |
|---|
| 592 | Â Â Â Â Â Â Â Â Â Â Â Â img = gtk.Image() |
|---|
| 593 | Â Â Â Â Â Â Â Â Â Â Â Â animations = gajim.interface.emoticons_animations |
|---|
| 594 |             if not emot_ascii in animations: |
|---|
| 595 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â animations[emot_ascii] = gtk.gdk.PixbufAnimation( |
|---|
| 596 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â gajim.interface.emoticons[emot_ascii]) |
|---|
| 597 | Â Â Â Â Â Â Â Â Â Â Â Â img.set_from_animation(animations[emot_ascii]) |
|---|
| 598 | Â Â Â Â Â Â Â Â Â Â Â Â img.show() |
|---|
| 599 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 600 | Â Â Â Â Â Â Â Â Â Â Â Â self.tv.add_child_at_anchor(img, anchor) |
|---|
| 601 | Â Â Â Â Â Â Â Â |
|---|
| 602 |         elif special_text.startswith('http://') or \ |
|---|
| 603 |             special_text.startswith('www.') or \ |
|---|
| 604 |             special_text.startswith('ftp://') or \ |
|---|
| 605 |             special_text.startswith('ftp.') or \ |
|---|
| 606 |             special_text.startswith('https://') or \ |
|---|
| 607 |             special_text.startswith('gopher://') or \ |
|---|
| 608 |             special_text.startswith('news://') or \ |
|---|
| 609 |             special_text.startswith('ed2k://') or \ |
|---|
| 610 |             special_text.startswith('irc://') or \ |
|---|
| 611 |             special_text.startswith('sip:') or \ |
|---|
| 612 | Â Â Â Â Â Â Â Â Â Â Â Â special_text.startswith('magnet:'): |
|---|
| 613 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 614 | Â Â Â Â Â Â Â Â Â Â Â Â tags.append('url') |
|---|
| 615 | Â Â Â Â Â Â Â Â Â Â Â Â use_other_tags = False |
|---|
| 616 |         elif special_text.startswith('mailto:') or \ |
|---|
| 617 | Â Â Â Â Â Â Â Â gajim.interface.sth_at_sth_dot_sth_re.match(special_text): |
|---|
| 618 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 619 | Â Â Â Â Â Â Â Â Â Â Â Â tags.append('mail') |
|---|
| 620 | Â Â Â Â Â Â Â Â Â Â Â Â use_other_tags = False |
|---|
| 621 |         elif special_text.startswith('*'): |
|---|
| 622 | Â Â Â Â Â Â Â Â Â Â Â Â tags.append('bold') |
|---|
| 623 |             if special_text[1] == '/' and special_text[-2] == '/' and len(special_text) > 4: |
|---|
| 624 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â tags.append('italic') |
|---|
| 625 |                 if not show_ascii_formatting_chars: |
|---|
| 626 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â special_text = special_text[2:-2] |
|---|
| 627 |             elif special_text[1] == '_' and special_text[-2] == '_' and len(special_text) > 4: |
|---|
| 628 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â tags.append('underline') |
|---|
| 629 |                 if not show_ascii_formatting_chars: |
|---|
| 630 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â special_text = special_text[2:-2] |
|---|
| 631 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 632 |                 if not show_ascii_formatting_chars: |
|---|
| 633 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â special_text = special_text[1:-1] |
|---|
| 634 |         elif special_text.startswith('/'): |
|---|
| 635 | Â Â Â Â Â Â Â Â Â Â Â Â tags.append('italic') |
|---|
| 636 |             if special_text[1] == '*' and special_text[-2] == '*' and len(special_text) > 4: |
|---|
| 637 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â tags.append('bold') |
|---|
| 638 |                 if not show_ascii_formatting_chars: |
|---|
| 639 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â special_text = special_text[2:-2] |
|---|
| 640 |             elif special_text[1] == '_' and special_text[-2] == '_' and len(special_text) > 4: |
|---|
| 641 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â tags.append('underline') |
|---|
| 642 |                 if not show_ascii_formatting_chars: |
|---|
| 643 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â special_text = special_text[2:-2] |
|---|
| 644 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 645 |                 if not show_ascii_formatting_chars: |
|---|
| 646 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â special_text = special_text[1:-1] |
|---|
| 647 |         elif special_text.startswith('_'): |
|---|
| 648 | Â Â Â Â Â Â Â Â Â Â Â Â tags.append('underline') |
|---|
| 649 |             if special_text[1] == '*' and special_text[-2] == '*' and len(special_text) > 4: |
|---|
| 650 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â tags.append('bold') |
|---|
| 651 |                 if not show_ascii_formatting_chars: |
|---|
| 652 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â special_text = special_text[2:-2] |
|---|
| 653 |             elif special_text[1] == '/' and special_text[-2] == '/' and len(special_text) > 4: |
|---|
| 654 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â tags.append('italic') |
|---|
| 655 |                 if not show_ascii_formatting_chars: |
|---|
| 656 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â special_text = special_text[2:-2] |
|---|
| 657 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 658 |                 if not show_ascii_formatting_chars: |
|---|
| 659 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â special_text = special_text[1:-1] |
|---|
| 660 | Â Â Â Â Â Â Â Â else: |
|---|
| 661 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 662 | Â Â Â Â Â Â Â Â Â Â Â Â tags.append('url') |
|---|
| 663 | Â Â Â Â Â Â Â Â Â Â Â Â use_other_tags = False |
|---|
| 664 | |
|---|
| 665 |         if len(tags) > 0: |
|---|
| 666 | Â Â Â Â Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 667 | Â Â Â Â Â Â Â Â Â Â Â Â all_tags = tags[:] |
|---|
| 668 |             if use_other_tags: |
|---|
| 669 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â all_tags += other_tags |
|---|
| 670 | Â Â Â Â Â Â Â Â Â Â Â Â buffer.insert_with_tags_by_name(end_iter, special_text, *all_tags) |
|---|
| 671 | |
|---|
| 672 |     def print_empty_line(self): |
|---|
| 673 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 674 | Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 675 | Â Â Â Â Â Â Â Â buffer.insert_with_tags_by_name(end_iter, '\n', 'eol') |
|---|
| 676 | |
|---|
| 677 |     def print_conversation_line(self, text, jid, kind, name, tim, |
|---|
| 678 | Â Â Â Â other_tags_for_name = [], other_tags_for_time = [], other_tags_for_text = [], |
|---|
| 679 | Â Â Â Â subject = None, old_kind = None, xhtml = None): |
|---|
| 680 | Â Â Â Â Â Â Â Â '''prints 'chat' type messages''' |
|---|
| 681 | Â Â Â Â Â Â Â Â buffer = self.tv.get_buffer() |
|---|
| 682 | Â Â Â Â Â Â Â Â buffer.begin_user_action() |
|---|
| 683 | Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 684 | Â Â Â Â Â Â Â Â at_the_end = False |
|---|
| 685 |         if self.at_the_end(): |
|---|
| 686 | Â Â Â Â Â Â Â Â Â Â Â Â at_the_end = True |
|---|
| 687 | |
|---|
| 688 |         if buffer.get_char_count() > 0: |
|---|
| 689 | Â Â Â Â Â Â Â Â Â Â Â Â buffer.insert_with_tags_by_name(end_iter, '\n', 'eol') |
|---|
| 690 |         if kind == 'incoming_queue': |
|---|
| 691 | Â Â Â Â Â Â Â Â Â Â Â Â kind = 'incoming' |
|---|
| 692 |         if old_kind == 'incoming_queue': |
|---|
| 693 | Â Â Â Â Â Â Â Â Â Â Â Â old_kind = 'incoming' |
|---|
| 694 | Â Â Â Â Â Â Â Â |
|---|
| 695 |         if not tim: |
|---|
| 696 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 697 | Â Â Â Â Â Â Â Â Â Â Â Â tim = time.localtime() |
|---|
| 698 | Â Â Â Â Â Â Â Â current_print_time = gajim.config.get('print_time') |
|---|
| 699 |         if current_print_time == 'always' and kind != 'info': |
|---|
| 700 | Â Â Â Â Â Â Â Â Â Â Â Â timestamp_str = self.get_time_to_show(tim) |
|---|
| 701 | Â Â Â Â Â Â Â Â Â Â Â Â timestamp = time.strftime(timestamp_str, tim) |
|---|
| 702 | Â Â Â Â Â Â Â Â Â Â Â Â buffer.insert_with_tags_by_name(end_iter, timestamp, |
|---|
| 703 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *other_tags_for_time) |
|---|
| 704 |         elif current_print_time == 'sometimes' and kind != 'info': |
|---|
| 705 | Â Â Â Â Â Â Â Â Â Â Â Â every_foo_seconds = 60 * gajim.config.get( |
|---|
| 706 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'print_ichat_every_foo_minutes') |
|---|
| 707 | Â Â Â Â Â Â Â Â Â Â Â Â seconds_passed = time.mktime(tim) - self.last_time_printout |
|---|
| 708 |             if seconds_passed > every_foo_seconds: |
|---|
| 709 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.last_time_printout = time.mktime(tim) |
|---|
| 710 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â end_iter = buffer.get_end_iter() |
|---|
| 711 |                 if gajim.config.get('print_time_fuzzy') > 0: |
|---|
| 712 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â fc = FuzzyClock() |
|---|
| 713 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â fc.setTime(time.strftime('%H:%M', tim)) |
|---|
| 714 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ft = fc.getFuzzyTime(gajim.config.get('print_time_fuzzy')) |
|---|
| 715 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â tim_format = ft.decode(locale.getpreferredencoding()) |
|---|
| 716 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 717 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â tim_format = self.get_time_to_show(tim) |
|---|
| 718 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â buffer.insert_with_tags_by_name(end_iter, tim_format + '\n', |
|---|
| 719 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'time_sometimes') |
|---|
| 720 | Â Â Â Â Â Â Â Â |
|---|
| 721 |         if kind == 'info': |
|---|
| 722 | Â Â Â Â Â Â Â Â Â Â Â Â kind = 'status' |
|---|
| 723 | Â Â Â Â Â Â Â Â other_text_tag = self.detect_other_text_tag(text, kind) |
|---|
| 724 | Â Â Â Â Â Â Â Â text_tags = other_tags_for_text[:] |
|---|
| 725 |         if other_text_tag: |
|---|
| 726 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 727 | Â Â Â Â Â Â Â Â Â Â Â Â text_tags.append(other_text_tag) |
|---|
| 728 | Â Â Â Â Â Â Â Â else: |
|---|
| 729 |             if gajim.config.get( |
|---|
| 730 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'chat_merge_consecutive_nickname'): |
|---|
| 731 |                 if kind != old_kind: |
|---|
| 732 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.print_name(name, kind, other_tags_for_name) |
|---|
| 733 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 734 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.print_real_text(gajim.config.get( |
|---|
| 735 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â 'chat_merge_consecutive_nickname_indent')) |
|---|
| 736 | Â Â Â Â Â Â Â Â Â Â Â Â else: |
|---|
| 737 | Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â self.print_name(name, kind, other_tags_for_name) |
|---|
| 738 | Â Â Â Â Â Â Â Â self.print_subject(subject) |
|---|
| 739 | Â Â Â Â Â Â Â Â self.print_real_text(text, text_tags, name, xhtml) |
|---|
| 740 | |
|---|
| 741 | Â Â Â Â Â Â Â Â |
|---|
| 742 |         if at_the_end or kind == 'outgoing': |
|---|
| 743 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 744 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 745 | Â Â Â Â Â Â Â Â Â Â Â Â gobject.idle_add(self.scroll_to_end) |
|---|
| 746 | |
|---|
| 747 | Â Â Â Â Â Â Â Â buffer.end_user_action() |
|---|
| 748 | |
|---|
| 749 |     def get_time_to_show(self, tim): |
|---|
| 750 | Â Â Â Â Â Â Â Â '''Get the time, with the day before if needed and return it. |
|---|
| 751 | Â Â Â Â Â Â Â Â It DOESN'T format a fuzzy time''' |
|---|
| 752 | Â Â Â Â Â Â Â Â format = '' |
|---|
| 753 | Â Â Â Â Â Â Â Â |
|---|
| 754 | Â Â Â Â Â Â Â Â |
|---|
| 755 | Â Â Â Â Â Â Â Â |
|---|
| 756 | Â Â Â Â Â Â Â Â diff_day = int(timegm(time.localtime())) / 86400 -\ |
|---|
| 757 | Â Â Â Â Â Â Â Â Â Â Â Â int(timegm(tim)) / 86400 |
|---|
| 758 |         if diff_day == 0: |
|---|
| 759 | Â Â Â Â Â Â Â Â Â Â Â Â day_str = '' |
|---|
| 760 |         elif diff_day == 1: |
|---|
| 761 | Â Â Â Â Â Â Â Â Â Â Â Â day_str = _('Yesterday') |
|---|
| 762 | Â Â Â Â Â Â Â Â else: |
|---|
| 763 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 764 | Â Â Â Â Â Â Â Â Â Â Â Â |
|---|
| 765 | Â Â Â Â Â Â Â Â Â Â Â Â day_str = _('%i days ago') % diff_day |
|---|
| 766 |         if day_str: |
|---|
| 767 | Â Â Â Â Â Â Â Â Â Â Â Â format += day_str + ' ' |
|---|
| 768 | Â Â Â Â Â Â Â Â timestamp_str = gajim.config.get('time_stamp') |
|---|
| 769 | Â Â Â Â Â Â Â Â timestamp_str = helpers.from_one_line(timestamp_str) |
|---|
| 770 | Â Â Â Â Â Â |
|---|