Debian Codegraph @

Dekko/workers/MailboxWorker.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 1.0
21 import Dekko.Mail.API 1.0
22 import Dekko.Mail.Stores.Mail 1.0
23
24 AppListener {
25
26 waitFor: [
27 MailboxStore.listenerId
28 ]
29
30 property string mailboxPickerUrl: ""
31
32 Filter {
33 type: MessageKeys.resetFolderLists
34 onDispatched: {
35 MailboxStore.smartFolders.reset()
36 MailboxStore.standardFolders.reset()
37 }
38 }
39 Filter {
40 type: MailboxKeys.emptyTrash
41 onDispatched: {
42 Log.logInfo("MailboxWorker::emptyTrash", "Emptying trash folder. This cannot be undone!")
43 Client.emptyTrash()
44 }
45 }
46 Filter {
47 type: MailboxKeys.markStandardFoldersRead
48 onDispatched: {
49 Log.logInfo("MailboxWorker::markStandardFoldersRead", "Marking unified standard folder as read")
50 Client.markStandardFolderRead(message.standardFolder)
51 }
52 }
53
54 Filter {
55 type: MailboxKeys.markStandardFolderRead
56 onDispatched: {
57 Log.logInfo("MailboxWorker::markStandardFolderRead", "Marking standard folder for account id: %1 as read".arg(message.accountId))
58 Client.markStandardFolderRead(message.accountId, message.standardFolder)
59 }
60 }
61
62 Filter {
63 type: MailboxKeys.syncStandardFolders
64 onDispatched: {
65 Log.logInfo("MailboxWorker::syncStandardFolders", "Syncing standard folder")
66 Client.syncStandardFolder(message.standardFolder)
67 MailboxStore.folderSyncActive = true
68 }
69 }
70
71 Filter {
72 type: MailboxKeys.syncStandardFolder
73 onDispatched: {
74 Log.logInfo("MailboxWorker::syncStandardFolder", "Syncing folder for account: %1".arg(message.accountId))
75 Client.syncStandardFolder(message.accountId, message.standardFolder)
76 MailboxStore.folderSyncActive = true
77 }
78 }
79
80 Filter {
81 type: MailboxKeys.syncFolder
82 onDispatched: {
83 Log.logInfo("MailboxWorker::syncFolder", "Syncing folder for account: %1".arg(message.accountId))
84 Client.syncFolder(message.accountId, message.folderId)
85 MailboxStore.folderSyncActive = true
86 }
87 }
88
89 Filter {
90 type: MailboxKeys.resetSelectedMsgIndex
91 onDispatched: {
92 MailStore.currentSelectedIndex = -1
93 MailStore.currentMessageId = -1
94 }
95 }
96
97 Filter {
98 type: MessageKeys.setCurrentMessage
99 onDispatched: {
100 Log.logInfo("MailboxWorker::setCurrentMessage", "Settings current msg to: %1".arg(message.msgId))
101 MailStore.currentMessageId = message.msgId
102 }
103 }
104
105 AppScript {
106 property string pickerId: "move-msg-picker"
107 runWhen: MailboxKeys.moveMessage
108 script: {
109 Log.logInfo("MailboxWorker::moveMessage", "Opening folder picker.")
110 ViewActions.pushToStageArea(ViewKeys.messageListStack,
111 mailboxPickerUrl,
112 {
113 pickerId: pickerId,
114 accountId: message.accountId
115 })
116 once(MailboxKeys.folderSelected, function (result) {
117 Log.logInfo("MailboxWorker::moveMessage", "Folder selected")
118 if (result.pickerId !== pickerId) {
119 return;
120 }
121 if (result.folderType === Folder.StandardFolder) {
122 d.moveConfig = {specialUse: false, id: message.msgId, folder: result.folderId}
123 } else {
124 d.moveConfig = {specialUse: true, id: message.msgId, folder: result.folderType}
125 }
126 ViewActions.popStageArea(ViewKeys.messageListStack)
127 Log.logInfo("MailboxWorker::moveMessage", "Ordering the mail squirrels to take this message somewhere else")
128 d.delayMoveTimer.start()
129 })
130 once(MailboxKeys.moveMessageCancelled, function (msg) {
131 ViewActions.popStageArea(ViewKeys.messageListStack)
132 exit.bind(this, 0)
133 })
134 }
135
136 }
137
138 Connections {
139 target: Client
140 onFoldersSynced: {
141 MailboxStore.folderSyncActive = false
142 if(folderSyncErrorOccurred) {
143 console.log("Errors occurred during folder synchronization.");
144 }
145 }
146 }
147
148 QtObject {
149 id: d
150 property var moveConfig
151 property Timer delayMoveTimer: Timer {
152 interval:300
153 repeat: false
154 onTriggered: {
155 Log.logInfo("MailboxWorker::moveMessage", "Ok the squirrels have been released! Message now in transit")
156 if(d.moveConfig["specialUse"]) {
157 Client.moveToStandardFolder(d.moveConfig["id"], d.moveConfig["folder"])
158 } else {
159 Client.moveToFolder(d.moveConfig["id"], d.moveConfig["folder"])
160 }
161 ViewActions.orderSimpleToast(ViewKeys.toastMainWindow, qsTr("Message moved"))
162 }
163 }
164 }
165 }