Debian Codegraph @

Dekko/workers/SettingsWorker.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 1.0
22 import Dekko.Mail.API 1.0
23 import Dekko.Mail.Settings 1.0
24 import Dekko.Mail.Stores.Settings 1.0
25
26 AppListener {
27
28 waitFor: [SettingsStore.listenerId]
29
30 property url mailboxPickerUrl: ""
31
32 Filter {
33 type: SettingsKeys.updateMarkAsReadInterval
34 onDispatched: {
35 if (!PolicyManager.idValid(message.accountId)) {
36 Log.logInfo("SettingsWorker::updateMarkAsReadInterval", "Invalid account id. doing nothing")
37 return;
38 }
39 Log.logInfo("SettingsWorker::updateMarkAsReadInterval", "Updating interval to %1 for account: %2".arg(message.interval).arg(message.accountId))
40 PolicyManager.mailPolicy(message.accountId).markAsReadInterval = message.interval
41 }
42 }
43
44 Filter {
45 type: SettingsKeys.updateMarkAsReadMode
46 onDispatched: {
47 if (!PolicyManager.idValid(message.accountId)) {
48 Log.logInfo("SettingsWorker::updateMarkAsReadMode", "Invalid account id. doing nothing")
49 return;
50 }
51 Log.logInfo("SettingsWorker::updateMarkAsReadMode", "Updating mode to %1 for account: %2".arg(message.mode).arg(message.accountId))
52 PolicyManager.mailPolicy(message.accountId).markRead = message.mode
53 }
54 }
55
56 Filter {
57 type: SettingsKeys.openSettingsGroup
58 onDispatched: {
59 SettingsActions.saveCurrentGroup()
60 SettingsStore.currentGroup = message.group
61 if (SettingsStore.viewState.isSmallFF) {
62 ViewActions.pushToStageArea(ViewKeys.settingsStack1, SettingsStore.currentGroup, {})
63 } else {
64 ViewActions.replaceTopStageAreaItem(ViewKeys.settingsStack2, SettingsStore.currentGroup, {})
65 }
66 }
67 }
68
69 Filter {
70 type: SettingsKeys.setSelectedAccount
71 property Component accountComponent: Component {
72 Account {
73 accountId: SettingsStore.selectedAccountId
74 }
75 }
76 onDispatched: {
77 SettingsStore.selectedAccountId = message.account.id
78 SettingsStore.selectedAccount = accountComponent.createObject()
79 }
80 }
81
82 Filter {
83 type: SettingsKeys.switchSettingsGroupLocation
84 onDispatched: {
85 SettingsActions.saveCurrentGroup()
86 ViewActions.popStageArea(message.stackKey)
87 delaySwitch.start()
88 }
89 property Timer delaySwitch: Timer {
90 interval: 50
91 repeat: false
92 onTriggered: {
93 console.log("CurrentGroup", SettingsStore.currentGroup)
94 SettingsActions.openSettingsGroup(SettingsStore.currentGroup)
95 }
96 }
97 }
98
99 Filter {
100 type: SettingsKeys.saveSelectedAccount
101 onDispatched: {
102 SettingsStore.selectedAccount.save()
103 ViewActions.orderSimpleToast(ViewKeys.toastSettingsWindow, qsTr("Account saved"))
104 }
105 }
106
107 Filter {
108 type: SettingsKeys.detectStandardFolders
109 onDispatched: {
110 SettingsActions.saveCurrentGroup()
111 SettingsActions.saveSelectedAccount()
112 if (Client.detectStandardFolders(SettingsStore.selectedAccount.id)) {
113 console.log("Standard Folders detected")
114 } else {
115 console.log("Standard folders no detected")
116 }
117 }
118 }
119
120 Filter {
121 type: SettingsKeys.createStandardFolders
122 onDispatched: {
123 Client.createStandardFolders(message.accountId)
124 }
125 }
126
127 AppScript {
128 property string pickerId: "settings-mbox-picker"
129 property string fieldId: ""
130 runWhen: SettingsKeys.pickFolder
131 script: {
132 console.log("SettingsWorker::moveMessage", "Opening folder picker.")
133 fieldId = message.fieldId
134 ViewActions.pushToStageArea(ViewKeys.settingsStack1,
135 mailboxPickerUrl,
136 {
137 pickerId: pickerId,
138 accountId: message.accountId
139 })
140 once(SettingsKeys.folderPicked, function (result) {
141 console.log("SettingsWorker::moveMessage", "Folder selected")
142 if (result.pickerId !== pickerId) {
143 return;
144 }
145 SettingsActions.folderPathPicked(fieldId, result.folder.path)
146 ViewActions.popStageArea(ViewKeys.settingsStack1)
147 })
148
149 once(SettingsKeys.pickFolderCancelled, function (msg) {
150 ViewActions.popStageArea(ViewKeys.settingsStack1)
151 exit.bind(this, 0)
152 })
153 }
154
155 }
156 }