Skip to content
Snippets Groups Projects
Commit 20eb63c5 authored by Klemens Schölhorn's avatar Klemens Schölhorn
Browse files

Move all UI logic into the Ui class

Previsouly parts of the logic were in the OmemoButton and OmemoMenu classes.
This commit moves them all into the main Ui class and thus makes it easier to
reuse the functionality in other places. It also extracts some common actions
into their own functions.
parent 8fbba685
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@ UNTRUSTED = 0
class OmemoButton(gtk.Button):
def __init__(self, plugin, chat_control, menu):
def __init__(self, plugin, chat_control, ui, enabled):
super(OmemoButton, self).__init__(label=None, stock=None)
self.chat_control = chat_control
......@@ -48,35 +48,28 @@ class OmemoButton(gtk.Button):
self.set_image(icon)
self.set_tooltip_text('OMEMO Encryption')
self.connect('clicked', self.on_click, menu)
self.connect('clicked', self.on_click)
self.menu = OmemoMenu(ui, enabled)
def on_click(self, widget, menu):
def on_click(self, widget):
"""
Popup omemo menu
"""
gtkgui_helpers.popup_emoticons_under_button(
menu, widget, self.chat_control.parent_win)
self.menu, widget, self.chat_control.parent_win)
def set_omemo_state(self, state):
self.menu.set_omemo_state(state)
class OmemoMenu(gtk.Menu):
def __init__(self, plugin, chat_control, ui, enabled):
def __init__(self, ui, enabled):
super(OmemoMenu, self).__init__()
self.plugin = plugin
self.ui = ui
self.contact = chat_control.contact
self.chat_control = chat_control
self.item_omemo_state = gtk.CheckMenuItem('Activate OMEMO')
if enabled:
self.item_omemo_state.set_active(True)
self.chat_control.print_conversation_line(
u'OMEMO encryption enabled ', 'status', '', None)
self.ui.refreshAuthLockSymbol()
else:
self.item_omemo_state.set_active(False)
self.chat_control.print_conversation_line(
u'OMEMO encryption disabled', 'status', '', None)
self.ui.refreshAuthLockSymbol()
self.item_omemo_state.set_active(enabled)
self.item_omemo_state.connect('activate', self.on_toggle_omemo)
self.append(self.item_omemo_state)
......@@ -90,26 +83,10 @@ class OmemoMenu(gtk.Menu):
self.show_all()
def on_toggle_omemo(self, widget):
enabled = widget.get_active()
if enabled:
log.debug(self.contact.account.name + ' => Enable OMEMO for ' +
self.contact.jid)
self.plugin.omemo_enable_for(self.contact)
self.chat_control.print_conversation_line(
u'OMEMO encryption enabled ', 'status', '', None)
self.ui.WarnIfUndecidedFingerprints()
else:
log.debug(self.contact.account.name + ' => Disable OMEMO for ' +
self.contact.jid)
self.plugin.omemo_disable_for(self.contact)
self.ui.refreshAuthLockSymbol()
self.chat_control.print_conversation_line(
u'OMEMO encryption disabled', 'status', '', None)
self.ui.set_omemo_state(widget.get_active())
def on_open_fingerprint_window(self, widget):
dlg = FingerprintWindow(self.plugin, self.contact,
self.chat_control.parent_win.window)
dlg.show_all()
self.ui.show_fingerprint_window()
def set_omemo_state(self, state):
self.item_omemo_state.set_active(state)
......@@ -128,24 +105,58 @@ class Ui(object):
def __init__(self, plugin, chat_control, enabled, state):
self.contact = chat_control.contact
self.chat_control = chat_control
self.plugin = plugin
self.state = state
self.menu = OmemoMenu(plugin, chat_control, self, enabled)
self.omemobutton = OmemoButton(plugin, chat_control, self.menu)
self.display_omemo_state()
self.refreshAuthLockSymbol()
self.omemobutton = OmemoButton(plugin, chat_control, self, enabled)
_add_widget(self.omemobutton, self.chat_control)
def set_omemo_state(self, enabled):
"""
Enable or disable OMEMO for this window's contact and update the
window ui accordingly
"""
if enabled:
log.debug(self.contact.account.name + ' => Enable OMEMO for ' +
self.contact.jid)
self.plugin.omemo_enable_for(self.contact)
self.WarnIfUndecidedFingerprints() # calls refreshAuthLockSymbol()
else:
log.debug(self.contact.account.name + ' => Disable OMEMO for ' +
self.contact.jid)
self.plugin.omemo_disable_for(self.contact)
self.refreshAuthLockSymbol()
self.omemobutton.set_omemo_state(enabled)
self.display_omemo_state()
def encryption_active(self):
return self.state.encryption.is_active(self.contact.jid)
def activate_omemo(self):
self.menu.set_omemo_state(True)
self.omemobutton.set_omemo_state(True)
def show_fingerprint_window(self):
dlg = FingerprintWindow(self.plugin, self.contact,
self.chat_control.parent_win.window)
dlg.show_all()
def plain_warning(self):
self.chat_control.print_conversation_line(
'Received plaintext message! ' +
'Your next message will still be encrypted!', 'status', '', None)
def display_omemo_state(self):
if self.encryption_active():
msg = u'OMEMO encryption enabled'
else:
msg = u'OMEMO encryption disabled'
self.chat_control.print_conversation_line(msg, 'status', '', None)
def WarnIfUndecidedFingerprints(self):
if self.state.store.identityKeyStore. \
getUndecidedFingerprints(self.contact.jid):
......
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