aboutsummaryrefslogtreecommitdiff
path: root/plugins/openpgp/src/contact_details_provider.vala
blob: f2fa8f06ec3e6cbcafad62244aff97fa68669383 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Gtk;

using Dino.Entities;

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;

    public ContactDetailsProvider(StreamInteractor stream_interactor) {
        this.stream_interactor = stream_interactor;
    }

    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;
    }
}

}