FileDialogueIos.qml 7.52 KB
Newer Older
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
/*
 * Copyright (C) 2014-2018 CZ.NIC
 *
 * 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
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 * 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.2
import QtQuick.Layouts 1.3
import cz.nic.mobileDatovka 1.0
import cz.nic.mobileDatovka.qmlInteraction 1.0
import cz.nic.mobileDatovka.models 1.0

Dialog {
    id: root
    focus: true
    modal: true
    title: qsTr("Select files")

    footer: DialogButtonBox {
        AccessibleButton {
            text: qsTr("Cancel")
            DialogButtonBox.buttonRole: DialogButtonBox.RejectRole
        }
        AccessibleButton {
            text: qsTr("Add")
            DialogButtonBox.buttonRole: DialogButtonBox.AcceptRole
        }
    }

    /* Place the dialogue in the centre. */
    x: 2 * defaultMargin
    y: 2 * defaultMargin

    height: parent.height - 4 * defaultMargin
    width: parent.width - 4 * defaultMargin

    signal finished(variant pathListModel)

    function raise(title, filters, showFiles, targetLocation) {
        cloudFileListModel.clearAll()
        pathListModel.clear()
        filterBar.filterField.text = ""
        iCloudHelper.getCloudHierarchyAsync()
        root.open()
    }

    /* Holds cloud file list model */
    CloudFileListModel {
        id: cloudFileListModel
        Component.onCompleted: {
        }
    }

    ListSortFilterProxyModel {
        id: proxyCloudFileListModel
        Component.onCompleted: {
            setFilterRoles([CloudFileListModel.ROLE_FILE_NAME,
                CloudFileListModel.ROLE_FILE_SHORT_PATH])
            proxyCloudFileListModel.setSourceModel(cloudFileListModel)
        }
    }

    ListModel {
        id: pathListModel
    }

    contentItem: ColumnLayout {
        spacing: formItemVerticalSpacing
        Connections {
           target: iCloudHelper
            onCloudContentSig: {
                iCloudHelper.setCloudFileModel(cloudFileListModel, iCloudFileList);
91
                if (cloudFileListModel.rowCount() > 0) {
92
                    cloudFileList.visible = true
93 94 95 96 97
                    emptyList.visible = !cloudFileList.visible
                } else {
                    emptyList.text = qsTr("No files in the iCloud.")
                    cloudFileList.visible = false
                    emptyList.visible = !cloudFileList.visible
98 99 100 101 102
                }
            }
            onCloudActivitySig: {
                emptyList.text = txt
                cloudFileList.visible = false
103
                emptyList.visible = !cloudFileList.visible
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
            }
        }
        Component {
            id: attachmentDelegate
            Rectangle {
                id: attachmentItem
                width: parent.width
                height: cloudFileList.delegateHeight
                color: rFileSelected ? datovkaPalette.midlight : datovkaPalette.base
                Image {
                    id: imageAttachment
                    anchors.left: parent.left
                    anchors.verticalCenter: parent.verticalCenter
                    sourceSize.height: cloudFileList.delegateHeight * 0.8
                    source: files.getAttachmentFileIcon(rFileName)
                }
                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 {
                            text: rFileName
                            color: datovkaPalette.text
                            font.bold: true
                        }
                        Text {
135
                            text: "iCloud:" + rFileShortPath
136 137 138 139 140 141 142 143 144 145 146 147 148 149
                            color: datovkaPalette.mid
                            font.pointSize: textFontSizeSmall
                        }
                    }
                }
                Rectangle {
                    anchors.top: parent.bottom
                    height: 1
                    width: parent.width
                    color: datovkaPalette.dark
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
150 151 152 153
                        if (!rFileSelected) {
                            iCloudHelper.downloadFileFromCloud(rFileCloudPath)
                        }
                        cloudFileListModel.setFileSelected(rFileCloudPath)
154 155 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 196 197 198 199 200 201 202 203 204 205 206 207
                    }
                }
            } // Rectangle
        } // Component
        FilterBar {
            id: filterBar
            visible: true
            Layout.fillWidth: true
            height: filterField.height
            color: (filterField.text.length === 0) ? datovkaPalette.alternateBase :
                    (cloudFileList.count > 0) ? "#afffaf" : "#ffafaf"
            border.color: filterField.activeFocus ? "#0066ff" : "#bdbebf"

            placeholderText: qsTr("Set filter")
            fontPointSize: defaultTextFont.font.pointSize
            buttonImageHeight: imgHeight
            buttonAccessibleName: qsTr("Clear and hide filter field")

            onTextChanged: {
                proxyCloudFileListModel.setFilterRegExpStr(text)
            }

            onClearClicked: {
                filterField.text.clear
            }
        }
        AccessibleText {
            id: emptyList
            visible: true
            color: datovkaPalette.text
            Layout.fillHeight: true
            Layout.fillWidth: true
            horizontalAlignment: Text.AlignHCenter
            wrapMode: Text.Wrap
            text: qsTr("No files in the iCloud.")
        }
        ScrollableListView {
            id: cloudFileList
            visible: false
            delegateHeight: headerHeight
            Layout.fillHeight: true
            Layout.fillWidth: true
            clip: true
            spacing: 1
            opacity: 1
            interactive: true
            model: proxyCloudFileListModel
            delegate: attachmentDelegate
            ScrollIndicator.vertical: ScrollIndicator {}
        } // Listview
    } // ColumnLayout
    onAccepted: {
        for (var i = 0; i < cloudFileListModel.rowCount(); ++i) {
            if (cloudFileListModel.fileSelected(i)) {
208 209 210 211
                var filePath = iCloudHelper.copyFileFromCloud(cloudFileListModel.fileCloudPathFromRow(i), cloudFileListModel.fileShortCloudPathFromRow(i))
                if (filePath !== "") {
                    pathListModel.append({path: filePath})
                }
212 213 214 215 216 217
            }
        }
        finished(pathListModel)
    }
    onRejected: {
        pathListModel.clear()
218
        iCloudHelper.stopCloudHierarchyAsync()
219 220
    }
}