KIdentityManagement

IdentityEditorPage.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.Layouts
6import QtQuick.Controls as QQC2
7
8import org.kde.kirigami 2.20 as Kirigami
9import org.kde.kidentitymanagement 1.0
10import org.kde.kirigamiaddons.formcard 1.0 as FormCard
11
12FormCard.FormCardPage {
13 id: root
14
15 property alias mode: backend.mode
16 property alias identityUoid: backend.identityUoid
17
18 required property bool allowDelete
19 required property string identityName
20 required property var cryptographyEditorBackend
21 onCryptographyEditorBackendChanged: cryptographyEditorBackend.identity = identity
22
23 readonly property IdentityEditorBackend backend: IdentityEditorBackend {
24 id: backend
25 mode: IdentityEditorBackend.CreateMode
26 }
27 readonly property var identity: backend.identity
28 onIdentityChanged: cryptographyEditorBackend.identity = identity
29
30 readonly property QQC2.Action submitAction: QQC2.Action {
31 id: submitAction
32 enabled: !root.identity.isNull
33 shortcut: "Return"
34 onTriggered: {
35 root.backend.saveIdentity(root.identity);
36 root.closeDialog();
37 }
38 }
39
40 title: if (mode === IdentityEditorBackend.CreateMode) {
41 return i18n("Add Identity");
42 } else {
43 return i18n("Edit Identity");
44 }
45
46 header: QQC2.Control {
47 id: errorContainer
48
49 property bool displayError: false
50 property string errorMessage: ''
51
52 padding: contentItem.visible ? Kirigami.Units.smallSpacing : 0
53 leftPadding: padding
54 rightPadding: padding
55 topPadding: padding
56 bottomPadding: padding
57 contentItem: Kirigami.InlineMessage {
58 type: Kirigami.MessageType.Error
59 visible: errorContainer.displayError
60 text: errorContainer.errorMessage
61 showCloseButton: true
62 }
63 }
64
65 BasicIdentityEditorCard {
66 identity: root.identity
67 }
68
69 FormCard.FormHeader {
70 visible: root.cryptographyEditorBackend.validBackend
71 title: i18ndc("libkpimidentities6", "@title:group", "Cryptography")
72 }
73
74 Loader {
75 Layout.fillWidth: true
76 active: root.cryptographyEditorBackend.validBackend
77 sourceComponent: CryptographyEditorCard {
78 identity: root.identity
79 cryptographyEditorBackend: root.cryptographyEditorBackend
80 }
81 }
82
83 footer: ColumnLayout {
84 spacing: 0
85
86 Kirigami.Separator {
87 Layout.fillWidth: true
88 }
89
90 QQC2.DialogButtonBox {
91 Layout.fillWidth: true
92
93 standardButtons: QQC2.DialogButtonBox.Cancel
94
95 QQC2.Button {
96 icon.name: "delete"
97 text: i18n("Delete")
98 visible: root.mode === IdentityEditorBackend.EditMode
99 enabled: root.allowDelete
100 QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.DestructiveRole
101 }
102
103 QQC2.Button {
104 icon.name: root.mode === IdentityEditorBackend.EditMode ? "document-save" : "list-add"
105 text: root.mode === IdentityEditorBackend.EditMode ? i18n("Save") : i18n("Add")
106 QQC2.DialogButtonBox.buttonRole: QQC2.DialogButtonBox.AcceptRole
107 }
108
109 onRejected: root.closeDialog()
110 onAccepted: submitAction.trigger();
111 onDiscarded: {
112 dialogLoader.active = true;
113 dialogLoader.item.open();
114 }
115
116 Loader {
117 id: dialogLoader
118 sourceComponent: Kirigami.PromptDialog {
119 id: dialog
120 title: i18n("Delete %1", root.identityName)
121 subtitle: i18n("Are you sure you want to delete this identity?")
122 standardButtons: Kirigami.Dialog.NoButton
123
124 customFooterActions: [
126 text: i18n("Delete")
127 icon.name: "delete"
128 onTriggered: {
129 IdentityUtils.removeIdentity(root.identity.identityName);
130 dialog.close();
131 root.closeDialog();
132 }
133 },
134 Kirigami.Action {
135 text: i18n("Cancel")
136 icon.name: "dialog-cancel"
137 onTriggered: dialog.close()
138 }
139 ]
140 }
141 }
142 }
143 }
144}
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:57:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.