changeset 71f841beb313 in /home/hg/repos/gajim-plugins
author: lovetox <[email protected]>
branches:
details:gajim-plugins?cmd=changeset;node=71f841beb313
description: Add popup of fpr dialog on new fpr received
diffstat:
omemo/__init__.py | 34 +++++++++++++++++++---------------
omemo/fpr_dialog.ui | 5 +++--
omemo/omemo/liteaxolotlstore.py | 6 ++++++
omemo/omemo/liteidentitykeystore.py | 16 ++++++++++++++++
omemo/omemo/sql.py | 5 ++++-
omemo/ui.py | 36 +++++++++++++++++++++++++++++++-----
6 files changed, 79 insertions(+), 23 deletions(-)
diffs (228 lines):
diff -r 2cb144c5e7e6 -r 71f841beb313 omemo/__init__.py
--- a/omemo/__init__.py Sat Jul 30 22:50:58 2016 +0200
+++ b/omemo/__init__.py Sun Jul 31 11:06:56 2016 +0200
@@ -321,13 +321,13 @@
' => Switch encryption ON automatically ...')
self.omemo_enable_for(contact_jid, account)
- if (account in self.ui_list and
- contact_jid not in self.ui_list[account]):
+ if account in self.ui_list and \
+ contact_jid not in self.ui_list[account]:
chat_control = gajim.interface.msg_win_mgr.get_control(
contact_jid, account)
- if chat_control is not None:
+ if chat_control:
self.connect_ui(chat_control)
# Look if Public Keys are missing and fetch them
@@ -352,24 +352,26 @@
@log_calls('OmemoPlugin')
def connect_ui(self, chat_control):
- account_name = chat_control.contact.account.name
+ account = chat_control.contact.account.name
contact_jid = chat_control.contact.jid
- if account_name not in self.ui_list:
- self.ui_list[account_name] = {}
- state = self.get_omemo_state(account_name)
- my_jid = gajim.get_jid_from_account(account_name)
+ if account not in self.ui_list:
+ self.ui_list[account] = {}
+ state = self.get_omemo_state(account)
+ my_jid = gajim.get_jid_from_account(account)
omemo_enabled = state.encryption.is_active(contact_jid)
if omemo_enabled:
- log.debug(account_name + " => Adding OMEMO ui for " + contact_jid)
- self.ui_list[account_name][contact_jid] = Ui(self, chat_control,
- omemo_enabled, state)
+ log.debug(account + " => Adding OMEMO ui for " + contact_jid)
+ self.ui_list[account][contact_jid] = Ui(self, chat_control,
+ omemo_enabled, state)
+ self.ui_list[account][contact_jid].new_fingerprints_available()
return
if contact_jid in state.device_ids or contact_jid == my_jid:
- log.debug(account_name + " => Adding OMEMO ui for " + contact_jid)
- self.ui_list[account_name][contact_jid] = Ui(self, chat_control,
- omemo_enabled, state)
+ log.debug(account + " => Adding OMEMO ui for " + contact_jid)
+ self.ui_list[account][contact_jid] = Ui(self, chat_control,
+ omemo_enabled, state)
+ self.ui_list[account][contact_jid].new_fingerprints_available()
else:
- log.warn(account_name + " => No devices for " + contact_jid)
+ log.warn(account + " => No devices for " + contact_jid)
@log_calls('OmemoPlugin')
def disconnect_ui(self, chat_control):
@@ -474,6 +476,8 @@
recipient_id in self.ui_list[account_name]:
self.ui_list[account_name][recipient_id]. \
WarnIfUndecidedFingerprints()
+ self.ui_list[account_name][recipient_id]. \
+ new_fingerprints_available()
@log_calls('OmemoPlugin')
def query_own_devicelist(self, account):
diff -r 2cb144c5e7e6 -r 71f841beb313 omemo/fpr_dialog.ui
--- a/omemo/fpr_dialog.ui Sat Jul 30 22:50:58 2016 +0200
+++ b/omemo/fpr_dialog.ui Sun Jul 31 11:06:56 2016 +0200
@@ -32,7 +32,8 @@
<property name="spacing">10</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
- <property name="height_request">100</property>
+ <property name="width_request">500</property>
+ <property name="height_request">250</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
@@ -97,7 +98,7 @@
<property name="spacing">5</property>
<child>
<object class="GtkButton" id="trust_button">
- <property name="label" translatable="yes"
comments="button">Verify Fingerprint</property>
+ <property name="label" translatable="yes"
comments="button">Trust/Revoke Fingerprint</property>
<property name="width_request">150</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
diff -r 2cb144c5e7e6 -r 71f841beb313 omemo/omemo/liteaxolotlstore.py
--- a/omemo/omemo/liteaxolotlstore.py Sat Jul 30 22:50:58 2016 +0200
+++ b/omemo/omemo/liteaxolotlstore.py Sun Jul 31 11:06:56 2016 +0200
@@ -87,6 +87,12 @@
return self.identityKeyStore.isTrustedIdentity(recepientId,
identityKey)
+ def setShownFingerprints(self, jid):
+ return self.identityKeyStore.setShownFingerprints(jid)
+
+ def getNewFingerprints(self, jid):
+ return self.identityKeyStore.getNewFingerprints(jid)
+
def loadPreKey(self, preKeyId):
return self.preKeyStore.loadPreKey(preKeyId)
diff -r 2cb144c5e7e6 -r 71f841beb313 omemo/omemo/liteidentitykeystore.py
--- a/omemo/omemo/liteidentitykeystore.py Sat Jul 30 22:50:58 2016 +0200
+++ b/omemo/omemo/liteidentitykeystore.py Sun Jul 31 11:06:56 2016 +0200
@@ -131,6 +131,22 @@
return result
+ def getNewFingerprints(self, jid):
+ q = "SELECT _id FROM identities WHERE shown = 0 AND " \
+ "recipient_id = ?"
+ c = self.dbConn.cursor()
+ result = []
+ for row in c.execute(q, (jid,)):
+ result.append(row[0])
+ return result
+
+ def setShownFingerprints(self, fingerprints):
+ q = "UPDATE identities SET shown = 1 WHERE _id IN ({})" \
+ .format(', '.join(['?'] * len(fingerprints)))
+ c = self.dbConn.cursor()
+ c.execute(q, fingerprints)
+ self.dbConn.commit()
+
def setTrust(self, _id, trust):
q = "UPDATE identities SET trust = ? WHERE _id = ?"
c = self.dbConn.cursor()
diff -r 2cb144c5e7e6 -r 71f841beb313 omemo/omemo/sql.py
--- a/omemo/omemo/sql.py Sat Jul 30 22:50:58 2016 +0200
+++ b/omemo/omemo/sql.py Sun Jul 31 11:06:56 2016 +0200
@@ -44,7 +44,8 @@
CREATE TABLE IF NOT EXISTS identities (
_id INTEGER PRIMARY KEY AUTOINCREMENT, recipient_id TEXT,
registration_id INTEGER, public_key BLOB, private_key BLOB,
- next_prekey_id INTEGER, timestamp INTEGER, trust INTEGER);
+ next_prekey_id INTEGER, timestamp INTEGER, trust INTEGER,
+ shown INTEGER DEFAULT 0);
CREATE UNIQUE INDEX IF NOT EXISTS
public_key_index ON identities (public_key, recipient_id);
@@ -135,6 +136,8 @@
_id INTEGER PRIMARY KEY AUTOINCREMENT,
prekey_id INTEGER UNIQUE,
timestamp NUMERIC DEFAULT CURRENT_TIMESTAMP, record BLOB);
+ ALTER TABLE identities ADD COLUMN shown INTEGER DEFAULT 0;
+ UPDATE identities SET shown = 1;
"""
self.dbConn.executescript(""" BEGIN TRANSACTION;
diff -r 2cb144c5e7e6 -r 71f841beb313 omemo/ui.py
--- a/omemo/ui.py Sat Jul 30 22:50:58 2016 +0200
+++ b/omemo/ui.py Sun Jul 31 11:06:56 2016 +0200
@@ -103,6 +103,8 @@
self.chat_control = chat_control
self.plugin = plugin
self.state = state
+ self.account = self.contact.account.name
+ self.windowinstances = {}
self.display_omemo_state()
self.refreshAuthLockSymbol()
@@ -164,10 +166,27 @@
if not self.encryption_active():
self.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 new_fingerprints_available(self):
+ fingerprints = self.state.store.getNewFingerprints(self.contact.jid)
+ if fingerprints:
+ self.show_fingerprint_window(fingerprints)
+
+ def show_fingerprint_window(self, fingerprints=None):
+ if 'dialog' not in self.windowinstances:
+ self.windowinstances['dialog'] = \
+ FingerprintWindow(self.plugin, self.contact,
+ self.chat_control.parent_win.window,
+ self.windowinstances)
+ self.windowinstances['dialog'].show_all()
+ if fingerprints:
+ log.debug(self.account +
+ ' => Showing Fingerprint Prompt for ' +
+ self.contact.jid)
+ self.state.store.setShownFingerprints(fingerprints)
+ else:
+ self.windowinstances['dialog'].update_context_list()
+ if fingerprints:
+ self.state.store.setShownFingerprints(fingerprints)
def plain_warning(self):
self.chat_control.print_conversation_line(
@@ -392,14 +411,16 @@
class FingerprintWindow(gtk.Dialog):
- def __init__(self, plugin, contact, parent):
+ def __init__(self, plugin, contact, parent, windowinstances):
self.contact = contact
+ self.windowinstances = windowinstances
gtk.Dialog.__init__(self,
title=('Fingerprints for %s') % contact.jid,
parent=parent,
flags=gtk.DIALOG_DESTROY_WITH_PARENT)
close_button = self.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
close_button.connect('clicked', self.on_close_button_clicked)
+ self.connect('delete-event', self.on_window_delete)
self.plugin = plugin
self.GTK_BUILDER_FILE_PATH = \
self.plugin.local_file_path('fpr_dialog.ui')
@@ -439,6 +460,11 @@
self.update_context_list()
def on_close_button_clicked(self, widget):
+ del self.windowinstances['dialog']
+ self.hide()
+
+ def on_window_delete(self, widget, event):
+ del self.windowinstances['dialog']
self.hide()
def trust_button_clicked_cb(self, button, *args):
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits