aboutsummaryrefslogtreecommitdiff
path: root/libdino/src/service
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2017-03-11 22:48:35 +0100
committerMarvin W <git@larma.de>2017-03-11 22:50:28 +0100
commit0ea4ac7e20674e3e6a8d1b3d4b53702dace72907 (patch)
tree09a4f713b66d45a1ecdb9a826611899fad35105a /libdino/src/service
parent47ab19b3a06b6f96965482e4a33d443c2276c1d8 (diff)
downloaddino-0ea4ac7e20674e3e6a8d1b3d4b53702dace72907.tar.gz
dino-0ea4ac7e20674e3e6a8d1b3d4b53702dace72907.zip
Plug-In API: allow adding custom entries to account settings
Also make OpenPGP code use this API
Diffstat (limited to 'libdino/src/service')
-rw-r--r--libdino/src/service/pgp_manager.vala80
1 files changed, 79 insertions, 1 deletions
diff --git a/libdino/src/service/pgp_manager.vala b/libdino/src/service/pgp_manager.vala
index 76f70b84..a91feac6 100644
--- a/libdino/src/service/pgp_manager.vala
+++ b/libdino/src/service/pgp_manager.vala
@@ -17,7 +17,85 @@ namespace Dino {
public static void start(StreamInteractor stream_interactor, Database db) {
PgpManager m = new PgpManager(stream_interactor, db);
stream_interactor.add_module(m);
- (GLib.Application.get_default() as Application).plugin_registry.register_encryption_list_entry(new EncryptionListEntry(m));
+
+ Plugins.Registry plugin_registry = (GLib.Application.get_default() as Application).plugin_registry;
+ plugin_registry.register_encryption_list_entry(new EncryptionListEntry(m));
+ plugin_registry.register_account_settings_entry(new AccountSettingsEntry(m));
+ }
+
+ private class AccountSettingsEntry : Plugins.AccountSettingsEntry {
+ private PgpManager pgp_manager;
+
+ public AccountSettingsEntry(PgpManager pgp_manager) {
+ this.pgp_manager = pgp_manager;
+ }
+
+ public override string id { get {
+ return "pgp_key_picker";
+ }}
+
+ public override string name { get {
+ return "OpenPGP";
+ }}
+
+ public override Plugins.AccountSettingsWidget get_widget() {
+ return new AccountSettingsWidget();
+ }
+ }
+
+ [GtkTemplate (ui = "/org/dino-im/manage_accounts/pgp_stack.ui")]
+ private class AccountSettingsWidget : Gtk.Stack, Plugins.AccountSettingsWidget {
+ [GtkChild] private Gtk.Label pgp_label;
+ [GtkChild] private Gtk.Button pgp_button;
+ [GtkChild] private Gtk.ComboBox pgp_combobox;
+
+ private Gtk.ListStore list_store = new Gtk.ListStore(2, typeof(string), typeof(string?));
+
+ public AccountSettingsWidget() {
+ Gtk.CellRendererText renderer = new Gtk.CellRendererText();
+ renderer.set_padding(0, 0);
+ pgp_combobox.pack_start(renderer, true);
+ pgp_combobox.add_attribute(renderer, "markup", 0);
+ pgp_button.clicked.connect(() => { activated(); this.set_visible_child_name("entry"); pgp_combobox.popup(); });
+ }
+
+ public void deactivate() {
+ this.set_visible_child_name("label");
+ }
+
+ private void key_changed() {
+ Gtk.TreeIter selected;
+ pgp_combobox.get_active_iter(out selected);
+ Value text;
+ list_store.get_value(selected, 0, out text);
+ pgp_label.set_markup((string) text);
+ deactivate();
+ }
+
+ public void set_account(Account account) {
+ populate_pgp_combobox(account);
+ }
+
+ private void populate_pgp_combobox(Account account) {
+ pgp_combobox.changed.disconnect(key_changed);
+
+ Gtk.TreeIter iter;
+ pgp_combobox.set_model(list_store);
+
+ list_store.clear();
+ list_store.append(out iter);
+ pgp_label.set_markup("Disabled\n<span font='9'>Select key</span>");
+ list_store.set(iter, 0, "Disabled\n<span font='9'>Select key</span>", 1, null);
+ Gee.List<GPG.Key> list = GPGHelper.get_keylist(null, true);
+ foreach (GPG.Key key in list) {
+ list_store.append(out iter);
+ list_store.set(iter, 0, @"<span font='11'>$(Markup.escape_text(key.uids[0].uid))</span>\n<span font='9'>0x$(Markup.escape_text(key.fpr[0:16]))</span>");
+ list_store.set(iter, 1, key.fpr);
+ }
+
+ pgp_combobox.set_active(0);
+ pgp_combobox.changed.connect(key_changed);
+ }
}
private class EncryptionListEntry : Plugins.EncryptionListEntry, Object {