From a9ea0e9f87e71c60bc570066525d3e3634fbdcc0 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sun, 12 Mar 2017 02:28:23 +0100 Subject: Split OMEMO plug-in into files, various fixes --- plugins/omemo/src/plugin.vala | 138 +++++++----------------------------------- 1 file changed, 21 insertions(+), 117 deletions(-) (limited to 'plugins/omemo/src/plugin.vala') diff --git a/plugins/omemo/src/plugin.vala b/plugins/omemo/src/plugin.vala index a062640b..04e02625 100644 --- a/plugins/omemo/src/plugin.vala +++ b/plugins/omemo/src/plugin.vala @@ -1,130 +1,34 @@ -using Xmpp; +namespace Dino.Plugins.Omemo { -namespace Dino.Omemo { +public class Plugin : RootInterface, Object { + public static Signal.Context context; - public class EncryptionListEntry : Plugins.EncryptionListEntry, Object { - private Plugin plugin; + public Dino.Application app; + public Database db; + public EncryptionListEntry list_entry; + public AccountSettingsEntry settings_entry; - public EncryptionListEntry(Plugin plugin) { - this.plugin = plugin; - } - - public Entities.Encryption encryption { get { - return Entities.Encryption.OMEMO; - }} - - public string name { get { - return "OMEMO"; - }} - - public bool can_encrypt(Entities.Conversation conversation) { - return Manager.get_instance(plugin.app.stream_interaction).con_encrypt(conversation); - } - } - - public class AccountSettingsEntry : Plugins.AccountSettingsEntry { - private Plugin plugin; - - public AccountSettingsEntry(Plugin plugin) { - this.plugin = plugin; - } - - public override string id { get { - return "omemo_identity_key"; - }} - - public override string name { get { - return "OMEMO"; - }} - - public override Plugins.AccountSettingsWidget get_widget() { - return new AccountSettingWidget(plugin); - } - } - - public class AccountSettingWidget : Plugins.AccountSettingsWidget, Gtk.Box { - private Plugin plugin; - private Gtk.Label fingerprint; - private Entities.Account account; - - public AccountSettingWidget(Plugin plugin) { - this.plugin = plugin; - - fingerprint = new Gtk.Label("..."); - fingerprint.xalign = 0; - Gtk.Border border = new Gtk.Button().get_style_context().get_padding(Gtk.StateFlags.NORMAL); - fingerprint.set_padding(border.left + 1, border.top + 1); - fingerprint.visible = true; - pack_start(fingerprint); - - Gtk.Button btn = new Gtk.Button(); - btn.image = new Gtk.Image.from_icon_name("view-list-symbolic", Gtk.IconSize.BUTTON); - btn.relief = Gtk.ReliefStyle.NONE; - btn.visible = true; - btn.valign = Gtk.Align.CENTER; - btn.clicked.connect(() => { activated(); }); - pack_start(btn, false); - } - - public void set_account(Entities.Account account) { - this.account = account; - try { - Qlite.Row? row = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id); - if (row == null) { - fingerprint.set_markup(@"Own fingerprint\nWill be generated on first connect"); - } else { - uint8[] arr = Base64.decode(row[plugin.db.identity.identity_key_public_base64]); - arr = arr[1:arr.length]; - string res = ""; - foreach (uint8 i in arr) { - string s = i.to_string("%x"); - if (s.length == 1) s = "0" + s; - res = res + s; - if ((res.length % 9) == 8) { - if (res.length == 35) { - res += "\n"; - } else { - res += " "; - } - } - } - fingerprint.set_markup(@"Own fingerprint\n$res"); - } - } catch (Qlite.DatabaseError e) { - fingerprint.set_markup(@"Own fingerprint\nDatabase error"); - } - } - - public void deactivate() { - } - } - - public class Plugin : Plugins.RootInterface, Object { - public Dino.Application app; - public Database db; - public EncryptionListEntry list_entry; - public AccountSettingsEntry settings_entry; - - public void registered(Dino.Application app) { + public void registered(Dino.Application app) { + try { + context = new Signal.Context(false); this.app = app; this.db = new Database("omemo.db"); this.list_entry = new EncryptionListEntry(this); this.settings_entry = new AccountSettingsEntry(this); - app.plugin_registry.register_encryption_list_entry(list_entry); - app.plugin_registry.register_account_settings_entry(settings_entry); - app.stream_interaction.module_manager.initialize_account_modules.connect((account, list) => { - list.add(new Module()); + this.app.plugin_registry.register_encryption_list_entry(list_entry); + this.app.plugin_registry.register_account_settings_entry(settings_entry); + this.app.stream_interaction.module_manager.initialize_account_modules.connect((account, list) => { + list.add(new StreamModule()); }); - Manager.start(app.stream_interaction, db); - } - - public void shutdown() { - // Nothing to do + Manager.start(this.app.stream_interaction, db); + } catch (Error e) { + print(@"Error initializing OMEMO: $(e.message)\n"); } } + public void shutdown() { + // Nothing to do + } } -public Type register_plugin(Module module) { - return typeof (Dino.Omemo.Plugin); -} +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf