Dekko
Loading...
Searching...
No Matches
IdentityInput.qml
1import QtQuick 2.4
2import Lomiri.Components 1.3
3import QtQuick.Controls.Suru 2.2
4// FIXME: These are most likely going to be deprecated soon
5import Lomiri.Components.ListItems 1.0 as CanWeStillUseThis
6import Dekko.Mail.API 1.0
7import Dekko.Mail.Stores.Accounts 1.0
8import Dekko.Mail.Stores.Settings 1.0
9import QuickFlux 1.0
10import Dekko.Lomiri.Components 1.0
12PageFlickable {
13 id: input
14 property bool newIdentity: false
15
16 AppListener {
17 Filter {
18 type: SettingsKeys.saveCurrentGroup
19 onDispatched: {
20 if (SettingsStore.saveGroupDisabled) {
21 return
22 }
23 SettingsStore.tempIsNew = input.newIdentity
24 SettingsStore.tempIdentity = input.toMap()
25 }
26 }
27
28 Filter {
29 type: SettingsKeys.saveIdentity
30 onDispatched: {
31 if (newIdentity) {
32 AccountActions.addIdentity(input.toMap())
33 } else {
34 AccountActions.updateIdentity(input.toMap())
35 }
36 }
37 }
38 }
39
40 function toMap() {
41 var map = {}
42 if (!newIdentity) {
43 map["id"] = SettingsStore.tempIdentity.id
44 }
45 map["parentId"] = accountSelector.selectedAccount
46 map["name"] = name.text
47 map["email"] = email.text
48 map["replyTo"] = replyTo.text
49 map["signature"] = signature.text
50 return map
51 }
52
54 readonly property bool isDefault: SettingsStore.tempIdentity.id === AccountStore.identities.defaultIdentity
55 text: qsTr("Default identity")
56 visible: !input.newIdentity
57 checked: isDefault
58 onCheckedChanged: {
59 if (checked) {
60 AccountStore.identities.defaultIdentity = SettingsStore.tempIdentity.id
61 } else if (isDefault) {
62 AccountStore.identities.defaultIdentity = -1
63 }
64 }
65 }
66
67 Label {
68 text: qsTr("Account")
69 color: Suru.secondaryForegroundColor
70 }
71
72 CanWeStillUseThis.ItemSelector {
73 id: accountSelector
74 property int setIdx: 0
75 property int selectedAccount
76 property Timer setIndexTimer: Timer {
77 interval: 100
78 repeat: false
79 onTriggered: accountSelector.selectedIndex = accountSelector.setIdx
80 }
81 model: AccountStore.enabledAccountsModel
82 delegate: OptionSelectorDelegate {
83 id: delegate
84 property bool isSelected: accountSelector.selectedIndex === model.index
85 property var account: model.qtObject
86 text: account.name
87 Binding {
88 target: accountSelector
89 property: "selectedAccount"
90 value: delegate.account.id
91 when: delegate.isSelected
92 }
93 Component.onCompleted: {
94 if (!input.newIdentity || SettingsStore.tempIsNew) {
95 if (SettingsStore.tempIdentity.parentId === account.id) {
96 accountSelector.setIdx = model.index
97 accountSelector.setIndexTimer.start()
98 }
99 }
100 }
101 }
102 }
103
105 id: name
106 title: qsTr("Name")
107 }
108
110 id: email
111 title: qsTr("Email Address")
112 }
113
115 id: replyTo
116 title: qsTr("Reply-To")
117 }
118
119 Label {
120 text: qsTr("Signature")
121 color: Suru.secondaryForegroundColor
122 }
123
124 TextArea {
125 id: signature
126 anchors {
127 left: parent.left
128 right: parent.right
129 }
130 }
131
132 states: [
133 State {
134 name: "new"
135 when: input.newIdentity && !SettingsStore.tempIsNew
136 PropertyChanges {
137 target: root
138 title: qsTr("New identity")
139 }
140 },
141 State {
142 name: "new-continued"
143 when: input.newIdentity && SettingsStore.tempIsNew
144 PropertyChanges {
145 target: root
146 title: qsTr("New identity")
147 }
148 PropertyChanges {
149 target: name
150 text: SettingsStore.tempIdentity.name
151 }
152 PropertyChanges {
153 target: email
154 text: SettingsStore.tempIdentity.email
155 }
156 PropertyChanges {
157 target: replyTo
158 text: SettingsStore.tempIdentity.replyTo
159 }
160 PropertyChanges {
161 target: signature
162 text: SettingsStore.tempIdentity.signature
163 }
164 },
165 State {
166 name: "edit"
167 when: !input.newIdentity
168 PropertyChanges {
169 target: root
170 title: qsTr("Edit identity")
171 }
172 PropertyChanges {
173 target: name
174 text: SettingsStore.tempIdentity.name
175 }
176 PropertyChanges {
177 target: email
178 text: SettingsStore.tempIdentity.email
179 }
180 PropertyChanges {
181 target: replyTo
182 text: SettingsStore.tempIdentity.replyTo
183 }
184 PropertyChanges {
185 target: signature
186 text: SettingsStore.tempIdentity.signature
187 }
188 }
189 ]
190}