Debian Codegraph @

Dekko/workers/AccountsWorker.qml

raw
1 /* Copyright (C) 2016 - 2017 Dan Chapman <[email protected]>
2
3 This file is part of Dekko email client for Ubuntu devices
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of
8 the License or (at your option) version 3
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 import QtQuick 2.4
19 import QuickFlux 1.0
20 import Dekko.Mail.Accounts 1.0
21 import Dekko.Mail.API 1.0
22 import Dekko.Mail.Stores.Accounts 1.0
23
24 AppListener {
25
26 waitFor: [AccountStore.listenerId]
27
28 Filter {
29 type: AccountKeys.deleteAccount
30 onDispatched: {
31 d.__accountAboutToRemove = message.accountId
32 d.removeAccountName = message.accountName
33 if (!AccountStore.enabledAccounts.hasAccount(d.__accountAboutToRemove)) {
34 Log.logError("AccountWorker::deleteAccount", "Invalid account id. Cancelling removal")
35 if (message.confirmRemoval) {
36 ViewActions.orderSimpleToast(ViewKeys.toastSettingsWindow, qsTr("Account removal failed"));
37 }
38 }
39 // It doesn't matter which we use here
40 if (message.confirmRemoval) {
41 Log.logInfo("AccountWorker::deleteAccount", "Confirming account removal")
42 AccountActions.confirmRemoveAccount()
43 } else {
44 Log.logInfo("AccountWorker::deleteAccount", "Doesn't need confirmation. Removing now")
45 AccountActions._confirmRemoval()
46 }
47 }
48 }
49
50 Filter {
51 type: AccountKeys.confirmRemoveAccount
52 onDispatched: {
53 Log.logWarning("AccountWorker::confirmRemoveAccount", "Prompting to confirm account removal")
54 PopupActions.showConfirmationDialog(PopupKeys.popupSettings, d.removeAccountDlgId, qsTr("Remove %1").arg(d.removeAccountName), qsTr("Are you sure you wish to remove this account?"))
55 }
56 }
57
58 Filter {
59 type: PopupKeys.confirmationDialogConfirmed
60 onDispatched: {
61 if (message.id !== d.removeAccountDlgId) {
62 return;
63 }
64 Log.logInfo("AccountWorker::confirmationDialogConfirmed", "Confirmed account removal")
65 AccountActions._confirmRemoval()
66 }
67 }
68
69 Filter {
70 type: PopupKeys.confirmationDialogCancelled
71 onDispatched: {
72 if (message.id !== d.removeAccountDlgId) {
73 return
74 }
75 Log.logInfo("AccountWorker::confirmationFialogCancelled", "Cancelling account removal")
76 d.__accountAboutToRemove = -1
77 }
78 }
79
80 Filter {
81 type: AccountKeys._confirmRemoval
82 onDispatched: {
83 Log.logInfo("AccountWorker::_confirmRemoval", "Let's delete it \o/")
84 if (AccountStore.enabledAccounts.hasAccount(d.__accountAboutToRemove)) {
85 AccountActions.removeIdentitiesForAccount(d.__accountAboutToRemove)
86 AccountStore.enabledAccounts.deleteAccount(d.__accountAboutToRemove)
87 ViewActions.orderSimpleToast(ViewKeys.toastSettingsWindow, qsTr("Account removed"));
88 } else {
89 Log.logError("AccountWorker::_confirmRemoval", "Invalid account id. Cancelling removal")
90 ViewActions.orderSimpleToast(ViewKeys.toastSettingsWindow, qsTr("Account removal failed"));
91 }
92 d.__accountAboutToRemove = -1
93 }
94 }
95
96 Filter {
97 type: AccountKeys.addIdentity
98 onDispatched: {
99 Log.logInfo("AccountWorker::addIdentity", "Adding new identity")
100 var identity = message.identity
101 if (identity.id) {
102 Log.logInfo("AccountWorker::addIdentity", "Identity has valid id. Updating instead")
103 AccountActions.updateIdentity(identity)
104 } else {
105 if (AccountStore.identities.add(identity)) {
106 Log.logInfo("AccountWorker::addIdentity", "Identity created")
107 } else {
108 Log.logError("AccountWorker::addIdentity", "Failed creating identity")
109 }
110 }
111 }
112 }
113
114 Filter {
115 type: AccountKeys.updateIdentity
116 onDispatched: {
117 Log.logInfo("AccountWorker::updateIdentity", "Adding new identity")
118 var identity = message.identity
119 if (!identity.id) {
120 Log.logInfo("AccountWorker::updateIdentity", "Identity has no valid id. Adding new identity instead")
121 AccountActions.addIdentity(identity)
122 } else {
123 if (AccountStore.identities.update(identity)) {
124 Log.logInfo("AccountWorker::updateIdentity", "Identity updated")
125 } else {
126 Log.logError("AccountWorker::updateIdentity", "Identity update failed")
127 }
128 }
129 }
130 }
131
132 Filter {
133 type: AccountKeys.removeIdentity
134 onDispatched: {
135 if (AccountStore.identities.remove(message.id)) {
136 Log.logInfo("AccountWorker::removeIdentity", "Identity removed")
137 } else {
138 Log.logError("AccountWorker::removeIdentity", "Identity removal failed")
139 }
140 }
141 }
142
143 Filter {
144 type: AccountKeys.removeIdentitiesForAccount
145 onDispatched: {
146 Log.logInfo("AccountWorker::removeIdentitiesForAccount", "Removing identities for account")
147 AccountStore.identities.removeAccount(message.accountId)
148 }
149 }
150
151 QtObject {
152 id: d
153 property string removeAccountDlgId: "remove-account-dlg"
154 property string removeAccountName: "remove-account-name"
155 property int __accountAboutToRemove: -1
156 }
157 }