ConvTextview: Rework display of encryption
This commit is contained in:
parent
cb692ae4eb
commit
fa65653adc
|
@ -338,6 +338,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
self._schedule_activity_timers()
|
self._schedule_activity_timers()
|
||||||
|
|
||||||
self.encryption = self.get_encryption_state()
|
self.encryption = self.get_encryption_state()
|
||||||
|
self.conv_textview.encryption_enabled = self.encryption is not None
|
||||||
|
|
||||||
# PluginSystem: adding GUI extension point for ChatControlBase
|
# PluginSystem: adding GUI extension point for ChatControlBase
|
||||||
# instance object (also subclasses, eg. ChatControl or GroupchatControl)
|
# instance object (also subclasses, eg. ChatControl or GroupchatControl)
|
||||||
|
@ -429,8 +430,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
def set_encryption_state(self, encryption):
|
def set_encryption_state(self, encryption):
|
||||||
config_key = '%s-%s' % (self.account, self.contact.jid)
|
config_key = '%s-%s' % (self.account, self.contact.jid)
|
||||||
self.encryption = encryption
|
self.encryption = encryption
|
||||||
|
self.conv_textview.encryption_enabled = encryption is not None
|
||||||
app.config.set_per('encryption', config_key,
|
app.config.set_per('encryption', config_key,
|
||||||
'encryption', self.encryption or '')
|
'encryption', self.encryption or '')
|
||||||
|
|
||||||
def get_encryption_state(self):
|
def get_encryption_state(self):
|
||||||
config_key = '%s-%s' % (self.account, self.contact.jid)
|
config_key = '%s-%s' % (self.account, self.contact.jid)
|
||||||
|
|
|
@ -186,6 +186,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
self.tv.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
|
self.tv.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
|
||||||
self.tv.set_left_margin(2)
|
self.tv.set_left_margin(2)
|
||||||
self.tv.set_right_margin(2)
|
self.tv.set_right_margin(2)
|
||||||
|
self._buffer = self.tv.get_buffer()
|
||||||
self.handlers = {}
|
self.handlers = {}
|
||||||
self.image_cache = {}
|
self.image_cache = {}
|
||||||
self.xep0184_marks = {}
|
self.xep0184_marks = {}
|
||||||
|
@ -204,6 +205,7 @@ class ConversationTextview(GObject.GObject):
|
||||||
self.account = account
|
self.account = account
|
||||||
self.cursor_changed = False
|
self.cursor_changed = False
|
||||||
self.last_time_printout = 0
|
self.last_time_printout = 0
|
||||||
|
self.encryption_enabled = False
|
||||||
|
|
||||||
style = self.tv.get_style_context()
|
style = self.tv.get_style_context()
|
||||||
style.add_class('gajim-conversation-font')
|
style.add_class('gajim-conversation-font')
|
||||||
|
@ -261,6 +263,9 @@ class ConversationTextview(GObject.GObject):
|
||||||
self.tagMarked.set_property('foreground', color)
|
self.tagMarked.set_property('foreground', color)
|
||||||
self.tagMarked.set_property('weight', Pango.Weight.BOLD)
|
self.tagMarked.set_property('weight', Pango.Weight.BOLD)
|
||||||
|
|
||||||
|
textview_icon = buffer_.create_tag('textview-icon')
|
||||||
|
textview_icon.set_property('rise', Pango.units_from_double(-4.45))
|
||||||
|
|
||||||
tag = buffer_.create_tag('time_sometimes')
|
tag = buffer_.create_tag('time_sometimes')
|
||||||
tag.set_property('foreground', 'darkgrey')
|
tag.set_property('foreground', 'darkgrey')
|
||||||
#Pango.SCALE_SMALL
|
#Pango.SCALE_SMALL
|
||||||
|
@ -1147,14 +1152,13 @@ class ConversationTextview(GObject.GObject):
|
||||||
if kind == 'status':
|
if kind == 'status':
|
||||||
direction_mark = i18n.direction_mark
|
direction_mark = i18n.direction_mark
|
||||||
|
|
||||||
|
# print the encryption icon
|
||||||
|
self.print_encryption_status(iter_, additional_data)
|
||||||
|
|
||||||
# print the time stamp
|
# print the time stamp
|
||||||
self.print_time(text, kind, tim, simple, direction_mark,
|
self.print_time(text, kind, tim, simple, direction_mark,
|
||||||
other_tags_for_time, iter_)
|
other_tags_for_time, iter_)
|
||||||
|
|
||||||
icon = load_icon('channel-secure-croped-symbolic', self.tv, pixbuf=True)
|
|
||||||
if encrypted:
|
|
||||||
buffer_.insert_pixbuf(iter_, icon)
|
|
||||||
|
|
||||||
# If there's a displaymarking, print it here.
|
# If there's a displaymarking, print it here.
|
||||||
if displaymarking:
|
if displaymarking:
|
||||||
self.print_displaymarking(displaymarking, iter_=iter_)
|
self.print_displaymarking(displaymarking, iter_=iter_)
|
||||||
|
@ -1275,6 +1279,52 @@ class ConversationTextview(GObject.GObject):
|
||||||
if text.startswith('/me ') or text.startswith('/me\n'):
|
if text.startswith('/me ') or text.startswith('/me\n'):
|
||||||
return kind
|
return kind
|
||||||
|
|
||||||
|
def print_encryption_status(self, iter_, additional_data):
|
||||||
|
details = self._get_encryption_details(additional_data)
|
||||||
|
if details is None:
|
||||||
|
# Message was not encrypted
|
||||||
|
if not self.encryption_enabled:
|
||||||
|
return
|
||||||
|
icon = 'security-low-symbolic'
|
||||||
|
color = 'error-color'
|
||||||
|
tooltip = _('Not encrypted')
|
||||||
|
else:
|
||||||
|
icon = 'security-high-symbolic'
|
||||||
|
color = 'success-color'
|
||||||
|
name, fingerprint = details
|
||||||
|
if fingerprint is None:
|
||||||
|
tooltip = name
|
||||||
|
else:
|
||||||
|
tooltip = '%s %s' % (name, fingerprint)
|
||||||
|
|
||||||
|
temp_mark = self._buffer.create_mark(None, iter_, True)
|
||||||
|
self._buffer.insert(iter_, ' ')
|
||||||
|
anchor = self._buffer.create_child_anchor(iter_)
|
||||||
|
anchor.plaintext = ''
|
||||||
|
self._buffer.insert(iter_, ' ')
|
||||||
|
|
||||||
|
# Apply mark to vertically center the icon
|
||||||
|
start = self._buffer.get_iter_at_mark(temp_mark)
|
||||||
|
self._buffer.apply_tag_by_name('textview-icon', start, iter_)
|
||||||
|
|
||||||
|
image = Gtk.Image.new_from_icon_name(icon, Gtk.IconSize.MENU)
|
||||||
|
image.show()
|
||||||
|
image.set_tooltip_text(tooltip)
|
||||||
|
image.get_style_context().add_class(color)
|
||||||
|
self.tv.add_child_at_anchor(image, anchor)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_encryption_details(additional_data):
|
||||||
|
encrypted = additional_data.get('encrypted')
|
||||||
|
if encrypted is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
name = encrypted.get('name')
|
||||||
|
if name is None:
|
||||||
|
return
|
||||||
|
fingerprint = encrypted.get('fingerprint')
|
||||||
|
return name, fingerprint
|
||||||
|
|
||||||
def print_time(self, text, kind, tim, simple, direction_mark, other_tags_for_time, iter_):
|
def print_time(self, text, kind, tim, simple, direction_mark, other_tags_for_time, iter_):
|
||||||
local_tim = time.localtime(tim)
|
local_tim = time.localtime(tim)
|
||||||
buffer_ = self.tv.get_buffer()
|
buffer_ = self.tv.get_buffer()
|
||||||
|
|
|
@ -534,6 +534,10 @@ class HistoryWindow:
|
||||||
buf.insert_with_tags_by_name(
|
buf.insert_with_tags_by_name(
|
||||||
end_iter, tim + '\n', 'time_sometimes')
|
end_iter, tim + '\n', 'time_sometimes')
|
||||||
|
|
||||||
|
# print the encryption icon
|
||||||
|
self.history_textview.print_encryption_status(
|
||||||
|
end_iter, additional_data)
|
||||||
|
|
||||||
tag_name = ''
|
tag_name = ''
|
||||||
tag_msg = ''
|
tag_msg = ''
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue