Warning, /plasma/plasma-mobile/kcms/cellularnetwork/ui/SimLockPage.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 import QtQuick 0005 import QtQuick.Layouts 1.2 0006 import QtQuick.Controls 2.12 as Controls 0007 0008 import org.kde.kirigami 2.19 as Kirigami 0009 import org.kde.kcmutils 0010 import org.kde.kirigamiaddons.formcard 1.0 as FormCard 0011 0012 import cellularnetworkkcm 1.0 0013 0014 FormCard.FormCardPage { 0015 id: root 0016 0017 property Sim sim 0018 0019 title: i18n("SIM Lock") 0020 0021 MessagesList { 0022 Layout.fillWidth: true 0023 Layout.margins: Kirigami.Units.gridUnit 0024 model: kcm.messages 0025 } 0026 0027 ColumnLayout { 0028 id: unlockSimPlaceholder 0029 visible: sim.locked 0030 0031 // HACK: prevent infinite binding loop? 0032 Component.onCompleted: unlockSimPlaceholder.Layout.preferredHeight = root.height 0033 0034 Kirigami.PlaceholderMessage { 0035 Layout.margins: Kirigami.Units.gridUnit * 2 0036 Layout.fillWidth: true 0037 Layout.fillHeight: true 0038 text: i18n("SIM is locked") 0039 explanation: i18n("In order to use this SIM, you must first unlock it.") 0040 icon.name: "lock" 0041 helpfulAction: Kirigami.Action { 0042 icon.name: "unlock" 0043 text: "Unlock SIM" 0044 onTriggered: unlockPinDialog.open() // TODO replace custom unlock pin dialog with just opening the system unlock PIN dialog 0045 } 0046 } 0047 } 0048 0049 ColumnLayout { 0050 id: notLockedSimPlaceholder 0051 visible: !sim.pinEnabled && !unlockSimPlaceholder.visible 0052 Layout.fillWidth: true 0053 0054 // HACK: prevent infinite binding loop? 0055 Component.onCompleted: notLockedSimPlaceholder.Layout.preferredHeight = root.height 0056 0057 Kirigami.PlaceholderMessage { 0058 Layout.margins: Kirigami.Units.gridUnit * 2 0059 Layout.fillWidth: true 0060 Layout.fillHeight: true 0061 text: i18n("SIM is not locked") 0062 explanation: i18n("You can lock your SIM to require a set PIN code for phone calls and mobile data.") 0063 icon.name: "unlock" 0064 helpfulAction: Kirigami.Action { 0065 icon.name: "lock" 0066 text: i18n("Lock SIM") 0067 onTriggered: createPinDialog.open() 0068 } 0069 } 0070 } 0071 0072 FormCard.FormCard { 0073 visible: !notLockedSimPlaceholder.visible && !unlockSimPlaceholder.visible 0074 Layout.fillWidth: true 0075 0076 FormCard.FormButtonDelegate { 0077 id: disableSimLockButton 0078 text: i18n("Disable SIM Lock") 0079 description: i18n("Disable the SIM lock feature and remove the passcode on the SIM.") 0080 onClicked: removePinDialog.open(); 0081 } 0082 0083 Kirigami.Separator { 0084 Layout.leftMargin: Kirigami.Units.largeSpacing 0085 Layout.rightMargin: Kirigami.Units.largeSpacing 0086 opacity: (!disableSimLockButton.controlHovered && !changePinButton.controlHovered) ? 0.5 : 0 0087 } 0088 0089 FormCard.FormButtonDelegate { 0090 id: changePinButton 0091 text: i18n("Change PIN") 0092 description: i18n("Change the passcode set on the SIM.") 0093 onClicked: changePinDialog.open() 0094 } 0095 } 0096 0097 data: [ 0098 RegularExpressionValidator { 0099 id: pinValidator 0100 regularExpression: /[0-9]+/ 0101 }, 0102 // dialogs 0103 0104 Kirigami.Dialog { 0105 id: unlockPinDialog 0106 title: i18n("Unlock SIM") 0107 standardButtons: Controls.Dialog.Ok | Controls.Dialog.Cancel 0108 padding: Kirigami.Units.largeSpacing 0109 0110 onAccepted: sim.sendPin(unlockPinCurPin.text) 0111 0112 ColumnLayout { 0113 Controls.Label { 0114 text: i18n("Attempts left: %1", sim.unlockRetriesLeft) 0115 } 0116 Kirigami.PasswordField { 0117 id: unlockPinCurPin 0118 placeholderText: i18n("Enter PIN") 0119 validator: pinValidator 0120 } 0121 } 0122 }, 0123 0124 Kirigami.Dialog { 0125 id: changePinDialog 0126 title: i18n("Change SIM PIN") 0127 standardButtons: isValid ? Controls.Dialog.Ok | Controls.Dialog.Cancel : Controls.Dialog.Cancel 0128 padding: Kirigami.Units.largeSpacing 0129 0130 property bool isValid: changePinNewPin.text == changePinConfirmPin.text && 0131 changePinNewPin.text.length >= 4 && changePinNewPin.text.length <= 8 // SIM PINs are between 4-8 digits 0132 0133 onAccepted: { 0134 if (isValid) { 0135 sim.changePin(changePinCurPin.text, changePinNewPin.text); 0136 } 0137 } 0138 0139 ColumnLayout { 0140 spacing: Kirigami.Units.smallSpacing 0141 Kirigami.InlineMessage { 0142 id: changePinMatch 0143 Layout.fillWidth: true 0144 visible: changePinNewPin.text != changePinConfirmPin.text 0145 text: i18n("PINs don't match!") 0146 type: Kirigami.MessageType.Error 0147 } 0148 Kirigami.InlineMessage { 0149 Layout.fillWidth: true 0150 visible: !changePinMatch.visible && changePinNewPin.text.length != 0 && (changePinNewPin.text.length < 4 || changePinNewPin.text.length > 8) 0151 text: i18n("PINs must be between 4 and 8 digits!") 0152 type: Kirigami.MessageType.Error 0153 } 0154 Kirigami.PasswordField { 0155 id: changePinCurPin 0156 placeholderText: i18n("Current PIN") 0157 validator: pinValidator 0158 } 0159 Kirigami.PasswordField { 0160 id: changePinNewPin 0161 placeholderText: i18n("New PIN") 0162 validator: pinValidator 0163 } 0164 Kirigami.PasswordField { 0165 id: changePinConfirmPin 0166 placeholderText: i18n("Confirm PIN") 0167 validator: pinValidator 0168 } 0169 } 0170 }, 0171 0172 Kirigami.Dialog { 0173 id: removePinDialog 0174 title: i18n("Remove SIM PIN") 0175 standardButtons: Controls.Dialog.Ok | Controls.Dialog.Cancel 0176 padding: Kirigami.Units.largeSpacing 0177 0178 onAccepted: sim.togglePinEnabled(removePinCurPin.text); 0179 0180 ColumnLayout { 0181 Kirigami.PasswordField { 0182 id: removePinCurPin 0183 placeholderText: i18n("Current PIN") 0184 validator: pinValidator 0185 } 0186 } 0187 }, 0188 0189 Kirigami.Dialog { 0190 id: createPinDialog 0191 title: i18n("Add SIM PIN") 0192 standardButtons: isValid ? Controls.Dialog.Ok | Controls.Dialog.Cancel : Controls.Dialog.Cancel 0193 padding: Kirigami.Units.largeSpacing 0194 0195 property bool isValid: createPinNewPin.text == createPinConfirmPin.text && 0196 createPinNewPin.text.length >= 4 && createPinNewPin.text.length <= 8 // SIM PINs are between 4-8 digits 0197 0198 onAccepted: { 0199 if (isValid) { 0200 sim.togglePinEnabled(createPinNewPin.text); 0201 } 0202 } 0203 0204 ColumnLayout { 0205 spacing: Kirigami.Units.smallSpacing 0206 Kirigami.InlineMessage { 0207 id: createPinMatch 0208 Layout.fillWidth: true 0209 visible: createPinNewPin.text != createPinConfirmPin.text 0210 text: i18n("PINs don't match!") 0211 type: Kirigami.MessageType.Error 0212 } 0213 Kirigami.InlineMessage { 0214 Layout.fillWidth: true 0215 visible: !createPinMatch.visible && createPinNewPin.text.length != 0 && (createPinNewPin.text.length < 4 || createPinNewPin.text.length > 8) 0216 text: i18n("PINs must be between 4 and 8 digits!") 0217 type: Kirigami.MessageType.Error 0218 } 0219 Kirigami.PasswordField { 0220 id: createPinNewPin 0221 placeholderText: i18n("New PIN") 0222 validator: pinValidator 0223 } 0224 Kirigami.PasswordField { 0225 id: createPinConfirmPin 0226 placeholderText: i18n("Confirm PIN") 0227 validator: pinValidator 0228 } 0229 } 0230 } 0231 ] 0232 } 0233