Change_Folder fa tre cose con lo stesso comando: rinomina con Length>0, sposta con Target>=0, elimina con Length 0 e Target -1. Forget ripulisce quello che il motore teneva della cartella. Redirect usa Kind=3 e l'origine: il motore ricompone l'originale con Resent-*. L'inoltro come allegato allega il file originale, perche' il motore non ha un forward-come-allegato.
445 lines
17 KiB
QML
445 lines
17 KiB
QML
import QtQuick 2.0
|
|
import Sailfish.Silica 1.0
|
|
import "../js/linkify.js" as Linkify
|
|
import "../js/reply.js" as Reply
|
|
import "../js/htmltext.js" as HtmlText
|
|
import "../js/htmlpulito.js" as HtmlPulito
|
|
|
|
// Lettura di un messaggio, dal motore. Paginazione a tap: un tocco sul lato
|
|
// destro passa al successivo, sul sinistro al precedente; il corpo resta
|
|
// scorrevole al centro, cosi' i due gesti non si rubano.
|
|
Page {
|
|
id: page
|
|
|
|
property int cartella: -1
|
|
property int riga: 0
|
|
property int totale: 0
|
|
|
|
property string mittente: ""
|
|
property string oggetto: ""
|
|
// non "data": e' una proprieta' finale di Item (la lista dei figli) e
|
|
// sovrascriverla fa rifiutare la pagina ("Impossibile caricare la pagina")
|
|
property string quando: ""
|
|
property string indirizzo: ""
|
|
property string corpo: ""
|
|
property string mostrato: ""
|
|
// La parte HTML del messaggio e se la si sta disegnando come tale.
|
|
property string html: ""
|
|
property bool mostraHtml: true
|
|
property var allegati: []
|
|
|
|
Component.onCompleted: leggi()
|
|
|
|
Connections {
|
|
target: engine
|
|
onReady: page.leggi()
|
|
}
|
|
|
|
// Colonne del motore: 4 mittente, 5 data, 7 oggetto.
|
|
function leggi() {
|
|
if (page.cartella < 0) return;
|
|
page.mittente = engine.cell(page.cartella, page.riga, 4);
|
|
page.quando = engine.cell(page.cartella, page.riga, 5);
|
|
page.oggetto = engine.cell(page.cartella, page.riga, 7);
|
|
page.corpo = engine.body(page.cartella, page.riga);
|
|
page.mostrato = page.testoMostrato();
|
|
// L'HTML vero, se c'e': si disegna quando ha una struttura (paragrafi,
|
|
// elenchi, tabelle); altrimenti si resta sul testo, che si legge meglio.
|
|
page.html = engine.corpoHtml(page.cartella, page.riga);
|
|
page.mostraHtml = HtmlPulito.valeHtml(page.html);
|
|
page.allegati = engine.attachments(page.cartella, page.riga);
|
|
// La colonna 4 e' solo il nome: per rispondere serve l'indirizzo vero.
|
|
page.indirizzo = engine.senderOf(page.cartella, page.riga);
|
|
page.totale = engine.messages(page.cartella).length;
|
|
|
|
// Aprire un messaggio lo segna letto (regola di Eudora), tranne nelle
|
|
// cartelle di uscita: quello che abbiamo scritto noi si legge sempre
|
|
// in tondo, non e' posta da leggere.
|
|
var tipo = engine.folderType(page.cartella);
|
|
if (tipo !== "out" && tipo !== "draft"
|
|
&& engine.isUnread(page.cartella, page.riga)) {
|
|
engine.markRead(page.cartella, page.riga, true);
|
|
}
|
|
}
|
|
|
|
function testoMostrato() {
|
|
var t = page.corpo;
|
|
if (t.length === 0) return "";
|
|
// Un messaggio solo HTML arriva come markup: prima si riduce a testo,
|
|
// poi si rendono toccabili gli indirizzi rimasti.
|
|
if (t.indexOf("<") >= 0 && t.indexOf(">") >= 0)
|
|
t = HtmlText.daHtml(t);
|
|
return Linkify.html(t);
|
|
}
|
|
|
|
function salvaAllegato(indice) {
|
|
var path = engine.saveAttachment(page.cartella, page.riga, indice);
|
|
if (path.length > 0) {
|
|
avviso.text = qsTr("Salvato in %1").arg(path);
|
|
avvisoTimer.restart();
|
|
Qt.openUrlExternally("file://" + path);
|
|
} else {
|
|
avviso.text = qsTr("Non e' stato possibile salvare l'allegato");
|
|
avvisoTimer.restart();
|
|
}
|
|
}
|
|
|
|
// Tutti gli allegati in un colpo: uno per uno, perché il motore li salva
|
|
// singolarmente e un file illeggibile non deve fermare gli altri.
|
|
function salvaTutti() {
|
|
var salvati = 0;
|
|
for (var i = 0; i < page.allegati.length; i++) {
|
|
if (engine.saveAttachment(page.cartella, page.riga,
|
|
page.allegati[i].indice).length > 0)
|
|
salvati++;
|
|
}
|
|
avviso.text = qsTr("%1 allegati salvati in Download").arg(salvati);
|
|
avvisoTimer.restart();
|
|
}
|
|
|
|
// Etichetta corrente: il motore ne ha otto (0 = nessuna) e senza nomi
|
|
// nell'interfaccia si cicla, invece di riempire il menu di otto voci.
|
|
property int etichetta: 0
|
|
|
|
function segnaJunk(junk) {
|
|
var motivo = engine.segnalaJunk(page.cartella, page.riga, junk);
|
|
if (motivo.length > 0) {
|
|
avviso.text = motivo;
|
|
avvisoTimer.restart();
|
|
return;
|
|
}
|
|
// Il messaggio è uscito da questa cartella: si torna all'elenco.
|
|
pageStack.pop();
|
|
}
|
|
|
|
function priorita(valore) {
|
|
engine.impostaPriorita(page.cartella, page.riga, valore);
|
|
avviso.text = valore === 1 ? qsTr("Priorità alta")
|
|
: valore === 5 ? qsTr("Priorità bassa")
|
|
: qsTr("Priorità normale");
|
|
avvisoTimer.restart();
|
|
}
|
|
|
|
function ciclaEtichetta() {
|
|
page.etichetta = (page.etichetta + 1) % 8;
|
|
engine.impostaEtichetta(page.cartella, page.riga, page.etichetta);
|
|
avviso.text = page.etichetta === 0 ? qsTr("Etichetta tolta")
|
|
: qsTr("Etichetta %1").arg(page.etichetta);
|
|
avvisoTimer.restart();
|
|
}
|
|
|
|
function dimensione(bytes) {
|
|
if (bytes < 1024) return bytes + " B";
|
|
if (bytes < 1048576) return Math.round(bytes / 1024) + " KB";
|
|
return (bytes / 1048576).toFixed(1) + " MB";
|
|
}
|
|
|
|
function vai(delta) {
|
|
var nuovo = page.riga + delta;
|
|
if (nuovo < 0 || nuovo >= page.totale) {
|
|
avviso.text = delta < 0 ? qsTr("Primo messaggio")
|
|
: qsTr("Ultimo messaggio");
|
|
avvisoTimer.restart();
|
|
return;
|
|
}
|
|
pageStack.replace(Qt.resolvedUrl("MessagePage.qml"), {
|
|
cartella: page.cartella,
|
|
riga: nuovo
|
|
});
|
|
}
|
|
|
|
SilicaFlickable {
|
|
anchors.fill: parent
|
|
contentHeight: contenuto.height + Theme.paddingLarge
|
|
|
|
PageHeader {
|
|
id: intestazione
|
|
title: page.oggetto
|
|
description: qsTr("%1 di %2").arg(page.riga + 1).arg(page.totale)
|
|
}
|
|
|
|
Column {
|
|
id: contenuto
|
|
anchors.top: intestazione.bottom
|
|
anchors.left: parent.left
|
|
anchors.right: parent.right
|
|
anchors.leftMargin: Theme.horizontalPageMargin
|
|
anchors.rightMargin: Theme.horizontalPageMargin
|
|
spacing: Theme.paddingSmall
|
|
|
|
Label {
|
|
width: parent.width
|
|
text: qsTr("Da: %1").arg(page.mittente)
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
color: Theme.highlightColor
|
|
truncationMode: TruncationMode.Fade
|
|
}
|
|
Label {
|
|
width: parent.width
|
|
visible: page.indirizzo.length > 0
|
|
text: page.indirizzo
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.secondaryColor
|
|
truncationMode: TruncationMode.Fade
|
|
}
|
|
Label {
|
|
width: parent.width
|
|
text: qsTr("A: me — %1").arg(page.quando)
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.secondaryColor
|
|
}
|
|
|
|
Item {
|
|
width: parent.width
|
|
height: Theme.paddingMedium
|
|
}
|
|
|
|
Label {
|
|
width: parent.width
|
|
// Due strade: l'HTML ripulito e disegnato da Qt (paragrafi,
|
|
// elenchi, tabelle, link) oppure il testo con i link
|
|
// riconosciuti. Il mittente non può iniettare niente: si
|
|
// passa sempre da htmlpulito.js, provato con node.
|
|
text: page.mostraHtml && page.html.length > 0
|
|
? HtmlPulito.pulisci(page.html)
|
|
: (page.mostrato.length > 0 ? page.mostrato
|
|
: qsTr("(nessun testo)"))
|
|
wrapMode: Text.Wrap
|
|
textFormat: Text.RichText
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
color: Theme.primaryColor
|
|
bottomPadding: Theme.paddingLarge
|
|
onLinkActivated: Qt.openUrlExternally(link)
|
|
}
|
|
|
|
// Allegati: un tocco li salva in Download e li apre con l'app
|
|
// associata. I nomi li sceglie il mittente, quindi il bridge
|
|
// scarta ogni percorso.
|
|
SectionHeader {
|
|
visible: page.allegati.length > 0
|
|
text: page.allegati.length === 1 ? qsTr("1 allegato")
|
|
: qsTr("%1 allegati").arg(page.allegati.length)
|
|
}
|
|
|
|
Repeater {
|
|
model: page.allegati
|
|
|
|
delegate: BackgroundItem {
|
|
width: contenuto.width
|
|
height: Theme.itemSizeSmall
|
|
onClicked: page.salvaAllegato(modelData.indice)
|
|
|
|
Row {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
spacing: Theme.paddingMedium
|
|
|
|
Image {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
width: Theme.iconSizeExtraSmall
|
|
height: width
|
|
source: "qrc:/images/icona-allegato.png"
|
|
smooth: false
|
|
}
|
|
Label {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: modelData.nome
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
color: Theme.primaryColor
|
|
truncationMode: TruncationMode.Fade
|
|
}
|
|
Label {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: page.dimensione(modelData.dimensione)
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.secondaryColor
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
PullDownMenu {
|
|
MenuItem {
|
|
text: qsTr("Rispondi")
|
|
onClicked: {
|
|
const a = Reply.rispondi(page.indirizzo);
|
|
if (a === "") {
|
|
avviso.text = qsTr("Indirizzo del mittente non disponibile");
|
|
return;
|
|
}
|
|
pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
|
{ destinatario: a,
|
|
oggetto: "Re: " + page.oggetto });
|
|
}
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Rispondi a tutti")
|
|
onClicked: pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
|
{ destinatario: Reply.rispondiATutti(
|
|
page.indirizzo,
|
|
engine.headerOf(page.cartella, page.riga, "to"),
|
|
engine.headerOf(page.cartella, page.riga, "cc"),
|
|
account.persona),
|
|
oggetto: "Re: " + page.oggetto })
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Inoltra")
|
|
onClicked: pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
|
{ oggetto: "Fwd: " + page.oggetto,
|
|
corpo: page.corpo })
|
|
}
|
|
}
|
|
|
|
PushUpMenu {
|
|
MenuItem {
|
|
text: qsTr("Segna come non letto")
|
|
onClicked: {
|
|
engine.markRead(page.cartella, page.riga, false);
|
|
avviso.text = qsTr("Segnato non letto");
|
|
avvisoTimer.restart();
|
|
}
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Riprendi la bozza")
|
|
visible: engine.folderType(page.cartella) === "draft"
|
|
onClicked: pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
|
{ "bozzaCartella": page.cartella,
|
|
"bozzaRiga": page.riga })
|
|
}
|
|
MenuItem {
|
|
text: page.mostraHtml ? qsTr("Vedi come testo")
|
|
: qsTr("Vedi come HTML")
|
|
visible: page.html.length > 0
|
|
onClicked: page.mostraHtml = !page.mostraHtml
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Salva tutti gli allegati")
|
|
visible: page.allegati.length > 1
|
|
onClicked: page.salvaTutti()
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Inoltro come allegato")
|
|
onClicked: pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
|
{ "origineCartella": page.cartella,
|
|
"origineRiga": page.riga,
|
|
"comeAllegato": true })
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Redirect")
|
|
onClicked: pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
|
{ "origineCartella": page.cartella,
|
|
"origineRiga": page.riga,
|
|
"redirectMode": true })
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Invia di nuovo")
|
|
visible: engine.folderType(page.cartella) === "out"
|
|
onClicked: pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
|
{ "origineCartella": page.cartella,
|
|
"origineRiga": page.riga,
|
|
"comeNuovo": true })
|
|
}
|
|
MenuItem {
|
|
text: qsTr("È junk")
|
|
onClicked: page.segnaJunk(true)
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Non è junk")
|
|
onClicked: page.segnaJunk(false)
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Priorità alta")
|
|
onClicked: page.priorita(1)
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Priorità normale")
|
|
onClicked: page.priorita(3)
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Priorità bassa")
|
|
onClicked: page.priorita(5)
|
|
}
|
|
MenuItem {
|
|
text: page.etichetta === 0 ? qsTr("Etichetta")
|
|
: qsTr("Etichetta %1").arg(page.etichetta)
|
|
onClicked: page.ciclaEtichetta()
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Sposta in…")
|
|
onClicked: pageStack.push(Qt.resolvedUrl("FolderPickerPage.qml"),
|
|
{ "da": page.cartella,
|
|
"riga": page.riga,
|
|
"oggetto": page.oggetto })
|
|
}
|
|
MenuItem {
|
|
text: qsTr("Sposta in Trash")
|
|
onClicked: {
|
|
if (engine.moveToTrash(page.cartella, page.riga)) {
|
|
pageStack.pop();
|
|
} else {
|
|
avviso.text = qsTr("Non e' stato possibile spostarlo");
|
|
avvisoTimer.restart();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
VerticalScrollDecorator { }
|
|
}
|
|
|
|
// Zone di tap: destra avanti, sinistra indietro.
|
|
Item {
|
|
anchors.left: parent.left
|
|
anchors.top: parent.top
|
|
anchors.bottom: parent.bottom
|
|
width: Theme.itemSizeMedium
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: page.vai(-1)
|
|
}
|
|
Label {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
anchors.left: parent.left
|
|
anchors.leftMargin: Theme.paddingSmall
|
|
text: "\u2039"
|
|
font.pixelSize: Theme.fontSizeHuge
|
|
color: Theme.rgba(Theme.primaryColor, 0.25)
|
|
}
|
|
}
|
|
|
|
Item {
|
|
anchors.right: parent.right
|
|
anchors.top: parent.top
|
|
anchors.bottom: parent.bottom
|
|
width: Theme.itemSizeMedium
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
onClicked: page.vai(1)
|
|
}
|
|
Label {
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
anchors.right: parent.right
|
|
anchors.rightMargin: Theme.paddingSmall
|
|
text: "\u203a"
|
|
font.pixelSize: Theme.fontSizeHuge
|
|
color: Theme.rgba(Theme.primaryColor, 0.25)
|
|
}
|
|
}
|
|
|
|
Label {
|
|
id: avviso
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
anchors.bottom: parent.bottom
|
|
anchors.bottomMargin: Theme.paddingLarge
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
color: Theme.highlightColor
|
|
}
|
|
Timer {
|
|
id: avvisoTimer
|
|
interval: 1400
|
|
onTriggered: avviso.text = ""
|
|
}
|
|
}
|