2024-10-15 19:26:12 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Layouts 1.15
|
|
|
|
import QtQuick.Controls 2.15
|
2022-07-21 11:29:18 +00:00
|
|
|
|
|
|
|
import StatusQ.Core 0.1
|
|
|
|
import StatusQ.Core.Theme 0.1
|
|
|
|
import StatusQ.Controls 0.1
|
|
|
|
import StatusQ.Controls.Validators 0.1
|
|
|
|
|
|
|
|
import utils 1.0
|
|
|
|
|
|
|
|
import "../stores"
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
|
|
|
property StartupStore startupStore
|
|
|
|
|
2022-11-16 18:35:40 +00:00
|
|
|
property int remainingAttempts: root.startupStore.startupModuleInst.remainingAttempts
|
2022-07-21 11:29:18 +00:00
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
d.allEntriesValid = false
|
|
|
|
d.pukArray = Array(d.pukLength)
|
|
|
|
d.pukArray.fill("")
|
|
|
|
}
|
|
|
|
|
|
|
|
QtObject {
|
|
|
|
id: d
|
|
|
|
|
|
|
|
readonly property int pukLength: 12
|
|
|
|
property var pukArray: []
|
|
|
|
property bool allEntriesValid: false
|
2024-10-15 19:26:12 +00:00
|
|
|
readonly property int rowSpacing: Theme.padding
|
2022-07-21 11:29:18 +00:00
|
|
|
|
|
|
|
function updateValidity() {
|
|
|
|
for(let i = 0; i < pukLength; ++i) {
|
|
|
|
if(pukArray[i].length !== 1) {
|
|
|
|
allEntriesValid = false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
allEntriesValid = true
|
|
|
|
}
|
|
|
|
|
|
|
|
function submitPuk() {
|
|
|
|
let puk = d.pukArray.join("")
|
|
|
|
root.startupStore.setPuk(puk)
|
|
|
|
root.startupStore.doPrimaryAction()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-29 13:30:17 +00:00
|
|
|
ColumnLayout {
|
|
|
|
anchors.centerIn: parent
|
2023-05-09 16:23:48 +00:00
|
|
|
height: Constants.onboarding.loginHeight
|
2024-10-15 19:26:12 +00:00
|
|
|
spacing: Theme.bigPadding
|
2022-09-29 13:30:17 +00:00
|
|
|
|
|
|
|
StatusBaseText {
|
|
|
|
id: title
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
font.pixelSize: Constants.keycard.general.fontSize1
|
|
|
|
font.weight: Font.Bold
|
|
|
|
color: Theme.palette.directColor1
|
|
|
|
text: qsTr("Enter PUK code to recover Keycard")
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-29 13:30:17 +00:00
|
|
|
RowLayout {
|
|
|
|
id: rowLayout
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
spacing: d.rowSpacing
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-29 13:30:17 +00:00
|
|
|
Component.onCompleted: {
|
|
|
|
for (var i = 0; i < children.length - 1; ++i) {
|
|
|
|
if(children[i] && children[i].input && children[i+1] && children[i+1].input){
|
|
|
|
children[i].input.tabNavItem = children[i+1].input.edit
|
2022-07-21 11:29:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-29 13:30:17 +00:00
|
|
|
if(children.length > 0){
|
|
|
|
children[0].input.edit.forceActiveFocus()
|
|
|
|
}
|
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-29 13:30:17 +00:00
|
|
|
Repeater {
|
|
|
|
model: d.pukLength
|
|
|
|
delegate: StatusInput {
|
|
|
|
Layout.preferredWidth: Constants.keycard.general.pukCellWidth
|
|
|
|
Layout.preferredHeight: Constants.keycard.general.pukCellHeight
|
|
|
|
input.acceptReturn: true
|
|
|
|
validators: [
|
|
|
|
StatusRegularExpressionValidator {
|
|
|
|
regularExpression: /[0-9]/
|
|
|
|
errorMessage: ""
|
|
|
|
},
|
|
|
|
StatusMinLengthValidator {
|
|
|
|
minLength: 1
|
|
|
|
errorMessage: ""
|
|
|
|
}
|
|
|
|
]
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-29 13:30:17 +00:00
|
|
|
onTextChanged: {
|
|
|
|
text = text.trim()
|
|
|
|
if(text.length >= 1) {
|
|
|
|
text = text.charAt(0);
|
|
|
|
}
|
|
|
|
if(Utils.isDigit(text)) {
|
|
|
|
let nextInd = index+1
|
|
|
|
if(nextInd <= rowLayout.children.length - 1 &&
|
|
|
|
rowLayout.children[nextInd] &&
|
|
|
|
rowLayout.children[nextInd].input){
|
|
|
|
rowLayout.children[nextInd].input.edit.forceActiveFocus()
|
2022-07-21 11:29:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-29 13:30:17 +00:00
|
|
|
else {
|
|
|
|
text = ""
|
|
|
|
}
|
|
|
|
d.pukArray[index] = text
|
|
|
|
d.updateValidity()
|
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-29 13:30:17 +00:00
|
|
|
onKeyPressed: {
|
|
|
|
if(input.edit.keyEvent === Qt.Key_Backspace){
|
|
|
|
if (text == ""){
|
|
|
|
let prevInd = index-1
|
|
|
|
if(prevInd >= 0){
|
|
|
|
rowLayout.children[prevInd].input.edit.forceActiveFocus()
|
2022-07-21 11:29:18 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-29 13:30:17 +00:00
|
|
|
}
|
|
|
|
else if (input.edit.keyEvent === Qt.Key_Return ||
|
|
|
|
input.edit.keyEvent === Qt.Key_Enter) {
|
|
|
|
if(d.allEntriesValid) {
|
|
|
|
event.accepted = true
|
|
|
|
d.submitPuk()
|
2022-07-21 11:29:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-29 13:30:17 +00:00
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
2022-09-29 13:30:17 +00:00
|
|
|
StatusBaseText {
|
|
|
|
id: info
|
|
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
font.pixelSize: Constants.keycard.general.fontSize3
|
|
|
|
color: Theme.palette.dangerColor1
|
|
|
|
horizontalAlignment: Qt.AlignHCenter
|
2022-07-21 11:29:18 +00:00
|
|
|
}
|
|
|
|
|
2022-09-29 13:30:17 +00:00
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
}
|
2022-07-21 11:29:18 +00:00
|
|
|
|
|
|
|
StatusButton {
|
2022-09-29 13:30:17 +00:00
|
|
|
Layout.alignment: Qt.AlignHCenter
|
2022-07-21 11:29:18 +00:00
|
|
|
enabled: d.allEntriesValid
|
|
|
|
text: qsTr("Recover Keycard")
|
|
|
|
onClicked: {
|
|
|
|
d.submitPuk()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
states: [
|
|
|
|
State {
|
|
|
|
name: Constants.startupState.keycardEnterPuk
|
|
|
|
when: root.startupStore.currentStartupState.stateType === Constants.startupState.keycardEnterPuk
|
|
|
|
PropertyChanges {
|
|
|
|
target: info
|
|
|
|
text: ""
|
|
|
|
}
|
|
|
|
},
|
|
|
|
State {
|
|
|
|
name: Constants.startupState.keycardWrongPuk
|
|
|
|
when: root.startupStore.currentStartupState.stateType === Constants.startupState.keycardWrongPuk
|
|
|
|
PropertyChanges {
|
|
|
|
target: info
|
|
|
|
text: qsTr("Invalid PUK code, %n attempt(s) remaining", "", root.remainingAttempts)
|
|
|
|
}
|
|
|
|
StateChangeScript {
|
|
|
|
script: d.allEntriesValid = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|