Debian Codegraph @

Dekko/workers/UriWorker.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.API 1.0
21 import Dekko.Mail.Stores.Composer 1.0
22 import Dekko.Utils 1.0 as JSUtils
23
24 AppListener {
25
26 waitFor: [ComposerStore.listenerId]
27
28 Filter {
29 type: ViewKeys.openUris
30 onDispatched: {
31 d.processUris(message.uris)
32 }
33 }
34
35 // We make these private as we want to enforce the use
36 // of the dispatcher api.
37 // If you need to open a uri from anywhere in the app
38 // then you just need to dispatch ViewActions.openUris
39 QtObject {
40 id: d
41
42 function processUris(uris) {
43 if (!uris.isEmpty()) {
44 uris.foreach(function (idx, uri) {
45 processUri(uri);
46 })
47 }
48 }
49
50 function processUri(uri) {
51 Log.logInfo("UriListener::processUri", "Processing URI: " + uri)
52 if (typeof uri === "undefined") {
53 Log.logInfo("UriListener::processUri", "false alarm.. its a bum uri")
54 return
55 }
56 if (uri.startsWith("mailto:")) {
57 Log.logInfo("UriListener::processUri", "Recieved mailto: uri. Opening composer")
58 ComposerActions.composeMailtoUri(uri)
59 return
60 }
61
62 if (uri.startsWith("dekko:")) {
63 var commands = uri.split("://")[1].split("/")
64 if (commands.isEmpty()) {
65 Log.logInfo("UriListener::processUri", "Dekko command is empty, nothing we can do")
66 return
67 }
68 switch (commands.at(0).toLowerCase()) {
69 case "notify":
70 Log.logInfo("UriListener::processUri", "Were opening a notification")
71 if (commands.size() < 2) {
72 Log.logInfo("UriListener::processUri", "Not enough args to show a notification")
73 return
74 } else if (commands.size() === 2) {
75 Log.logInfo("UriListener::processUri", "Navigating to account")
76 // Call later: This is equivalent to ViewActions.navigateToAccount(commands.at(1))
77 ViewActions.delayCallWithArgs(ViewKeys.navigateToAccount, {accountId: commands.at(1)})
78 } else if (commands.size() === 3) {
79 Log.logInfo("UriListener::processUri", "Navigating to folder")
80 // Call later: ViewActions.navigateToFolder(commands.at(1), commands.at(2))
81 ViewActions.delayCallWithArgs(ViewKeys.navigateToFolder,
82 {
83 accountId: commands.at(1),
84 folderId: commands.at(2)
85 })
86 } else if (commands.size() === 4) {
87 Log.logInfo("UriListener::processUri", "Navigating to message")
88 // Call later: ViewActions.navigateToMessage(commands.at(1), commands.at(2), commands.at(3))
89 ViewActions.delayCallWithArgs(ViewKeys.navigateToMessage,
90 {
91 accountId: commands.at(1),
92 folderId: commands.at(2),
93 messageId: commands.at(3)
94 })
95 }
96 break
97 case "contacts":
98 Log.logInfo("UriListener::processUri", "We're opening contacts")
99 switch (commands.at(1)) {
100 case "new":
101 Log.logInfo("UriListener::processUri", "Create new contact")
102 break
103 case "edit":
104 Log.logInfo("UriListener::processUri", "Edit existing contact")
105 break
106 case "remove":
107 Log.logInfo("UriListener::processUri", "Remove contact")
108 break
109 case "open":
110 Log.logInfo("UriListener::processUri", "Opening addressbook")
111 // We have most likely got this off the commandline args or from url dispatcher
112 // now we need to wait for the stage stacks to be done first so just
113 // schedule a dispatch in a little while.
114 ViewActions.delayCall(ViewKeys.openAddressBook)
115 break
116 }
117 break
118 case "settings":
119 Log.logInfo("UriListener::processUri", "We're opening settings")
120 break
121 }
122 return
123 }
124 if (uri.startsWith("http://") || uri.startsWith("https://")) {
125 Log.logInfo("UriListener::processUri", "Recieved external uri. Prompting user to allow opening externally")
126 return
127 }
128 }
129 }
130
131 Component.onCompleted: {
132 if (appUris) {
133 Log.logInfo("UriListener::onCompleted", "We got some uri's to handle: " + appUris)
134 d.processUris(appUris)
135 }
136 }
137 }