MainBlock.qml 3.83 KB
Newer Older
David Edmundson's avatar
David Edmundson committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 *   Copyright 2016 David Edmundson <davidedmundson@kde.org>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Library General Public License as
 *   published by the Free Software Foundation; either version 2 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 Library General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import QtQuick 2.2
21
22
23

import QtQuick.Layouts 1.1
import QtQuick.Controls 1.1
David Edmundson's avatar
David Edmundson committed
24

25
import org.kde.plasma.core 2.0 as PlasmaCore
26
import org.kde.plasma.components 3.0 as PlasmaComponents3
David Edmundson's avatar
David Edmundson committed
27

28
29
import "../components"

David Edmundson's avatar
David Edmundson committed
30
SessionManagementScreen {
31
32

    property Item mainPasswordBox: passwordBox
33
    property bool lockScreenUiVisible: false
34
35
36
37

    //the y position that should be ensured visible when the on screen keyboard is visible
    property int visibleBoundary: mapFromItem(loginButton, 0, 0).y
    onHeightChanged: visibleBoundary = mapFromItem(loginButton, 0, 0).y + loginButton.height + units.smallSpacing
David Edmundson's avatar
David Edmundson committed
38
39
40
41
42
    /*
     * Login has been requested with the following username and password
     * If username field is visible, it will be taken from that, otherwise from the "name" property of the currentIndex
     */
    signal loginRequest(string password)
43

David Edmundson's avatar
David Edmundson committed
44
45
46
47
    function startLogin() {
        var password = passwordBox.text

        //this is partly because it looks nicer
Yuri Chornoivan's avatar
Yuri Chornoivan committed
48
        //but more importantly it works round a Qt bug that can trigger if the app is closed with a TextField focused
David Edmundson's avatar
David Edmundson committed
49
50
51
        //See https://bugreports.qt.io/browse/QTBUG-55460
        loginButton.forceActiveFocus();
        loginRequest(password);
52
53
    }

54
    RowLayout {
David Edmundson's avatar
David Edmundson committed
55
56
        Layout.fillWidth: true

57
        PlasmaComponents3.TextField {
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
            id: passwordBox
            font.pointSize: theme.defaultFont.pointSize + 1
            Layout.fillWidth: true

            placeholderText: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Password")
            focus: true
            echoMode: TextInput.Password
            inputMethodHints: Qt.ImhHiddenText | Qt.ImhSensitiveData | Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
            enabled: !authenticator.graceLocked
            revealPasswordButtonShown: true

            onAccepted: {
                if (lockScreenUiVisible) {
                    startLogin();
                }
73
            }
David Edmundson's avatar
David Edmundson committed
74

75
76
77
78
79
80
81
82
83
84
85
            //if empty and left or right is pressed change selection in user switch
            //this cannot be in keys.onLeftPressed as then it doesn't reach the password box
            Keys.onPressed: {
                if (event.key == Qt.Key_Left && !text) {
                    userList.decrementCurrentIndex();
                    event.accepted = true
                }
                if (event.key == Qt.Key_Right && !text) {
                    userList.incrementCurrentIndex();
                    event.accepted = true
                }
David Edmundson's avatar
David Edmundson committed
86
            }
87

88
89
            Connections {
                target: root
90
                function onClearPassword() {
91
                    passwordBox.forceActiveFocus()
92
                    passwordBox.text = "";
93
                }
94
95
            }
        }
David Edmundson's avatar
David Edmundson committed
96

97
        PlasmaComponents3.Button {
98
99
            id: loginButton
            Accessible.name: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Unlock")
100
101
            Layout.preferredHeight: passwordBox.implicitHeight
            Layout.preferredWidth: loginButton.Layout.preferredHeight
102
103

            icon.name: "go-next"
104
105
106

            onClicked: startLogin()
        }
David Edmundson's avatar
David Edmundson committed
107
    }
108
}