KIdentityManagement

BasicIdentityEditorCard.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
7import Qt.labs.platform
8
9import org.kde.kirigami as Kirigami
10import org.kde.kirigamiaddons.formcard 1.0 as FormCard
11import org.kde.kidentitymanagement 1.0
12
13ColumnLayout {
14 id: root
15
16 required property var identity
17 property alias toAddEmailText: toAddEmail.text
18
19 function isNotEmptyStr(str) {
20 return str.trim().length > 0;
21 }
22
23 spacing: 0
24
25 FormCard.FormHeader {
26 title: i18n("Identity")
27 }
28
29 FormCard.FormCard {
30 FormCard.FormTextFieldDelegate {
31 id: identityDelegate
32 label: i18nc("@label:textbox", "Identity Name")
33 text: root.identity.identityName
34 onTextChanged: root.identity.identityName = text
35 }
37 id: nameDelegate
38 Layout.fillWidth: true
39 label: i18n("Your name")
40 text: root.identity.fullName
41 onTextChanged: root.identity.fullName = text
42 }
43
45 id: emailDelegate
46 label: i18n("Email address")
47 text: root.identity.primaryEmailAddress
48 onTextChanged: root.identity.primaryEmailAddress = text
49 inputMethodHints: Qt.ImhEmailCharactersOnly
50 }
51 }
52
54 title: i18n("E-mail aliases")
55 }
56
57 FormCard.FormCard {
58 Repeater {
59 id: emailAliasesRepeater
60
61 property var emailAliases: root.identity.emailAliases
62
63 model: emailAliases
64
65 delegate: FormCard.AbstractFormDelegate {
66 id: emailRow
67
68 Layout.fillWidth: true
69
70 contentItem: RowLayout {
71 QQC2.TextField {
72 id: emailAliasField
73 Layout.fillWidth: true
74 text: modelData
75 inputMethodHints: Qt.ImhEmailCharactersOnly
76 onEditingFinished: {
77 let emailAliases = emailAliasesRepeater.emailAliases;
78 emailAliases[model.index] = text;
79 identity.emailAliases = emailAliases;
80 emailAliasesRepeater.emailAliases = emailAliases;
81 }
82 }
83
84 QQC2.Button {
85 icon.name: "list-remove"
86 implicitWidth: implicitHeight
87 QQC2.ToolTip {
88 text: i18n("Remove email alias")
89 }
90 onClicked: {
91 let emailAliases = emailAliasesRepeater.emailAliases;
92 emailAliases = Array.from(emailAliases).filter(email => email !== modelData);
93 identity.emailAliases = emailAliases;
94 emailAliasesRepeater.emailAliases = emailAliases;
95 }
96 }
97 }
98 }
99 }
100
101 FormCard.AbstractFormDelegate {
102 Layout.fillWidth: true
103
104 contentItem: RowLayout {
105 QQC2.TextField {
106 id: toAddEmail
107 Layout.fillWidth: true
108 placeholderText: i18n("user@example.org")
109 inputMethodHints: Qt.ImhEmailCharactersOnly
110 }
111
112 QQC2.Button {
113 icon.name: "list-add"
114 implicitWidth: implicitHeight
115 enabled: isNotEmptyStr(toAddEmail.text)
116 QQC2.ToolTip {
117 text: i18n("Add email alias")
118 }
119 onClicked: {
120 let emailAliases = emailAliasesRepeater.emailAliases;
121 emailAliases.push(toAddEmail.text);
122 identity.emailAliases = emailAliasesRepeater.emailAliases;
123 emailAliasesRepeater.emailAliases = emailAliases;
124 toAddEmail.clear();
125 }
126 }
127 }
128 }
129 }
130}
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
QString label(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.