2
* Copyright 2016 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
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 Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by Jonas G. Drange <jonas.drange@canonical.com>
20
import QtQuick.Layouts 1.1
23
import Ubuntu.Components 1.3
24
import Ubuntu.Components.Popups 1.3
25
import Ubuntu.Settings.Fingerprint 0.1
29
objectName: "fingerprintPage"
32
title: i18n.dtr("ubuntu-settings-components", "Fingerprint ID")
36
property var _ts: Biometryd.defaultDevice.templateStore
37
property var _enrollmentOperation: null
38
property var _clearanceOperation: null
39
property var _removalOperation: null
40
property var _listOperation: null
41
property var _setupPage: null
42
property var _fpInstancePage: null
43
property var _settings: sysSettings
45
property Dialog _diag: null
46
property bool passcodeSet: false
49
_enrollmentOperation = _ts.enroll(user);
50
_enrollmentOperation.start(enrollmentObserver);
54
if (_enrollmentOperation)
55
_enrollmentOperation.cancel();
59
_clearanceOperation = _ts.clear(user);
60
_clearanceOperation.start(clearanceObserver);
63
function removeTemplate(templateId) {
64
var names = sysSettings.fingerprintNames;
65
delete names[templateId];
66
sysSettings.fingerprintNames = names;
69
function renameTemplate(templateId, newName) {
70
var names = sysSettings.fingerprintNames;
71
names[templateId] = newName;
72
sysSettings.fingerprintNames = names;
75
function addTemplate(templateId, name) {
76
var names = sysSettings.fingerprintNames;
77
names[templateId] = name;
78
sysSettings.fingerprintNames = names;
81
function createTemplateName() {
82
var map = sysSettings.fingerprintNames;
83
var currentNames = [];
86
if (map.hasOwnProperty(k))
87
currentNames.push(map[k]);
92
newName = i18n.dtr("ubuntu-settings-components",
93
"Finger %1").arg(++i); // Start at 1
94
} while (currentNames.indexOf(newName) >= 0);
98
// Assign names to unnamed fingerprints. This exist because we can't
99
// guarantee that all fingerprints get names (i.e. enrollment can complete
100
// after System Settings closes).
101
function assignNames(templateIds) {
102
var names = sysSettings.fingerprintNames;
103
for (var i = 0; i < templateIds.length; i++) {
104
if ( !(templateIds[i] in names) || !names[templateIds[i]])
105
names[templateIds[i]] = createTemplateName();
106
sysSettings.fingerprintNames = names;
110
signal requestPasscode()
112
Component.onCompleted: {
113
// Start a list operation immediately.
114
if (Biometryd.available) {
115
_listOperation = _ts.list(user);
116
_listOperation.start(listObserver);
120
Component.onDestruction: {
121
if (_enrollmentOperation)
122
_enrollmentOperation.cancel();
124
if (_clearanceOperation)
125
_clearanceOperation.cancel();
127
if (_removalOperation)
128
_removalOperation.cancel();
131
_listOperation.cancel();
138
target: setupPasscode
142
target: setupFingerprint
146
target: fingerprintsList
154
target: setupFingerprint
158
target: fingerprintsList
161
when: !Biometryd.available
168
boundsBehavior: (contentHeight > root.height) ?
169
Flickable.DragAndOvershootBounds :
170
Flickable.StopAtBounds
171
contentHeight: contentItem.childrenRect.height
174
anchors { left: parent.left; right: parent.right }
178
anchors { left: parent.left; right: parent.right }
182
height: setPcodeLayout.height + (divider.visible ? divider.height : 0)
185
title.text: i18n.dtr(
186
"ubuntu-settings-components",
189
subtitle.text: i18n.dtr(
190
"ubuntu-settings-components",
191
"You must set a passcode to use fingerprint ID"
194
objectName: "fingerprintSetPasscodeButton"
195
onClicked: root.requestPasscode()
197
"ubuntu-settings-components",
207
anchors { left: parent.left; right: parent.right }
211
property bool enabled: true
212
objectName: "fingerprintsList"
214
var map = sysSettings.fingerprintNames;
217
if (map.hasOwnProperty(k)) {
224
m.sort(function (a, b) {
225
if (a.name < b.name) return -1;
226
if (a.name > b.name) return 1;
227
if (a.name == b.name) return 0;
233
height: fpLayout.height + (divider.visible ? divider.height : 0)
234
onClicked: _fpInstancePage = pageStack.push(
235
Qt.resolvedUrl("Fingerprint.qml"), {
236
name: modelData.name,
237
templateId: modelData.templateId
240
enabled: fingerprintsList.enabled
244
objectName: "fingerprintInstance-" + index
245
title.text: modelData.name
256
anchors { left: parent.left; right: parent.right }
257
objectName: "fingerprintSetupEntry"
258
property bool enabled: true
262
height: addFpLayout.height + (divider.visible ? divider.height : 0)
264
_setupPage = pageStack.push(Qt.resolvedUrl("Setup.qml"));
267
enabled: parent.enabled
271
objectName: "fingerprintAddListItemLayout"
272
title.text: i18n.dtr(
273
"ubuntu-settings-components",
282
anchors.horizontalCenter: parent.horizontalCenter
283
enabled: fingerprintsList.model.length > 0
284
objectName: "fingerprintRemoveAllButton"
285
onClicked: _diag = PopupUtils.open(removeAllAlert)
286
text: i18n.dtr("ubuntu-settings-components",
297
id: removeAllAlertDialog
299
objectName: "fingerprintRemoveAllDialog"
301
"ubuntu-settings-components",
302
"Are you sure you want to forget all stored fingerprints?"
306
anchors { left: parent.left; right: parent.right }
310
onClicked: PopupUtils.close(removeAllAlertDialog)
311
text: i18n.dtr("ubuntu-settings-components", "Cancel")
312
Layout.fillWidth: true
316
objectName: "fingerprintRemoveAllConfirmationButton"
317
onClicked: root.clear()
318
text: i18n.dtr("ubuntu-settings-components", "Remove")
319
Layout.fillWidth: true
326
id: fingerprintReaderBroken
329
id: fingerprintReaderBrokenDialog
330
objectName: "fingerprintReaderBrokenDialog"
331
text: i18n.dtr("ubuntu-settings-components",
332
"Sorry, the reader doesn’t seem to be working.")
335
objectName: "fingerprintReaderBrokenDialogOK"
336
onClicked: PopupUtils.close(fingerprintReaderBrokenDialog)
337
text: i18n.dtr("ubuntu-settings-components", "OK")
344
onEnroll: root.enroll()
345
onCancel: root.cancel()
349
target: _fpInstancePage
352
_removalOperation = _ts.remove(user, templateId);
353
_removalOperation.start(removalObserver);
355
onRequestRename: renameTemplate(templateId, name)
359
id: enrollmentObserver
360
objectName: "enrollmentObserver"
363
_setupPage.enrollmentFailed(reason);
364
_enrollmentOperation = null;
365
console.error("Enrollment failed", reason);
367
onCanceled: _enrollmentOperation = null
368
onProgressed: _setupPage.enrollmentProgressed(percent, details)
370
if (!(result in sysSettings.fingerprintNames))
371
root.addTemplate(result, root.createTemplateName());
373
_setupPage.enrollmentCompleted();
374
_enrollmentOperation = null;
379
id: clearanceObserver
380
objectName: "clearanceObserver"
382
_clearanceOperation = null;
383
if (_diag) PopupUtils.close(_diag);
384
_diag = PopupUtils.open(fingerprintReaderBroken);
385
console.error("Biometry clearance failed:", reason);
387
onCanceled: _clearanceOperation = null
389
_clearanceOperation = null;
390
if (_diag) PopupUtils.close(_diag);
391
sysSettings.fingerprintNames = {};
397
objectName: "removalObserver"
399
_removalOperation = null;
401
_fpInstancePage.deletionFailed()
402
console.error("Biometryd template deletion failed:", reason);
404
onCanceled: _removalOperation = null
406
_removalOperation = null;
407
if (pageStack.currentPage === _fpInstancePage)
409
root.removeTemplate(result);
415
objectName: "listObserver"
417
_listOperation = null;
418
if (_diag) PopupUtils.close(_diag);
419
_diag = PopupUtils.open(fingerprintReaderBroken);
420
console.error("Biometryd list failed:", reason);
422
onCanceled: _listOperation = null
424
_listOperation = null;
425
root.assignNames(result);
431
uid: UbuntuSettingsFingerprint.uid
436
objectName: "systemSettings"
437
schema.id: "com.ubuntu.touch.system"