Skip to content
Snippets Groups Projects
Commit 000b0d90 authored by roidelapluie's avatar roidelapluie
Browse files

Add a tooltip to the XEP-0184 warning icon

parent 303c0f6a
No related branches found
No related tags found
No related merge requests found
...@@ -268,6 +268,8 @@ def __init__(self, account, used_in_history_window = False): ...@@ -268,6 +268,8 @@ def __init__(self, account, used_in_history_window = False):
tag.set_property('underline', pango.UNDERLINE_SINGLE) tag.set_property('underline', pango.UNDERLINE_SINGLE)
buffer.create_tag('focus-out-line', justification = gtk.JUSTIFY_CENTER) buffer.create_tag('focus-out-line', justification = gtk.JUSTIFY_CENTER)
tag = buffer.create_tag('xep0184-warning')
# One mark at the begining then 2 marks between each lines # One mark at the begining then 2 marks between each lines
size = gajim.config.get('max_conversation_lines') size = gajim.config.get('max_conversation_lines')
...@@ -278,6 +280,8 @@ def __init__(self, account, used_in_history_window = False): ...@@ -278,6 +280,8 @@ def __init__(self, account, used_in_history_window = False):
# holds a mark at the end of --- line # holds a mark at the end of --- line
self.focus_out_end_mark = None self.focus_out_end_mark = None
self.xep0184_warning_tooltip = tooltips.BaseTooltip()
self.line_tooltip = tooltips.BaseTooltip() self.line_tooltip = tooltips.BaseTooltip()
# use it for hr too # use it for hr too
self.tv.focus_out_line_pixbuf = ConversationTextview.FOCUS_OUT_LINE_PIXBUF self.tv.focus_out_line_pixbuf = ConversationTextview.FOCUS_OUT_LINE_PIXBUF
...@@ -416,6 +420,13 @@ def show_it(): ...@@ -416,6 +420,13 @@ def show_it():
buffer.insert(end_iter, ' ') buffer.insert(end_iter, ' ')
buffer.insert_pixbuf(end_iter, buffer.insert_pixbuf(end_iter,
ConversationTextview.XEP0184_WARNING_PIXBUF) ConversationTextview.XEP0184_WARNING_PIXBUF)
before_img_iter = buffer.get_iter_at_mark(
self.xep0184_marks[id])
before_img_iter.forward_char()
post_img_iter = before_img_iter.copy()
post_img_iter.forward_char()
buffer.apply_tag_by_name('xep0184-warning', before_img_iter,
post_img_iter)
self.xep0184_shown[id] = SHOWN self.xep0184_shown[id] = SHOWN
return False return False
...@@ -511,6 +522,24 @@ def show_focus_out_line(self): ...@@ -511,6 +522,24 @@ def show_focus_out_line(self):
# scroll to the end (via idle in case the scrollbar has appeared) # scroll to the end (via idle in case the scrollbar has appeared)
gobject.idle_add(self.scroll_to_end) gobject.idle_add(self.scroll_to_end)
def show_xep0184_warning_tooltip(self):
pointer = self.tv.get_pointer()
x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer[0],
pointer[1])
tags = self.tv.get_iter_at_location(x, y).get_tags()
tag_table = self.tv.get_buffer().get_tag_table()
xep0184_warning = False
for tag in tags:
if tag == tag_table.lookup('xep0184-warning'):
xep0184_warning = True
break
if xep0184_warning and not self.xep0184_warning_tooltip.win:
# check if the current pointer is still over the line
position = self.tv.window.get_origin()
self.xep0184_warning_tooltip.show_tooltip(_('This message '
'was not delivered'),
8, position[1] + pointer[1])
def show_line_tooltip(self): def show_line_tooltip(self):
pointer = self.tv.get_pointer() pointer = self.tv.get_pointer()
x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer[0], x, y = self.tv.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, pointer[0],
...@@ -567,6 +596,7 @@ def on_textview_motion_notify_event(self, widget, event): ...@@ -567,6 +596,7 @@ def on_textview_motion_notify_event(self, widget, event):
self.change_cursor = None self.change_cursor = None
tag_table = self.tv.get_buffer().get_tag_table() tag_table = self.tv.get_buffer().get_tag_table()
over_line = False over_line = False
xep0184_warning = False
for tag in tags: for tag in tags:
if tag in (tag_table.lookup('url'), tag_table.lookup('mail')): if tag in (tag_table.lookup('url'), tag_table.lookup('mail')):
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor( self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
...@@ -574,6 +604,8 @@ def on_textview_motion_notify_event(self, widget, event): ...@@ -574,6 +604,8 @@ def on_textview_motion_notify_event(self, widget, event):
self.change_cursor = tag self.change_cursor = tag
elif tag == tag_table.lookup('focus-out-line'): elif tag == tag_table.lookup('focus-out-line'):
over_line = True over_line = True
elif tag == tag_table.lookup('xep0184-warning'):
xep0184_warning = True
if self.line_tooltip.timeout != 0: if self.line_tooltip.timeout != 0:
# Check if we should hide the line tooltip # Check if we should hide the line tooltip
...@@ -585,6 +617,13 @@ def on_textview_motion_notify_event(self, widget, event): ...@@ -585,6 +617,13 @@ def on_textview_motion_notify_event(self, widget, event):
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor( self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)) gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
self.change_cursor = tag self.change_cursor = tag
if xep0184_warning and not self.xep0184_warning_tooltip.win:
self.xep0184_warning_tooltip.timeout = \
gobject.timeout_add(500,
self.show_xep0184_warning_tooltip)
self.tv.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(
gtk.gdk.Cursor(gtk.gdk.LEFT_PTR))
self.change_cursor = tag
def clear(self, tv = None): def clear(self, tv = None):
'''clear text in the textview''' '''clear text in the textview'''
...@@ -1237,4 +1276,4 @@ def print_real_text(self, text, text_tags = [], name = None, xhtml = None): ...@@ -1237,4 +1276,4 @@ def print_real_text(self, text, text_tags = [], name = None, xhtml = None):
end_iter = buffer.get_end_iter() end_iter = buffer.get_end_iter()
buffer.insert_with_tags_by_name(end_iter, text[index:], *text_tags) buffer.insert_with_tags_by_name(end_iter, text[index:], *text_tags)
# vim: se ts=3: # vim: se ts=3:
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment