Debian Codegraph @

qml/Components/KeysDelegate.qml

raw
1 /*
2 * This file is part of the 2FA Manager App for Ubuntu Touch
3 * Copyright (C) 2019 Joan CiberSheep
4 *
5 * This App is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 *
10 * This App is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 import QtQuick 2.9
21 import Lomiri.Components 1.3
22
23 //TODO: Avoid loading this on every element
24 //try send signals for delete and refresh
25 import QtQuick.LocalStorage 2.0
26 import "../js/db.js" as KeysDB
27
28 ListItem {
29 width: parent.width
30 anchors.horizontalCenter: parent.horizontalCenter
31 divider.visible: false
32 clip: true
33 highlightColor: root.highlightColor
34
35 onClicked: {
36 mainStack.push(Qt.resolvedUrl("PageKeysInfo.qml"), {
37 "key": authkey,
38 "id": id,
39 "reminingTime": bar.value,
40 "secret": secret,
41 "url": url,
42 "desc": desc
43 });
44
45 root.leftSearchView();
46 }
47
48 leadingActions: ListItemActions {
49 actions: Action {
50 iconName: "delete"
51 text: i18n.tr("Delete")
52 onTriggered: {
53 KeysDB.deleteKey(id);
54 root.initDB();
55 }
56 }
57 }
58
59 trailingActions: ListItemActions {
60 actions: [
61 Action {
62 enabled: authkey.period == undefined
63 visible: enabled
64 iconName: "view-refresh"
65 onTriggered: {
66 var difference = 1;
67 KeysDB.updateCounter(id, difference);
68 root.initDB();
69 }
70 },
71 Action {
72 iconName: "edit-copy"
73 text: i18n.tr("Copy key")
74 onTriggered: {
75 Clipboard.push(root.formatCode(layout.title.text, false))
76 }
77 },
78 Action {
79 iconName: "edit"
80 text: i18n.tr("Edit key")
81 onTriggered: {
82 mainStack.push(Qt.resolvedUrl("PageEditAddKey.qml"), {
83 "editMode": true,
84 "uriToEdit": url,
85 "descriptionToEdit": desc,
86 "idToUpdate": id
87 });
88
89 root.leftSearchView();
90 }
91 }
92 ]
93 }
94
95 ListItemLayout {
96 id:layout
97
98 title.text: authkey.counter == undefined
99 ? root.formatCode(OTPAuth.TOTP.generate(authkey), true)
100 : root.formatCode(OTPAuth.HOTP.generate(authkey), true);
101 title.font.bold: true
102
103 subtitle.text: !!!desc
104 ? i18n.tr("%1 at %2").arg(authkey.label).arg(authkey.issuer)
105 : i18n.tr("%1. %2 at %3").arg(desc).arg(authkey.label).arg(authkey.issuer)
106
107 width: parent.width
108 anchors.horizontalCenter: parent.horizontalCenter
109
110 Text {
111 id: currentCounter
112 SlotsLayout.position: SlotsLayout.Trailing
113 text: authkey.counter == undefined
114 ? ""
115 : i18n.tr("# %1").arg(authkey.counter)
116 color: theme.palette.normal.baseText
117 }
118
119 ProgressionSlot {}
120
121 //Let's connect with the main ticker
122 Connections {
123 target: timer
124
125 onTriggered: {
126 layout.title.text = authkey.counter == undefined
127 ? root.formatCode(OTPAuth.TOTP.generate(authkey), true)
128 : root.formatCode(OTPAuth.HOTP.generate(authkey), true);
129
130 bar.value = timer.time % authkey.period
131 }
132 }
133 }
134
135 ProgressBar {
136 id: bar
137 visible: authkey.counter == undefined
138 width: parent.width
139 anchors.bottom: parent.bottom
140
141 maximumValue: authkey.period || 0
142 minimumValue: 0
143 value: timer.time % authkey.period
144 }
145 }