main.qml 10.8 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
import QtQuick.Window 2.1
import QtQuick.Layouts 1.2
import QtQuick.Dialogs 1.2
30
import cz.nic.mobileDatovka 1.0
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

ApplicationWindow {

    // Get deafult color theme and palette from system
    SystemPalette { id: datovkaPalette; colorGroup: SystemPalette.Active }
    id: mainWindow
    visible: true
    title: "Datovka"
    width: 800
    height: 600
    color: datovkaPalette.window

    Text {
        id: defaultTextFont
        text: ""
    }

    // define all pages for stackview
    property Component accountsPage: AccountsPage {}
    property Component messagesPage: MessagesPage {}
51 52
    property Component messagesMenuPage: MessagesMenuPage {}
    property Component messageMenuPage: MessageMenuPage {}
53
    property Component messageDetailPage: MessageDetailPage {}
54
    property Component messageDetailMenuPage: MessageDetailMenuPage {}
55 56
    property Component accountDetailPage: AccountDetailPage {}
    property Component accountSettingsPage: AccountSettingsPage {}
57
    property Component accountMenuPage: AccountMenuPage {}
58
    property Component aboutPage: AboutPage {}
59 60 61 62
    property Component settingsMainPage: SettingsMainPage {}
    property Component settingsGeneralPage: SettingsGeneralPage {}
    property Component settingsSyncPage: SettingsSyncPage {}
    property Component settingsStoragePage: SettingsStoragePage {}
63 64
    property Component pinPage: PinPage {}

65 66 67 68
    // header background color
    property string mainHeaderBgColor: "#00539b"
    property int statusBarTimer: 5000
    // dimension and style based on font pixel size and screen dpi
69 70 71 72
    property int textFontSizeInPixels: defaultTextFont.font.pixelSize
    property int textPointSmall: Math.round(defaultTextFont.font.pointSize * 0.7)
    property int textFontSizeSmall: if (textPointSmall > 0) {textPointSmall} else {8}
    property int headerHeight: textFontSizeInPixels * 3
73 74 75 76 77
    property int imgHeight: headerHeight * 0.8
    property int navImgHeight: headerHeight * 0.3
    property int listItemHeight: headerHeight * 1.5
    property int defaultMargin: Math.round(Screen.pixelDensity)
    property int acntListSpacing: defaultMargin * 2
78
    property int formItemVerticalSpacing: defaultMargin * 3
79 80 81 82 83 84
    property int formButtonHorizontalSpacing: defaultMargin * 5
    // global passing arguments between pages
    property string gUserName
    property string gAcntName
    property int gMsgType
    property string gMsgId
85
    property bool gCanDeleteMsg: false
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

    /* compare message delivery date with current date-90days */
    property int deleteAfterDays: 90
    function compareMsgDate(msgDeliveryTime) {
        if (msgDeliveryTime == "") {
            // message has virus or delivery time missing
            return true
        } else {
            // convert qml date format to ISO date format
            var inputDateFormat = /(\d{2})\.(\d{2})\.(\d{4})/;
            var msgDate = new Date(msgDeliveryTime.replace(inputDateFormat,'$3-$2-$1'));
            var today = new Date()
            today.setDate(today.getDate()-deleteAfterDays)
            // compare both dates in milliseconds
            return (today.getTime() > msgDate.getTime())
        }
    }

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
    // page stack
    Rectangle  {
        id: mainPage
        anchors.fill: parent
        color: "transparent"
        visible: false
        StackView {
            id: pageView
            anchors.fill: parent
            visible: true
            initialItem: accountsPage
        }
    }
    Rectangle {
        id: statusBar
        visible: false
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        height: headerHeight * 0.5
        color: datovkaPalette.alternateBase
        BusyIndicator {
           id: busyuIndicator
127 128
           width: parent.height
           height: parent.height
129 130 131 132 133 134 135 136 137 138 139
           anchors.centerIn: parent
           running: false
        }
        Label {
            id: statusBarText
            color: datovkaPalette.text
            anchors.centerIn: parent
            text: mainWindow.width + " x "+ mainWindow.height
            Connections {
                target: isds
                onStatusBarTextChanged: {
140
                    statusBar.visible = isVisible
141 142 143 144 145 146 147 148
                    statusBarText.text = txt
                    busyuIndicator.running = busy
                    timerId.running = !busy
                }
            }
            Connections {
                target: files
                onStatusBarTextChanged: {
149 150 151 152 153 154
                    statusBar.visible = true
                    statusBarText.text = txt
                    busyuIndicator.running = busy
                    timerId.running = !busy
                }
            }
155 156 157 158 159 160 161 162 163
            Connections {
                target: settings
                onStatusBarTextChanged: {
                    statusBar.visible = true
                    statusBarText.text = txt
                    busyuIndicator.running = busy
                    timerId.running = !busy
                }
            }
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
        }
        Timer {
            id: timerId
            interval: statusBarTimer;
            running: false;
            repeat: false
            onTriggered: {
                timerId.running = false
                statusBar.visible = false
                statusBarText.text = ""
            }
        }
    }
    Rectangle  {
        id: pinScreen
        visible: false
        anchors.fill: parent
        color: "transparent"
182 183 184
        Component.onCompleted: {
            settings.loadVersion()
        }
185 186 187
        Column {
            spacing: formItemVerticalSpacing
            anchors.centerIn: parent
188 189 190 191 192 193 194 195 196 197 198
            Image{
                id: datovkaLogo
                anchors.horizontalCenter: parent.horizontalCenter
                width: imgHeight * 1.4
                height: imgHeight * 1.4
                source: "qrc:/datovka.png"
            }
            Text {
                id: versionLabel
                anchors.horizontalCenter: parent.horizontalCenter
                color: datovkaPalette.text
Karel Slaný's avatar
Karel Slaný committed
199
                text: qsTr("Version") + ": 1.0.0"
200 201 202 203 204 205 206 207
            }
            Rectangle {
                id: blankField
                width: formItemVerticalSpacing
                height: headerHeight
                color: "transparent"
                anchors.horizontalCenter: parent.horizontalCenter
            }
208 209
            TextField {
                id: pinCodeInput
Karel Slaný's avatar
Karel Slaný committed
210
                //focus: true // Forcing focus here causes troubles on mobile devices.
211
                echoMode: TextInput.Password
212
                passwordMaskDelay: 500 // milliseconds
213 214
                inputMethodHints: Qt.ImhDigitsOnly
                placeholderText: qsTr("Enter PIN code")
215 216
                anchors.horizontalCenter: parent.horizontalCenter
                horizontalAlignment: TextInput.AlignHCenter
217 218 219 220 221 222

                function verifyPin() {
                    settings.verifyPin(pinCodeInput.text.toString())
                }

                onEditingFinished: {
Karel Slaný's avatar
Karel Slaný committed
223 224 225 226 227 228
                    // This function is called repeatedly when switching
                    // windows. The condition should reduce PIN verification
                    // calls.
                    if (pinCodeInput.text.length > 0) {
                        verifyPin()
                    }
229
                }
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
            }
            Text {
                id: wrongPin
                font.bold: true
                visible: false
                color: datovkaPalette.text
                anchors.horizontalCenter: parent.horizontalCenter
                text: qsTr("Wrong PIN code!")
            }
            Row {
                spacing: formButtonHorizontalSpacing
                anchors.horizontalCenter: parent.horizontalCenter
                Button {
                    text: qsTr("Enter")
                    onClicked: {
245
                        pinCodeInput.verifyPin()
246 247 248 249
                    }
                }
            }
        }
250 251 252 253 254 255
        Connections {
             target: settings
             onSendVersionData: {
                 versionLabel.text = qsTr("Version") + ": " + version
              }
        }
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
        Connections {
            target: settings
            onShowPinScreen: {
                if (show) {
                    mainPage.visible = false
                    pinScreen.visible = true
                } else {
                    pinScreen.visible = false
                    mainPage.visible = true
                }
            }
        }
        Connections {
            target: settings
            onSendPinReply: {
                if (success) {
                    Qt.inputMethod.hide()
                    pinScreen.visible = false
                    mainPage.visible = true
                }
Karel Slaný's avatar
Karel Slaný committed
276 277
                wrongPin.visible = !success
                pinCodeInput.text = ""
278 279
            }
        }
280 281 282 283 284 285 286
        Connections {
            target: locker
            onLockApp: {
                mainPage.visible = false
                pinScreen.visible = true
            }
        }
287 288 289 290 291 292 293 294 295
    }
    Item {
        id: backButton
        focus: true
        Keys.onReleased: {
            if (event.key === Qt.Key_Back) {
                event.accepted = true
                if (pageView.depth > 1) {
                    event.accepted = true
Karel Slaný's avatar
Karel Slaný committed
296
                    pageView.pop(StackView.Immediate)
297 298 299 300 301 302 303
                } else {
                    event.accepted = false
                    Qt.quit()
                }
            }
        }
    }
304 305 306 307 308 309 310 311
    Text {
        id: dummyText
        text: ""
        visible: false
        wrapMode: Text.NoWrap
        elide: Text.ElideNone
    }
    function computeMenuWidth(menu) {
312
        var w = 0.0
313
        for (var i = 0; i < menu.contentData.length; i++) {
314
            dummyText.text = menu.contentData[i].text + "www"
315 316 317 318 319
            if (w < dummyText.width) {
                w = dummyText.width
            }
        }
        dummyText.text = ""
320
        return Math.round(w)
321
    }
322
}