PageAccountList.qml 20.4 KB
Newer Older
1
/*
2
 * Copyright (C) 2014-2018 CZ.NIC
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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.
 */

24
import QtQuick 2.7
25
import QtQuick.Controls 2.1
26 27
import QtQuick.Layouts 1.2
import QtGraphicalEffects 1.0
28
import cz.nic.mobileDatovka 1.0
29
import cz.nic.mobileDatovka.messages 1.0
30
import cz.nic.mobileDatovka.models 1.0
31

32 33 34 35 36
/*
 * Roles are defined in AccountListModel::roleNames() and are accessed directly
 * via their names.
 */

37
Component {
Karel Slaný's avatar
Karel Slaný committed
38
    id: pageAccountList
39 40
    Item {
        id: mainPage
41 42 43 44 45 46 47 48 49 50

        /* These properties must be set by caller. */
        //property var pageView
        //property var statusBar
        /*
         * TODO -- Is there a way how to pas the pageView as a property?
         * This pageView property is not passed because the page is created
         * within the StackView.
         */

51 52 53 54
        Component.onCompleted: {
            if (accountList.count == 0) {
                accountList.visible = false
                emptyList.visible = true
55 56
                syncAllButton.visible = false
                syncAllButton.enabled = false
57 58
            }
        }
59 60 61 62 63 64 65 66 67 68 69 70 71 72

        /*
         * The account list model is created by C++ code because the accounts
         * need to be set up and saved from within the main function.
         * But, the account model is explicitly passed to other QML pages just
         * to maintain consistency with other models and to emphasise the fact
         * that the pages need to access the model.
         */
        //AccountListModel {
        //    id: mainAccountModel
        //
        //    Component.onCompleted: {
        //    }
        //}
73
        property var accountModel: mainAccountModel /* Cannot use an alias here. */
74

75 76 77 78 79 80
        Rectangle {
            id: datovkaHeader
            anchors.top: parent.top
            width: parent.width
            height: headerHeight
            color: mainHeaderBgColor
81
            AccessibleImageButton {
Martin Straka's avatar
Martin Straka committed
82
                id: headerLogo
Martin Straka's avatar
Martin Straka committed
83 84
                anchors.left: parent.left
                anchors.leftMargin: defaultMargin
Martin Straka's avatar
Martin Straka committed
85
                anchors.verticalCenter: parent.verticalCenter
Martin Straka's avatar
Martin Straka committed
86
                sourceSize.height: imgHeightHeader
87
                source: "qrc:/ui/datovka@2x.png"
88 89 90 91 92 93
                accessibleName: qsTr("Show information about the application.")
                onClicked: {
                    pageView.push(pageAboutApp, {
                        "pageView": pageView,
                        "statusBar": statusBar
                    }, StackView.Immediate)
94 95 96 97 98 99 100
                }
            }
            Row {
                anchors.verticalCenter: parent.verticalCenter
                spacing: defaultMargin
                anchors.right: parent.right
                anchors.rightMargin: defaultMargin
101
                AccessibleImageButton {
102 103
                    id: syncAllButton
                    anchors.verticalCenter: parent.verticalCenter
Martin Straka's avatar
Martin Straka committed
104
                    sourceSize.height: imgHeightHeader
105
                    source: "qrc:/ui/sync-all.svg"
106 107 108
                    accessibleName: qsTr("Synchronise all accounts.")
                    onClicked: {
                        isds.doIsdsAction("syncAllAccounts", "")
109 110
                    }
                }
111
                AccessibleImageButton {
Martin Straka's avatar
Martin Straka committed
112 113
                    id: settingsButton
                    anchors.verticalCenter: parent.verticalCenter
Martin Straka's avatar
Martin Straka committed
114
                    sourceSize.height: imgHeightHeader
Martin Straka's avatar
Martin Straka committed
115
                    source: "qrc:/ui/menu.svg"
116 117 118 119 120 121 122
                    accessibleName: qsTr("Show application preferences.")
                    onClicked: {
                        pageView.push(pageMenuDatovkaSettings, {
                                "pageView": pageView,
                                "statusBar": statusBar,
                                "accountModel": accountModel
                            }, StackView.Immediate)
Martin Straka's avatar
Martin Straka committed
123 124
                    }
                }
125 126
            }
        }
127
        AccessibleTextButton {
128 129 130 131
            id: emptyList
            visible: false
            color: datovkaPalette.text
            anchors.centerIn: parent
132 133
            font.bold: true
            text: qsTr("Add a new account")
134 135 136 137 138 139 140 141
            onClicked: {
                pageView.push(pageSettingsAccount, {
                        "pageView": pageView,
                        "statusBar": statusBar,
                        "acntName": "",
                        "userName": "",
                        "accountModel": accountModel
                    }, StackView.Immediate)
142
            }
143
        }
144
        ScrollableListView {
145
            id: accountList
146 147 148

            delegateHeight: headerHeight * 3

149 150 151 152 153 154 155 156
            anchors.top: datovkaHeader.bottom
            anchors.bottom: parent.bottom
            clip: true
            spacing: acntListSpacing
            opacity: 1
            visible: true
            width: parent.width
            interactive: true
157
            model: accountModel
158 159 160 161
            onCountChanged: {
                if (accountList.count == 0) {
                    accountList.visible = false
                    emptyList.visible = true
162 163
                    syncAllButton.enabled = false
                    syncAllButton.visible = false
164 165 166
                } else {
                    accountList.visible = true
                    emptyList.visible = false
167 168
                    syncAllButton.enabled = true
                    syncAllButton.visible = true
169 170 171 172 173
                }
            }
            delegate: Item {
                id: accountItem
                width: parent.width
174
                height: accountList.delegateHeight
175 176 177 178 179
                ColumnLayout {
                    spacing: 0
                    width: parent.width
                    height: parent.height
                    anchors.fill: parent
180
                    Rectangle { // account description line
181
                        id: accountHeader
182
                        color: (!rTestAccount ? headerColor : datovkaPalette.dark) // Testing accounts are shown in dark colour.
183
                        width: parent.width
184 185 186
                        Layout.fillHeight: true
                        Layout.preferredWidth: parent.width
                        Layout.preferredHeight: headerHeight
187 188 189 190 191
                        Image {
                            id: accountImage
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.left: parent.left
                            anchors.leftMargin: defaultMargin
Martin Straka's avatar
Martin Straka committed
192
                            sourceSize.height: imgHeightHeader
193
                            source: "qrc:/ui/account-box.svg"
194
                        }
195 196 197 198
                        Rectangle {
                            anchors.top: parent.top
                            height: 1
                            width: parent.width
199
                            color: datovkaPalette.dark
200
                        }
201 202
                        Column {
                            anchors.verticalCenter: parent.verticalCenter
203
                            anchors.left: accountImage.right
204 205 206 207 208 209 210 211 212
                            Row {
                                spacing: defaultMargin
                                anchors.left: parent.left
                                anchors.leftMargin: defaultMargin
                                Text {
                                    id: accountName
                                    text: rAcntName
                                    color: datovkaPalette.text
                                    font.bold: true
213
                                    font.italic: !rStoreIntoDb // Ephemeral accounts use italics.
214 215 216 217
                                }
                                Text {
                                    id: uName
                                    anchors.verticalCenter: parent.verticalCenter
218
                                    text: "" // "(" + rUserName + ")" // Don't display user name.
219
                                    color: datovkaPalette.text
220
                                    font.pointSize: textFontSizeSmall
221
                                    font.italic: !rStoreIntoDb // Ephemeral accounts use italics.
222
                                    renderType: Text.NativeRendering
223 224 225 226 227 228 229 230 231
                                }
                            }
                        }
                        Rectangle {
                            anchors.left: parent.left
                            width: parent.width * 0.7
                            height: parent.height
                            color: "transparent"
                            MouseArea {
232
                                function handleClick() {
233
                                    statusBar.visible = false
234 235 236 237
                                    pageView.push(pageMenuAccount, {
                                            "pageView": pageView,
                                            "statusBar": statusBar,
                                            "acntName": rAcntName,
238
                                            "userName": rUserName,
239
                                            "accountModel": accountModel
240
                                        }, StackView.Immediate)
241
                                }
242 243 244 245

                                anchors.fill: parent

                                Accessible.role: Accessible.Button
Karel Slaný's avatar
Karel Slaný committed
246
                                Accessible.name: !rTestAccount ? qsTr("Account '%1'.").arg(rAcntName) : qsTr("Testing account '%1'.").arg(rAcntName)
247 248
                                Accessible.onScrollDownAction: accountList.scrollDown()
                                Accessible.onScrollUpAction: accountList.scrollUp()
249 250 251 252 253 254
                                Accessible.onPressAction: {
                                    handleClick()
                                }
                                onClicked: {
                                    handleClick()
                                }
255 256
                            }
                        }
257
                        AccessibleImageButton {
258 259 260 261
                            id: syncThisButton
                            anchors.right: parent.right
                            anchors.rightMargin: defaultMargin
                            anchors.verticalCenter: parent.verticalCenter
Martin Straka's avatar
Martin Straka committed
262
                            sourceSize.height: imgHeightHeader
263
                            source: "qrc:/ui/sync.svg"
264
                            accessibleName: qsTr("Synchronise account '%1'.").arg(rAcntName)
265 266
                            onClicked: {
                                isds.doIsdsAction("syncOneAccount", rUserName)
267
                            }
268 269 270 271 272 273
                        }
                        ColorOverlay {
                            anchors.fill: syncThisButton
                            source: syncThisButton
                            color: datovkaPalette.text
                        }
274 275 276 277 278 279
                        Rectangle {
                            anchors.bottom: parent.bottom
                            height: 1
                            width: parent.width
                            color: datovkaPalette.mid
                        }
280
                    }
281
                    Rectangle { // received messages line
282
                        color: datovkaPalette.base
283
                        width: parent.width
284 285 286 287 288 289 290 291
                        Layout.fillHeight: true
                        Layout.preferredWidth: parent.width
                        Layout.preferredHeight: headerHeight
                        Image {
                            id: msgRecievedImage
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.left: parent.left
                            anchors.leftMargin: defaultMargin
Martin Straka's avatar
Martin Straka committed
292
                            sourceSize.height: imgHeightHeader
293
                            source: "qrc:/ui/received-msgs.svg"
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
                        }
                        ColorOverlay {
                            anchors.fill: msgRecievedImage
                            source: msgRecievedImage
                            color: datovkaPalette.text
                        }
                        Text {
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.left: msgRecievedImage.right
                            anchors.leftMargin: defaultMargin
                            color: datovkaPalette.text
                            text: qsTr("Received messages") + "   [" + rRcvdUnread + "/" + rRcvdTotal + "]"
                            font.bold: true
                        }
                        Rectangle {
                            id: next1
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.right: parent.right
                            height: parent.height
                            width: parent.width * 0.07
                            color: parent.color
                            Image {
                                id: nextImage1
                                anchors.verticalCenter: parent.verticalCenter
                                anchors.right: parent.right
                                anchors.rightMargin: defaultMargin
                                sourceSize.height: navImgHeight
                                source: "qrc:/ui/next.svg"
                            }
                            ColorOverlay {
                                anchors.fill: nextImage1
                                source: nextImage1
                                color: datovkaPalette.text
                            }
                        }
                        MouseArea {
330
                            function handleClick() {
331
                                statusBar.visible = false
332 333 334 335 336
                                pageView.push(pageMessageList, {
                                        "pageView": pageView,
                                        "statusBar": statusBar,
                                        "acntName": rAcntName,
                                        "userName": rUserName,
337
                                        "msgType": MessageType.TYPE_RECEIVED,
338
                                        "accountModel": accountModel
339
                                    })
340
                            }
341 342 343 344 345

                            anchors.fill: parent

                            Accessible.role: Accessible.Button
                            Accessible.name: qsTr("Received messages of account '%1'. (Unread %2 of %3 received messages.)").arg(rAcntName).arg(rRcvdUnread).arg(rRcvdTotal)
346 347
                            Accessible.onScrollDownAction: accountList.scrollDown()
                            Accessible.onScrollUpAction: accountList.scrollUp()
348 349 350 351 352 353
                            Accessible.onPressAction: {
                                handleClick()
                            }
                            onClicked: {
                                handleClick()
                            }
354 355 356 357 358 359 360 361
                        }
                        Rectangle {
                            anchors.bottom: parent.bottom
                            height: 1
                            width: parent.width
                            color: datovkaPalette.mid
                        }
                    }
362
                    Rectangle { // sent messages line
363
                        color: datovkaPalette.base
364
                        width: parent.width
365 366 367 368 369 370 371 372
                        Layout.fillHeight: true
                        Layout.preferredWidth: parent.width
                        Layout.preferredHeight: headerHeight
                        Image {
                            id: msgSentImage
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.left: parent.left
                            anchors.leftMargin: defaultMargin
Martin Straka's avatar
Martin Straka committed
373
                            sourceSize.height: imgHeightHeader
374
                            source: "qrc:/ui/sent-msgs.svg"
375 376 377 378 379 380 381 382 383 384 385
                        }
                        ColorOverlay {
                            anchors.fill: msgSentImage
                            source: msgSentImage
                            color: datovkaPalette.text
                        }
                        Text {
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.left: msgSentImage.right
                            anchors.leftMargin: defaultMargin
                            color: datovkaPalette.text
386
                            text: qsTr("Sent messages") + "   [" + rSntTotal + "]"
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
                            font.bold: true
                        }
                        Rectangle {
                            id: next2
                            anchors.verticalCenter: parent.verticalCenter
                            anchors.right: parent.right
                            height: parent.height
                            width: parent.width * 0.07
                            color: parent.color
                            Image {
                                id: nextImage2
                                anchors.verticalCenter: parent.verticalCenter
                                anchors.right: parent.right
                                anchors.rightMargin: defaultMargin
                                sourceSize.height: navImgHeight
                                source: "qrc:/ui/next.svg"
                            }
                            ColorOverlay {
                                anchors.fill: nextImage2
                                source: nextImage2
                                color: datovkaPalette.text
                            }
                        }
                        MouseArea {
411
                            function handleClick() {
412
                                statusBar.visible = false
413 414 415 416 417
                                pageView.push(pageMessageList, {
                                        "pageView": pageView,
                                        "statusBar": statusBar,
                                        "acntName": rAcntName,
                                        "userName": rUserName,
418
                                        "msgType": MessageType.TYPE_SENT,
419
                                        "accountModel": accountModel
420
                                    })
421
                            }
422 423 424 425 426

                            anchors.fill: parent

                            Accessible.role: Accessible.Button
                            Accessible.name: qsTr("Sent messages of account '%1'. (Total of %2 sent messages.)").arg(rAcntName).arg(rSntTotal)
427 428
                            Accessible.onScrollDownAction: accountList.scrollDown()
                            Accessible.onScrollUpAction: accountList.scrollUp()
429 430 431 432 433 434
                            Accessible.onPressAction: {
                                handleClick()
                            }
                            onClicked: {
                                handleClick()
                            }
435 436 437 438 439
                        }
                        Rectangle {
                            anchors.bottom: parent.bottom
                            height: 1
                            width: parent.width
440
                            color: datovkaPalette.dark
441 442 443 444
                        }
                    }
                }
            }
445
            ScrollIndicator.vertical: ScrollIndicator {}
446
        }
447 448 449 450 451 452 453 454 455
        Connections {
            target: isds
            onDownloadMessageListFinishedSig: {
                if (isMsgReceived) {
                    settings.setLastUpdateToNow()
                    settings.saveAllSettings(accountModel)
                }
            }
        }
456 457 458 459
        Connections {
            target: isds
            onRunSyncOneAccountSig: isds.syncOneAccount(accountModel, userName)
        }
460 461
    }
}