[localeq] Demonstrate "offline" lookups
- we can do GeoIP and GeoNames lookups, **or** - use Calamares's internal GeoIP lookup and country / city hints. The online version is much more accurate, but costs more lookups; in these examples, set it all to "offline" and document what needs to change (code edit) to use the online version. It's probably a good beginner job to introduce a bool in localeq.qml to switch the behaviors.
This commit is contained in:
parent
71ca1e1544
commit
c69bd972e9
@ -36,7 +36,12 @@ Column {
|
|||||||
property var cityName: ""
|
property var cityName: ""
|
||||||
property var countryName: ""
|
property var countryName: ""
|
||||||
|
|
||||||
function getIp() {
|
/* This is an extra GeoIP lookup, which will find better-accuracy
|
||||||
|
* location data for the user's IP, and then sets the current timezone
|
||||||
|
* and map location. Call it from Component.onCompleted so that
|
||||||
|
* it happens "on time" before the page is shown.
|
||||||
|
*/
|
||||||
|
function getIpOnline() {
|
||||||
var xhr = new XMLHttpRequest
|
var xhr = new XMLHttpRequest
|
||||||
|
|
||||||
xhr.onreadystatechange = function() {
|
xhr.onreadystatechange = function() {
|
||||||
@ -59,6 +64,16 @@ Column {
|
|||||||
xhr.send()
|
xhr.send()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is an "offline" GeoIP lookup -- it just follows what
|
||||||
|
* Calamares itself has figured out with its GeoIP or configuration.
|
||||||
|
* Call it from the **Component** onActivate() -- in localeq.qml --
|
||||||
|
* so it happens as the page is shown.
|
||||||
|
*/
|
||||||
|
function getIpOffline() {
|
||||||
|
cityName = config.currentLocation.zone
|
||||||
|
countryName = config.currentLocation.countryCode
|
||||||
|
}
|
||||||
|
|
||||||
/* This is an **accurate** TZ lookup method: it queries an
|
/* This is an **accurate** TZ lookup method: it queries an
|
||||||
* online service for the TZ at the given coordinates. It
|
* online service for the TZ at the given coordinates. It
|
||||||
* requires an internet connection, though, and the distribution
|
* requires an internet connection, though, and the distribution
|
||||||
@ -239,7 +254,11 @@ Column {
|
|||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: getIp();
|
/* If you want an extra (and accurate) GeoIP lookup,
|
||||||
|
* enable this one and disable the offline lookup in
|
||||||
|
* onActivate().
|
||||||
|
Component.onCompleted: getIpOnline();
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,14 @@ Page {
|
|||||||
width: 800
|
width: 800
|
||||||
height: 550
|
height: 550
|
||||||
|
|
||||||
|
function onActivate() {
|
||||||
|
/* If you want the map to follow Calamares's GeoIP
|
||||||
|
* lookup or configuration, call the update function
|
||||||
|
* here, and disable the one at onCompleted in Map.qml.
|
||||||
|
*/
|
||||||
|
if (Network.hasInternet) { image.item.getIpOffline() }
|
||||||
|
}
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
id: image
|
id: image
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
Loading…
Reference in New Issue
Block a user