KIdentityManagement

CryptographyEditorCard.qml
1// SPDX-FileCopyrightText: 2023 Claudio Cambra <claudio.cambra@kde.org>
2// SPDX-License-Identifier: LGPL-2.0-or-later
3
4import QtQuick
5import QtQuick.Controls as QQC2
6import QtQuick.Layouts
7
8import org.kde.kirigami as Kirigami
9import org.kde.kirigamiaddons.formcard 1.0 as FormCard
10import org.kde.kidentitymanagement 1.0
11
12FormCard.FormCard {
13 id: root
14
15 // Since Identity is not a QObject and its properties do not emit signals,
16 // we use these convenience functions to update the values of each interactive
17 // component of this card when editing happens
18
19 function _index(model, keyUse) {
20 return cryptographyEditorBackend.indexForIdentity(model, identity, keyUse).row
21 }
22
23 function _updateComboIndices() {
24 combinedPgpModeCheckBox.updateChecked();
25 combinedSmimeModeCheckBox.updateChecked();
26
27 pgpSigningOrCombinedDelegate.updateIndex();
28 pgpEncryptionDelegate.updateIndex();
29 smimeSigningOrCombinedDelegate.updateIndex();
30 smimeEncryptionDelegate.updateIndex();
31 }
32
33 required property var identity
34 onIdentityChanged: _updateComboIndices()
35 required property var cryptographyEditorBackend
36
37 Component.onCompleted: _updateComboIndices()
38
40 id: pgpSigningOrCombinedDelegate
41
42 function updateIndex() {
43 currentIndex = root._index(cryptographyEditorBackend.openPgpKeyListModel, KeyUseTypes.KeySigningUse);
44 }
45
46 readonly property bool combinedMode: combinedPgpModeCheckBox.checked
47
48 text: combinedMode ? i18ndc("libkpimidentities6", "@label", "OpenPGP key") : i18ndc("libkpimidentities6", "@label", "OpenPGP signing key")
49 model: cryptographyEditorBackend.openPgpKeyListModel
50 textRole: "display"
51 valueRole: "keyByteArray"
52 onActivated: {
53 root.identity.pgpSigningKey = currentValue;
54
55 if (combinedMode) {
56 root.identity.pgpEncryptionKey = currentValue;
57 pgpEncryptionDelegate.updateIndex();
58 }
59 }
60 }
61
62 FormCard.FormDelegateSeparator {
63 above: combinedPgpModeCheckBox; below: pgpSigningOrCombinedDelegate
64 }
65
66 FormCard.FormCheckDelegate {
67 id: combinedPgpModeCheckBox
68
69 function updateChecked() {
70 const pgpEncryptionKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.pgpEncryptionKey);
71 const pgpSigningKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.pgpSigningKey);
72 checked = pgpEncryptionKey === pgpSigningKey;
73 }
74
75 text: i18ndc("libkpimidentities6", "@label", "Use same OpenPGP key for encryption and signing")
76 onClicked: {
77 if (!checked) {
78 return;
79 }
80
81 const pgpEncryptionKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.pgpEncryptionKey);
82 const pgpSigningKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.pgpSigningKey);
83
84 // Use the signing key as this is represented by the top combo box
85 if (pgpEncryptionKey !== pgpSigningKey) {
86 root.identity.pgpEncryptionKey = root.identity.pgpSigningKey;
87 }
88 }
89 }
90
91 FormCard.FormDelegateSeparator {
92 below: combinedPgpModeCheckBox
93 above: pgpEncryptionDelegate
94 visible: pgpEncryptionDelegate.visible
95 }
96
97 FormCard.FormComboBoxDelegate {
98 id: pgpEncryptionDelegate
99
100 function updateIndex() {
101 currentIndex = root._index(cryptographyEditorBackend.openPgpKeyListModel, KeyUseTypes.KeyEncryptionUse);
102 }
103
104 text: i18ndc("libkpimidentities6", "@label", "OpenPGP encryption key")
105 model: cryptographyEditorBackend.openPgpKeyListModel
106 textRole: "display"
107 valueRole: "keyByteArray"
108 onActivated: root.identity.pgpEncryptionKey = currentValue
109 visible: !combinedPgpModeCheckBox.checked
110 }
111
113 above: smimeSigningOrCombinedDelegate
114 below: pgpEncryptionDelegate.visible ? pgpEncryptionDelegate : combinedPgpModeCheckBox
115 }
116
117 FormCard.FormComboBoxDelegate {
118 id: smimeSigningOrCombinedDelegate
119
120 function updateIndex() {
121 currentIndex = root._index(cryptographyEditorBackend.smimeKeyListModel, KeyUseTypes.KeySigningUse);
122 }
123
124 property bool combinedMode: combinedSmimeModeCheckBox.checked
125
126 text: i18ndc("libkpimidentities6", "@label", "S/MIME signing key")
127 model: cryptographyEditorBackend.smimeKeyListModel
128 textRole: "display"
129 valueRole: "keyByteArray"
130 onActivated: {
131 root.identity.smimeSigningKey = currentValue;
132
133 if (combinedMode) {
134 root.identity.smimeEncryptionKey = currentValue;
135 smimeEncryptionDelegate.updateIndex();
136 }
137 }
138 }
139
140 FormCard.FormDelegateSeparator { above: combinedSmimeModeCheckBox; below: smimeSigningOrCombinedDelegate }
141
142 FormCard.FormCheckDelegate {
143 id: combinedSmimeModeCheckBox
144
145 function updateChecked() {
146 const smimeEncryptionKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.smimeEncryptionKey);
147 const smimeSigningKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.smimeSigningKey);
148 checked = smimeEncryptionKey === smimeSigningKey;
149 }
150
151 text: i18ndc("libkpimidentities6", "@label", "Use same S/MIME key for encryption and signing")
152 onClicked: {
153 if (!checked) {
154 return;
155 }
156
157 const smimeEncryptionKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.smimeEncryptionKey);
158 const smimeSigningKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.smimeSigningKey);
159
160 // Use the signing key as this is represented by the top combo box
161 if (smimeEncryptionKey !== smimeSigningKey) {
162 root.identity.smimeEncryptionKey = root.identity.smimeSigningKey;
163 }
164 }
165 }
166
167 FormCard.FormDelegateSeparator {
168 above: smimeEncryptionDelegate
169 below: combinedSmimeModeCheckBox
170 visible: !combinedSmimeModeCheckBox.checked
171 }
172
173 FormCard.FormComboBoxDelegate {
174 id: smimeEncryptionDelegate
175
176 function updateIndex() {
177 currentIndex = root._index(cryptographyEditorBackend.smimeKeyListModel, KeyUseTypes.KeyEncryptionUse);
178 }
179
180 text: i18ndc("libkpimidentities6", "@label", "S/MIME encryption key")
181 model: cryptographyEditorBackend.smimeKeyListModel
182 textRole: "display"
183 valueRole: "keyByteArray"
184 onActivated: root.identity.smimeEncryptionKey = currentValue
185 visible: !combinedSmimeModeCheckBox.checked
186 }
187}
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:04:54 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.