Debian Codegraph @

src/app/qml/authentication/FingerprintDialog.qml

raw
1 /*
2 * Copyright (C) 2017 Stefano Verzegnassi
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 3 as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see http://www.gnu.org/licenses/.
16 */
17
18 import QtQuick 2.4
19 import Lomiri.Components 1.3
20 import Lomiri.Components.Popups 1.3
21 import Biometryd 0.0 as BiometrydPlugin
22
23 Dialog {
24 id: fingerprintDialog
25
26 title: i18n.tr("Authentication required")
27 text: i18n.tr("Use your fingerprint to access restricted content")
28
29 signal succeeded()
30 signal failed(var reason)
31 signal aborted()
32 signal usePasswordRequested()
33
34 Row {
35 spacing: units.gu(1)
36 height: units.gu(8)
37
38 Rectangle {
39 id: fingerprintCircle
40 width: units.gu(8); height: width; radius: width * 0.5
41 color: theme.palette.normal.focus
42
43 Icon {
44 anchors.fill: parent
45 source: Qt.resolvedUrl("assets/fingerprint.png")
46 color: "white"
47 }
48 }
49
50 Label {
51 id: fingerprintHint
52 anchors.verticalCenter: parent.verticalCenter
53 color: theme.palette.normal.backgroundTertiaryText
54 // TRANSLATORS: "Touch" here is a verb
55 text: i18n.tr("Touch sensor")
56 }
57 }
58
59 Button {
60 text: i18n.tr("Use password")
61 onClicked: {
62 fingerprintDialog.usePasswordRequested()
63 PopupUtils.close(fingerprintDialog)
64 }
65 }
66
67 Button {
68 text: i18n.tr("Cancel")
69 onClicked: {
70 fingerprintDialog.aborted()
71 PopupUtils.close(fingerprintDialog)
72 }
73 }
74
75 /*** BIOMETRYD ***/
76 BiometrydPlugin.Observer {
77 id: biometryd
78
79 property var operation: null
80
81 function cancelOperation() {
82 if (operation) {
83 operation.cancel();
84 operation = null;
85 }
86 }
87
88 function restartOperation() {
89 cancelOperation();
90
91 var identifier = BiometrydPlugin.Biometryd.defaultDevice.identifier;
92 operation = identifier.identifyUser();
93 operation.start(biometryd);
94 }
95
96 Component.onCompleted: restartOperation()
97 Component.onDestruction: cancelOperation()
98
99 onSucceeded: {
100 console.log("Identified user by fingerprint:", result);
101 fingerprintDialog.succeeded()
102 PopupUtils.close(fingerprintDialog)
103 }
104
105 onFailed: {
106 console.log("Failed to identify user by fingerprint:", reason);
107 authFailedAnimation.restart()
108 fingerprintDialog.failed(reason)
109 }
110 }
111
112 /*** ANIMATIONS ***/
113 SequentialAnimation {
114 id: authFailedAnimation
115
116 ParallelAnimation {
117 ColorAnimation {
118 target: fingerprintCircle
119 property: "color"
120 from: theme.palette.normal.focus
121 to: theme.palette.normal.negative
122 duration: 250
123 }
124 ScriptAction { script: fingerprintHint.text = i18n.tr("Authentication failed!") }
125 }
126
127 ParallelAnimation {
128 ColorAnimation {
129 target: fingerprintCircle
130 property: "color"
131 from: theme.palette.normal.negative
132 to: theme.palette.normal.focus
133 duration: 250
134 }
135 ScriptAction { script: fingerprintHint.text = i18n.tr("Please retry") }
136 }
137 }
138 }
139