MessagesPage.qml 11.6 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
/*
 * Copyright (C) 2014-2016 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.
 */


25
import QtQuick 2.7
Karel Slaný's avatar
Karel Slaný committed
26
import QtQuick.Controls 2.0
27
28
29
30
import QtQuick.Window 2.1
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
import QtGraphicalEffects 1.0
31
import cz.nic.mobileDatovka.messages 1.0
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

Component {
    id: messagespage
    Item {
        id: msgListPage
        Component.onCompleted: {
            if (messageList.count == 0) {
                emptyList.visible = true
                settingsButton.visible = false
            }
        }
        Rectangle {
            id: header2
            anchors.top: parent.top
            width: parent.width
            height: headerHeight
            color: datovkaPalette.highlight
            Image {
                id: backElement2
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left
                anchors.leftMargin: defaultMargin
                sourceSize.height: navImgHeight
                source: "qrc:/ui/back.svg"
            }
            Rectangle {
                anchors.left: parent.left
                width: parent.width * 0.5
                height: parent.height
                color: "transparent"
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        messages.clearMessagesModel()
                        accounts.updateNewMessageCounter(gUserName)
                        statusBar.visible = false
Karel Slaný's avatar
Karel Slaný committed
68
                        pageView.pop(StackView.Immediate)
69
70
71
72
73
74
75
76
77
78
79
80
81
82
                    }
                }
            }
            Column {
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: backElement2.right
                anchors.leftMargin: defaultMargin
                Label {
                    text: gAcntName + " (" + gUserName + ")"
                    font.bold: true
                    color: datovkaPalette.text
                }
                Label {
                    text: {
83
                        if (gMsgType == MessageType.TYPE_RECEIVED) {
84
                            qsTr("Received messages")
85
86
                        } else {
                            qsTr("Sent messages")
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
                        }
                    }
                    font.bold: true
                    color: datovkaPalette.text
                }
            }
            Row {
                anchors.verticalCenter: parent.verticalCenter
                spacing: defaultMargin
                anchors.right: parent.right
                anchors.rightMargin: defaultMargin
                Image {
                    id: settingsButton
                    anchors.verticalCenter: parent.verticalCenter
                    sourceSize.height: imgHeight
                    source: "qrc:/ui/settings.svg"
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
106
107
                            statusBar.visible = false
                            pageView.push(messagesMenuPage, StackView.Immediate)
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
135
136
137
138
139
140
141
142
143
144
145
146
                        }
                    }
                }
            }
        }
        Text {
            id: emptyList
            visible: false
            color: datovkaPalette.text
            anchors.centerIn: parent
            text: qsTr("Messages have not been downloaded yet.")
        }
        ListView {
            id: messageList
            anchors.top: header2.bottom
            anchors.bottom: parent.bottom
            clip: true
            spacing: 1
            opacity: 1
            visible: true
            width: parent.width
            interactive: true
            model: messageListModel
            onCountChanged: {
                if (messageList.count == 0) {
                    emptyList.visible = true
                    settingsButton.visible = false
                } else {
                    emptyList.visible = false
                    settingsButton.visible = true
                }
            }
            delegate:
                Rectangle {
                id: messageItem
                height: listItemHeight
                width: parent.width
                color: if (rReadLocally) {
                           datovkaPalette.alternateBase
147
148
                       } else {
                           datovkaPalette.base
149
150
151
152
153
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
                       }
                Rectangle {
                    id: msgEnvelope
                    anchors.left: parent.left
                    anchors.leftMargin: defaultMargin
                    height: parent.height
                    width: parent.width * 0.95
                    color: parent.color
                    GridLayout {
                        id: grid
                        columns: 2
                        rows: 3
                        rowSpacing: defaultMargin * 0.2
                        columnSpacing: defaultMargin
                        anchors.verticalCenter: parent.verticalCenter
                        Rectangle {
                            id: r1c1
                            width: defaultMargin * 3
                            Layout.fillHeight: true
                            color: "transparent"
                            Image {
                                id: r1c1p
                                anchors.centerIn: parent
                                sourceSize.height: parent.height * 0.8
                                source: if (rReadLocally) {
                                    "qrc:/ui/email-open-outline.svg"
                                } else {
                                    "qrc:/ui/email-outline.svg"
                                }
                            }
                            ColorOverlay {
                                anchors.fill: r1c1p
                                source: r1c1p
                                color: datovkaPalette.text
                            }
                        }
                        Text {
                            id: r1c2
                            text: rFromTo
188
189
190
191
192
                            color: if (rReadLocally) {
                                datovkaPalette.dark
                            } else {
                                datovkaPalette.highlight
                            }
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
                            font.bold: true
                        }
                        Rectangle {
                            id: r2c1
                            width: defaultMargin * 3
                            Layout.fillHeight: true
                            color: "transparent"
                            Image {
                                id: r2c1p
                                anchors.centerIn: parent
                                sourceSize.height: parent.height * 0.8
                                source: if (rAttachmentsDownloaded) {
                                    "qrc:/ui/paperclip.svg"
                                } else {
                                    "qrc:/ui/datovka-msg-blank.png"
                                }
                            }
                            ColorOverlay {
                                anchors.fill: r2c1p
                                source: r2c1p
                                color: datovkaPalette.text
                            }
                        }
                        Text {
                            id: r2c2
                            text: rAnnotation
                            color: datovkaPalette.text
                            font.bold: true
                        }
                        Image {
                            id: r3c1
                            anchors.centerIn: parent
                            sourceSize.width: 1
                            fillMode: Image.PreserveAspectFit
                            source: "qrc:/ui/datovka-msg-blank.png"
                        }
                        Text {
                            id: r3c2
                            text: rMsgId + "     " + rDelivTime + "     " + rAcceptTime
                            color: datovkaPalette.mid
233
                            font.pointSize: textFontSizeSmall
234
                            renderType: Text.NativeRendering
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
                            font.bold: true
                        }
                    }
                }
                Rectangle {
                    id: next
                    anchors.verticalCenter: parent.verticalCenter
                    anchors.right: parent.right
                    height: parent.height
                    width: parent.width * 0.07
                    color: parent.color
                    Image {
                        id: nextImage
                        anchors.verticalCenter: parent.verticalCenter
                        anchors.right: parent.right
                        anchors.rightMargin: defaultMargin
                        sourceSize.height: navImgHeight
                        source: "qrc:/ui/next.svg"
                    }
                    ColorOverlay {
                        anchors.fill: nextImage
                        source: nextImage
                        color: datovkaPalette.text
                    }
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        gMsgId = rMsgId
                        statusBar.visible = false
Karel Slaný's avatar
Karel Slaný committed
265
                        pageView.push(messageDetailPage, StackView.Immediate)
266
                        messages.markMessageAsLocallyRead(gUserName, rMsgId, true)
267
268
269
                        messages.fillMessageDetail(gUserName, rMsgId)
                        files.fillFileList(gUserName, rMsgId)
                    }
270
271
                    onPressAndHold: {
                        gMsgId = rMsgId
272
                        gCanDeleteMsg = compareMsgDate(rDelivTime)
273
                        statusBar.visible = false
274
                        pageView.push(messageMenuPage, StackView.Immediate)
275
                    }
276
277
278
279
280
281
282
283
                }
                Rectangle {
                    anchors.top: parent.bottom
                    height: 1
                    width: parent.width
                    color: datovkaPalette.mid
                }
            }
284
285
286
287
288

            property bool downloadStart: false
            onMovementEnded: {
                if (downloadStart) {
                    downloadStart = false
289
                    if (gMsgType == MessageType.TYPE_RECEIVED) {
290
                        isds.syncSingleAccountReceived(gUserName)
291
                    } else if (gMsgType == MessageType.TYPE_SENT) {
292
293
294
295
296
297
298
299
                        isds.syncSingleAccountSent(gUserName)
                    }
                    messages.fillMessageList(gUserName, gMsgType)
                }
            }
            onDragEnded: {
                downloadStart = contentY < -120
            }
300
301
302
        }
    }
}