PageSendMessage.qml 39.9 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 13 14
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21 22 23 24 25 26 27 28
 *
 * In addition, as a special exception, the copyright holders give
 * permission to link the code of portions of this program with the
 * OpenSSL library under certain conditions as described in each
 * individual source file, and distribute linked combinations including
 * the two.
 */

import QtQuick 2.7
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.0
import cz.nic.mobileDatovka 1.0
Martin Straka's avatar
Martin Straka committed
29
import cz.nic.mobileDatovka.files 1.0
30 31 32 33 34 35 36 37 38
import cz.nic.mobileDatovka.messages 1.0
import cz.nic.mobileDatovka.models 1.0

Item {
    id: pageSendMessage

    /* These properties must be set by caller. */
    property var pageView
    property var statusBar
39
    property string acntName
40 41 42 43 44
    property string userName
    property string msgId
    property int msgType
    property string action: "new"

45 46 47 48 49
    /*
     * These properties are constants and specifies some attachment size limits.
     * Do not change these! See ISDS documentation about more message limit info.
     */
    property int max_ATTACHMENT_FILES: 900
50
    property int max_ATTACHMENT_SIZE_BYTES: 20971520 // = 20 * 1024 * 1024.
51
    property int max_ATTACHMENT_SIZE_MB: 20
52
    property int max_OVM_ATTACHMENT_SIZE_BYTES: 52428800 // = 50 * 1024 * 1024.
53 54
    property int max_OVM_ATTACHMENT_SIZE_MB: 50

Martin Straka's avatar
Martin Straka committed
55 56
    property string text_COLOR_RED: "#ff0000"

57 58
    property bool iOS: false

59 60 61
    /* This property holds total attachment size in bytes */
    property int totalAttachmentSizeBytes: 0

62 63
    /* This property defines mandate textinput width. */
    property int mandateFieldLenght : defaultTextFont.font.pointSize * 4
Martin Straka's avatar
Martin Straka committed
64 65

    /* This property holds message type for sending. */
Martin Straka's avatar
Martin Straka committed
66
    property string dmType: ""
67 68 69 70 71 72

    /* Return file name from file path */
    function getFileNameFromPath(filePath) {
        return filePath.replace(/^.*[\\\/]/, '')
    }

73 74
    /* Check attachment number ans size. */
    function attachmentSizeOk() {
75 76 77 78 79 80 81 82
        attachmentsSizeLabel.color = datovkaPalette.text
        var attachmentNumber = sendMsgAttachmentModel.rowCount()
        if (attachmentNumber === 0) {
            attachmentsSizeLabel.text = qsTr("Total size of attachments is %1 B.").arg(0)
            return false;
        }
        if (attachmentNumber >= max_ATTACHMENT_FILES) {
            attachmentsSizeLabel.text = qsTr("The permitted number of (%1) attachments has been exceeded.").arg(max_ATTACHMENT_FILES)
Martin Straka's avatar
Martin Straka committed
83
            attachmentsSizeLabel.color = text_COLOR_RED
84 85 86 87
            return false
        }
        if (totalAttachmentSizeBytes >= max_OVM_ATTACHMENT_SIZE_BYTES) {
            attachmentsSizeLabel.text = qsTr("Total size of attachments exceeds %1 MB.").arg(max_OVM_ATTACHMENT_SIZE_MB)
Martin Straka's avatar
Martin Straka committed
88
            attachmentsSizeLabel.color = text_COLOR_RED
89 90 91 92
            return false
        }
        if (totalAttachmentSizeBytes >= max_ATTACHMENT_SIZE_BYTES) {
            attachmentsSizeLabel.text = qsTr("Total size of attachments exceeds %1 MB. Most of the data boxes cannot receive messages larger than %1 MB. However, some OVM data boxes can receive message up to %2 MB.").arg(max_ATTACHMENT_SIZE_MB).arg(max_OVM_ATTACHMENT_SIZE_MB)
Martin Straka's avatar
Martin Straka committed
93
            attachmentsSizeLabel.color = text_COLOR_RED
94 95 96
            return true
        }
        if (totalAttachmentSizeBytes >= 1024) {
97
            attachmentsSizeLabel.text = qsTr("Total size of attachments is ~%1 kB.").arg(Math.round(totalAttachmentSizeBytes/1024))
98 99 100 101 102 103
        } else {
            attachmentsSizeLabel.text = qsTr("Total size of attachments is %1 B.").arg(totalAttachmentSizeBytes)
        }
        return true
    }

Martin Straka's avatar
Martin Straka committed
104
    /* Set mandate fields in QML */
105 106 107 108 109 110
    function setMandate(isdsEnvelope) {
        dmLegalTitleLaw.text = isdsEnvelope.dmLegalTitleLawStr
        dmLegalTitleYear.text = isdsEnvelope.dmLegalTitleYearStr
        dmLegalTitleSect.text = isdsEnvelope.dmLegalTitleSect
        dmLegalTitlePar.text = isdsEnvelope.dmLegalTitlePar
        dmLegalTitlePoint.text = isdsEnvelope.dmLegalTitlePoint
111 112
    }

113 114
    /* Set reply message data and add recipient to model */
    function setReplyData(userName, msgId) {
115
        headerBar.title = qsTr("Reply %1").arg(msgId)
116
        // get some message envelope data and add recipient to recipient model
117 118
        var isdsEnvelope = messages.getMsgEnvelopeDataAndSetRecipient(userName, msgId, recipBoxModel)
        dmAnnotation.text = "Re: " + isdsEnvelope.dmAnnotation
Martin Straka's avatar
Martin Straka committed
119
        // swap sender ref and ident data to recipient (reply)
120 121 122 123 124
        dmSenderRefNumber.text = isdsEnvelope.dmRecipientRefNumber
        dmSenderIdent.text = isdsEnvelope.dmRecipientIdent
        dmRecipientRefNumber.text = isdsEnvelope.dmSenderRefNumber
        dmRecipientIdent.text = isdsEnvelope.dmSenderIdent
        if (isdsEnvelope.dmType === "I") {
Martin Straka's avatar
Martin Straka committed
125 126 127 128 129 130
            replyPDZ.visible = true
            dmType = "O"
        } else {
            replyPDZ.visible = false
            dmType = ""
        }
131
        setMandate(isdsEnvelope)
Martin Straka's avatar
Martin Straka committed
132 133
    }

134 135
    /* Set message envelope data and files to attachment model*/
    function setTemplateData(userName, msgId) {
136
        headerBar.title = qsTr("Forward %1").arg(msgId)
Martin Straka's avatar
Martin Straka committed
137
        // get some message envelope data, recipient model must be null (no recipient)
138 139 140 141 142 143 144
        var isdsEnvelope = messages.getMsgEnvelopeDataAndSetRecipient(userName, msgId, null)
        dmAnnotation.text = isdsEnvelope.dmAnnotation
        dmSenderRefNumber.text = isdsEnvelope.dmSenderRefNumber
        dmSenderIdent.text = isdsEnvelope.dmSenderIdent
        dmRecipientRefNumber.text = isdsEnvelope.dmRecipientRefNumber
        dmRecipientIdent.text = isdsEnvelope.dmRecipientIdent
        setMandate(isdsEnvelope)
145
        sendMsgAttachmentModel.setFromDb(userName, msgId)
146
        totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
147
        attachmentSizeOk()
148 149
    }

Martin Straka's avatar
Martin Straka committed
150 151
    /* Set message forward data and add ZFO file to model */
    function setForwardZfoData(userName, msgId) {
152
        headerBar.title = qsTr("Forward ZFO %1").arg(msgId)
153 154
        var isdsEnvelope = messages.getMsgEnvelopeDataAndSetRecipient(userName, msgId, null)
        dmAnnotation.text = "Fwd: " + isdsEnvelope.dmAnnotation
Martin Straka's avatar
Martin Straka committed
155 156 157 158
        var fileName = (msgType == MessageType.TYPE_SENT) ? "ODZ_" + msgId + ".zfo" : "DDZ_" + msgId + ".zfo"
        var zfoSize = zfo.getZfoSizeFromDb(userName, msgId)
        // Zfo file must exist in the local database so zfoSize must be > 0
        if (zfoSize > 0) {
159
            sendMsgAttachmentModel.appendFileFromPath(FileIdType.DB_ZFO_ID, fileName, "", zfoSize)
160
            totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
Martin Straka's avatar
Martin Straka committed
161 162 163 164 165 166 167
        } else {
            mainPanel.visible = false
            errorText.text = qsTr("ZFO file of message %1 is not available. Download complete message to get it before forwarding.").arg(msgId)
            errorText.visible = true
        }
    }

168 169
    /* Append one file into send model */
    function appendFileToSendModel(filePath) {
170 171
            var isInFiletList = false
            for (var i = 0; i < sendMsgAttachmentModel.rowCount(); i++) {
172
                if (sendMsgAttachmentModel.filePathFromRow(i) === filePath) {
173 174 175 176 177
                    isInFiletList = true
                    break
                }
            }
            if (!isInFiletList) {
178 179
                var fileName = getFileNameFromPath(filePath)
                var fileSizeBytes = files.getAttachmentSizeInBytes(filePath)
180
                sendMsgAttachmentModel.appendFileFromPath(FileIdType.NO_FILE_ID,
181
                    fileName, filePath, fileSizeBytes)
182 183
                totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
            }
184 185 186 187 188 189 190
    }

    /* Append file list into send model */
    function appendFilesToSendModel(pathListModel) {
        var listLength = pathListModel.count
        for (var j = 0; j < listLength; ++j) {
            appendFileToSendModel(pathListModel.get(j).path)
191 192 193 194
        }
        pathListModel.clear()
    }

195
    Component.onCompleted: {
196
        iOS = files.isIos()
Martin Straka's avatar
Martin Straka committed
197 198 199 200
        actionButton.enabled = false
        initPDZ.visible = false
        initPDZ.checked = false
        replyPDZ.visible = false
201
        replyPDZ.checked = false
Martin Straka's avatar
Martin Straka committed
202 203 204
        var boxEffectiveOVM = accounts.boxEffectiveOVM(userName)
        dmOVM.visible = boxEffectiveOVM
        dmAllowSubstDelivery.visible = boxEffectiveOVM
205
        if (action === "new") {
Martin Straka's avatar
Martin Straka committed
206
            initPDZ.visible = !boxEffectiveOVM
207
            headerBar.title = qsTr("New message")
208 209
        } else if (action === "reply") {
            setReplyData(userName, msgId)
210
        } else if (action === "template") {
Martin Straka's avatar
Martin Straka committed
211
            initPDZ.visible = !boxEffectiveOVM
212
            setTemplateData(userName, msgId)
Martin Straka's avatar
Martin Straka committed
213
        } else if (action == "fwdzfo") {
Martin Straka's avatar
Martin Straka committed
214
            initPDZ.visible = !boxEffectiveOVM
Martin Straka's avatar
Martin Straka committed
215
            setForwardZfoData(userName, msgId)
216 217 218
        }
    }

219
    Component.onDestruction: {
220
       if (iOS) {
Martin Straka's avatar
Martin Straka committed
221
            iOSHelper.clearSendDir()
222
       }
223 224 225
       statusBar.visible = false
    }

226
    /* File dialog for choose of files from the storage */
227 228
    FileDialogue {
        id: fileDialogue
229
        multiSelect: true
230
        onFinished: appendFilesToSendModel(pathListModel)
231 232 233
    }

    /* Holds send message recipent list model */
234
    DataboxListModel {
235
        id: recipBoxModel
236 237 238 239 240
        Component.onCompleted: {
        }
    }

    /* Holds send message attachment list model */
Martin Straka's avatar
Martin Straka committed
241
    FileListModel {
242 243 244 245 246 247 248 249
        id: sendMsgAttachmentModel
        Component.onCompleted: {
        }
    }

    PageHeader {
        id: headerBar
        title: qsTr("Create message")
250 251
        onBackClicked: {
            pageView.pop(StackView.Immediate)
252
        }
253
        AccessibleOverlaidImageButton {
254 255 256 257
            id: actionButton
            anchors.verticalCenter: parent.verticalCenter
            anchors.right: parent.right
            anchors.rightMargin: defaultMargin
258 259
            image.sourceSize.height: imgHeightHeader
            image.source: "qrc:/ui/send-msg.svg"
260 261 262 263
            accessibleName: qsTr("Send message")
            onClicked: {
                actionButton.enabled = false
                mainPanel.doSendRequest()
264 265 266
            }
        }
    } // PageHeader
267
    AccessibleText {
268 269 270 271 272 273 274 275 276
        id: errorText
        visible: false
        color: datovkaPalette.text
        anchors.centerIn: parent
        width: parent.width
        horizontalAlignment: Text.AlignHCenter
        wrapMode: Text.Wrap
        text: qsTr("Error during message creation.")
    }
277
    Item {
278 279 280 281 282
        id: mainPanel
        anchors.top: headerBar.bottom
        anchors.bottom: parent.bottom
        width: parent.width

283 284 285
        Connections {
            target: isds
            onRunSendMessageSig: {
286
                actionButton.enabled = false
Martin Straka's avatar
Martin Straka committed
287
                isds.sendMessage(userName, msgId, dmAnnotation.text.toString(),
Martin Straka's avatar
Martin Straka committed
288
                    recipBoxModel, sendMsgAttachmentModel,
289 290 291 292 293
                    dmLegalTitleLaw.text.toString(), dmLegalTitleYear.text.toString(),
                    dmLegalTitleSect.text.toString(), dmLegalTitlePar.text.toString(),
                    dmLegalTitlePoint.text.toString(), dmToHands.text.toString(),
                    dmRecipientRefNumber.text.toString(), dmRecipientIdent.text.toString(),
                    dmSenderRefNumber.text.toString(), dmSenderIdent.text.toString(),
Martin Straka's avatar
Martin Straka committed
294 295
                    dmOVM.checked, dmPublishOwnID.checked, dmAllowSubstDelivery.checked,
                    dmPersonalDelivery.checked, dmType)
296 297 298
            }
        }

299
        function doSendRequest() {
300
            isds.doIsdsAction("sendMessage", userName)
301 302 303 304
        }

        /* Enable send message button if all required fields are filled */
        function areReguiredFieldsFilled() {
305
            actionButton.enabled = (attachmentSizeOk() && (dmAnnotation.text.toString() !== "") && (recipBoxModel.rowCount() > 0))
306 307 308
        }

        TabBar {
309 310
            id: tabBar
            z: 1
311 312
            width: parent.width
            Repeater {
313
                model: [qsTr("General"), qsTr("Recipients"), qsTr("Attachments"), qsTr("Additional")]
314
                AccessibleTabButton {
315
                    text: modelData
316
                    width: Math.max(100, tabBar.width / 4)
317 318 319 320 321
                }
            }
        } // TabBar
        StackLayout {
            width: parent.width
322
            anchors.top: tabBar.bottom
323
            anchors.bottom: parent.bottom
324 325 326
            currentIndex: tabBar.currentIndex
            onCurrentIndexChanged: {
                tabGeneral.contentY = 0
327
                tabAdditional.contentY = 0
328
            }
329
//----SUBJECT SECTION------------
330
            Flickable {
331
                id: tabGeneral
332 333 334 335 336 337 338
                z: 0
                anchors.fill: parent
                contentHeight: generalContent.implicitHeight
                Pane {
                    id: generalContent
                    anchors.fill: parent
                    Column {
339 340 341
                        anchors.right: parent.right
                        anchors.left: parent.left
                        spacing: formItemVerticalSpacing
342
                        AccessibleText {
343 344
                            color: datovkaPalette.mid
                            wrapMode: Text.Wrap
345
                            horizontalAlignment: Text.AlignHCenter
346
                            width: parent.width
347
                            text: qsTr("Please fill in the subject of the message, select at least one recipient data box and specify at least one attachment file before sending the message.")
348
                        }
Martin Straka's avatar
Martin Straka committed
349 350 351
                        Text {
                            text: " "
                        }
352
                        AccessibleText {
353 354
                            color: datovkaPalette.text
                            font.bold: true
355
                            text: qsTr("Sender account")
356
                        }
357
                        AccessibleText {
358 359 360
                            color: datovkaPalette.text
                            text: acntName + " (" + userName + ")"
                        }
361 362 363
                        Text {
                            text: " "
                        }
364
                        AccessibleText {
365
                            color: datovkaPalette.text
366
                            font.bold: true
367 368
                            text: qsTr("Subject")
                        }
369
                        AccessibleTextField {
370
                            id: dmAnnotation
371
                            width: parent.width
372 373 374 375 376 377 378
                            height: inputItemHeight
                            font.pointSize: defaultTextFont.font.pointSize
                            placeholderText: qsTr("Enter subject")
                            InputLineMenu {
                                id: subjectMenu
                                inputTextControl: dmAnnotation
                                isPassword: false
379
                            }
380 381 382 383
                            onPressAndHold: {
                                if (settings.useExplicitClipboardOperations()) {
                                    subjectMenu.implicitWidth = computeMenuWidth(subjectMenu)
                                    subjectMenu.open()
384 385
                                }
                            }
386 387 388
                            onTextChanged: {
                                mainPanel.areReguiredFieldsFilled()
                            }
389
                        }
390
                        AccessibleSwitch {
391 392 393 394
                            id: dmPublishOwnID
                            text: qsTr("Include sender identification")
                            font.pointSize: defaultTextFont.font.pointSize
                            checked: true
Martin Straka's avatar
Martin Straka committed
395
                        }
396
                        AccessibleSwitch {
397 398 399 400 401
                            id: dmPersonalDelivery
                            text: qsTr("Personal delivery")
                            font.pointSize: defaultTextFont.font.pointSize
                            checked: false
                        }
402
                        AccessibleSwitch {
403 404 405 406 407 408
                            id: dmAllowSubstDelivery
                            visible: false
                            text: qsTr("Allow acceptance through fiction")
                            font.pointSize: defaultTextFont.font.pointSize
                            checked: true
                        }
409
                        AccessibleSwitch {
410 411 412 413 414 415
                            id: dmOVM
                            visible: false
                            text: qsTr("Send as OVM")
                            font.pointSize: defaultTextFont.font.pointSize
                            checked: true
                        }
416
                        AccessibleSwitch {
417 418 419 420 421 422 423 424 425
                            id: initPDZ
                            visible: false
                            text: qsTr("Pay transfer charges for reply")
                            font.pointSize: defaultTextFont.font.pointSize
                            checked: false
                            onClicked: {
                                (initPDZ.checked) ? dmType = "I" : dmType = ""
                            }
                        }
426
                        AccessibleSwitch {
427 428
                            id: replyPDZ
                            visible: false
429
                            text: qsTr("Use transfer charges from recipient")
430
                            font.pointSize: defaultTextFont.font.pointSize
431
                            checked: false
432 433 434
                            onClicked: {
                                (replyPDZ.checked) ? dmType = "O" : dmType = ""
                            }
Martin Straka's avatar
Martin Straka committed
435
                        }
436 437 438
                    } // Column
                } // Pane
            } // Flickable
439 440 441 442 443 444 445 446 447 448 449
//----RECIPIENTS SECTION------------
            Item {
                id: tabRecipients
                Item {
                    id: buttonMenu
                    anchors.left: parent.left
                    anchors.right: parent.right
                    height: inputItemHeight
                    Row {
                        spacing: formItemVerticalSpacing * 5
                        anchors.horizontalCenter: parent.horizontalCenter
450
                        AccessibleButton {
Martin Straka's avatar
Martin Straka committed
451 452 453
                            id: addContact
                            height: inputItemHeight
                            font.pointSize: defaultTextFont.font.pointSize
454
                            text: qsTr("Add")
Martin Straka's avatar
Martin Straka committed
455 456 457 458 459 460 461 462 463
                            onClicked: {
                                pageView.push(pageContactList, {
                                        "pageView": pageView,
                                        "statusBar": statusBar,
                                        "userName": userName,
                                        "recipBoxModel": recipBoxModel
                                    }, StackView.Immediate)
                            }
                        }
464
                        AccessibleButton {
465 466 467
                            id: findDS
                            height: inputItemHeight
                            font.pointSize: defaultTextFont.font.pointSize
468
                            text: qsTr("Find")
469 470 471 472 473
                            onClicked: {
                                pageView.push(pageDataboxSearch, {
                                        "pageView": pageView,
                                        "statusBar": statusBar,
                                        "userName": userName,
474
                                        "recipBoxModel": recipBoxModel
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
                                    }, StackView.Immediate)
                            }
                        }
                    } // Row
                } // Item
                DataboxList {
                    id: recipientList
                    anchors.top: buttonMenu.bottom
                    anchors.bottom: parent.bottom
                    clip: true
                    spacing: 1
                    opacity: 1
                    visible: true
                    width: parent.width
                    height: 600
                    interactive: true
491
                    model: recipBoxModel
492
                    canRemoveBoxes: true
493
                    localContactFormat: true
494 495 496
                    onCountChanged: {
                        mainPanel.areReguiredFieldsFilled()
                    }
497
                    onBoxRemove: {
498
                        recipBoxModel.removeEntry(boxId)
499
                    }
500 501 502 503 504
                } // DataboxList
            }
//----ATTACHMENT SECTION------------
            Item {
                id: tabAttachments
505
                Connections {
Martin Straka's avatar
Martin Straka committed
506
                   target: iOSHelper
507 508 509 510 511 512
                    onFileSelectedSig: {
                        if (filePath !== "") {
                            appendFileToSendModel(filePath)
                        }
                    }
                }
513 514
                Row {
                    id: buttonBar
515
                    spacing: formItemVerticalSpacing * 2
516
                    anchors.horizontalCenter: parent.horizontalCenter
517 518 519 520 521 522
                    AccessibleButton {
                        id: addFile
                        height: inputItemHeight
                        font.pointSize: defaultTextFont.font.pointSize
                        text: qsTr("Add file")
                        onClicked: {
523
                            fileDialogue.raise(qsTr("Select files"), ["*.*"], true, "", iOS)
524
                        }
525
                    }
526 527 528 529 530 531 532
                   AccessibleButton {
                        id: storage
                        visible: iOS
                        height: inputItemHeight
                        font.pointSize: defaultTextFont.font.pointSize
                        text: qsTr("Storage")
                        onClicked: {
Martin Straka's avatar
Martin Straka committed
533
                            iOSHelper.openDocumentPickerController()
534 535
                        }
                   }
536 537 538 539 540 541
                }
                Component {
                    id: attachmentDelegate
                    Rectangle {
                        id: attachmentItem
                        width: parent.width
542
                        height: attachmentListSend.delegateHeight
543
                        color: datovkaPalette.base
544
                        MouseArea {
545
                            function handleClick() {
Martin Straka's avatar
Martin Straka committed
546
                                // fileId is set and is valid, use files from database
547
                                if (rFileId > 0) {
Martin Straka's avatar
Martin Straka committed
548 549
                                    if (files.isZfoFile(rFileName)) {
                                        pageView.push(pageMessageDetail, {
550 551 552
                                            "pageView": pageView,
                                            "statusBar": statusBar,
                                            "fromLocalDb": false,
553
                                            "rawZfoContent": files.getFileRawContentFromDb(userName, rFileId)})
Martin Straka's avatar
Martin Straka committed
554
                                    } else {
555
                                        files.openAttachmentFromDb(userName, rFileId)
Martin Straka's avatar
Martin Straka committed
556
                                    }
557 558 559 560 561 562
                                } else if (rFileId == FileIdType.DB_ZFO_ID)  {
                                        pageView.push(pageMessageDetail, {
                                            "pageView": pageView,
                                            "statusBar": statusBar,
                                            "fromLocalDb": false,
                                            "rawZfoContent": zfo.getZfoContentFromDb(userName, msgId)})
563
                                } else {
Martin Straka's avatar
Martin Straka committed
564 565 566 567 568 569 570 571 572
                                    if (files.isZfoFile(getFileNameFromPath(rFilePath))) {
                                        pageView.push(pageMessageDetail, {
                                            "pageView": pageView,
                                            "statusBar": statusBar,
                                            "fromLocalDb": false,
                                            "rawZfoContent": files.rawFileContent(rFilePath)})
                                    } else {
                                        files.openAttachmentFromPath(rFilePath)
                                    }
573 574
                                }
                            }
575 576 577 578 579 580 581 582 583 584 585

                            anchors.fill: parent

                            Accessible.role: Accessible.Button
                            Accessible.name: qsTr("Open file '%1'.").arg(rFileName)
                            Accessible.onPressAction: {
                                handleClick()
                            }
                            onClicked: {
                                handleClick()
                            }
586
                        }
587 588 589 590
                        Image {
                            id: imageAttachment
                            anchors.left: parent.left
                            anchors.verticalCenter: parent.verticalCenter
591
                            sourceSize.height: attachmentListSend.delegateHeight * 0.8
592
                            source: files.getAttachmentFileIcon(rFileName)
593 594 595 596 597 598 599 600 601 602 603
                        }
                        Item {
                            anchors.left: imageAttachment.right
                            anchors.leftMargin: defaultMargin
                            height: parent.height
                            width: parent.width
                            Column {
                                width: parent.width
                                anchors.verticalCenter: parent.verticalCenter
                                spacing: defaultMargin
                                Text {
Martin Straka's avatar
Martin Straka committed
604
                                    text: rFileName
605 606 607 608
                                    color: datovkaPalette.text
                                    font.bold: true
                                }
                                Text {
609
                                    text: if (rFilePath != "") {
Martin Straka's avatar
Martin Straka committed
610
                                        iOS ? iOSHelper.getShortSendFilePath(rFilePath) : rFilePath
611 612
                                    } else {
                                        qsTr("Local database")
Martin Straka's avatar
Martin Straka committed
613
                                    }
614 615 616 617
                                    color: datovkaPalette.mid
                                    font.pointSize: textFontSizeSmall
                                }
                                Text {
Karel Slaný's avatar
Karel Slaný committed
618
                                    text: rFileSizeStr
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
                                    color: datovkaPalette.mid
                                    font.pointSize: textFontSizeSmall
                                }
                            }
                        }
                        Rectangle {
                            id: remove
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.right: parent.right
                            height: parent.height
                            width: parent.width * 0.07
                            color: parent.color
                            Image {
                                id: removeImage
                                anchors.verticalCenter: parent.verticalCenter
                                anchors.right: parent.right
                                anchors.rightMargin: defaultMargin
636
                                sourceSize.height: navImgHeight
637 638 639 640 641 642 643 644
                                source: "qrc:/ui/remove.svg"
                            }
                            ColorOverlay {
                                anchors.fill: removeImage
                                source: removeImage
                                color: datovkaPalette.windowText
                            }
                            MouseArea {
645 646
                                function handleClick() {
                                    sendMsgAttachmentModel.removeItem(index)
647
                                    totalAttachmentSizeBytes = sendMsgAttachmentModel.dataSizeSum()
648 649
                                }

650
                                anchors.fill: parent
651 652 653

                                Accessible.role: Accessible.Button
                                Accessible.name: qsTr("Remove file '%1' from list.").arg(rFileName)
654 655
                                Accessible.onScrollDownAction: attachmentListSend.scrollDown()
                                Accessible.onScrollUpAction: attachmentListSend.scrollUp()
656 657 658
                                Accessible.onPressAction: {
                                    handleClick()
                                }
659
                                onClicked: {
660
                                    handleClick()
661 662 663 664 665 666 667 668 669 670 671
                                }
                            }
                        } // Rectangle
                        Rectangle {
                            anchors.top: parent.bottom
                            height: 1
                            width: parent.width
                            color: datovkaPalette.dark
                        }
                    } // Rectangle
                } // Component
672 673 674 675 676
                AccessibleText {
                    id: attachmentsSizeLabel
                    color: datovkaPalette.text
                    anchors.left: parent.left
                    anchors.leftMargin: defaultMargin
677
                    anchors.top: buttonBar.bottom
678 679 680 681 682 683 684 685
                    anchors.topMargin: defaultMargin
                    anchors.right: parent.right
                    anchors.rightMargin: defaultMargin
                    horizontalAlignment: Text.AlignHCenter
                    wrapMode: Text.Wrap
                    font.pointSize: textFontSizeSmall
                    text: qsTr("Total size of attachments is %1 B.").arg(totalAttachmentSizeBytes)
                }
686
                ScrollableListView {
687
                    id: attachmentListSend
688
                    delegateHeight: listItemHeight
689 690
                    anchors.top: attachmentsSizeLabel.bottom
                    anchors.bottom: parent.bottom
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
                    clip: true
                    spacing: 1
                    opacity: 1
                    visible: true
                    width: parent.width
                    height: 600
                    interactive: true
                    model: sendMsgAttachmentModel
                    delegate: attachmentDelegate
                    onCountChanged: {
                        mainPanel.areReguiredFieldsFilled()
                    }
                    ScrollIndicator.vertical: ScrollIndicator {}
                } // Listview
            }
//----ADDITIONALS SECTION------------
707
            Flickable {
708
                id: tabAdditional
709 710 711 712 713 714
                z: 0
                anchors.fill: parent
                contentHeight: additonalsContent.implicitHeight
                Pane {
                    id: additonalsContent
                    anchors.fill: parent
715 716 717 718
                    Column {
                        anchors.right: parent.right
                        anchors.left: parent.left
                        spacing: formItemVerticalSpacing
719
    //---Mandate---------------------
720
                        AccessibleText {
721 722
                            font.bold: true
                            text: qsTr("Mandate")
723
                        }
724
                        Row {
725
                            width: parent.width
726
                            spacing: defaultMargin
727
                            AccessibleTextField {
728 729 730 731 732 733
                                id: dmLegalTitleLaw
                                width: mandateFieldLenght
                                height: inputItemHeight
                                maximumLength: 4
                                font.pointSize: defaultTextFont.font.pointSize
                            }
734
                            AccessibleText {
735 736 737
                                anchors.verticalCenter: parent.verticalCenter
                                text: "/"
                            }
738
                            AccessibleTextField {
739 740 741 742 743 744
                                id: dmLegalTitleYear
                                width: mandateFieldLenght
                                height: inputItemHeight
                                maximumLength: 4
                                font.pointSize: defaultTextFont.font.pointSize
                            }
745
                            AccessibleText {
746 747 748
                                anchors.verticalCenter: parent.verticalCenter
                                text: "§"
                            }
749
                            AccessibleTextField {
750 751 752 753 754 755
                                id: dmLegalTitleSect
                                width: mandateFieldLenght
                                height: inputItemHeight
                                maximumLength: 4
                                font.pointSize: defaultTextFont.font.pointSize
                            }
756
                            AccessibleText {
757 758 759
                                anchors.verticalCenter: parent.verticalCenter
                                text: qsTr("par.")
                            }
760
                            AccessibleTextField {
761 762 763 764 765 766
                                id: dmLegalTitlePar
                                width: mandateFieldLenght / 2
                                height: inputItemHeight
                                maximumLength: 2
                                font.pointSize: defaultTextFont.font.pointSize
                            }
767
                            AccessibleText {
768 769 770
                                anchors.verticalCenter: parent.verticalCenter
                                text: qsTr("let.")
                            }
771
                            AccessibleTextField {
772 773 774 775 776 777 778 779
                                id: dmLegalTitlePoint
                                width: mandateFieldLenght / 2
                                height: inputItemHeight
                                maximumLength: 2
                                font.pointSize: defaultTextFont.font.pointSize
                            }
                        }
    //---Our ref.number---------------------
780
                        AccessibleText {
781 782
                            font.bold: true
                            text: qsTr("Our reference number")
783
                        }
784
                        AccessibleTextField {
785
                            id: dmSenderRefNumber
786 787
                            height: inputItemHeight
                            font.pointSize: defaultTextFont.font.pointSize
788
                            placeholderText: qsTr("Enter our reference number")
789
                            width: parent.width
790 791 792 793 794 795 796 797 798 799 800
                            InputLineMenu {
                                id: r2c2M
                                inputTextControl: dmSenderRefNumber
                                isPassword: false
                            }
                            onPressAndHold: {
                                if (settings.useExplicitClipboardOperations()) {
                                    r2c2M.implicitWidth = computeMenuWidth(r2c2M)
                                    r2c2M.open()
                                }
                            }
801
                        }
802
    //---Our file mark---------------------
803
                        AccessibleText {
804 805
                            font.bold: true
                            text: qsTr("Our file mark")
806
                        }
807
                        AccessibleTextField {
808
                            id: dmSenderIdent
809 810
                            height: inputItemHeight
                            font.pointSize: defaultTextFont.font.pointSize
811
                            placeholderText: qsTr("Enter our file mark")
812
                            width: parent.width
813 814 815 816 817 818 819 820 821 822 823
                            InputLineMenu {
                                id: r3c2M
                                inputTextControl: dmSenderIdent
                                isPassword: false
                            }
                            onPressAndHold: {
                                if (settings.useExplicitClipboardOperations()) {
                                    r3c2M.implicitWidth = computeMenuWidth(r3c2M)
                                    r3c2M.open()
                                }
                            }
824
                        }
825
    //---Your ref.number---------------------
826
                        AccessibleText {
827 828
                            font.bold: true
                            text: qsTr("Your reference number")
829
                        }
830
                        AccessibleTextField {
831
                            id: dmRecipientRefNumber
832 833
                            height: inputItemHeight
                            font.pointSize: defaultTextFont.font.pointSize
834
                            placeholderText: qsTr("Enter your reference number")
835
                            width: parent.width
836 837 838 839 840 841 842 843 844 845 846
                            InputLineMenu {
                                id: r4c2M
                                inputTextControl: dmRecipientRefNumber
                                isPassword: false
                            }
                            onPressAndHold: {
                                if (settings.useExplicitClipboardOperations()) {
                                    r4c2M.implicitWidth = computeMenuWidth(r4c2M)
                                    r4c2M.open()
                                }
                            }
847
                        }
848
    //---Your file mark---------------------
849
                        AccessibleText {
850 851
                            font.bold: true
                            text: qsTr("Your file mark")
852
                        }
853
                        AccessibleTextField {
854
                            id: dmRecipientIdent
855 856
                            height: inputItemHeight
                            font.pointSize: defaultTextFont.font.pointSize
857
                            placeholderText: qsTr("Enter your file mark")
858
                            width: parent.width
859 860 861 862
                            InputLineMenu {
                                id: r5c2M
                                inputTextControl: dmRecipientIdent
                                isPassword: false
863
                            }
864 865 866 867 868
                            onPressAndHold: {
                                if (settings.useExplicitClipboardOperations()) {
                                    r5c2M.implicitWidth = computeMenuWidth(r5c2M)
                                    r5c2M.open()
                                }
869 870
                            }
                        }
871
    //---To hands---------------------
872
                        AccessibleText {
873 874
                            font.bold: true
                            text: qsTr("To hands")
875
                        }
876
                        AccessibleTextField {
877 878 879 880
                            id: dmToHands
                            height: inputItemHeight
                            font.pointSize: defaultTextFont.font.pointSize
                            placeholderText: qsTr("Enter name")
881
                            width: parent.width
882 883 884 885
                            InputLineMenu {
                                id: r6c2M
                                inputTextControl: dmToHands
                                isPassword: false
886
                            }
887 888 889 890 891
                            onPressAndHold: {
                                if (settings.useExplicitClipboardOperations()) {
                                    r6c2M.implicitWidth = computeMenuWidth(r6c2M)
                                    r6c2M.open()
                                }
892 893
                            }
                        }
894
                    } // Column
895 896
                 } // Pane
            } // Flickable
897
        } //StackLayout
898
    } // Item
899 900 901
    Connections {
        // Connection is activated when message sending was successful.
        target: isds
902 903
        onSentMessageFinished: {
            (closePage) ? pageView.pop(StackView.Immediate) : actionButton.enabled = true
904 905
        }
    } // Connections
906
} // Item