PageImportMessage.qml 7.29 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
3 4 5 6 7 8 9 10 11 12 13 14
 *
 * 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
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
 *
 * 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 QtGraphicalEffects 1.0
import cz.nic.mobileDatovka 1.0

Component {
    id: importMessage
    Item {
        id: mainLayout

        /* These properties must be set by caller. */
        property var pageView
        property var statusBar
        property string acntName
        property string userName
        property var accountModel: null

        /* Clear import info and import results */
        function clearInfo() {
            infoText.text = ""
            progressText.text = ""
        }

        Component.onCompleted: {
            clearInfo()
        }

        Component.onDestruction: {
52
            accounts.updateAccountCounters(accountModel)
53 54 55
            statusBar.visible = false
        }

56
        /* File dialog for choosing of files/directories from the storage. */
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
        FileDialogue {
            id: fileDialogue
            multiSelect: true
            onFinished: {
                var files = []
                for (var j = 0; j < pathListModel.count; ++j) {
                    files.push(pathListModel.get(j).path)
                }
                clearInfo()
                infoText.text = isds.importZfoMessages(userName, files, verifyMessage.checked)
                pathListModel.clear()
            }
        }

        PageHeader {
            id: headerBar
            title: qsTr("ZFO message import")
            onBackClicked: {
                pageView.pop(StackView.Immediate)
            }
        }
78 79 80 81 82

        /* Object (associative array) holding functions. */
        property var funcs: {
            "zfoFile": function callZfoFile() {
                clearInfo()
83
                fileDialogue.raise(qsTr("Select ZFO files"), ["*.zfo"], true, "")
84 85 86
            },
            "zfoDir": function callZfoDir() {
                clearInfo()
87
                fileDialogue.raise(qsTr("Select import directory"), ["*.*"], false, "")
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
            }
        }

        ListModel {
            id: importMenuListModel
            ListElement {
                image: "qrc:/ui/datovka-file-zfo.svg"
                showEntry: true
                showNext: true
                name: qsTr("Import selected ZFO files")
                funcName: "zfoFile"
            }
            ListElement {
                image: "qrc:/ui/datovka-folder-open.svg"
                showEntry: true
                showNext: true
104
                name: qsTr("Import ZFO files from directory")
105 106 107 108
                funcName: "zfoDir"
            }
        }

109 110 111 112 113 114 115 116 117 118 119 120 121 122
        Flickable {
            id: flickable
            z: 0
            anchors.top: headerBar.bottom
            anchors.right: parent.right
            anchors.left: parent.left
            anchors.bottom: parent.bottom
            contentHeight: flickContent.implicitHeight
            Pane {
                id: flickContent
                anchors.fill: parent
                Column {
                    anchors.right: parent.right
                    anchors.left: parent.left
123
                    spacing: formItemVerticalSpacing
124 125 126 127 128
                    AccessibleText {
                        color: datovkaPalette.mid
                        wrapMode: Text.Wrap
                        horizontalAlignment: Text.AlignHCenter
                        width: parent.width
129
                        text: qsTr("Here you can import messages from ZFO files into the local database. You can manually specify individual ZFO files or you can select whole directories containing ZFO files.")
130 131 132
                    }
                    AccessibleSwitch {
                        id: verifyMessage
133
                        text: qsTr("Verify data on server")
134 135 136
                        font.pointSize: defaultTextFont.font.pointSize
                        checked: false
                    }
137 138 139 140 141
                    AccessibleText {
                        color: datovkaPalette.mid
                        wrapMode: Text.Wrap
                        width: parent.width
                        text: (verifyMessage.checked ?
142 143
                            (qsTr("Messages will be validated on the ISDS server before being imported. Imported messages are going to be sent to the ISDS server where they are going to be checked. Messages failing this test won't be imported.")
                             + "\n" + qsTr("Working internet connection is required. The duration of the operation depends on the speed of your internet connection. The size of the generated upload traffic depends on the amount of imported data.")
144 145 146
                             + "\n" + qsTr("We don't recommend using this option when you are using a mobile internet connection.")) :
                            qsTr("Imported messages won't be validated on the ISDS server."))
                    }
147 148 149
                    AccessibleMenu {
                        id: importMenuList
                        height: 2 * delegateHeight
150
                        width: parent.width
151 152 153 154 155
                        clip: true
                        spacing: 1
                        opacity: 1
                        funcArr: funcs
                        model: importMenuListModel
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
                    }
                    Text {
                        text: " "
                    }
                    AccessibleText {
                        id: infoText
                        color: datovkaPalette.text
                        wrapMode: Text.Wrap
                        horizontalAlignment: Text.AlignHCenter
                        width: parent.width
                        font.bold: true
                        text: ""
                    }
                    AccessibleText {
                        id: progressText
                        color: datovkaPalette.text
                        wrapMode: Text.Wrap
                        width: parent.width
                        font.pointSize: textFontSizeSmall
                        textFormat: TextEdit.RichText
                        text: ""
                    }
                } // Column layout
            } // Pane
            ScrollIndicator.vertical: ScrollIndicator {}
        } // Flickable
        Connections {
            target: isds
            onZfoImportFinishedSig: {
                infoText.text = txt
            }
        }
        Connections {
            target: isds
            onZfoImportProgressSig: {
                progressText.text = progressText.text + "<br/>" + txt
            }
        }
    }
}