Files
harbour-aira/qml/pages/SettingsPage.qml
T
Carlo fddd21e16a 0.4.0: interfaccia in italiano e inglese, scelta nelle impostazioni
L'inglese è la lingua sorgente delle stringhe; l'italiano sta nel catalogo
translations/harbour-aira-it.ts (99 stringhe), che lupdate aggiorna e lrelease
compila in build. Di serie la lingua del sistema, con ripiego sull'inglese.

- nuova classe Translator: risolve la lingua prima di createView e allinea
  QLocale::setDefault, così anche i numeri seguono la lingua (23,0 °C in
  italiano, 23.0 °C in inglese) — le temperature passano da formatValue, non
  più dal toFixed() di JavaScript che metteva sempre il punto
- Qt 5.6 non ha QQmlEngine::retranslate(): al cambio di lingua la radice QML
  viene ricaricata (setSource ricrea il componente anche a url invariata)
- le etichette di stato in airajson.cpp usano QCoreApplication::translate per
  esteso: lupdate non riconosce una funzione wrapper e le avrebbe perse
- selettore della lingua in Impostazioni (Sistema / English / Italiano)
- test: 41/41, carica il .qm vero come fa main.cpp e verifica entrambe le
  lingue, il ripiego e i formati numerici
- anteprime bilingui (docs/anteprima/ inglese, it/ italiano), README e PIANO
  aggiornati, spec RPM con i cataloghi in %files
2026-10-10 08:19:20 +02:00

158 lines
5.5 KiB
QML

import QtQuick 2.2
import Sailfish.Silica 1.0
// Indirizzo e token del bridge. Si salvano all'uscita dalla pagina, alla
// pressione di Invio e col pulsante Salva: NON a ogni tasto (QSettings.sync()
// su ogni carattere consuma scritture senza motivo).
Page {
id: page
allowedOrientations: Orientation.All
property string urlText: appSettings.baseUrl
property string tokenText: appSettings.token
property string testResult: ""
property bool testOk: false
function save() {
appSettings.baseUrl = urlText.trim()
appSettings.token = tokenText.trim()
}
function testAndReport() {
save()
page.testResult = qsTr("checking…")
api.testConnection()
}
onStatusChanged: {
if (status === PageStatus.Inactive)
save()
}
Connections {
target: api
onConnectionTested: {
page.testOk = ok
page.testResult = message
}
}
SilicaFlickable {
anchors.fill: parent
contentHeight: col.height + Theme.paddingLarge
Column {
id: col
width: parent.width
spacing: Theme.paddingMedium
PageHeader { title: qsTr("Settings") }
// ---- lingua ---------------------------------------------------- //
SectionHeader { text: qsTr("Language") }
// Le voci si scelgono dal menu: il valore mostrato segue la scelta
// salvata (translator.language), non l'ultimo tocco.
ComboBox {
id: langBox
x: Theme.horizontalPageMargin
width: parent.width - 2 * Theme.horizontalPageMargin
label: qsTr("Language")
value: translator.language === "it" ? "Italiano"
: translator.language === "en" ? "English"
: qsTr("System")
menu: ContextMenu {
MenuItem {
text: qsTr("System")
onClicked: translator.language = ""
}
// I nomi delle lingue restano nella lingua che nominano.
MenuItem {
text: "English"
onClicked: translator.language = "en"
}
MenuItem {
text: "Italiano"
onClicked: translator.language = "it"
}
}
}
Label {
x: Theme.horizontalPageMargin
width: parent.width - 2 * Theme.horizontalPageMargin
text: qsTr("Changing the language reloads the app.")
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeExtraSmall
wrapMode: Text.Wrap
}
// ---- bridge ---------------------------------------------------- //
SectionHeader { text: qsTr("Bridge") }
TextField {
id: urlField
x: Theme.horizontalPageMargin
width: parent.width - 2 * Theme.horizontalPageMargin
label: qsTr("Bridge address")
placeholderText: "192.168.2.50:8790"
text: page.urlText
onTextChanged: if (text !== page.urlText) page.urlText = text
EnterKey.enabled: true
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
EnterKey.onClicked: page.save()
}
// PasswordField: mette l'icona nativa mostra/nascondi, niente
// TextField con echoMode gestito a mano.
PasswordField {
id: tokenField
x: Theme.horizontalPageMargin
width: parent.width - 2 * Theme.horizontalPageMargin
label: qsTr("Bridge token")
showEchoModeToggle: true
text: page.tokenText
onTextChanged: if (text !== page.tokenText) page.tokenText = text
EnterKey.enabled: true
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
EnterKey.onClicked: page.save()
}
Label {
x: Theme.horizontalPageMargin
width: parent.width - 2 * Theme.horizontalPageMargin
text: qsTr("Address and token live on the server: the token is in aira_bridge.json next to the bridge. Without a scheme, http:// is used.")
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeExtraSmall
wrapMode: Text.Wrap
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Save")
onClicked: {
page.save()
page.testResult = qsTr("settings saved")
page.testOk = true
}
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Test connection")
onClicked: page.testAndReport()
}
Label {
visible: page.testResult.length > 0
x: Theme.horizontalPageMargin
width: parent.width - 2 * Theme.horizontalPageMargin
text: page.testResult
color: page.testOk ? Theme.highlightColor : Theme.errorColor
font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.Wrap
}
}
}
}