Files
harbour-quill/qml/pages/MainPage.qml
T
kaneda 82d85ab30b 0.3.1: la nota nasce nella cartella aperta, navigazione senza voci fantasma
- NewNoteDialog riceve la cartella corrente: il file va dove sei, non nella
  radice del caveau. Un nome gia' presente viene rifiutato (la PUT avrebbe
  sovrascritto la nota senza chiedere) e il nome non puo' contenere "/".
- PropfindParser.listing(): scarta la collezione stessa (il PROPFIND Depth:1 la
  include, e dentro una cartella sembrava di non essere entrati) e le voci
  nascoste (.obsidian/, .trash/), anche nella scansione di ricerca e tag: le
  note nel cestino non finiscono piu' nei risultati.
- MainPage: se il client e' occupato la navigazione va in coda invece di essere
  persa, e l'elenco precedente viene svuotato subito (non resta sotto
  l'intestazione nuova).
- Test del filtro con la risposta reale di Libro/; verificatore aggiornato per i
  segnali di cambio proprieta' (onBusyChanged).
2026-11-08 21:04:31 +01:00

215 lines
7.4 KiB
QML

import QtQuick 2.2
import Sailfish.Silica 1.0
import "../components"
Page {
id: page
property var dav
property string currentPath: ""
property string coverText: currentPath === "" ? qsTr("Notes") : currentPath
property bool loading: false
property var pendingEditor: null
property var allEntries: []
property string filterText: ""
// Una navigazione chiesta mentre il client è occupato non va persa: senza
// questa coda l'intestazione cambiava e la lista restava quella di prima.
property bool pendingReload: false
onFilterTextChanged: page.applyFilter()
onStatusChanged: {
if (status === PageStatus.Active) {
if (page.pendingEditor) {
// New note accepted: the dialog pops itself, then we open the
// editor (push here — after the dialog pop — avoids stack races).
var ed = page.pendingEditor
page.pendingEditor = null
pageStack.push(Qt.resolvedUrl("EditorPage.qml"),
{ dav: page.dav,
notePath: ed.path,
noteName: ed.name,
initialContent: "# " + ed.name.replace(/\.md$/, "") + "\n\n",
skipLoad: true })
} else {
reload()
}
}
}
Component.onCompleted: reload()
function reload() {
if (!dav) return
if (dav.busy || dav.scanning) {
pendingReload = true
return
}
pendingReload = false
loading = true
dav.listDir(currentPath)
}
function enterFolder(path) {
filterText = ""
currentPath = path
// L'elenco vecchio non deve restare sotto l'intestazione nuova mentre
// arriva la risposta: si vedrebbe la cartella di prima.
allEntries = []
notesModel.clear()
reload()
}
function applyFilter() {
notesModel.clear()
var f = page.filterText.trim().toLowerCase()
for (var i = 0; i < allEntries.length; i++) {
var e = allEntries[i]
// All files are shown (not only .md) — any file can be opened as text.
if (f && e.name.toLowerCase().indexOf(f) < 0) continue
notesModel.append({ name: e.name, path: e.path, isDir: e.isDir, mtime: e.mtime, size: e.size })
}
}
ListModel {
id: notesModel
}
Connections {
target: dav
onBusyChanged: {
if (!dav.busy && !dav.scanning && page.pendingReload) page.reload()
}
onListReady: {
loading = false
allEntries = entries
console.log("Quill listReady:", entries.length, "entries in", page.currentPath)
page.applyFilter()
}
// Refresh the list whenever a write completes elsewhere (new note,
// editor save, delete) — the list under the stack stays fresh.
onWriteDone: page.reload()
onDeleteDone: page.reload()
onFailed: {
loading = false
banner.show(message, true)
}
}
SilicaListView {
id: listView
anchors.fill: parent
model: notesModel
header: Column {
width: parent.width
PageHeader { title: "Quill" }
SearchField {
id: searchField
width: parent.width
placeholderText: qsTr("Filter by title")
// Bound to the page property so the delegates (which cannot
// see header ids) can clear it via page.filterText.
text: page.filterText
onTextChanged: {
if (text !== page.filterText) page.filterText = text
}
}
ListItem {
visible: page.currentPath !== ""
contentHeight: Theme.itemSizeSmall
onClicked: page.enterFolder("")
Label {
anchors.verticalCenter: parent.verticalCenter
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
color: Theme.highlightColor
font.pixelSize: Theme.fontSizeSmall
text: "▲ " + page.currentPath
}
}
}
ViewPlaceholder {
enabled: notesModel.count === 0 && !page.loading
text: page.currentPath === "" ? qsTr("No notes yet. Create one from the pulley menu.")
: qsTr("Empty folder")
}
delegate: ListItem {
id: noteItem
contentHeight: Theme.itemSizeMedium
onClicked: {
if (model.isDir) {
page.enterFolder(model.path)
} else {
pageStack.push(Qt.resolvedUrl("EditorPage.qml"),
{ dav: page.dav, notePath: model.path, noteName: model.name })
}
}
Column {
anchors.verticalCenter: parent.verticalCenter
x: Theme.paddingLarge
width: parent.width - 2 * Theme.paddingLarge
Label {
text: model.name + (model.isDir ? "/" : "")
color: model.isDir ? Theme.highlightColor : Theme.primaryColor
font.pixelSize: Theme.fontSizeMedium
truncationMode: TruncationMode.Fade
}
Label {
visible: !model.isDir
text: model.mtime
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
truncationMode: TruncationMode.Fade
}
}
}
VerticalScrollDecorator {}
PullDownMenu {
MenuItem {
text: qsTr("Settings")
onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"), { dav: page.dav })
}
MenuItem {
text: qsTr("New note")
onClicked: {
var names = []
for (var i = 0; i < page.allEntries.length; i++) names.push(page.allEntries[i].name)
var dlg = pageStack.push(Qt.resolvedUrl("NewNoteDialog.qml"),
{ dav: page.dav, folder: page.currentPath, existingNames: names })
dlg.accepted.connect(function () {
if (dlg.resultPath) {
page.pendingEditor = { path: dlg.resultPath, name: dlg.resultName }
}
})
}
}
MenuItem {
text: qsTr("Search in the text")
onClicked: pageStack.push(Qt.resolvedUrl("SearchPage.qml"),
{ dav: page.dav, rootPath: page.currentPath })
}
MenuItem {
text: qsTr("Tags")
onClicked: pageStack.push(Qt.resolvedUrl("TagPage.qml"),
{ dav: page.dav, rootPath: "" })
}
MenuItem {
text: qsTr("Refresh")
onClicked: page.reload()
}
}
BusyIndicator {
anchors.centerIn: parent
running: page.loading
}
}
Banner { id: banner }
}