summary refs log tree commit diff
path: root/resources/qml/EncryptionIndicator.qml
blob: 5338b6bedb2a7631c8ec096776dd89a262c512a0 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick 2.12
import QtQuick.Controls 2.1
import QtQuick.Window 2.15
import im.nheko 1.0

Image {
    id: stateImg

    property bool encrypted: false
    property int trust: Crypto.Unverified
    property string unencryptedIcon: ":/icons/icons/ui/shield-filled-cross.svg"
    property color unencryptedColor: Nheko.theme.error
    property color unencryptedHoverColor: unencryptedColor
    property bool hovered: ma.hovered

    property string sourceUrl: {
        if (!encrypted)
        return "image://colorimage/" + unencryptedIcon + "?";

        switch (trust) {
            case Crypto.Verified:
            return "image://colorimage/:/icons/icons/ui/shield-filled-checkmark.svg?";
            case Crypto.TOFU:
            return "image://colorimage/:/icons/icons/ui/shield-filled.svg?";
            case Crypto.Unverified:
            return "image://colorimage/:/icons/icons/ui/shield-filled-exclamation-mark.svg?";
            default:
            return "image://colorimage/:/icons/icons/ui/shield-filled-cross.svg?";
        }
    }

    width: 16
    height: 16
    sourceSize.height: height
    sourceSize.width: width
    source: {
        if (encrypted) {
            switch (trust) {
            case Crypto.Verified:
                return sourceUrl + Nheko.theme.green;
            case Crypto.TOFU:
                return sourceUrl + Nheko.colors.buttonText;
            default:
                return sourceUrl + Nheko.theme.error;
            }
        } else {
            return sourceUrl + (stateImg.hovered ? unencryptedHoverColor : unencryptedColor);
        }
    }
    ToolTip.visible: stateImg.hovered
    ToolTip.text: {
        if (!encrypted)
            return qsTr("This message is not encrypted!");

        switch (trust) {
        case Crypto.Verified:
            return qsTr("Encrypted by a verified device");
        case Crypto.TOFU:
            return qsTr("Encrypted by an unverified device, but you have trusted that user so far.");
        default:
            return qsTr("Encrypted by an unverified device or the key is from an untrusted source like the key backup.");
        }
    }

    HoverHandler {
        id: ma
    }

}