PageMessageSearch.qml 5.92 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
 *
 * 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
26
import QtQuick.Layouts 1.3
27
import cz.nic.mobileDatovka 1.0
28
import cz.nic.mobileDatovka.messages 1.0
29
import cz.nic.mobileDatovka.models 1.0
30 31 32 33 34 35

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

36 37
Item {
    id: pageMessageSearch
38

39 40 41
    /* These properties must be set by caller. */
    property var pageView
    property var statusBar
42

43
    property int soughtMsgType: MessageType.TYPE_RECEIVED | MessageType.TYPE_SENT
44

45 46 47
    Component.onCompleted: {
         searchPhraseText.forceActiveFocus()
    }
48 49 50 51 52

    Component.onDestruction: {
       statusBar.visible = false
    }

53 54
    MessageListModel {
        id: messageModel
55 56
        Component.onCompleted: {
        }
57 58 59 60
    }
    PageHeader {
        id: headerBar
        title: qsTr("Search message")
61 62
        onBackClicked: {
            pageView.pop(StackView.Immediate)
63
        }
64 65 66 67 68
        Row {
            anchors.verticalCenter: parent.verticalCenter
            spacing: defaultMargin
            anchors.right: parent.right
            anchors.rightMargin: defaultMargin
69
            AccessibleImageButton {
70 71
                id: actionButton
                anchors.verticalCenter: parent.verticalCenter
Martin Straka's avatar
Martin Straka committed
72
                sourceSize.height: imgHeightHeader
73
                source: "qrc:/ui/magnify.svg"
74 75 76 77 78 79
                accessibleName: qsTr("Search messages.")
                onClicked: {
                    // Set textfield focus on false = hide input keyboard
                    // and obtain textfield value
                    searchPhraseText.focus = false
                    emptyList.visible = searchPanel.doSearchRequest()
80 81 82
                }
            }
        }
83 84 85 86 87 88 89 90
    } // PageHeader
    Pane {
        id: searchPanel
        anchors.top: headerBar.bottom
        width: parent.width
        function doSearchRequest() {
            return (messages.searchMsg(messageModel, searchPhraseText.text, soughtMsgType) <= 0)
        }
91
        Column {
92 93
            anchors.right: parent.right
            anchors.left: parent.left
94
            spacing: formItemVerticalSpacing
95
            AccessibleComboBox {
96
                id: searchOptionComboBox
97
                width: parent.width
98
                accessibleDescription: qsTr("Select type of sought messages")
99 100
                model: ListModel {
                    id: searchOptionComboBoxModel
101 102 103 104
                    /* Cannot have an expression here because QML complains that it cannot use script for property key. */
                    ListElement { label: qsTr("All messages"); key: -1 }
                    ListElement { label: qsTr("Received messages"); key: MessageType.TYPE_RECEIVED }
                    ListElement { label: qsTr("Sent messages"); key: MessageType.TYPE_SENT }
105 106
                }
                onCurrentIndexChanged: {
107
                    if (currentKey() == -1) {
108 109
                        soughtMsgType = MessageType.TYPE_RECEIVED | MessageType.TYPE_SENT
                    } else {
110
                        soughtMsgType = currentKey()
111 112 113
                    }
                }
            }
114
            AccessibleTextField {
115 116 117
                id: searchPhraseText
                placeholderText: qsTr("Enter phrase")
                focus: true
118
                width: parent.width
119 120 121 122 123 124 125 126 127 128 129 130 131 132
                font.pointSize: defaultTextFont.font.pointSize
                height: inputItemHeight
                onAccepted: emptyList.visible = searchPanel.doSearchRequest()
                InputLineMenu {
                    id: searchPhraseTextMenu
                    inputTextControl: searchPhraseText
                    isPassword: false
                }
                onPressAndHold: {
                    if (settings.useExplicitClipboardOperations()) {
                        searchPhraseTextMenu.implicitWidth = computeMenuWidth(searchPhraseTextMenu)
                        searchPhraseTextMenu.open()
                    }
                }
133 134
            }
        }
135 136 137 138 139 140 141 142 143 144
    } // Pane
    Text {
        id: emptyList
        visible: false
        color: datovkaPalette.text
        anchors.centerIn: parent
        width: parent.width
        horizontalAlignment: Text.AlignHCenter
        wrapMode: Text.Wrap
        text: qsTr("No message found for given search phrase.")
145
    }
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    MessageList {
        id: messageList
        anchors.top: searchPanel.bottom
        anchors.bottom: parent.bottom
        clip: true
        spacing: 1
        opacity: 1
        visible: true
        width: parent.width
        interactive: true
        model: messageModel
        onMsgClicked: {
            statusBar.visible = false
            pageView.push(pageMessageDetail, {
                    "pageView": pageView,
                    "statusBar": statusBar,
                    "fromLocalDb": true,
                    "acntName": "",
                    "userName": userName,
                    "msgType": msgType,
                    "msgId": msgId,
                    "messageModel": messageModel
Martin Straka's avatar
Martin Straka committed
168
                })
169 170 171
        }
    } // MessageList
} // Item