| 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 |
import Dekko.Mail.Stores.Views 1.0 |
| 24 |
|
| 25 |
AppListener { |
| 26 |
|
| 27 |
waitFor: [ |
| 28 |
MailStore.listenerId, |
| 29 |
ViewStore.listenerId |
| 30 |
] |
| 31 |
|
| 32 |
Filter { |
| 33 |
type: MessageKeys.changeMessageListSortOrder |
| 34 |
onDispatched: { |
| 35 |
if (message.order !== Qt.DescendingOrder || message.order !== Qt.AscendingOrder) { |
| 36 |
Log.logError("MailWorker::changeMessageListOrder", "Unknown sort order... defaulting to descending order") |
| 37 |
MailStore.msgList.sortOrder = Qt.DescendingOrder |
| 38 |
} else { |
| 39 |
MailStore.msgList.sortOrder = message.order |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
AppScript { |
| 45 |
id: openFolderScript |
| 46 |
property var fkey |
| 47 |
property string fname |
| 48 |
runWhen: MessageKeys.openFolder |
| 49 |
script: { |
| 50 |
Log.logStatus("MailWorker::openFolder", "Opening %1 folder with key %2".arg(message.folderName).arg(message.folderKey)) |
| 51 |
// So this is a performance critical point. Well for the UI anyway |
| 52 |
// We may have views stacked ontop of the base message list view |
| 53 |
// so before we go resetting models we first need to rewind the stack to the view we |
| 54 |
// want and *then* reset the model and apply the new key |
| 55 |
MessageActions.rewindMessageListStack() |
| 56 |
|
| 57 |
// Wait for the MailStage to inform us the stack has been rewound |
| 58 |
once(MessageKeys.stackRewound, function() { |
| 59 |
MessageActions.resetMessageList() |
| 60 |
MailStore.currentMessageId = -1 |
| 61 |
// nice! we still have the message value captured from script execution |
| 62 |
// so we don't need to store the values in tmp properties |
| 63 |
MailStore.folderTitle = message.folderName |
| 64 |
ViewActions.setCurrentNavFolder(MailStore.folderTitle) |
| 65 |
MailStore.msgList.messageKey = message.folderKey |
| 66 |
}) |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
// Delete selected messages. Use when in selection mode |
| 71 |
Filter { |
| 72 |
type: MessageKeys.deleteSelectedMessages |
| 73 |
onDispatched: { |
| 74 |
if (!MailStore.isInSelectionMode) { |
| 75 |
Log.logError("MailWorker::deleteSelectedMessages", "Not in selection mode! Not going to delete anything...") |
| 76 |
return; |
| 77 |
} |
| 78 |
MailStore.msgList.deleteSelectedMessages() |
| 79 |
} |
| 80 |
} |
| 81 |
Filter { |
| 82 |
type: MessageKeys.markSelectedMessagesRead |
| 83 |
onDispatched: { |
| 84 |
if (!MailStore.isInSelectionMode) { |
| 85 |
Log.logError("MailWorker::markSeectedMessagesRead", "Not in selection mode! Not applying action...") |
| 86 |
return |
| 87 |
} |
| 88 |
MailStore.msgList.markSelectedMessagesRead() |
| 89 |
} |
| 90 |
} |
| 91 |
|
| 92 |
Filter { |
| 93 |
type: MessageKeys.markSelectedMessagesImportant |
| 94 |
onDispatched: { |
| 95 |
if (!MailStore.isInSelectionMode) { |
| 96 |
Log.logError("MailWorker::markSelectedMessagesImportant", "Not in selection mode! Not applying action...") |
| 97 |
return |
| 98 |
} |
| 99 |
MailStore.msgList.markSelectedMessagesImportant() |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
Filter { |
| 104 |
type: MessageKeys.undoRecentActions |
| 105 |
onDispatched: { |
| 106 |
if (MailStore.hasUndoableActions) { |
| 107 |
Log.logInfo("MailWorker::undoRecentActions", "Undoing actions from the last 5 seconds") |
| 108 |
Client.undoActions() |
| 109 |
} |
| 110 |
} |
| 111 |
} |
| 112 |
|
| 113 |
Filter { |
| 114 |
type: MessageKeys.setMessageListFilter |
| 115 |
onDispatched: { |
| 116 |
Log.logInfo("MailWorker::setMessageListFilter", "Setting message list filter with index: " + message.filter) |
| 117 |
MailStore.msgList.filter = message.filter |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
Filter { |
| 122 |
type: MessageKeys.setMessageCheck |
| 123 |
onDispatched: { |
| 124 |
Log.logInfo("MailWorker::setMessageCheck", "Setting %1 as checked: %2".arg(message.msgIndex).arg(message.checked)) |
| 125 |
MailStore.msgList.setChecked(message.msgIndex, message.checked) |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
Filter { |
| 130 |
type: MessageKeys.startMultiSelection |
| 131 |
onDispatched: { |
| 132 |
Log.logStatus("MailWorker::startMultiSelection", "Started") |
| 133 |
MailStore.msgList.startSelection() |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
Filter { |
| 138 |
type: MessageKeys.endMultiSelection |
| 139 |
onDispatched: { |
| 140 |
Log.logStatus("MailWorker::endMultiSelection", "Ended") |
| 141 |
MailStore.msgList.endSelection() |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
Filter { |
| 146 |
type: MessageKeys.selectAllMessages |
| 147 |
onDispatched: { |
| 148 |
Log.logInfo("MailWorker::selectAllMessages", "Selecting all messages") |
| 149 |
MailStore.msgList.selectAll() |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
Filter { |
| 154 |
type: MessageKeys.unselectAllMessages |
| 155 |
onDispatched: MailStore.msgList.unselectAll() |
| 156 |
} |
| 157 |
|
| 158 |
Filter { |
| 159 |
type: MessageKeys.showMoreMessages |
| 160 |
onDispatched: MailStore.msgList.loadMore() |
| 161 |
} |
| 162 |
|
| 163 |
// Delete message by ID |
| 164 |
Filter { |
| 165 |
type: MessageKeys.deleteMessage |
| 166 |
onDispatched: { |
| 167 |
Log.logInfo("MailWorker::deleteMessage", "Deleting message %1".arg(message.msgId)) |
| 168 |
if (ViewStore.formFactor === "small") { |
| 169 |
MailboxActions.resetSelectedMsgIndex() |
| 170 |
} |
| 171 |
Client.deleteMessage(message.msgId) |
| 172 |
} |
| 173 |
} |
| 174 |
Filter { |
| 175 |
type: MessageKeys.markMessageRead |
| 176 |
onDispatched: { |
| 177 |
Log.logInfo("MailWorker::markMessageRead", "Marking message %1 as %2".arg(message.msgId).arg((message.read ? "read":"unread"))) |
| 178 |
Client.markMessageRead(message.msgId, message.read) |
| 179 |
} |
| 180 |
} |
| 181 |
Filter { |
| 182 |
type: MessageKeys.markMessageImportant |
| 183 |
onDispatched: Client.markMessageImportant(message.msgId, message.important) |
| 184 |
} |
| 185 |
|
| 186 |
Filter { |
| 187 |
type: MessageKeys.markMessageAsTodo |
| 188 |
onDispatched: Client.markMessageTodo(message.msgId, message.todo) |
| 189 |
} |
| 190 |
|
| 191 |
Filter { |
| 192 |
type: MessageKeys.markMessageAsDone |
| 193 |
onDispatched: Client.markMessageDone(message.msgId, message.done) |
| 194 |
} |
| 195 |
|
| 196 |
Filter { |
| 197 |
type: MessageKeys.restoreMessage |
| 198 |
onDispatched: Client.restoreMessage(message.msgId) |
| 199 |
} |
| 200 |
|
| 201 |
Filter { |
| 202 |
type: MessageKeys.sendPendingMessages |
| 203 |
onDispatched: { |
| 204 |
Log.logStatus("MailWorker::sendPendingMessages", "Enqueuing any pending messages") |
| 205 |
Client.sendPendingMessages() |
| 206 |
} |
| 207 |
} |
| 208 |
} |