Commit 52ccca95 authored by Philipp Hörist's avatar Philipp Hörist

ChatControl: Move set_lock_image to ChatControlBase

parent bcd15212
......@@ -109,19 +109,10 @@ class ChatControl(ChatControlBase):
self.widget_set_visible(self.xml.get_object('banner_eventbox'),
app.config.get('hide_chat_banner'))
self.authentication_button = self.xml.get_object(
'authentication_button')
id_ = self.authentication_button.connect('clicked',
self._on_authentication_button_clicked)
self.handlers[id_] = self.authentication_button
self.sendfile_button = self.xml.get_object('sendfile_button')
self.sendfile_button.set_action_name('win.send-file-' + \
self.control_id)
# Add lock image to show chat encryption
self.lock_image = self.xml.get_object('lock_image')
# Menu for the HeaderBar
self.control_menu = gui_menu_builder.get_singlechat_menu(
self.control_id, self.account, self.contact.jid)
......@@ -792,42 +783,6 @@ class ChatControl(ChatControlBase):
fixed.set_no_show_all(True)
self.close_jingle_content(jingle_type)
def set_lock_image(self):
encryption_state = {'visible': self.encryption is not None,
'enc_type': self.encryption,
'authenticated': False}
if self.encryption:
app.plugin_manager.extension_point(
'encryption_state' + self.encryption, self, encryption_state)
self._show_lock_image(**encryption_state)
def _show_lock_image(self, visible, enc_type='', authenticated=False):
"""
Set lock icon visibility and create tooltip
"""
if authenticated:
authenticated_string = _('and authenticated')
self.lock_image.set_from_icon_name(
'security-high-symbolic', Gtk.IconSize.MENU)
else:
authenticated_string = _('and NOT authenticated')
self.lock_image.set_from_icon_name(
'security-low-symbolic', Gtk.IconSize.MENU)
tooltip = _('%(type)s encryption is active %(authenticated)s') % \
{'type': enc_type, 'authenticated': authenticated_string}
self.authentication_button.set_tooltip_text(tooltip)
self.widget_set_visible(self.authentication_button, not visible)
self.lock_image.set_sensitive(visible)
def _on_authentication_button_clicked(self, widget):
if self.encryption:
app.plugin_manager.extension_point(
'encryption_dialog' + self.encryption, self)
def _nec_mam_decrypted_message_received(self, obj):
if obj.conn.name != self.account:
return
......
......@@ -448,6 +448,37 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.set_encryption_menu_icon()
self.set_lock_image()
def set_lock_image(self):
encryption_state = {'visible': self.encryption is not None,
'enc_type': self.encryption,
'authenticated': False}
if self.encryption:
app.plugin_manager.extension_point(
'encryption_state' + self.encryption, self, encryption_state)
visible, enc_type, authenticated = encryption_state.values()
if authenticated:
authenticated_string = _('and authenticated')
self.xml.lock_image.set_from_icon_name(
'security-high-symbolic', Gtk.IconSize.MENU)
else:
authenticated_string = _('and NOT authenticated')
self.xml.lock_image.set_from_icon_name(
'security-low-symbolic', Gtk.IconSize.MENU)
tooltip = _('%(type)s encryption is active %(authenticated)s.') % {
'type': enc_type, 'authenticated': authenticated_string}
self.xml.authentication_button.set_tooltip_text(tooltip)
self.xml.authentication_button.set_visible(visible)
self.xml.lock_image.set_sensitive(visible)
def _on_authentication_button_clicked(self, _button):
app.plugin_manager.extension_point(
'encryption_dialog' + self.encryption, self)
def set_encryption_state(self, encryption):
config_key = '%s-%s' % (self.account, self.contact.jid)
self.encryption = encryption
......
......@@ -851,6 +851,7 @@ microphone-sensitivity-high-symbolic</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="no_show_all">True</property>
<property name="relief">none</property>
<signal name="clicked" handler="_on_authentication_button_clicked" swapped="no"/>
<child>
<object class="GtkImage" id="lock_image">
<property name="visible">True</property>
......
......@@ -263,6 +263,7 @@
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="no_show_all">True</property>
<property name="relief">none</property>
<signal name="clicked" handler="_on_authentication_button_clicked" swapped="no"/>
<child>
<object class="GtkImage" id="lock_image">
<property name="visible">True</property>
......
......@@ -149,12 +149,6 @@ class GroupchatControl(ChatControlBase):
self.control_id)
# Encryption
self.lock_image = self.xml.get_object('lock_image')
self.authentication_button = self.xml.get_object(
'authentication_button')
id_ = self.authentication_button.connect('clicked',
self._on_authentication_button_clicked)
self.handlers[id_] = self.authentication_button
self.set_lock_image()
self.encryption_menu = self.xml.get_object('encryption_menu')
......@@ -773,41 +767,6 @@ class GroupchatControl(ChatControlBase):
tab_image = get_icon_name('muc-inactive')
return tab_image
def set_lock_image(self):
encryption_state = {'visible': self.encryption is not None,
'enc_type': self.encryption,
'authenticated': False}
if self.encryption:
app.plugin_manager.extension_point(
'encryption_state' + self.encryption, self, encryption_state)
self._show_lock_image(**encryption_state)
def _show_lock_image(self, visible, enc_type='', authenticated=False):
"""
Set lock icon visibility and create tooltip
"""
if authenticated:
authenticated_string = _('and authenticated')
self.lock_image.set_from_icon_name(
'security-high-symbolic', Gtk.IconSize.MENU)
else:
authenticated_string = _('and NOT authenticated')
self.lock_image.set_from_icon_name(
'security-low-symbolic', Gtk.IconSize.MENU)
tooltip = _('%(type)s encryption is active %(authenticated)s.') % {
'type': enc_type, 'authenticated': authenticated_string}
self.authentication_button.set_tooltip_text(tooltip)
self.widget_set_visible(self.authentication_button, not visible)
self.lock_image.set_sensitive(visible)
def _on_authentication_button_clicked(self, widget):
app.plugin_manager.extension_point(
'encryption_dialog' + self.encryption, self)
def _update_banner_state_image(self):
surface = app.interface.avatar_storage.get_muc_surface(
self.account,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment