Warning, /pim/kidentitymanagement/src/quick/qml/CryptographyEditorCard.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 Claudio Cambra <claudio.cambra@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003
0004 import QtQuick 2.15
0005 import QtQuick.Controls 2.15 as QQC2
0006 import QtQuick.Layouts 1.15
0007
0008 import org.kde.kirigami 2.19 as Kirigami
0009 import org.kde.kirigamiaddons.formcard 1.0 as FormCard
0010 import org.kde.kidentitymanagement 1.0
0011
0012 FormCard.FormCard {
0013 id: root
0014
0015 // Since Identity is not a QObject and its properties do not emit signals,
0016 // we use these convenience functions to update the values of each interactive
0017 // component of this card when editing happens
0018
0019 function _index(model, keyUse) {
0020 return cryptographyEditorBackend.indexForIdentity(model, identity, keyUse).row
0021 }
0022
0023 function _updateComboIndices() {
0024 combinedPgpModeCheckBox.updateChecked();
0025 combinedSmimeModeCheckBox.updateChecked();
0026
0027 pgpSigningOrCombinedDelegate.updateIndex();
0028 pgpEncryptionDelegate.updateIndex();
0029 smimeSigningOrCombinedDelegate.updateIndex();
0030 smimeEncryptionDelegate.updateIndex();
0031 }
0032
0033 required property var identity
0034 onIdentityChanged: _updateComboIndices()
0035 required property var cryptographyEditorBackend
0036
0037 Component.onCompleted: _updateComboIndices()
0038
0039 FormCard.FormComboBoxDelegate {
0040 id: pgpSigningOrCombinedDelegate
0041
0042 function updateIndex() {
0043 currentIndex = root._index(cryptographyEditorBackend.openPgpKeyListModel, KeyUseTypes.KeySigningUse);
0044 }
0045
0046 readonly property bool combinedMode: combinedPgpModeCheckBox.checked
0047
0048 text: combinedMode ? i18ndc("libkpimidentities6", "@label", "OpenPGP key") : i18ndc("libkpimidentities6", "@label", "OpenPGP signing key")
0049 model: cryptographyEditorBackend.openPgpKeyListModel
0050 textRole: "display"
0051 valueRole: "keyByteArray"
0052 onActivated: {
0053 root.identity.pgpSigningKey = currentValue;
0054
0055 if (combinedMode) {
0056 root.identity.pgpEncryptionKey = currentValue;
0057 pgpEncryptionDelegate.updateIndex();
0058 }
0059 }
0060 }
0061
0062 FormCard.FormDelegateSeparator {
0063 above: combinedPgpModeCheckBox; below: pgpSigningOrCombinedDelegate
0064 }
0065
0066 FormCard.FormCheckDelegate {
0067 id: combinedPgpModeCheckBox
0068
0069 function updateChecked() {
0070 const pgpEncryptionKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.pgpEncryptionKey);
0071 const pgpSigningKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.pgpSigningKey);
0072 checked = pgpEncryptionKey === pgpSigningKey;
0073 }
0074
0075 text: i18ndc("libkpimidentities6", "@label", "Use same OpenPGP key for encryption and signing")
0076 onClicked: {
0077 if (!checked) {
0078 return;
0079 }
0080
0081 const pgpEncryptionKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.pgpEncryptionKey);
0082 const pgpSigningKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.pgpSigningKey);
0083
0084 // Use the signing key as this is represented by the top combo box
0085 if (pgpEncryptionKey !== pgpSigningKey) {
0086 root.identity.pgpEncryptionKey = root.identity.pgpSigningKey;
0087 }
0088 }
0089 }
0090
0091 FormCard.FormDelegateSeparator {
0092 below: combinedPgpModeCheckBox
0093 above: pgpEncryptionDelegate
0094 visible: pgpEncryptionDelegate.visible
0095 }
0096
0097 FormCard.FormComboBoxDelegate {
0098 id: pgpEncryptionDelegate
0099
0100 function updateIndex() {
0101 currentIndex = root._index(cryptographyEditorBackend.openPgpKeyListModel, KeyUseTypes.KeyEncryptionUse);
0102 }
0103
0104 text: i18ndc("libkpimidentities6", "@label", "OpenPGP encryption key")
0105 model: cryptographyEditorBackend.openPgpKeyListModel
0106 textRole: "display"
0107 valueRole: "keyByteArray"
0108 onActivated: root.identity.pgpEncryptionKey = currentValue
0109 visible: !combinedPgpModeCheckBox.checked
0110 }
0111
0112 FormCard.FormDelegateSeparator {
0113 above: smimeSigningOrCombinedDelegate
0114 below: pgpEncryptionDelegate.visible ? pgpEncryptionDelegate : combinedPgpModeCheckBox
0115 }
0116
0117 FormCard.FormComboBoxDelegate {
0118 id: smimeSigningOrCombinedDelegate
0119
0120 function updateIndex() {
0121 currentIndex = root._index(cryptographyEditorBackend.smimeKeyListModel, KeyUseTypes.KeySigningUse);
0122 }
0123
0124 property bool combinedMode: combinedSmimeModeCheckBox.checked
0125
0126 text: i18ndc("libkpimidentities6", "@label", "S/MIME signing key")
0127 model: cryptographyEditorBackend.smimeKeyListModel
0128 textRole: "display"
0129 valueRole: "keyByteArray"
0130 onActivated: {
0131 root.identity.smimeSigningKey = currentValue;
0132
0133 if (combinedMode) {
0134 root.identity.smimeEncryptionKey = currentValue;
0135 smimeEncryptionDelegate.updateIndex();
0136 }
0137 }
0138 }
0139
0140 FormCard.FormDelegateSeparator { above: combinedSmimeModeCheckBox; below: smimeSigningOrCombinedDelegate }
0141
0142 FormCard.FormCheckDelegate {
0143 id: combinedSmimeModeCheckBox
0144
0145 function updateChecked() {
0146 const smimeEncryptionKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.smimeEncryptionKey);
0147 const smimeSigningKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.smimeSigningKey);
0148 checked = smimeEncryptionKey === smimeSigningKey;
0149 }
0150
0151 text: i18ndc("libkpimidentities6", "@label", "Use same S/MIME key for encryption and signing")
0152 onClicked: {
0153 if (!checked) {
0154 return;
0155 }
0156
0157 const smimeEncryptionKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.smimeEncryptionKey);
0158 const smimeSigningKey = root.cryptographyEditorBackend.stringFromKeyByteArray(root.identity.smimeSigningKey);
0159
0160 // Use the signing key as this is represented by the top combo box
0161 if (smimeEncryptionKey !== smimeSigningKey) {
0162 root.identity.smimeEncryptionKey = root.identity.smimeSigningKey;
0163 }
0164 }
0165 }
0166
0167 FormCard.FormDelegateSeparator {
0168 above: smimeEncryptionDelegate
0169 below: combinedSmimeModeCheckBox
0170 visible: !combinedSmimeModeCheckBox.checked
0171 }
0172
0173 FormCard.FormComboBoxDelegate {
0174 id: smimeEncryptionDelegate
0175
0176 function updateIndex() {
0177 currentIndex = root._index(cryptographyEditorBackend.smimeKeyListModel, KeyUseTypes.KeyEncryptionUse);
0178 }
0179
0180 text: i18ndc("libkpimidentities6", "@label", "S/MIME encryption key")
0181 model: cryptographyEditorBackend.smimeKeyListModel
0182 textRole: "display"
0183 valueRole: "keyByteArray"
0184 onActivated: root.identity.smimeEncryptionKey = currentValue
0185 visible: !combinedSmimeModeCheckBox.checked
0186 }
0187 }