diff --git a/omemo/gtk/config.py b/omemo/gtk/config.py
index fdbd343..952d4b7 100644
--- a/omemo/gtk/config.py
+++ b/omemo/gtk/config.py
@@ -17,12 +17,8 @@
# along with OMEMO Gajim Plugin. If not, see .
import logging
-import os
-
-from gi.repository import GdkPixbuf
from gajim.common import app
-from gajim.common import configpaths
from gajim.plugins.gui import GajimPluginConfigDialog
from gajim.plugins.helpers import get_builder
@@ -30,14 +26,6 @@ from omemo.backend.util import get_fingerprint
log = logging.getLogger('gajim.plugin_system.omemo')
-PILLOW = False
-try:
- import qrcode
- PILLOW = True
-except ImportError as error:
- log.debug(error)
- log.error('python-qrcode or dependencies of it are not available')
-
class OMEMOConfigDialog(GajimPluginConfigDialog):
def init(self):
@@ -97,27 +85,6 @@ class OMEMOConfigDialog(GajimPluginConfigDialog):
def account_combobox_changed_cb(self, box, *args):
self.update_context_list()
- @staticmethod
- def _get_qrcode(jid, sid, identity_key):
- fingerprint = get_fingerprint(identity_key)
- file_name = 'omemo_{}.png'.format(jid)
- path = os.path.join(
- configpaths.get('MY_DATA'), file_name)
-
- ver_string = 'xmpp:{}?omemo-sid-{}={}'.format(jid, sid, fingerprint)
- log.debug('Verification String: %s', ver_string)
-
- if os.path.exists(path):
- return path
-
- qr = qrcode.QRCode(version=None, error_correction=2,
- box_size=4, border=1)
- qr.add_data(ver_string)
- qr.make(fit=True)
- img = qr.make_image()
- img.save(path)
- return path
-
def update_disabled_account_view(self):
self._ui.disabled_account_store.clear()
for account in self.disabled_accounts:
@@ -168,7 +135,6 @@ class OMEMOConfigDialog(GajimPluginConfigDialog):
self._ui.fingerprint_label.set_markup('')
self._ui.refresh.set_sensitive(False)
self._ui.cleardevice_button.set_sensitive(False)
- self._ui.qrcode.clear()
return
active = self._ui.account_combobox.get_active()
account = self._ui.account_store[active][0]
@@ -192,16 +158,3 @@ class OMEMOConfigDialog(GajimPluginConfigDialog):
# Set Device ID List
for item in omemo.backend.get_devices(own_jid):
self._ui.deviceid_store.append([item])
-
- # Set QR Verification Code
- if PILLOW:
- path = self._get_qrcode(own_jid,
- omemo.backend.own_device,
- identity_key)
- pixbuf = GdkPixbuf.Pixbuf.new_from_file(path)
- self._ui.qrcode.set_from_pixbuf(pixbuf)
- self._ui.qrcode.show()
- self._ui.qrinfo.hide()
- else:
- self._ui.qrcode.hide()
- self._ui.qrinfo.show()
diff --git a/omemo/gtk/config.ui b/omemo/gtk/config.ui
index b114fa0..d80a188 100644
--- a/omemo/gtk/config.ui
+++ b/omemo/gtk/config.ui
@@ -30,74 +30,6 @@
18
vertical
6
-
-
-
- False
- True
- 0
-
-
True
@@ -213,15 +145,20 @@
-
+
+ True
False
- True
- Scan this QR-Code with your mobile device for easy verification
start
- 6
- 6
- gtk-missing-image
- 1
+ Note: Fingerprints of your contacts are managed in the message window.
+ True
+ 50
+ 0
+
+
+
+
1
@@ -232,41 +169,19 @@
True
False
- OMEMO
- start
+ end
+ gtk-missing-image
0
3
-
-
- True
- False
- start
- Note: Fingerprints of your contacts are managed in the message window.
- True
-
-
-
-
-
-
- 1
- 4
-
-
-
-
-
False
True
- 1
+ 0
diff --git a/omemo/gtk/key.py b/omemo/gtk/key.py
index 73524cf..f1bc575 100644
--- a/omemo/gtk/key.py
+++ b/omemo/gtk/key.py
@@ -14,14 +14,17 @@
# You should have received a copy of the GNU General Public License
# along with OMEMO Gajim Plugin. If not, see .
+import os
import time
import logging
+import tempfile
from gi.repository import Gtk
from gi.repository import GdkPixbuf
from gajim.common import app
from gajim.plugins.plugins_i18n import _
+from gajim.plugins.helpers import get_builder
from omemo.gtk.util import DialogButton, ButtonAction
from omemo.gtk.util import NewConfirmationDialog
@@ -31,6 +34,7 @@ from omemo.backend.util import get_fingerprint
log = logging.getLogger('gajim.plugin_system.omemo')
+
TRUST_DATA = {
Trust.NOT_TRUSTED: ('dialog-error-symbolic',
_('Not Trusted'),
@@ -64,56 +68,27 @@ class KeyDialog(Gtk.Dialog):
self._omemo = self._plugin.get_omemo(self._account)
self._own_jid = app.get_jid_from_account(self._account)
- # Header
- jid = self._contact.jid
- self._header = Gtk.Label(label=_('Fingerprints for %s') % jid)
- self._header.get_style_context().add_class('bold')
- self._header.get_style_context().add_class('dim-label')
+ path = self._plugin.local_file_path('gtk/key.ui')
+ self._ui = get_builder(path)
- # Fingerprints list
- self._listbox = Gtk.ListBox()
- self._listbox.set_selection_mode(Gtk.SelectionMode.NONE)
+ self._ui.header.set_text(_('Fingerprints for %s') % self._contact.jid)
- self._scrolled = Gtk.ScrolledWindow()
- self._scrolled.set_policy(Gtk.PolicyType.NEVER,
- Gtk.PolicyType.AUTOMATIC)
- self._scrolled.add(self._listbox)
-
- # Own fingerprint
- self._label = Gtk.Label(label=_('Own Fingerprint'))
- self._label.get_style_context().add_class('bold')
- self._label.get_style_context().add_class('dim-label')
-
- self._omemo_logo = Gtk.Image()
omemo_img_path = self._plugin.local_file_path('omemo.png')
- omemo_pixbuf = GdkPixbuf.Pixbuf.new_from_file(omemo_img_path)
- self._omemo_logo.set_from_pixbuf(omemo_pixbuf)
+ self._ui.omemo_image.set_from_file(omemo_img_path)
- identity_key = self._omemo.backend.storage.getIdentityKeyPair()
- ownfpr_format = get_fingerprint(identity_key, formatted=True)
- self._ownfpr = Gtk.Label(label=ownfpr_format)
- self._ownfpr.get_style_context().add_class('omemo-mono')
- self._ownfpr.set_selectable(True)
+ self._identity_key = self._omemo.backend.storage.getIdentityKeyPair()
+ ownfpr_format = get_fingerprint(self._identity_key, formatted=True)
+ self._ui.own_fingerprint.set_text(ownfpr_format)
- self._ownfpr_box = Gtk.Box(spacing=12)
- self._ownfpr_box.set_halign(Gtk.Align.CENTER)
- self._ownfpr_box.pack_start(self._omemo_logo, True, True, 0)
- self._ownfpr_box.pack_start(self._ownfpr, True, True, 0)
-
- box = self.get_content_area()
- box.set_orientation(Gtk.Orientation.VERTICAL)
- box.set_spacing(12)
- box.pack_start(self._header, False, True, 0)
- box.pack_start(self._scrolled, True, True, 0)
- box.pack_start(self._label, False, True, 0)
- box.pack_start(self._ownfpr_box, False, True, 0)
+ self.get_content_area().add(self._ui.grid)
self.update()
+ self._load_qrcode()
self.connect('destroy', self._on_destroy)
self.show_all()
def update(self):
- self._listbox.foreach(self._listbox.remove)
+ self._ui.list.foreach(self._ui.list.remove)
self._load_fingerprints(self._own_jid)
self._load_fingerprints(self._contact.jid, self._groupchat is True)
@@ -153,7 +128,45 @@ class KeyDialog(Gtk.Dialog):
key_row.device_id = item.device_id
for row in rows.values():
- self._listbox.add(row)
+ self._ui.list.add(row)
+
+ @staticmethod
+ def _get_qrcode(jid, sid, identity_key):
+ fingerprint = get_fingerprint(identity_key)
+ path = os.path.join(tempfile.gettempdir(),
+ 'omemo_{}.png'.format(jid))
+
+ ver_string = 'xmpp:{}?omemo-sid-{}={}'.format(jid, sid, fingerprint)
+ log.debug('Verification String: %s', ver_string)
+
+ import qrcode
+ qr = qrcode.QRCode(version=None, error_correction=2,
+ box_size=4, border=1)
+ qr.add_data(ver_string)
+ qr.make(fit=True)
+ qr.make()
+
+ back_color = 'transparent'
+ if app.css_config.prefer_dark:
+ back_color = 'white'
+ img = qr.make_image(fill_color='black', back_color=back_color)
+ img.save(path)
+ return path
+
+ def _load_qrcode(self):
+ try:
+ path = self._get_qrcode(self._own_jid,
+ self._omemo.backend.own_device,
+ self._identity_key)
+ except ImportError:
+ log.exception('Failed to generate QR code')
+ self._ui.qrcode.hide()
+ self._ui.qrinfo.show()
+ else:
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file(path)
+ self._ui.qrcode.set_from_pixbuf(pixbuf)
+ self._ui.qrcode.show()
+ self._ui.qrinfo.hide()
def _on_destroy(self, *args):
del self._windows['dialog']
diff --git a/omemo/gtk/key.ui b/omemo/gtk/key.ui
new file mode 100644
index 0000000..b02e498
--- /dev/null
+++ b/omemo/gtk/key.ui
@@ -0,0 +1,158 @@
+
+
+
+
+
+ False
+ none
+
+
+ True
+ False
+ 12
+ 12
+ 12
+ 12
+ vertical
+ 12
+
+
+ True
+ False
+ True
+
+
+
+ False
+ True
+ 0
+
+
+
+
+ True
+ False
+ gtk-missing-image
+
+
+ False
+ True
+ 1
+
+
+
+
+ True
+ False
+ For verification via QR-Code
+you have to install python-qrcode
+
+
+
+ False
+ True
+ 2
+
+
+
+
+
+
+ True
+ False
+ 12
+
+
+ True
+ True
+ True
+ never
+ in
+ 270
+ False
+
+
+ True
+ False
+
+
+ True
+ False
+ none
+
+
+
+
+
+
+ 0
+ 1
+
+
+
+
+
+ 0
+ 2
+
+
+
+
+ True
+ False
+ center
+ 11
+
+
+ True
+ False
+ gtk-missing-image
+
+
+ False
+ True
+ 0
+
+
+
+
+
+ False
+ True
+ 1
+
+
+
+
+ 0
+ 0
+
+
+
+
diff --git a/omemo/gtk/style.css b/omemo/gtk/style.css
index 5d1003a..0361536 100644
--- a/omemo/gtk/style.css
+++ b/omemo/gtk/style.css
@@ -1,6 +1,8 @@
.omemo-dark-success-color { color: darker(@success_color); }
.omemo-inactive-color { color: @insensitive_fg_color; }
+.omemo-qr-not-available {color: red;}
+
.omemo-mono { font-size: 12px; font-family: monospace; }
.omemo-last-seen { font-size: 11px; }