Files
harbour-aira/qml/pages/SettingsPage.qml
T

117 lines
3.8 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("verifico…")
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("Impostazioni") }
TextField {
id: urlField
x: Theme.horizontalPageMargin
width: parent.width - 2 * Theme.horizontalPageMargin
label: qsTr("Indirizzo del bridge")
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("Token del bridge")
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("Indirizzo e token si leggono sul server: il token è in ~/.hermes/profiles/carlo/aira_bridge.json. Senza schema viene usato http://.")
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeExtraSmall
wrapMode: Text.Wrap
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Salva")
onClicked: {
page.save()
page.testResult = qsTr("impostazioni salvate")
page.testOk = true
}
}
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Prova connessione")
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
}
}
}
}