Lomiri
passcode-set.qml
1 /*
2  * Copyright (C) 2014-2016 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.12
18 import Lomiri.Components 1.3
19 import Lomiri.SystemSettings.SecurityPrivacy 1.0
20 import ".." as LocalComponents
21 import "../../Components"
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: passcodeSetPage
30  objectName: "passcodeSetPage"
31  customTitle: true
32  backButtonText: i18n.tr("Cancel")
33 
34  // If we are entering this page, clear any saved password and get focus
35  onEnabledChanged: if (enabled) lockscreen.clear(false)
36 
37  function confirm() {
38  root.password = lockscreen.passphrase;
39  confirmTimer.start()
40  }
41 
42  Timer {
43  id: confirmTimer
44  interval: LomiriAnimation.SnapDuration
45  onTriggered: pageStack.load(Qt.resolvedUrl("passcode-confirm.qml"));
46  }
47 
48  Lockscreen {
49  id: lockscreen
50  anchors {
51  fill: content
52  }
53 
54  infoText: i18n.tr("Choose passcode")
55  foregroundColor: textColor
56 
57  // Note that the number four comes from PAM settings,
58  // which we don't have a good way to interrogate. We
59  // only do this matching instead of PAM because we want
60  // to set the password via PAM in a different place
61  // than this page. See comments at top of passwd-type file.
62  errorText: i18n.tr("Passcode must be at least 4 characters long")
63 
64  showEmergencyCallButton: false
65  showCancelButton: false
66  alphaNumeric: false
67  minPinLength: 4
68  maxPinLength: 12
69 
70  onEntered: {
71  if (passphrase.length >= 4) {
72  passcodeSetPage.confirm();
73  } else {
74  lockscreen.clear(true);
75  }
76  }
77  }
78 }