ricerca città: log diagnostici, timeout geocoding, footer lista vuota, traduzioni
This commit is contained in:
+48
-5
@@ -60,6 +60,22 @@ Page {
|
|||||||
|
|
||||||
header: SectionHeader { text: qsTr("Ports") }
|
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 {
|
delegate: ListItem {
|
||||||
contentHeight: Theme.itemSizeMedium
|
contentHeight: Theme.itemSizeMedium
|
||||||
highlighted: model.isPreferred
|
highlighted: model.isPreferred
|
||||||
@@ -92,6 +108,7 @@ Page {
|
|||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
}
|
}
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
console.log("[tide] open port:", model.name, "custom:", model.custom)
|
||||||
page.pageStack.push(Qt.resolvedUrl("DetailPage.qml"),
|
page.pageStack.push(Qt.resolvedUrl("DetailPage.qml"),
|
||||||
{ port: model.port, portIndex: model.realIndex, custom: model.custom })
|
{ port: model.port, portIndex: model.realIndex, custom: model.custom })
|
||||||
}
|
}
|
||||||
@@ -130,13 +147,14 @@ Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Ricerca libera (geocoding) ---
|
// --- Ricerca libera (geocoding) ---
|
||||||
function geoFail() {
|
function geoFail(msg) {
|
||||||
geoMsg.text = qsTr("City not found (offline and not in local dataset).")
|
geoMsg.text = msg || qsTr("City not found (offline and not in local dataset).")
|
||||||
geoMsg.visible = true
|
geoMsg.visible = true
|
||||||
geoMsg.color = Theme.errorColor
|
geoMsg.color = Theme.errorColor
|
||||||
}
|
}
|
||||||
|
|
||||||
function geoFound(name, lat, lon, src) {
|
function geoFound(name, lat, lon, src) {
|
||||||
|
console.log("[tide] geoFound:", name, lat, lon, src)
|
||||||
if (!name) { geoFail(); return }
|
if (!name) { geoFail(); return }
|
||||||
var np = Tides.nearestPort(lat, lon)
|
var np = Tides.nearestPort(lat, lon)
|
||||||
var cost, flag
|
var cost, flag
|
||||||
@@ -153,19 +171,37 @@ Page {
|
|||||||
geoMsg.text = qsTr("Found %1 (via %2)").arg(name).arg(src)
|
geoMsg.text = qsTr("Found %1 (via %2)").arg(name).arg(src)
|
||||||
geoMsg.visible = true
|
geoMsg.visible = true
|
||||||
geoMsg.color = Theme.highlightColor
|
geoMsg.color = Theme.highlightColor
|
||||||
page.pageStack.push(Qt.resolvedUrl("DetailPage.qml"),
|
try {
|
||||||
{ port: port, portIndex: -1, custom: true })
|
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) {
|
function geoXhr(query, cb) {
|
||||||
// Photon (komoot) invece di Nominatim: accetta qualsiasi User-Agent
|
// Photon (komoot) invece di Nominatim: accetta qualsiasi User-Agent
|
||||||
// (Nominatim risponde 403 all'UA generico inviato dalle XHR QML di Qt)
|
// (Nominatim risponde 403 all'UA generico inviato dalle XHR QML di Qt)
|
||||||
// e supporta il filtro osm_tag=place:city per le città vere.
|
// e supporta il filtro osm_tag=place:city per le città vere.
|
||||||
|
console.log("[tide] geoXhr:", query)
|
||||||
var xhr = new XMLHttpRequest()
|
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="
|
xhr.open("GET", "https://photon.komoot.io/api/?limit=1&osm_tag=place:city&q="
|
||||||
+ encodeURIComponent(query), true)
|
+ encodeURIComponent(query), true)
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === 4) {
|
||||||
|
if (done) return
|
||||||
|
done = true
|
||||||
|
clearTimeout(to)
|
||||||
|
console.log("[tide] geoXhr status:", xhr.status)
|
||||||
if (xhr.status === 200) {
|
if (xhr.status === 200) {
|
||||||
try {
|
try {
|
||||||
var j = JSON.parse(xhr.responseText)
|
var j = JSON.parse(xhr.responseText)
|
||||||
@@ -190,6 +226,7 @@ Page {
|
|||||||
|
|
||||||
function findCity() {
|
function findCity() {
|
||||||
var q = geoField.text.trim()
|
var q = geoField.text.trim()
|
||||||
|
console.log("[tide] findCity:", q)
|
||||||
if (q === "") return
|
if (q === "") return
|
||||||
geoMsg.text = qsTr("Searching…")
|
geoMsg.text = qsTr("Searching…")
|
||||||
geoMsg.visible = true
|
geoMsg.visible = true
|
||||||
@@ -198,7 +235,13 @@ Page {
|
|||||||
if (loc) {
|
if (loc) {
|
||||||
geoFound(loc[0], loc[2], loc[3], qsTr("local dataset"))
|
geoFound(loc[0], loc[2], loc[3], qsTr("local dataset"))
|
||||||
} else {
|
} 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)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
<message><source>local dataset</source><translation type="unfinished"></translation></message>
|
<message><source>local dataset</source><translation type="unfinished"></translation></message>
|
||||||
<message><source>searched city</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>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>
|
||||||
<context>
|
<context>
|
||||||
<name>DetailPage</name>
|
<name>DetailPage</name>
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
<message><source>local dataset</source><translation>dataset locale</translation></message>
|
<message><source>local dataset</source><translation>dataset locale</translation></message>
|
||||||
<message><source>searched city</source><translation>città cercata</translation></message>
|
<message><source>searched city</source><translation>città cercata</translation></message>
|
||||||
<message><source>Ports</source><translation>Porti</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>
|
||||||
<context>
|
<context>
|
||||||
<name>DetailPage</name>
|
<name>DetailPage</name>
|
||||||
|
|||||||
Reference in New Issue
Block a user