Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 2.0
- import Sailfish.Silica 1.0
- import com.jolla.settings.system 1.0
- import org.nemomobile.systemsettings 1.0
- Page {
- DeviceLockInterface {
- id: devicelock
- property string cachedPin
- property bool active: Qt.application.active
- onActiveChanged: if (active === false) cachedPin = ""
- }
- DeviceLockSettings {
- id: lockSettings
- onAutomaticLockingChanged: lockingCombobox.currentIndex = lockingCombobox.updateIndex(lockSettings.automaticLocking)
- onMaximumAttemptsChanged: {
- attemptsSlider.value = lockSettings.maximumAttempts != -1 ? lockSettings.maximumAttempts : attemptsSlider.maximumValue
- }
- }
- onStatusChanged: {
- if (status === PageStatus.Deactivating) devicelock.cachedPin = ""
- }
- SilicaFlickable {
- anchors.fill: parent
- contentHeight: content.height
- PullDownMenu {
- visible: !devicelock.isSet
- MenuItem {
- //% "Set device lock"
- text: qsTrId("settings_devicelock-he-set_lock_code")
- onClicked: {
- pageStack.push(pinInputComponent, {setup: true})
- }
- }
- }
- ViewPlaceholder {
- enabled: !devicelock.isSet
- //% "Device lock has not been set"
- text: qsTrId("settings_devicelock-he-device_lock_not_been_set")
- }
- Column {
- id: content
- width: parent.width
- anchors.left: parent.left
- anchors.right: parent.right
- PageHeader {
- //% "Device lock"
- title: qsTrId("settings_devicelock-he-devicelock")
- }
- ComboBox {
- id: lockingCombobox
- visible: devicelock.isSet
- width: parent.width
- //% "Automatic locking"
- label: qsTrId("settings_devicelock-la-status_combobox")
- currentIndex: updateIndex(lockSettings.automaticLocking)
- menu: ContextMenu {
- MenuItem {
- //% "Not in use"
- text: qsTrId("settings_devicelock-me-off")
- onClicked: lockingCombobox.setAutomaticLocking("-1")
- }
- MenuItem {
- //% "No delay"
- text: qsTrId("settings_devicelock-me-on0")
- onClicked: lockingCombobox.setAutomaticLocking("0")
- }
- MenuItem {
- //% "5 minutes"
- text: qsTrId("settings_devicelock-me-on5")
- onClicked: lockingCombobox.setAutomaticLocking("5")
- }
- MenuItem {
- //% "10 minutes"
- text: qsTrId("settings_devicelock-me-on10")
- onClicked: lockingCombobox.setAutomaticLocking("10")
- }
- MenuItem {
- //% "30 minutes"
- text: qsTrId("settings_devicelock-me-on30")
- onClicked: lockingCombobox.setAutomaticLocking("30")
- }
- MenuItem {
- //% "60 minutes"
- text: qsTrId("settings_devicelock-me-on60")
- onClicked: lockingCombobox.setAutomaticLocking("60")
- }
- }
- function setAutomaticLocking(minutes) {
- if (devicelock.isSet && lockSettings.automaticLocking !== minutes) {
- if (devicelock.cachedPin) {
- lockSettings.setAutomaticLocking(devicelock.cachedPin, minutes)
- } else {
- var d = pageStack.push(pinInputComponent, {requestSignalOnly: true})
- d.lockCodeConfirmed.connect(function(enteredPin) {
- lockSettings.setAutomaticLocking(enteredPin, minutes)
- })
- d.lockCodeCanceled.connect(function() {
- lockingCombobox.currentIndex = lockingCombobox.updateIndex(lockSettings.automaticLocking)
- })
- }
- }
- }
- function updateIndex(value) {
- if (value === "-1") {
- return 0
- } else if (value === "0") {
- return 1
- } else if (value === "5") {
- return 2
- } else if (value === "10") {
- return 3
- } else if (value === "30") {
- return 4
- } else if (value === "60") {
- return 5
- }
- }
- }
- Slider {
- id: attemptsSlider
- value: lockSettings.maximumAttempts != -1 ? lockSettings.maximumAttempts : maximumValue
- minimumValue: 4
- maximumValue: 51
- stepSize: 1
- width: parent.width
- anchors.horizontalCenter: parent.horizontalCenter
- //% "No limit"
- valueText: (value < maximumValue) ? value.toFixed(0) : qsTrId("settings_devicelock-me-nolimit")
- visible: devicelock.isSet
- //% "Number of attempts"
- label: qsTrId("settings_devicelock-la-attempts_combobox")
- onDownChanged: {
- if (!down) {
- if (devicelock.isSet && lockSettings.maximumAttempts != value) {
- var new_value = value != maximumValue ? value : -1
- if (devicelock.cachedPin) {
- lockSettings.setMaximumAttempts(devicelock.cachedPin, new_value)
- } else {
- var d = pageStack.push(pinInputComponent, {requestSignalOnly: true})
- d.lockCodeConfirmed.connect(function(enteredPin) {
- lockSettings.setMaximumAttempts(enteredPin, new_value)
- })
- d.lockCodeCanceled.connect(function() {
- attemptsSlider.value = lockSettings.maximumAttempts != -1 ? lockSettings.maximumAttempts : attemptsSlider.maximumValue
- })
- }
- }
- }
- }
- }
- TextSwitch {
- id: peekSwitch
- //% "Allow feeds while locked"
- text: qsTrId("settings_devicelock-la-allow_feeds")
- //visible: devicelock.isSet
- visible: false // hidden until JB#27250 has been implemented.
- automaticCheck: false
- checked: lockSettings.peekingAllowed == 1
- onClicked: {
- if (devicelock.isSet) {
- if (devicelock.cachedPin) {
- lockSettings.setPeekingAllowed(devicelock.cachedPin, checked ? "-1" : "1")
- } else {
- var d = pageStack.push(pinInputComponent, {requestSignalOnly: true})
- d.lockCodeConfirmed.connect(function(enteredPin) {
- lockSettings.setPeekingAllowed(enteredPin, checked ? "-1" : "1")
- })
- }
- }
- }
- }
- TextSwitch {
- //: This switch chooses between Digit only keypad (current default behaviour) and new qwerty-keyboard for devicelock
- //% "Digit only keypad"
- text: qsTrId("settings_devicelock-la-digit_only_keypad")
- // [TMP HOTFIX] do not permit alphanum code to new users until proper fix is in place. Contributes to jb#24201
- // Those who already have enabled alphanumeric code right after update10, and want to revert back to numpad, a cmdline tool can be provided
- visible: false // devicelock.isSet
- automaticCheck: false
- checked: !lockSettings.codeInputIsKeyboard
- //: This description how to get digit only keypad back is showed when user has defined non-digit lockcode and he has qwerty enabled
- //% "You can only enable when your lock code is digit only"
- description: !lockSettings.codeCurrentIsDigitOnly ? qsTrId("settings_devicelock-la-busy-description") : ""
- onClicked: {
- if (devicelock.isSet && (lockSettings.codeCurrentIsDigitOnly || checked)) {
- if (devicelock.cachedPin) {
- lockSettings.setInputIsKeyboard(devicelock.cachedPin, checked)
- } else {
- var d = pageStack.push(pinInputComponent, {requestSignalOnly: true})
- d.lockCodeConfirmed.connect(function(enteredPin) {
- // break binding on purpose to avoid vkb open animation on settings switch
- d.showDigitPad = d.showDigitPad
- lockSettings.setInputIsKeyboard(enteredPin, checked)
- })
- }
- }
- }
- }
- Item {
- width: parent.width
- height: Theme.paddingLarge * 2
- }
- Button {
- id: changeLockCodeBox
- visible: devicelock.isSet
- anchors.horizontalCenter: parent.horizontalCenter
- preferredWidth: Theme.buttonWidthLarge
- //% "Change device lock code"
- text: qsTrId("settings_devicelock-he-change_lock_code")
- onClicked: {
- pageStack.push(pinInputComponent)
- }
- }
- Item {
- width: parent.width
- height: Theme.paddingLarge
- }
- Button {
- id: clearLockCodeBox
- visible: devicelock.isSet
- anchors.horizontalCenter: parent.horizontalCenter
- preferredWidth: Theme.buttonWidthLarge
- //% "Clear device lock code"
- text: qsTrId("settings_devicelock-he-clear_lock_code")
- onClicked: {
- if (devicelock.isSet) {
- if (devicelock.cachedPin) {
- devicelock.clearCode(devicelock.cachedPin)
- } else {
- var d = pageStack.push(pinInputComponent, {requestSignalOnly: true})
- d.lockCodeConfirmed.connect(function(enteredPin) {
- devicelock.clearCode(enteredPin)
- devicelock.cachedPin = ""
- })
- }
- }
- }
- }
- }
- }
- Component {
- id: pinInputComponent
- Page {
- property string _confirmedPin
- property bool setup
- property bool requestSignalOnly
- property alias showDigitPad: pininput.showDigitPad
- backNavigation: false
- signal lockCodeConfirmed(string enteredPin)
- signal lockCodeCanceled()
- DeviceLockInput {
- id: pininput
- showDigitPad: !lockSettings.codeInputIsKeyboard
- //: Devicelock UI's header-text which indicates Locked state.
- //% "Enter current lock code"
- titleText: qsTrId("settings_devicelock-he-enter_current_lock_code")
- //: Devicelock UI's enter-key which is pressed to confirm the new lockingComboboxlockcode.
- //% "Enter"
- okText: (enteringNewPin || requestSignalOnly) ? qsTrId("settings_devicelock-bt-enter")
- //: Devicelock UI's unlock-key which is pressed to confirm the lockcode.
- //% "Unlock"
- : qsTrId("settings_devicelock-bt-unlock")
- showEmergencyButton: false
- //% "You need atleast %n digits."
- pinShortLengthWarning: qsTrId("settings_devicelock-la-devicelock_min_length_warning", minimumLength)
- //: Enter a new lock code
- //% "Enter new lock code"
- enterNewPinText: qsTrId("settings_devicelock-he-enter_new_lock_code")
- //: Re-enter the lock code that was just entered
- //% "Re-enter new lock code"
- confirmNewPinText: qsTrId("settings_devicelock-he-reenter_new_lock_code")
- //: Shown when a new lock code is entered twice for confirmation but the two entered lock codes are not the same.
- //% "Re-entered lock code did not match."
- pinMismatchText: qsTrId("settings_devicelock-he-reentered_lock_code_mismatch")
- //: Shown when the new PIN is not allowed because it is the same as the current PIN.
- //% "The new lock code cannot be the same as the current lock code."
- pinUnchangedText: qsTrId("settings_pin-he-new_lock_code_same_as_old")
- onPinConfirmed: {
- if (enteringNewPin) {
- devicelock.setCode(_confirmedPin, enteredPin)
- devicelock.cachedPin = enteredPin
- if (setup) lockSettings.setAutomaticLocking(enteredPin, "10")
- pageStack.pop()
- } else if (devicelock.checkCode(enteredPin)) {
- // OK, open change code UI query
- _confirmedPin = enteredPin
- devicelock.cachedPin = enteredPin
- _badPinWarning = ""
- if (requestSignalOnly) {
- lockCodeConfirmed(enteredPin)
- pageStack.pop()
- } else {
- requestAndConfirmNewPin(enteredPin)
- }
- } else {
- //% "Incorrect lock code"
- _badPinWarning = qsTrId("settings_devicelock-la-devicelock_incorrect_lock_code")
- clear()
- }
- }
- onPinEntryCanceled: {
- lockCodeCanceled()
- clear()
- pageStack.pop()
- }
- Component.onCompleted: {
- if (!devicelock.isSet) {
- //: Inital setup of lock code
- //% "Set your lock code"
- _overridingWarningText = qsTrId("settings_devicelock-la-devicelock_set_lock_code.")
- requestAndConfirmNewPin()
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement