@ -29,17 +29,12 @@ import QtPositioning 5.14
Column {
width: parent . width
/ / N e e d s t o c o m e f r o m . c o n f / g e o i p
property var configCity: "New York"
property var configCountry: "USA"
property var configTimezone: "America/New York"
property var geoipCity: "" / / " A m s t e r d a m "
property var geoipCountry: "" / / " N e t h e r l a n d s "
property var geoipTimezone: "" / / " E u r o p e / A m s t e r d a m "
/ / v a r s t h a t w i l l s t a y o n c e c o n n e c t e d
property var cityName: ( geoipCity != "" ) ? geoipCity : configCity
property var countryName: ( geoipCountry != "" ) ? geoipCountry : configCountry
property var timeZone: ( geoipTimezone != "" ) ? geoipTimezone : configTimezone
/ / T h e s e a r e u s e d b y t h e m a p q u e r y t o i n i t i a l l y c e n t e r t h e
/ / m a p o n t h e u s e r ' s l i k e l y l o c a t i o n . T h e y a r e u p d a t e d b y
/ / g e t I p ( ) w h i c h d o e s a m o r e a c c u r a t e G e o I P l o o k u p t h a n
/ / t h e d e f a u l t o n e i n C a l a m a r e s
property var cityName: ""
property var countryName: ""
function getIp ( ) {
var xhr = new XMLHttpRequest
@ -51,9 +46,10 @@ Column {
var ct = responseJSON . city
var cy = responseJSON . country
tzText . text = "Timezone: " + tz
cityName = ct
countryName = cy
config . setCurrentLocation ( tz )
}
}
@ -63,7 +59,15 @@ Column {
xhr . send ( )
}
function getTz ( ) {
/ * T h i s i s a n * * a c c u r a t e * * T Z l o o k u p m e t h o d : i t q u e r i e s a n
* 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 latC = map . center . latitude
var lonC = map . center . longitude
@ -73,16 +77,29 @@ Column {
var responseJSON = JSON . parse ( xhr . responseText )
var tz2 = responseJSON . timezoneId
tzText . text = "Timezone: " + tz2
config . setCurrentLocation ( tz2 )
}
}
console . log ( "Online lookup" , latC , lonC )
/ / N e e d s t o m o v e t o l o c a l e q . c o n f , e a c h d i s t r i b u t i o n w i l l n e e d t h e i r o w n a c c o u n t
xhr . open ( "GET" , "http://api.geonames.org/timezoneJSON?lat=" + latC + "&lng=" + lonC + "&username=SOME_USERNAME" )
xhr . send ( )
}
/ * T h i s i s a q u i c k T Z l o o k u p m e t h o d : i t u s e s t h e e x i s t i n g
* 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 {
width: parent . width
height: parent . height / 1.28
@ -156,9 +173,8 @@ Column {
map . center . latitude = coordinate . latitude
map . center . longitude = coordinate . longitude
getTz ( ) ;
console . log ( coordinate . latitude , coordinate . longitude )
/ / P i c k a T Z l o o k u p m e t h o d h e r e ( q u i c k : o f f l i n e , a c c u r a t e : o n l i n e )
getTzOffline ( ) ;
}
}
}
@ -218,8 +234,7 @@ Column {
Text {
id: tzText
text: tzText . text
/ / t e x t : q s T r ( " T i m e z o n e : % 1 " ) . a r g ( t i m e Z o n e )
text: qsTr ( "Timezone: %1" ) . arg ( config . currentTimezoneName )
color: Kirigami . Theme . textColor
anchors.centerIn: parent
}