- qml/js/linkify.js: escape di tutto il testo, poi URL e indirizzi diventano link; la punteggiatura finale resta fuori; una sola passata (niente link annidati). ES5, provato con node: tests/test_linkify.js, 9 controlli - MessagePage: RichText e onLinkActivated -> Qt.openUrlExternally
275 lines
9.4 KiB
QML
275 lines
9.4 KiB
QML
import QtQuick 2.0
|
|
import Sailfish.Silica 1.0
|
|
import "../js/linkify.js" as Linkify
|
|
|
|
// 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 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.allegati = engine.attachments(page.cartella, page.riga);
|
|
page.totale = engine.messages(page.cartella).length;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
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
|
|
text: page.corpo.length > 0 ? Linkify.html(page.corpo)
|
|
: qsTr("(nessun testo)")
|
|
wrapMode: Text.Wrap
|
|
// il testo arriva da chiunque: linkify escapa tutto e inserisce
|
|
// solo i propri tag (vedi qml/js/linkify.js, provato con node)
|
|
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: pageStack.push(Qt.resolvedUrl("ComposePage.qml"),
|
|
{ destinatario: page.indirizzo,
|
|
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("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 = ""
|
|
}
|
|
}
|