PageContactList.qml 5.26 KB
Newer Older
Martin Straka's avatar
Martin Straka committed
1
/*
2
 * Copyright (C) 2014-2019 CZ.NIC
Martin Straka's avatar
Martin Straka committed
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/>.
Martin Straka's avatar
Martin Straka committed
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
 *
 * 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 cz.nic.mobileDatovka 1.0
import cz.nic.mobileDatovka.models 1.0

/*
 * Roles are defined in DataboxListModel::roleNames() and are accessed directly
 * via their names.
 */

Item {
    id: pageContactList

    /* These properties must be set by caller. */
    property var pageView
    property var statusBar
    property string userName
    // recipBoxModel (if not null) holds recipient list of send message page
    property var recipBoxModel: null

    Component.onCompleted: {
        var currentBoxId = accounts.boxId(userName)
        messages.fillContactList(foundBoxModel, userName, currentBoxId)
47 48
        if (foundBoxModel.rowCount() === 0) {
            emptyList.visible = true
49
            filterButton.visible = false
50
        }
51 52 53
        if (recipBoxModel != null) {
            foundBoxModel.selectEntries(recipBoxModel.boxIds(), true)
        }
Martin Straka's avatar
Martin Straka committed
54 55
        proxyDataboxModel.setSourceModel(foundBoxModel)
    }
56 57 58 59 60

    Component.onDestruction: {
       statusBar.visible = false
    }

Martin Straka's avatar
Martin Straka committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74
    DataboxListModel {
        id: foundBoxModel
        Component.onCompleted: {
        }
    }
    ListSortFilterProxyModel {
        id: proxyDataboxModel
        Component.onCompleted: {
            setFilterRoles([DataboxListModel.ROLE_DB_NAME,
                DataboxListModel.ROLE_DB_ADDRESS, DataboxListModel.ROLE_DB_ID])
        }
    }
    PageHeader {
        id: headerBar
75
        title: qsTr("Contacts")
76 77
        onBackClicked: {
            pageView.pop(StackView.Immediate)
Martin Straka's avatar
Martin Straka committed
78
        }
79 80 81
        Row {
            anchors.verticalCenter: parent.verticalCenter
            spacing: defaultMargin
Martin Straka's avatar
Martin Straka committed
82 83
            anchors.right: parent.right
            anchors.rightMargin: defaultMargin
84 85
            AccessibleImageButton {
                id: filterButton
86
                anchors.verticalCenter: parent.verticalCenter
Martin Straka's avatar
Martin Straka committed
87
                sourceSize.height: imgHeightHeader
88
                source: "qrc:/ui/magnify.svg"
89 90 91 92
                accessibleName: qsTr("Filter data boxes.")
                onClicked: {
                    databoxList.anchors.top = filterBar.bottom
                    filterBar.visible = true
93
                    filterBar.filterField.forceActiveFocus()
94
                    Qt.inputMethod.show()
95 96 97 98
                }
            }
        }
    } // PageHeader
99
    FilterBar {
Martin Straka's avatar
Martin Straka committed
100
        id: filterBar
101 102 103 104
        visible: false
        z: 1
        anchors.top: headerBar.bottom
        width: parent.width
105 106
        height: filterField.height
        color: (filterField.text.length == 0) ? datovkaPalette.alternateBase :
107
                (databoxList.count > 0) ? "#afffaf" : "#ffafaf"
108 109 110 111 112 113 114 115 116
        border.color: filterField.activeFocus ? "#0066ff" : "#bdbebf"

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

        onTextChanged: {
            proxyDataboxModel.setFilterRegExpStr(text)
117
        }
118 119 120 121 122

        onClearClicked: {
            filterBar.visible = false
            databoxList.anchors.top = headerBar.bottom
            Qt.inputMethod.hide()
Martin Straka's avatar
Martin Straka committed
123
        }
124
    }
125
    AccessibleText {
Martin Straka's avatar
Martin Straka committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
        id: emptyList
        visible: false
        color: datovkaPalette.text
        anchors.centerIn: parent
        wrapMode: Text.Wrap
        text: qsTr("No databox found in contacts.")
    }
    DataboxList {
        id: databoxList
        anchors.top: headerBar.bottom
        anchors.bottom: parent.bottom
        clip: true
        spacing: 1
        opacity: 1
        visible: true
        width: parent.width
        interactive: true
        model: proxyDataboxModel
        canDetailBoxes: recipBoxModel == null
        canSelectBoxes: recipBoxModel != null
        canDeselectBoxes: recipBoxModel != null
147
        localContactFormat: true
Martin Straka's avatar
Martin Straka committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
        onBoxSelect: {
            var boxEntry = foundBoxModel.entry(boxId)
            statusBar.visible = false
            if (recipBoxModel != null) {
                foundBoxModel.selectEntry(boxEntry.dbID, true)
                recipBoxModel.addEntry(boxEntry)
            }
        }
        onBoxDeselect: {
            statusBar.visible = false
            if (recipBoxModel != null) {
                foundBoxModel.selectEntry(boxId, false)
                recipBoxModel.removeEntry(boxId)
            }
        }
    } // DataboxList
} // Item