4import QtQuick.Controls 2.0
6import QtQuick.Layouts 1.1
7import "../../constants" 1.0
9import QtPositioning 5.2
13 title: editMode ? xi18n("Edit location") : (isReadOnly ?
xi18n(
"View location") :
xi18n(
"Add location"))
14 property bool editMode: false
15 property bool isAvailable: positionSource.valid
16 property bool isReadOnly: false
17 property string geoName
18 property bool fieldsChanged: false
19 property string loadingText
20 property string fetchingCoordinatesLoading:
xi18n(
"Please, wait while we are fetching coordinates")
22 property bool fetchingName: false
23 property bool addAutomatically: false
25 signal locationFetched(var _lat, var _lng)
26 signal locNameFetched(var _city, var _region, var _country)
30 function setAutomaticallyFromGPS() {
31 addAutomatically =
true
33 positionSource.start()
34 loadingText = fetchingCoordinatesLoading
35 if(!positionSource.valid) {
37 skyMapLite.notification.showNotification(xi18(
"Positioning is not available on your device"))
44 property string region
57 locationLoading.close()
58 var city =
xi18n(
"Default city")
59 var province = xi18n("Default province")
60 var country = xi18n("Default country")
61 if(addAutomatically) {
62 skyMapLite.notification.showNotification(
xi18n(
"Could not fetch location name (check your Internet connection). Added with default name"))
66 skyMapLite.notification.showNotification(xi18n(
"Failed to set location"))
71 skyMapLite.notification.showNotification(xi18n(
"Successfully set your location"))
73 skyMapLite.notification.showNotification(xi18n(
"Could not set your location"))
76 skyMapLite.notification.showNotification(
xi18n(
"Could not fetch location name (check your Internet connection). Set default name"))
78 provinceField.text = province
80 comboBoxTZ.currentIndex = comboBoxTZ.find(tz)
83 addAutomatically =
false
88 nameFetchTimeout.running =
false
96 skyMapLite.notification.showNotification(
xi18n(
"Failed to set location"))
100 skyMapLite.notification.showNotification(
xi18n(
"Successfully set your location"))
102 skyMapLite.notification.showNotification(
xi18n(
"Could not set your location"))
105 addAutomatically =
false
112 fieldsChanged =
false
115 function openEdit(fullName, readOnly) {
117 isReadOnly = readOnly
133 fieldsChanged =
false
139 property bool error:
false
141 onSourceErrorChanged: {
142 if (sourceError == PositionSource.NoError)
147 if (sourceError == 2 || sourceError == 1) {
148 errorDesc =
xi18n(
"No location service (GPS, cellular service, etc.) is available.\nPlease, switch on the location service, and retry")
149 }
else if (sourceError == 4) {
150 errorDesc =
xi18n(
"Unknown error occurred. Please contact the application developer.")
153 skyMapLite.notification.showNotification(errorDesc)
154 positionSource.stop()
156 locationLoading.close()
160 skyMapLite.notification.showNotification(
xi18n(
"Timeout occurred. Try again."))
161 locationLoading.close()
165 if(positionSource.active && !error) {
166 locationLoading.open()
167 }
else if (!fetchingName) {
168 locationLoading.close()
175 skyMapLite.notification.showNotification(
xi18n(
"Found your longitude and altitude"))
176 var lat = positionSource.position.coordinate.latitude
177 var lng = positionSource.position.coordinate.longitude
180 if(addAutomatically) {
181 locationFetched(lat, lng)
184 tz = (
new Date().getTimezoneOffset()/60)*-1
185 loadingText =
xi18n(
"Please, wait while we are retrieving location name")
187 positionSource.stop()
189 nameFetchTimeout.running =
true
190 setTZComboBox(
new Date().getTimezoneOffset())
193 preferredPositioningMethods: PositionSource.AllPositioningMethods
196 function setTZComboBox(TZMinutes) {
197 var TZ = (TZMinutes/60)*-1
198 comboBoxTZ.currentIndex = comboBoxTZ.find(TZ)
203 onNewNameFromCoordinates: {
204 if(addAutomatically) {
205 locNameFetched(city, region, country)
207 cityField.text = city
208 provinceField.text = region
211 locationLoading.close()
212 addAutomatically =
false
220 provinceField.clear()
239 flow:
window.isPortrait ? GridLayout.TopToBottom : GridLayout.LeftToRight
242 anchors.top: parent.top
243 Layout.maximumWidth:
window.isPortrait ? parent.
width : parent.width/2
247 text:
xi18n(
"City: ")
252 Layout.fillWidth:
true
253 onTextChanged: fieldsChanged =
true
260 text:
xi18n(
"Province: ")
265 Layout.fillWidth:
true
266 onTextChanged: fieldsChanged =
true
273 text:
xi18n(
"Country: ")
278 Layout.fillWidth:
true
279 onTextChanged: fieldsChanged =
true
286 height:
window.isPortrait ? 15 : 0
290 Layout.maximumWidth:
window.isPortrait ? parent.
width : parent.width/2
294 text:
xi18n(
"Latitude: ")
299 Layout.fillWidth:
true
307 text:
xi18n(
"Longitude: ")
312 Layout.fillWidth:
true
318 Layout.fillWidth:
true
323 text:
xi18n(
"UT offset: ")
334 text:
xi18n(
"DST rule: ")
347 Layout.fillWidth:
true
352 text:
xi18n(
"Set from GPS")
355 positionSource.stop()
356 positionSource.start()
357 loadingText = fetchingCoordinatesLoading
358 if(!positionSource.valid) {
359 positionSource.stop()
360 skyMapLite.notification.showNotification(xi18(
"Positioning is not available on your device"))
365 target: locationLoading
367 positionSource.stop()
377 if(cityField.text ==
"") {
378 skyMapLite.notification.showNotification(xi18n(
"Please, fill in the city"))
380 }
else if(countryField.text ==
"") {
381 skyMapLite.notification.showNotification(xi18n(
"Please, fill in the country"))
383 }
else if(latField.text ==
"") {
384 skyMapLite.notification.showNotification(xi18n(
"Please, fill in the latitude"))
386 }
else if(longField.text ==
"") {
387 skyMapLite.notification.showNotification(xi18n(
"Please, fill in the longitude"))
392 skyMapLite.notification.showNotification(xi18n(
"Either the longitude or the latitude values are not valid"))
397 if(LocationDialogLite.isDuplicate(cityField.text, provinceField.text, countryField.text)) {
398 skyMapLite.notification.showNotification(xi18n(
"This location already exists. Change either the city, the province or the country"))
404 var
fullName = cityField.text +
", "
405 if(provinceField.text !=
"") {
406 fullName += provinceField.text +
", "
412 latField.text, longField.text, comboBoxTZ.currentText,
413 comboBoxDST.currentText)) {
414 skyMapLite.notification.showNotification(
xi18n(
"Failed to add location"))
417 skyMapLite.notification.showNotification(
xi18n(
"Added new location - %1", fullName))
420 if(!
LocationDialogLite.editCity(geoName, cityField.text, provinceField.text, countryField.text,
421 latField.text, longField.text, comboBoxTZ.currentText,
422 comboBoxDST.currentText)) {
423 skyMapLite.notification.showNotification(
xi18n(
"Failed to edit city"))
428 locationDialog.filterCities()
431 locationsGeoMenu.openMenu(fullName)
439 text:
xi18n(
"Cancel")
A backend of location dialog declared in QML.
Q_INVOKABLE bool checkLongLat(const QString &longitude, const QString &latitude)
checkLongLat checks whether given longitude and latitude are valid
Q_INVOKABLE void getNameFromCoordinates(double latitude, double longitude)
Retrieve name of location by latitude and longitude.
QString xi18n(const char *text, const TYPE &arg...)
QString fullName(const PartType &type)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
KI18NLOCALEDATA_EXPORT KCountry country(const char *ianaId)
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)