Advertisement
Guest User

Untitled

a guest
Apr 14th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 15.39 KB | None | 0 0
  1. import QtQuick 2.0
  2. import Sailfish.Silica 1.0
  3. import com.jolla.settings.system 1.0
  4. import org.nemomobile.systemsettings 1.0
  5.  
  6. Page {
  7.     DeviceLockInterface {
  8.         id: devicelock
  9.         property string cachedPin
  10.         property bool active: Qt.application.active
  11.         onActiveChanged: if (active === false) cachedPin = ""
  12.     }
  13.     DeviceLockSettings {
  14.         id: lockSettings
  15.         onAutomaticLockingChanged: lockingCombobox.currentIndex = lockingCombobox.updateIndex(lockSettings.automaticLocking)
  16.         onMaximumAttemptsChanged: {
  17.             attemptsSlider.value = lockSettings.maximumAttempts != -1 ? lockSettings.maximumAttempts : attemptsSlider.maximumValue
  18.         }
  19.     }
  20.     onStatusChanged: {
  21.         if (status === PageStatus.Deactivating) devicelock.cachedPin = ""
  22.     }
  23.  
  24.     SilicaFlickable {
  25.         anchors.fill: parent
  26.         contentHeight: content.height
  27.  
  28.         PullDownMenu {
  29.             visible: !devicelock.isSet
  30.  
  31.             MenuItem {
  32.                 //% "Set device lock"
  33.                 text: qsTrId("settings_devicelock-he-set_lock_code")
  34.                 onClicked: {
  35.                     pageStack.push(pinInputComponent, {setup: true})
  36.                 }
  37.             }
  38.         }
  39.  
  40.         ViewPlaceholder {
  41.             enabled: !devicelock.isSet
  42.             //% "Device lock has not been set"
  43.             text: qsTrId("settings_devicelock-he-device_lock_not_been_set")
  44.         }
  45.  
  46.         Column {
  47.             id: content
  48.             width: parent.width
  49.             anchors.left: parent.left
  50.             anchors.right: parent.right
  51.  
  52.             PageHeader {
  53.                 //% "Device lock"
  54.                 title: qsTrId("settings_devicelock-he-devicelock")
  55.             }
  56.  
  57.             ComboBox {
  58.                 id: lockingCombobox
  59.  
  60.                 visible: devicelock.isSet
  61.                 width: parent.width
  62.                 //% "Automatic locking"
  63.                 label: qsTrId("settings_devicelock-la-status_combobox")
  64.                 currentIndex: updateIndex(lockSettings.automaticLocking)
  65.  
  66.                 menu: ContextMenu {
  67.                     MenuItem {
  68.                         //% "Not in use"
  69.                         text: qsTrId("settings_devicelock-me-off")
  70.                         onClicked: lockingCombobox.setAutomaticLocking("-1")
  71.                     }
  72.                     MenuItem {
  73.                         //% "No delay"
  74.                         text: qsTrId("settings_devicelock-me-on0")
  75.                         onClicked: lockingCombobox.setAutomaticLocking("0")
  76.                     }
  77.                     MenuItem {
  78.                         //% "5 minutes"
  79.                         text: qsTrId("settings_devicelock-me-on5")
  80.                         onClicked: lockingCombobox.setAutomaticLocking("5")
  81.                     }
  82.                     MenuItem {
  83.                         //% "10 minutes"
  84.                         text: qsTrId("settings_devicelock-me-on10")
  85.                         onClicked: lockingCombobox.setAutomaticLocking("10")
  86.                     }
  87.                     MenuItem {
  88.                         //% "30 minutes"
  89.                         text: qsTrId("settings_devicelock-me-on30")
  90.                         onClicked: lockingCombobox.setAutomaticLocking("30")
  91.                     }
  92.                     MenuItem {
  93.                         //% "60 minutes"
  94.                         text: qsTrId("settings_devicelock-me-on60")
  95.                         onClicked: lockingCombobox.setAutomaticLocking("60")
  96.                     }
  97.                 }
  98.  
  99.                 function setAutomaticLocking(minutes) {
  100.                     if (devicelock.isSet && lockSettings.automaticLocking !== minutes) {
  101.                         if (devicelock.cachedPin) {
  102.                             lockSettings.setAutomaticLocking(devicelock.cachedPin, minutes)
  103.                         } else {
  104.                             var d = pageStack.push(pinInputComponent, {requestSignalOnly: true})
  105.                             d.lockCodeConfirmed.connect(function(enteredPin) {
  106.                                 lockSettings.setAutomaticLocking(enteredPin, minutes)
  107.                             })
  108.                             d.lockCodeCanceled.connect(function() {
  109.                                 lockingCombobox.currentIndex = lockingCombobox.updateIndex(lockSettings.automaticLocking)
  110.                             })
  111.                         }
  112.                     }
  113.                 }
  114.  
  115.                 function updateIndex(value) {
  116.                     if (value === "-1") {
  117.                         return 0
  118.                     } else if (value === "0") {
  119.                         return 1
  120.                     } else if (value === "5") {
  121.                         return 2
  122.                     } else if (value === "10") {
  123.                         return 3
  124.                     } else if (value === "30") {
  125.                         return 4
  126.                     } else if (value === "60") {
  127.                         return 5
  128.                     }
  129.                 }
  130.             }
  131.  
  132.             Slider {
  133.                 id: attemptsSlider
  134.                 value: lockSettings.maximumAttempts != -1 ? lockSettings.maximumAttempts : maximumValue
  135.                 minimumValue: 4
  136.                 maximumValue: 51
  137.                 stepSize: 1
  138.                 width: parent.width
  139.                 anchors.horizontalCenter: parent.horizontalCenter
  140.                 //% "No limit"
  141.                 valueText: (value < maximumValue) ? value.toFixed(0) : qsTrId("settings_devicelock-me-nolimit")
  142.                 visible: devicelock.isSet
  143.                 //% "Number of attempts"
  144.                 label: qsTrId("settings_devicelock-la-attempts_combobox")
  145.                 onDownChanged: {
  146.                     if (!down) {
  147.                         if (devicelock.isSet && lockSettings.maximumAttempts != value) {
  148.                             var new_value = value != maximumValue ? value : -1
  149.                             if (devicelock.cachedPin) {
  150.                                 lockSettings.setMaximumAttempts(devicelock.cachedPin, new_value)
  151.                             } else {
  152.                                 var d = pageStack.push(pinInputComponent, {requestSignalOnly: true})
  153.                                 d.lockCodeConfirmed.connect(function(enteredPin) {
  154.                                     lockSettings.setMaximumAttempts(enteredPin, new_value)
  155.                                 })
  156.                                 d.lockCodeCanceled.connect(function() {
  157.                                     attemptsSlider.value = lockSettings.maximumAttempts != -1 ? lockSettings.maximumAttempts : attemptsSlider.maximumValue
  158.                                 })
  159.                             }
  160.                         }
  161.                     }
  162.                 }
  163.             }
  164.  
  165.             TextSwitch {
  166.                 id: peekSwitch
  167.                 //% "Allow feeds while locked"
  168.                 text: qsTrId("settings_devicelock-la-allow_feeds")
  169.                 //visible: devicelock.isSet
  170.                 visible: false // hidden until JB#27250 has been implemented.
  171.                 automaticCheck: false
  172.                 checked: lockSettings.peekingAllowed == 1
  173.                 onClicked: {
  174.                     if (devicelock.isSet) {
  175.                         if (devicelock.cachedPin) {
  176.                             lockSettings.setPeekingAllowed(devicelock.cachedPin, checked ? "-1" : "1")
  177.                         } else {
  178.                             var d = pageStack.push(pinInputComponent, {requestSignalOnly: true})
  179.                             d.lockCodeConfirmed.connect(function(enteredPin) {
  180.                                 lockSettings.setPeekingAllowed(enteredPin, checked ? "-1" : "1")
  181.                             })
  182.                         }
  183.                     }
  184.                 }
  185.             }
  186.             TextSwitch {
  187.                 //: This switch chooses between Digit only keypad (current default behaviour) and new qwerty-keyboard for devicelock
  188.                 //% "Digit only keypad"
  189.                 text: qsTrId("settings_devicelock-la-digit_only_keypad")
  190.                 // [TMP HOTFIX] do not permit alphanum code to new users until proper fix is in place. Contributes to jb#24201
  191.                 // Those who already have enabled alphanumeric code right after update10, and want to revert back to numpad, a cmdline tool can be provided
  192.                 visible: false // devicelock.isSet
  193.                 automaticCheck: false
  194.                 checked: !lockSettings.codeInputIsKeyboard
  195.                 //: This description how to get digit only keypad back is showed when user has defined non-digit lockcode and he has qwerty enabled
  196.                 //% "You can only enable when your lock code is digit only"
  197.                 description: !lockSettings.codeCurrentIsDigitOnly ? qsTrId("settings_devicelock-la-busy-description") : ""
  198.                 onClicked: {
  199.                     if (devicelock.isSet && (lockSettings.codeCurrentIsDigitOnly || checked)) {
  200.                         if (devicelock.cachedPin) {
  201.                             lockSettings.setInputIsKeyboard(devicelock.cachedPin, checked)
  202.                         } else {
  203.                             var d = pageStack.push(pinInputComponent, {requestSignalOnly: true})
  204.                             d.lockCodeConfirmed.connect(function(enteredPin) {
  205.                                 // break binding on purpose to avoid vkb open animation on settings switch
  206.                                 d.showDigitPad = d.showDigitPad
  207.                                 lockSettings.setInputIsKeyboard(enteredPin, checked)
  208.                             })
  209.                         }
  210.                     }
  211.                 }
  212.             }
  213.             Item {
  214.                 width: parent.width
  215.                 height: Theme.paddingLarge * 2
  216.             }
  217.             Button {
  218.                 id: changeLockCodeBox
  219.                 visible: devicelock.isSet
  220.                 anchors.horizontalCenter: parent.horizontalCenter
  221.                 preferredWidth: Theme.buttonWidthLarge
  222.                 //% "Change device lock code"
  223.                 text: qsTrId("settings_devicelock-he-change_lock_code")
  224.                 onClicked: {
  225.                     pageStack.push(pinInputComponent)
  226.                 }
  227.             }
  228.             Item {
  229.                 width: parent.width
  230.                 height: Theme.paddingLarge
  231.             }
  232.             Button {
  233.                 id: clearLockCodeBox
  234.                 visible: devicelock.isSet
  235.                 anchors.horizontalCenter: parent.horizontalCenter
  236.                 preferredWidth: Theme.buttonWidthLarge
  237.                 //% "Clear device lock code"
  238.                 text: qsTrId("settings_devicelock-he-clear_lock_code")
  239.                 onClicked: {
  240.                     if (devicelock.isSet) {
  241.                         if (devicelock.cachedPin) {
  242.                             devicelock.clearCode(devicelock.cachedPin)
  243.                         } else {
  244.                             var d = pageStack.push(pinInputComponent, {requestSignalOnly: true})
  245.                             d.lockCodeConfirmed.connect(function(enteredPin) {
  246.                                 devicelock.clearCode(enteredPin)
  247.                                 devicelock.cachedPin = ""
  248.                             })
  249.                         }
  250.                     }
  251.                 }
  252.             }
  253.         }
  254.     }
  255.  
  256.     Component {
  257.         id: pinInputComponent
  258.         Page {
  259.             property string _confirmedPin
  260.             property bool setup
  261.             property bool requestSignalOnly
  262.             property alias showDigitPad: pininput.showDigitPad
  263.             backNavigation: false
  264.  
  265.             signal lockCodeConfirmed(string enteredPin)
  266.             signal lockCodeCanceled()
  267.  
  268.             DeviceLockInput {
  269.                 id: pininput
  270.  
  271.                 showDigitPad: !lockSettings.codeInputIsKeyboard
  272.                 //: Devicelock UI's header-text which indicates Locked state.
  273.                 //% "Enter current lock code"
  274.                 titleText: qsTrId("settings_devicelock-he-enter_current_lock_code")
  275.  
  276.                 //: Devicelock UI's enter-key which is pressed to confirm the new lockingComboboxlockcode.
  277.                 //% "Enter"
  278.                 okText: (enteringNewPin || requestSignalOnly) ? qsTrId("settings_devicelock-bt-enter")
  279.                                          //: Devicelock UI's unlock-key which is pressed to confirm the lockcode.
  280.                                          //% "Unlock"
  281.                                        : qsTrId("settings_devicelock-bt-unlock")
  282.  
  283.                 showEmergencyButton: false
  284.  
  285.                 //% "You need atleast %n digits."
  286.                 pinShortLengthWarning: qsTrId("settings_devicelock-la-devicelock_min_length_warning", minimumLength)
  287.                 //: Enter a new lock code
  288.                 //% "Enter new lock code"
  289.                 enterNewPinText: qsTrId("settings_devicelock-he-enter_new_lock_code")
  290.                 //: Re-enter the lock code that was just entered
  291.                 //% "Re-enter new lock code"
  292.                 confirmNewPinText: qsTrId("settings_devicelock-he-reenter_new_lock_code")
  293.                 //: Shown when a new lock code is entered twice for confirmation but the two entered lock codes are not the same.
  294.                 //% "Re-entered lock code did not match."
  295.                 pinMismatchText: qsTrId("settings_devicelock-he-reentered_lock_code_mismatch")
  296.                 //: Shown when the new PIN is not allowed because it is the same as the current PIN.
  297.                 //% "The new lock code cannot be the same as the current lock code."
  298.                 pinUnchangedText: qsTrId("settings_pin-he-new_lock_code_same_as_old")
  299.  
  300.                 onPinConfirmed: {
  301.                     if (enteringNewPin) {
  302.                         devicelock.setCode(_confirmedPin, enteredPin)
  303.                         devicelock.cachedPin = enteredPin
  304.                         if (setup) lockSettings.setAutomaticLocking(enteredPin, "10")
  305.                         pageStack.pop()
  306.                     } else if (devicelock.checkCode(enteredPin)) {
  307.                         // OK, open change code UI query
  308.                         _confirmedPin = enteredPin
  309.                         devicelock.cachedPin = enteredPin
  310.                         _badPinWarning = ""
  311.  
  312.                         if (requestSignalOnly) {
  313.                             lockCodeConfirmed(enteredPin)
  314.                             pageStack.pop()
  315.                         } else {
  316.                             requestAndConfirmNewPin(enteredPin)
  317.                         }
  318.                     } else {
  319.                         //% "Incorrect lock code"
  320.                         _badPinWarning = qsTrId("settings_devicelock-la-devicelock_incorrect_lock_code")
  321.                         clear()
  322.                     }
  323.                 }
  324.  
  325.                 onPinEntryCanceled: {
  326.                     lockCodeCanceled()
  327.                     clear()
  328.                     pageStack.pop()
  329.                 }
  330.                 Component.onCompleted: {
  331.                     if (!devicelock.isSet) {
  332.                         //: Inital setup of lock code
  333.                         //% "Set your lock code"
  334.                         _overridingWarningText = qsTrId("settings_devicelock-la-devicelock_set_lock_code.")
  335.                         requestAndConfirmNewPin()
  336.                     }
  337.                 }
  338.             }
  339.         }
  340.     }
  341. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement