ricerca città: log diagnostici, timeout geocoding, footer lista vuota, traduzioni

This commit is contained in:
2026-08-25 09:10:53 +02:00
parent 5383517aeb
commit 2b14571906
3 changed files with 54 additions and 5 deletions
+48 -5
View File
@@ -60,6 +60,22 @@ Page {
header: SectionHeader { text: qsTr("Ports") }
footer: Item {
width: parent.width
height: portModel.count === 0 ? Theme.itemSizeMedium : 0
Label {
visible: portModel.count === 0
anchors.fill: parent
anchors.margins: Theme.horizontalPageMargin
text: qsTr("No ports match the filter. Try the free city search above.")
color: Theme.secondaryColor
font.pixelSize: Theme.fontSizeSmall
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
delegate: ListItem {
contentHeight: Theme.itemSizeMedium
highlighted: model.isPreferred
@@ -92,6 +108,7 @@ Page {
anchors.verticalCenter: parent.verticalCenter
}
onClicked: {
console.log("[tide] open port:", model.name, "custom:", model.custom)
page.pageStack.push(Qt.resolvedUrl("DetailPage.qml"),
{ port: model.port, portIndex: model.realIndex, custom: model.custom })
}
@@ -130,13 +147,14 @@ Page {
}
// --- Ricerca libera (geocoding) ---
function geoFail() {
geoMsg.text = qsTr("City not found (offline and not in local dataset).")
function geoFail(msg) {
geoMsg.text = msg || qsTr("City not found (offline and not in local dataset).")
geoMsg.visible = true
geoMsg.color = Theme.errorColor
}
function geoFound(name, lat, lon, src) {
console.log("[tide] geoFound:", name, lat, lon, src)
if (!name) { geoFail(); return }
var np = Tides.nearestPort(lat, lon)
var cost, flag
@@ -153,19 +171,37 @@ Page {
geoMsg.text = qsTr("Found %1 (via %2)").arg(name).arg(src)
geoMsg.visible = true
geoMsg.color = Theme.highlightColor
page.pageStack.push(Qt.resolvedUrl("DetailPage.qml"),
{ port: port, portIndex: -1, custom: true })
try {
page.pageStack.push(Qt.resolvedUrl("DetailPage.qml"),
{ port: port, portIndex: -1, custom: true })
} catch (e) {
console.log("[tide] push DetailPage failed:", e)
geoFail(qsTr("Could not open the detail page: %1").arg(e))
}
}
function geoXhr(query, cb) {
// Photon (komoot) invece di Nominatim: accetta qualsiasi User-Agent
// (Nominatim risponde 403 all'UA generico inviato dalle XHR QML di Qt)
// e supporta il filtro osm_tag=place:city per le città vere.
console.log("[tide] geoXhr:", query)
var xhr = new XMLHttpRequest()
var done = false
var to = setTimeout(function() {
if (!done) {
done = true
console.log("[tide] geoXhr timeout")
cb(null, true)
}
}, 12000)
xhr.open("GET", "https://photon.komoot.io/api/?limit=1&osm_tag=place:city&q="
+ encodeURIComponent(query), true)
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (done) return
done = true
clearTimeout(to)
console.log("[tide] geoXhr status:", xhr.status)
if (xhr.status === 200) {
try {
var j = JSON.parse(xhr.responseText)
@@ -190,6 +226,7 @@ Page {
function findCity() {
var q = geoField.text.trim()
console.log("[tide] findCity:", q)
if (q === "") return
geoMsg.text = qsTr("Searching…")
geoMsg.visible = true
@@ -198,7 +235,13 @@ Page {
if (loc) {
geoFound(loc[0], loc[2], loc[3], qsTr("local dataset"))
} else {
geoXhr(q, geoFound)
geoXhr(q, function(name, lat, lon, src, timeout) {
if (timeout) {
geoFail(qsTr("Geocoding service not reachable (timeout). Check the network."))
return
}
geoFound(name, lat, lon, src)
})
}
}
+3
View File
@@ -12,6 +12,9 @@
<message><source>local dataset</source><translation type="unfinished"></translation></message>
<message><source>searched city</source><translation type="unfinished"></translation></message>
<message><source>Ports</source><translation type="unfinished"></translation></message>
<message><source>No ports match the filter. Try the free city search above.</source><translation type="unfinished"></translation></message>
<message><source>Geocoding service not reachable (timeout). Check the network.</source><translation type="unfinished"></translation></message>
<message><source>Could not open the detail page: %1</source><translation type="unfinished"></translation></message>
</context>
<context>
<name>DetailPage</name>
+3
View File
@@ -12,6 +12,9 @@
<message><source>local dataset</source><translation>dataset locale</translation></message>
<message><source>searched city</source><translation>città cercata</translation></message>
<message><source>Ports</source><translation>Porti</translation></message>
<message><source>No ports match the filter. Try the free city search above.</source><translation>Nessun porto corrisponde al filtro. Prova la ricerca libera qui sopra.</translation></message>
<message><source>Geocoding service not reachable (timeout). Check the network.</source><translation>Servizio di geocoding non raggiungibile (timeout). Controlla la rete.</translation></message>
<message><source>Could not open the detail page: %1</source><translation>Impossibile aprire la pagina di dettaglio: %1</translation></message>
</context>
<context>
<name>DetailPage</name>