diff options
author | fiaxh <git@lightrise.org> | 2019-10-22 01:23:43 +0200 |
---|---|---|
committer | fiaxh <git@lightrise.org> | 2019-10-22 01:23:43 +0200 |
commit | 26e970a4d4e835cc879fc8cc5a0604fb50e67ce3 (patch) | |
tree | 1e57bf88cb3f28c04b7d855adef0d2c1002ff02b /plugins/omemo/src/ui/contact_details_dialog.vala | |
parent | c032ab00ecc9d2b0c5d2fdbc5bd622a5406f691c (diff) | |
download | dino-26e970a4d4e835cc879fc8cc5a0604fb50e67ce3.tar.gz dino-26e970a4d4e835cc879fc8cc5a0604fb50e67ce3.zip |
Colapse inactive keys in OMEMO keys dialog
Diffstat (limited to 'plugins/omemo/src/ui/contact_details_dialog.vala')
-rw-r--r-- | plugins/omemo/src/ui/contact_details_dialog.vala | 178 |
1 files changed, 98 insertions, 80 deletions
diff --git a/plugins/omemo/src/ui/contact_details_dialog.vala b/plugins/omemo/src/ui/contact_details_dialog.vala index 463b5cd7..ad43f00e 100644 --- a/plugins/omemo/src/ui/contact_details_dialog.vala +++ b/plugins/omemo/src/ui/contact_details_dialog.vala @@ -28,6 +28,7 @@ public class ContactDetailsDialog : Gtk.Dialog { [GtkChild] private ListBox new_keys_listbox; [GtkChild] private Box keys_container; [GtkChild] private ListBox keys_listbox; + [GtkChild] private ListBox unused_keys_listbox; [GtkChild] private Switch auto_accept_switch; [GtkChild] private Button copy_button; [GtkChild] private Button show_qrcode_button; @@ -54,11 +55,17 @@ public class ContactDetailsDialog : Gtk.Dialog { (get_header_bar() as HeaderBar).set_subtitle(jid.bare_jid.to_string()); } + keys_listbox.row_activated.connect(on_key_entry_clicked); + unused_keys_listbox.row_activated.connect(on_key_entry_clicked); + auto_accept_switch.state_set.connect(on_auto_accept_toggled); + int identity_id = plugin.db.identity.get_id(account.id); if (identity_id < 0) return; - // Dialog opened from the account settings menu - // Show the fingerprint for this device separately with buttons for a qrcode and to copy + auto_accept_switch.set_active(plugin.db.trust.get_blind_trust(identity_id, jid.bare_jid.to_string())); + + // Dialog opened from the account settings menu + // Show the fingerprint for this device separately with buttons for a qrcode and to copy if(jid.equals(account.bare_jid)) { own = true; own_id = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.device_id]; @@ -107,24 +114,6 @@ public class ContactDetailsDialog : Gtk.Dialog { } add_fingerprint(device, (TrustLevel) device[plugin.db.identity_meta.trust_level]); } - - auto_accept_switch.set_active(plugin.db.trust.get_blind_trust(identity_id, jid.bare_jid.to_string())); - - auto_accept_switch.state_set.connect((active) => { - plugin.trust_manager.set_blind_trust(account, jid, active); - - if (active) { - new_keys_container.visible = false; - - foreach (Row device in plugin.db.identity_meta.get_new_devices(identity_id, jid.to_string())) { - plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], TrustLevel.TRUSTED); - add_fingerprint(device, TrustLevel.TRUSTED); - } - } - - return false; - }); - } private void header_function(ListBoxRow row, ListBoxRow? before) { @@ -133,74 +122,50 @@ public class ContactDetailsDialog : Gtk.Dialog { } } - private void set_row(int trust, bool now_active, Image img, Label status_lbl, Label lbl, ListBoxRow lbr){ - switch(trust) { - case TrustLevel.TRUSTED: - img.icon_name = "emblem-ok-symbolic"; - status_lbl.set_markup("<span color='#1A63D9'>%s</span>".printf(_("Accepted"))); - lbl.get_style_context().remove_class("dim-label"); - break; - case TrustLevel.UNTRUSTED: - img.icon_name = "action-unavailable-symbolic"; - status_lbl.set_markup("<span color='#D91900'>%s</span>".printf(_("Rejected"))); - lbl.get_style_context().add_class("dim-label"); - break; - case TrustLevel.VERIFIED: - img.icon_name = "security-high-symbolic"; - status_lbl.set_markup("<span color='#1A63D9'>%s</span>".printf(_("Verified"))); - lbl.get_style_context().remove_class("dim-label"); - break; - } - - if (!now_active) { - img.icon_name = "appointment-missed-symbolic"; - status_lbl.set_markup("<span color='#8b8e8f'>%s</span>".printf(_("Unused"))); - lbr.activatable = false; + private void add_fingerprint(Row device, TrustLevel trust) { + string key_base64 = device[plugin.db.identity_meta.identity_key_public_base64]; + bool key_active = device[plugin.db.identity_meta.now_active]; + FingerprintRow fingerprint_row = new FingerprintRow(device, key_base64, trust, key_active) { visible = true, activatable = true, hexpand = true }; + + if (device[plugin.db.identity_meta.now_active]) { + keys_container.visible = true; + keys_listbox.add(fingerprint_row); + } else { + unused_keys_listbox.add(fingerprint_row); } } - private void add_fingerprint(Row device, TrustLevel trust) { - keys_container.visible = true; - - ListBoxRow lbr = new ListBoxRow() { visible = true, activatable = true, hexpand = true }; - Box box = new Box(Gtk.Orientation.HORIZONTAL, 40) { visible = true, margin_start = 20, margin_end = 20, margin_top = 14, margin_bottom = 14, hexpand = true }; - - Box status_box = new Box(Gtk.Orientation.HORIZONTAL, 5) { visible = true, hexpand = true }; - Label status_lbl = new Label(null) { visible = true, hexpand = true, xalign = 0 }; - - Image img = new Image() { visible = true, halign = Align.END, icon_size = IconSize.BUTTON }; - - string res = fingerprint_markup(fingerprint_from_base64(device[plugin.db.identity_meta.identity_key_public_base64])); - Label lbl = new Label(res) - { use_markup=true, justify=Justification.RIGHT, visible=true, halign = Align.START, valign = Align.CENTER, hexpand = false }; - - set_row(trust, device[plugin.db.identity_meta.now_active], img, status_lbl, lbl, lbr); + private void on_key_entry_clicked(ListBoxRow widget) { + FingerprintRow? fingerprint_row = widget as FingerprintRow; + if (fingerprint_row == null) return; + + Row updated_device = plugin.db.identity_meta.get_device(fingerprint_row.row[plugin.db.identity_meta.identity_id], fingerprint_row.row[plugin.db.identity_meta.address_name], fingerprint_row.row[plugin.db.identity_meta.device_id]); + ManageKeyDialog manage_dialog = new ManageKeyDialog(updated_device, plugin.db); + manage_dialog.set_transient_for((Gtk.Window) get_toplevel()); + manage_dialog.present(); + manage_dialog.response.connect((response) => { + fingerprint_row.update_trust_state(response, fingerprint_row.row[plugin.db.identity_meta.now_active]); + update_stored_trust(response, fingerprint_row.row); + }); + } - box.add(lbl); - box.add(status_box); + private bool on_auto_accept_toggled(bool active) { + plugin.trust_manager.set_blind_trust(account, jid, active); - status_box.add(status_lbl); - status_box.add(img); + if (active) { + int identity_id = plugin.db.identity.get_id(account.id); + if (identity_id < 0) return false; - lbr.add(box); - keys_listbox.add(lbr); - - //Row clicked - pull the most up to date device info from the database and show the manage window - keys_listbox.row_activated.connect((row) => { - if(row == lbr) { - Row updated_device = plugin.db.identity_meta.get_device(device[plugin.db.identity_meta.identity_id], device[plugin.db.identity_meta.address_name], device[plugin.db.identity_meta.device_id]); - ManageKeyDialog manage_dialog = new ManageKeyDialog(updated_device, plugin.db); - manage_dialog.set_transient_for((Gtk.Window) get_toplevel()); - manage_dialog.present(); - manage_dialog.response.connect((response) => { - set_row(response, device[plugin.db.identity_meta.now_active], img, status_lbl, lbl, lbr); - update_device(response, device); - }); + new_keys_container.visible = false; + foreach (Row device in plugin.db.identity_meta.get_new_devices(identity_id, jid.to_string())) { + plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], TrustLevel.TRUSTED); + add_fingerprint(device, TrustLevel.TRUSTED); } - }); + } + return false; } - private void update_device(int response, Row device){ + private void update_stored_trust(int response, Row device) { switch (response) { case TrustLevel.TRUSTED: plugin.trust_manager.set_device_trust(account, jid, device[plugin.db.identity_meta.device_id], TrustLevel.TRUSTED); @@ -216,7 +181,7 @@ public class ContactDetailsDialog : Gtk.Dialog { } } - private void add_new_fingerprint(Row device){ + private void add_new_fingerprint(Row device) { new_keys_container.visible = true; ListBoxRow lbr = new ListBoxRow() { visible = true, activatable = false, hexpand = true }; @@ -264,4 +229,57 @@ public class ContactDetailsDialog : Gtk.Dialog { } } +public class FingerprintRow : ListBoxRow { + + private Image trust_image = new Image() { visible = true, halign = Align.END, icon_size = IconSize.BUTTON }; + private Label fingerprint_label = new Label("") { use_markup=true, justify=Justification.RIGHT, visible=true, halign = Align.START, valign = Align.CENTER, hexpand = false }; + private Label trust_label = new Label(null) { visible = true, hexpand = true, xalign = 0 }; + + public Row row; + + construct { + Box box = new Box(Gtk.Orientation.HORIZONTAL, 40) { visible = true, margin_start = 20, margin_end = 20, margin_top = 14, margin_bottom = 14, hexpand = true }; + Box status_box = new Box(Gtk.Orientation.HORIZONTAL, 5) { visible = true, hexpand = true }; + + box.add(fingerprint_label); + box.add(status_box); + + status_box.add(trust_label); + status_box.add(trust_image); + + this.add(box); + } + + public FingerprintRow(Row row, string key_base64, int trust, bool now_active) { + this.row = row; + fingerprint_label.label = fingerprint_markup(fingerprint_from_base64(key_base64)); + update_trust_state(trust, now_active); + } + + public void update_trust_state(int trust, bool now_active) { + switch(trust) { + case TrustLevel.TRUSTED: + trust_image.icon_name = "emblem-ok-symbolic"; + trust_label.set_markup("<span color='#1A63D9'>%s</span>".printf(_("Accepted"))); + fingerprint_label.get_style_context().remove_class("dim-label"); + break; + case TrustLevel.UNTRUSTED: + trust_image.icon_name = "action-unavailable-symbolic"; + trust_label.set_markup("<span color='#D91900'>%s</span>".printf(_("Rejected"))); + fingerprint_label.get_style_context().add_class("dim-label"); + break; + case TrustLevel.VERIFIED: + trust_image.icon_name = "security-high-symbolic"; + trust_label.set_markup("<span color='#1A63D9'>%s</span>".printf(_("Verified"))); + fingerprint_label.get_style_context().remove_class("dim-label"); + break; + } + + if (!now_active) { + trust_image.icon_name = "appointment-missed-symbolic"; + trust_label.set_markup("<span color='#8b8e8f'>%s</span>".printf(_("Unused"))); + } + } +} + } |