[pgp] Move all Gajim PGP code into plugin
This commit is contained in:
0
pgp/gtk/__init__.py
Normal file
0
pgp/gtk/__init__.py
Normal file
69
pgp/gtk/choose_key.ui
Normal file
69
pgp/gtk/choose_key.ui
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkListStore" id="liststore">
|
||||
<columns>
|
||||
<!-- column-name keyid -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name contactname -->
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkBox" id="box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">6</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="vexpand">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView" id="keys_treeview">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">liststore</property>
|
||||
<property name="search_column">1</property>
|
||||
<signal name="cursor-changed" handler="_on_row_changed" swapped="no"/>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="title" translatable="yes">Key ID</property>
|
||||
<property name="sort_order">descending</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="title" translatable="yes">Contact Name</property>
|
||||
<property name="sort_column_id">1</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
104
pgp/gtk/config.py
Normal file
104
pgp/gtk/config.py
Normal file
@@ -0,0 +1,104 @@
|
||||
# Copyright (C) 2019 Philipp Hörist <philipp AT hoerist.com>
|
||||
#
|
||||
# This file is part of the PGP Gajim Plugin.
|
||||
#
|
||||
# PGP Gajim Plugin is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published
|
||||
# by the Free Software Foundation; version 3 only.
|
||||
#
|
||||
# PGP Gajim Plugin is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PGP Gajim Plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
|
||||
from gajim.common import app
|
||||
|
||||
from gajim.plugins.helpers import get_builder
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
from pgp.gtk.key import ChooseGPGKeyDialog
|
||||
|
||||
|
||||
class PGPConfigDialog(Gtk.ApplicationWindow):
|
||||
def __init__(self, plugin, parent):
|
||||
Gtk.ApplicationWindow.__init__(self)
|
||||
self.set_application(app.app)
|
||||
self.set_show_menubar(False)
|
||||
self.set_title(_('PGP Configuration'))
|
||||
self.set_transient_for(parent)
|
||||
self.set_resizable(True)
|
||||
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
|
||||
self.set_destroy_with_parent(True)
|
||||
|
||||
ui_path = Path(__file__).parent
|
||||
self._ui = get_builder(ui_path.resolve() / 'config.ui')
|
||||
|
||||
self.add(self._ui.config_box)
|
||||
|
||||
self._ui.connect_signals(self)
|
||||
|
||||
self._plugin = plugin
|
||||
|
||||
for account in app.connections.keys():
|
||||
page = Page(plugin, account)
|
||||
self._ui.stack.add_titled(page,
|
||||
account,
|
||||
app.get_account_label(account))
|
||||
|
||||
self.show_all()
|
||||
|
||||
|
||||
class Page(Gtk.Box):
|
||||
def __init__(self, plugin, account):
|
||||
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
|
||||
|
||||
self._con = app.connections[account]
|
||||
self._plugin = plugin
|
||||
self._label = Gtk.Label()
|
||||
self._button = Gtk.Button(label=_('Assign Key'))
|
||||
self._button.connect('clicked', self._on_assign)
|
||||
|
||||
self._load_key()
|
||||
self.add(self._label)
|
||||
self.add(self._button)
|
||||
self.show_all()
|
||||
|
||||
def _on_assign(self, _button):
|
||||
backend = self._con.get_module('PGPLegacy').pgp_backend
|
||||
secret_keys = backend.get_keys(secret=True)
|
||||
dialog = ChooseGPGKeyDialog(secret_keys, self.get_toplevel())
|
||||
dialog.connect('response', self._on_response)
|
||||
|
||||
def _load_key(self):
|
||||
key_data = self._con.get_module('PGPLegacy').get_own_key_data()
|
||||
if key_data is None:
|
||||
self._set_key(None)
|
||||
else:
|
||||
self._set_key((key_data['key_id'], key_data['key_user']))
|
||||
|
||||
def _on_response(self, dialog, response):
|
||||
if response != Gtk.ResponseType.OK:
|
||||
return
|
||||
|
||||
if dialog.selected_key is None:
|
||||
self._con.get_module('PGPLegacy').set_own_key_data(None)
|
||||
self._set_key(None)
|
||||
else:
|
||||
self._con.get_module('PGPLegacy').set_own_key_data(
|
||||
dialog.selected_key)
|
||||
self._set_key(dialog.selected_key)
|
||||
|
||||
def _set_key(self, key_data):
|
||||
if key_data is None:
|
||||
self._label.set_text(_('No key assigned'))
|
||||
else:
|
||||
key_id, key_user = key_data
|
||||
self._label.set_text('%s %s' % (key_id, key_user))
|
||||
39
pgp/gtk/config.ui
Normal file
39
pgp/gtk/config.ui
Normal file
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.22.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.20"/>
|
||||
<object class="GtkBox" id="config_box">
|
||||
<property name="width_request">500</property>
|
||||
<property name="height_request">400</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">12</property>
|
||||
<child>
|
||||
<object class="GtkStackSidebar" id="sidebar">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stack">stack</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkStack" id="stack">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="transition_type">crossfade</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
154
pgp/gtk/key.py
Normal file
154
pgp/gtk/key.py
Normal file
@@ -0,0 +1,154 @@
|
||||
# Copyright (C) 2019 Philipp Hörist <philipp AT hoerist.com>
|
||||
#
|
||||
# This file is part of the PGP Gajim Plugin.
|
||||
#
|
||||
# PGP Gajim Plugin is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published
|
||||
# by the Free Software Foundation; version 3 only.
|
||||
#
|
||||
# PGP Gajim Plugin is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with PGP Gajim Plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
from gajim.common import app
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
from gajim.plugins.helpers import get_builder
|
||||
|
||||
|
||||
class KeyDialog(Gtk.Dialog):
|
||||
def __init__(self, plugin, account, jid, transient):
|
||||
super().__init__(title=_('Assign key for %s') % jid,
|
||||
destroy_with_parent=True)
|
||||
|
||||
self.set_transient_for(transient)
|
||||
self.set_resizable(True)
|
||||
self.set_default_size(500, 300)
|
||||
|
||||
self._plugin = plugin
|
||||
self._jid = jid
|
||||
self._con = app.connections[account]
|
||||
|
||||
self._label = Gtk.Label()
|
||||
|
||||
self._assign_button = Gtk.Button(label='assign')
|
||||
self._assign_button.connect('clicked', self._choose_key)
|
||||
|
||||
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
box.add(self._label)
|
||||
box.add(self._assign_button)
|
||||
|
||||
area = self.get_content_area()
|
||||
area.pack_start(box, True, True, 0)
|
||||
|
||||
self._load_key()
|
||||
self.show_all()
|
||||
|
||||
def _choose_key(self, *args):
|
||||
backend = self._con.get_module('PGPLegacy').pgp_backend
|
||||
dialog = ChooseGPGKeyDialog(backend.get_keys(), self)
|
||||
dialog.connect('response', self._on_response)
|
||||
|
||||
def _load_key(self):
|
||||
key_data = self._con.get_module('PGPLegacy').get_contact_key_data(
|
||||
self._jid)
|
||||
if key_data is None:
|
||||
self._set_key(None)
|
||||
else:
|
||||
self._set_key(key_data.values())
|
||||
|
||||
def _on_response(self, dialog, response):
|
||||
if response != Gtk.ResponseType.OK:
|
||||
return
|
||||
|
||||
if dialog.selected_key is None:
|
||||
self._con.get_module('PGPLegacy').set_contact_key_data(
|
||||
self._jid, None)
|
||||
self._set_key(None)
|
||||
else:
|
||||
self._con.get_module('PGPLegacy').set_contact_key_data(
|
||||
self._jid, dialog.selected_key)
|
||||
self._set_key(dialog.selected_key)
|
||||
|
||||
def _set_key(self, key_data):
|
||||
if key_data is None:
|
||||
self._label.set_text(_('No key assigned'))
|
||||
else:
|
||||
key_id, key_user = key_data
|
||||
self._label.set_text('%s %s' % (key_id, key_user))
|
||||
|
||||
|
||||
class ChooseGPGKeyDialog(Gtk.Dialog):
|
||||
def __init__(self, secret_keys, transient_for):
|
||||
Gtk.Dialog.__init__(self,
|
||||
title=_('Assign PGP Key'),
|
||||
transient_for=transient_for)
|
||||
|
||||
secret_keys[_('None')] = _('None')
|
||||
|
||||
self.set_position(Gtk.WindowPosition.CENTER_ON_PARENT)
|
||||
self.set_resizable(True)
|
||||
self.set_default_size(500, 300)
|
||||
|
||||
self.add_button(_('OK'), Gtk.ResponseType.OK)
|
||||
self.add_button(_('Cancel'), Gtk.ResponseType.CANCEL)
|
||||
|
||||
self._selected_key = None
|
||||
|
||||
ui_path = Path(__file__).parent
|
||||
self._ui = get_builder(ui_path.resolve() / 'choose_key.ui')
|
||||
|
||||
self._ui.keys_treeview = self._ui.keys_treeview
|
||||
|
||||
model = self._ui.keys_treeview.get_model()
|
||||
model.set_sort_func(1, self._sort)
|
||||
|
||||
model = self._ui.keys_treeview.get_model()
|
||||
for key_id in secret_keys.keys():
|
||||
model.append((key_id, secret_keys[key_id]))
|
||||
|
||||
self.get_content_area().add(self._ui.box)
|
||||
|
||||
self._ui.connect_signals(self)
|
||||
|
||||
self.connect_after('response', self._on_response)
|
||||
|
||||
self.show_all()
|
||||
|
||||
@property
|
||||
def selected_key(self):
|
||||
return self._selected_key
|
||||
|
||||
@staticmethod
|
||||
def _sort(model, iter1, iter2, _data):
|
||||
value1 = model[iter1][1]
|
||||
value2 = model[iter2][1]
|
||||
if value1 == _('None'):
|
||||
return -1
|
||||
if value2 == _('None'):
|
||||
return 1
|
||||
if value1 < value2:
|
||||
return -1
|
||||
return 1
|
||||
|
||||
def _on_response(self, _dialog, _response):
|
||||
self.destroy()
|
||||
|
||||
def _on_row_changed(self, treeview):
|
||||
selection = treeview.get_selection()
|
||||
model, iter_ = selection.get_selected()
|
||||
if iter_ is None:
|
||||
self._selected_key = None
|
||||
else:
|
||||
key_id, key_user = model[iter_][0], model[iter_][1]
|
||||
if key_id == _('None'):
|
||||
self._selected_key = None
|
||||
else:
|
||||
self._selected_key = key_id, key_user
|
||||
Reference in New Issue
Block a user