Warning, /utilities/keysmith/src/contents/ui/TOTPDetailsForm.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-License-Identifier: GPL-3.0-or-later
0003 * SPDX-FileCopyrightText: 2020 Johan Ouwerkerk <jm.ouwerkerk@gmail.com>
0004 */
0005
0006 import QtQuick 2.15
0007 import QtQuick.Layouts 1.15
0008 import QtQuick.Controls 2.15 as QQC2
0009 import org.kde.kirigami 2.20 as Kirigami
0010 import org.kde.kirigamiaddons.formcard 1.0 as FormCard
0011
0012 import Keysmith.Models 1.0 as Models
0013 import Keysmith.Validators 1.0 as Validators
0014
0015 FormCard.FormCard {
0016 id: root
0017 property Models.ValidatedAccountInput validatedInput
0018
0019 property bool timeStepAcceptable: timeStepField.acceptableInput
0020 property bool algorithmAcceptable: sha1Radio.checked || sha256Radio.checked || sha512Radio.checked
0021 property bool epochAcceptable: epochField.acceptableInput
0022 property bool acceptable: timeStepAcceptable && algorithmAcceptable && epochAcceptable
0023
0024 FormCard.FormTextFieldDelegate {
0025 id: timeStepField
0026
0027 label: i18nc("@label:textbox", "Timer:")
0028 text: validatedInput ? "" + validatedInput.timeStep : ""
0029 validator: IntValidator {
0030 bottom: 1
0031 }
0032 inputMethodHints: Qt.ImhDigitsOnly
0033 onTextChanged: {
0034 if (acceptableInput) {
0035 validatedInput.timeStep = parseInt(text);
0036 }
0037 }
0038 }
0039
0040 FormCard.FormDelegateSeparator {}
0041
0042 FormCard.FormTextFieldDelegate {
0043 id: epochField
0044
0045 label: i18nc("@label:textbox", "Starting at:")
0046 text: validatedInput ? validatedInput.epoch : ""
0047 validator: Validators.TOTPEpochValidator {}
0048 onTextChanged: {
0049 if (acceptableInput) {
0050 validatedInput.epoch = text;
0051 }
0052 }
0053 }
0054
0055 FormCard.FormDelegateSeparator {}
0056
0057 /*
0058 * OATH tokens are derived from a 32bit value, base-10 encoded.
0059 * Meaning tokens should not be longer than 10 digits max.
0060 * In addition tokens must be 6 digits long at minimum.
0061 *
0062 * Make a virtue of it by offering a spinner for better UX
0063 */
0064 FormCard.FormSpinBoxDelegate {
0065 id: tokenLengthField
0066
0067 label: i18nc("@label:spinbox", "Token length:")
0068 from: 6
0069 to: 10
0070 value: validatedInput ? validatedInput.tokenLength : 6
0071 onValueChanged: {
0072 validatedInput.tokenLength = value;
0073 }
0074 }
0075
0076 FormCard.FormDelegateSeparator {}
0077
0078 FormCard.FormTextDelegate {
0079 text: i18nc("@label:chooser", "Hash algorithm:")
0080 }
0081
0082 FormCard.FormRadioDelegate {
0083 id: sha1Radio
0084
0085 checked: validatedInput.algorithm === Models.ValidatedAccountInput.Sha1
0086 text: i18nc("@option:radio", "SHA-1")
0087 onCheckedChanged: {
0088 if (checked) {
0089 validatedInput.algorithm = Models.ValidatedAccountInput.Sha1;
0090 }
0091 }
0092 }
0093
0094 FormCard.FormRadioDelegate {
0095 id: sha256Radio
0096
0097 checked: validatedInput.algorithm === Models.ValidatedAccountInput.Sha256
0098 text: i18nc("@option:radio", "SHA-256")
0099 onCheckedChanged: {
0100 if (checked) {
0101 validatedInput.algorithm = Models.ValidatedAccountInput.Sha256;
0102 }
0103 }
0104 }
0105
0106 FormCard.FormRadioDelegate {
0107 id: sha512Radio
0108
0109 checked: validatedInput.algorithm === Models.ValidatedAccountInput.Sha512
0110 text: i18nc("@option:radio", "SHA-512")
0111 onCheckedChanged: {
0112 if (checked) {
0113 validatedInput.algorithm = Models.ValidatedAccountInput.Sha512;
0114 }
0115 }
0116 }
0117 }