mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-25 03:15:44 -05:00
[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
2 changed files with 29 additions and 2 deletions
|
@ -36,7 +36,12 @@ Column {
|
|||
property var cityName: ""
|
||||
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
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
|
@ -59,6 +64,16 @@ Column {
|
|||
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
|
||||
* online service for the TZ at the given coordinates. It
|
||||
* requires an internet connection, though, and the distribution
|
||||
|
@ -239,7 +254,11 @@ Column {
|
|||
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
|
||||
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 {
|
||||
id: image
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
|
Loading…
Add table
Reference in a new issue