Changeset View
Changeset View
Standalone View
Standalone View
kstars/kstarslite/qml/dialogs/helpers/LocationEdit.qml
Show All 35 Lines | 18 | KSPage { | |||
---|---|---|---|---|---|
36 | about location */ | 36 | about location */ | ||
37 | function setAutomaticallyFromGPS() { | 37 | function setAutomaticallyFromGPS() { | ||
38 | addAutomatically = true | 38 | addAutomatically = true | ||
39 | positionSource.stop() | 39 | positionSource.stop() | ||
40 | positionSource.start() | 40 | positionSource.start() | ||
41 | loadingText = fetchingCoordinatesLoading | 41 | loadingText = fetchingCoordinatesLoading | ||
42 | if(!positionSource.valid) { | 42 | if(!positionSource.valid) { | ||
43 | positionSource.stop() | 43 | positionSource.stop() | ||
44 | notification.showNotification(xi18("Positioning is not available on your device")) | 44 | skyMapLite.notification.showNotification(xi18("Positioning is not available on your device")) | ||
45 | } | 45 | } | ||
46 | } | 46 | } | ||
47 | 47 | | |||
48 | property double lat | 48 | property double lat | ||
49 | property double lng | 49 | property double lng | ||
50 | property string city | 50 | property string city | ||
51 | property string region | 51 | property string region | ||
52 | property string country | 52 | property string country | ||
53 | property int tz | 53 | property int tz | ||
54 | 54 | | |||
55 | onLocationFetched: { | 55 | onLocationFetched: { | ||
56 | lat = _lat | 56 | lat = _lat | ||
57 | lng = _lng | 57 | lng = _lng | ||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | Timer { | 60 | Timer { | ||
61 | id: nameFetchTimeout | 61 | id: nameFetchTimeout | ||
62 | interval: 20000; | 62 | interval: 20000; | ||
63 | onTriggered: { | 63 | onTriggered: { | ||
64 | locationLoading.close() | 64 | locationLoading.close() | ||
65 | var city = xi18n("Default city") | 65 | var city = xi18n("Default city") | ||
66 | var province = xi18n("Default province") | 66 | var province = xi18n("Default province") | ||
67 | var country = xi18n("Default country") | 67 | var country = xi18n("Default country") | ||
68 | if(addAutomatically) { | 68 | if(addAutomatically) { | ||
69 | notification.showNotification(xi18n("Could not fetch location name (check your Internet connection). Added with default name")) | 69 | skyMapLite.notification.showNotification(xi18n("Could not fetch location name (check your Internet connection). Added with default name")) | ||
70 | if(!LocationDialogLite.addCity(city, province, country, | 70 | if(!LocationDialogLite.addCity(city, province, country, | ||
71 | lat, lng, tz, | 71 | lat, lng, tz, | ||
72 | "--")) { | 72 | "--")) { | ||
73 | notification.showNotification(xi18n("Failed to set location")) | 73 | skyMapLite.notification.showNotification(xi18n("Failed to set location")) | ||
74 | return | 74 | return | ||
75 | } | 75 | } | ||
76 | 76 | | |||
77 | if(LocationDialogLite.setLocation(city + ", " + province + ", " + country)) { | 77 | if(LocationDialogLite.setLocation(city + ", " + province + ", " + country)) { | ||
78 | notification.showNotification(xi18n("Successfully set your location")) | 78 | skyMapLite.notification.showNotification(xi18n("Successfully set your location")) | ||
79 | } else { | 79 | } else { | ||
80 | notification.showNotification(xi18n("Could not set your location")) | 80 | skyMapLite.notification.showNotification(xi18n("Could not set your location")) | ||
81 | } | 81 | } | ||
82 | } else { | 82 | } else { | ||
83 | notification.showNotification(xi18n("Could not fetch location name (check your Internet connection). Set default name")) | 83 | skyMapLite.notification.showNotification(xi18n("Could not fetch location name (check your Internet connection). Set default name")) | ||
84 | cityField.text = city | 84 | cityField.text = city | ||
85 | provinceField.text = province | 85 | provinceField.text = province | ||
86 | countryField.text = country | 86 | countryField.text = country | ||
87 | comboBoxTZ.currentIndex = comboBoxTZ.find(tz) | 87 | comboBoxTZ.currentIndex = comboBoxTZ.find(tz) | ||
88 | } | 88 | } | ||
89 | fetchingName = false | 89 | fetchingName = false | ||
90 | addAutomatically = false | 90 | addAutomatically = false | ||
91 | } | 91 | } | ||
92 | } | 92 | } | ||
93 | 93 | | |||
94 | onLocNameFetched: { | 94 | onLocNameFetched: { | ||
95 | nameFetchTimeout.running = false | 95 | nameFetchTimeout.running = false | ||
96 | city = _city | 96 | city = _city | ||
97 | region = _region | 97 | region = _region | ||
98 | country = _country | 98 | country = _country | ||
99 | 99 | | |||
100 | if(!LocationDialogLite.addCity(city, region, country, | 100 | if(!LocationDialogLite.addCity(city, region, country, | ||
101 | lat, lng, tz, | 101 | lat, lng, tz, | ||
102 | "--")) { | 102 | "--")) { | ||
103 | notification.showNotification(xi18n("Failed to set location")) | 103 | skyMapLite.notification.showNotification(xi18n("Failed to set location")) | ||
104 | } | 104 | } | ||
105 | 105 | | |||
106 | if(LocationDialogLite.setLocation(city + ", " + region + ", " + country)) { | 106 | if(LocationDialogLite.setLocation(city + ", " + region + ", " + country)) { | ||
107 | notification.showNotification(xi18n("Successfully set your location")) | 107 | skyMapLite.notification.showNotification(xi18n("Successfully set your location")) | ||
108 | } else { | 108 | } else { | ||
109 | notification.showNotification(xi18n("Could not set your location")) | 109 | skyMapLite.notification.showNotification(xi18n("Could not set your location")) | ||
110 | } | 110 | } | ||
111 | 111 | | |||
112 | addAutomatically = false | 112 | addAutomatically = false | ||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | function openAdd() { | 115 | function openAdd() { | ||
116 | editMode = false | 116 | editMode = false | ||
117 | isReadOnly = false | 117 | isReadOnly = false | ||
Show All 34 Lines | 148 | onSourceErrorChanged: { | |||
152 | var errorDesc = "" | 152 | var errorDesc = "" | ||
153 | 153 | | |||
154 | if (sourceError == 2 || sourceError == 1) { | 154 | if (sourceError == 2 || sourceError == 1) { | ||
155 | errorDesc = xi18n("No location service (GPS, cellular service, etc.) is available.\nPlease, switch on the location service, and retry") | 155 | errorDesc = xi18n("No location service (GPS, cellular service, etc.) is available.\nPlease, switch on the location service, and retry") | ||
156 | } else if (sourceError == 4) { | 156 | } else if (sourceError == 4) { | ||
157 | errorDesc = xi18n("Unknown error occurred. Please contact the application developer.") | 157 | errorDesc = xi18n("Unknown error occurred. Please contact the application developer.") | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | notification.showNotification(errorDesc) | 160 | skyMapLite.notification.showNotification(errorDesc) | ||
161 | positionSource.stop() | 161 | positionSource.stop() | ||
162 | error = true | 162 | error = true | ||
163 | locationLoading.close() | 163 | locationLoading.close() | ||
164 | } | 164 | } | ||
165 | 165 | | |||
166 | onUpdateTimeout: { | 166 | onUpdateTimeout: { | ||
167 | notification.showNotification(xi18n("Timeout occurred. Try again.")) | 167 | skyMapLite.notification.showNotification(xi18n("Timeout occurred. Try again.")) | ||
168 | locationLoading.close() | 168 | locationLoading.close() | ||
169 | } | 169 | } | ||
170 | 170 | | |||
171 | onActiveChanged: { | 171 | onActiveChanged: { | ||
172 | if(positionSource.active && !error) { | 172 | if(positionSource.active && !error) { | ||
173 | locationLoading.open() | 173 | locationLoading.open() | ||
174 | } else if (!fetchingName) { | 174 | } else if (!fetchingName) { | ||
175 | locationLoading.close() | 175 | locationLoading.close() | ||
176 | error = false | 176 | error = false | ||
177 | } | 177 | } | ||
178 | } | 178 | } | ||
179 | 179 | | |||
180 | onPositionChanged: { | 180 | onPositionChanged: { | ||
181 | if(isLoaded) { | 181 | if(isLoaded) { | ||
182 | notification.showNotification(xi18n("Found your longitude and altitude")) | 182 | skyMapLite.notification.showNotification(xi18n("Found your longitude and altitude")) | ||
183 | var lat = positionSource.position.coordinate.latitude | 183 | var lat = positionSource.position.coordinate.latitude | ||
184 | var lng = positionSource.position.coordinate.longitude | 184 | var lng = positionSource.position.coordinate.longitude | ||
185 | latField.text = lat | 185 | latField.text = lat | ||
186 | longField.text = lng | 186 | longField.text = lng | ||
187 | if(addAutomatically) { | 187 | if(addAutomatically) { | ||
188 | locationFetched(lat, lng) | 188 | locationFetched(lat, lng) | ||
189 | } | 189 | } | ||
190 | 190 | | |||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 357 | Button { | |||
359 | text: "Set from GPS" | 359 | text: "Set from GPS" | ||
360 | enabled: isAvailable | 360 | enabled: isAvailable | ||
361 | onClicked: { | 361 | onClicked: { | ||
362 | positionSource.stop() | 362 | positionSource.stop() | ||
363 | positionSource.start() | 363 | positionSource.start() | ||
364 | loadingText = fetchingCoordinatesLoading | 364 | loadingText = fetchingCoordinatesLoading | ||
365 | if(!positionSource.valid) { | 365 | if(!positionSource.valid) { | ||
366 | positionSource.stop() | 366 | positionSource.stop() | ||
367 | notification.showNotification(xi18("Positioning is not available on your device")) | 367 | skyMapLite.notification.showNotification(xi18("Positioning is not available on your device")) | ||
368 | } | 368 | } | ||
369 | } | 369 | } | ||
370 | 370 | | |||
371 | Connections { | 371 | Connections { | ||
372 | target: locationLoading | 372 | target: locationLoading | ||
373 | onClosed: { | 373 | onClosed: { | ||
374 | positionSource.stop() | 374 | positionSource.stop() | ||
375 | } | 375 | } | ||
376 | } | 376 | } | ||
377 | } | 377 | } | ||
378 | 378 | | |||
379 | Button { | 379 | Button { | ||
380 | //enabled: | 380 | //enabled: | ||
381 | visible: !isReadOnly | 381 | visible: !isReadOnly | ||
382 | text: editMode ? xi18n("Save") : xi18n("Add") | 382 | text: editMode ? xi18n("Save") : xi18n("Add") | ||
383 | onClicked: { | 383 | onClicked: { | ||
384 | if(cityField.text == "") { | 384 | if(cityField.text == "") { | ||
385 | notification.showNotification(xi18n("Please, fill in the city")) | 385 | skyMapLite.notification.showNotification(xi18n("Please, fill in the city")) | ||
386 | return | 386 | return | ||
387 | } else if(countryField.text == "") { | 387 | } else if(countryField.text == "") { | ||
388 | notification.showNotification(xi18n("Please, fill in the country")) | 388 | skyMapLite.notification.showNotification(xi18n("Please, fill in the country")) | ||
389 | return | 389 | return | ||
390 | } else if(latField.text == "") { | 390 | } else if(latField.text == "") { | ||
391 | notification.showNotification(xi18n("Please, fill in the latitude")) | 391 | skyMapLite.notification.showNotification(xi18n("Please, fill in the latitude")) | ||
392 | return | 392 | return | ||
393 | } else if(longField.text == "") { | 393 | } else if(longField.text == "") { | ||
394 | notification.showNotification(xi18n("Please, fill in the longitude")) | 394 | skyMapLite.notification.showNotification(xi18n("Please, fill in the longitude")) | ||
395 | return | 395 | return | ||
396 | } | 396 | } | ||
397 | 397 | | |||
398 | if(!LocationDialogLite.checkLongLat(longField.text, latField.text)) { | 398 | if(!LocationDialogLite.checkLongLat(longField.text, latField.text)) { | ||
399 | notification.showNotification(xi18n("Either the longitude or the latitude values are not valid")) | 399 | skyMapLite.notification.showNotification(xi18n("Either the longitude or the latitude values are not valid")) | ||
400 | return | 400 | return | ||
401 | } | 401 | } | ||
402 | 402 | | |||
403 | if(fieldsChanged) { | 403 | if(fieldsChanged) { | ||
404 | if(LocationDialogLite.isDuplicate(cityField.text, provinceField.text, countryField.text)) { | 404 | if(LocationDialogLite.isDuplicate(cityField.text, provinceField.text, countryField.text)) { | ||
405 | notification.showNotification(xi18n("This location already exists. Change either the city, the province or the country")) | 405 | skyMapLite.notification.showNotification(xi18n("This location already exists. Change either the city, the province or the country")) | ||
406 | return | 406 | return | ||
407 | } | 407 | } | ||
408 | } | 408 | } | ||
409 | 409 | | |||
410 | //Fullname of new location | 410 | //Fullname of new location | ||
411 | var fullName = cityField.text + ", " | 411 | var fullName = cityField.text + ", " | ||
412 | if(provinceField.text != "") { | 412 | if(provinceField.text != "") { | ||
413 | fullName += provinceField.text + ", " | 413 | fullName += provinceField.text + ", " | ||
414 | } | 414 | } | ||
415 | fullName += countryField.text | 415 | fullName += countryField.text | ||
416 | 416 | | |||
417 | if(!editMode) { | 417 | if(!editMode) { | ||
418 | if(!LocationDialogLite.addCity(cityField.text, provinceField.text, countryField.text, | 418 | if(!LocationDialogLite.addCity(cityField.text, provinceField.text, countryField.text, | ||
419 | latField.text, longField.text, comboBoxTZ.currentText, | 419 | latField.text, longField.text, comboBoxTZ.currentText, | ||
420 | comboBoxDST.currentText)) { | 420 | comboBoxDST.currentText)) { | ||
421 | notification.showNotification(xi18n("Failed to add location")) | 421 | skyMapLite.notification.showNotification(xi18n("Failed to add location")) | ||
422 | return | 422 | return | ||
423 | } else { | 423 | } else { | ||
424 | notification.showNotification(xi18n("Added new location - %1", fullName)) | 424 | skyMapLite.notification.showNotification(xi18n("Added new location - %1", fullName)) | ||
425 | } | 425 | } | ||
426 | } else { | 426 | } else { | ||
427 | if(!LocationDialogLite.editCity(geoName, cityField.text, provinceField.text, countryField.text, | 427 | if(!LocationDialogLite.editCity(geoName, cityField.text, provinceField.text, countryField.text, | ||
428 | latField.text, longField.text, comboBoxTZ.currentText, | 428 | latField.text, longField.text, comboBoxTZ.currentText, | ||
429 | comboBoxDST.currentText)) { | 429 | comboBoxDST.currentText)) { | ||
430 | notification.showNotification(xi18n("Failed to edit city")) | 430 | skyMapLite.notification.showNotification(xi18n("Failed to edit city")) | ||
431 | return | 431 | return | ||
432 | } | 432 | } | ||
433 | } | 433 | } | ||
434 | 434 | | |||
435 | locationDialog.filterCities() | 435 | locationDialog.filterCities() | ||
436 | if(!editMode) { | 436 | if(!editMode) { | ||
437 | //If we are adding location then open menu with newly added location | 437 | //If we are adding location then open menu with newly added location | ||
438 | locationsGeoMenu.openMenu(fullName) | 438 | locationsGeoMenu.openMenu(fullName) | ||
Show All 15 Lines |