| 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 |
pragma Singleton |
| 19 |
import QtQuick 2.4 |
| 20 |
import QuickFlux 1.0 |
| 21 |
import Dekko.Mail 1.0 |
| 22 |
import Dekko.Mail.API 1.0 |
| 23 |
import Dekko.Mail.Stores.Accounts 1.0 |
| 24 |
import Dekko.Mail.Stores.Mail 1.0 |
| 25 |
import Dekko.Mail.Stores.Composer 1.0 |
| 26 |
import Dekko.Utils 1.0 as QtCoreAPI |
| 27 |
import PlugMan 1.0 |
| 28 |
|
| 29 |
/*! |
| 30 |
* |
| 31 |
* ViewStore API |
| 32 |
* |
| 33 |
* ViewStore maintains the state of the views for the whole application. |
| 34 |
* |
| 35 |
* @ingroup qml_stores |
| 36 |
*/ |
| 37 |
AppListener { |
| 38 |
id: viewStore |
| 39 |
|
| 40 |
property string formFactor |
| 41 |
readonly property string selectedNavFolder: d.currentNavFolder |
| 42 |
property int selectedNavIndex: 0 |
| 43 |
|
| 44 |
waitFor: [ |
| 45 |
ComposerStore.listenerId, |
| 46 |
MailStore.listenerId, |
| 47 |
AccountStore.listenerId |
| 48 |
] |
| 49 |
|
| 50 |
ItemRegistry { |
| 51 |
id: registry |
| 52 |
} |
| 53 |
|
| 54 |
Filter { |
| 55 |
type: ViewKeys.stageStackReady |
| 56 |
onDispatched: { |
| 57 |
Log.logStatus("ViewStore::stageStackReady", "Stack is ready") |
| 58 |
ViewActions.pushStage(registry.findFirstEnabled("Dekko::Stage::Mail"), {}) |
| 59 |
if (!Client.hasConfiguredAccounts) { |
| 60 |
console.log("Opening setup wizard as none configured") |
| 61 |
ViewActions.delayCall(ViewKeys.runSetupWizard) |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
Connections { |
| 67 |
target: Client |
| 68 |
onMessagesSent: { |
| 69 |
if (ids.length > 1) { |
| 70 |
ViewActions.orderSimpleToast(ViewKeys.toastMainWindow, qsTr("Messages sent")) |
| 71 |
} else { |
| 72 |
ViewActions.orderSimpleToast(ViewKeys.toastMainWindow, qsTr("Message sent")) |
| 73 |
} |
| 74 |
} |
| 75 |
onMessageSendingFailed: ViewActions.orderSimpleToast(ViewKeys.toastMainWindow, qsTr("Message sending failed")) |
| 76 |
} |
| 77 |
|
| 78 |
Filter { |
| 79 |
type: ViewKeys.setCurrentNavFolder |
| 80 |
onDispatched: { |
| 81 |
d.currentNavFolder = message.folderName |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
Filter { |
| 86 |
id: switchFilter |
| 87 |
type: ViewKeys.switchMessageViewLocation |
| 88 |
onDispatched: { |
| 89 |
ViewActions.popStageArea(message.currentStageArea) |
| 90 |
msgId = message.msgId |
| 91 |
delaySwitch.start() |
| 92 |
} |
| 93 |
property int msgId |
| 94 |
property Timer delaySwitch: Timer { |
| 95 |
interval: 50 |
| 96 |
repeat: false |
| 97 |
onTriggered: { |
| 98 |
MessageActions.setCurrentMessage(-1) |
| 99 |
MessageActions.openMessage(switchFilter.msgId) |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
Filter { |
| 105 |
type: ViewKeys.navigateToAccount |
| 106 |
onDispatched: { |
| 107 |
var id = parseInt(message.accountId) |
| 108 |
if (AccountStore.recieveAccounts.hasAccount(id)) { |
| 109 |
var account = AccountStore.recieveAccounts.get(id) |
| 110 |
MessageActions.openAccountFolder(account.name, account.id) |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
Filter { |
| 116 |
type: ViewKeys.navigateToFolder |
| 117 |
onDispatched: { |
| 118 |
Log.logWarning("ViewStore::navigateToFolder", "Not implemented yet") |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
Filter { |
| 123 |
type: ViewKeys.navigateToMessage |
| 124 |
onDispatched: { |
| 125 |
Log.logWarning("ViewStore::navigateToFolder", "Not implemented yet") |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
Filter { |
| 130 |
type: ViewKeys.delayCall |
| 131 |
onDispatched: { |
| 132 |
if (message.funcKey.isEmpty()) { |
| 133 |
return; |
| 134 |
} |
| 135 |
Log.logInfo("ViewStore::delayCall", "Queuing call for key %1".arg(message.funcKey)) |
| 136 |
d.pendingCalls.push(message.funcKey) |
| 137 |
if (!delayCallTimer.running) { |
| 138 |
delayCallTimer.start() |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
Timer { |
| 144 |
id: delayCallTimer |
| 145 |
interval: 350 |
| 146 |
repeat: false |
| 147 |
onTriggered: { |
| 148 |
AppDispatcher.dispatch(d.pendingCalls.takeAt(0), {}) |
| 149 |
if (!d.pendingCalls.isEmpty()) { |
| 150 |
Log.logInfo("ViewStore::delayCallTimer", "Moving to next pending call") |
| 151 |
interval = 50 // we don't want to wait half a second for every call, just the first one. |
| 152 |
delayCallTimer.start() |
| 153 |
} else { |
| 154 |
Log.logInfo("ViewStore::delayCallTimer", "No more pending calls") |
| 155 |
interval = 350 |
| 156 |
delayCallTimer.stop() |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
Filter { |
| 162 |
type: ViewKeys.delayCallWithArgs |
| 163 |
onDispatched: { |
| 164 |
if (message.funcKey.isEmpty()) { |
| 165 |
return; |
| 166 |
} |
| 167 |
Log.logInfo("ViewStore::delayCallWithArgs", "Queuing call for key %1".arg(message.funcKey)) |
| 168 |
d.pendingCalls2.push(message.funcKey) |
| 169 |
d.pendingArgs.push(message.args) |
| 170 |
if (!delayCallTimer2.running) { |
| 171 |
delayCallTimer2.start() |
| 172 |
} |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
Timer { |
| 177 |
id: delayCallTimer2 |
| 178 |
interval: 400 |
| 179 |
repeat: false |
| 180 |
onTriggered: { |
| 181 |
AppDispatcher.dispatch(d.pendingCalls2.takeAt(0), d.pendingArgs.takeAt(0)) |
| 182 |
if (!d.pendingCalls2.isEmpty()) { |
| 183 |
Log.logInfo("ViewStore::delayCallTimer2", "Moving to next pending call") |
| 184 |
interval = 50 // we don't want to wait half a second for every call, just the first one. |
| 185 |
delayCallTimer2.start() |
| 186 |
} else { |
| 187 |
Log.logInfo("ViewStore::delayCallTimer2", "No more pending calls") |
| 188 |
interval = 300 |
| 189 |
delayCallTimer2.stop() |
| 190 |
} |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
QtObject { |
| 195 |
id: d |
| 196 |
property string currentNavFolder: "" |
| 197 |
property var pendingCalls: [] |
| 198 |
property var pendingCalls2: [] |
| 199 |
property var pendingArgs: [] |
| 200 |
} |
| 201 |
} |
| 202 |
|