InputDialogue.qml 2.99 KB
Newer Older
Martin Straka's avatar
Martin Straka committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
 * Copyright (C) 2014-2017 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.
 */

import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.1

/*
 * Input dialog for password or OTP code.
 */
Dialog {
    id: root

34
    signal finished(string isdsAction, string pwdType, string userName, string pwd)
Martin Straka's avatar
Martin Straka committed
35 36

    property int minimumInputSize: parent.width / 2
37 38
    property string dIsdsAction
    property string dPwdType
Martin Straka's avatar
Martin Straka committed
39 40
    property string dUserName

41 42 43
    function openInputDialog(isdsAction, pwdType, userName, title, text, placeholderText, hidePwd) {
        dIsdsAction = isdsAction
        dPwdType = pwdType
Martin Straka's avatar
Martin Straka committed
44 45 46 47
        dUserName = userName
        root.title = title
        roottext.text = text
        rootpwd.clear()
48
        rootpwd.placeholderText = placeholderText
Martin Straka's avatar
Martin Straka committed
49
        rootpwd.echoMode = (hidePwd) ? TextInput.Password : TextInput.Normal
50
        if (pwdType == "totp" || pwdType == "hotp") {
51 52 53
            rootpwd.inputMethodHints = Qt.ImhPreferNumbers
        } else {
            rootpwd.inputMethodHints = Qt.ImhNone
54
        }
55
        rootpwd.focus = true
Martin Straka's avatar
Martin Straka committed
56 57 58
        root.open()
    }

59
    // center dialogue
Martin Straka's avatar
Martin Straka committed
60
    x: parent.width / 2 - width / 2
61
    y: parent.height / 2 - height / 2
Martin Straka's avatar
Martin Straka committed
62

Martin Straka's avatar
Martin Straka committed
63 64 65
    // show dialogue in 1/3 of vertical screen size (ios)
    //y: parent.height / 2 - height

Martin Straka's avatar
Martin Straka committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    focus: true
    modal: true
    title: qsTr("QML input dialog")
    standardButtons: Dialog.Ok | Dialog.Cancel

    contentItem: ColumnLayout {
        Text {
            id: roottext
            Layout.fillWidth: true
            Layout.minimumWidth: minimumInputSize
            text: ""
            Layout.alignment: Qt.AlignLeft | Qt.AlignBaseline
            wrapMode: Text.WordWrap
        }
        TextField {
            id: rootpwd
            focus: true
            Layout.fillWidth: true
            Layout.minimumWidth: minimumInputSize
            Layout.alignment: Qt.AlignLeft | Qt.AlignBaseline
            echoMode: TextInput.Normal
            placeholderText: placeholderText
            horizontalAlignment: TextInput.AlignHCenter
        }
    } // ColumnLayout

92
    onAccepted: finished(dIsdsAction, dPwdType, dUserName, rootpwd.text.toString())
Martin Straka's avatar
Martin Straka committed
93
}