Compose con Queue=0 scrive il messaggio senza metterlo in coda; la cartella e' Drafts (nuovo tipo 'draft' in folders()). Riprendendo una bozza il motore la sostituisce per id (Draft), non ne crea una seconda; dopo l'invio va nel cestino. Foglio di composizione estratto in foglioMessaggio(), usato da invio e bozza.
353 lines
13 KiB
QML
353 lines
13 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
|
|
|
|
// 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();
|
|
}
|
|
|
|
// 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 = "";
|
|
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()
|
|
}
|
|
}
|