[locale] Update the map-QML implementation
- Config has suitable strings for displaying TZ information. Use them and automatic bindings. Don't update the strings manually. - Suggest online or offline TZ lookups based on what the distro wants. Edit the QML to pick online lookups (needs access to the geonames service, though). - Drop the variables that point at config and geoip: the Config object has a currentLocation, which is filled in by both the configuration and any GeoIP lookup -- it doesn't have city or country information though.
This commit is contained in:
parent
15a8d62986
commit
91cc5a2b42
@ -29,17 +29,12 @@ import QtPositioning 5.14
|
|||||||
Column {
|
Column {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
|
|
||||||
//Needs to come from .conf/geoip
|
// These are used by the map query to initially center the
|
||||||
property var configCity: "New York"
|
// map on the user's likely location. They are updated by
|
||||||
property var configCountry: "USA"
|
// getIp() which does a more accurate GeoIP lookup than
|
||||||
property var configTimezone: "America/New York"
|
// the default one in Calamares
|
||||||
property var geoipCity: "" //"Amsterdam"
|
property var cityName: ""
|
||||||
property var geoipCountry: "" //"Netherlands"
|
property var countryName: ""
|
||||||
property var geoipTimezone: "" //"Europe/Amsterdam"
|
|
||||||
// vars that will stay once connected
|
|
||||||
property var cityName: (geoipCity != "") ? geoipCity : configCity
|
|
||||||
property var countryName: (geoipCountry != "") ? geoipCountry : configCountry
|
|
||||||
property var timeZone: (geoipTimezone != "") ? geoipTimezone : configTimezone
|
|
||||||
|
|
||||||
function getIp() {
|
function getIp() {
|
||||||
var xhr = new XMLHttpRequest
|
var xhr = new XMLHttpRequest
|
||||||
@ -51,9 +46,10 @@ Column {
|
|||||||
var ct = responseJSON.city
|
var ct = responseJSON.city
|
||||||
var cy = responseJSON.country
|
var cy = responseJSON.country
|
||||||
|
|
||||||
tzText.text = "Timezone: " + tz
|
|
||||||
cityName = ct
|
cityName = ct
|
||||||
countryName = cy
|
countryName = cy
|
||||||
|
|
||||||
|
config.setCurrentLocation(tz)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +59,15 @@ Column {
|
|||||||
xhr.send()
|
xhr.send()
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTz() {
|
/* This is an **accurate** TZ lookup method: it queries an
|
||||||
|
* online service for the TZ at the given coordinates. It
|
||||||
|
* requires an internet connection, though, and the distribution
|
||||||
|
* will need to have an account with geonames to not hit the
|
||||||
|
* daily query limit.
|
||||||
|
*
|
||||||
|
* See below, in MouseArea, for calling the right method.
|
||||||
|
*/
|
||||||
|
function getTzOnline() {
|
||||||
var xhr = new XMLHttpRequest
|
var xhr = new XMLHttpRequest
|
||||||
var latC = map.center.latitude
|
var latC = map.center.latitude
|
||||||
var lonC = map.center.longitude
|
var lonC = map.center.longitude
|
||||||
@ -73,16 +77,29 @@ Column {
|
|||||||
var responseJSON = JSON.parse(xhr.responseText)
|
var responseJSON = JSON.parse(xhr.responseText)
|
||||||
var tz2 = responseJSON.timezoneId
|
var tz2 = responseJSON.timezoneId
|
||||||
|
|
||||||
tzText.text = "Timezone: " + tz2
|
|
||||||
config.setCurrentLocation(tz2)
|
config.setCurrentLocation(tz2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Online lookup", latC, lonC)
|
||||||
// Needs to move to localeq.conf, each distribution will need their own account
|
// Needs to move to localeq.conf, each distribution will need their own account
|
||||||
xhr.open("GET", "http://api.geonames.org/timezoneJSON?lat=" + latC + "&lng=" + lonC + "&username=SOME_USERNAME")
|
xhr.open("GET", "http://api.geonames.org/timezoneJSON?lat=" + latC + "&lng=" + lonC + "&username=SOME_USERNAME")
|
||||||
xhr.send()
|
xhr.send()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is a quick TZ lookup method: it uses the existing
|
||||||
|
* Calamares "closest TZ" code, which has lots of caveats.
|
||||||
|
*
|
||||||
|
* See below, in MouseArea, for calling the right method.
|
||||||
|
*/
|
||||||
|
function getTzOffline() {
|
||||||
|
var latC = map.center.latitude
|
||||||
|
var lonC = map.center.longitude
|
||||||
|
var tz = config.zonesModel.lookup(latC, lonC)
|
||||||
|
console.log("Offline lookup", latC, lonC)
|
||||||
|
config.setCurrentLocation(tz.region, tz.zone)
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
width: parent.width
|
width: parent.width
|
||||||
height: parent.height / 1.28
|
height: parent.height / 1.28
|
||||||
@ -156,9 +173,8 @@ Column {
|
|||||||
map.center.latitude = coordinate.latitude
|
map.center.latitude = coordinate.latitude
|
||||||
map.center.longitude = coordinate.longitude
|
map.center.longitude = coordinate.longitude
|
||||||
|
|
||||||
getTz();
|
// Pick a TZ lookup method here (quick:offline, accurate:online)
|
||||||
|
getTzOffline();
|
||||||
console.log(coordinate.latitude, coordinate.longitude)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,8 +234,7 @@ Column {
|
|||||||
|
|
||||||
Text {
|
Text {
|
||||||
id: tzText
|
id: tzText
|
||||||
text: tzText.text
|
text: qsTr("Timezone: %1").arg(config.currentTimezoneName)
|
||||||
//text: qsTr("Timezone: %1").arg(timeZone)
|
|
||||||
color: Kirigami.Theme.textColor
|
color: Kirigami.Theme.textColor
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user