19import QtQuick.Window 2.1
21import Lomiri.Components.Popups 1.3
22import Lomiri.Content 1.1
23import Dekko.Mail.API 1.0
24import Dekko.Mail.Stores.Views 1.0
25import Dekko.Mail.Stores.Composer 1.0
27import Dekko.Lomiri.Dialogs 1.0
43 waitFor: [ViewStore.listenerId, ComposerStore.listenerId]
44 property string pickerUrl: ""
49 Log.logStatus("[ContentHub::importRequested]
", "import requested, running import...")
50 ContentActions.importFromContentHub(transfer)
53 Log.logStatus("[ContentHub::shareRequested]
", "share requested. importing share
")
54 ContentActions.importFromContentHub(transfer)
57 Log.logStatus("ContentHub::exportRequested
", "NotImplementedYet
")
62 runWhen: ContentKeys.pickFile
64 // First open the file picker for the platform
65 // This will either be the ContentHub picker
66 // or Qt's own FileDialog for non unity8 platforms
67 ContentActions.openFilePicker(message.root)
68 // Listen on selected files and add them to the composer
69 once(ContentKeys.filesSelected, function(message) {
70 console.debug("FILES:
", message.files)
71 const files = message.files
72 for (let i in message.files) {
73 console.debug("File:
", message.files[i])
74 const file = message.files[i]
75 ComposerActions.addFileAttachment(file.toString().replace("file:
79 once(ContentKeys.pickerClosed, exit.bind(
this, 0))
89 id: contactPickerComponent
94 id: emailSelectionComponent
99 runWhen: ContentKeys.pickContacts
101 const rootItem = message.root;
102 const recipientType = message.type;
103 console.debug(
"[ContentWorker] pickContacts triggered, recipientType:", recipientType)
105 ContentActions.openContactPicker(rootItem)
107 once(ContentKeys.contactsSelected, function(message) {
108 const files = message.files;
109 console.debug(
"[ContentWorker] contactsSelected, files:", JSON.stringify(files))
111 const reader = Qt.createQmlObject(
'import Dekko.Components 1.0; FileReaderHelper {}', rootItem,
"Reader");
112 for (let i = 0; i < files.length; i++) {
113 const vcardData = reader.readFromFile(files[i]);
115 console.debug(
"[ContentWorker] Could not read vCard file:", files[i])
119 const emailRegex = /^EMAIL(?:;[^:]*)?:(.*)$/gm;
122 while ((match = emailRegex.exec(vcardData)) !== null) {
123 const email = match[1].trim();
124 if (emails.indexOf(email) === -1) {
128 console.debug(
"[ContentWorker] Found emails:", JSON.stringify(emails))
129 if (emails.length === 1) {
130 ComposerActions.addRecipientFromAddress(recipientType, emails[0]);
131 }
else if (emails.length > 1) {
132 const dialog = PopupUtils.open(emailSelectionComponent, rootItem, {
"emailList": emails,
"recipientType": recipientType})
133 dialog.emailSelected.connect(function(email, type) {
134 if (email) ComposerActions.addRecipientFromAddress(type, email)
141 once(ContentKeys.contactPickerClosed, exit.bind(
this, 0))
146 type: ContentKeys.openContactPicker
148 console.debug(
"[ContentWorker] openContactPicker dispatched")
149 const chPicker = PopupUtils.open(contactPickerComponent, message.root)
150 chPicker.contactsImported.connect(function(files) {
151 console.debug(
"[ContentWorker] contactsImported, files:", JSON.stringify(files))
152 ContentActions.contactsSelected(files)
163 type: ContentKeys.openFilePicker
166 const chPicker = PopupUtils.open(chp, message.root, {isExport: false})
167 chPicker.filesImported.connect(function(files){
168 const imports =
new Array()
169 for (let i in files) {
170 Log.logInfo(
"ContentManager::filesPicked",
"File selected: %1".arg(files[i].url))
171 imports.push(files[i].url)
173 ContentActions.filesSelected(imports)
176 const c = Qt.createComponent(
"")
177 const filePicker = c.createObject(message.root)
178 filePicker.accepted.connect(function(){
179 const files =
new Array()
180 for (let i in filePicker.fileUrls) {
181 Log.logInfo(
"ContentManager::filesPicked",
"File selected: %1".arg(filePicker.fileUrls[i]))
182 files.push(filePicker.fileUrls[i])
184 ContentActions.filesSelected(files)
188 filePicker.rejected.connect(function() {
189 Log.logInfo(
"ContentManager::filePickerRejected",
"No attachments selected")
190 ContentActions.pickerClosed()
197 type: ContentKeys.importFromContentHub
199 if (message.transfer.length === 0) {
200 Log.logWarning(
"ContentManager::importFromContentHub",
"Not items to transfer :-/")
203 Log.logInfo(
"ContentManager::importFromContentHub",
"Number of transferred items: " + message.transfer.items.length)
205 ViewActions.delayCallWithArgs(ViewKeys.openComposer, {})
206 for (let item in message.transfer.items) {
207 const url = message.transfer.items[item].url
208 Log.logInfo(
"ContentManager::importFromContentHub",
"Item url: " + url)
209 const text = message.transfer.items[item].text
210 Log.logInfo(
"ContentManager::importFromContentHub",
"Item text: " + text)
211 switch (message.transfer.contentType) {
212 case ContentType.Links:
213 Log.logInfo(
"ContentManager::importFromContentHub",
"ContentType is Link: " + url.toString())
214 ViewActions.delayCallWithArgs(ComposerKeys.appendTextToSubject, {text: text})
215 ViewActions.delayCallWithArgs(ComposerKeys.appendTextToBody, {text: url.toString()})
217 case ContentType.Text:
218 Log.logInfo(
"ContentManager::importFromContentHub",
"ContentType is Text: " + text)
219 ViewActions.delayCallWithArgs(ComposerKeys.appendTextToBody, {text: text})
222 const other = url.toString().replace(
"file://",
"")
223 Log.logInfo(
"ContentManager::importFromContentHub",
"ContentType is Other, most likely a file: " + other)
224 ComposerActions.addFileAttachment(other)
232 type: ContentKeys.exportFile
234 PopupUtils.open(chp, message.root, {fileUrl: message.file})