108 lines
3.0 KiB
QML
108 lines
3.0 KiB
QML
import QtQuick 2.0
|
|
import Sailfish.Silica 1.0
|
|
|
|
Page {
|
|
id: page
|
|
|
|
property bool loading: false
|
|
property string errorMessage: ""
|
|
|
|
SilicaListView {
|
|
id: listView
|
|
anchors.fill: parent
|
|
header: PageHeader { title: "Calibre Web" }
|
|
model: sectionModel
|
|
|
|
delegate: ListItem {
|
|
id: sectionItem
|
|
contentHeight: Theme.itemSizeMedium
|
|
|
|
Label {
|
|
anchors.left: parent.left
|
|
anchors.leftMargin: Theme.horizontalPageMargin
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
text: model.title
|
|
color: sectionItem.highlighted ? Theme.highlightColor : Theme.primaryColor
|
|
}
|
|
|
|
Icon {
|
|
anchors.right: parent.right
|
|
anchors.rightMargin: Theme.horizontalPageMargin
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
source: "image://theme/icon-m-right"
|
|
}
|
|
|
|
onClicked: {
|
|
pageStack.push(Qt.resolvedUrl("FeedPage.qml"),
|
|
{ feedUrl: model.linkUrl, pageTitle: model.title })
|
|
}
|
|
}
|
|
|
|
PullDownMenu {
|
|
MenuItem {
|
|
text: "Cerca"
|
|
onClicked: pageStack.push(Qt.resolvedUrl("SearchPage.qml"))
|
|
}
|
|
MenuItem {
|
|
text: "Impostazioni"
|
|
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
|
|
}
|
|
MenuItem {
|
|
text: "Aggiorna"
|
|
onClicked: loadIndex()
|
|
}
|
|
}
|
|
|
|
ViewPlaceholder {
|
|
enabled: sectionModel.count === 0 && !page.loading
|
|
text: page.errorMessage.length > 0
|
|
? page.errorMessage
|
|
: "Apri le impostazioni e inserisci l'indirizzo del tuo Calibre Web"
|
|
}
|
|
|
|
BusyIndicator {
|
|
anchors.centerIn: parent
|
|
running: page.loading
|
|
size: BusyIndicatorSize.Large
|
|
}
|
|
}
|
|
|
|
ListModel {
|
|
id: sectionModel
|
|
}
|
|
|
|
function loadIndex() {
|
|
var base = appSettings.baseUrl
|
|
if (base.length === 0) {
|
|
page.errorMessage = "Server non configurato"
|
|
return
|
|
}
|
|
page.loading = true
|
|
page.errorMessage = ""
|
|
apiClient.getFeed(base + "/opds")
|
|
}
|
|
|
|
Component.onCompleted: loadIndex()
|
|
|
|
Connections {
|
|
target: apiClient
|
|
onFeedReady: {
|
|
if (pageStack.currentPage !== page)
|
|
return
|
|
page.loading = false
|
|
sectionModel.clear()
|
|
for (var i = 0; i < entries.length; i++) {
|
|
var e = entries[i]
|
|
if (e.isNavigation)
|
|
sectionModel.append({ title: e.title, linkUrl: e.linkUrl })
|
|
}
|
|
if (sectionModel.count === 0)
|
|
page.errorMessage = "Nessuna sezione trovata nel feed OPDS"
|
|
}
|
|
onFeedError: {
|
|
page.loading = false
|
|
page.errorMessage = message
|
|
}
|
|
}
|
|
}
|