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

190 lines
6.2 KiB
QML

import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
property string testResult: ""
property bool testOk: false
property bool testing: false
property string languageNotice: ""
SilicaFlickable {
anchors.fill: parent
contentHeight: column.height
Column {
id: column
width: parent.width
PageHeader { title: qsTr("Settings") }
SectionHeader { text: qsTr("Server") }
TextField {
id: serverField
anchors.left: parent.left
anchors.right: parent.right
label: qsTr("Calibre Web address")
placeholderText: "https://calibre.example.com"
text: appSettings.serverUrl
inputMethodHints: Qt.ImhUrlCharactersOnly
onTextChanged: appSettings.serverUrl = text
}
TextField {
id: userField
anchors.left: parent.left
anchors.right: parent.right
label: qsTr("User (empty = anonymous access)")
text: appSettings.username
onTextChanged: appSettings.username = text
}
TextField {
id: passField
anchors.left: parent.left
anchors.right: parent.right
label: qsTr("Password")
text: appSettings.password
echoMode: TextInput.Password
onTextChanged: appSettings.password = text
}
TextSwitch {
text: qsTr("Ignore SSL certificate errors")
description: qsTr("Enable if the server uses a self-signed certificate")
checked: appSettings.ignoreSslErrors
onCheckedChanged: appSettings.ignoreSslErrors = checked
}
SectionHeader { text: qsTr("Reader") }
Slider {
id: marginSlider
width: parent.width
label: qsTr("Side margins")
minimumValue: 0
maximumValue: 80
stepSize: 4
value: appSettings.readerMargin
valueText: value + " px"
onValueChanged: appSettings.readerMargin = value
}
Slider {
id: marginVSlider
width: parent.width
label: qsTr("Top and bottom margin")
minimumValue: 0
maximumValue: 80
stepSize: 4
value: appSettings.readerMarginV
valueText: value + " px"
onValueChanged: appSettings.readerMarginV = value
}
SectionHeader { text: qsTr("Connection") }
Button {
anchors.horizontalCenter: parent.horizontalCenter
text: qsTr("Test connection")
enabled: !page.testing
onClicked: testConnection()
}
Item {
width: parent.width
height: page.testing ? Theme.itemSizeSmall : 0
BusyIndicator {
anchors.horizontalCenter: parent.horizontalCenter
running: page.testing
size: BusyIndicatorSize.Small
}
}
Label {
x: Theme.horizontalPageMargin
width: parent.width - 2 * Theme.horizontalPageMargin
text: page.testResult
color: page.testOk ? Theme.secondaryHighlightColor : Theme.errorColor
wrapMode: Text.Wrap
visible: text.length > 0
}
SectionHeader { text: qsTr("Language") }
ComboBox {
id: langBox
width: parent.width
label: qsTr("Language")
currentIndex: appSettings.language === "it" ? 2 : (appSettings.language === "en" ? 1 : 0)
menu: ContextMenu {
MenuItem { text: qsTr("System (default)") }
MenuItem { text: "English" }
MenuItem { text: "Italiano" }
}
onCurrentIndexChanged: {
var v = currentIndex === 2 ? "it" : (currentIndex === 1 ? "en" : "system")
if (v !== appSettings.language) {
appSettings.language = v
page.languageNotice = qsTr("Language will be applied after restarting the app")
langNoticeTimer.restart()
}
}
}
Label {
x: Theme.horizontalPageMargin
width: parent.width - 2 * Theme.horizontalPageMargin
text: page.languageNotice
color: Theme.highlightColor
wrapMode: Text.Wrap
visible: text.length > 0
}
Timer {
id: langNoticeTimer
interval: 4000
onTriggered: page.languageNotice = ""
}
Item { width: 1; height: Theme.paddingLarge }
}
}
function testConnection() {
var base = appSettings.serverUrl.trim()
if (base.length === 0) {
page.testResult = qsTr("Enter the server address")
page.testOk = false
return
}
// normalizza: senza schema aggiunge https:// e lo salva nel campo
if (base.indexOf("http://") !== 0 && base.indexOf("https://") !== 0)
base = "https://" + base
appSettings.serverUrl = base
page.testing = true
page.testResult = qsTr("Testing…")
apiClient.getFeed(base + "/opds")
}
Connections {
target: apiClient
onFeedReady: {
if (pageStack.currentPage !== page)
return
page.testing = false
page.testOk = true
page.testResult = qsTr("Connection OK: %1 sections found").arg(entries.length)
}
onFeedError: {
if (pageStack.currentPage !== page)
return
page.testing = false
page.testOk = false
page.testResult = message
}
}
}