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 } } } }