aboutsummaryrefslogtreecommitdiff
path: root/plugins/omemo/src/account_settings_dialog.vala
blob: eebdfc8a0f8bff3537d473bd43a30fe4244170df (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
54
using Gtk;
using Qlite;
using Dino.Entities;

namespace Dino.Plugins.Omemo {

[GtkTemplate (ui = "/im/dino/omemo/account_settings_dialog.ui")]
public class AccountSettingsDialog : Gtk.Dialog {

    private Plugin plugin;
    private Account account;
    private string fingerprint;

    [GtkChild] private Label own_fingerprint;
    [GtkChild] private ListBox other_list;

    public AccountSettingsDialog(Plugin plugin, Account account) {
        Object(use_header_bar : 1);
        this.plugin = plugin;
        this.account = account;

        string own_b64 = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.identity_key_public_base64];
        fingerprint = fingerprint_from_base64(own_b64);
        own_fingerprint.set_markup(fingerprint_markup(fingerprint));

        int own_id = plugin.db.identity.row_with(plugin.db.identity.account_id, account.id)[plugin.db.identity.device_id];

        int i = 0;
        foreach (Row row in plugin.db.identity_meta.with_address(account.bare_jid.to_string())) {
            if (row[plugin.db.identity_meta.device_id] == own_id) continue;
            if (i == 0) {
                other_list.foreach((widget) => { widget.destroy(); });
            }
            string? other_b64 = row[plugin.db.identity_meta.identity_key_public_base64];
            Label lbl = new Label(other_b64 != null ? fingerprint_markup(fingerprint_from_base64(other_b64)) : _("Unknown device (0x%xd)").printf(row[plugin.db.identity_meta.device_id])) { use_markup = true, visible = true, margin = 8, selectable=true };
            if (row[plugin.db.identity_meta.now_active] && other_b64 != null) {
                other_list.insert(lbl, 0);
            } else {
                lbl.sensitive = false;
                other_list.insert(lbl, i);
            }
            i++;
        }
    }

    [GtkCallback]
    public void copy_button_clicked() {
        Clipboard.get_default(get_display()).set_text(fingerprint, fingerprint.length);
    }


}

}