- datastore: export/import JSON con le chiavi camelCase dell'app Android (breedSettings/reservations/customers), scorte e ultimo aggiornamento preservati al ripristino - settings: flag 'introduzione vista' - desktop: permesso Documents (dove finisce il backup) - nuovi controlli: tools/check_qml.py (chiavi di traduzione, simboli JS, pagine, componenti) e qmllint nella suite - versione 0.2.0
131 lines
3.9 KiB
QML
131 lines
3.9 KiB
QML
import QtQuick 2.2
|
|
import Sailfish.Silica 1.0
|
|
import "../js/i18n.js" as I18N
|
|
|
|
// Backup e ripristino, nello STESSO formato JSON dell'app Android
|
|
// ({breedSettings, reservations, customers}): i file esportati dalle due
|
|
// versioni si scambiano senza conversioni.
|
|
// Qui non esiste la condivisione di Android: l'esportazione scrive il file
|
|
// nella cartella Documenti (e lo si puo' copiare negli appunti), il
|
|
// ripristino si fa incollando il JSON.
|
|
Page {
|
|
id: page
|
|
allowedOrientations: Orientation.All
|
|
|
|
property string lang: "en"
|
|
property var onChanged: null
|
|
property string message: ""
|
|
property bool messageIsError: false
|
|
|
|
function tr(key, arg) { return I18N.t(key, arg, page.lang) }
|
|
|
|
function showMessage(text, isError) {
|
|
page.message = text
|
|
page.messageIsError = isError
|
|
hideTimer.restart()
|
|
}
|
|
|
|
function exportData() {
|
|
var path = appData.exportBackup()
|
|
if (path.length > 0)
|
|
page.showMessage(page.tr("export_data") + ": " + path, false)
|
|
else
|
|
page.showMessage(page.tr("import_error"), true)
|
|
}
|
|
|
|
function copyData() {
|
|
clipboard.text = appData.backupJson()
|
|
page.showMessage(page.tr("copied"), false)
|
|
}
|
|
|
|
function importData() {
|
|
if (!appData.isValidBackup(backupField.text)) {
|
|
page.showMessage(page.tr("import_error"), true)
|
|
return
|
|
}
|
|
if (appData.importBackup(backupField.text)) {
|
|
backupField.text = ""
|
|
page.showMessage(page.tr("import_success"), false)
|
|
if (page.onChanged)
|
|
page.onChanged()
|
|
} else {
|
|
page.showMessage(page.tr("import_error"), true)
|
|
}
|
|
}
|
|
|
|
Component.onCompleted: page.lang = I18N.langFor(appSettings.language, Qt.locale().name)
|
|
|
|
Timer {
|
|
id: hideTimer
|
|
interval: 6000
|
|
onTriggered: page.message = ""
|
|
}
|
|
|
|
Clipboard { id: clipboard }
|
|
|
|
SilicaFlickable {
|
|
anchors.fill: parent
|
|
contentHeight: content.height
|
|
|
|
Column {
|
|
id: content
|
|
width: parent.width
|
|
spacing: Theme.paddingMedium
|
|
|
|
PageHeader { title: page.tr("backup_restore") }
|
|
|
|
Button {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: page.tr("export_data")
|
|
onClicked: page.exportData()
|
|
}
|
|
|
|
Button {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: page.tr("copy_to_clipboard")
|
|
onClicked: page.copyData()
|
|
}
|
|
|
|
Label {
|
|
x: Theme.horizontalPageMargin
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
text: page.message
|
|
color: page.messageIsError ? Theme.errorColor : Theme.highlightColor
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
wrapMode: Text.Wrap
|
|
visible: text.length > 0
|
|
}
|
|
|
|
SectionHeader { text: page.tr("import_data") }
|
|
|
|
TextArea {
|
|
id: backupField
|
|
width: parent.width
|
|
height: Theme.itemSizeLarge * 3
|
|
placeholderText: page.tr("paste_json_here")
|
|
label: page.tr("paste_json_here")
|
|
}
|
|
|
|
Button {
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
text: page.tr("import_data")
|
|
enabled: appData.isValidBackup(backupField.text)
|
|
onClicked: page.importData()
|
|
}
|
|
|
|
Label {
|
|
x: Theme.horizontalPageMargin
|
|
width: parent.width - 2 * Theme.horizontalPageMargin
|
|
text: appData.dataFilePath()
|
|
color: Theme.secondaryColor
|
|
font.pixelSize: Theme.fontSizeExtraSmall
|
|
wrapMode: Text.Wrap
|
|
}
|
|
|
|
Item { width: parent.width; height: Theme.paddingLarge }
|
|
}
|
|
|
|
VerticalScrollDecorator {}
|
|
}
|
|
}
|