OK, I did it. Here is a first try.
I put the code in the “MessageViewPullDown.qml”.
So this is for users who use the email view with pulldown menu (modified “HtmlViewer.qml”). As a noob, that was the simplest solution for me ;-).
The PDF files end up in Downloads.
There is definitely room for improvement.
For example, a reminder popup when saving or a status message after the download is complete would be nice.
It’s a pity, you can’t attach PDF files as an example here
/*
* Copyright (c) 2013 – 2019 Jolla Ltd.
*
* License: Proprietary
*/
import QtQuick 2.0
import Sailfish.Silica 1.0
import Sailfish.WebView.Controls 1.0
import Sailfish.WebEngine 1.0
import Nemo.Notifications 1.0
PullDownMenu {
id: root
signal removeRequested
signal savePageAsPDF
function _openComposer(action) {
pageStack.animatorPush(Qt.resolvedUrl("ComposerPage.qml"), { popDestination: previousPage, action: action, originalMessageId: message.messageId })
}
onSavePageAsPDF: {
var filename = ((message.subject && message.subject.length !== 0) ? message.subject : (message.Id || "unnamed_file")) + ".pdf"
var targetUrl = DownloadHelper.createUniqueFileUrl(filename, StandardPaths.download)
WebEngine.notifyObservers("embedui:download",
{
"msg": "saveAsPdf",
"to": targetUrl
})
var text = "Nachricht wird gespeichert: " + targetUrl
showSingleLineNotification(text)
}
function showSingleLineNotification(text) {
if (text.length > 0) {
var n = notificationComponent.createObject(null, { 'summary': text,
'appIcon': "image://theme/icon-m-file-download-as-pdf" })
n.publish()
}
}
MenuItem {
//% "Delete"
text: qsTrId("jolla-email-me-delete")
onClicked: {
pageStack.pop()
root.removeRequested()
}
}
MenuItem {
//: Forward message menu item
//% "Forward"
text: qsTrId("jolla-email-me-forward")
onClicked: _openComposer('forward')
}
MenuItem {
visible: replyAll
//: Reply to all message recipients menu item
//% "Reply to All"
text: qsTrId("jolla-email-me-reply_all")
onClicked: _openComposer('replyAll')
}
MenuItem {
//: Reply to message sender menu item
//% "Reply"
text: qsTrId("jolla-email-me-reply")
onClicked: _openComposer('reply')
}
MenuItem {
//: Save message as PDF
//% "Save as PDF
text: qsTrId("Nachricht als PDF speichern")
onClicked: savePageAsPDF()
}
}
Edit - 09.07.23
I’ve added info using “SingleLineNotification”.