Selezione: modo che si accende dal menu, tap per scegliere, sposta in una cartella qualsiasi, cestina, letti/non letti. spostaMolti legge tutti gli id prima di muovere: dopo il primo spostamento le righe non sono piu' quelle. Firma in Account, aggiunta solo ai messaggi nuovi.
395 lines
15 KiB
QML
395 lines
15 KiB
QML
import QtQuick 2.0
|
|
import Sailfish.Silica 1.0
|
|
import Sailfish.Pickers 1.0
|
|
import "../js/indirizzi.js" as Indirizzi
|
|
|
|
// Composizione e invio. Il motore mette il messaggio nella coda (Out), lo
|
|
// manda con SMTP e lascia la copia in Sent; qui si segue l'esito.
|
|
Page {
|
|
id: page
|
|
|
|
property string destinatario: ""
|
|
property string copia: ""
|
|
property string bcc: ""
|
|
property string oggetto: ""
|
|
property string corpo: ""
|
|
property string mittente: ""
|
|
|
|
property bool inviando: false
|
|
property string errore: ""
|
|
property var suggerimenti: []
|
|
// Percorsi dei file da allegare: li legge il motore dal disco.
|
|
property var allegati: []
|
|
// Bozza che si sta riprendendo: cartella e riga; -1 = messaggio nuovo.
|
|
property int bozzaCartella: -1
|
|
property int bozzaRiga: -1
|
|
property int bozzaId: -1
|
|
// Messaggio d'origine: inoltro come allegato, redirect, invia di nuovo.
|
|
property int origineCartella: -1
|
|
property int origineRiga: -1
|
|
property bool comeAllegato: false
|
|
property bool redirectMode: false
|
|
property bool comeNuovo: false
|
|
|
|
// Il "Da" si vede e si può correggere qui: se il campo in Account non è
|
|
// stato salvato, l'invio non resta bloccato senza spiegazione.
|
|
Component.onCompleted: {
|
|
if (account.mittente.length > 0)
|
|
page.mittente = account.mittente;
|
|
else if (account.persona.indexOf("@") > 0)
|
|
page.mittente = account.persona;
|
|
if (page.bozzaRiga >= 0) page.riprendi();
|
|
else if (account.firma.length > 0 && page.corpo.length === 0)
|
|
// La firma entra solo nei messaggi nuovi: in una risposta o in una
|
|
// bozza ripresa il testo è già stato scritto.
|
|
page.corpo = "\n\n-- \n" + account.firma;
|
|
if (page.comeAllegato && page.origineRiga >= 0) page.preparaInoltro();
|
|
if (page.comeNuovo && page.origineRiga >= 0) page.preparaNuovo();
|
|
}
|
|
|
|
// Inoltro come allegato: non è un forward del motore (che non lo prevede),
|
|
// è il file originale allegato al messaggio nuovo.
|
|
function preparaInoltro() {
|
|
page.oggetto = "Fwd: " + engine.headerOf(page.origineCartella,
|
|
page.origineRiga,
|
|
"Subject");
|
|
var percorso = engine.percorsoMessaggio(page.origineCartella,
|
|
page.origineRiga);
|
|
if (percorso.length > 0) page.allegati = [percorso];
|
|
}
|
|
|
|
// Invia di nuovo: gli stessi destinatari e lo stesso testo, come nuovo.
|
|
function preparaNuovo() {
|
|
page.destinatario = engine.headerOf(page.origineCartella, page.origineRiga, "To");
|
|
page.copia = engine.headerOf(page.origineCartella, page.origineRiga, "Cc");
|
|
page.oggetto = engine.headerOf(page.origineCartella, page.origineRiga, "Subject");
|
|
page.corpo = engine.body(page.origineCartella, page.origineRiga);
|
|
}
|
|
|
|
// Riprendere una bozza: i campi tornano come erano, allegati compresi.
|
|
function riprendi() {
|
|
var b = engine.bozza(page.bozzaCartella, page.bozzaRiga);
|
|
page.destinatario = b.a;
|
|
page.copia = b.cc;
|
|
page.bcc = b.bcc;
|
|
page.oggetto = b.oggetto;
|
|
page.corpo = b.corpo;
|
|
page.allegati = b.allegati ? b.allegati : [];
|
|
if (b.da.length > 0) page.mittente = b.da;
|
|
// L'id serve al motore per sostituire questa bozza invece di
|
|
// crearne una seconda.
|
|
page.bozzaId = engine.idOf(page.bozzaCartella, page.bozzaRiga);
|
|
}
|
|
|
|
function salvaBozza() {
|
|
page.errore = engine.salvaBozza(campoA.text, campoCc.text,
|
|
campoBcc.text, campoDa.text,
|
|
campoOggetto.text, campoCorpo.text,
|
|
page.allegati, page.bozzaId);
|
|
if (page.errore.length === 0)
|
|
pageStack.pop();
|
|
}
|
|
|
|
SilicaFlickable {
|
|
anchors.fill: parent
|
|
contentHeight: colonna.height + Theme.paddingLarge
|
|
|
|
PageHeader { title: qsTr("Nuovo messaggio") }
|
|
|
|
Column {
|
|
id: colonna
|
|
anchors.top: parent.top
|
|
anchors.topMargin: Theme.itemSizeLarge
|
|
width: parent.width
|
|
spacing: Theme.paddingMedium
|
|
|
|
TextField {
|
|
id: campoDa
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
label: qsTr("Da")
|
|
placeholderText: qsTr("il tuo indirizzo")
|
|
text: page.mittente
|
|
inputMethodHints: Qt.ImhEmailCharactersOnly | Qt.ImhNoAutoUppercase
|
|
EnterKey.enabled: true
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-next"
|
|
EnterKey.onClicked: campoA.forceActiveFocus()
|
|
}
|
|
|
|
TextField {
|
|
id: campoA
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
label: qsTr("A")
|
|
placeholderText: qsTr("indirizzo, anche piu' di uno")
|
|
text: page.destinatario
|
|
inputMethodHints: Qt.ImhEmailCharactersOnly | Qt.ImhNoAutoUppercase
|
|
EnterKey.enabled: true
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-next"
|
|
EnterKey.onClicked: campoCc.forceActiveFocus()
|
|
onTextChanged: suggerimentiTimer.restart()
|
|
}
|
|
|
|
Repeater {
|
|
model: page.suggerimenti
|
|
|
|
BackgroundItem {
|
|
width: colonna.width - 2 * Theme.horizontalPageMargin
|
|
anchors.horizontalCenter: colonna.horizontalCenter
|
|
height: Theme.itemSizeSmall
|
|
// Con un array di oggetti il modello si legge da modelData:
|
|
// model.nome sarebbe undefined e la riga non si disegna.
|
|
onClicked: page.completaCon(modelData.indirizzo)
|
|
|
|
Label {
|
|
x: Theme.paddingMedium
|
|
width: parent.width - 2 * Theme.paddingMedium
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: modelData.nome.length > 0
|
|
? modelData.nome + " — " + modelData.indirizzo
|
|
: modelData.indirizzo
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.secondaryColor
|
|
truncationMode: TruncationMode.Fade
|
|
}
|
|
}
|
|
}
|
|
|
|
TextField {
|
|
id: campoCc
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
label: qsTr("Cc")
|
|
placeholderText: qsTr("facoltativo")
|
|
text: page.copia
|
|
inputMethodHints: Qt.ImhEmailCharactersOnly | Qt.ImhNoAutoUppercase
|
|
EnterKey.enabled: true
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-next"
|
|
EnterKey.onClicked: campoBcc.forceActiveFocus()
|
|
}
|
|
|
|
TextField {
|
|
id: campoBcc
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
label: qsTr("Bcc")
|
|
placeholderText: qsTr("destinatari nascosti, facoltativo")
|
|
text: page.bcc
|
|
inputMethodHints: Qt.ImhEmailCharactersOnly | Qt.ImhNoAutoUppercase
|
|
EnterKey.enabled: true
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-next"
|
|
EnterKey.onClicked: campoOggetto.forceActiveFocus()
|
|
}
|
|
|
|
TextField {
|
|
id: campoOggetto
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
label: qsTr("Oggetto")
|
|
text: page.oggetto
|
|
EnterKey.enabled: true
|
|
EnterKey.iconSource: "image://theme/icon-m-enter-next"
|
|
EnterKey.onClicked: campoCorpo.forceActiveFocus()
|
|
}
|
|
|
|
TextArea {
|
|
id: campoCorpo
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
label: qsTr("Testo")
|
|
text: page.corpo
|
|
// Il campo cresce con il testo: nessuno scroll annidato.
|
|
height: Math.max(Theme.itemSizeLarge * 4,
|
|
implicitHeight + Theme.paddingLarge)
|
|
}
|
|
|
|
Button {
|
|
id: pulsanteAllega
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: qsTr("Allega un file")
|
|
preferredWidth: Theme.buttonWidthSmall
|
|
enabled: !page.inviando
|
|
onClicked: pageStack.push(sceltaFile)
|
|
}
|
|
|
|
// Gli allegati scelti: nome del file, e un tocco per toglierlo.
|
|
Repeater {
|
|
model: page.allegati
|
|
|
|
BackgroundItem {
|
|
width: colonna.width - 2 * Theme.horizontalPageMargin
|
|
anchors.horizontalCenter: colonna.horizontalCenter
|
|
height: Theme.itemSizeSmall
|
|
onClicked: page.togliAllegato(modelData)
|
|
|
|
Label {
|
|
x: Theme.paddingMedium
|
|
width: parent.width - 2 * Theme.paddingMedium
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: page.nomeFile(modelData)
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.secondaryColor
|
|
truncationMode: TruncationMode.Elide
|
|
}
|
|
}
|
|
}
|
|
|
|
Button {
|
|
id: pulsanteBozza
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: qsTr("Salva bozza")
|
|
preferredWidth: Theme.buttonWidthSmall
|
|
enabled: !page.inviando
|
|
onClicked: page.salvaBozza()
|
|
}
|
|
|
|
Button {
|
|
id: pulsanteInvia
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: page.inviando ? qsTr("Invio in corso…") : qsTr("Invia")
|
|
preferredWidth: Theme.buttonWidthSmall
|
|
enabled: !page.inviando
|
|
onClicked: page.invia()
|
|
}
|
|
|
|
Label {
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
horizontalAlignment: Text.AlignHCenter
|
|
text: page.errore
|
|
visible: page.errore.length > 0
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
color: Theme.highlightColor
|
|
wrapMode: Text.Wrap
|
|
}
|
|
|
|
Button {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: qsTr("Apri Account")
|
|
preferredWidth: Theme.buttonWidthSmall
|
|
visible: page.errore.indexOf("Account") >= 0
|
|
|| page.errore.indexOf("SMTP") >= 0
|
|
|| page.errore.indexOf("mittente") >= 0
|
|
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
|
|
}
|
|
}
|
|
|
|
VerticalScrollDecorator { }
|
|
}
|
|
|
|
Connections {
|
|
target: engine
|
|
onSendFinished: {
|
|
page.inviando = false;
|
|
if (falliti === 0) {
|
|
avviso.text = inviati === 1 ? qsTr("Messaggio inviato")
|
|
: qsTr("%1 messaggi inviati").arg(inviati);
|
|
avvisoTimer.restart();
|
|
timerPop.restart();
|
|
} else {
|
|
page.errore = esito.length > 0 ? esito
|
|
: qsTr("Invio non riuscito");
|
|
}
|
|
}
|
|
}
|
|
|
|
Timer {
|
|
id: suggerimentiTimer
|
|
interval: 250
|
|
onTriggered: page.aggiornaSuggerimenti()
|
|
}
|
|
|
|
// Il suggerimento riguarda l'ultimo indirizzo del campo: chi ne scrive due
|
|
// non si vede cancellare il primo.
|
|
function aggiornaSuggerimenti() {
|
|
var pezzo = Indirizzi.ultimoPezzo(campoA.text);
|
|
if (pezzo.length < 2) { page.suggerimenti = []; return; }
|
|
page.suggerimenti = engine.suggerisci(pezzo, 6);
|
|
}
|
|
|
|
function completaCon(indirizzo) {
|
|
campoA.text = Indirizzi.completa(campoA.text, indirizzo);
|
|
page.suggerimenti = [];
|
|
campoCc.forceActiveFocus();
|
|
}
|
|
|
|
// Il picker restituisce un URL: il motore vuole un percorso.
|
|
function aggiungiAllegato(url) {
|
|
var s = String(url);
|
|
if (s.length === 0) return;
|
|
var p = s.indexOf("file://") === 0 ? decodeURIComponent(s.substring(7)) : s;
|
|
if (p.length === 0) return;
|
|
var elenco = page.allegati.slice();
|
|
if (elenco.indexOf(p) < 0) elenco.push(p);
|
|
page.allegati = elenco;
|
|
}
|
|
|
|
function togliAllegato(percorso) {
|
|
var elenco = [];
|
|
for (var i = 0; i < page.allegati.length; i++)
|
|
if (page.allegati[i] !== percorso) elenco.push(page.allegati[i]);
|
|
page.allegati = elenco;
|
|
}
|
|
|
|
function nomeFile(percorso) {
|
|
return percorso.substring(percorso.lastIndexOf("/") + 1);
|
|
}
|
|
|
|
// La pagina del picker, non un Dialog: i dialog figli di una Page hanno
|
|
// già fatto fallire il caricamento in questa app.
|
|
Component {
|
|
id: sceltaFile
|
|
FilePickerPage {
|
|
onSelectedContentChanged: page.aggiungiAllegato(selectedContent)
|
|
}
|
|
}
|
|
|
|
function invia() {
|
|
page.errore = "";
|
|
// Il redirect non passa dal foglio normale: ricompone l'originale.
|
|
if (page.redirectMode && page.origineRiga >= 0) {
|
|
var r = engine.redirect(page.origineCartella, page.origineRiga,
|
|
campoA.text, campoDa.text);
|
|
if (r.length > 0) {
|
|
page.errore = r;
|
|
return;
|
|
}
|
|
page.inviando = true;
|
|
return;
|
|
}
|
|
const motivo = engine.sendMessage(campoA.text, campoCc.text,
|
|
campoBcc.text,
|
|
campoDa.text,
|
|
campoOggetto.text, campoCorpo.text,
|
|
page.allegati);
|
|
if (motivo.length > 0) {
|
|
page.errore = motivo;
|
|
return;
|
|
}
|
|
// Se il messaggio partiva da una bozza, la bozza ha finito il suo
|
|
// lavoro: la si toglie di mezzo, altrimenti resta lì a confondere.
|
|
if (page.bozzaRiga >= 0)
|
|
engine.moveToTrash(page.bozzaCartella, page.bozzaRiga);
|
|
page.inviando = true;
|
|
}
|
|
|
|
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: 1500
|
|
onTriggered: avviso.text = ""
|
|
}
|
|
Timer {
|
|
id: timerPop
|
|
interval: 700
|
|
onTriggered: pageStack.pop()
|
|
}
|
|
}
|