2005-10-28 23:46:55 +02:00
|
|
|
## conversation_textview.py
|
|
|
|
##
|
2006-10-07 14:50:34 +02:00
|
|
|
## Copyright (C) 2005-2006 Yann Le Boulanger <asterix@lagaule.org>
|
|
|
|
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem@gmail.com>
|
|
|
|
## Copyright (C) 2005-2006 Travis Shirk <travis@pobox.com>
|
2005-10-28 23:46:55 +02:00
|
|
|
##
|
|
|
|
## This program is free software; you can redistribute it and/or modify
|
|
|
|
## it under the terms of the GNU General Public License as published
|
|
|
|
## by the Free Software Foundation; version 2 only.
|
|
|
|
##
|
|
|
|
## This program is distributed in the hope that it will be useful,
|
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
|
|
|
|
2007-04-25 23:51:08 +02:00
|
|
|
import random
|
|
|
|
from tempfile import gettempdir
|
|
|
|
from subprocess import Popen
|
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
import gtk
|
|
|
|
import pango
|
|
|
|
import gobject
|
|
|
|
import time
|
2006-07-27 12:54:12 +02:00
|
|
|
import os
|
2005-10-28 23:46:55 +02:00
|
|
|
import tooltips
|
|
|
|
import dialogs
|
2006-03-05 23:13:37 +01:00
|
|
|
import locale
|
2007-07-21 16:58:56 +02:00
|
|
|
import Queue
|
2005-10-28 23:46:55 +02:00
|
|
|
|
2006-05-02 18:25:59 +02:00
|
|
|
import gtkgui_helpers
|
2005-10-28 23:46:55 +02:00
|
|
|
from common import gajim
|
|
|
|
from common import helpers
|
2006-01-17 23:36:54 +01:00
|
|
|
from calendar import timegm
|
2006-06-15 09:14:39 +02:00
|
|
|
from common.fuzzyclock import FuzzyClock
|
2005-10-28 23:46:55 +02:00
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
from htmltextview import HtmlTextView
|
2006-10-10 17:29:10 +02:00
|
|
|
from common.exceptions import GajimGeneralException
|
2006-10-03 16:12:42 +02:00
|
|
|
|
2006-04-18 17:36:16 +02:00
|
|
|
class ConversationTextview:
|
2005-10-29 17:30:24 +02:00
|
|
|
'''Class for the conversation textview (where user reads already said messages)
|
|
|
|
for chat/groupchat windows'''
|
2007-02-09 00:00:27 +01:00
|
|
|
|
|
|
|
path_to_file = os.path.join(gajim.DATA_DIR, 'pixmaps', 'muc_separator.png')
|
|
|
|
FOCUS_OUT_LINE_PIXBUF = gtk.gdk.pixbuf_new_from_file(path_to_file)
|
|
|
|
|
2006-10-07 15:23:20 +02:00
|
|
|
def __init__(self, account, used_in_history_window = False):
|
|
|
|
'''if used_in_history_window is True, then we do not show
|
|
|
|
Clear menuitem in context menu'''
|
|
|
|
self.used_in_history_window = used_in_history_window
|
|
|
|
|
|
|
|
# no need to inherit TextView, use it as atrribute is safer
|
2006-10-03 16:12:42 +02:00
|
|
|
self.tv = HtmlTextView()
|
|
|
|
self.tv.html_hyperlink_handler = self.html_hyperlink_handler
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2005-10-29 17:07:42 +02:00
|
|
|
# set properties
|
2006-04-18 17:36:16 +02:00
|
|
|
self.tv.set_border_width(1)
|
|
|
|
self.tv.set_accepts_tab(True)
|
|
|
|
self.tv.set_editable(False)
|
|
|
|
self.tv.set_cursor_visible(False)
|
2006-05-27 11:18:30 +02:00
|
|
|
self.tv.set_wrap_mode(gtk.WRAP_WORD_CHAR)
|
2006-04-18 17:36:16 +02:00
|
|
|
self.tv.set_left_margin(2)
|
|
|
|
self.tv.set_right_margin(2)
|
|
|
|
self.handlers = {}
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2005-10-29 17:07:42 +02:00
|
|
|
# connect signals
|
2006-10-07 15:23:20 +02:00
|
|
|
id = self.tv.connect('motion_notify_event',
|
|
|
|
self.on_textview_motion_notify_event)
|
2006-04-18 17:36:16 +02:00
|
|
|
self.handlers[id] = self.tv
|
|
|
|
id = self.tv.connect('populate_popup', self.on_textview_populate_popup)
|
|
|
|
self.handlers[id] = self.tv
|
2006-10-07 15:23:20 +02:00
|
|
|
id = self.tv.connect('button_press_event',
|
|
|
|
self.on_textview_button_press_event)
|
2006-04-18 17:36:16 +02:00
|
|
|
self.handlers[id] = self.tv
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
self.account = account
|
|
|
|
self.change_cursor = None
|
2005-10-29 10:44:41 +02:00
|
|
|
self.last_time_printout = 0
|
2005-10-28 23:46:55 +02:00
|
|
|
|
|
|
|
font = pango.FontDescription(gajim.config.get('conversation_font'))
|
2006-04-18 17:36:16 +02:00
|
|
|
self.tv.modify_font(font)
|
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
end_iter = buffer.get_end_iter()
|
|
|
|
buffer.create_mark('end', end_iter, False)
|
|
|
|
|
|
|
|
self.tagIn = buffer.create_tag('incoming')
|
|
|
|
color = gajim.config.get('inmsgcolor')
|
|
|
|
self.tagIn.set_property('foreground', color)
|
|
|
|
self.tagOut = buffer.create_tag('outgoing')
|
|
|
|
color = gajim.config.get('outmsgcolor')
|
|
|
|
self.tagOut.set_property('foreground', color)
|
|
|
|
self.tagStatus = buffer.create_tag('status')
|
|
|
|
color = gajim.config.get('statusmsgcolor')
|
|
|
|
self.tagStatus.set_property('foreground', color)
|
|
|
|
|
2006-06-22 16:44:06 +02:00
|
|
|
colors = gajim.config.get('gc_nicknames_colors')
|
|
|
|
colors = colors.split(':')
|
|
|
|
for color in xrange(len(colors)):
|
|
|
|
tagname = 'gc_nickname_color_' + str(color)
|
|
|
|
tag = buffer.create_tag(tagname)
|
|
|
|
color = colors[color]
|
|
|
|
tag.set_property('foreground', color)
|
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
tag = buffer.create_tag('marked')
|
|
|
|
color = gajim.config.get('markedmsgcolor')
|
|
|
|
tag.set_property('foreground', color)
|
|
|
|
tag.set_property('weight', pango.WEIGHT_BOLD)
|
|
|
|
|
|
|
|
tag = buffer.create_tag('time_sometimes')
|
2006-10-03 16:12:42 +02:00
|
|
|
tag.set_property('foreground', 'darkgrey')
|
2005-10-28 23:46:55 +02:00
|
|
|
tag.set_property('scale', pango.SCALE_SMALL)
|
|
|
|
tag.set_property('justification', gtk.JUSTIFY_CENTER)
|
|
|
|
|
|
|
|
tag = buffer.create_tag('small')
|
|
|
|
tag.set_property('scale', pango.SCALE_SMALL)
|
|
|
|
|
2005-11-24 01:17:28 +01:00
|
|
|
tag = buffer.create_tag('restored_message')
|
|
|
|
color = gajim.config.get('restored_messages_color')
|
|
|
|
tag.set_property('foreground', color)
|
2005-10-28 23:46:55 +02:00
|
|
|
|
2006-12-03 13:23:44 +01:00
|
|
|
self.tagURL = buffer.create_tag('url')
|
2005-12-26 00:48:08 +01:00
|
|
|
color = gajim.config.get('urlmsgcolor')
|
2006-12-03 13:23:44 +01:00
|
|
|
self.tagURL.set_property('foreground', color)
|
|
|
|
self.tagURL.set_property('underline', pango.UNDERLINE_SINGLE)
|
|
|
|
id = self.tagURL.connect('event', self.hyperlink_handler, 'url')
|
|
|
|
self.handlers[id] = self.tagURL
|
2005-10-28 23:46:55 +02:00
|
|
|
|
2006-12-03 13:23:44 +01:00
|
|
|
self.tagMail = buffer.create_tag('mail')
|
|
|
|
self.tagMail.set_property('foreground', color)
|
|
|
|
self.tagMail.set_property('underline', pango.UNDERLINE_SINGLE)
|
|
|
|
id = self.tagMail.connect('event', self.hyperlink_handler, 'mail')
|
|
|
|
self.handlers[id] = self.tagMail
|
2005-10-28 23:46:55 +02:00
|
|
|
|
|
|
|
tag = buffer.create_tag('bold')
|
|
|
|
tag.set_property('weight', pango.WEIGHT_BOLD)
|
|
|
|
|
|
|
|
tag = buffer.create_tag('italic')
|
|
|
|
tag.set_property('style', pango.STYLE_ITALIC)
|
|
|
|
|
|
|
|
tag = buffer.create_tag('underline')
|
|
|
|
tag.set_property('underline', pango.UNDERLINE_SINGLE)
|
|
|
|
|
2005-10-29 17:07:42 +02:00
|
|
|
buffer.create_tag('focus-out-line', justification = gtk.JUSTIFY_CENTER)
|
2005-10-28 23:46:55 +02:00
|
|
|
|
2007-08-07 15:13:49 +02:00
|
|
|
# One mark at the begining then 2 marks between each lines
|
2007-07-21 16:58:56 +02:00
|
|
|
size = gajim.config.get('max_conversation_lines')
|
|
|
|
size = 2 * size - 1
|
|
|
|
self.marks_queue = Queue.Queue(size)
|
|
|
|
|
2006-07-27 12:54:12 +02:00
|
|
|
self.allow_focus_out_line = True
|
2007-08-07 15:13:49 +02:00
|
|
|
# holds a mark at the end of --- line
|
|
|
|
self.focus_out_end_mark = None
|
2006-07-27 12:54:12 +02:00
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
self.line_tooltip = tooltips.BaseTooltip()
|
2006-10-03 16:12:42 +02:00
|
|
|
# use it for hr too
|
2007-02-09 00:00:27 +01:00
|
|
|
self.tv.focus_out_line_pixbuf = ConversationTextview.FOCUS_OUT_LINE_PIXBUF
|
2005-10-28 23:46:55 +02:00
|
|
|
|
2006-04-18 17:36:16 +02:00
|
|
|
def del_handlers(self):
|
|
|
|
for i in self.handlers.keys():
|
2006-04-19 14:21:06 +02:00
|
|
|
if self.handlers[i].handler_is_connected(i):
|
|
|
|
self.handlers[i].disconnect(i)
|
2006-04-18 17:36:16 +02:00
|
|
|
del self.handlers
|
|
|
|
self.tv.destroy()
|
2006-10-07 15:23:20 +02:00
|
|
|
#FIXME:
|
2006-04-18 17:36:16 +02:00
|
|
|
# self.line_tooltip.destroy()
|
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
def update_tags(self):
|
|
|
|
self.tagIn.set_property('foreground', gajim.config.get('inmsgcolor'))
|
|
|
|
self.tagOut.set_property('foreground', gajim.config.get('outmsgcolor'))
|
|
|
|
self.tagStatus.set_property('foreground',
|
|
|
|
gajim.config.get('statusmsgcolor'))
|
2006-12-03 13:23:44 +01:00
|
|
|
self.tagURL.set_property('foreground', gajim.config.get('urlmsgcolor'))
|
|
|
|
self.tagMail.set_property('foreground', gajim.config.get('urlmsgcolor'))
|
2005-10-28 23:46:55 +02:00
|
|
|
|
|
|
|
def at_the_end(self):
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
end_iter = buffer.get_end_iter()
|
2006-04-18 17:36:16 +02:00
|
|
|
end_rect = self.tv.get_iter_location(end_iter)
|
|
|
|
visible_rect = self.tv.get_visible_rect()
|
2005-10-28 23:46:55 +02:00
|
|
|
if end_rect.y <= (visible_rect.y + visible_rect.height):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def scroll_to_end(self):
|
2006-04-18 17:36:16 +02:00
|
|
|
parent = self.tv.get_parent()
|
|
|
|
buffer = self.tv.get_buffer()
|
2006-05-20 21:06:16 +02:00
|
|
|
end_mark = buffer.get_mark('end')
|
|
|
|
if not end_mark:
|
|
|
|
return False
|
|
|
|
self.tv.scroll_to_mark(end_mark, 0, True, 0, 1)
|
2005-10-28 23:46:55 +02:00
|
|
|
adjustment = parent.get_hadjustment()
|
|
|
|
adjustment.set_value(0)
|
|
|
|
return False # when called in an idle_add, just do it once
|
|
|
|
|
|
|
|
def bring_scroll_to_end(self, diff_y = 0):
|
|
|
|
''' scrolls to the end of textview if end is not visible '''
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
end_iter = buffer.get_end_iter()
|
2006-04-18 17:36:16 +02:00
|
|
|
end_rect = self.tv.get_iter_location(end_iter)
|
|
|
|
visible_rect = self.tv.get_visible_rect()
|
2005-10-28 23:46:55 +02:00
|
|
|
# scroll only if expected end is not visible
|
|
|
|
if end_rect.y >= (visible_rect.y + visible_rect.height + diff_y):
|
|
|
|
gobject.idle_add(self.scroll_to_end_iter)
|
|
|
|
|
|
|
|
def scroll_to_end_iter(self):
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
end_iter = buffer.get_end_iter()
|
2006-06-05 23:02:19 +02:00
|
|
|
if not end_iter:
|
|
|
|
return False
|
2006-04-18 17:36:16 +02:00
|
|
|
self.tv.scroll_to_iter(end_iter, 0, False, 1, 1)
|
2005-10-28 23:46:55 +02:00
|
|
|
return False # when called in an idle_add, just do it once
|
|
|
|
|
2006-07-27 12:54:12 +02:00
|
|
|
def show_focus_out_line(self):
|
|
|
|
if not self.allow_focus_out_line:
|
|
|
|
# if room did not receive focus-in from the last time we added
|
|
|
|
# --- line then do not readd
|
|
|
|
return
|
|
|
|
|
|
|
|
print_focus_out_line = False
|
|
|
|
buffer = self.tv.get_buffer()
|
|
|
|
|
2007-08-07 15:13:49 +02:00
|
|
|
if self.focus_out_end_mark is None:
|
2006-07-27 12:54:12 +02:00
|
|
|
# this happens only first time we focus out on this room
|
|
|
|
print_focus_out_line = True
|
|
|
|
|
|
|
|
else:
|
2007-08-07 15:13:49 +02:00
|
|
|
focus_out_end_iter = buffer.get_iter_at_mark(self.focus_out_end_mark)
|
|
|
|
focus_out_end_iter_offset = focus_out_end_iter.get_offset()
|
|
|
|
if focus_out_end_iter_offset != buffer.get_end_iter().get_offset():
|
2006-07-27 12:54:12 +02:00
|
|
|
# this means after last-focus something was printed
|
|
|
|
# (else end_iter's offset is the same as before)
|
|
|
|
# only then print ---- line (eg. we avoid printing many following
|
|
|
|
# ---- lines)
|
|
|
|
print_focus_out_line = True
|
|
|
|
|
|
|
|
if print_focus_out_line and buffer.get_char_count() > 0:
|
|
|
|
buffer.begin_user_action()
|
|
|
|
|
|
|
|
# remove previous focus out line if such focus out line exists
|
2007-08-07 15:13:49 +02:00
|
|
|
if self.focus_out_end_mark is not None:
|
|
|
|
end_iter_for_previous_line = buffer.get_iter_at_mark(
|
|
|
|
self.focus_out_end_mark)
|
2006-07-27 12:54:12 +02:00
|
|
|
begin_iter_for_previous_line = end_iter_for_previous_line.copy()
|
|
|
|
# img_char+1 (the '\n')
|
|
|
|
begin_iter_for_previous_line.backward_chars(2)
|
|
|
|
|
|
|
|
# remove focus out line
|
|
|
|
buffer.delete(begin_iter_for_previous_line,
|
|
|
|
end_iter_for_previous_line)
|
2007-08-07 15:13:49 +02:00
|
|
|
buffer.delete_mark(self.focus_out_end_mark)
|
2006-07-27 12:54:12 +02:00
|
|
|
|
|
|
|
# add the new focus out line
|
|
|
|
end_iter = buffer.get_end_iter()
|
|
|
|
buffer.insert(end_iter, '\n')
|
2007-02-09 00:00:27 +01:00
|
|
|
buffer.insert_pixbuf(end_iter,
|
|
|
|
ConversationTextview.FOCUS_OUT_LINE_PIXBUF)
|
2006-07-27 12:54:12 +02:00
|
|
|
|
|
|
|
end_iter = buffer.get_end_iter()
|
|
|
|
before_img_iter = end_iter.copy()
|
|
|
|
before_img_iter.backward_char() # one char back (an image also takes one char)
|
|
|
|
buffer.apply_tag_by_name('focus-out-line', before_img_iter, end_iter)
|
|
|
|
|
2007-01-22 22:08:54 +01:00
|
|
|
self.allow_focus_out_line = False
|
|
|
|
|
2006-07-27 12:54:12 +02:00
|
|
|
# update the iter we hold to make comparison the next time
|
2007-08-07 15:13:49 +02:00
|
|
|
self.focus_out_end_mark = buffer.create_mark(None,
|
|
|
|
buffer.get_end_iter(), left_gravity=True)
|
2006-07-27 12:54:12 +02:00
|
|
|
|
|
|
|
buffer.end_user_action()
|
|
|
|
|
|
|
|
# scroll to the end (via idle in case the scrollbar has appeared)
|
|
|
|
gobject.idle_add(self.scroll_to_end)
|
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
def show_line_tooltip(self):
|
2006-04-18 17:36:16 +02:00
|
|
|
pointer = self.tv.get_pointer()
|
|
|
|
x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer[0],
|
2005-10-28 23:46:55 +02:00
|
|
|
pointer[1])
|
2006-04-18 17:36:16 +02:00
|
|
|
tags = self.tv.get_iter_at_location(x, y).get_tags()
|
|
|
|
tag_table = self.tv.get_buffer().get_tag_table()
|
2005-10-28 23:46:55 +02:00
|
|
|
over_line = False
|
|
|
|
for tag in tags:
|
|
|
|
if tag == tag_table.lookup('focus-out-line'):
|
|
|
|
over_line = True
|
|
|
|
break
|
|
|
|
if over_line and not self.line_tooltip.win:
|
|
|
|
# check if the current pointer is still over the line
|
2006-04-18 17:36:16 +02:00
|
|
|
position = self.tv.window.get_origin()
|
2005-11-18 20:16:45 +01:00
|
|
|
self.line_tooltip.show_tooltip(_('Text below this line is what has '
|
2006-03-01 18:36:44 +01:00
|
|
|
'been said since the last time you paid attention to this group chat'), 8, position[1] + pointer[1])
|
2005-10-28 23:46:55 +02:00
|
|
|
|
|
|
|
def on_textview_motion_notify_event(self, widget, event):
|
|
|
|
'''change the cursor to a hand when we are over a mail or an url'''
|
2006-04-18 17:36:16 +02:00
|
|
|
pointer_x, pointer_y, spam = self.tv.window.get_pointer()
|
|
|
|
x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer_x,
|
2005-10-28 23:46:55 +02:00
|
|
|
pointer_y)
|
2006-04-18 17:36:16 +02:00
|
|
|
tags = self.tv.get_iter_at_location(x, y).get_tags()
|
2005-10-28 23:46:55 +02:00
|
|
|
if self.change_cursor:
|
2006-04-18 17:36:16 +02:00
|
|
|
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
2005-10-28 23:46:55 +02:00
|
|
|
gtk.gdk.Cursor(gtk.gdk.XTERM))
|
|
|
|
self.change_cursor = None
|
2006-04-18 17:36:16 +02:00
|
|
|
tag_table = self.tv.get_buffer().get_tag_table()
|
2005-10-28 23:46:55 +02:00
|
|
|
over_line = False
|
|
|
|
for tag in tags:
|
|
|
|
if tag in (tag_table.lookup('url'), tag_table.lookup('mail')):
|
2006-04-18 17:36:16 +02:00
|
|
|
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
2005-10-28 23:46:55 +02:00
|
|
|
gtk.gdk.Cursor(gtk.gdk.HAND2))
|
|
|
|
self.change_cursor = tag
|
|
|
|
elif tag == tag_table.lookup('focus-out-line'):
|
|
|
|
over_line = True
|
|
|
|
|
|
|
|
if self.line_tooltip.timeout != 0:
|
|
|
|
# Check if we should hide the line tooltip
|
|
|
|
if not over_line:
|
|
|
|
self.line_tooltip.hide_tooltip()
|
|
|
|
if over_line and not self.line_tooltip.win:
|
|
|
|
self.line_tooltip.timeout = gobject.timeout_add(500,
|
|
|
|
self.show_line_tooltip)
|
2006-04-18 17:36:16 +02:00
|
|
|
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
|
2005-10-28 23:46:55 +02:00
|
|
|
gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
|
|
|
|
self.change_cursor = tag
|
|
|
|
|
|
|
|
def clear(self, tv = None):
|
|
|
|
'''clear text in the textview'''
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
start, end = buffer.get_bounds()
|
|
|
|
buffer.delete(start, end)
|
2007-07-21 16:58:56 +02:00
|
|
|
size = gajim.config.get('max_conversation_lines')
|
|
|
|
size = 2 * size - 1
|
|
|
|
self.marks_queue = Queue.Queue(size)
|
2007-08-07 15:13:49 +02:00
|
|
|
self.focus_out_end_mark = None
|
2005-10-28 23:46:55 +02:00
|
|
|
|
|
|
|
def visit_url_from_menuitem(self, widget, link):
|
|
|
|
'''basically it filters out the widget instance'''
|
|
|
|
helpers.launch_browser_mailer('url', link)
|
|
|
|
|
|
|
|
def on_textview_populate_popup(self, textview, menu):
|
|
|
|
'''we override the default context menu and we prepend Clear
|
2006-10-07 15:23:20 +02:00
|
|
|
(only if used_in_history_window is False)
|
2005-10-28 23:46:55 +02:00
|
|
|
and if we have sth selected we show a submenu with actions on the phrase
|
|
|
|
(see on_conversation_textview_button_press_event)'''
|
2006-10-07 15:23:20 +02:00
|
|
|
|
|
|
|
separator_menuitem_was_added = False
|
|
|
|
if not self.used_in_history_window:
|
|
|
|
item = gtk.SeparatorMenuItem()
|
|
|
|
menu.prepend(item)
|
|
|
|
separator_menuitem_was_added = True
|
|
|
|
|
|
|
|
item = gtk.ImageMenuItem(gtk.STOCK_CLEAR)
|
|
|
|
menu.prepend(item)
|
|
|
|
id = item.connect('activate', self.clear)
|
|
|
|
self.handlers[id] = item
|
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
if self.selected_phrase:
|
2006-10-07 15:23:20 +02:00
|
|
|
if not separator_menuitem_was_added:
|
|
|
|
item = gtk.SeparatorMenuItem()
|
|
|
|
menu.prepend(item)
|
|
|
|
|
|
|
|
self.selected_phrase = helpers.reduce_chars_newlines(
|
2006-10-15 14:59:23 +02:00
|
|
|
self.selected_phrase, 25, 2)
|
2006-10-07 14:50:34 +02:00
|
|
|
item = gtk.MenuItem(_('_Actions for "%s"') % self.selected_phrase)
|
2005-10-28 23:46:55 +02:00
|
|
|
menu.prepend(item)
|
|
|
|
submenu = gtk.Menu()
|
|
|
|
item.set_submenu(submenu)
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
always_use_en = gajim.config.get('always_english_wikipedia')
|
|
|
|
if always_use_en:
|
|
|
|
link = 'http://en.wikipedia.org/wiki/Special:Search?search=%s'\
|
|
|
|
% self.selected_phrase
|
|
|
|
else:
|
|
|
|
link = 'http://%s.wikipedia.org/wiki/Special:Search?search=%s'\
|
|
|
|
% (gajim.LANG, self.selected_phrase)
|
|
|
|
item = gtk.MenuItem(_('Read _Wikipedia Article'))
|
2006-04-18 17:36:16 +02:00
|
|
|
id = item.connect('activate', self.visit_url_from_menuitem, link)
|
|
|
|
self.handlers[id] = item
|
2005-10-28 23:46:55 +02:00
|
|
|
submenu.append(item)
|
|
|
|
|
|
|
|
item = gtk.MenuItem(_('Look it up in _Dictionary'))
|
|
|
|
dict_link = gajim.config.get('dictionary_url')
|
|
|
|
if dict_link == 'WIKTIONARY':
|
|
|
|
# special link (yeah undocumented but default)
|
|
|
|
always_use_en = gajim.config.get('always_english_wiktionary')
|
|
|
|
if always_use_en:
|
|
|
|
link = 'http://en.wiktionary.org/wiki/Special:Search?search=%s'\
|
|
|
|
% self.selected_phrase
|
|
|
|
else:
|
|
|
|
link = 'http://%s.wiktionary.org/wiki/Special:Search?search=%s'\
|
|
|
|
% (gajim.LANG, self.selected_phrase)
|
2006-04-18 17:36:16 +02:00
|
|
|
id = item.connect('activate', self.visit_url_from_menuitem, link)
|
|
|
|
self.handlers[id] = item
|
2005-10-28 23:46:55 +02:00
|
|
|
else:
|
|
|
|
if dict_link.find('%s') == -1:
|
2006-10-15 18:40:42 +02:00
|
|
|
# we must have %s in the url if not WIKTIONARY
|
2005-10-28 23:46:55 +02:00
|
|
|
item = gtk.MenuItem(_('Dictionary URL is missing an "%s" and it is not WIKTIONARY'))
|
|
|
|
item.set_property('sensitive', False)
|
|
|
|
else:
|
|
|
|
link = dict_link % self.selected_phrase
|
2006-10-07 14:50:34 +02:00
|
|
|
id = item.connect('activate', self.visit_url_from_menuitem,
|
|
|
|
link)
|
2006-04-18 17:36:16 +02:00
|
|
|
self.handlers[id] = item
|
2005-10-28 23:46:55 +02:00
|
|
|
submenu.append(item)
|
2005-12-07 19:00:29 +01:00
|
|
|
|
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
search_link = gajim.config.get('search_engine')
|
|
|
|
if search_link.find('%s') == -1:
|
2006-10-15 18:40:42 +02:00
|
|
|
# we must have %s in the url
|
2005-10-28 23:46:55 +02:00
|
|
|
item = gtk.MenuItem(_('Web Search URL is missing an "%s"'))
|
|
|
|
item.set_property('sensitive', False)
|
|
|
|
else:
|
|
|
|
item = gtk.MenuItem(_('Web _Search for it'))
|
|
|
|
link = search_link % self.selected_phrase
|
2006-04-18 17:36:16 +02:00
|
|
|
id = item.connect('activate', self.visit_url_from_menuitem, link)
|
|
|
|
self.handlers[id] = item
|
2005-10-28 23:46:55 +02:00
|
|
|
submenu.append(item)
|
2006-10-07 14:50:34 +02:00
|
|
|
|
2006-10-07 17:05:22 +02:00
|
|
|
item = gtk.MenuItem(_('Open as _Link'))
|
2006-10-07 14:50:34 +02:00
|
|
|
id = item.connect('activate', self.visit_url_from_menuitem, link)
|
|
|
|
self.handlers[id] = item
|
|
|
|
submenu.append(item)
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
menu.show_all()
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
def on_textview_button_press_event(self, widget, event):
|
|
|
|
# If we clicked on a taged text do NOT open the standard popup menu
|
|
|
|
# if normal text check if we have sth selected
|
2006-10-15 18:40:42 +02:00
|
|
|
self.selected_phrase = '' # do not move belove event button check!
|
2005-10-28 23:46:55 +02:00
|
|
|
|
|
|
|
if event.button != 3: # if not right click
|
|
|
|
return False
|
|
|
|
|
2006-04-18 17:36:16 +02:00
|
|
|
x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT,
|
2005-10-28 23:46:55 +02:00
|
|
|
int(event.x), int(event.y))
|
2006-04-18 17:36:16 +02:00
|
|
|
iter = self.tv.get_iter_at_location(x, y)
|
2005-10-28 23:46:55 +02:00
|
|
|
tags = iter.get_tags()
|
|
|
|
|
|
|
|
|
|
|
|
if tags: # we clicked on sth special (it can be status message too)
|
|
|
|
for tag in tags:
|
|
|
|
tag_name = tag.get_property('name')
|
2007-01-06 11:20:13 +01:00
|
|
|
if tag_name in ('url', 'mail'):
|
2005-10-28 23:46:55 +02:00
|
|
|
return True # we block normal context menu
|
|
|
|
|
|
|
|
# we check if sth was selected and if it was we assign
|
|
|
|
# selected_phrase variable
|
|
|
|
# so on_conversation_textview_populate_popup can use it
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
return_val = buffer.get_selection_bounds()
|
|
|
|
if return_val: # if sth was selected when we right-clicked
|
|
|
|
# get the selected text
|
|
|
|
start_sel, finish_sel = return_val[0], return_val[1]
|
|
|
|
self.selected_phrase = buffer.get_text(start_sel, finish_sel).decode('utf-8')
|
|
|
|
|
|
|
|
def on_open_link_activate(self, widget, kind, text):
|
|
|
|
helpers.launch_browser_mailer(kind, text)
|
|
|
|
|
|
|
|
def on_copy_link_activate(self, widget, text):
|
|
|
|
clip = gtk.clipboard_get()
|
|
|
|
clip.set_text(text)
|
|
|
|
|
|
|
|
def on_start_chat_activate(self, widget, jid):
|
|
|
|
gajim.interface.roster.new_chat_from_jid(self.account, jid)
|
|
|
|
|
2006-10-07 14:18:51 +02:00
|
|
|
def on_join_group_chat_menuitem_activate(self, widget, room_jid):
|
2006-10-08 14:07:33 +02:00
|
|
|
if 'join_gc' in gajim.interface.instances[self.account]:
|
2005-11-13 16:08:47 +01:00
|
|
|
instance = gajim.interface.instances[self.account]['join_gc']
|
2006-10-07 14:18:51 +02:00
|
|
|
instance.xml.get_widget('room_jid_entry').set_text(room_jid)
|
2005-12-07 19:00:29 +01:00
|
|
|
gajim.interface.instances[self.account]['join_gc'].window.present()
|
2005-10-28 23:46:55 +02:00
|
|
|
else:
|
|
|
|
try:
|
2005-11-13 16:08:47 +01:00
|
|
|
gajim.interface.instances[self.account]['join_gc'] = \
|
2006-10-07 14:18:51 +02:00
|
|
|
dialogs.JoinGroupchatWindow(self.account, room_jid)
|
2006-10-08 14:07:33 +02:00
|
|
|
except GajimGeneralException:
|
2005-10-28 23:46:55 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
def on_add_to_roster_activate(self, widget, jid):
|
|
|
|
dialogs.AddNewContactWindow(self.account, jid)
|
|
|
|
|
|
|
|
def make_link_menu(self, event, kind, text):
|
2006-05-02 17:53:25 +02:00
|
|
|
xml = gtkgui_helpers.get_glade('chat_context_menu.glade')
|
2005-10-28 23:46:55 +02:00
|
|
|
menu = xml.get_widget('chat_context_menu')
|
|
|
|
childs = menu.get_children()
|
|
|
|
if kind == 'url':
|
2006-04-18 17:36:16 +02:00
|
|
|
id = childs[0].connect('activate', self.on_copy_link_activate, text)
|
|
|
|
self.handlers[id] = childs[0]
|
|
|
|
id = childs[1].connect('activate', self.on_open_link_activate, kind, text)
|
|
|
|
self.handlers[id] = childs[1]
|
2005-10-28 23:46:55 +02:00
|
|
|
childs[2].hide() # copy mail address
|
|
|
|
childs[3].hide() # open mail composer
|
2006-03-21 15:26:01 +01:00
|
|
|
childs[4].hide() # jid section separator
|
2005-10-28 23:46:55 +02:00
|
|
|
childs[5].hide() # start chat
|
|
|
|
childs[6].hide() # join group chat
|
|
|
|
childs[7].hide() # add to roster
|
|
|
|
else: # It's a mail or a JID
|
2006-11-27 14:14:29 +01:00
|
|
|
# load muc icon
|
|
|
|
join_group_chat_menuitem = xml.get_widget('join_group_chat_menuitem')
|
|
|
|
muc_icon = gajim.interface.roster.load_icon('muc_active')
|
|
|
|
if muc_icon:
|
|
|
|
join_group_chat_menuitem.set_image(muc_icon)
|
|
|
|
|
2006-10-08 23:43:07 +02:00
|
|
|
text = text.lower()
|
2006-04-18 17:36:16 +02:00
|
|
|
id = childs[2].connect('activate', self.on_copy_link_activate, text)
|
|
|
|
self.handlers[id] = childs[2]
|
|
|
|
id = childs[3].connect('activate', self.on_open_link_activate, kind, text)
|
|
|
|
self.handlers[id] = childs[3]
|
|
|
|
id = childs[5].connect('activate', self.on_start_chat_activate, text)
|
|
|
|
self.handlers[id] = childs[5]
|
|
|
|
id = childs[6].connect('activate',
|
2005-10-28 23:46:55 +02:00
|
|
|
self.on_join_group_chat_menuitem_activate, text)
|
2006-04-18 17:36:16 +02:00
|
|
|
self.handlers[id] = childs[6]
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
allow_add = False
|
Merged in trunk updates, including meta_contacts
Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk
........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line
fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines
merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.
........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines
correct contacts file
........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines
dict.remove() doesn't exists, it's del dict[]
........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines
some missing commits from branch
........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines
end of gc_contact.nick -> gc_contact.name
........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines
new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences
........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines
0.9.1-2 in debian that solve the group bug (commit [4924])
........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines
typo
........
2006-01-01 21:06:26 +01:00
|
|
|
c = gajim.contacts.get_first_contact_from_jid(self.account, text)
|
|
|
|
if c and not gajim.contacts.is_pm_from_contact(self.account, c):
|
2006-01-19 22:55:01 +01:00
|
|
|
if _('Not in Roster') in c.groups:
|
2005-10-28 23:46:55 +02:00
|
|
|
allow_add = True
|
2005-11-12 15:17:27 +01:00
|
|
|
else: # he or she's not at all in the account contacts
|
2005-10-28 23:46:55 +02:00
|
|
|
allow_add = True
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
if allow_add:
|
2006-04-18 17:36:16 +02:00
|
|
|
id = childs[7].connect('activate', self.on_add_to_roster_activate, text)
|
|
|
|
self.handlers[id] = childs[7]
|
2005-10-28 23:46:55 +02:00
|
|
|
childs[7].show() # show add to roster menuitem
|
|
|
|
else:
|
|
|
|
childs[7].hide() # hide add to roster menuitem
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
childs[0].hide() # copy link location
|
|
|
|
childs[1].hide() # open link in browser
|
|
|
|
|
|
|
|
menu.popup(None, None, None, event.button, event.time)
|
|
|
|
|
|
|
|
def hyperlink_handler(self, texttag, widget, event, iter, kind):
|
|
|
|
if event.type == gtk.gdk.BUTTON_PRESS:
|
|
|
|
begin_iter = iter.copy()
|
|
|
|
# we get the begining of the tag
|
|
|
|
while not begin_iter.begins_tag(texttag):
|
|
|
|
begin_iter.backward_char()
|
|
|
|
end_iter = iter.copy()
|
|
|
|
# we get the end of the tag
|
|
|
|
while not end_iter.ends_tag(texttag):
|
|
|
|
end_iter.forward_char()
|
2006-04-18 17:36:16 +02:00
|
|
|
word = self.tv.get_buffer().get_text(begin_iter, end_iter).decode('utf-8')
|
2005-10-28 23:46:55 +02:00
|
|
|
if event.button == 3: # right click
|
|
|
|
self.make_link_menu(event, kind, word)
|
|
|
|
else:
|
|
|
|
# we launch the correct application
|
|
|
|
helpers.launch_browser_mailer(kind, word)
|
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
def html_hyperlink_handler(self, texttag, widget, event, iter, kind, href):
|
|
|
|
if event.type == gtk.gdk.BUTTON_PRESS:
|
|
|
|
if event.button == 3: # right click
|
|
|
|
self.make_link_menu(event, kind, href)
|
|
|
|
else:
|
|
|
|
# we launch the correct application
|
|
|
|
helpers.launch_browser_mailer(kind, href)
|
|
|
|
|
|
|
|
|
2005-12-12 10:12:06 +01:00
|
|
|
def detect_and_print_special_text(self, otext, other_tags):
|
2005-11-01 14:33:13 +01:00
|
|
|
'''detects special text (emots & links & formatting)
|
|
|
|
prints normal text before any special text it founts,
|
|
|
|
then print special text (that happens many times until
|
|
|
|
last special text is printed) and then returns the index
|
|
|
|
after *last* special text, so we can print it in
|
|
|
|
print_conversation_line()'''
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
|
|
|
|
start = 0
|
|
|
|
end = 0
|
|
|
|
index = 0
|
|
|
|
|
|
|
|
# basic: links + mail + formatting is always checked (we like that)
|
2006-03-17 12:11:45 +01:00
|
|
|
if gajim.config.get('emoticons_theme'): # search for emoticons & urls
|
2005-10-28 23:46:55 +02:00
|
|
|
iterator = gajim.interface.emot_and_basic_re.finditer(otext)
|
|
|
|
else: # search for just urls + mail + formatting
|
|
|
|
iterator = gajim.interface.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 = buffer.get_end_iter()
|
2005-11-01 14:33:13 +01:00
|
|
|
# we insert normal text
|
2005-10-28 23:46:55 +02:00
|
|
|
buffer.insert_with_tags_by_name(end_iter,
|
|
|
|
text_before_special_text, *other_tags)
|
|
|
|
index = end # update index
|
|
|
|
|
|
|
|
# now print it
|
|
|
|
self.print_special_text(special_text, other_tags)
|
|
|
|
|
2005-11-01 14:33:13 +01:00
|
|
|
return index # the position after *last* special text
|
2005-10-28 23:46:55 +02:00
|
|
|
|
2007-04-25 23:51:08 +02:00
|
|
|
def latex_to_image(self, str):
|
|
|
|
result = None
|
2007-04-26 19:06:05 +02:00
|
|
|
exitcode = 0
|
|
|
|
|
|
|
|
# some latex commands are really bad
|
|
|
|
blacklist = ["\\def", "\\let", "\\futurelet",
|
|
|
|
"\\newcommand", "\\renewcomment", "\\else", "\\fi", "\\write",
|
|
|
|
"\\input", "\\include", "\\chardef", "\\catcode", "\\makeatletter",
|
|
|
|
"\\noexpand", "\\toksdef", "\\every", "\\errhelp", "\\errorstopmode",
|
|
|
|
"\\scrollmode", "\\nonstopmode", "\\batchmode", "\\read", "\\csname",
|
|
|
|
"\\newhelp", "\\relax", "\\afterground", "\\afterassignment",
|
|
|
|
"\\expandafter", "\\noexpand", "\\special", "\\command", "\\loop",
|
|
|
|
"\\repeat", "\\toks", "\\output", "\\line", "\\mathcode", "\\name",
|
|
|
|
"\\item", "\\section", "\\mbox", "\\DeclareRobustCommand", "\\[",
|
|
|
|
"\\]"]
|
2007-04-25 23:51:08 +02:00
|
|
|
|
2007-04-26 19:06:05 +02:00
|
|
|
str = str[2:len(str)-2]
|
2007-04-25 23:51:08 +02:00
|
|
|
|
2007-04-26 19:06:05 +02:00
|
|
|
# filter latex code with bad commands
|
|
|
|
for word in blacklist:
|
|
|
|
if word in str:
|
|
|
|
exitcode = 1
|
|
|
|
break
|
2007-04-25 23:51:08 +02:00
|
|
|
|
2007-04-26 19:06:05 +02:00
|
|
|
if exitcode == 0:
|
|
|
|
random.seed()
|
|
|
|
tmpfile = os.path.join(gettempdir(), "gajimtex_" + random.randint(0,
|
|
|
|
100).__str__())
|
|
|
|
|
|
|
|
# build latex string
|
|
|
|
texstr = "\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}\\usepackage{amsmath}\\usepackage{amssymb}\\pagestyle{empty}"
|
|
|
|
texstr += "\\begin{document}\\begin{large}\\begin{gather*}"
|
|
|
|
texstr += str
|
|
|
|
texstr += "\\end{gather*}\\end{large}\\end{document}"
|
|
|
|
|
|
|
|
file = open(os.path.join(tmpfile + ".tex"), "w+")
|
|
|
|
file.write(texstr)
|
|
|
|
file.flush()
|
|
|
|
file.close()
|
|
|
|
|
|
|
|
p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'],
|
|
|
|
cwd=gettempdir())
|
|
|
|
exitcode = p.wait()
|
2007-04-25 23:51:08 +02:00
|
|
|
|
|
|
|
if exitcode == 0:
|
2007-04-26 19:06:05 +02:00
|
|
|
p = Popen(['dvips', '-E', '-o', tmpfile + '.ps', tmpfile + '.dvi'],
|
|
|
|
cwd=gettempdir())
|
2007-04-25 23:51:08 +02:00
|
|
|
exitcode = p.wait()
|
|
|
|
|
|
|
|
if exitcode == 0:
|
2007-04-26 19:06:05 +02:00
|
|
|
p = Popen(['convert', tmpfile + '.ps', tmpfile + '.png'],
|
|
|
|
cwd=gettempdir())
|
|
|
|
exitcode = p.wait()
|
|
|
|
|
2007-04-25 23:51:08 +02:00
|
|
|
extensions = [".tex", ".log", ".aux", ".dvi", ".ps"]
|
|
|
|
for ext in extensions:
|
|
|
|
try:
|
|
|
|
os.remove(tmpfile + ext)
|
|
|
|
except Exception:
|
|
|
|
pass
|
2007-04-26 19:06:05 +02:00
|
|
|
|
2007-04-25 23:51:08 +02:00
|
|
|
if exitcode == 0:
|
|
|
|
result = tmpfile + '.png'
|
|
|
|
|
2007-04-26 19:06:05 +02:00
|
|
|
return result
|
2007-04-25 23:51:08 +02:00
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
def print_special_text(self, special_text, other_tags):
|
2005-11-01 14:43:57 +01:00
|
|
|
'''is called by detect_and_print_special_text and prints
|
|
|
|
special text (emots, links, formatting)'''
|
2005-10-28 23:46:55 +02:00
|
|
|
tags = []
|
|
|
|
use_other_tags = True
|
|
|
|
show_ascii_formatting_chars = \
|
|
|
|
gajim.config.get('show_ascii_formatting_chars')
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
|
|
|
|
possible_emot_ascii_caps = special_text.upper() # emoticons keys are CAPS
|
2006-03-17 12:11:45 +01:00
|
|
|
if gajim.config.get('emoticons_theme') and \
|
2005-11-16 00:35:08 +01:00
|
|
|
possible_emot_ascii_caps in gajim.interface.emoticons.keys():
|
2007-02-07 09:59:40 +01:00
|
|
|
# it's an emoticon
|
2005-10-28 23:46:55 +02:00
|
|
|
emot_ascii = possible_emot_ascii_caps
|
|
|
|
end_iter = buffer.get_end_iter()
|
|
|
|
anchor = buffer.create_child_anchor(end_iter)
|
|
|
|
img = gtk.Image()
|
2007-02-07 09:59:40 +01:00
|
|
|
animations = gajim.interface.emoticons_animations
|
|
|
|
if not emot_ascii in animations:
|
|
|
|
animations[emot_ascii] = gtk.gdk.PixbufAnimation(
|
|
|
|
gajim.interface.emoticons[emot_ascii])
|
|
|
|
img.set_from_animation(animations[emot_ascii])
|
2005-10-28 23:46:55 +02:00
|
|
|
img.show()
|
2007-02-07 09:59:40 +01:00
|
|
|
# add with possible animation
|
2006-04-18 17:36:16 +02:00
|
|
|
self.tv.add_child_at_anchor(img, anchor)
|
2006-09-25 14:04:30 +02:00
|
|
|
#FIXME: one day, somehow sync with regexp in gajim.py
|
2006-01-20 14:18:48 +01:00
|
|
|
elif special_text.startswith('http://') or \
|
|
|
|
special_text.startswith('www.') or \
|
2006-01-15 14:55:19 +01:00
|
|
|
special_text.startswith('ftp://') or \
|
|
|
|
special_text.startswith('ftp.') or \
|
2006-01-20 14:18:48 +01:00
|
|
|
special_text.startswith('https://') or \
|
|
|
|
special_text.startswith('gopher://') or \
|
|
|
|
special_text.startswith('news://') or \
|
|
|
|
special_text.startswith('ed2k://') or \
|
|
|
|
special_text.startswith('irc://') or \
|
|
|
|
special_text.startswith('sip:') or \
|
|
|
|
special_text.startswith('magnet:'):
|
2007-02-07 09:59:40 +01:00
|
|
|
# it's a url
|
2006-01-15 14:55:19 +01:00
|
|
|
tags.append('url')
|
|
|
|
use_other_tags = False
|
2006-11-27 14:14:29 +01:00
|
|
|
elif special_text.startswith('mailto:') or \
|
|
|
|
gajim.interface.sth_at_sth_dot_sth_re.match(special_text):
|
|
|
|
# it's a mail
|
2005-10-28 23:46:55 +02:00
|
|
|
tags.append('mail')
|
|
|
|
use_other_tags = False
|
|
|
|
elif special_text.startswith('*'): # it's a bold text
|
|
|
|
tags.append('bold')
|
2005-12-08 19:28:35 +01:00
|
|
|
if special_text[1] == '/' and special_text[-2] == '/' and len(special_text) > 4: # it's also italic
|
2005-10-28 23:46:55 +02:00
|
|
|
tags.append('italic')
|
|
|
|
if not show_ascii_formatting_chars:
|
|
|
|
special_text = special_text[2:-2] # remove */ /*
|
2005-12-08 19:28:35 +01:00
|
|
|
elif special_text[1] == '_' and special_text[-2] == '_' and len(special_text) > 4: # it's also underlined
|
2005-10-28 23:46:55 +02:00
|
|
|
tags.append('underline')
|
|
|
|
if not show_ascii_formatting_chars:
|
|
|
|
special_text = special_text[2:-2] # remove *_ _*
|
|
|
|
else:
|
|
|
|
if not show_ascii_formatting_chars:
|
|
|
|
special_text = special_text[1:-1] # remove * *
|
|
|
|
elif special_text.startswith('/'): # it's an italic text
|
|
|
|
tags.append('italic')
|
2005-12-08 19:28:35 +01:00
|
|
|
if special_text[1] == '*' and special_text[-2] == '*' and len(special_text) > 4: # it's also bold
|
2005-10-28 23:46:55 +02:00
|
|
|
tags.append('bold')
|
|
|
|
if not show_ascii_formatting_chars:
|
|
|
|
special_text = special_text[2:-2] # remove /* */
|
2005-12-08 19:28:35 +01:00
|
|
|
elif special_text[1] == '_' and special_text[-2] == '_' and len(special_text) > 4: # it's also underlined
|
2005-10-28 23:46:55 +02:00
|
|
|
tags.append('underline')
|
|
|
|
if not show_ascii_formatting_chars:
|
|
|
|
special_text = special_text[2:-2] # remove /_ _/
|
|
|
|
else:
|
|
|
|
if not show_ascii_formatting_chars:
|
|
|
|
special_text = special_text[1:-1] # remove / /
|
|
|
|
elif special_text.startswith('_'): # it's an underlined text
|
|
|
|
tags.append('underline')
|
2005-12-08 19:28:35 +01:00
|
|
|
if special_text[1] == '*' and special_text[-2] == '*' and len(special_text) > 4: # it's also bold
|
2005-10-28 23:46:55 +02:00
|
|
|
tags.append('bold')
|
|
|
|
if not show_ascii_formatting_chars:
|
|
|
|
special_text = special_text[2:-2] # remove _* *_
|
2005-12-08 19:28:35 +01:00
|
|
|
elif special_text[1] == '/' and special_text[-2] == '/' and len(special_text) > 4: # it's also italic
|
2005-10-28 23:46:55 +02:00
|
|
|
tags.append('italic')
|
|
|
|
if not show_ascii_formatting_chars:
|
|
|
|
special_text = special_text[2:-2] # remove _/ /_
|
|
|
|
else:
|
|
|
|
if not show_ascii_formatting_chars:
|
|
|
|
special_text = special_text[1:-1] # remove _ _
|
2007-04-25 23:51:08 +02:00
|
|
|
elif special_text.startswith('$$') and special_text.endswith('$$'):
|
|
|
|
imagepath = self.latex_to_image(special_text)
|
|
|
|
end_iter = buffer.get_end_iter()
|
|
|
|
anchor = buffer.create_child_anchor(end_iter)
|
|
|
|
if imagepath != None:
|
|
|
|
img = gtk.Image()
|
|
|
|
img.set_from_file(imagepath)
|
|
|
|
img.show()
|
|
|
|
# add
|
|
|
|
self.tv.add_child_at_anchor(img, anchor)
|
|
|
|
# delete old file
|
|
|
|
try:
|
|
|
|
os.remove(imagepath)
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
buffer.insert(end_iter, special_text)
|
|
|
|
use_other_tags = False
|
2005-10-28 23:46:55 +02:00
|
|
|
else:
|
|
|
|
#it's a url
|
|
|
|
tags.append('url')
|
|
|
|
use_other_tags = False
|
|
|
|
|
|
|
|
if len(tags) > 0:
|
|
|
|
end_iter = buffer.get_end_iter()
|
|
|
|
all_tags = tags[:]
|
|
|
|
if use_other_tags:
|
|
|
|
all_tags += other_tags
|
|
|
|
buffer.insert_with_tags_by_name(end_iter, special_text, *all_tags)
|
|
|
|
|
|
|
|
def print_empty_line(self):
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
end_iter = buffer.get_end_iter()
|
2006-10-03 16:12:42 +02:00
|
|
|
buffer.insert_with_tags_by_name(end_iter, '\n', 'eol')
|
2005-10-28 23:46:55 +02:00
|
|
|
|
|
|
|
def print_conversation_line(self, text, jid, kind, name, tim,
|
2006-10-03 16:12:42 +02:00
|
|
|
other_tags_for_name = [], other_tags_for_time = [], other_tags_for_text = [],
|
|
|
|
subject = None, old_kind = None, xhtml = None):
|
2005-10-28 23:46:55 +02:00
|
|
|
'''prints 'chat' type messages'''
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
buffer.begin_user_action()
|
2007-07-21 16:58:56 +02:00
|
|
|
if self.marks_queue.full():
|
|
|
|
# remove oldest line
|
|
|
|
m1 = self.marks_queue.get()
|
|
|
|
m2 = self.marks_queue.get()
|
|
|
|
i1 = buffer.get_iter_at_mark(m1)
|
|
|
|
i2 = buffer.get_iter_at_mark(m2)
|
|
|
|
buffer.delete(i1, i2)
|
|
|
|
buffer.delete_mark(m1)
|
2005-10-28 23:46:55 +02:00
|
|
|
end_iter = buffer.get_end_iter()
|
|
|
|
at_the_end = False
|
|
|
|
if self.at_the_end():
|
|
|
|
at_the_end = True
|
2005-12-07 19:00:29 +01:00
|
|
|
|
2007-07-21 16:58:56 +02:00
|
|
|
# Create one mark and add it to queue once if it's the first line
|
|
|
|
# else twice (one for end bound, one for start bound)
|
|
|
|
mark = None
|
2005-10-28 23:46:55 +02:00
|
|
|
if buffer.get_char_count() > 0:
|
2006-10-03 16:12:42 +02:00
|
|
|
buffer.insert_with_tags_by_name(end_iter, '\n', 'eol')
|
2007-07-21 16:58:56 +02:00
|
|
|
mark = buffer.create_mark(None, end_iter, left_gravity=True)
|
|
|
|
self.marks_queue.put(mark)
|
|
|
|
if not mark:
|
|
|
|
mark = buffer.create_mark(None, end_iter, left_gravity=True)
|
|
|
|
self.marks_queue.put(mark)
|
2005-10-28 23:46:55 +02:00
|
|
|
if kind == 'incoming_queue':
|
|
|
|
kind = 'incoming'
|
2006-05-08 10:19:20 +02:00
|
|
|
if old_kind == 'incoming_queue':
|
|
|
|
old_kind = 'incoming'
|
2005-10-28 23:46:55 +02:00
|
|
|
# print the time stamp
|
2005-11-15 15:23:16 +01:00
|
|
|
if not tim:
|
2005-12-07 19:00:29 +01:00
|
|
|
# We don't have tim for outgoing messages...
|
2005-11-15 15:23:16 +01:00
|
|
|
tim = time.localtime()
|
2006-05-08 10:19:20 +02:00
|
|
|
current_print_time = gajim.config.get('print_time')
|
2006-07-01 20:35:57 +02:00
|
|
|
if current_print_time == 'always' and kind != 'info':
|
2007-01-15 19:37:19 +01:00
|
|
|
timestamp_str = self.get_time_to_show(tim)
|
2007-01-12 20:27:00 +01:00
|
|
|
timestamp = time.strftime(timestamp_str, tim)
|
|
|
|
buffer.insert_with_tags_by_name(end_iter, timestamp,
|
2005-10-28 23:46:55 +02:00
|
|
|
*other_tags_for_time)
|
2006-07-01 20:35:57 +02:00
|
|
|
elif current_print_time == 'sometimes' and kind != 'info':
|
2005-10-28 23:46:55 +02:00
|
|
|
every_foo_seconds = 60 * gajim.config.get(
|
|
|
|
'print_ichat_every_foo_minutes')
|
2005-11-15 15:23:16 +01:00
|
|
|
seconds_passed = time.mktime(tim) - self.last_time_printout
|
2005-10-28 23:46:55 +02:00
|
|
|
if seconds_passed > every_foo_seconds:
|
2005-11-15 15:23:16 +01:00
|
|
|
self.last_time_printout = time.mktime(tim)
|
2005-10-28 23:46:55 +02:00
|
|
|
end_iter = buffer.get_end_iter()
|
2006-06-15 09:14:39 +02:00
|
|
|
if gajim.config.get('print_time_fuzzy') > 0:
|
|
|
|
fc = FuzzyClock()
|
2006-08-21 12:20:33 +02:00
|
|
|
fc.setTime(time.strftime('%H:%M', tim))
|
2006-06-15 09:14:39 +02:00
|
|
|
ft = fc.getFuzzyTime(gajim.config.get('print_time_fuzzy'))
|
|
|
|
tim_format = ft.decode(locale.getpreferredencoding())
|
|
|
|
else:
|
2006-11-21 19:46:33 +01:00
|
|
|
tim_format = self.get_time_to_show(tim)
|
2005-10-28 23:46:55 +02:00
|
|
|
buffer.insert_with_tags_by_name(end_iter, tim_format + '\n',
|
|
|
|
'time_sometimes')
|
2006-07-01 20:35:57 +02:00
|
|
|
# kind = info, we print things as if it was a status: same color, ...
|
|
|
|
if kind == 'info':
|
|
|
|
kind = 'status'
|
2005-12-12 10:12:06 +01:00
|
|
|
other_text_tag = self.detect_other_text_tag(text, kind)
|
2005-10-28 23:46:55 +02:00
|
|
|
text_tags = other_tags_for_text[:] # create a new list
|
2005-12-12 10:12:06 +01:00
|
|
|
if other_text_tag:
|
2006-09-02 11:56:52 +02:00
|
|
|
# note that color of /me may be overwritten in gc_control
|
2005-12-12 10:12:06 +01:00
|
|
|
text_tags.append(other_text_tag)
|
|
|
|
else: # not status nor /me
|
2006-05-08 10:19:20 +02:00
|
|
|
if gajim.config.get(
|
|
|
|
'chat_merge_consecutive_nickname'):
|
|
|
|
if kind != old_kind:
|
|
|
|
self.print_name(name, kind, other_tags_for_name)
|
|
|
|
else:
|
|
|
|
self.print_real_text(gajim.config.get(
|
|
|
|
'chat_merge_consecutive_nickname_indent'))
|
|
|
|
else:
|
|
|
|
self.print_name(name, kind, other_tags_for_name)
|
2005-12-12 10:12:06 +01:00
|
|
|
self.print_subject(subject)
|
2006-10-03 16:12:42 +02:00
|
|
|
self.print_real_text(text, text_tags, name, xhtml)
|
2005-12-12 10:12:06 +01:00
|
|
|
|
|
|
|
# scroll to the end of the textview
|
|
|
|
if at_the_end or kind == 'outgoing':
|
|
|
|
# we are at the end or we are sending something
|
|
|
|
# scroll to the end (via idle in case the scrollbar has appeared)
|
|
|
|
gobject.idle_add(self.scroll_to_end)
|
|
|
|
|
|
|
|
buffer.end_user_action()
|
|
|
|
|
2006-11-21 19:46:33 +01:00
|
|
|
def get_time_to_show(self, tim):
|
|
|
|
'''Get the time, with the day before if needed and return it.
|
|
|
|
It DOESN'T format a fuzzy time'''
|
|
|
|
format = ''
|
|
|
|
# get difference in days since epoch (86400 = 24*3600)
|
|
|
|
# number of days since epoch for current time (in GMT) -
|
|
|
|
# number of days since epoch for message (in GMT)
|
|
|
|
diff_day = int(timegm(time.localtime())) / 86400 -\
|
2007-02-04 14:01:04 +01:00
|
|
|
int(timegm(tim)) / 86400
|
2006-11-21 19:46:33 +01:00
|
|
|
if diff_day == 0:
|
|
|
|
day_str = ''
|
|
|
|
elif diff_day == 1:
|
|
|
|
day_str = _('Yesterday')
|
|
|
|
else:
|
|
|
|
#the number is >= 2
|
|
|
|
# %i is day in year (1-365), %d (1-31) we want %i
|
|
|
|
day_str = _('%i days ago') % diff_day
|
|
|
|
if day_str:
|
|
|
|
format += day_str + ' '
|
2007-01-15 19:37:19 +01:00
|
|
|
timestamp_str = gajim.config.get('time_stamp')
|
|
|
|
timestamp_str = helpers.from_one_line(timestamp_str)
|
|
|
|
format += timestamp_str
|
2006-11-21 19:46:33 +01:00
|
|
|
tim_format = time.strftime(format, tim)
|
2006-11-25 15:34:53 +01:00
|
|
|
if locale.getpreferredencoding() != 'KOI8-R':
|
2006-11-21 19:46:33 +01:00
|
|
|
# if tim_format comes as unicode because of day_str.
|
|
|
|
# we convert it to the encoding that we want (and that is utf-8)
|
|
|
|
tim_format = helpers.ensure_utf8_string(tim_format)
|
|
|
|
return tim_format
|
|
|
|
|
2005-12-12 10:12:06 +01:00
|
|
|
def detect_other_text_tag(self, text, kind):
|
2005-10-28 23:46:55 +02:00
|
|
|
if kind == 'status':
|
2005-12-12 10:12:06 +01:00
|
|
|
return kind
|
2005-10-28 23:46:55 +02:00
|
|
|
elif text.startswith('/me ') or text.startswith('/me\n'):
|
2005-12-12 10:12:06 +01:00
|
|
|
return kind
|
2005-10-28 23:46:55 +02:00
|
|
|
|
2005-12-12 10:12:06 +01:00
|
|
|
def print_name(self, name, kind, other_tags_for_name):
|
|
|
|
if name:
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-12-12 10:12:06 +01:00
|
|
|
end_iter = buffer.get_end_iter()
|
2005-10-28 23:46:55 +02:00
|
|
|
name_tags = other_tags_for_name[:] # create a new list
|
|
|
|
name_tags.append(kind)
|
|
|
|
before_str = gajim.config.get('before_nickname')
|
2006-09-20 22:00:20 +02:00
|
|
|
before_str = helpers.from_one_line(before_str)
|
2005-10-28 23:46:55 +02:00
|
|
|
after_str = gajim.config.get('after_nickname')
|
2006-09-20 22:00:20 +02:00
|
|
|
after_str = helpers.from_one_line(after_str)
|
2005-12-07 19:00:29 +01:00
|
|
|
format = before_str + name + after_str + ' '
|
2005-10-28 23:46:55 +02:00
|
|
|
buffer.insert_with_tags_by_name(end_iter, format, *name_tags)
|
|
|
|
|
2005-12-12 10:12:06 +01:00
|
|
|
def print_subject(self, subject):
|
2005-10-28 23:46:55 +02:00
|
|
|
if subject: # if we have subject, show it too!
|
|
|
|
subject = _('Subject: %s\n') % subject
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-10-28 23:46:55 +02:00
|
|
|
end_iter = buffer.get_end_iter()
|
|
|
|
buffer.insert(end_iter, subject)
|
2005-12-07 17:35:51 +01:00
|
|
|
self.print_empty_line()
|
2005-12-07 17:28:04 +01:00
|
|
|
|
2006-10-03 16:12:42 +02:00
|
|
|
def print_real_text(self, text, text_tags = [], name = None, xhtml = None):
|
2005-12-12 14:00:46 +01:00
|
|
|
'''this adds normal and special text. call this to add text'''
|
2006-10-03 16:12:42 +02:00
|
|
|
if xhtml:
|
|
|
|
try:
|
|
|
|
if name and (text.startswith('/me ') or text.startswith('/me\n')):
|
|
|
|
xhtml = xhtml.replace('/me', '<dfn>%s</dfn>'% (name,), 1)
|
|
|
|
self.tv.display_html(xhtml.encode('utf-8'))
|
|
|
|
return
|
|
|
|
except Exception, e:
|
|
|
|
gajim.log.debug(str("Error processing xhtml")+str(e))
|
|
|
|
gajim.log.debug(str("with |"+xhtml+"|"))
|
|
|
|
|
2006-04-18 17:36:16 +02:00
|
|
|
buffer = self.tv.get_buffer()
|
2005-12-12 14:00:46 +01:00
|
|
|
# /me is replaced by name if name is given
|
2006-04-11 13:41:02 +02:00
|
|
|
if name and (text.startswith('/me ') or text.startswith('/me\n')):
|
2005-12-12 10:12:06 +01:00
|
|
|
text = '* ' + name + text[3:]
|
2005-12-12 14:00:46 +01:00
|
|
|
# detect urls formatting and if the user has it on emoticons
|
2005-12-12 10:12:06 +01:00
|
|
|
index = self.detect_and_print_special_text(text, text_tags)
|
2005-12-07 17:28:04 +01:00
|
|
|
|
2005-10-28 23:46:55 +02:00
|
|
|
# add the rest of text located in the index and after
|
|
|
|
end_iter = buffer.get_end_iter()
|
|
|
|
buffer.insert_with_tags_by_name(end_iter, text[index:], *text_tags)
|
|
|
|
|