aboutsummaryrefslogtreecommitdiff
path: root/plugins/openpgp
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2024-12-24 16:02:13 +0100
committerfiaxh <git@lightrise.org>2025-01-12 19:35:58 +0100
commit5ee322cbd987d36497522b82b876659e1d19da43 (patch)
treec22d0bdbf92b30207b64ec74e925af4263ce91fc /plugins/openpgp
parentd78ec0562288fa4ed7d414d2269c00b7b8c2c588 (diff)
downloaddino-5ee322cbd987d36497522b82b876659e1d19da43.tar.gz
dino-5ee322cbd987d36497522b82b876659e1d19da43.zip
Contact details dialog: Add encryption tab
Diffstat (limited to 'plugins/openpgp')
-rw-r--r--plugins/openpgp/src/contact_details_provider.vala49
-rw-r--r--plugins/openpgp/src/util.vala37
2 files changed, 36 insertions, 50 deletions
diff --git a/plugins/openpgp/src/contact_details_provider.vala b/plugins/openpgp/src/contact_details_provider.vala
index 9ec84c21..f2fa8f06 100644
--- a/plugins/openpgp/src/contact_details_provider.vala
+++ b/plugins/openpgp/src/contact_details_provider.vala
@@ -6,6 +6,7 @@ namespace Dino.Plugins.OpenPgp {
public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object {
public string id { get { return "pgp_info"; } }
+ public string tab { get { return "encryption"; } }
private StreamInteractor stream_interactor;
@@ -13,23 +14,39 @@ public class ContactDetailsProvider : Plugins.ContactDetailsProvider, Object {
this.stream_interactor = stream_interactor;
}
- public void populate(Conversation conversation, Plugins.ContactDetails contact_details, WidgetType type) {
- if (conversation.type_ == Conversation.Type.CHAT && type == WidgetType.GTK4) {
- string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart);
- if (key_id != null) {
- Label label = new Label("") { use_markup=true, justify=Justification.RIGHT, selectable=true };
- Gee.List<GPG.Key>? keys = null;
- try {
- keys = GPGHelper.get_keylist(key_id);
- } catch (Error e) { }
- if (keys != null && keys.size > 0) {
- label.label = markup_colorize_id(keys[0].fpr, true);
- } else {
- label.label = _("Key not in keychain") + "\n" + markup_colorize_id(key_id, false);
- }
- contact_details.add(_("Encryption"), "OpenPGP", "", label);
- }
+ public void populate(Conversation conversation, Plugins.ContactDetails contact_details, WidgetType type) { }
+
+ public Object? get_widget(Conversation conversation) {
+ var preferences_group = new Adw.PreferencesGroup() { title="OpenPGP" };
+
+ if (conversation.type_ != Conversation.Type.CHAT) return null;
+
+ string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart);
+ if (key_id == null) return null;
+
+ Gee.List<GPG.Key>? keys = null;
+ try {
+ keys = GPGHelper.get_keylist(key_id);
+ } catch (Error e) { }
+
+ var str = "";
+ if (keys != null && keys.size > 0) {
+ str = markup_id(keys[0].fpr, true);
+ } else {
+ str = _("Key not in keychain") + "\n" + markup_id(key_id, false);
}
+
+ var view = new Adw.ActionRow() {
+ title = "Fingerprint",
+ subtitle = str,
+#if Adw_1_3
+ subtitle_selectable = true,
+#endif
+ };
+
+ preferences_group.add(view);
+
+ return preferences_group;
}
}
diff --git a/plugins/openpgp/src/util.vala b/plugins/openpgp/src/util.vala
index d40cf6ef..9cba9b2f 100644
--- a/plugins/openpgp/src/util.vala
+++ b/plugins/openpgp/src/util.vala
@@ -5,47 +5,16 @@ using Xmpp.Util;
namespace Dino.Plugins.OpenPgp {
-/* Adapted from OpenKeychain */
-public static string markup_colorize_id(string s, bool is_fingerprint) {
+public static string markup_id(string s, bool is_fingerprint) {
string markup = is_fingerprint ? "" : "0x";
for (int i = 0; i < s.length; i += 4) {
string four_chars = s.substring(i, 4).down();
- int raw = (int) from_hex(four_chars);
- uint8[] bytes = {(uint8) ((raw >> 8) & 0xff - 128), (uint8) (raw & 0xff - 128)};
-
- Checksum checksum = new Checksum(ChecksumType.SHA1);
- checksum.update(bytes, bytes.length);
- uint8[] digest = new uint8[20];
- size_t len = 20;
- checksum.get_digest(digest, ref len);
-
- uint8 r = digest[0];
- uint8 g = digest[1];
- uint8 b = digest[2];
-
- if (r == 0 && g == 0 && b == 0) r = g = b = 1;
-
- double brightness = 0.2126 * r + 0.7152 * g + 0.0722 * b;
-
- if (brightness < 80) {
- double factor = 80.0 / brightness;
- r = uint8.min(255, (uint8) (r * factor));
- g = uint8.min(255, (uint8) (g * factor));
- b = uint8.min(255, (uint8) (b * factor));
-
- } else if (brightness > 180) {
- double factor = 180.0 / brightness;
- r = (uint8) (r * factor);
- g = (uint8) (g * factor);
- b = (uint8) (b * factor);
- }
-
if (i == 4 * 5) markup += "\n";
- markup += @"<span foreground=\"$("#%02x%02x%02x".printf(r, g, b))\">$four_chars</span>";
+ markup += four_chars;
if (is_fingerprint) markup += " ";
}
- return "<span font_family='monospace' font='8'>" + markup + "</span>";
+ return "<span font_family='monospace' font='9'>" + markup + "</span>";
}
}