Untitled diff

Created Diff never expires
14 removals
101 lines
5 additions
92 lines
/*
/*
* Copyright 2016 David Edmundson <davidedmundson@kde.org>
* Copyright 2016 David Edmundson <davidedmundson@kde.org>
*
*
* This program is free software; you can redistribute it and/or modify
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 or
* published by the Free Software Foundation; either version 2 or
* (at your option) any later version.
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details
* GNU General Public License for more details
*
*
* You should have received a copy of the GNU Library General Public
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
*/


import QtQuick 2.2
import QtQuick 2.2


import QtQuick.Layouts 1.1
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.1
import QtQuick.Controls 1.1


import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.components 2.0 as PlasmaComponents


import "../components"
import "../components"


SessionManagementScreen {
SessionManagementScreen {


property Item mainPasswordBox: passwordBox
property Item mainPasswordBox: passwordBox
property bool lockScreenUiVisible: false
property bool lockScreenUiVisible: false


//the y position that should be ensured visible when the on screen keyboard is visible
//the y position that should be ensured visible when the on screen keyboard is visible
property int visibleBoundary: mapFromItem(loginButton, 0, 0).y
property int visibleBoundary: mapFromItem(passwordBox, 0, 0).y + passwordBox.height + units.smallSpacing
onHeightChanged: visibleBoundary = mapFromItem(loginButton, 0, 0).y + loginButton.height + units.smallSpacing
onHeightChanged: visibleBoundary = mapFromItem(passwordBox, 0, 0).y + passwordBox.height + units.smallSpacing
/*
/*
* Login has been requested with the following username and password
* 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
* If username field is visible, it will be taken from that, otherwise from the "name" property of the currentIndex
*/
*/
signal loginRequest(string password)
signal loginRequest(string password)


function startLogin() {
function startLogin() {
var password = passwordBox.text
var password = passwordBox.text


//this is partly because it looks nicer
//this is partly because it looks nicer
//but more importantly it works round a Qt bug that can trigger if the app is closed with a TextField focused
//but more importantly it works round a Qt bug that can trigger if the app is closed with a TextField focused
//See https://bugreports.qt.io/browse/QTBUG-55460
//See https://bugreports.qt.io/browse/QTBUG-55460
loginButton.forceActiveFocus();
loginRequest(password);
loginRequest(password);
}
}


PlasmaComponents.TextField {
PlasmaComponents.TextField {
id: passwordBox
id: passwordBox
Layout.fillWidth: true
Layout.fillWidth: true


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


onAccepted: {
onAccepted: {
if (lockScreenUiVisible) {
if (lockScreenUiVisible) {
startLogin();
startLogin();
}
}
}
}


//if empty and left or right is pressed change selection in user switch
//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
//this cannot be in keys.onLeftPressed as then it doesn't reach the password box
Keys.onPressed: {
Keys.onPressed: {
if (event.key == Qt.Key_Left && !text) {
if (event.key == Qt.Key_Left && !text) {
userList.decrementCurrentIndex();
userList.decrementCurrentIndex();
event.accepted = true
event.accepted = true
}
}
if (event.key == Qt.Key_Right && !text) {
if (event.key == Qt.Key_Right && !text) {
userList.incrementCurrentIndex();
userList.incrementCurrentIndex();
event.accepted = true
event.accepted = true
}
}
}
}


Connections {
Connections {
target: root
target: root
onClearPassword: {
onClearPassword: {
passwordBox.forceActiveFocus()
passwordBox.forceActiveFocus()
passwordBox.selectAll()
passwordBox.selectAll()
}
}
}
}
}

PlasmaComponents.Button {
id: loginButton
Layout.fillWidth: true

text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Unlock")
onClicked: startLogin()
}
}
}
}