Unity 8
passwd-set.qml
1 /*
2  * Copyright (C) 2014 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.4
18 import Ubuntu.Components 1.3
19 import Ubuntu.SystemSettings.SecurityPrivacy 1.0
20 import ".." as LocalComponents
21 import "../../Components" as UnityComponents
22 
23 /**
24  * See the main passwd-type page for an explanation of why we don't actually
25  * directly set the password here.
26  */
27 
28 LocalComponents.Page {
29  id: passwdSetPage
30  objectName: "passwdSetPage"
31  forwardButtonSourceComponent: forwardButton
32 
33  skip: root.passwordMethod === UbuntuSecurityPrivacyPanel.Swipe
34 
35  // If we are entering this page, clear any saved password and get focus
36  onEnabledChanged: if (enabled) lockscreen.clear(false)
37 
38  function confirm() {
39  root.password = lockscreen.passphrase;
40  confirmTimer.start()
41  }
42 
43  Timer {
44  id: confirmTimer
45  interval: UbuntuAnimation.SnapDuration
46  onTriggered: pageStack.load(Qt.resolvedUrl("passwd-confirm.qml"));
47  }
48 
49  UnityComponents.Lockscreen {
50  id: lockscreen
51  anchors {
52  fill: parent
53  topMargin: topMargin
54  leftMargin: leftMargin
55  rightMargin: rightMargin
56  bottomMargin: buttonMargin
57  }
58 
59  infoText: root.passwordMethod === UbuntuSecurityPrivacyPanel.Passphrase ?
60  i18n.tr("Enter passphrase") :
61  i18n.tr("Choose your passcode")
62 
63  // Note that the number four comes from PAM settings,
64  // which we don't have a good way to interrogate. We
65  // only do this matching instead of PAM because we want
66  // to set the password via PAM in a different place
67  // than this page. See comments at top of passwd-type file.
68  errorText: i18n.tr("Passphrase must be 4 characters long")
69 
70  showEmergencyCallButton: false
71  showCancelButton: false
72  alphaNumeric: root.passwordMethod === UbuntuSecurityPrivacyPanel.Passphrase
73  minPinLength: 4
74  maxPinLength: 4
75 
76  onEntered: {
77  if (passphrase.length >= 4) {
78  passwdSetPage.confirm();
79  } else {
80  lockscreen.clear(true)
81  }
82  }
83  }
84 
85  Component {
86  id: forwardButton
87  LocalComponents.StackButton {
88  visible: root.passwordMethod === UbuntuSecurityPrivacyPanel.Passphrase
89  enabled: lockscreen.passphrase.length >= 4
90  text: i18n.tr("Continue")
91  onClicked: passwdSetPage.confirm()
92  }
93  }
94 }