aboutsummaryrefslogtreecommitdiff
path: root/qml/ComposePane.qml
blob: 6bcdec9b1eae7387425d2749ebeba24d961a5b68 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import DeltaChat 1.0
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQuick.Dialogs 1.3

Pane {
    id: root

    required property DcContext context
    required property var chatId
    required property var chat
    property bool canSend: root.chat && root.chat.canSend
    property bool isContactRequest: root.chat && root.chat.isContactRequest

    function createMessage() {
        let DC_MSG_TEXT = 10;
        var msg = root.context.newMessage(DC_MSG_TEXT);
        msg.setText(messageField.text);
        return msg;
    }

    padding: 0

    FileDialog {
        id: attachFileDialog
        title: "Attach"
        folder: shortcuts.home

        onAccepted: {
            var url = attachFileDialog.fileUrl.toString()
            if (url.startsWith("file://")) {
                var filename = url.substring(7)
                console.log("Attaching " + filename)
            }
        }
    }

    RowLayout {
        width: parent.width

        Button {
            id: attachButton
            visible: root.canSend
            text: qsTr("Attach")

            Layout.alignment: Qt.AlignBottom

            icon.name: "mail-attachment"

            onClicked: attachFileDialog.open()
        }

        TextArea {
            id: messageField

            visible: root.canSend
            Layout.fillWidth: true
            placeholderText: qsTr("Message")
            wrapMode: TextArea.Wrap
            selectByMouse: true
            Component.onCompleted: {
                let draft = root.context.getDraft(chatId);
                if (draft)
                    messageField.text = draft.text;

            }

            Connections {
                function onEditingFinished() {
                    let msg = root.createMessage();
                    root.context.setDraft(chatId, msg);
                }

            }

        }

        Button {
            id: sendButton

            visible: root.canSend
            Layout.alignment: Qt.AlignBottom
            icon.name: "document-send"
            text: qsTr("Send")
            enabled: messageField.length > 0
            onClicked: {
                let msg = root.createMessage();
                root.context.sendMessage(root.chatId, msg);
                messageField.text = "";
                root.context.setDraft(chatId, null);
            }
        }

        Button {
            Layout.alignment: Qt.AlignBottom
            Layout.fillWidth: true
            text: "Accept"
            onClicked: root.context.acceptChat(root.chatId)
            visible: root.isContactRequest
            icon.name: "call-start"
        }

        Button {
            Layout.alignment: Qt.AlignBottom
            Layout.fillWidth: true
            text: "Block"
            onClicked: root.context.acceptChat(root.chatId)
            visible: root.isContactRequest
            icon.name: "call-stop"
        }

    }

}