diff --git a/src/modules/localeq/Map.qml b/src/modules/localeq/Map.qml index 06b4f7a1f..d414825dd 100644 --- a/src/modules/localeq/Map.qml +++ b/src/modules/localeq/Map.qml @@ -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(); + */ } } diff --git a/src/modules/localeq/localeq.qml b/src/modules/localeq/localeq.qml index 49719db65..1a250f5c1 100644 --- a/src/modules/localeq/localeq.qml +++ b/src/modules/localeq/localeq.qml @@ -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